initial commit: skeleton for parser using the simple parser infrastructure

parents
# use glob syntax.
syntax: glob
*.ser
*.class
*~
*.bak
#*.off
*.old
*.pyc
*.bk
*.swp
.DS_Store
# logging files
detailed.log
# eclipse conf file
.settings
.classpath
.project
.manager
.scala_dependencies
# idea
.idea
*.iml
# building
target
build
null
tmp*
temp*
dist
test-output
build.log
# other scm
.svn
.CVS
.hg*
# switch to regexp syntax.
# syntax: regexp
# ^\.pc/
#SHITTY output not in target directory
build.log
#emacs TAGS
TAGS
lib/
env/
# Octopus Parser
This is the parser for [octopus](http://www.tddft.org/programs/octopus/wiki/index.php/Main_Page).
It is part of the [NOMAD Laboratory](http://nomad-lab.eu).
The official version lives at
git@gitlab.mpcdf.mpg.de:nomad-lab/parser-octopus.git
you can browse it at
https://gitlab.mpcdf.mpg.de/nomad-lab/parser-octopus
It relies on having the nomad-meta-info and the python common repositories one level higher.
The simplest way to have this is to check out nomad-lab-base recursively:
git clone --recursive git@gitlab.mpcdf.mpg.de:nomad-lab/nomad-lab-base.git
then this will be in parsers/octopus.
import setup_paths
from nomadcore.simple_parser import mainFunction, SimpleMatcher as SM
from nomadcore.local_meta_info import loadJsonFile, InfoKindEl
import os, sys, json
# description of the input
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',
startReStr = r"\s*# SampleParser #\s*")
])
])
# loading metadata from nomad-meta-info/meta_info/nomad_meta_info/octopus.nomadmetainfo.json
metaInfoPath = os.path.normpath(os.path.join(os.path.dirname(os.path.abspath(__file__)),"../../../../nomad-meta-info/meta_info/nomad_meta_info/octopus.nomadmetainfo.json"))
metaInfoEnv, warnings = loadJsonFile(filePath = metaInfoPath, dependencyLoader = None, extraArgsHandling = InfoKindEl.ADD_EXTRA_ARGS, uri = None)
parserInfo = {
"name": "parser_octopus",
"version": "1.0"
}
class OctopusParserContext(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 = {}
if __name__ == "__main__":
mainFunction(mainFileDescription, metaInfoEnv, parserInfo,
cachingLevelForMetaName = cachingLevelForMetaName,
superContext = OctopusParserContext())
import sys, os, os.path
baseDir = os.path.dirname(os.path.abspath(__file__))
commonDir = os.path.normpath(os.path.join(baseDir,"../../../../python-common/python"))
if not commonDir in sys.path:
sys.path.insert(0, commonDir)
sample files to test the parser
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment