Skip to content
Snippets Groups Projects
Commit 2f3cc139 authored by Daria Tomecka's avatar Daria Tomecka
Browse files

sub parser for struct file

parent 6e0eca4f
No related branches found
No related tags found
No related merge requests found
from builtins import object
import setup_paths
from nomadcore.simple_parser import mainFunction
from nomadcore.simple_parser import mainFunction, AncillaryParser, CachingLevel
from nomadcore.simple_parser import SimpleMatcher as SM
from nomadcore.local_meta_info import loadJsonFile, InfoKindEl
import os, sys, json
import wien2k_parser_struct
class Wien2kContext(object):
"""context for wien2k parser"""
......@@ -13,7 +14,7 @@ class Wien2kContext(object):
def initialize_values(self):
"""allows to reset values if the same superContext is used to parse different files"""
pass
self.metaInfoEnv = self.parser.parserBuilder.metaInfoEnv
def startedParsing(self, path, parser):
"""called when parsing starts"""
......@@ -26,6 +27,21 @@ class Wien2kContext(object):
section["x_wien2k_version"][0] + " " +
section["x_wien2k_release_date"][0])
def onOpen_section_system(self, backend, gIndex, section):
structSuperContext = wien2k_parser_struct.Wien2kStructContext()
structParser = AncillaryParser(
fileDescription = wien2k_parser_struct.buildStructureMatchers(),
parser = self.parser,
cachingLevelForMetaName = wien2k_parser_struct.get_cachingLevelForMetaName(self.metaInfoEnv, CachingLevel.PreOpenedIgnore),
superContext = structSuperContext)
mainFile = self.parser.fIn.fIn.name
fName = mainFile[:-4] + ".struct"
if os.path.exists(fName):
with open(fName) as fIn:
structParser.parseFile(fIn)
# description of the input
mainFileDescription = SM(
name = 'root',
......@@ -37,7 +53,7 @@ mainFileDescription = SM(
repeats = True,
required = True,
forwardMatch = True,
sections = ['section_run', 'section_single_configuration_calculation'],
sections = ['section_run', 'section_method', 'section_system', 'section_single_configuration_calculation'],
subMatchers = [
SM(
name = 'header',
......@@ -48,9 +64,12 @@ mainFileDescription = SM(
name = "scf iteration",
startReStr = r"\s*:ITE(?P<x_wien2k_iteration_number>[0-9]+):\s*[0-9]*. ITERATION",
sections=["section_scf_iteration"],
repeats = True,
subMatchers=[
SM(r":NATO :\s*(?P<x_wien2k_number_of_independent_atoms>[0-9]+)INDEPENDENT AND\s*(?P<x_wien2k_total_atoms>[0-9]+)\s*TOTAL ATOMS IN UNITCELL"),
SM("\s*SUBSTANCE: (?P<x_wien2k_system_name>.*)")
SM(r"\s*SUBSTANCE: (?P<x_wien2k_system_name>.*)"),
SM(r":POT\s*:\s*POTENTIAL OPTION\s*(?P<x_wien2k_potential_option>[0-9]+)"),
SM(r":VOL\s*:\s*UNIT CELL VOLUME\s*=\s*(?P<x_wien2k_unit_cell_volume__angstrom3>[0-9.]+)")
]
)
]
......
from builtins import object
import setup_paths
from nomadcore.simple_parser import mainFunction, CachingLevel
from nomadcore.simple_parser import SimpleMatcher as SM
from nomadcore.local_meta_info import loadJsonFile, InfoKindEl
import os, sys, json
class Wien2kStructContext(object):
"""context for wien2k struct parser"""
def __init__(self):
self.parser = None
def initialize_values(self):
"""allows to reset values if the same superContext is used to parse different files"""
pass
def startedParsing(self, path, parser):
"""called when parsing starts"""
self.parser = parser
# allows to reset values if the same superContext is used to parse different files
self.initialize_values()
# description of the input
def buildStructureMatchers():
return SM(
name = 'root',
weak = True,
startReStr = "",
sections = ["section_run", "section_system"],
subMatchers = [
SM(name = 'systemName',
startReStr = r"(?P<x_wien2k_system_nameIn>.*)")
])
def get_cachingLevelForMetaName(metaInfoEnv, CachingLvl):
"""Sets the caching level for the metadata.
Args:
metaInfoEnv: metadata which is an object of the class InfoKindEnv in nomadcore.local_meta_info.py.
CachingLvl: Sets the CachingLevel for the sections k_band, run, and single_configuration_calculation.
This allows to run the parser without opening new sections.
Returns:
Dictionary with metaname as key and caching level as value.
"""
# manually adjust caching of metadata
cachingLevelForMetaName = {
'section_run': CachingLvl,
'section_system': CachingLvl
}
cachingLevelForMetaName["x_wien2k_system_nameIn"] = CachingLevel.ForwardAndCache
return cachingLevelForMetaName
# loading metadata from nomad-meta-info/meta_info/nomad_meta_info/fhi_aims.nomadmetainfo.json
......@@ -27,6 +27,7 @@ object Wien2kParser extends SimpleExternalParserGenerator(
"--uri", "${mainFileUri}", "${mainFilePath}"),
resList = Seq(
"parser-wien2k/wien2k_parser.py",
"parser-wien2k/wien2k_parser_struct.py",
"parser-wien2k/setup_paths.py",
"nomad_meta_info/public.nomadmetainfo.json",
"nomad_meta_info/common.nomadmetainfo.json",
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment