diff --git a/parser/parser-qbox/QboxInputParser.py b/parser/parser-qbox/QboxInputParser.py new file mode 100644 index 0000000000000000000000000000000000000000..0fb28bc34f963f6de9b28f148f2fdee175dba241 --- /dev/null +++ b/parser/parser-qbox/QboxInputParser.py @@ -0,0 +1,303 @@ +from builtins import object +import setup_paths +import numpy as np +import nomadcore.ActivateLogging +from nomadcore.caching_backend import CachingLevel +from nomadcore.simple_parser import AncillaryParser, mainFunction +from nomadcore.simple_parser import SimpleMatcher as SM +from QboxCommon import get_metaInfo +import logging, os, re, sys + +############################################################ +# This is the parser for the input file of qbox. +############################################################ + + +############################################################ +###############[1] transfer PARSER CONTEXT ################# +############################################################ +logger = logging.getLogger("nomad.qboxInputParser") + +class QboxInputParserContext(object): + + def __init__(self): + self.functionals = [] + + + def initialize_values(self): + """Initializes the values of certain variables. + + 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.singleConfCalcs = [] + + + def startedParsing(self, fInName, parser): + """Function is called when the parsing starts. + + Get compiled parser, filename and metadata. + + Args: + fInName: The file name on which the current parser is running. + parser: The compiled parser. Is an object of the class SimpleParser in nomadcore.simple_parser.py. + """ + self.parser = parser + self.fName = fInName + # save metadata + self.metaInfoEnv = self.parser.parserBuilder.metaInfoEnv + # allows to reset values if the same superContext is used to parse different files + self.initialize_values() + + + def onClose_section_run(self, backend, gIndex, section): + """Trigger called when section_run is closed. + """ + # reset all variables + self.initialize_values() + # frame sequence + sampling_method = "geometry_optimization" + + 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.addArrayValues("frame_sequence_local_frames_ref", np.asarray(self.singleConfCalcs)) + backend.closeSection("section_frame_sequence", frameSequenceGIndex) + + + + def onClose_x_qbox_section_functionals(self, backend, gIndex, section): + functional_list = section["x_qbox_functional_name"] + + if not functional_list: # default is LDA in qbox + functional = "LDA" + else : + functional = functional_list[-1] # use the xc appeared the last time + + + if functional: + functionalMap = { + "LDA": ["LDA_X", "LDA_C_PZ"], + "VMN": ["LDA_X", "LDA_C_VWN"], + "PBE": ["GGA_X_PBE","GGA_C_PBE"], + "PBE0": ["GGA_X_PBE","GGA_C_PBE"], + "B3LYP": ["HYB_GGA_XC_B3LYP5"] + #need to be extended to add alpha_PBE0 :coefficient of Hartree-Fock exchange in the PBE0 xc functional + } + # Push the functional string into the backend + nomadNames = functionalMap.get(functional) + if not nomadNames: + raise Exception("Unhandled xc functional %s found" % functional) + for name in nomadNames: + s = backend.openSection("section_XC_functionals") + backend.addValue('XC_functional_name', name) + backend.closeSection("section_XC_functionals", s) + + + + + ################################################################### + # (3.4) onClose for geometry and force (section_system) + # todo: maybe we can move the force to onClose_section_single_configuration_calculation in the future. + ################################################################### + def onOpen_section_method(self, backend, gIndex, section): + # keep track of the latest method section + self.secMethodIndex = gIndex + + + def onOpen_section_system(self, backend, gIndex, section): + # keep track of the latest system description section + self.secSystemDescriptionIndex = gIndex + + + def onClose_section_system(self, backend, gIndex, section): + """Trigger called when section_system is closed. + Writes atomic positions, atom labels and lattice vectors. + """ + # keep track of the latest system description section + self.secSystemDescriptionIndex = gIndex + + #------1.atom_positions + atom_pos = [] + for i in ['x', 'y', 'z']: + api = section['x_qbox_geometry_atom_positions_' + i] + if api is not None: + atom_pos.append(api) + if atom_pos: + # need to transpose array since its shape is [number_of_atoms,3] in the metadata + backend.addArrayValues('atom_positions', np.transpose(np.asarray(atom_pos))) + + #------2.atom labels + atom_labels = section['x_qbox_geometry_atom_labels'] + if atom_labels is not None: + backend.addArrayValues('atom_labels', np.asarray(atom_labels)) + + + + #----3. unit_cell + unit_cell = [] + for i in ['x', 'y', 'z']: + uci = section['x_qbox_geometry_lattice_vector_' + i] + if uci is not None: + unit_cell.append(uci) + if unit_cell: + backend.addArrayValues('simulation_cell', np.asarray(unit_cell)) + backend.addArrayValues("configuration_periodic_dimensions", np.ones(3, dtype=bool)) + + + + + def onOpen_section_single_configuration_calculation(self, backend, gIndex, section): + self.singleConfCalcs.append(gIndex) + + def onClose_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) + + + + + + +############################################################# +#################[2] MAIN PARSER STARTS HERE ############### +############################################################# + +def build_QboxInputFileSimpleMatcher(): + """Builds the SimpleMatcher to parse the input file of qbox (*.i) . + + First, several subMatchers are defined, which are then used to piece together + the final SimpleMatcher. + SimpleMatchers are called with 'SM (' as this string has length 4, + which allows nice formating of nested SimpleMatchers in python. + + Returns: + SimpleMatcher that parses input file of qbox. + """ + + + + + #################################################################### + # (2) submatcher for control method that echo INPUT file (section_method) + #################################################################### + calculationMethodSubMatcher = SM(name = 'calculationMethods', + startReStr = "", + #endReStr = r"\s*", + repeats = True, + sections = ["section_method"], + subMatchers = [ + + + #--------k_point------------- + SM(r"\s*kpoint add\s+(?P<x_qbox_k_point_x>[-+0-9.eEdD]+)\s+(?P<x_qbox_k_point_y>[-+0-9.eEdD]+)\s+(?P<x_qbox_k_point_z>[-+0-9.eEdD]+)\s+(?P<x_qbox_k_point_weight>[-+0-9.eEdD]+)\s*",repeats = True), + + #--------set method--------- + SM(r"\s*set\s+ecut\s+(?P<x_qbox_ecut__rydberg>[0-9.]+)\s*"), + SM(r"\s*set\s+wf_dyn\s+(?P<x_qbox_wf_dyn>[A-Za-z0-9]+)\s*"), + SM(r"\s*set\s+atoms_dyn\s+(?P<x_qbox_atoms_dyn>[A-Za-z0-9]+)\s*"), + SM(r"\s*set\s+cell_dyn\s+(?P<x_qbox_cell_dyn>[A-Za-z0-9]+)\s*"), + + #--------set xc--------- + SM(name = "qboxXC", + startReStr = r"\s*set\s+xc\s+(?P<x_qbox_functional_name>[A-Za-z0-9]+)\s*", + sections = ["x_qbox_section_functionals"] + ), + + #-------set efield--------- + SM (r"\s*set\s+e_field\s*(?P<x_qbox_efield_x>[-+0-9.]+)\s+(?P<x_qbox_efield_y>[-+0-9.]+)\s+(?P<x_qbox_efield_z>[-+0-9.]+)\s*",repeats = True) + #???both this version adn qbox_section_efield version could not give mather for efield, need to check. + ]) + + + + + + + ######################################## + # return main Parser + ######################################## + return SM (name = 'Root', + + startReStr = "", + forwardMatch = True, + weak = True, + subMatchers = [ + + #============================================================================= + # read OUPUT file *.r, the method part comes from INPUT file *.i, so we + # do not need to parser INPUT file, the OUTPUT file contains all information + #============================================================================= + SM (name = 'NewRun', + startReStr = r"", + #endReStr = r"\s*<end_time", + repeats = False, + required = True, + forwardMatch = True, + fixedStartValues={'program_name': 'qbox', 'program_basis_set_type': 'plane waves'}, + sections = ['section_run'], + subMatchers = [ + + #-----------input method--------------------- + calculationMethodSubMatcher + + ]) # CLOSING SM NewRun + + + ]) # END Root + +def get_cachingLevelForMetaName(metaInfoEnv): + """Sets the caching level for the metadata. + + Args: + metaInfoEnv: metadata which is an object of the class InfoKindEnv in nomadcore.local_meta_info.py. + + Returns: + Dictionary with metaname as key and caching level as value. + """ + # manually adjust caching of metadata + cachingLevelForMetaName = { + 'eigenvalues_values': CachingLevel.Cache, + 'eigenvalues_kpoints':CachingLevel.Cache + } + + # Set caching for temparary storage variables + for name in metaInfoEnv.infoKinds: + if ( name.startswith('x_qbox_store_') + or name.startswith('x_qbox_cell_')): + cachingLevelForMetaName[name] = CachingLevel.Cache + return cachingLevelForMetaName + + + + +def main(): + """Main function. + + Set up everything for the parsing of the qbox main file and run the parsing. + """ + # get main file description + QboxInputFileSimpleMatcher = build_QboxInputFileSimpleMatcher() + # loading metadata from nomad-meta-info/meta_info/nomad_meta_info/qbox.nomadmetainfo.json + metaInfoPath = os.path.normpath(os.path.join(os.path.dirname(os.path.abspath(__file__)), "../../../../nomad-meta-info/meta_info/nomad_meta_info/qbox.nomadmetainfo.json")) + metaInfoEnv = get_metaInfo(metaInfoPath) + # set parser info + parserInfo = {'name':'qbox-input-parser', 'version': '1.0'} + # get caching level for metadata + cachingLevelForMetaName = get_cachingLevelForMetaName(metaInfoEnv) + # start parsing + mainFunction(mainFileDescription = QboxInputFileSimpleMatcher, + metaInfoEnv = metaInfoEnv, + parserInfo = parserInfo, + cachingLevelForMetaName = cachingLevelForMetaName, + superContext = QboxInputParserContext()) + +if __name__ == "__main__": + main() + diff --git a/parser/parser-qbox/QboxParser.py b/parser/parser-qbox/QboxParser.py index fecf929a3c95436d2f81d7738f213b5d710446bf..be995ead97bbaa5ae5c23d14407c28a79cbf9364 100644 --- a/parser/parser-qbox/QboxParser.py +++ b/parser/parser-qbox/QboxParser.py @@ -10,7 +10,7 @@ import QboxXMLParser import logging, os, re, sys ############################################################ -# This is the parser for the main file of qbox. +# This is the parser for the main file of qbox (for the output file *.r) . ############################################################ @@ -74,11 +74,11 @@ class QboxParserContext(object): ################################################################# # (2) onClose for INPUT control (section_method) ################################################################# - def onClose_qbox_section_xml_file(self, backend, gIndex, section): + def onClose_x_qbox_section_xml_file(self, backend, gIndex, section): - qbox_loading_xml_file_list = section['qbox_loading_xml_file'] + x_qbox_loading_xml_file_list = section['x_qbox_loading_xml_file'] - xml_file = qbox_loading_xml_file_list[-1] + xml_file = x_qbox_loading_xml_file_list[-1] if xml_file is not None: logger.warning("This output showed this calculation need to load xml file, so we need this xml file ('%s') to read geometry information" % os.path.normpath(xml_file) ) @@ -99,8 +99,8 @@ class QboxParserContext(object): logger.warning("Could not find xml file in directory '%s'. " % os.path.dirname(os.path.abspath(self.fName))) - def onClose_qbox_section_functionals(self, backend, gIndex, section): - functional_list = section["qbox_functional_name"] + def onClose_x_qbox_section_functionals(self, backend, gIndex, section): + functional_list = section["x_qbox_functional_name"] if not functional_list: # default is LDA in qbox functional = "LDA" @@ -195,7 +195,7 @@ class QboxParserContext(object): #------1.atom_positions atom_pos = [] for i in ['x', 'y', 'z']: - api = section['qbox_geometry_atom_positions_' + i] + api = section['x_qbox_geometry_atom_positions_' + i] if api is not None: atom_pos.append(api) if atom_pos: @@ -203,14 +203,14 @@ class QboxParserContext(object): backend.addArrayValues('atom_positions', np.transpose(np.asarray(atom_pos))) #------2.atom labels - atom_labels = section['qbox_geometry_atom_labels'] + atom_labels = section['x_qbox_geometry_atom_labels'] if atom_labels is not None: backend.addArrayValues('atom_labels', np.asarray(atom_labels)) #------3.atom force atom_force = [] for i in ['x', 'y', 'z']: - api = section['qbox_atom_force_' + i] + api = section['x_qbox_atom_force_' + i] if api is not None: atom_force.append(api) if atom_force: @@ -221,7 +221,7 @@ class QboxParserContext(object): #----4. unit_cell unit_cell = [] for i in ['x', 'y', 'z']: - uci = section['qbox_geometry_lattice_vector_' + i] + uci = section['x_qbox_geometry_lattice_vector_' + i] if uci is not None: unit_cell.append(uci) if unit_cell: @@ -240,15 +240,15 @@ class QboxParserContext(object): backend.addValue('single_configuration_calculation_to_system_ref', self.secSystemDescriptionIndex) - def onClose_qbox_section_stress_tensor(self, backend, gIndex, section): - qbox_stress_tensor = [] + def onClose_x_qbox_section_stress_tensor(self, backend, gIndex, section): + x_qbox_stress_tensor = [] for i in ['xx', 'yy', 'zz', 'xy', 'yz', 'xz']: - api = section['qbox_stress_tensor_' + i] + api = section['x_qbox_stress_tensor_' + i] if api is not None: - qbox_stress_tensor.append(api) - if qbox_stress_tensor: + x_qbox_stress_tensor.append(api) + if x_qbox_stress_tensor: # need to transpose array since its shape is [number_of_atoms,3] in the metadata - backend.addArrayValues('stress_tensor', np.transpose(np.asarray(qbox_stress_tensor))) + backend.addArrayValues('stress_tensor', np.transpose(np.asarray(x_qbox_stress_tensor))) @@ -276,14 +276,14 @@ def build_QboxMainFileSimpleMatcher(): ##################################################################### # (1) submatcher for header - #note: we add qbox_section_functionals here because we want to add + #note: we add x_qbox_section_functionals here because we want to add # a default LDA here even 'set xc' is not shown in *.i file. ##################################################################### headerSubMatcher = SM(name = 'ProgramHeader', startReStr = r"\s*I qbox\s+(?P<program_version>[0-9.]+)", - sections = ["qbox_section_functionals"], + sections = ["x_qbox_section_functionals"], subMatchers = [ - SM(r"\s*<nodename>\s+(?P<qbox_nodename>[a-zA-Z0-9.-]+)\s+</nodename>") + SM(r"\s*<nodename>\s+(?P<x_qbox_nodename>[a-zA-Z0-9.-]+)\s+</nodename>") ]) #################################################################### @@ -313,28 +313,28 @@ def build_QboxMainFileSimpleMatcher(): SM(name = "qboxXMLfile", startReStr = r"\s*LoadCmd", forwardMatch = True, #use this or not like qboxXC - sections = ["qbox_section_xml_file"], + sections = ["x_qbox_section_xml_file"], subMatchers = [ - SM(r"\s*LoadCmd:\s*loading from\s+(?P<qbox_loading_xml_file>[A-Za-z0-9./-_]+)"), + SM(r"\s*LoadCmd:\s*loading from\s+(?P<x_qbox_loading_xml_file>[A-Za-z0-9./-_]+)"), ]), # CLOSING qbox_section_xml_file #--------k_point------------- - SM(r"\s*\[qbox\]\s+<cmd>\s*kpoint add\s+(?P<qbox_k_point_x>[-+0-9.eEdD]+)\s+(?P<qbox_k_point_y>[-+0-9.eEdD]+)\s+(?P<qbox_k_point_z>[-+0-9.eEdD]+)\s+(?P<qbox_k_point_weight>[-+0-9.eEdD]+)\s*</cmd>",repeats = True), + SM(r"\s*\[qbox\]\s+<cmd>\s*kpoint add\s+(?P<x_qbox_k_point_x>[-+0-9.eEdD]+)\s+(?P<x_qbox_k_point_y>[-+0-9.eEdD]+)\s+(?P<x_qbox_k_point_z>[-+0-9.eEdD]+)\s+(?P<x_qbox_k_point_weight>[-+0-9.eEdD]+)\s*</cmd>",repeats = True), #--------set method--------- - SM(r"\s*\[qbox\]\s*\[qbox\]\s*<cmd>\s*set\s+ecut\s+(?P<qbox_ecut__rydberg>[0-9.]+)\s*</cmd>"), - SM(r"\s*\[qbox\]\s+<cmd>\s*set\s+wf_dyn\s+(?P<qbox_wf_dyn>[A-Za-z0-9]+)\s*</cmd>"), - SM(r"\s*\[qbox\]\s+<cmd>\s*set\s+atoms_dyn\s+(?P<qbox_atoms_dyn>[A-Za-z0-9]+)\s*</cmd>"), - SM(r"\s*\[qbox\]\s+<cmd>\s*set\s+cell_dyn\s+(?P<qbox_cell_dyn>[A-Za-z0-9]+)\s*</cmd>"), + SM(r"\s*\[qbox\]\s*\[qbox\]\s*<cmd>\s*set\s+ecut\s+(?P<x_qbox_ecut__rydberg>[0-9.]+)\s*</cmd>"), + SM(r"\s*\[qbox\]\s+<cmd>\s*set\s+wf_dyn\s+(?P<x_qbox_wf_dyn>[A-Za-z0-9]+)\s*</cmd>"), + SM(r"\s*\[qbox\]\s+<cmd>\s*set\s+atoms_dyn\s+(?P<x_qbox_atoms_dyn>[A-Za-z0-9]+)\s*</cmd>"), + SM(r"\s*\[qbox\]\s+<cmd>\s*set\s+cell_dyn\s+(?P<x_qbox_cell_dyn>[A-Za-z0-9]+)\s*</cmd>"), #--------set xc--------- SM(name = "qboxXC", - startReStr = r"\s*\[qbox\]\s+<cmd>\s*set\s+xc\s+(?P<qbox_functional_name>[A-Za-z0-9]+)\s*</cmd>", - sections = ["qbox_section_functionals"] + startReStr = r"\s*\[qbox\]\s+<cmd>\s*set\s+xc\s+(?P<x_qbox_functional_name>[A-Za-z0-9]+)\s*</cmd>", + sections = ["x_qbox_section_functionals"] ), #-------set efield--------- - SM (r"\s*\[qbox\]\s*\[qbox\]\s*<cmd>\s*set\s+e_field\s*(?P<qbox_efield_x>[-+0-9.]+)\s+(?P<qbox_efield_y>[-+0-9.]+)\s+(?P<qbox_efield_z>[-+0-9.]+)\s*</cmd>",repeats = True) + SM (r"\s*\[qbox\]\s*\[qbox\]\s*<cmd>\s*set\s+e_field\s*(?P<x_qbox_efield_x>[-+0-9.]+)\s+(?P<x_qbox_efield_y>[-+0-9.]+)\s+(?P<x_qbox_efield_z>[-+0-9.]+)\s*</cmd>",repeats = True) #???both this version adn qbox_section_efield version could not give mather for efield, need to check. ]) @@ -381,51 +381,51 @@ def build_QboxMainFileSimpleMatcher(): subMatchers = [ SM (startReStr = r"\s*<unit_cell\s*", subMatchers = [ - SM (r"\s*[a-z]=\"\s*(?P<qbox_geometry_lattice_vector_x__bohr>[-+0-9.]+)\s+(?P<qbox_geometry_lattice_vector_y__bohr>[-+0-9.]+)\s+(?P<qbox_geometry_lattice_vector_z__bohr>[-+0-9.]+)\s*\"", repeats = True) + SM (r"\s*[a-z]=\"\s*(?P<x_qbox_geometry_lattice_vector_x__bohr>[-+0-9.]+)\s+(?P<x_qbox_geometry_lattice_vector_y__bohr>[-+0-9.]+)\s+(?P<x_qbox_geometry_lattice_vector_z__bohr>[-+0-9.]+)\s*\"", repeats = True) ]), - SM (startReStr = r"\s*<atom\s+name=\"(?P<qbox_geometry_atom_labels>[a-zA-Z0-9]+)\"", + SM (startReStr = r"\s*<atom\s+name=\"(?P<x_qbox_geometry_atom_labels>[a-zA-Z0-9]+)\"", subMatchers = [ - SM (r"\s*<position>\s+(?P<qbox_geometry_atom_positions_x__bohr>[-+0-9.]+)\s+(?P<qbox_geometry_atom_positions_y__bohr>[-+0-9.]+)\s+(?P<qbox_geometry_atom_positions_z__bohr>[-+0-9.]+)\s*</position>", repeats = True), - SM (r"\s*<force>\s+(?P<qbox_atom_force_x__hartree_bohr_1>[-+0-9.]+)\s+(?P<qbox_atom_force_y__hartree_bohr_1>[-+0-9.]+)\s+(?P<qbox_atom_force_z__hartree_bohr_1>[-+0-9.]+)\s*</force>", repeats = True) + SM (r"\s*<position>\s+(?P<x_qbox_geometry_atom_positions_x__bohr>[-+0-9.]+)\s+(?P<x_qbox_geometry_atom_positions_y__bohr>[-+0-9.]+)\s+(?P<x_qbox_geometry_atom_positions_z__bohr>[-+0-9.]+)\s*</position>", repeats = True), + SM (r"\s*<force>\s+(?P<x_qbox_atom_force_x__hartree_bohr_1>[-+0-9.]+)\s+(?P<x_qbox_atom_force_y__hartree_bohr_1>[-+0-9.]+)\s+(?P<x_qbox_atom_force_z__hartree_bohr_1>[-+0-9.]+)\s*</force>", repeats = True) ], repeats = True) ]) ##################################################################### - # (3.5) submatcher for OUTPUT stress_tensor(qbox_section_stress_tensor) + # (3.5) submatcher for OUTPUT stress_tensor(x_qbox_section_stress_tensor) ##################################################################### stresstensorSubMatcher = SM(name = 'StressTensor', startReStr = r"\s*<stress_tensor\s*unit=\"GPa\">", - sections = ['qbox_section_stress_tensor'], + sections = ['x_qbox_section_stress_tensor'], subMatchers = [ - SM (r"\s*<sigma_xx>\s+(?P<qbox_stress_tensor_xx__GPa>[-+0-9.]+)\s*</sigma_xx>"), - SM (r"\s*<sigma_yy>\s+(?P<qbox_stress_tensor_yy__GPa>[-+0-9.]+)\s*</sigma_yy>"), - SM (r"\s*<sigma_zz>\s+(?P<qbox_stress_tensor_zz__GPa>[-+0-9.]+)\s*</sigma_zz>"), - SM (r"\s*<sigma_xy>\s+(?P<qbox_stress_tensor_xy__GPa>[-+0-9.]+)\s*</sigma_xy>"), - SM (r"\s*<sigma_yz>\s+(?P<qbox_stress_tensor_yz__GPa>[-+0-9.]+)\s*</sigma_yz>"), - SM (r"\s*<sigma_xz>\s+(?P<qbox_stress_tensor_xz__GPa>[-+0-9.]+)\s*</sigma_xz>") + SM (r"\s*<sigma_xx>\s+(?P<x_qbox_stress_tensor_xx__GPa>[-+0-9.]+)\s*</sigma_xx>"), + SM (r"\s*<sigma_yy>\s+(?P<x_qbox_stress_tensor_yy__GPa>[-+0-9.]+)\s*</sigma_yy>"), + SM (r"\s*<sigma_zz>\s+(?P<x_qbox_stress_tensor_zz__GPa>[-+0-9.]+)\s*</sigma_zz>"), + SM (r"\s*<sigma_xy>\s+(?P<x_qbox_stress_tensor_xy__GPa>[-+0-9.]+)\s*</sigma_xy>"), + SM (r"\s*<sigma_yz>\s+(?P<x_qbox_stress_tensor_yz__GPa>[-+0-9.]+)\s*</sigma_yz>"), + SM (r"\s*<sigma_xz>\s+(?P<x_qbox_stress_tensor_xz__GPa>[-+0-9.]+)\s*</sigma_xz>") ]) #################################################################### - # (4.1) submatcher for properties : MLWF (qbox_section_MLWF) + # (4.1) submatcher for properties : MLWF (x_qbox_section_MLWF) #################################################################### MLWFSubMatcher = SM(name = 'MLWF', startReStr = r"\s*<mlwfs>", - sections = ["qbox_section_MLWF"], + sections = ["x_qbox_section_MLWF"], subMatchers = [ - SM (r"\s*<mlwf center=\"\s*(?P<qbox_geometry_MLWF_atom_positions_x__bohr>[-+0-9.]+)\s+(?P<qbox_geometry_MLWF_atom_positions_y__bohr>[-+0-9.]+)\s+(?P<qbox_geometry_MLWF_atom_positions_z__bohr>[-+0-9.]+)\s*\"\s+spread=\"\s*(?P<qbox_geometry_MLWF_atom_spread__bohr>[-+0-9.]+)\s*\"", repeats = True) + SM (r"\s*<mlwf center=\"\s*(?P<x_qbox_geometry_MLWF_atom_positions_x__bohr>[-+0-9.]+)\s+(?P<x_qbox_geometry_MLWF_atom_positions_y__bohr>[-+0-9.]+)\s+(?P<x_qbox_geometry_MLWF_atom_positions_z__bohr>[-+0-9.]+)\s*\"\s+spread=\"\s*(?P<x_qbox_geometry_MLWF_atom_spread__bohr>[-+0-9.]+)\s*\"", repeats = True) ]) #################################################################### - # (4.2) submatcher for properties : dipole (qbox_section_dipole) + # (4.2) submatcher for properties : dipole (x_qbox_section_dipole) #################################################################### dipoleSubMatcher = SM(name = 'Dipole', startReStr = r"\s*<dipole>", - sections = ["qbox_section_dipole"], + sections = ["x_qbox_section_dipole"], subMatchers = [ - SM (r"\s*<dipole_total>\s+(?P<qbox_dipole_x>[-+0-9.]+)\s+(?P<qbox_dipole_y>[-+0-9.]+)\s+(?P<qbox_dipole_z>[-+0-9.]+)\s*</dipole_total>", repeats = True) + SM (r"\s*<dipole_total>\s+(?P<x_qbox_dipole_x>[-+0-9.]+)\s+(?P<x_qbox_dipole_y>[-+0-9.]+)\s+(?P<x_qbox_dipole_z>[-+0-9.]+)\s*</dipole_total>", repeats = True) ]) ######################################## @@ -507,8 +507,8 @@ def get_cachingLevelForMetaName(metaInfoEnv): # Set caching for temparary storage variables for name in metaInfoEnv.infoKinds: - if ( name.startswith('qbox_store_') - or name.startswith('qbox_cell_')): + if ( name.startswith('x_qbox_store_') + or name.startswith('x_qbox_cell_')): cachingLevelForMetaName[name] = CachingLevel.Cache return cachingLevelForMetaName diff --git a/parser/parser-qbox/QboxXMLParser.py b/parser/parser-qbox/QboxXMLParser.py index 34ba223993289cb16ea95d9138757b906169fc5c..570f4051f8f1c940c8f7690fdb9a195db6bf4dbb 100644 --- a/parser/parser-qbox/QboxXMLParser.py +++ b/parser/parser-qbox/QboxXMLParser.py @@ -46,7 +46,7 @@ class QboxXMLParserContext(object): #------1.atom_positions atom_pos = [] for i in ['x', 'y', 'z']: - api = section['qbox_geometry_atom_positions_' + i] + api = section['x_qbox_geometry_atom_positions_' + i] if api is not None: atom_pos.append(api) if atom_pos: @@ -54,7 +54,7 @@ class QboxXMLParserContext(object): backend.addArrayValues('atom_positions', np.transpose(np.asarray(atom_pos))) #------2.atom labels - atom_labels = section['qbox_geometry_atom_labels'] + atom_labels = section['x_qbox_geometry_atom_labels'] if atom_labels is not None: backend.addArrayValues('atom_labels', np.asarray(atom_labels)) @@ -82,11 +82,11 @@ def build_QboxXMLFileSimpleMatcher(): subMatchers = [ SM (startReStr = r"\s*<unit_cell\s*", subMatchers = [ - SM (r"\s*[a-z]=\"\s*(?P<qbox_geometry_lattice_vector_x__bohr>[-+0-9.]+)\s+(?P<qbox_geometry_lattice_vector_y__bohr>[-+0-9.]+)\s+(?P<qbox_geometry_lattice_vector_z__bohr>[-+0-9.]+)\s*\"", repeats = True) + SM (r"\s*[a-z]=\"\s*(?P<x_qbox_geometry_lattice_vector_x__bohr>[-+0-9.]+)\s+(?P<x_qbox_geometry_lattice_vector_y__bohr>[-+0-9.]+)\s+(?P<x_qbox_geometry_lattice_vector_z__bohr>[-+0-9.]+)\s*\"", repeats = True) ]), - SM (startReStr = r"\s*<atom\s+name=\"(?P<qbox_geometry_atom_labels>[a-zA-Z0-9]+)\"", + SM (startReStr = r"\s*<atom\s+name=\"(?P<x_qbox_geometry_atom_labels>[a-zA-Z0-9]+)\"", subMatchers = [ - SM (r"\s*<position>\s+(?P<qbox_geometry_atom_positions_x__bohr>[-+0-9.]+)\s+(?P<qbox_geometry_atom_positions_y__bohr>[-+0-9.]+)\s+(?P<qbox_geometry_atom_positions_z__bohr>[-+0-9.]+)\s*</position>", repeats = True), + SM (r"\s*<position>\s+(?P<x_qbox_geometry_atom_positions_x__bohr>[-+0-9.]+)\s+(?P<x_qbox_geometry_atom_positions_y__bohr>[-+0-9.]+)\s+(?P<x_qbox_geometry_atom_positions_z__bohr>[-+0-9.]+)\s*</position>", repeats = True), ], repeats = True) ]) @@ -130,7 +130,7 @@ def get_cachingLevelForMetaName(metaInfoEnv, CachingLvl): } # Set all band metadata to Cache as they need post-processsing. for name in metaInfoEnv.infoKinds: - if name.startswith('qbox_'): + if name.startswith('x_qbox_'): cachingLevelForMetaName[name] = CachingLevel.Cache return cachingLevelForMetaName