Commit a2af5dc8 authored by Berk Onat's avatar Berk Onat
Browse files

Solved issue at dictionary evaluate at MetaInfoStorage

parent 9cc47a46
......@@ -634,7 +634,7 @@ def get_updateDictionary(self, defname):
lookupdict=self.cntrlDict
),
# 'geometry_optimization_threshold_force' : MetaInfoMap(startpage),
'settings_barostat' : MetaInfoMap(startpage,
'x_amber_barostat_type' : MetaInfoMap(startpage,
depends=[
{'test' : [['imin', '== 0'],
['ntp', '!= 0'],
......@@ -645,18 +645,20 @@ def get_updateDictionary(self, defname):
['barostat', '== 2']],
'assign' : 'Monte Carlo barostat'}
],
lookupdict=self.cntrlDict
lookupdict=self.cntrlDict,
activeSections=['settings_barostat']
),
'settings_integrator' : MetaInfoMap(startpage,
'x_amber_integrator_type' : MetaInfoMap(startpage,
depends=[
{'test' : [['imin', '== 0']],
'assign' : 'verlet'},
{'test' : [['imin', '== 1']],
'assign' : 'minimization'}
],
lookupdict=self.cntrlDict
lookupdict=self.cntrlDict,
activeSections=['settings_integrator']
),
'settings_thermostat' : MetaInfoMap(startpage,
'x_amber_thermostat_type' : MetaInfoMap(startpage,
depends=[
{'test' : [['imin', '== 0'], ['ntt', '== 1']],
'assign' : 'Constant Temperature Scaling with weak-coupling'},
......@@ -669,7 +671,8 @@ def get_updateDictionary(self, defname):
{'test' : [['imin', '== 0'], ['ntt', '== 10']],
'assign' : 'RESPA Stochastic Isokinetic Nose-Hoover'}
],
lookupdict=self.cntrlDict
lookupdict=self.cntrlDict,
activeSections=['settings_thermostat']
),
}
......@@ -717,18 +720,18 @@ def get_updateDictionary(self, defname):
}
frameseq = {
'frame_sequence_conserved_quantity_frames' : MetaInfoMap(startpage),
'frame_sequence_conserved_quantity_frames' : MetaInfoMap(startpage,
depends=[{'value' : 'NSTEP'}],
lookupdict=self.mddataDict
),
'frame_sequence_conserved_quantity_stats' : MetaInfoMap(startpage),
'frame_sequence_conserved_quantity' : MetaInfoMap(startpage),
'frame_sequence_conserved_quantity' : MetaInfoMap(startpage,
depends=[{'value' : 'RESTRAINT'}],
lookupdict=self.mddataDict
),
'frame_sequence_continuation_kind' : MetaInfoMap(startpage),
'frame_sequence_external_url' : MetaInfoMap(startpage),
'frame_sequence_kinetic_energy_frames' : MetaInfoMap(startpage),
'frame_sequence_kinetic_energy_frames' : MetaInfoMap(startpage,
depends=[{'value' : 'NSTEP'}],
lookupdict=self.mddataDict
),
......@@ -738,7 +741,7 @@ def get_updateDictionary(self, defname):
lookupdict=self.mddataDict
),
'frame_sequence_local_frames_ref' : MetaInfoMap(startpage),
'frame_sequence_potential_energy_frames' : MetaInfoMap(startpage),
'frame_sequence_potential_energy_frames' : MetaInfoMap(startpage,
depends=[{'value' : 'NSTEP'}],
lookupdict=self.mddataDict
),
......@@ -747,7 +750,7 @@ def get_updateDictionary(self, defname):
depends=[{'value' : 'EPtot'}],
lookupdict=self.mddataDict
),
'frame_sequence_pressure_frames' : MetaInfoMap(startpage),
'frame_sequence_pressure_frames' : MetaInfoMap(startpage,
depends=[{'value' : 'NSTEP'}],
lookupdict=self.mddataDict
),
......@@ -756,7 +759,7 @@ def get_updateDictionary(self, defname):
depends=[{'value' : 'PRESS'}],
lookupdict=self.mddataDict
),
'frame_sequence_temperature_frames' : MetaInfoMap(startpage),
'frame_sequence_temperature_frames' : MetaInfoMap(startpage,
depends=[{'value' : 'NSTEP'}],
lookupdict=self.mddataDict
),
......@@ -790,38 +793,38 @@ def get_updateDictionary(self, defname):
topology = {
'molecule_to_molecule_type_map' : MetaInfoMap(startpage),
'number_of_topology_atoms' : MetaInfoMap(startpage),
'number_of_topology_atoms' : MetaInfoMap(startpage,
depends=[{'value' : 'NATOM'}],
lookupdict=self.parmDict
),
'number_of_topology_molecules' : MetaInfoMap(startpage),
'topology_force_field_name' : MetaInfoMap(startpage)
'topology_force_field_name' : MetaInfoMap(startpage,
value='Amber Force Field',
),
)
}
atom_list = {
'atom_to_molecule' : MetaInfoMap(startpage,
subfunction=func_atom_to_mol()
#subfunction=func_atom_to_mol()
),
'number_of_electrons' : MetaInfoMap(startpage,
value=0,
),
'atom_labels' : MetaInfoMap(startpage),
subfunction=func_atom_labels()
'atom_labels' : MetaInfoMap(startpage,
#subfunction=func_atom_labels()
),
'atom_positions' : MetaInfoMap(startpage,
subfunction=func_atom_positions()
#subfunction=func_atom_positions()
),
'configuration_periodic_dimensions' : MetaInfoMap(startpage,
subfunction=func_pbc()
#subfunction=func_pbc()
),
'embedded_system' : MetaInfoMap(startpage),
'lattice_vectors' : MetaInfoMap(startpage,
subfunction=func_lat_vec()
#subfunction=func_lat_vec()
),
'simulation_cell' : MetaInfoMap(startpage,
subfunction=func_unitcell()
#subfunction=func_unitcell()
)
}
......@@ -862,15 +865,19 @@ def get_updateDictionary(self, defname):
if defname == 'system':
dictionary = systemDict
elif defname == 'topology':
dictionary = topologyDict
dictionary = topology
elif defname == 'singleconfcalc':
dictionary = singleconfcalc
elif defname == 'frameseq':
dictionary = frameseq
elif defname == 'atom_type':
dictionary = atomtypeDict
dictionary = atom_type
elif defname == 'molecule_type':
dictionary = moltypeDict
elif defname == 'interaction':
dictionary = interDict
dictionary = interaction
elif defname == 'sampling':
dictionary = samplingDict
dictionary = sampling
else:
dictionary = singleconfcalclist
return MapDictionary(dictionary)
......
......@@ -7,7 +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
from AMBERDictionary import set_excludeList, set_includeList, get_updateDictionary
from AMBERCommon import write_mdin
import AMBERCommon as AmberC
import trajectory_reader as TrajRead
......@@ -83,7 +83,6 @@ class AMBERParser(AmberC.AMBERParserBase):
This allows a consistent setting and resetting of the variables,
when the parsing starts and when a section_run closes.
"""
self.metaIntoStorage = None
self.secMethodIndex = None
self.secSystemDescriptionIndex = None
self.inputMethodIndex = None
......@@ -246,17 +245,20 @@ class AMBERParser(AmberC.AMBERParserBase):
# else:
# self.MD = False
# if self.MD:
sampling_method = "molecular_dynamics"
# sampling_method = "molecular_dynamics"
## elif len(self.singleConfCalcs) > 1:
# pass # to do
# else:
# return
# check for geometry optimization convergence
samplingGIndex = backend.openSection("section_sampling_method")
backend.addValue("sampling_method", sampling_method)
backend.closeSection("section_sampling_method", samplingGIndex)
# samplingGIndex = backend.openSection("section_sampling_method")
# 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)
# backend.addValue("frame_sequence_to_sampling_ref", samplingGIndex)
backend.addArrayValues("frame_sequence_local_frames_ref", np.asarray(self.singleConfCalcs))
backend.closeSection("section_frame_sequence", frameSequenceGIndex)
......@@ -380,16 +382,22 @@ class AMBERParser(AmberC.AMBERParserBase):
Writes atomic positions, atom labels and lattice vectors.
"""
# check if control keywords were found or verbatim_writeout is false
#verbatim_writeout = True
# check if control keywords were found
section_sampling_Dict = get_updateDictionary(self, 'sampling')
updateDict = {
'startSection' : [['section_sampling_method']],
#'muteSections' : [['section_system']],
'dictionary' : section_sampling_Dict
}
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)
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:
......@@ -516,6 +524,22 @@ class AMBERParser(AmberC.AMBERParserBase):
print(self.atompositions)
self.atompositions = self.trajectory.iread()
section_frameseq_Dict = get_updateDictionary(self, 'frameseq')
section_singlecalc_Dict = get_updateDictionary(self, 'singleconfcalc')
section_frameseq_single_Dict = section_frameseq_Dict
section_frameseq_single_Dict.update(section_singlecalc_Dict)
updateDict = {
'startSection' : [
['section_single_configuration_calculaion'],
['section_frame_sequence']],
'muteSections' : [['section_method']],
'dictionary' : section_frameseq_single_Dict
}
self.metaStorage.update(updateDict)
self.metaStorage.updateBackend(backend,
startsection=['section_frame_sequence'],
autoopenclose=False)
def setStartingPointCalculation(self, parser):
backend = parser.backend
backend.openSection('section_calculation_to_calculation_refs')
......@@ -526,7 +550,7 @@ class AMBERParser(AmberC.AMBERParserBase):
return None
def check_namelist_store(self, parser, lastLine, stopOnMatchRe, quitOnMatchRe,
metaNameStart, matchNameList, onlyCaseSensitive, stopOnFirstLine):
metaNameStart, matchNameList, matchNameDict, onlyCaseSensitive, stopOnFirstLine):
stopOnMatch = False
if stopOnMatchRe.findall(lastLine):
stopOnMatch = True
......@@ -561,11 +585,13 @@ class AMBERParser(AmberC.AMBERParserBase):
if k in list(parser.lastMatch.keys()):
parser.lastMatch[k]=v
else:
parser.backend.addValue(k, v)
matchNameDict[k].value=v
matchNameDict[k].activeInfo=True
#parser.backend.addValue(k, v)
return False
def adHoc_read_namelist_stop_parsing(self, parser, stopOnMatchStr, quitOnMatchStr,
metaNameStart, matchNameList, onlyCaseSensitive, stopOnFirstLine):
metaNameStart, matchNameList, matchNameDict, onlyCaseSensitive, stopOnFirstLine):
# currentContext = parser.context[len(parser.context) - 1]
# currentMatcherId = currentContext.compiledMatcher.matcher.index.
lastLine = parser.fIn.fInLine
......@@ -579,7 +605,7 @@ class AMBERParser(AmberC.AMBERParserBase):
if self.check_namelist_store(parser, lastLine,
stopOnMatchRe, quitOnMatchRe,
metaNameStart, matchNameList,
onlyCaseSensitive,
matchNameDict, onlyCaseSensitive,
stopOnFirstLine) is not True:
while True:
# lastLine = parser.fIn.readline()
......@@ -596,7 +622,7 @@ class AMBERParser(AmberC.AMBERParserBase):
if self.check_namelist_store(parser, lastLine,
stopOnMatchRe, quitOnMatchRe,
metaNameStart, matchNameList,
onlyCaseSensitive,
matchNameDict, onlyCaseSensitive,
stopOnFirstLine):
break
else:
......@@ -626,6 +652,7 @@ class AMBERParser(AmberC.AMBERParserBase):
quitOnMatchStr=None,
metaNameStart="x_amber_mdin_",
matchNameList=cntrlNameList,
matchNameDict=self.cntrlDict,
onlyCaseSensitive=True,
stopOnFirstLine=True)
)
......@@ -644,6 +671,7 @@ class AMBERParser(AmberC.AMBERParserBase):
quitOnMatchStr=None,
metaNameStart="x_amber_mdin_",
matchNameList=wtNameList,
matchNameDict=self.wtDict,
onlyCaseSensitive=False,
stopOnFirstLine=True)
)
......@@ -662,6 +690,7 @@ class AMBERParser(AmberC.AMBERParserBase):
quitOnMatchStr=None,
metaNameStart="x_amber_mdin_",
matchNameList=ewaldNameList,
matchNameDict=self.ewaldDict,
onlyCaseSensitive=True,
stopOnFirstLine=True)
)
......@@ -680,6 +709,7 @@ class AMBERParser(AmberC.AMBERParserBase):
quitOnMatchStr=None,
metaNameStart="x_amber_mdin_",
matchNameList=qmmmNameList,
matchNameDict=self.qmmmDict,
onlyCaseSensitive=True,
stopOnFirstLine=True)
)
......@@ -705,6 +735,7 @@ class AMBERParser(AmberC.AMBERParserBase):
quitOnMatchStr=None,
metaNameStart="x_amber_parm_",
matchNameList=parmNameList,
matchNameDict=self.parmDict,
onlyCaseSensitive=True,
stopOnFirstLine=True)
)
......@@ -730,6 +761,7 @@ class AMBERParser(AmberC.AMBERParserBase):
quitOnMatchStr=None,
metaNameStart="x_amber_mdin_",
matchNameList=mdoutNameList,
matchNameDict=newDict,
onlyCaseSensitive=True,
stopOnFirstLine=True)
)
......@@ -839,6 +871,7 @@ class AMBERParser(AmberC.AMBERParserBase):
quitOnMatchStr=r"\s*(?:FINAL\s*RESULTS|A\sV\sE\sR\sA\sG\sE\sS\s*O\sV\sE\sR)",
metaNameStart="x_amber_mdout_",
matchNameList=mddataNameList,
matchNameDict=self.mddataDict,
onlyCaseSensitive=True,
stopOnFirstLine=False)
)
......
import setup_paths
import numpy as np
from nomadcore.unit_conversion.unit_conversion import convert_unit
from contextlib import contextmanager
import logging
import json
import os
......@@ -104,35 +105,35 @@ class Container(object):
def updateBackend(self, backend, startsection=None, autoopenclose=False):
if startsection:
if (self.Name in startsection or
self.Name == startsection):
if self.Name == startsection:
if autoopenclose:
with self.autosection(self.Name):
self.updateBackendValues(self, backend)
with self.autosection(backend, self.Name):
self.updateBackendValues(backend)
else:
self.updateBackendValues(self, backend)
self.updateBackendValues(backend)
else:
if self.Containers:
for module in self.Containers:
module.updateBackend(backend, startsection, autoopenclose)
else:
if autoopenclose:
with self.autosection(self.Name):
self.updateBackendValues(self, backend)
with self.autosection(backend, self.Name):
self.updateBackendValues(backend)
else:
self.updateBackendValues(self, backend)
self.updateBackendValues(backend)
def autosection(self, sectionname):
self.opensection(sectionname)
@contextmanager
def autosection(self, backend, name):
self.gid = backend.openSection(name)
yield self.gid
self.closesection(sectionname)
backend.closeSection(name, self.gid)
def opensection(self, backend, sectionname):
self.gid = backend.openSection(sectionname)
def opensection(self, backend, name):
self.gid = backend.openSection(name)
yield self.gid
def closesection(self, backend, sectionname):
backend.closeSection(sectionname, self.gid)
def closesection(self, backend, name):
backend.closeSection(name, self.gid)
def fetchAttr(self, resdict):
for item in resdict:
......@@ -151,7 +152,7 @@ class Container(object):
def updateBackendValues(self, backend):
if self.Storage:
self.updateBackendStorage()
self.updateBackendStorage(backend)
self.Active = False
if self.Containers:
for module in self.Containers:
......@@ -197,25 +198,25 @@ class Container(object):
updateValue = None
if "depends" in item:
if "lookupdict" in item:
if "test" in item["depends"]:
updateValue, localdict = checkTestsDicts(item, localdict)
elif 'assign' in item["depends"]:
updateValue = item["depends"]["assign"]
elif 'value' in item["depends"]:
itemdepval = item["depends"]['value']
if "test" in item["depends"][0]:
updateValue, localdict = self.checkTestsDicts(item, localdict)
elif 'assign' in item["depends"][0]:
updateValue = item["depends"][0]["assign"]
elif 'value' in item["depends"][0]:
itemdepval = item["depends"][0]['value']
if itemdepval in localdict:
checkval = localdict[itemdepval]
else:
accessName, checkval = findNameInLookupDict(itemdepval, item["lookupdict"])
accessName, checkval = self.findNameInLookupDict(itemdepval, item["lookupdict"])
localdict.update({itemdepval : checkval})
updateValue = checkval
else:
if "test" in item["depends"]:
updateValue, localdict = checkTestsAttr(item, localdict)
if 'assign' in item["depends"]:
updateValue = item["depends"]["assign"]
elif 'value' in item["depends"]:
itemdepval = item["depends"]['value']
if "test" in item["depends"][0]:
updateValue, localdict = self.checkTestsAttr(item, localdict)
if 'assign' in item["depends"][0]:
updateValue = item["depends"][0]["assign"]
elif 'value' in item["depends"][0]:
itemdepval = item["depends"][0]['value']
if itemdepval in localdict:
checkval = localdict[itemdepval]
else:
......@@ -231,18 +232,17 @@ class Container(object):
return updateValue, localdict
def checkTestsDicts(self, item, localdict):
for tests in item["depends"]:
depdict = item["depends"][tests]
for deptests in depdict["test"]:
depmeet = 0
for deptest in deptests:
if deptest[0] in localdict:
checkval = localdict[deptest[0]]
else:
accessName, checkval = findNameInLookupDict(deptest[0], item.lookupdict)
localdict.update({deptest[0] : checkval})
if eval(str(checkval) + deptest[1]):
depmeet += 1
for depdict in item["depends"]:
deptests = depdict["test"]
depmeet = 0
for deptest in deptests:
if deptest[0] in localdict:
checkval = localdict[deptest[0]]
else:
accessName, checkval = self.findNameInLookupDict(deptest[0], item.lookupdict)
localdict.update({deptest[0] : checkval})
if eval(str(checkval) + deptest[1]):
depmeet += 1
if depmeet == len(deptests):
if 'assign' in depdict:
return depdict['assign'], localdict
......@@ -250,14 +250,15 @@ class Container(object):
if depdict['value'] in localdict:
checkval = localdict[depdict['value']]
else:
accessName, checkval = findNameInLookupDict(depdict['value'], item.lookupdict)
accessName, checkval = self.findNameInLookupDict(depdict['value'],
item.lookupdict)
localdict.update({depdict['value'] : checkval})
return checkval, localdict
return None, localdict
def checkTestsAttr(self, item, localdict):
for tests in item["depends"]:
depdict = item["depends"][tests]
for depdict in item["depends"]:
#depdict = item["depends"][tests]
for deptests in depdict["test"]:
depmeet = 0
for deptest in deptests:
......@@ -305,19 +306,31 @@ class Container(object):
def accumulateDict(self, checkDict):
localdict = {}
for itemk in checkDict:
if itemk in self.Storage.__dict__:
itemv = checkDict[itemk]
updateValue, localdict = self.checkUpdateValue(itemv, localdict)
if updateValue:
itemv = checkDict[itemk]
updateValue, localdict = self.checkUpdateValue(itemv, localdict)
if updateValue:
if itemk in self.Storage.__dict__:
self.Storage.__dict__[itemk]["val"] = updateValue
self.Storage.__dict__[itemk]["act"] = True
self.Active = True
if "valueSize" in itemv:
if "sizeMetaName" in itemv:
self.Storage.__dict__[itemv["sizeMetaName"]] = itemv["valueSize"]
if "unitconverter" in itemv:
newValue = itemv["unitconverter"](self, itemv)
self.Storage.__dict__[itemk["val"]] = newvalue
elif (itemk.startswith('x_') and
itemv.activeSection == self.Name):
attrvalues = {
'act' : True,
'val' : updateValue,
'kind': None,
'dtyp': "C",
'unit': None,
'size': [],
'refs': None
}
self.Storage.__dict__.update({itemk : attrvalues})
self.Active = True
if "valueSize" in itemv:
if "sizeMetaName" in itemv:
self.Storage.__dict__[itemv["sizeMetaName"]] = itemv["valueSize"]
if "unitconverter" in itemv:
newValue = itemv["unitconverter"](self, itemv)
self.Storage.__dict__[itemk["val"]] = newvalue
def __str__(self, caller=None, decorate='', color=None, printactive=None, onlynames=None):
string = ''
......
Supports Markdown
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