Commit 488d0409 authored by Berk Onat's avatar Berk Onat

Corrected MapDictionary/MetaInfoStorage behaviour on Meta Name (matchStr) conversion.

parent a2af5dc8
......@@ -5,7 +5,9 @@ from nomadcore.unit_conversion.unit_conversion import convert_unit
from nomadcore.caching_backend import CachingLevel
from nomadcore.simple_parser import mainFunction
from nomadcore.simple_parser import SimpleMatcher as SM
from AMBERDictionary import get_nameList, get_fileListDict, set_excludeList, set_includeList
from AMBERDictionary import get_nameListDict, get_fileListDict, set_excludeList, set_includeList
from MetaInfoStorage import COMMON_META_INFO_PATH, PUBLIC_META_INFO_PATH
import MetaInfoStorage as mStore
import logging
import json
import os
......@@ -27,23 +29,14 @@ def get_metaInfo(self):
dependencyLoader=None,
extraArgsHandling=InfoKindEl.ADD_EXTRA_ARGS,
uri=None)
metaInfoEnv = set_metaInfoEnv(metaInfoEnv, 'mdin', get_nameList('cntrl'), 'C', ["x_amber_mdin_method"])
metaInfoEnv = set_metaInfoEnv(metaInfoEnv, 'mdin', get_nameList('ewald'), 'C', ["x_amber_mdin_method"])
metaInfoEnv = set_metaInfoEnv(metaInfoEnv, 'mdin', get_nameList('qmmm'), 'C', ["x_amber_mdin_method"])
metaInfoEnv = set_metaInfoEnv(metaInfoEnv, 'parm', get_nameList('parm'), 'C', ["x_amber_mdin_method"])
metaInfoEnv = set_section_metaInfoEnv(metaInfoEnv, 'section', ['input_output_files'], 'type_section', False, ["section_run"])
# metaInfoEnv = set_section_metaInfoEnv(metaInfoEnv, 'mdin_file',
# ['input_output_files'], 'type_abstract_document_content',
# False, ["x_amber_section_input_output_files"])
metaInfoEnv = setDict_metaInfoEnv(metaInfoEnv, self.fileDict)
metaInfoEnv = set_metaInfoEnv(metaInfoEnv, 'mdout', get_nameList('mddata'), 'C', ["section_single_configuration_calculation"])
# metaInfoEnv = set_metaInfoEnv(metaInfoEnv, 'mdout', get_nameList('mddata'), 'C', ["x_amber_mdout_single_configuration_calculation"])
metaInfoEnv = set_metaInfoEnv(metaInfoEnv, 'parm',
[ 'flags', 'box_info',
'unitcell_radius', 'total_memory',
'file_format', 'file_version',
'file_date', 'file_time'],
'C', ["x_amber_mdin_method"])
metaInfoEnv = setDict_metaInfoEnv(metaInfoEnv, self.cntrlDict)
metaInfoEnv = setDict_metaInfoEnv(metaInfoEnv, self.ewaldDict)
metaInfoEnv = setDict_metaInfoEnv(metaInfoEnv, self.qmmmDict)
metaInfoEnv = setDict_metaInfoEnv(metaInfoEnv, self.parmDict)
metaInfoEnv = setDict_metaInfoEnv(metaInfoEnv, self.mddataDict)
metaInfoEnv = setDict_metaInfoEnv(metaInfoEnv, self.extraDict)
return metaInfoEnv
def set_section_metaInfoEnv(infoEnv, metaNameTag, newList, listTypStr, repeatingSection, supraNames):
......@@ -109,64 +102,33 @@ def set_metaInfoEnv(infoEnv, metaNameTag, newList, listTypStr, supraNames):
return infoEnv
def write_mdin(self, backend, metaInfoEnv, metaNameStart, valuesDict, writeCheck, location, logger):
"""Writes the values of the mdin file.
Write the last occurrence of a keyword, i.e. [-1], since aims uses the last occurrence of a keyword.
ATTENTION
backend.superBackend is used here instead of only the backend to write the JSON values,
since this allows to bybass the caching setting which was used to collect the values for processing.
However, this also bypasses the checking of validity of the metadata name by the backend.
The scala part will check the validity nevertheless.
Args:
backend: Class that takes care of writing and caching of metadata.
metainfoenv: Loaded metadata.
valuesdict: Dictionary that contains the cached values of a section.
writecheck: Boolean that determines whether the keywords related to the ?? should be written.
location: A string that is used to specify where more than one setting was found.
logger: Logging object where messages should be written to.
"""
# list of excluded metadata for writeout
# namelist values at metdata are only needed to detect
# the type of simulation from cntrl not to writeout to backend.
excludelist = set_excludeList(self)
includelist = set_includeList()
# write settings
for k,v in valuesDict.items():
if (k.startswith('x_amber_mdin_') or
k.startswith('x_amber_mdout_') or
k.startswith('x_amber_parm_')):
if (k in excludelist and
k not in includelist):
continue
# default writeout
else:
# convert keyword values of mdin which are strings to lowercase for consistency
if isinstance(v[-1], str):
value = v[-1].lower()
else:
value = v[-1]
backend.superBackend.addValue(k, value)
#if writecheck:
# return 1
# distinguish between cntrl namelist
if metaNameStart == 'x_amber_mdin':
Write = False
elif metaNameStart == 'x_amber_mdinout':
Write = True
else:
logger.error("Unknown metaNameStart %s in function in %s. Please correct." % (metaNameStart, os.path.basename(__file__)))
return
class AMBERParserBase(object):
"""Base class for Amber parsers"""
def __init__(self,cachingLevelForMetaName=None, coverageIgnoreList=None,
re_program_name=None):
self.metaStorage = mStore.Container('section_run')
exclude_dict = {
'section_run' : [
'section_processor_info',
'section_processor_log',
'section_springer_material',
'section_repository_info'
]}
jsonmetadata = mStore.JsonMetaInfo(
COMMON_META_INFO_PATH,
PUBLIC_META_INFO_PATH,
META_INFO_PATH
)
self.metaStorage.build(jsonmetadata, 'section_run', exclude_dict)
self.re_program_name = re_program_name
self.fileDict = get_fileListDict()
self.cntrlDict = get_nameListDict('cntrl')
self.ewaldDict = get_nameListDict('ewald')
self.qmmmDict = get_nameListDict('qmmm')
self.wtDict = get_nameListDict('wt')
self.parmDict = get_nameListDict('parm')
self.mddataDict = get_nameListDict('mddata')
self.extraDict = get_nameListDict('extra')
self.parserInfo = PARSER_INFO_DEFAULT.copy()
self.metaInfoEnv = get_metaInfo(self)
# self.cachingLevelForMetaName = {
......@@ -213,9 +175,4 @@ class AMBERParserBase(object):
def build_subMatchers(self):
return []
#class MetaInfoStorageBase(object):
# """Base class for meta info storage"""
# def __init__(self,cachingLevelForMetaName=None, coverageIgnoreList=None):
# self.re_program_name = re_program_name
......@@ -117,7 +117,10 @@ class MapDictionary(dict):
metaStr = metaStr + v.metaHeader + '_'
if v.metaNameTag:
metaStr = metaStr + v.metaNameTag + '_'
self[metaStr + v.metaName] = v
metaStr = metaStr + v.metaName
self[metaStr] = v
if metaStr != k:
self.pop(k, None)
if kwargs:
for k, v in kwargs.items():
......@@ -127,12 +130,16 @@ class MapDictionary(dict):
v.metaName = v.nameTranslate(k)
else:
v.metaName = k
v.matchStr = k
metaStr = ''
if v.metaHeader:
metaStr = metaStr + v.metaHeader + '_'
if v.metaNameTag:
metaStr = metaStr + v.metaNameTag + '_'
self[metaStr + v.metaName] = v
metaStr = metaStr + v.metaName
self[metaStr] = v
if metaStr != k:
self.pop(k, None)
def __getattr__(self, attr):
return self.get(attr)
......@@ -677,10 +684,10 @@ def get_updateDictionary(self, defname):
}
singleconfcalc = {
'atom_forces_type' : MetaInfoMap(startpage,
depends=[{'assign' : 'Amber Force Field'}],
lookupdict=self.mddataDict
),
#'atom_forces_type' : MetaInfoMap(startpage,
# depends=[{'assign' : 'Amber Force Field'}],
# lookupdict=self.mddataDict
# ),
'energy_correction_entropy' : MetaInfoMap(startpage),
'energy_current' : MetaInfoMap(startpage,
depends=[{'value' : 'Etot'}],
......@@ -721,63 +728,71 @@ def get_updateDictionary(self, defname):
frameseq = {
'frame_sequence_conserved_quantity_frames' : MetaInfoMap(startpage,
depends=[{'value' : 'NSTEP'}],
depends=[{'store' : 'NSTEP'}],
lookupdict=self.mddataDict
),
'frame_sequence_conserved_quantity_stats' : MetaInfoMap(startpage),
'frame_sequence_conserved_quantity' : MetaInfoMap(startpage,
depends=[{'value' : 'RESTRAINT'}],
depends=[{'store' : 'RESTRAINT'}],
lookupdict=self.mddataDict
),
'frame_sequence_continuation_kind' : MetaInfoMap(startpage),
'frame_sequence_external_url' : MetaInfoMap(startpage),
'frame_sequence_kinetic_energy_frames' : MetaInfoMap(startpage,
depends=[{'value' : 'NSTEP'}],
depends=[{'store' : 'NSTEP'}],
lookupdict=self.mddataDict
),
'frame_sequence_kinetic_energy_stats' : MetaInfoMap(startpage),
'frame_sequence_kinetic_energy' : MetaInfoMap(startpage,
depends=[{'value' : 'EKtot'}],
depends=[{'store' : 'EKtot'}],
lookupdict=self.mddataDict
),
'frame_sequence_local_frames_ref' : MetaInfoMap(startpage),
'frame_sequence_potential_energy_frames' : MetaInfoMap(startpage,
depends=[{'value' : 'NSTEP'}],
depends=[{'store' : 'NSTEP'}],
lookupdict=self.mddataDict
),
'frame_sequence_potential_energy_stats' : MetaInfoMap(startpage),
'frame_sequence_potential_energy' : MetaInfoMap(startpage,
depends=[{'value' : 'EPtot'}],
depends=[{'store' : 'EPtot'}],
lookupdict=self.mddataDict
),
'frame_sequence_pressure_frames' : MetaInfoMap(startpage,
depends=[{'value' : 'NSTEP'}],
depends=[{'store' : 'NSTEP'}],
lookupdict=self.mddataDict
),
'frame_sequence_pressure_stats' : MetaInfoMap(startpage),
'frame_sequence_pressure' : MetaInfoMap(startpage,
depends=[{'value' : 'PRESS'}],
depends=[{'store' : 'PRESS'}],
lookupdict=self.mddataDict
),
'frame_sequence_temperature_frames' : MetaInfoMap(startpage,
depends=[{'value' : 'NSTEP'}],
depends=[{'store' : 'NSTEP'}],
lookupdict=self.mddataDict
),
'frame_sequence_temperature_stats' : MetaInfoMap(startpage),
'frame_sequence_temperature' : MetaInfoMap(startpage,
depends=[{'value' : 'TEMP'}],
depends=[{'store' : 'TEMP'}],
lookupdict=self.mddataDict
),
'frame_sequence_time' : MetaInfoMap(startpage,
depends=[{'value' : 'TIME'}],
depends=[{'store' : 'TIME'}],
lookupdict=self.mddataDict
),
'frame_sequence_volume' : MetaInfoMap(startpage,
depends=[{'value' : 'VOLUME'}],
'x_amber_frame_sequence_volume_frames' : MetaInfoMap(startpage,
depends=[{'store' : 'NSTEP'}],
lookupdict=self.mddataDict
),
'frame_sequence_density' : MetaInfoMap(startpage,
depends=[{'value' : 'Density'}],
'x_amber_frame_sequence_volume' : MetaInfoMap(startpage,
depends=[{'store' : 'VOLUME'}],
lookupdict=self.mddataDict
),
'x_amber_frame_sequence_density_frames' : MetaInfoMap(startpage,
depends=[{'store' : 'NSTEP'}],
lookupdict=self.mddataDict
),
'x_amber_frame_sequence_density' : MetaInfoMap(startpage,
depends=[{'store' : 'Density'}],
lookupdict=self.mddataDict
),
'frame_sequence_to_sampling_ref' : MetaInfoMap(startpage),
......@@ -910,4 +925,23 @@ def set_includeList():
]
return includelist
def getList_MetaStrInDict(sourceDict):
"""Returns a list that includes all meta name
strings for the given dictionary.
Meta name strings are not actual meta names but
used as the keywords in the parsing.
"""
return [sourceDict[item].matchStr for item in sourceDict]
def getDict_MetaStrInDict(sourceDict):
"""Returns a dict that includes all meta name
strings and corresponding values for the given dictionary.
Meta name strings are not actual meta names but
used as the keywords in the parsing.
"""
newDict = {}
for item in sourceDict:
newDict.update({sourceDict[item].matchStr : sourceDict[item]})
return newDict
......@@ -7,8 +7,7 @@ import nomadcore.ActivateLogging
from nomadcore.caching_backend import CachingLevel
from nomadcore.simple_parser import AncillaryParser, mainFunction, ParsingContext
from nomadcore.simple_parser import SimpleMatcher as SM
from AMBERDictionary import set_excludeList, set_includeList, get_updateDictionary
from AMBERCommon import write_mdin
from AMBERDictionary import set_excludeList, set_includeList, get_updateDictionary, getList_MetaStrInDict
import AMBERCommon as AmberC
import trajectory_reader as TrajRead
import logging
......@@ -85,6 +84,7 @@ class AMBERParser(AmberC.AMBERParserBase):
"""
self.secMethodIndex = None
self.secSystemDescriptionIndex = None
self.samplingGIndex = None
self.inputMethodIndex = None
self.mainMethodIndex = None
self.mainCalcIndex = None
......@@ -219,14 +219,6 @@ class AMBERParser(AmberC.AMBERParserBase):
# write trajectory
valuesDict = section.simpleValues
location = 'verbatim writeout of mdin',
# write settings of control.in
write_mdin(self, backend=backend,
metaInfoEnv=self.metaInfoEnv,
valuesDict=valuesDict,
metaNameStart='x_amber_mdin',
writeCheck=False,
location=location,
logger=LOGGER)
# write settings of aims output from the parsed control.in
for k,v in section.simpleValues.items():
if (k.startswith('x_amber_mdin_') or
......@@ -258,7 +250,10 @@ class AMBERParser(AmberC.AMBERParserBase):
# backend.addValue("sampling_method", sampling_method)
# backend.closeSection("section_sampling_method", samplingGIndex)
frameSequenceGIndex = backend.openSection("section_frame_sequence")
# backend.addValue("frame_sequence_to_sampling_ref", samplingGIndex)
self.metaStorage.updateBackend(backend,
startsection=['section_frame_sequence'],
autoopenclose=False)
backend.addValue("frame_sequence_to_sampling_ref", self.samplingGIndex)
backend.addArrayValues("frame_sequence_local_frames_ref", np.asarray(self.singleConfCalcs))
backend.closeSection("section_frame_sequence", frameSequenceGIndex)
......@@ -346,13 +341,6 @@ class AMBERParser(AmberC.AMBERParserBase):
# check if control keywords were found or verbatim_writeout is false
#verbatim_writeout = True
counter = 0
write_mdin(self, backend=backend,
metaInfoEnv=self.metaInfoEnv,
valuesDict=section.simpleValues,
metaNameStart='x_amber_mdin',
writeCheck=True,
location='verbatim writeout of mdin',
logger=LOGGER)
exclude_list = set_excludeList(self)
include_list = set_includeList()
#for name in self.metaInfoEnv.infoKinds:
......@@ -389,12 +377,12 @@ class AMBERParser(AmberC.AMBERParserBase):
#'muteSections' : [['section_system']],
'dictionary' : section_sampling_Dict
}
self.samplingGIndex = backend.openSection("section_sampling_method")
self.metaStorage.update(updateDict)
samplingGIndex = backend.openSection("section_sampling_method")
self.metaStorage.updateBackend(backend,
startsection=['section_sampling_method'],
autoopenclose=False)
backend.closeSection("section_sampling_method", samplingGIndex)
backend.closeSection("section_sampling_method", self.samplingGIndex)
counter = 0
......@@ -530,15 +518,17 @@ class AMBERParser(AmberC.AMBERParserBase):
section_frameseq_single_Dict.update(section_singlecalc_Dict)
updateDict = {
'startSection' : [
['section_single_configuration_calculaion'],
['section_single_configuration_calculation'],
['section_frame_sequence']],
'muteSections' : [['section_method']],
'dictionary' : section_frameseq_single_Dict
}
self.metaStorage.update(updateDict)
singleGIndex = backend.openSection("section_single_configuration_calculation")
self.metaStorage.updateBackend(backend,
startsection=['section_frame_sequence'],
startsection=['section_single_configuration_calculation'],
autoopenclose=False)
backend.closeSection("section_single_configuration_calculation", singleGIndex)
def setStartingPointCalculation(self, parser):
backend = parser.backend
......@@ -633,10 +623,10 @@ class AMBERParser(AmberC.AMBERParserBase):
'x_amber_settings_integrator_dt__ps': '0.001',
'x_amber_ensemble_type': 'NVE'
},
cntrlNameList=self.cntrlDict.keys()
ewaldNameList=self.ewaldDict.keys()
qmmmNameList=self.qmmmDict.keys()
wtNameList=self.wtDict.keys()
cntrlNameList=getList_MetaStrInDict(self.cntrlDict)
ewaldNameList=getList_MetaStrInDict(self.ewaldDict)
qmmmNameList=getList_MetaStrInDict(self.qmmmDict)
wtNameList=getList_MetaStrInDict(self.wtDict)
return [
SM(name="cntrl",
startReStr=r"\s*&cntrl",
......@@ -717,7 +707,7 @@ class AMBERParser(AmberC.AMBERParserBase):
]
def build_parmKeywordsSimpleMatchers(self):
parmNameList=self.parmDict.keys()
parmNameList=getList_MetaStrInDict(self.parmDict)
return [
SM(name="parm",
startReStr=r"\|\s*Version\s*=\s*(?P<x_amber_parm_file_version>[0-9.eEdD]+)" +
......@@ -745,7 +735,7 @@ class AMBERParser(AmberC.AMBERParserBase):
def build_mdoutKeywordsSimpleMatchers(self):
newDict = self.cntrlDict
newDict.update(self.qmmmDict)
mdoutNameList = newDict.keys()
mdoutNameList = getList_MetaStrInDict(newDict)
return [
SM(name="mdout",
startReStr=r"\s*General\s*flags:",
......@@ -850,7 +840,7 @@ class AMBERParser(AmberC.AMBERParserBase):
########################################
# submatcher for MD
mddataNameList=self.mddataDict.keys()
mddataNameList=getList_MetaStrInDict(self.mddataDict)
MDSubMatcher = SM(name='MDStep',
# startReStr=r"\s*(?:NSTEP\s*=|NSTEP\s*ENERGY\s*RMS)",
startReStr=r"\s*(?:NSTEP\s*=|NSTEP\s*ENERGY\s*RMS\s*)",
......
......@@ -200,23 +200,23 @@ class Container(object):
if "lookupdict" in item:
if "test" in item["depends"][0]:
updateValue, localdict = self.checkTestsDicts(item, localdict)
elif 'assign' in item["depends"][0]:
elif "assign" in item["depends"][0]:
updateValue = item["depends"][0]["assign"]
elif 'value' in item["depends"][0]:
itemdepval = item["depends"][0]['value']
elif "value" in item["depends"][0]:
itemdepval = item["depends"][0]["value"]
if itemdepval in localdict:
checkval = localdict[itemdepval]
else:
accessName, checkval = self.findNameInLookupDict(itemdepval, item["lookupdict"])
accessName, checkval = self.findNameInLookupDict(itemdepval, item.lookupdict)
localdict.update({itemdepval : checkval})
updateValue = checkval
else:
if "test" in item["depends"][0]:
updateValue, localdict = self.checkTestsAttr(item, localdict)
if 'assign' in item["depends"][0]:
elif "assign" in item["depends"][0]:
updateValue = item["depends"][0]["assign"]
elif 'value' in item["depends"][0]:
itemdepval = item["depends"][0]['value']
elif "value" in item["depends"][0]:
itemdepval = item["depends"][0]["value"]
if itemdepval in localdict:
checkval = localdict[itemdepval]
else:
......@@ -288,7 +288,8 @@ class Container(object):
def findNameInLookupDict(self, metaname, lookupdict):
for item in lookupdict:
itemMap = lookupdict[item]
if metaname in itemMap.metaName:
#if metaname in itemMap.metaName:
if metaname in itemMap.matchStr:
return item, itemMap.value
def updateBackendStorage(self, backend):
......
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