exciting_parser_GS_input.py 1.03 KB
Newer Older
Pardini, Lorenzo (lopa)'s avatar
Pardini, Lorenzo (lopa) committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import xml.sax
import logging
import numpy as np
from nomadcore.unit_conversion.unit_conversion import convert_unit_function
from nomadcore.unit_conversion.unit_conversion import convert_unit
from nomadcore.unit_conversion import unit_conversion

class InputHandler(xml.sax.handler.ContentHandler):
    def __init__(self, backend):
        self.backend = backend

    def startElement(self, name, attrs):
        if name == "libxc":        #libXC
            correlation = attrs.getValue("correlation")[3:]
            exchange = attrs.getValue("exchange")[3:]
            xcName = [correlation, exchange]
            for xc in xcName:
                gi = self.backend.openSection("section_XC_functionals")
                self.backend.addValue("XC_functional_name", xc)
                self.backend.closeSection("section_XC_functionals", gi)

    def endElement(self, name):
        pass

def parseInput(inF, backend):
    handler = InputHandler(backend)
    logging.error("will parse")
    xml.sax.parse(inF, handler)
    logging.error("did parse")