parser_gaussian.py 2.3 KB
Newer Older
1
import setup_paths
2
from nomadcore.simple_parser import mainFunction, SimpleMatcher as SM
3 4 5 6
from nomadcore.local_meta_info import loadJsonFile, InfoKindEl
import os, sys, json

# description of the input
7 8 9 10 11 12 13 14 15 16 17 18 19
mainFileDescription = SM(
    name = 'root',
    weak = True,
    startReStr = "",
    subMatchers = [
        SM(name = 'newRun',
           startReStr = r"\s*# SampleParser #\s*",
           repeats = True,
           required = True,
           forwardMatch = True,
           sections   = ['section_run'],
           subMatchers = [
               SM(name = 'header',
20
                  startReStr = r"\s*# SampleParser #\s*")
21 22
           ])
])
23 24 25 26 27 28 29 30 31 32

# loading metadata from nomad-meta-info/meta_info/nomad_meta_info/gaussian.nomadmetainfo.json
metaInfoPath = os.path.normpath(os.path.join(os.path.dirname(os.path.abspath(__file__)),"../../../../nomad-meta-info/meta_info/nomad_meta_info/gaussian.nomadmetainfo.json"))
metaInfoEnv, warnings = loadJsonFile(filePath = metaInfoPath, dependencyLoader = None, extraArgsHandling = InfoKindEl.ADD_EXTRA_ARGS, uri = None)

parserInfo = {
  "name": "parser_gaussian",
  "version": "1.0"
}

33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
class GaussianParserContext(object):
    """main place to keep the parser status, open ancillary files,..."""
    def __init__(self):
        self.scfIterNr = 0

    # just examples, you probably want to remove the following two triggers

    def onClose_section_single_point_evaluation(self, backend, gIndex, section):
        """trigger called when section_single_point_evaluation is closed"""
        #backend.addValue("", self.scfIterNr)
        logging.getLogger("nomadcore.parsing").info("closing section_single_point_evaluation gIndex %d %s", gIndex, section.simpleValues)
        self.scfIterNr = 0

    def onClose_section_scf_iteration(self, backend, gIndex, section):
        """trigger called when section_scf_iteration is closed"""
        logging.getLogger("nomadcore.parsing").info("closing section_scf_iteration bla gIndex %d %s", gIndex, section.simpleValues)
        self.scfIterNr += 1

# which values to cache or forward (mapping meta name -> CachingLevel)
cachingLevelForMetaName = {}
53 54

if __name__ == "__main__":
55 56
    mainFunction(mainFileDescription, metaInfoEnv, parserInfo,
                 cachingLevelForMetaName = cachingLevelForMetaName,
Mohamed, Fawzi Roberto (fawzi)'s avatar
cleanup  
Mohamed, Fawzi Roberto (fawzi) committed
57
                 superContext = GaussianParserContext())