Skip to content
Snippets Groups Projects
Commit ccbb879e authored by Mohamed, Fawzi Roberto (fawzi)'s avatar Mohamed, Fawzi Roberto (fawzi)
Browse files

initial commit of the sample parser

parents
Branches
Tags
No related merge requests found
# Sample Parser
The aim of this project is to give the basic setup for a parser using the python library developed for
[NOMAD CoE](http://nomad-coe.eu)
The setup is expected to be improved as we find better ways to write the parsers.
For your parser rename parser/sample-parser to parser/parser-YourCode and likewise fix
the code.
The python-common and nomad-meta-info repositories are expected to be checked out one level
higher as this repository.
This is automatically the case if you clone nomad-lab-base (the parsers are in parsers subdirectory).
For more information on how to write a parser see the [wiki](https://gitlab.mpcdf.mpg.de/nomad-lab/nomad-lab-base/wikis/how-to-write-a-parser).
import setup_paths
from nomadcore.simple_parser import SimpleMatcher, mainFunction
from nomadcore.local_meta_info import loadJsonFile, InfoKindEl
import os, sys, json
# description of the input
mainFileDescription = SimpleMatcher(name = 'root',
weak = True,
startReStr = "",
subMatchers = [
SimpleMatcher(name = 'newRun',
startReStr = r"\s*# SampleParser #\s*",
repeats = True,
required = True,
forwardMatch = True,
sections = ['section_run'],
subMatchers = [
SimpleMatcher(name = 'header',
startReStr = r"\s*# SampleParser #\s*")
])
])
# loading metadata from nomad-meta-info/meta_info/nomad_meta_info/fhi_aims.nomadmetainfo.json
parserInfo = {
"name": "sample_parser",
"version": "1.0"
}
metaInfoPath = os.path.normpath(os.path.join(os.path.dirname(os.path.abspath(__file__)),"../../../../nomad-meta-info/meta_info/nomad_meta_info/sample_parser.nomadmetainfo.json"))
metaInfoEnv, warnings = loadJsonFile(filePath = metaInfoPath, dependencyLoader = None, extraArgsHandling = InfoKindEl.ADD_EXTRA_ARGS, uri = None)
if __name__ == "__main__":
mainFunction(mainFileDescription, metaInfoEnv, parserInfo)
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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment