diff --git a/parser/parser-amber/AMBERDictionary.py b/parser/parser-amber/AMBERDictionary.py index 7e721ec4e34dea82b7866daa97985c92ffc0af48..b7514213f15ca379547e6e8071c3ac32429ceb81 100644 --- a/parser/parser-amber/AMBERDictionary.py +++ b/parser/parser-amber/AMBERDictionary.py @@ -25,6 +25,7 @@ class MetaInfoMap(dict): lookupdict=None subfunction=None activeSections=None + autoSections=False def __init__(self, *args, **kwargs): super(MetaInfoMap, self).__init__(*args, **kwargs) @@ -163,6 +164,10 @@ class MapDictionary(dict): def metaNameConverter(keyName): newName = keyName.lower().replace(" ", "").replace("-", "") + newName = newName.replace("(", "").replace(")", "") + newName = newName.replace("[", "").replace("]", "") + newName = newName.replace(",", "").replace(".", "") + newName = newName.replace("\\", "").replace("/", "") return newName def get_fileListDict(): @@ -340,9 +345,9 @@ def get_nameListDict(deflist): 'ew_type' : MetaInfoMap(startpage, defaultValue=0), 'dsum_tol' : MetaInfoMap(startpage, defaultValue=1.0E-5), 'rsum_tol' : MetaInfoMap(startpage, defaultValue=5.0E-5), - 'mlimit(1)' : MetaInfoMap(startpage), - 'mlimit(2)' : MetaInfoMap(startpage), - 'mlimit(3)' : MetaInfoMap(startpage), + 'mlimit\(1\)' : MetaInfoMap(startpage), + 'mlimit\(2\)' : MetaInfoMap(startpage), + 'mlimit\(3\)' : MetaInfoMap(startpage), 'ew_coeff' : MetaInfoMap(startpage), 'nbflag' : MetaInfoMap(startpage, defaultValue=1), 'skinnb' : MetaInfoMap(startpage, defaultValue=2.0), @@ -514,8 +519,8 @@ def get_nameListDict(deflist): }) mddatalist = { 'NSTEP' : MetaInfoMap(startpage), - 'TIME' : MetaInfoMap(startpage), - 'TEMP' : MetaInfoMap(startpage), + 'TIME\(PS\)' : MetaInfoMap(startpage), + 'TEMP\(K\)' : MetaInfoMap(startpage), 'PRESS' : MetaInfoMap(startpage), 'Etot' : MetaInfoMap(startpage), 'EKtot' : MetaInfoMap(startpage), @@ -653,6 +658,27 @@ def get_updateDictionary(self, defname): 'assign' : 'Monte Carlo barostat'} ], lookupdict=self.cntrlDict, + #autoSections=True, + activeSections=['settings_barostat'] + ), + 'x_amber_barostat_target_pressure' : MetaInfoMap(startpage, + depends=[ + {'test' : [['imin', '== 0'], + ['ntp', '!= 0']], + 'value' : 'pres0'} + ], + lookupdict=self.cntrlDict, + #autoSections=True, + activeSections=['settings_barostat'] + ), + 'x_amber_barostat_tau' : MetaInfoMap(startpage, + depends=[ + {'test' : [['imin', '== 0'], + ['ntp', '!= 0']], + 'value' : 'taup'} + ], + lookupdict=self.cntrlDict, + #autoSections=True, activeSections=['settings_barostat'] ), 'x_amber_integrator_type' : MetaInfoMap(startpage, @@ -663,6 +689,22 @@ def get_updateDictionary(self, defname): 'assign' : 'minimization'} ], lookupdict=self.cntrlDict, + #autoSections=True, + activeSections=['settings_integrator'] + ), + 'x_amber_integrator_dt' : MetaInfoMap(startpage, + depends=[ + {'test' : [['imin', '== 0']], + 'value' : 'dt'} + ], + lookupdict=self.cntrlDict, + #autoSections=True, + activeSections=['settings_integrator'] + ), + 'x_amber_number_of_steps_requested' : MetaInfoMap(startpage, + depends=[{'value' : 'nstlim'}], + lookupdict=self.cntrlDict, + #autoSections=True, activeSections=['settings_integrator'] ), 'x_amber_thermostat_type' : MetaInfoMap(startpage, @@ -679,8 +721,53 @@ def get_updateDictionary(self, defname): 'assign' : 'RESPA Stochastic Isokinetic Nose-Hoover'} ], lookupdict=self.cntrlDict, + #autoSections=True, + activeSections=['settings_thermostat'] + ), + 'x_amber_thermostat_target_temperature' : MetaInfoMap(startpage, + depends=[ + {'test' : [['imin', '== 0'], ['ntt', '> 0']], + 'value' : 'temp0'} + ], + lookupdict=self.cntrlDict, + #autoSections=True, + activeSections=['settings_thermostat'] + ), + 'x_amber_thermostat_tau' : MetaInfoMap(startpage, + depends=[ + {'test' : [['imin', '== 0'], ['ntt', '== 1']], + 'value' : 'tautp'}, + {'test' : [['imin', '== 0'], ['ntt', '== 2']], + 'value' : 'tautp'}, + {'test' : [['imin', '== 0'], ['ntt', '== 9']], + 'value' : 'gamma_ln'}, + {'test' : [['imin', '== 0'], ['ntt', '== 10']], + 'value' : 'gamma_ln'}, + ], + lookupdict=self.cntrlDict, + #autoSections=True, + activeSections=['settings_thermostat'] + ), + 'x_amber_langevin_gamma' : MetaInfoMap(startpage, + depends=[ + {'test' : [['imin', '== 0'], ['ntt', '== 3']], + 'value' : 'gamma_ln'} + ], + lookupdict=self.cntrlDict, + #autoSections=True, activeSections=['settings_thermostat'] ), + 'x_amber_periodicity_type' : MetaInfoMap(startpage, + depends=[ + {'test' : [['ntb', '== 0']], + 'assign' : 'no periodic boundaries'}, + {'test' : [['ntb', '> 0']], + 'assign' : 'periodic boundaries'} + ], + lookupdict=self.cntrlDict, + #autoSections=True, + activeSections=['settings_thermostat'] + ) } singleconfcalc = { @@ -689,10 +776,11 @@ def get_updateDictionary(self, defname): # lookupdict=self.mddataDict # ), 'energy_correction_entropy' : MetaInfoMap(startpage), - 'energy_current' : MetaInfoMap(startpage, - depends=[{'value' : 'Etot'}], - lookupdict=self.mddataDict - ), + #'energy_current' : MetaInfoMap(startpage, + # depends=[{'value' : 'EPtot'}], + # lookupdict=self.mddataDict + # ), + 'energy_current' : MetaInfoMap(startpage), 'energy_electrostatic' : MetaInfoMap(startpage, depends=[{'value' : 'EELEC'}], lookupdict=self.mddataDict @@ -700,7 +788,7 @@ def get_updateDictionary(self, defname): 'energy_free_per_atom' : MetaInfoMap(startpage), 'energy_free' : MetaInfoMap(startpage), 'energy_method_current' : MetaInfoMap(startpage, - depends=[{'assign' : 'Amber Force Field'}], + depends=[{'assign' : 'Force Field'}], lookupdict=self.mddataDict ), 'energy_T0_per_atom' : MetaInfoMap(startpage), @@ -710,7 +798,6 @@ def get_updateDictionary(self, defname): depends=[{'value' : 'Etot'}], lookupdict=self.mddataDict ), - 'energy_type_van_der_Waals' : MetaInfoMap(startpage), 'hessian_matrix' : MetaInfoMap(startpage), 'single_configuration_calculation_converged' : MetaInfoMap(startpage), 'single_configuration_calculation_to_system_ref' : MetaInfoMap(startpage), @@ -725,6 +812,15 @@ def get_updateDictionary(self, defname): 'stress_tensor_kind' : MetaInfoMap(startpage), 'stress_tensor_value' : MetaInfoMap(startpage) } + + singlevdw = { + 'energy_van_der_Waals_value' : MetaInfoMap(startpage, + depends=[{'value' : 'VDWAALS'}], + lookupdict=self.mddataDict, + #autoSections=True, + activeSections=['section_energy_van_der_Waals'] + ), + } frameseq = { 'frame_sequence_conserved_quantity_frames' : MetaInfoMap(startpage, @@ -772,11 +868,11 @@ def get_updateDictionary(self, defname): ), 'frame_sequence_temperature_stats' : MetaInfoMap(startpage), 'frame_sequence_temperature' : MetaInfoMap(startpage, - depends=[{'store' : 'TEMP'}], + depends=[{'store' : 'TEMP\(K\)'}], lookupdict=self.mddataDict ), 'frame_sequence_time' : MetaInfoMap(startpage, - depends=[{'store' : 'TIME'}], + depends=[{'store' : 'TIME\(PS\)'}], lookupdict=self.mddataDict ), 'x_amber_frame_sequence_volume_frames' : MetaInfoMap(startpage, @@ -796,13 +892,51 @@ def get_updateDictionary(self, defname): lookupdict=self.mddataDict ), 'frame_sequence_to_sampling_ref' : MetaInfoMap(startpage), - 'geometry_optimization_converged' : MetaInfoMap(startpage), - 'number_of_conserved_quantity_evaluations_in_sequence' : MetaInfoMap(startpage), - 'number_of_frames_in_sequence' : MetaInfoMap(startpage), - 'number_of_kinetic_energies_in_sequence' : MetaInfoMap(startpage), - 'number_of_potential_energies_in_sequence' : MetaInfoMap(startpage), - 'number_of_pressure_evaluations_in_sequence' : MetaInfoMap(startpage), - 'number_of_temperatures_in_sequence' : MetaInfoMap(startpage), + 'geometry_optimization_converged' : MetaInfoMap(startpage, + value=self.minConverged + ), + 'number_of_conserved_quantity_evaluations_in_sequence' : MetaInfoMap(startpage, + value=len([ + item for item in self.metaStorage.fetchAttr( + {'frame_sequence_conserved_quantity_frames' : None} + )['frame_sequence_conserved_quantity_frames'] + ]) + ), + 'number_of_frames_in_sequence' : MetaInfoMap(startpage, + value=len([ + item for item in self.metaStorage.fetchAttr( + {'frame_sequence_potential_energy_frames' : None} + )['frame_sequence_potential_energy_frames'] + ]) + ), + 'number_of_kinetic_energies_in_sequence' : MetaInfoMap(startpage, + value=len([ + item for item in self.metaStorage.fetchAttr( + {'frame_sequence_kinetic_energy_frames' : None} + )['frame_sequence_kinetic_energy_frames'] + ]) + ), + 'number_of_potential_energies_in_sequence' : MetaInfoMap(startpage, + value=len([ + item for item in self.metaStorage.fetchAttr( + {'frame_sequence_potential_energy_frames' : None} + )['frame_sequence_potential_energy_frames'] + ]) + ), + 'number_of_pressure_evaluations_in_sequence' : MetaInfoMap(startpage, + value=len([ + item for item in self.metaStorage.fetchAttr( + {'frame_sequence_pressure_frames' : None} + )['frame_sequence_pressure_frames'] + ]) + ), + 'number_of_temperatures_in_sequence' : MetaInfoMap(startpage, + value=len([ + item for item in self.metaStorage.fetchAttr( + {'frame_sequence_temperature_frames' : None} + )['frame_sequence_temperature_frames'] + ]) + ), 'previous_sequence_ref' : MetaInfoMap(startpage) } @@ -893,6 +1027,8 @@ def get_updateDictionary(self, defname): dictionary = interaction elif defname == 'sampling': dictionary = sampling + elif defname == 'singlevdw': + dictionary = singlevdw else: dictionary = singleconfcalclist return MapDictionary(dictionary) @@ -907,6 +1043,7 @@ def set_excludeList(self): 'x_amber_mdin_verbatim_writeout', 'x_amber_dumm_text', 'x_amber_dummy', + 'x_amber_mdin_wt' ] excludelist.extend(['x_amber_mdin_file_%s' % fileNL.lower() for fileNL in self.fileDict.keys()]) excludelist.extend(['x_amber_mdin_%s' % cntrlNL.lower() for cntrlNL in self.cntrlDict.keys()]) @@ -920,9 +1057,7 @@ def set_includeList(): Returns: the list of names """ - includelist = [ - 'x_amber_mdin_wt' - ] + includelist = [] return includelist def getList_MetaStrInDict(sourceDict): @@ -940,8 +1075,8 @@ def getDict_MetaStrInDict(sourceDict): used as the keywords in the parsing. """ newDict = {} - for item in sourceDict: - newDict.update({sourceDict[item].matchStr : sourceDict[item]}) + for key, value in sourceDict.items(): + newDict.update({sourceDict[key].matchStr : key}) return newDict diff --git a/parser/parser-amber/AMBERParser.py b/parser/parser-amber/AMBERParser.py index 26e6d64003cc8f1cff8bc2aa299f0de2a06997c5..eaa4fea4a9ab7915194fb4ff916a0bf5f4598d04 100644 --- a/parser/parser-amber/AMBERParser.py +++ b/parser/parser-amber/AMBERParser.py @@ -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, get_updateDictionary, getList_MetaStrInDict +from AMBERDictionary import set_excludeList, set_includeList, get_updateDictionary, getList_MetaStrInDict, getDict_MetaStrInDict import AMBERCommon as AmberC import trajectory_reader as TrajRead import logging @@ -37,7 +37,6 @@ class AMBERParser(AmberC.AMBERParserBase): def __init__(self): # dictionary of energy values, which are tracked between SCF iterations and written after convergence self.totalEnergyList = { - 'electronic_kinetic_energy': None, 'energy_electrostatic': None, 'energy_total_T0_per_atom': None, 'energy_free_per_atom': None, @@ -49,8 +48,9 @@ class AMBERParser(AmberC.AMBERParserBase): 'x_amber_trajectory_file_detect': CachingLevel.Cache, 'x_amber_geometry_optimization_cdetect': CachingLevel.Cache, 'x_amber_mdin_finline': CachingLevel.Ignore, + 'x_amber_mdin_wt': CachingLevel.Ignore, 'x_amber_single_configuration_calculation_detect': CachingLevel.Cache, - 'x_amber_single_configuration_calculation': CachingLevel.Cache, + #'x_amber_single_configuration_calculation': CachingLevel.Cache, } for name in self.metaInfoEnv.infoKinds: metaInfo = self.metaInfoEnv.infoKinds[name] @@ -82,9 +82,11 @@ 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.secMethodIndex = None - self.secSystemDescriptionIndex = None - self.samplingGIndex = None + self.secMethodGIndex = None + self.secSystemGIndex = None + self.secSamplingGIndex = None + self.secSingleGIndex = None + self.secVDWGIndex = None self.inputMethodIndex = None self.mainMethodIndex = None self.mainCalcIndex = None @@ -101,7 +103,7 @@ class AMBERParser(AmberC.AMBERParserBase): # start with -1 since zeroth iteration is the initialization self.mdIterNr = -1 self.singleConfCalcs = [] - self.minConvergence = None + self.minConverged = None self.parsedLogFile = False self.LogSuperContext = None self.forces_raw = [] @@ -192,16 +194,6 @@ class AMBERParser(AmberC.AMBERParserBase): #else: # return False - #def compile_traj_parser(self): - # """Instantiate superContext and construct parser for MD trajactory file. - # """ - # self.trajSuperContext = AMBERmdcrdParser.AMBERmdcrdParserContext(False) - # self.trajParser = AncillaryParser( - # fileDescription = AMBERmdcrdParser.build_AMBERmdcrdFileSimpleMatcher(), - # parser = self.parser, - # cachingLevelForMetaName = AMBERmdcrdParser.get_cachingLevelForMetaName(self.metaInfoEnv, CachingLevel.Ignore), - # superContext = self.trajSuperContext) - def onClose_section_run(self, backend, gIndex, section): """Trigger called when section_run is closed. @@ -253,7 +245,7 @@ class AMBERParser(AmberC.AMBERParserBase): self.metaStorage.updateBackend(backend, startsection=['section_frame_sequence'], autoopenclose=False) - backend.addValue("frame_sequence_to_sampling_ref", self.samplingGIndex) + backend.addValue("frame_sequence_to_sampling_ref", self.secSamplingGIndex) backend.addArrayValues("frame_sequence_local_frames_ref", np.asarray(self.singleConfCalcs)) backend.closeSection("section_frame_sequence", frameSequenceGIndex) @@ -264,15 +256,6 @@ class AMBERParser(AmberC.AMBERParserBase): # """ # self.MD = True -# def check_file_exist(self, k, v, filePath, fileList): -# if k.startswith('x_amber_mdin_file_') and -# : -# -# file_name = os.path.normpath(os.path.join(filePath, v[-1])) -# = os.path.isfile(file_name) -# if self.topoFound: -# self.topoFileName = file_name - def onClose_x_amber_section_input_output_files(self, backend, gIndex, section): """Trigger called when x_amber_section_input_output_files is closed. @@ -304,7 +287,7 @@ class AMBERParser(AmberC.AMBERParserBase): def onOpen_section_method(self, backend, gIndex, section): # keep track of the latest method section - self.secMethodIndex = gIndex + self.secMethodGIndex = gIndex if self.inputMethodIndex is None: self.inputMethodIndex = gIndex else: @@ -361,28 +344,53 @@ class AMBERParser(AmberC.AMBERParserBase): if int(v[-1]) == 1: self.MD = False - def onOpen_section_system(self, backend, gIndex, section): - # keep track of the latest system description section - self.secSystemDescriptionIndex = gIndex + def onOpen_section_sampling_method(self, backend, gIndex, section): + # keep track of the latest sampling description section + self.secSamplingGIndex = gIndex - def onClose_section_system(self, backend, gIndex, section): - """Trigger called when section_system is closed. + def onClose_section_sampling_method(self, backend, gIndex, section): + """Trigger called when section_sampling_method is closed. - Writes atomic positions, atom labels and lattice vectors. + Writes sampling method details for minimization and molecular dynamics. """ - # check if control keywords were found + # check control keywords were found throguh dictionary support section_sampling_Dict = get_updateDictionary(self, 'sampling') updateDict = { 'startSection' : [['section_sampling_method']], #'muteSections' : [['section_system']], 'dictionary' : section_sampling_Dict } - self.samplingGIndex = backend.openSection("section_sampling_method") + #self.secSamplingGIndex = backend.openSection("section_sampling_method") self.metaStorage.update(updateDict) self.metaStorage.updateBackend(backend, startsection=['section_sampling_method'], autoopenclose=False) - backend.closeSection("section_sampling_method", self.samplingGIndex) + #backend.closeSection("section_sampling_method", self.secSamplingGIndex) + + def onOpen_section_system(self, backend, gIndex, section): + # keep track of the latest system description section + self.secSystemGIndex = gIndex + + def onClose_section_system(self, backend, gIndex, section): + """Trigger called when section_system is closed. + + Writes atomic positions, atom labels and lattice vectors. + """ + # 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.secSamplingGIndex = backend.openSection("section_sampling_method") + #self.metaStorage.update(updateDict) + #self.metaStorage.updateBackend(backend, + # startsection=['section_sampling_method'], + # autoopenclose=False) + #backend.closeSection("section_sampling_method", self.secSamplingGIndex) + #self.secMethodGIndex = backend.openSection("section_method") + #backend.closeSection("section_method", self.secMethodGIndex) counter = 0 @@ -401,10 +409,6 @@ class AMBERParser(AmberC.AMBERParserBase): # # default writeout # else: backend.superBackend.addValue(k, v[-1]) - if k.startswith('x_amber_mdin_imin'): -# print("-----IMIN----",k,v) - if int(v[-1]) == 1: - self.MD = False # Write atomic geometry in the case of MD # if not self.MD: @@ -457,9 +461,10 @@ class AMBERParser(AmberC.AMBERParserBase): def onOpen_section_single_configuration_calculation(self, backend, gIndex, section): # write the references to section_method and section_system - backend.addValue('single_configuration_to_calculation_method_ref', self.secMethodIndex) - backend.addValue('single_configuration_calculation_to_system_ref', self.secSystemDescriptionIndex) + backend.addValue('single_configuration_to_calculation_method_ref', self.secMethodGIndex) + backend.addValue('single_configuration_calculation_to_system_ref', self.secSystemGIndex) self.singleConfCalcs.append(gIndex) + self.secSingleGIndex = backend.superBackend.openSection("section_single_configuration_calculation") def onClose_section_single_configuration_calculation(self, backend, gIndex, section): """Trigger called when section_single_configuration_calculation is closed. @@ -489,46 +494,62 @@ class AMBERParser(AmberC.AMBERParserBase): # if self.forces_raw: # # need to transpose array since its shape is [number_of_atoms,3] in the metadata # backend.addArrayValues('atom_forces_free_raw', np.transpose(np.asarray(self.forces_raw))) - # get reference to current section_single_configuration_calculation if trajectory was found in there -# if self.trajFound: -# self.trajRefSingleConfigurationCalculation = gIndex -# self.trajFound = False self.lastCalculationGIndex = gIndex exclude_list = set_excludeList(self) include_list = set_includeList() #for name in self.metaInfoEnv.infoKinds: - # if name.startswith('x_fhi_aims_mdin_'): + # if name.startswith('x_amber_mdin_'): # exclude_list.append(name) - # write settings of aims output from the parsed mdin for k,v in section.simpleValues.items(): if (k.startswith('x_amber_section_single_') or k.startswith('x_amber_mdout_')): - if k in exclude_list and k not in include_list: - continue - # default writeout - else: - backend.superBackend.addValue(k, v[-1]) + backend.superBackend.addValue(k, v[-1]) +# if k in exclude_list and k not in include_list: +# continue +# # default writeout +# else: +# backend.superBackend.addValue(k, v[-1]) + # get reference to current section_single_configuration_calculation if trajectory was found in there if self.atompositions is not None: + self.trajRefSingleConfigurationCalculation = gIndex 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 = { + updateFrameDict = { 'startSection' : [ - ['section_single_configuration_calculation'], ['section_frame_sequence']], 'muteSections' : [['section_method']], - 'dictionary' : section_frameseq_single_Dict + 'dictionary' : section_frameseq_Dict + } + self.metaStorage.update(updateFrameDict) + section_singlevdw_Dict = get_updateDictionary(self, 'singlevdw') + updateDictVDW = { + 'startSection' : [ + ['section_energy_van_der_Waals']], + #'muteSections' : [['section_method']], + 'dictionary' : section_singlevdw_Dict + } + self.secVDWGIndex = backend.superBackend.openSection("section_energy_van_der_Waals") + self.metaStorage.update(updateDictVDW) + self.metaStorage.updateBackend(backend.superBackend, + startsection=['section_energy_van_der_Waals'], + autoopenclose=False) + backend.superBackend.closeSection("section_energy_van_der_Waals", self.secVDWGIndex) + section_singlecalc_Dict = get_updateDictionary(self, 'singleconfcalc') + updateDict = { + 'startSection' : [ + ['section_single_configuration_calculation']], + #'muteSections' : [['section_method']], + 'dictionary' : section_singlecalc_Dict } self.metaStorage.update(updateDict) - singleGIndex = backend.openSection("section_single_configuration_calculation") - self.metaStorage.updateBackend(backend, + #self.secSingleGIndex = backend.openSection("section_single_configuration_calculation") + self.metaStorage.updateBackend(backend.superBackend, startsection=['section_single_configuration_calculation'], autoopenclose=False) - backend.closeSection("section_single_configuration_calculation", singleGIndex) + #backend.closeSection("section_single_configuration_calculation", self.secSingleGIndex) + backend.superBackend.closeSection("section_single_configuration_calculation", self.secSingleGIndex) def setStartingPointCalculation(self, parser): backend = parser.backend @@ -560,8 +581,8 @@ class AMBERParser(AmberC.AMBERParserBase): if self.MD is not True: newLine = parser.fIn.readline() lastLine = ' = '.join([ "%s" % str(line) for line in zip(lastLine, newLine)]) - for cName in matchNameList: - key = metaNameStart + cName.lower().replace(" ", "").replace("-", "") + for cName, key in getDict_MetaStrInDict(matchNameDict).items(): + #key = metaNameStart + cName.lower().replace(" ", "").replace("-", "") reDict={key:value for value in re.compile(r"(?:\s%s|^%s|,%s)\s*=\s*(?:'|\")?(?P<%s>[\-+0-9.a-zA-Z:]+)(?:'|\")?\s*,?" % (cName, cName, cName, key)).findall(lastLine)} @@ -846,6 +867,8 @@ class AMBERParser(AmberC.AMBERParserBase): startReStr=r"\s*(?:NSTEP\s*=|NSTEP\s*ENERGY\s*RMS\s*)", # endReStr=r"\s*(?:FINAL\s*RESULTS|A\sV\sE\sR\sA\sG\sE\sS\s*O\sV\sE\sR)", # sections=['x_amber_section_single_configuration_calculation'], + #sections = ['section_method','section_single_configuration_calculation'], + #sections=['section_single_configuration_calculation', 'section_system'], forwardMatch=True, subMatchers=[ # SM(startReStr=(r"\s*(?:" + @@ -893,10 +916,10 @@ class AMBERParser(AmberC.AMBERParserBase): subFlags=SM.SubFlags.Unordered, subMatchers=fileNameListGroupSubMatcher ), # END SectionMethod - SM(name='SectionTopology', + SM(name='SectionMethod', startReStr=r"\s*Here\s*is\s*the\s*input\s*file:", forwardMatch=True, - sections=['section_system'], + sections=['section_sampling_method'], subMatchers=[ # parse verbatim writeout of mdin file mdinSubMatcher, @@ -904,14 +927,13 @@ class AMBERParser(AmberC.AMBERParserBase): parmSubMatcher, # parse control settings writeout of Amber mdoutSubMatcher - # parse geometry writeout of Amber - #geometryInSubMatcher ]), # END SectionMethod SM(name='SingleConfigurationCalculationWithSystemDescription', startReStr=r"\s*4\.\s*RESULTS", endReStr=r"\s*(?:FINAL\s*RESULTS|A\sV\sE\sR\sA\sG\sE\sS\s*O\sV\sE\sR)", #repeats=True, forwardMatch=True, + #sections=['section_single_configuration_calculation'], subMatchers=[ # the actual section for a single configuration calculation starts here SM(name='SingleConfigurationCalculation', @@ -919,7 +941,9 @@ class AMBERParser(AmberC.AMBERParserBase): # endReStr=r"\s*(?:FINAL\s*RESULTS|A\sV\sE\sR\sA\sG\sE\sS\s*O\sV\sE\sR)", repeats=True, forwardMatch=True, - #sections=['section_method', 'section_single_configuration_calculation'], + #sections=['section_system', 'section_single_configuration_calculation'], + #sections = ['section_method','section_single_configuration_calculation'], + #sections=['section_single_configuration_calculation', 'section_system'], sections=['section_single_configuration_calculation'], subMatchers=[ # MD diff --git a/parser/parser-amber/MetaInfoStorage.py b/parser/parser-amber/MetaInfoStorage.py index 7d7933c1a2d1377547b0d11da6193cad9e7d38a8..3b03be955ac3c2d4e1c4da4fd88c7ec82eba4571 100644 --- a/parser/parser-amber/MetaInfoStorage.py +++ b/parser/parser-amber/MetaInfoStorage.py @@ -196,14 +196,25 @@ class Container(object): # # Check whether depends is supplied in the item. updateValue = None + storeValue = False + if "prefunction" in item: + storeValue, updateValue, item = item.prefunction(item) if "depends" in item: + firstdepend = item["depends"][0] if "lookupdict" in item: - if "test" in item["depends"][0]: + needFetchVal = False + if "test" in firstdepend: 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"] + elif "assign" in firstdepend: + updateValue = firstdepend["assign"] + elif "value" in firstdepend: + itemdepval = firstdepend["value"] + needFetchVal = True + elif "store" in firstdepend: + itemdepval = firstdepend["store"] + needFetchVal = True + storeValue = True + if needFetchVal: if itemdepval in localdict: checkval = localdict[itemdepval] else: @@ -211,12 +222,19 @@ class Container(object): localdict.update({itemdepval : checkval}) updateValue = checkval else: - if "test" in item["depends"][0]: + needFetchVal = False + if "test" in firstdepend: updateValue, localdict = self.checkTestsAttr(item, localdict) - elif "assign" in item["depends"][0]: - updateValue = item["depends"][0]["assign"] - elif "value" in item["depends"][0]: - itemdepval = item["depends"][0]["value"] + elif "assign" in firstdepend: + updateValue = firstdepend["assign"] + elif "value" in firstdepend: + itemdepval = firstdepend["value"] + needFetchVal = True + elif "store" in firstdepend: + itemdepval = firstdepend["store"] + needFetchVal = True + storeValue = True + if needFetchVal: if itemdepval in localdict: checkval = localdict[itemdepval] else: @@ -226,10 +244,12 @@ class Container(object): checkval = attrdict[deptest[0]] updateValue = checkval elif "subfunction" in item: - updateValue = item.subfunction(item) + storeValue, updateValue, item = item.subfunction(item) elif "value" in item: updateValue = item['value'] - return updateValue, localdict + if "postfunction" in item: + storeValue, updateValue, item = item.postfunction(item) + return storeValue, updateValue, localdict def checkTestsDicts(self, item, localdict): for depdict in item["depends"]: @@ -308,10 +328,25 @@ class Container(object): localdict = {} for itemk in checkDict: itemv = checkDict[itemk] - updateValue, localdict = self.checkUpdateValue(itemv, localdict) + storeValue, updateValue, localdict = self.checkUpdateValue(itemv, localdict) if updateValue: if itemk in self.Storage.__dict__: - self.Storage.__dict__[itemk]["val"] = updateValue + if storeValue: + #If we need to store the updated values + if self.Storage.__dict__[itemk]["val"] is None: + #If not initialized, initialize with a list to store + self.Storage.__dict__[itemk]["val"] = [updateValue] + else: + #Append to the stored list if there is a list + if type(self.Storage.__dict__[itemk]["val"]) is list: + self.Storage.__dict__[itemk]["val"].append(updateValue) + else: + #Convert the prevoius update to list and append update + preValue = self.Storage.__dict__[itemk]["val"] + self.Storage.__dict__[itemk]["val"] = [preValue, updateValue] + else: + #No need to store, assign the updated value + self.Storage.__dict__[itemk]["val"] = updateValue self.Storage.__dict__[itemk]["act"] = True elif (itemk.startswith('x_') and itemv.activeSection == self.Name):