Commit 8adef6d3 authored by Lauri Himanen's avatar Lauri Himanen
Browse files

Minor refactoring in order to normalize how the Aalto parsers are structured.

parent 12b7f80f
......@@ -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)
......@@ -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()
),
......
......@@ -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()
),
......
......@@ -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,
......
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
......@@ -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)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment