diff --git a/parser/parser-cp2k/cp2kparser/parser.py b/parser/parser-cp2k/cp2kparser/parser.py index 0bca72450628fb0d02b32963d083caadd66d6bcc..c1dabfc9e9b6e3469762a24b525328a18dd24101 100644 --- a/parser/parser-cp2k/cp2kparser/parser.py +++ b/parser/parser-cp2k/cp2kparser/parser.py @@ -3,8 +3,8 @@ from builtins import range import os import re import logging +import importlib from nomadcore.baseclasses import ParserInterface -from cp2kparser.versions.versionsetup import get_main_parser logger = logging.getLogger("nomad") @@ -58,10 +58,69 @@ class CP2KParser(ParserInterface): # Setup the correct main parser based on the version id. If no match # for the version is found, use the main parser for CP2K 2.6.2 - self.main_parser = get_main_parser(version_id, run_type)(self.parser_context.main_file, self.parser_context) + self.setup_main_parser({"version_id": version_id, "run_type": run_type}) def get_metainfo_filename(self): return "cp2k.nomadmetainfo.json" def get_parser_info(self): return {'name': 'cp2k-parser', 'version': '1.0'} + + def setup_main_parser(self, version_dictionary): + """ + Setups a main parser class for this calculation. The main class can be + different for each version and run type. + + Args: + version_id: An integer representing the CP2K version. The version + number is originally a string the form '2.6.2', but here the numbers + are just concatenated into a single integer number 262. + run_type: A string that identifies the RUN_TYPE for the calculation. + All the possible run types can be found in the CP2K reference manual. + + Returns: + A python class that should be instantiated later with the correct + parameters. + """ + run_type = version_dictionary["run_type"] + version_id = version_dictionary["version_id"] + + # Search for a RUN_TYPE specific parser + parser_map = { + "ENERGY": "SinglePointParser", + "ENERGY_FORCE": "SinglePointParser", + "WAVEFUNCTION_OPTIMIZATION": "SinglePointParser", + "WFN_OPT": "SinglePointParser", + "GEO_OPT": "GeoOptParser", + "GEOMETRY_OPTIMIZATION": "GeoOptParser", + "MD": "MDParser", + "MOLECULAR_DYNAMICS": "MDParser", + } + try: + parser = parser_map[run_type] + except KeyError: + logger.exception("A parser corresponding to the run_type '{}' could not be found.".format(run_type)) + raise + + # Currently the version id is a pure integer, so it can directly be mapped + # into a package name. + base = "cp2kparser.versions.cp2k{}.{}".format(version_id, parser.lower()) + parser_module = None + parser_class = None + try: + parser_module = importlib.import_module(base) + except ImportError: + logger.warning("Could not find a parser for version '{}' and run type '{}'. Trying to default to the base implementation for CP2K 2.6.2".format(version_id, run_type)) + base = "cp2kparser.versions.cp2k262.{}".format(parser.lower()) + try: + parser_module = importlib.import_module(base) + except ImportError: + logger.exception("Tried to default to the CP2K 2.6.2 implementation but could not find the correct modules for run_type '{}'.".format(run_type)) + raise + try: + parser_class = getattr(parser_module, "CP2K{}".format(parser)) + except AttributeError: + logger.exception("A parser class '{}' could not be found in the module '[]'.".format(parser_class, parser_module)) + raise + + self.main_parser = parser_class(self.parser_context.main_file, self.parser_context) diff --git a/parser/parser-cp2k/cp2kparser/versions/cp2k262/commonmatcher.py b/parser/parser-cp2k/cp2kparser/versions/cp2k262/commonmatcher.py index 52bc4311bd1abf47545a3029d335ccf6412252eb..b6a4140ec3c3052bed13aef12d004887dc61a8a3 100644 --- a/parser/parser-cp2k/cp2kparser/versions/cp2k262/commonmatcher.py +++ b/parser/parser-cp2k/cp2kparser/versions/cp2k262/commonmatcher.py @@ -1,36 +1,25 @@ from __future__ import absolute_import from builtins import str -from builtins import object import re import numpy as np import logging from nomadcore.simple_parser import SimpleMatcher as SM -from nomadcore.simple_parser import extractOnCloseTriggers from nomadcore.caching_backend import CachingLevel from nomadcore.unit_conversion.unit_conversion import convert_unit +from nomadcore.baseclasses import CommonMatcher from .inputparser import CP2KInputParser logger = logging.getLogger("nomad") #=============================================================================== -class CommonMatcher(object): +class CP2KCommonMatcher(CommonMatcher): """ This class is used to store and instantiate common parts of the hierarchical SimpleMatcher structure used in the parsing of a CP2K output file. """ def __init__(self, parser_context): - - # Repeating regex definitions - self.parser_context = parser_context - self.backend = parser_context.caching_backend - self.file_service = parser_context.file_service - self.cache_service = parser_context.cache_service - self.regex_f = "-?\d+\.\d+(?:E(?:\+|-)\d+)?" # Regex for a floating point value - self.regex_i = "-?\d+" # Regex for an integer - self.regex_word = "[\S]+" # Regex for a single word. Can contain anything else but whitespace - self.regex_letter = "[^\W\d_]" # Regex for a single alphabetical letter - self.regex_eol = "[^\n]+" # Regex for a single alphabetical letter + super(CP2KCommonMatcher, self).__init__(parser_context) self.section_method_index = None self.section_system_index = None self.test_electronic_structure_method = "DFT" @@ -68,25 +57,25 @@ class CommonMatcher(object): forwardMatch=True, sections=['x_cp2k_section_dbcsr'], subMatchers=[ - SM( " DBCSR\| Multiplication driver\s+(?P<x_cp2k_dbcsr_multiplication_driver>{})".format(self.regex_word)), - SM( " DBCSR\| Multrec recursion limit\s+(?P<x_cp2k_dbcsr_multrec_recursion_limit>{})".format(self.regex_i)), - SM( " DBCSR\| Multiplication stack size\s+(?P<x_cp2k_dbcsr_multiplication_stack_size>{})".format(self.regex_i)), - SM( " DBCSR\| Multiplication size stacks\s+(?P<x_cp2k_dbcsr_multiplication_size_stacks>{})".format(self.regex_i)), - SM( " DBCSR\| Use subcommunicators\s+(?P<x_cp2k_dbcsr_use_subcommunicators>{})".format(self.regex_letter)), - SM( " DBCSR\| Use MPI combined types\s+(?P<x_cp2k_dbcsr_use_mpi_combined_types>{})".format(self.regex_letter)), - SM( " DBCSR\| Use MPI memory allocation\s+(?P<x_cp2k_dbcsr_use_mpi_memory_allocation>{})".format(self.regex_letter)), - SM( " DBCSR\| Use Communication thread\s+(?P<x_cp2k_dbcsr_use_communication_thread>{})".format(self.regex_letter)), - SM( " DBCSR\| Communication thread load\s+(?P<x_cp2k_dbcsr_communication_thread_load>{})".format(self.regex_i)), + SM( " DBCSR\| Multiplication driver\s+(?P<x_cp2k_dbcsr_multiplication_driver>{})".format(self.regexs.regex_word)), + SM( " DBCSR\| Multrec recursion limit\s+(?P<x_cp2k_dbcsr_multrec_recursion_limit>{})".format(self.regexs.regex_i)), + SM( " DBCSR\| Multiplication stack size\s+(?P<x_cp2k_dbcsr_multiplication_stack_size>{})".format(self.regexs.regex_i)), + SM( " DBCSR\| Multiplication size stacks\s+(?P<x_cp2k_dbcsr_multiplication_size_stacks>{})".format(self.regexs.regex_i)), + SM( " DBCSR\| Use subcommunicators\s+(?P<x_cp2k_dbcsr_use_subcommunicators>{})".format(self.regexs.regex_letter)), + SM( " DBCSR\| Use MPI combined types\s+(?P<x_cp2k_dbcsr_use_mpi_combined_types>{})".format(self.regexs.regex_letter)), + SM( " DBCSR\| Use MPI memory allocation\s+(?P<x_cp2k_dbcsr_use_mpi_memory_allocation>{})".format(self.regexs.regex_letter)), + SM( " DBCSR\| Use Communication thread\s+(?P<x_cp2k_dbcsr_use_communication_thread>{})".format(self.regexs.regex_letter)), + SM( " DBCSR\| Communication thread load\s+(?P<x_cp2k_dbcsr_communication_thread_load>{})".format(self.regexs.regex_i)), ] ), SM( " **** **** ****** ** PROGRAM STARTED AT".replace("*", "\*"), forwardMatch=True, sections=['x_cp2k_section_startinformation'], subMatchers=[ - SM( " **** **** ****** ** PROGRAM STARTED AT\s+(?P<x_cp2k_start_time>{})".replace("*", "\*").format(self.regex_eol)), - SM( " ***** ** *** *** ** PROGRAM STARTED ON\s+(?P<x_cp2k_start_host>{})".replace("*", "\*").format(self.regex_word)), - SM( " ** **** ****** PROGRAM STARTED BY\s+(?P<x_cp2k_start_user>{})".replace("*", "\*").format(self.regex_word)), - SM( " ***** ** ** ** ** PROGRAM PROCESS ID\s+(?P<x_cp2k_start_id>{})".replace("*", "\*").format(self.regex_i)), + SM( " **** **** ****** ** PROGRAM STARTED AT\s+(?P<x_cp2k_start_time>{})".replace("*", "\*").format(self.regexs.regex_eol)), + SM( " ***** ** *** *** ** PROGRAM STARTED ON\s+(?P<x_cp2k_start_host>{})".replace("*", "\*").format(self.regexs.regex_word)), + SM( " ** **** ****** PROGRAM STARTED BY\s+(?P<x_cp2k_start_user>{})".replace("*", "\*").format(self.regexs.regex_word)), + SM( " ***** ** ** ** ** PROGRAM PROCESS ID\s+(?P<x_cp2k_start_id>{})".replace("*", "\*").format(self.regexs.regex_i)), SM( " **** ** ******* ** PROGRAM STARTED IN".replace("*", "\*"), forwardMatch=True, adHoc=self.adHoc_run_dir(), @@ -97,29 +86,29 @@ class CommonMatcher(object): sections=['x_cp2k_section_program_information'], forwardMatch=True, subMatchers=[ - SM( " CP2K\| version string:\s+(?P<program_version>{})".format(self.regex_eol)), + SM( " CP2K\| version string:\s+(?P<program_version>{})".format(self.regexs.regex_eol)), SM( " CP2K\| source code revision number:\s+svn:(?P<x_cp2k_svn_revision>\d+)"), - SM( " CP2K\| is freely available from{}".format(self.regex_eol)), - SM( " CP2K\| Program compiled at\s+(?P<x_cp2k_program_compilation_datetime>{})".format(self.regex_eol)), - SM( " CP2K\| Program compiled on\s+(?P<program_compilation_host>{})".format(self.regex_eol)), - SM( " CP2K\| Program compiled for{}".format(self.regex_eol)), - SM( " CP2K\| Input file name\s+(?P<x_cp2k_input_filename>{})".format(self.regex_eol)), + SM( " CP2K\| is freely available from{}".format(self.regexs.regex_eol)), + SM( " CP2K\| Program compiled at\s+(?P<x_cp2k_program_compilation_datetime>{})".format(self.regexs.regex_eol)), + SM( " CP2K\| Program compiled on\s+(?P<program_compilation_host>{})".format(self.regexs.regex_eol)), + SM( " CP2K\| Program compiled for{}".format(self.regexs.regex_eol)), + SM( " CP2K\| Input file name\s+(?P<x_cp2k_input_filename>{})".format(self.regexs.regex_eol)), ] ), SM( " GLOBAL\|", sections=['x_cp2k_section_global_settings'], subMatchers=[ SM( " GLOBAL\| Force Environment number"), - SM( " GLOBAL\| Basis set file name\s+(?P<x_cp2k_basis_set_filename>{})".format(self.regex_eol)), - SM( " GLOBAL\| Geminal file name\s+(?P<x_cp2k_geminal_filename>{})".format(self.regex_eol)), - SM( " GLOBAL\| Potential file name\s+(?P<x_cp2k_potential_filename>{})".format(self.regex_eol)), - SM( " GLOBAL\| MM Potential file name\s+(?P<x_cp2k_mm_potential_filename>{})".format(self.regex_eol)), - SM( " GLOBAL\| Coordinate file name\s+(?P<x_cp2k_coordinate_filename>{})".format(self.regex_eol)), - SM( " GLOBAL\| Method name\s+(?P<x_cp2k_method_name>{})".format(self.regex_eol)), + SM( " GLOBAL\| Basis set file name\s+(?P<x_cp2k_basis_set_filename>{})".format(self.regexs.regex_eol)), + SM( " GLOBAL\| Geminal file name\s+(?P<x_cp2k_geminal_filename>{})".format(self.regexs.regex_eol)), + SM( " GLOBAL\| Potential file name\s+(?P<x_cp2k_potential_filename>{})".format(self.regexs.regex_eol)), + SM( " GLOBAL\| MM Potential file name\s+(?P<x_cp2k_mm_potential_filename>{})".format(self.regexs.regex_eol)), + SM( " GLOBAL\| Coordinate file name\s+(?P<x_cp2k_coordinate_filename>{})".format(self.regexs.regex_eol)), + SM( " GLOBAL\| Method name\s+(?P<x_cp2k_method_name>{})".format(self.regexs.regex_eol)), SM( " GLOBAL\| Project name"), - SM( " GLOBAL\| Preferred FFT library\s+(?P<x_cp2k_preferred_fft_library>{})".format(self.regex_eol)), - SM( " GLOBAL\| Preferred diagonalization lib.\s+(?P<x_cp2k_preferred_diagonalization_library>{})".format(self.regex_eol)), - SM( " GLOBAL\| Run type\s+(?P<x_cp2k_run_type>{})".format(self.regex_eol)), + SM( " GLOBAL\| Preferred FFT library\s+(?P<x_cp2k_preferred_fft_library>{})".format(self.regexs.regex_eol)), + SM( " GLOBAL\| Preferred diagonalization lib.\s+(?P<x_cp2k_preferred_diagonalization_library>{})".format(self.regexs.regex_eol)), + SM( " GLOBAL\| Run type\s+(?P<x_cp2k_run_type>{})".format(self.regexs.regex_eol)), SM( " GLOBAL\| All-to-all communication in single precision"), SM( " GLOBAL\| FFTs using library dependent lengths"), SM( " GLOBAL\| Global print level"), @@ -153,8 +142,8 @@ class CommonMatcher(object): sections=["x_cp2k_section_scf_iteration"], repeats=True, subMatchers=[ - SM( r" Exchange-correlation energy:\s+(?P<x_cp2k_energy_XC_scf_iteration__hartree>{})".format(self.regex_f)), - SM( r"\s+\d+\s+\S+\s+{0}\s+{0}\s+{0}\s+(?P<x_cp2k_energy_total_scf_iteration__hartree>{0})\s+(?P<x_cp2k_energy_change_scf_iteration__hartree>{0})".format(self.regex_f)), + SM( r" Exchange-correlation energy:\s+(?P<x_cp2k_energy_XC_scf_iteration__hartree>{})".format(self.regexs.regex_f)), + SM( r"\s+\d+\s+\S+\s+{0}\s+{0}\s+{0}\s+(?P<x_cp2k_energy_total_scf_iteration__hartree>{0})\s+(?P<x_cp2k_energy_change_scf_iteration__hartree>{0})".format(self.regexs.regex_f)), ] ), SM( r" \*\*\* SCF run converged in\s+(\d+) steps \*\*\*", @@ -165,12 +154,12 @@ class CommonMatcher(object): otherMetaInfo=["single_configuration_calculation_converged"], adHoc=self.adHoc_single_point_not_converged() ), - SM( r" Electronic kinetic energy:\s+(?P<x_cp2k_electronic_kinetic_energy__hartree>{})".format(self.regex_f)), + SM( r" Electronic kinetic energy:\s+(?P<x_cp2k_electronic_kinetic_energy__hartree>{})".format(self.regexs.regex_f)), SM( r" **************************** NUMERICAL STRESS ********************************".replace("*", "\*"), # endReStr=" **************************** NUMERICAL STRESS END *****************************".replace("*", "\*"), adHoc=self.adHoc_stress_calculation(), ), - SM( r" ENERGY\| Total FORCE_EVAL \( \w+ \) energy \(a\.u\.\):\s+(?P<x_cp2k_energy_total__hartree>{0})".format(self.regex_f), + SM( r" ENERGY\| Total FORCE_EVAL \( \w+ \) energy \(a\.u\.\):\s+(?P<x_cp2k_energy_total__hartree>{0})".format(self.regexs.regex_f), otherMetaInfo=["energy_total"], ), SM( r" ATOMIC FORCES in \[a\.u\.\]"), @@ -185,8 +174,8 @@ class CommonMatcher(object): adHoc=self.adHoc_stress_tensor(), otherMetaInfo=["stress_tensor", "section_stress_tensor"], ), - SM( " 1/3 Trace\(stress tensor\):\s+(?P<x_cp2k_stress_tensor_one_third_of_trace__GPa>{})".format(self.regex_f)), - SM( " Det\(stress tensor\)\s+:\s+(?P<x_cp2k_stress_tensor_determinant__GPa3>{})".format(self.regex_f)), + SM( " 1/3 Trace\(stress tensor\):\s+(?P<x_cp2k_stress_tensor_one_third_of_trace__GPa>{})".format(self.regexs.regex_f)), + SM( " Det\(stress tensor\)\s+:\s+(?P<x_cp2k_stress_tensor_determinant__GPa3>{})".format(self.regexs.regex_f)), SM( " EIGENVECTORS AND EIGENVALUES OF THE STRESS TENSOR", adHoc=self.adHoc_stress_tensor_eigenpairs()), ] @@ -203,10 +192,10 @@ class CommonMatcher(object): SM( " DFT\|", forwardMatch=True, subMatchers=[ - SM( " DFT\| Spin restricted Kohn-Sham (RKS) calculation\s+(?P<x_cp2k_spin_restriction>{})".format(self.regex_word)), - SM( " DFT\| Multiplicity\s+(?P<spin_target_multiplicity>{})".format(self.regex_i)), - SM( " DFT\| Number of spin states\s+(?P<number_of_spin_channels>{})".format(self.regex_i)), - SM( " DFT\| Charge\s+(?P<total_charge>{})".format(self.regex_i)), + SM( " DFT\| Spin restricted Kohn-Sham (RKS) calculation\s+(?P<x_cp2k_spin_restriction>{})".format(self.regexs.regex_word)), + SM( " DFT\| Multiplicity\s+(?P<spin_target_multiplicity>{})".format(self.regexs.regex_i)), + SM( " DFT\| Number of spin states\s+(?P<number_of_spin_channels>{})".format(self.regexs.regex_i)), + SM( " DFT\| Charge\s+(?P<total_charge>{})".format(self.regexs.regex_i)), SM( " DFT\| Self-interaction correction \(SIC\)\s+(?P<self_interaction_correction_method>[^\n]+)"), ], otherMetaInfo=["self_interaction_correction_method"], @@ -217,41 +206,41 @@ class CommonMatcher(object): SM( " QS\|", forwardMatch=True, subMatchers=[ - SM( " QS\| Method:\s+(?P<x_cp2k_quickstep_method>{})".format(self.regex_word)), - SM( " QS\| Density plane wave grid type\s+{}".format(self.regex_eol)), - SM( " QS\| Number of grid levels:\s+{}".format(self.regex_i)), - SM( " QS\| Density cutoff \[a\.u\.\]:\s+(?P<x_cp2k_planewave_cutoff>{})".format(self.regex_f)), - SM( " QS\| Multi grid cutoff \[a\.u\.\]: 1\) grid level\s+{}".format(self.regex_f)), - SM( " QS\| 2\) grid level\s+{}".format(self.regex_f)), - SM( " QS\| 3\) grid level\s+{}".format(self.regex_f)), - SM( " QS\| 4\) grid level\s+{}".format(self.regex_f)), - SM( " QS\| Grid level progression factor:\s+{}".format(self.regex_f)), - SM( " QS\| Relative density cutoff \[a\.u\.\]:".format(self.regex_f)), + SM( " QS\| Method:\s+(?P<x_cp2k_quickstep_method>{})".format(self.regexs.regex_word)), + SM( " QS\| Density plane wave grid type\s+{}".format(self.regexs.regex_eol)), + SM( " QS\| Number of grid levels:\s+{}".format(self.regexs.regex_i)), + SM( " QS\| Density cutoff \[a\.u\.\]:\s+(?P<x_cp2k_planewave_cutoff>{})".format(self.regexs.regex_f)), + SM( " QS\| Multi grid cutoff \[a\.u\.\]: 1\) grid level\s+{}".format(self.regexs.regex_f)), + SM( " QS\| 2\) grid level\s+{}".format(self.regexs.regex_f)), + SM( " QS\| 3\) grid level\s+{}".format(self.regexs.regex_f)), + SM( " QS\| 4\) grid level\s+{}".format(self.regexs.regex_f)), + SM( " QS\| Grid level progression factor:\s+{}".format(self.regexs.regex_f)), + SM( " QS\| Relative density cutoff \[a\.u\.\]:".format(self.regexs.regex_f)), SM( " QS\| Consistent realspace mapping and integration"), - SM( " QS\| Interaction thresholds: eps_pgf_orb:\s+{}".format(self.regex_f)), - SM( " QS\| eps_filter_matrix:\s+{}".format(self.regex_f)), - SM( " QS\| eps_core_charge:\s+{}".format(self.regex_f)), - SM( " QS\| eps_rho_gspace:\s+{}".format(self.regex_f)), - SM( " QS\| eps_rho_rspace:\s+{}".format(self.regex_f)), - SM( " QS\| eps_gvg_rspace:\s+{}".format(self.regex_f)), - SM( " QS\| eps_ppl:\s+{}".format(self.regex_f)), - SM( " QS\| eps_ppnl:\s+{}".format(self.regex_f)), + SM( " QS\| Interaction thresholds: eps_pgf_orb:\s+{}".format(self.regexs.regex_f)), + SM( " QS\| eps_filter_matrix:\s+{}".format(self.regexs.regex_f)), + SM( " QS\| eps_core_charge:\s+{}".format(self.regexs.regex_f)), + SM( " QS\| eps_rho_gspace:\s+{}".format(self.regexs.regex_f)), + SM( " QS\| eps_rho_rspace:\s+{}".format(self.regexs.regex_f)), + SM( " QS\| eps_gvg_rspace:\s+{}".format(self.regexs.regex_f)), + SM( " QS\| eps_ppl:\s+{}".format(self.regexs.regex_f)), + SM( " QS\| eps_ppnl:\s+{}".format(self.regexs.regex_f)), ], ), SM( " ATOMIC KIND INFORMATION", sections=["x_cp2k_section_atomic_kinds", "section_method_basis_set"], subMatchers=[ - SM( "\s+(?P<x_cp2k_kind_number>{0})\. Atomic kind: (?P<x_cp2k_kind_element_symbol>{1})\s+Number of atoms:\s+(?P<x_cp2k_kind_number_of_atoms>{1})".format(self.regex_i, self.regex_word), + SM( "\s+(?P<x_cp2k_kind_number>{0})\. Atomic kind: (?P<x_cp2k_kind_element_symbol>{1})\s+Number of atoms:\s+(?P<x_cp2k_kind_number_of_atoms>{1})".format(self.regexs.regex_i, self.regexs.regex_word), repeats=True, sections=["x_cp2k_section_atomic_kind", "x_cp2k_section_kind_basis_set"], subMatchers=[ - SM( " Orbital Basis Set\s+(?P<x_cp2k_kind_basis_set_name>{})".format(self.regex_word)), - SM( " Number of orbital shell sets:\s+(?P<x_cp2k_basis_set_number_of_orbital_shell_sets>{})".format(self.regex_i)), - SM( " Number of orbital shells:\s+(?P<x_cp2k_basis_set_number_of_orbital_shells>{})".format(self.regex_i)), - SM( " Number of primitive Cartesian functions:\s+(?P<x_cp2k_basis_set_number_of_primitive_cartesian_functions>{})".format(self.regex_i)), - SM( " Number of Cartesian basis functions:\s+(?P<x_cp2k_basis_set_number_of_cartesian_basis_functions>{})".format(self.regex_i)), - SM( " Number of spherical basis functions:\s+(?P<x_cp2k_basis_set_number_of_spherical_basis_functions>{})".format(self.regex_i)), - SM( " Norm type:\s+(?P<x_cp2k_basis_set_norm_type>{})".format(self.regex_i)), + SM( " Orbital Basis Set\s+(?P<x_cp2k_kind_basis_set_name>{})".format(self.regexs.regex_word)), + SM( " Number of orbital shell sets:\s+(?P<x_cp2k_basis_set_number_of_orbital_shell_sets>{})".format(self.regexs.regex_i)), + SM( " Number of orbital shells:\s+(?P<x_cp2k_basis_set_number_of_orbital_shells>{})".format(self.regexs.regex_i)), + SM( " Number of primitive Cartesian functions:\s+(?P<x_cp2k_basis_set_number_of_primitive_cartesian_functions>{})".format(self.regexs.regex_i)), + SM( " Number of Cartesian basis functions:\s+(?P<x_cp2k_basis_set_number_of_cartesian_basis_functions>{})".format(self.regexs.regex_i)), + SM( " Number of spherical basis functions:\s+(?P<x_cp2k_basis_set_number_of_spherical_basis_functions>{})".format(self.regexs.regex_i)), + SM( " Norm type:\s+(?P<x_cp2k_basis_set_norm_type>{})".format(self.regexs.regex_i)), ] ) ] @@ -292,11 +281,11 @@ class CommonMatcher(object): SM( " SCF PARAMETERS", forwardMatch=True, subMatchers=[ - SM( " SCF PARAMETERS Density guess:\s+{}".format(self.regex_eol)), - SM( " max_scf:\s+(?P<scf_max_iteration>{})".format(self.regex_i)), - SM( " max_scf_history:\s+{}".format(self.regex_i)), - SM( " max_diis:\s+{}".format(self.regex_i)), - SM( " eps_scf:\s+(?P<scf_threshold_energy_change>{})".format(self.regex_f)), + SM( " SCF PARAMETERS Density guess:\s+{}".format(self.regexs.regex_eol)), + SM( " max_scf:\s+(?P<scf_max_iteration>{})".format(self.regexs.regex_i)), + SM( " max_scf_history:\s+{}".format(self.regexs.regex_i)), + SM( " max_diis:\s+{}".format(self.regexs.regex_i)), + SM( " eps_scf:\s+(?P<scf_threshold_energy_change>{})".format(self.regexs.regex_f)), ] ), SM( " MP2\|", @@ -428,7 +417,7 @@ class CommonMatcher(object): c_line = parser.fIn.readline() # Define the regex that extracts the components and apply it to the lines - regex_string = r" CELL\| Vector \w \[angstrom\]:\s+({0})\s+({0})\s+({0})".format(self.regex_f) + regex_string = r" CELL\| Vector \w \[angstrom\]:\s+({0})\s+({0})\s+({0})".format(self.regexs.regex_f) regex_compiled = re.compile(regex_string) a_result = regex_compiled.match(a_line) b_result = regex_compiled.match(b_line) @@ -533,7 +522,7 @@ class CommonMatcher(object): def wrapper(parser): # Define the regex that extracts the information - regex_string = r"\s+\d+\s+(\d+)\s+(\w+)\s+\d+\s+({0})\s+({0})\s+({0})".format(self.regex_f) + regex_string = r"\s+\d+\s+(\d+)\s+(\w+)\s+\d+\s+({0})\s+({0})\s+({0})".format(self.regexs.regex_f) regex_compiled = re.compile(regex_string) match = True @@ -610,17 +599,6 @@ class CommonMatcher(object): #=========================================================================== # MISC functions - def getOnCloseTriggers(self): - """ - Returns: - A dictionary containing a section name as a key, and a list of - trigger functions associated with closing that section. - """ - onClose = {} - for attr, callback in extractOnCloseTriggers(self).items(): - onClose[attr] = [callback] - return onClose - def get_atomic_number(self, symbol): """ Returns the atomic number when given the atomic symbol. diff --git a/parser/parser-cp2k/cp2kparser/versions/cp2k262/geooptparser.py b/parser/parser-cp2k/cp2kparser/versions/cp2k262/geooptparser.py index 3f667438b6e0f593ef35d9461c09825b22c09bfa..e586df18bb42f59e33a90999ccbe4f6c009278c7 100644 --- a/parser/parser-cp2k/cp2kparser/versions/cp2k262/geooptparser.py +++ b/parser/parser-cp2k/cp2kparser/versions/cp2k262/geooptparser.py @@ -4,7 +4,7 @@ from builtins import next from builtins import range from nomadcore.simple_parser import SimpleMatcher as SM from nomadcore.baseclasses import MainHierarchicalParser -from .commonmatcher import CommonMatcher +from .commonmatcher import CP2KCommonMatcher import cp2kparser.generic.configurationreading import cp2kparser.generic.csvparsing from nomadcore.caching_backend import CachingLevel @@ -21,7 +21,7 @@ class CP2KGeoOptParser(MainHierarchicalParser): """ """ super(CP2KGeoOptParser, self).__init__(file_path, parser_context) - self.setup_common_matcher(CommonMatcher(parser_context)) + self.setup_common_matcher(CP2KCommonMatcher(parser_context)) self.traj_iterator = None self.energy_reeval_quickstep = None @@ -34,7 +34,7 @@ class CP2KGeoOptParser(MainHierarchicalParser): #======================================================================= # Cache levels - self.caching_level_for_metaname.update({ + self.caching_levels.update({ 'x_cp2k_section_geometry_optimization_step': CachingLevel.ForwardAndCache, 'x_cp2k_section_quickstep_calculation': CachingLevel.ForwardAndCache, 'x_cp2k_section_geometry_optimization': CachingLevel.ForwardAndCache, @@ -65,8 +65,8 @@ class CP2KGeoOptParser(MainHierarchicalParser): # subMatchers=[ # self.cm.quickstep_calculation(), # SM( " -------- Informations at step"), - # SM( " Optimization Method =\s+(?P<x_cp2k_optimization_method>{})".format(self.cm.regex_word)), - # SM( " Total Energy =\s+(?P<x_cp2k_optimization_energy__hartree>{})".format(self.cm.regex_f), + # SM( " Optimization Method =\s+(?P<x_cp2k_optimization_method>{})".format(self.regexs.regex_word)), + # SM( " Total Energy =\s+(?P<x_cp2k_optimization_energy__hartree>{})".format(self.regexs.regex_f), # otherMetaInfo=["frame_sequence_potential_energy"] # ), # ], @@ -87,7 +87,7 @@ class CP2KGeoOptParser(MainHierarchicalParser): subMatchers=[ # SM( "", # forwardMatch=True, - # endReStr=" *** MNBRACK - NUMBER OF ENERGY EVALUATIONS :\s+{}\s+***".replace("*", "\*").format(self.cm.regex_i), + # endReStr=" *** MNBRACK - NUMBER OF ENERGY EVALUATIONS :\s+{}\s+***".replace("*", "\*").format(self.regexs.regex_i), # subMatchers=[ # SM(" SCF WAVEFUNCTION OPTIMIZATION", # forwardMatch=True, @@ -100,7 +100,7 @@ class CP2KGeoOptParser(MainHierarchicalParser): # ), # SM( "", # forwardMatch=True, - # endReStr=" *** BRENT - NUMBER OF ENERGY EVALUATIONS :\s+{}\s+***".replace("*", "\*").format(self.cm.regex_i), + # endReStr=" *** BRENT - NUMBER OF ENERGY EVALUATIONS :\s+{}\s+***".replace("*", "\*").format(self.regexs.regex_i), # subMatchers=[ # SM(" SCF WAVEFUNCTION OPTIMIZATION", # forwardMatch=True, @@ -112,27 +112,27 @@ class CP2KGeoOptParser(MainHierarchicalParser): # ] # ), SM( " -------- Informations at step"), - SM( " Optimization Method =\s+(?P<x_cp2k_optimization_method>{})".format(self.cm.regex_word)), - SM( " Total Energy =\s+(?P<x_cp2k_optimization_energy__hartree>{})".format(self.cm.regex_f), + SM( " Optimization Method =\s+(?P<x_cp2k_optimization_method>{})".format(self.regexs.regex_word)), + SM( " Total Energy =\s+(?P<x_cp2k_optimization_energy__hartree>{})".format(self.regexs.regex_f), otherMetaInfo=["frame_sequence_potential_energy"] ), - SM( " Real energy change =\s+(?P<x_cp2k_optimization_energy_change__hartree>{})".format(self.cm.regex_f)), - SM( " Decrease in energy =\s+(?P<x_cp2k_optimization_energy_decrease>{})".format(self.cm.regex_word)), - SM( " Used time =\s+(?P<x_cp2k_optimization_used_time>{})".format(self.cm.regex_f)), - SM( " Max. step size =\s+(?P<x_cp2k_optimization_max_step_size__bohr>{})".format(self.cm.regex_f)), - SM( " Conv. limit for step size =\s+(?P<x_cp2k_optimization_step_size_convergence_limit__bohr>{})".format(self.cm.regex_f), + SM( " Real energy change =\s+(?P<x_cp2k_optimization_energy_change__hartree>{})".format(self.regexs.regex_f)), + SM( " Decrease in energy =\s+(?P<x_cp2k_optimization_energy_decrease>{})".format(self.regexs.regex_word)), + SM( " Used time =\s+(?P<x_cp2k_optimization_used_time>{})".format(self.regexs.regex_f)), + SM( " Max. step size =\s+(?P<x_cp2k_optimization_max_step_size__bohr>{})".format(self.regexs.regex_f)), + SM( " Conv. limit for step size =\s+(?P<x_cp2k_optimization_step_size_convergence_limit__bohr>{})".format(self.regexs.regex_f), otherMetaInfo=["geometry_optimization_geometry_change"] ), - SM( " Convergence in step size =\s+(?P<x_cp2k_optimization_step_size_convergence>{})".format(self.cm.regex_word)), - SM( " RMS step size =\s+(?P<x_cp2k_optimization_rms_step_size__bohr>{})".format(self.cm.regex_f)), - SM( " Convergence in RMS step =\s+(?P<x_cp2k_optimization_rms_step_size_convergence>{})".format(self.cm.regex_word)), - SM( " Max. gradient =\s+(?P<x_cp2k_optimization_max_gradient__bohr_1hartree>{})".format(self.cm.regex_f)), - SM( " Conv. limit for gradients =\s+(?P<x_cp2k_optimization_gradient_convergence_limit__bohr_1hartree>{})".format(self.cm.regex_f), + SM( " Convergence in step size =\s+(?P<x_cp2k_optimization_step_size_convergence>{})".format(self.regexs.regex_word)), + SM( " RMS step size =\s+(?P<x_cp2k_optimization_rms_step_size__bohr>{})".format(self.regexs.regex_f)), + SM( " Convergence in RMS step =\s+(?P<x_cp2k_optimization_rms_step_size_convergence>{})".format(self.regexs.regex_word)), + SM( " Max. gradient =\s+(?P<x_cp2k_optimization_max_gradient__bohr_1hartree>{})".format(self.regexs.regex_f)), + SM( " Conv. limit for gradients =\s+(?P<x_cp2k_optimization_gradient_convergence_limit__bohr_1hartree>{})".format(self.regexs.regex_f), otherMetaInfo=["geometry_optimization_threshold_force"] ), - SM( " Conv. for gradients =\s+(?P<x_cp2k_optimization_max_gradient_convergence>{})".format(self.cm.regex_word)), - SM( " RMS gradient =\s+(?P<x_cp2k_optimization_rms_gradient__bohr_1hartree>{})".format(self.cm.regex_f)), - SM( " Conv. in RMS gradients =\s+(?P<x_cp2k_optimization_rms_gradient_convergence>{})".format(self.cm.regex_word)), + SM( " Conv. for gradients =\s+(?P<x_cp2k_optimization_max_gradient_convergence>{})".format(self.regexs.regex_word)), + SM( " RMS gradient =\s+(?P<x_cp2k_optimization_rms_gradient__bohr_1hartree>{})".format(self.regexs.regex_f)), + SM( " Conv. in RMS gradients =\s+(?P<x_cp2k_optimization_rms_gradient_convergence>{})".format(self.regexs.regex_word)), ], # adHoc=self.adHoc_step() ), diff --git a/parser/parser-cp2k/cp2kparser/versions/cp2k262/mdparser.py b/parser/parser-cp2k/cp2kparser/versions/cp2k262/mdparser.py index 15e9cd8f268697647335a3507f066b594f79f117..054725e8fd7db003e2c2b699fd793b690de6bb96 100644 --- a/parser/parser-cp2k/cp2kparser/versions/cp2k262/mdparser.py +++ b/parser/parser-cp2k/cp2kparser/versions/cp2k262/mdparser.py @@ -4,7 +4,7 @@ from builtins import range import numpy as np from nomadcore.simple_parser import SimpleMatcher as SM from nomadcore.baseclasses import MainHierarchicalParser -from .commonmatcher import CommonMatcher +from .commonmatcher import CP2KCommonMatcher import cp2kparser.generic.configurationreading import cp2kparser.generic.csvparsing from nomadcore.caching_backend import CachingLevel @@ -23,7 +23,7 @@ class CP2KMDParser(MainHierarchicalParser): """ """ super(CP2KMDParser, self).__init__(file_path, parser_context) - self.setup_common_matcher(CommonMatcher(parser_context)) + self.setup_common_matcher(CP2KCommonMatcher(parser_context)) self.traj_iterator = None self.vel_iterator = None self.energy_iterator = None @@ -42,7 +42,7 @@ class CP2KMDParser(MainHierarchicalParser): #======================================================================= # Cache levels - self.caching_level_for_metaname.update({ + self.caching_levels.update({ 'x_cp2k_section_md_settings': CachingLevel.ForwardAndCache, 'x_cp2k_section_md_step': CachingLevel.ForwardAndCache, 'x_cp2k_section_quickstep_calculation': CachingLevel.ForwardAndCache, @@ -61,20 +61,20 @@ class CP2KMDParser(MainHierarchicalParser): forwardMatch=True, sections=["section_sampling_method", "x_cp2k_section_md_settings"], subMatchers=[ - SM( " MD\| Ensemble Type\s+(?P<x_cp2k_md_ensemble_type>{})".format(self.cm.regex_word)), - SM( " MD\| Number of Time Steps\s+(?P<x_cp2k_md_number_of_time_steps>{})".format(self.cm.regex_i)), - SM( " MD\| Time Step \[fs\]\s+(?P<x_cp2k_md_time_step__fs>{})".format(self.cm.regex_f)), - SM( " MD\| Temperature \[K\]\s+(?P<x_cp2k_md_target_temperature>{})".format(self.cm.regex_f)), - SM( " MD\| Temperature tolerance \[K\]\s+(?P<x_cp2k_md_target_temperature_tolerance>{})".format(self.cm.regex_f)), - SM( " MD\| Pressure \[Bar\]\s+(?P<x_cp2k_md_target_pressure>{})".format(self.cm.regex_f)), - SM( " MD\| Barostat time constant \[ fs\]\s+(?P<x_cp2k_md_barostat_time_constant>{})".format(self.cm.regex_f)), - SM( " MD\| Print MD information every\s+(?P<x_cp2k_md_print_frequency>{}) step\(s\)".format(self.cm.regex_i)), + SM( " MD\| Ensemble Type\s+(?P<x_cp2k_md_ensemble_type>{})".format(self.regexs.regex_word)), + SM( " MD\| Number of Time Steps\s+(?P<x_cp2k_md_number_of_time_steps>{})".format(self.regexs.regex_i)), + SM( " MD\| Time Step \[fs\]\s+(?P<x_cp2k_md_time_step__fs>{})".format(self.regexs.regex_f)), + SM( " MD\| Temperature \[K\]\s+(?P<x_cp2k_md_target_temperature>{})".format(self.regexs.regex_f)), + SM( " MD\| Temperature tolerance \[K\]\s+(?P<x_cp2k_md_target_temperature_tolerance>{})".format(self.regexs.regex_f)), + SM( " MD\| Pressure \[Bar\]\s+(?P<x_cp2k_md_target_pressure>{})".format(self.regexs.regex_f)), + SM( " MD\| Barostat time constant \[ fs\]\s+(?P<x_cp2k_md_barostat_time_constant>{})".format(self.regexs.regex_f)), + SM( " MD\| Print MD information every\s+(?P<x_cp2k_md_print_frequency>{}) step\(s\)".format(self.regexs.regex_i)), SM( " MD\| File type Print frequency\[steps\] File names"), - SM( " MD\| Coordinates\s+(?P<x_cp2k_md_coordinates_print_frequency>{})\s+(?P<x_cp2k_md_coordinates_filename>{})".format(self.cm.regex_i, self.cm.regex_word)), - SM( " MD\| Simulation Cel\s+(?P<x_cp2k_md_simulation_cell_print_frequency>{})\s+(?P<x_cp2k_md_simulation_cell_filename>{})".format(self.cm.regex_i, self.cm.regex_word)), - SM( " MD\| Velocities\s+(?P<x_cp2k_md_velocities_print_frequency>{})\s+(?P<x_cp2k_md_velocities_filename>{})".format(self.cm.regex_i, self.cm.regex_word)), - SM( " MD\| Energies\s+(?P<x_cp2k_md_energies_print_frequency>{})\s+(?P<x_cp2k_md_energies_filename>{})".format(self.cm.regex_i, self.cm.regex_word)), - SM( " MD\| Dump\s+(?P<x_cp2k_md_dump_print_frequency>{})\s+(?P<x_cp2k_md_dump_filename>{})".format(self.cm.regex_i, self.cm.regex_word)), + SM( " MD\| Coordinates\s+(?P<x_cp2k_md_coordinates_print_frequency>{})\s+(?P<x_cp2k_md_coordinates_filename>{})".format(self.regexs.regex_i, self.regexs.regex_word)), + SM( " MD\| Simulation Cel\s+(?P<x_cp2k_md_simulation_cell_print_frequency>{})\s+(?P<x_cp2k_md_simulation_cell_filename>{})".format(self.regexs.regex_i, self.regexs.regex_word)), + SM( " MD\| Velocities\s+(?P<x_cp2k_md_velocities_print_frequency>{})\s+(?P<x_cp2k_md_velocities_filename>{})".format(self.regexs.regex_i, self.regexs.regex_word)), + SM( " MD\| Energies\s+(?P<x_cp2k_md_energies_print_frequency>{})\s+(?P<x_cp2k_md_energies_filename>{})".format(self.regexs.regex_i, self.regexs.regex_word)), + SM( " MD\| Dump\s+(?P<x_cp2k_md_dump_print_frequency>{})\s+(?P<x_cp2k_md_dump_filename>{})".format(self.regexs.regex_i, self.regexs.regex_word)), ] ), SM( " ************************** Velocities initialization **************************".replace("*", "\*"), @@ -84,14 +84,14 @@ class CP2KMDParser(MainHierarchicalParser): subMatchers=[ self.cm.quickstep_calculation(), SM( " ******************************** GO CP2K GO! **********************************".replace("*", "\*")), - SM( " INITIAL POTENTIAL ENERGY\[hartree\] =\s+(?P<x_cp2k_md_potential_energy_instantaneous__hartree>{})".format(self.cm.regex_f)), - SM( " INITIAL KINETIC ENERGY\[hartree\] =\s+(?P<x_cp2k_md_kinetic_energy_instantaneous__hartree>{})".format(self.cm.regex_f)), - SM( " INITIAL TEMPERATURE\[K\] =\s+(?P<x_cp2k_md_temperature_instantaneous>{})".format(self.cm.regex_f)), - SM( " INITIAL BAROSTAT TEMP\[K\] =\s+(?P<x_cp2k_md_barostat_temperature_instantaneous>{})".format(self.cm.regex_f)), - SM( " INITIAL PRESSURE\[bar\] =\s+(?P<x_cp2k_md_pressure_instantaneous__bar>{})".format(self.cm.regex_f)), - SM( " INITIAL VOLUME\[bohr\^3\] =\s+(?P<x_cp2k_md_volume_instantaneous__bohr3>{})".format(self.cm.regex_f)), - SM( " INITIAL CELL LNTHS\[bohr\] =\s+(?P<x_cp2k_md_cell_length_a_instantaneous__bohr>{0})\s+(?P<x_cp2k_md_cell_length_b_instantaneous__bohr>{0})\s+(?P<x_cp2k_md_cell_length_c_instantaneous__bohr>{0})".format(self.cm.regex_f)), - SM( " INITIAL CELL ANGLS\[deg\] =\s+(?P<x_cp2k_md_cell_angle_a_instantaneous__deg>{0})\s+(?P<x_cp2k_md_cell_angle_b_instantaneous__deg>{0})\s+(?P<x_cp2k_md_cell_angle_c_instantaneous__deg>{0})".format(self.cm.regex_f)), + SM( " INITIAL POTENTIAL ENERGY\[hartree\] =\s+(?P<x_cp2k_md_potential_energy_instantaneous__hartree>{})".format(self.regexs.regex_f)), + SM( " INITIAL KINETIC ENERGY\[hartree\] =\s+(?P<x_cp2k_md_kinetic_energy_instantaneous__hartree>{})".format(self.regexs.regex_f)), + SM( " INITIAL TEMPERATURE\[K\] =\s+(?P<x_cp2k_md_temperature_instantaneous>{})".format(self.regexs.regex_f)), + SM( " INITIAL BAROSTAT TEMP\[K\] =\s+(?P<x_cp2k_md_barostat_temperature_instantaneous>{})".format(self.regexs.regex_f)), + SM( " INITIAL PRESSURE\[bar\] =\s+(?P<x_cp2k_md_pressure_instantaneous__bar>{})".format(self.regexs.regex_f)), + SM( " INITIAL VOLUME\[bohr\^3\] =\s+(?P<x_cp2k_md_volume_instantaneous__bohr3>{})".format(self.regexs.regex_f)), + SM( " INITIAL CELL LNTHS\[bohr\] =\s+(?P<x_cp2k_md_cell_length_a_instantaneous__bohr>{0})\s+(?P<x_cp2k_md_cell_length_b_instantaneous__bohr>{0})\s+(?P<x_cp2k_md_cell_length_c_instantaneous__bohr>{0})".format(self.regexs.regex_f)), + SM( " INITIAL CELL ANGLS\[deg\] =\s+(?P<x_cp2k_md_cell_angle_a_instantaneous__deg>{0})\s+(?P<x_cp2k_md_cell_angle_b_instantaneous__deg>{0})\s+(?P<x_cp2k_md_cell_angle_c_instantaneous__deg>{0})".format(self.regexs.regex_f)), ], adHoc=self.adHoc_save_md_quickstep() ), @@ -105,20 +105,20 @@ class CP2KMDParser(MainHierarchicalParser): self.cm.quickstep_calculation(), SM( " ENSEMBLE TYPE ="), SM( " STEP NUMBER ="), - SM( " TIME \[fs\] =\s+(?P<x_cp2k_md_time__fs>{})".format(self.cm.regex_f)), - SM( " CONSERVED QUANTITY \[hartree\] =\s+(?P<x_cp2k_md_conserved_quantity__hartree>{})".format(self.cm.regex_f)), - SM( " CPU TIME \[s\] =\s+(?P<x_cp2k_md_cpu_time_instantaneous>{})\s+(?P<x_cp2k_md_cpu_time_average>{})".format(self.cm.regex_f, self.cm.regex_f)), - SM( " ENERGY DRIFT PER ATOM \[K\] =\s+(?P<x_cp2k_md_energy_drift_instantaneous>{})\s+(?P<x_cp2k_md_energy_drift_average>{})".format(self.cm.regex_f, self.cm.regex_f)), - SM( " POTENTIAL ENERGY\[hartree\] =\s+(?P<x_cp2k_md_potential_energy_instantaneous__hartree>{})\s+(?P<x_cp2k_md_potential_energy_average__hartree>{})".format(self.cm.regex_f, self.cm.regex_f)), - SM( " KINETIC ENERGY \[hartree\] =\s+(?P<x_cp2k_md_kinetic_energy_instantaneous__hartree>{})\s+(?P<x_cp2k_md_kinetic_energy_average__hartree>{})".format(self.cm.regex_f, self.cm.regex_f)), - SM( " TEMPERATURE \[K\] =\s+(?P<x_cp2k_md_temperature_instantaneous>{})\s+(?P<x_cp2k_md_temperature_average>{})".format(self.cm.regex_f, self.cm.regex_f)), - SM( " PRESSURE \[bar\] =\s+(?P<x_cp2k_md_pressure_instantaneous__bar>{0})\s+(?P<x_cp2k_md_pressure_average__bar>{0})".format(self.cm.regex_f)), - SM( " BAROSTAT TEMP\[K\] =\s+(?P<x_cp2k_md_barostat_temperature_instantaneous>{0})\s+(?P<x_cp2k_md_barostat_temperature_average>{0})".format(self.cm.regex_f)), - SM( " VOLUME\[bohr\^3\] =\s+(?P<x_cp2k_md_volume_instantaneous__bohr3>{0})\s+(?P<x_cp2k_md_volume_average__bohr3>{0})".format(self.cm.regex_f)), - SM( " CELL LNTHS\[bohr\] =\s+(?P<x_cp2k_md_cell_length_a_instantaneous__bohr>{0})\s+(?P<x_cp2k_md_cell_length_b_instantaneous__bohr>{0})\s+(?P<x_cp2k_md_cell_length_c_instantaneous__bohr>{0})".format(self.cm.regex_f)), - SM( " AVE. CELL LNTHS\[bohr\] =\s+(?P<x_cp2k_md_cell_length_a_average__bohr>{0})\s+(?P<x_cp2k_md_cell_length_b_average__bohr>{0})\s+(?P<x_cp2k_md_cell_length_c_average__bohr>{0})".format(self.cm.regex_f)), - SM( " CELL ANGLS\[deg\] =\s+(?P<x_cp2k_md_cell_angle_a_instantaneous__deg>{0})\s+(?P<x_cp2k_md_cell_angle_b_instantaneous__deg>{0})\s+(?P<x_cp2k_md_cell_angle_c_instantaneous__deg>{0})".format(self.cm.regex_f)), - SM( " AVE. CELL ANGLS\[deg\] =\s+(?P<x_cp2k_md_cell_angle_a_average__deg>{0})\s+(?P<x_cp2k_md_cell_angle_b_average__deg>{0})\s+(?P<x_cp2k_md_cell_angle_c_average__deg>{0})".format(self.cm.regex_f)), + SM( " TIME \[fs\] =\s+(?P<x_cp2k_md_time__fs>{})".format(self.regexs.regex_f)), + SM( " CONSERVED QUANTITY \[hartree\] =\s+(?P<x_cp2k_md_conserved_quantity__hartree>{})".format(self.regexs.regex_f)), + SM( " CPU TIME \[s\] =\s+(?P<x_cp2k_md_cpu_time_instantaneous>{})\s+(?P<x_cp2k_md_cpu_time_average>{})".format(self.regexs.regex_f, self.regexs.regex_f)), + SM( " ENERGY DRIFT PER ATOM \[K\] =\s+(?P<x_cp2k_md_energy_drift_instantaneous>{})\s+(?P<x_cp2k_md_energy_drift_average>{})".format(self.regexs.regex_f, self.regexs.regex_f)), + SM( " POTENTIAL ENERGY\[hartree\] =\s+(?P<x_cp2k_md_potential_energy_instantaneous__hartree>{})\s+(?P<x_cp2k_md_potential_energy_average__hartree>{})".format(self.regexs.regex_f, self.regexs.regex_f)), + SM( " KINETIC ENERGY \[hartree\] =\s+(?P<x_cp2k_md_kinetic_energy_instantaneous__hartree>{})\s+(?P<x_cp2k_md_kinetic_energy_average__hartree>{})".format(self.regexs.regex_f, self.regexs.regex_f)), + SM( " TEMPERATURE \[K\] =\s+(?P<x_cp2k_md_temperature_instantaneous>{})\s+(?P<x_cp2k_md_temperature_average>{})".format(self.regexs.regex_f, self.regexs.regex_f)), + SM( " PRESSURE \[bar\] =\s+(?P<x_cp2k_md_pressure_instantaneous__bar>{0})\s+(?P<x_cp2k_md_pressure_average__bar>{0})".format(self.regexs.regex_f)), + SM( " BAROSTAT TEMP\[K\] =\s+(?P<x_cp2k_md_barostat_temperature_instantaneous>{0})\s+(?P<x_cp2k_md_barostat_temperature_average>{0})".format(self.regexs.regex_f)), + SM( " VOLUME\[bohr\^3\] =\s+(?P<x_cp2k_md_volume_instantaneous__bohr3>{0})\s+(?P<x_cp2k_md_volume_average__bohr3>{0})".format(self.regexs.regex_f)), + SM( " CELL LNTHS\[bohr\] =\s+(?P<x_cp2k_md_cell_length_a_instantaneous__bohr>{0})\s+(?P<x_cp2k_md_cell_length_b_instantaneous__bohr>{0})\s+(?P<x_cp2k_md_cell_length_c_instantaneous__bohr>{0})".format(self.regexs.regex_f)), + SM( " AVE. CELL LNTHS\[bohr\] =\s+(?P<x_cp2k_md_cell_length_a_average__bohr>{0})\s+(?P<x_cp2k_md_cell_length_b_average__bohr>{0})\s+(?P<x_cp2k_md_cell_length_c_average__bohr>{0})".format(self.regexs.regex_f)), + SM( " CELL ANGLS\[deg\] =\s+(?P<x_cp2k_md_cell_angle_a_instantaneous__deg>{0})\s+(?P<x_cp2k_md_cell_angle_b_instantaneous__deg>{0})\s+(?P<x_cp2k_md_cell_angle_c_instantaneous__deg>{0})".format(self.regexs.regex_f)), + SM( " AVE. CELL ANGLS\[deg\] =\s+(?P<x_cp2k_md_cell_angle_a_average__deg>{0})\s+(?P<x_cp2k_md_cell_angle_b_average__deg>{0})\s+(?P<x_cp2k_md_cell_angle_c_average__deg>{0})".format(self.regexs.regex_f)), ], adHoc=self.adHoc_save_md_quickstep() ), diff --git a/parser/parser-cp2k/cp2kparser/versions/cp2k262/singlepointparser.py b/parser/parser-cp2k/cp2kparser/versions/cp2k262/singlepointparser.py index 2a0bc1b8a5341c317db5aa3b2a82ac97dc2be3f7..29a3913dfa90f3b76227ac57cf65ef0528919a28 100644 --- a/parser/parser-cp2k/cp2kparser/versions/cp2k262/singlepointparser.py +++ b/parser/parser-cp2k/cp2kparser/versions/cp2k262/singlepointparser.py @@ -3,7 +3,7 @@ from nomadcore.simple_parser import SimpleMatcher as SM from nomadcore.baseclasses import MainHierarchicalParser from .singlepointforceparser import CP2KSinglePointForceParser from nomadcore.caching_backend import CachingLevel -from .commonmatcher import CommonMatcher +from .commonmatcher import CP2KCommonMatcher import logging logger = logging.getLogger("nomad") @@ -18,11 +18,11 @@ class CP2KSinglePointParser(MainHierarchicalParser): """ """ super(CP2KSinglePointParser, self).__init__(file_path, parser_context) - self.setup_common_matcher(CommonMatcher(parser_context)) + self.setup_common_matcher(CP2KCommonMatcher(parser_context)) #======================================================================= # Cache levels - self.caching_level_for_metaname.update({ + self.caching_levels.update({ 'x_cp2k_energy_total_scf_iteration': CachingLevel.ForwardAndCache, 'x_cp2k_energy_XC_scf_iteration': CachingLevel.ForwardAndCache, 'x_cp2k_energy_change_scf_iteration': CachingLevel.ForwardAndCache, diff --git a/parser/parser-cp2k/cp2kparser/versions/versionsetup.py b/parser/parser-cp2k/cp2kparser/versions/versionsetup.py deleted file mode 100644 index 6bbd36446678b2e1f49b59fbeea2c89f32578be9..0000000000000000000000000000000000000000 --- a/parser/parser-cp2k/cp2kparser/versions/versionsetup.py +++ /dev/null @@ -1,62 +0,0 @@ -import importlib -import logging -logger = logging.getLogger("nomad") - - -#=============================================================================== -def get_main_parser(version_id, run_type): - """ - Setups a main parser class for this calculation. The main class can be - different for each version and run type. - - Args: - version_id: An integer representing the CP2K version. The version - number is originally a string the form '2.6.2', but here the numbers - are just concatenated into a single integer number 262. - run_type: A string that identifies the RUN_TYPE for the calculation. - All the possible run types can be found in the CP2K reference manual. - - Returns: - A python class that should be instantiated later with the correct - parameters. - """ - - # Search for a RUN_TYPE specific parser - parser_map = { - "ENERGY": "SinglePointParser", - "ENERGY_FORCE": "SinglePointParser", - "WAVEFUNCTION_OPTIMIZATION": "SinglePointParser", - "WFN_OPT": "SinglePointParser", - "GEO_OPT": "GeoOptParser", - "GEOMETRY_OPTIMIZATION": "GeoOptParser", - "MD": "MDParser", - "MOLECULAR_DYNAMICS": "MDParser", - } - try: - parser = parser_map[run_type] - except KeyError: - logger.exception("A parser corresponding to the run_type '{}' could not be found.".format(run_type)) - raise - - # Currently the version id is a pure integer, so it can directly be mapped - # into a package name. - base = "cp2kparser.versions.cp2k{}.{}".format(version_id, parser.lower()) - parser_module = None - parser_class = None - try: - parser_module = importlib.import_module(base) - except ImportError: - logger.warning("Could not find a parser for version '{}' and run type '{}'. Trying to default to the base implementation for CP2K 2.6.2".format(version_id, run_type)) - base = "cp2kparser.versions.cp2k262.{}".format(parser.lower()) - try: - parser_module = importlib.import_module(base) - except ImportError: - logger.exception("Tried to default to the CP2K 2.6.2 implementation but could not find the correct modules for run_type '{}'.".format(run_type)) - raise - try: - parser_class = getattr(parser_module, "CP2K{}".format(parser)) - except AttributeError: - logger.exception("A parser class '{}' could not be found in the module '[]'.".format(parser_class, parser_module)) - raise - - return parser_class diff --git a/test/unittests/cp2k_2.6.2/run_tests.py b/test/unittests/cp2k_2.6.2/run_tests.py index 5c1c3d69e32f07fffff75ae946d292cacd022864..2cb0d12529c062c8cefdaa01d45b723f067c6a7c 100644 --- a/test/unittests/cp2k_2.6.2/run_tests.py +++ b/test/unittests/cp2k_2.6.2/run_tests.py @@ -1030,21 +1030,21 @@ if __name__ == '__main__': logger.setLevel(logging.ERROR) suites = [] - # suites.append(unittest.TestLoader().loadTestsFromTestCase(TestErrors)) - # suites.append(unittest.TestLoader().loadTestsFromTestCase(TestXCFunctional)) + suites.append(unittest.TestLoader().loadTestsFromTestCase(TestErrors)) + suites.append(unittest.TestLoader().loadTestsFromTestCase(TestXCFunctional)) suites.append(unittest.TestLoader().loadTestsFromTestCase(TestEnergyForce)) - # suites.append(unittest.TestLoader().loadTestsFromTestCase(TestStressTensorMethods)) - # suites.append(unittest.TestLoader().loadTestsFromTestCase(TestSelfInteractionCorrectionMethod)) - # suites.append(unittest.TestLoader().loadTestsFromTestCase(TestConfigurationPeriodicDimensions)) - # suites.append(unittest.TestLoader().loadTestsFromTestCase(TestSCFConvergence)) - # suites.append(unittest.TestLoader().loadTestsFromTestCase(TestForceFiles)) - # suites.append(unittest.TestLoader().loadTestsFromTestCase(TestPreprocessor)) - # suites.append(unittest.TestLoader().loadTestsFromTestCase(TestGeoOpt)) - # suites.append(unittest.TestLoader().loadTestsFromTestCase(TestGeoOptTrajFormats)) - # suites.append(unittest.TestLoader().loadTestsFromTestCase(TestGeoOptOptimizers)) - # suites.append(unittest.TestLoader().loadTestsFromTestCase(TestGeoOptTrajectory)) - # suites.append(unittest.TestLoader().loadTestsFromTestCase(TestMD)) - # suites.append(unittest.TestLoader().loadTestsFromTestCase(TestMDEnsembles)) - # suites.append(unittest.TestLoader().loadTestsFromTestCase(TestElectronicStructureMethod)) + suites.append(unittest.TestLoader().loadTestsFromTestCase(TestStressTensorMethods)) + suites.append(unittest.TestLoader().loadTestsFromTestCase(TestSelfInteractionCorrectionMethod)) + suites.append(unittest.TestLoader().loadTestsFromTestCase(TestConfigurationPeriodicDimensions)) + suites.append(unittest.TestLoader().loadTestsFromTestCase(TestSCFConvergence)) + suites.append(unittest.TestLoader().loadTestsFromTestCase(TestForceFiles)) + suites.append(unittest.TestLoader().loadTestsFromTestCase(TestPreprocessor)) + suites.append(unittest.TestLoader().loadTestsFromTestCase(TestGeoOpt)) + suites.append(unittest.TestLoader().loadTestsFromTestCase(TestGeoOptTrajFormats)) + suites.append(unittest.TestLoader().loadTestsFromTestCase(TestGeoOptOptimizers)) + suites.append(unittest.TestLoader().loadTestsFromTestCase(TestGeoOptTrajectory)) + suites.append(unittest.TestLoader().loadTestsFromTestCase(TestMD)) + suites.append(unittest.TestLoader().loadTestsFromTestCase(TestMDEnsembles)) + suites.append(unittest.TestLoader().loadTestsFromTestCase(TestElectronicStructureMethod)) alltests = unittest.TestSuite(suites) unittest.TextTestRunner(verbosity=0).run(alltests)