Commit c8fbaf28 authored by Lauri Himanen's avatar Lauri Himanen
Browse files

Created new cp2k specific metainfo for the quickstep calculation which required some modifications.

parent f4e2a529
#===============================================================================
def try_to_add_value(backend, section, source_name, destination_name):
original = section[source_name]
if original is not None:
backend.addValue(destination_name, original[0])
#===============================================================================
def try_to_add_array_values(backend, section, source_name, destination_name, unit=None):
original = section[source_name]
if original is not None:
backend.addArrayValues(destination_name, original[0])
...@@ -19,6 +19,7 @@ class CommonMatcher(object): ...@@ -19,6 +19,7 @@ class CommonMatcher(object):
# Repeating regex definitions # Repeating regex definitions
self.parser_context = parser_context self.parser_context = parser_context
self.backend = parser_context.caching_backend
self.file_service = parser_context.file_service self.file_service = parser_context.file_service
self.cache_service = parser_context.cache_service self.cache_service = parser_context.cache_service
self.regex_f = "-?\d+\.\d+(?:E(?:\+|-)\d+)?" # Regex for a floating point value self.regex_f = "-?\d+\.\d+(?:E(?:\+|-)\d+)?" # Regex for a floating point value
...@@ -26,7 +27,6 @@ class CommonMatcher(object): ...@@ -26,7 +27,6 @@ class CommonMatcher(object):
self.regex_word = "[^\s]+" # Regex for a single word. Can contain anything else but whitespace self.regex_word = "[^\s]+" # Regex for a single word. Can contain anything else but whitespace
self.section_method_index = None self.section_method_index = None
self.section_system_index = None self.section_system_index = None
self.forces = None
#======================================================================= #=======================================================================
# Cache levels # Cache levels
...@@ -34,15 +34,6 @@ class CommonMatcher(object): ...@@ -34,15 +34,6 @@ class CommonMatcher(object):
'x_cp2k_atoms': CachingLevel.ForwardAndCache, 'x_cp2k_atoms': CachingLevel.ForwardAndCache,
'section_XC_functionals': CachingLevel.ForwardAndCache, 'section_XC_functionals': CachingLevel.ForwardAndCache,
'self_interaction_correction_method': CachingLevel.Cache, 'self_interaction_correction_method': CachingLevel.Cache,
'x_cp2k_section_md_coordinates': CachingLevel.Cache,
'x_cp2k_section_md_coordinate_atom': CachingLevel.Cache,
'x_cp2k_md_coordinate_atom_string': CachingLevel.Cache,
'x_cp2k_md_coordinate_atom_float': CachingLevel.Cache,
'x_cp2k_section_md_forces': CachingLevel.Cache,
'x_cp2k_section_md_force_atom': CachingLevel.Cache,
'x_cp2k_md_force_atom_string': CachingLevel.Cache,
'x_cp2k_md_force_atom_float': CachingLevel.Cache,
} }
#======================================================================= #=======================================================================
...@@ -135,15 +126,16 @@ class CommonMatcher(object): ...@@ -135,15 +126,16 @@ class CommonMatcher(object):
) )
# SimpleMatcher for an SCF wavefunction optimization # SimpleMatcher for an SCF wavefunction optimization
def scf(self): def quickstep_calculation(self):
return SM( " SCF WAVEFUNCTION OPTIMIZATION", return SM( " SCF WAVEFUNCTION OPTIMIZATION",
sections=["x_cp2k_section_quickstep_calculation"],
subMatchers=[ subMatchers=[
SM( r" Trace\(PS\):", SM( r" Trace\(PS\):",
sections=["section_scf_iteration"], sections=["x_cp2k_section_scf_iteration"],
repeats=True, repeats=True,
subMatchers=[ subMatchers=[
SM( r" Exchange-correlation energy:\s+(?P<energy_XC_scf_iteration__hartree>{})".format(self.regex_f)), 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<energy_total_scf_iteration__hartree>{0})\s+(?P<energy_change_scf_iteration__hartree>{0})".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" \*\*\* SCF run converged in\s+(\d+) steps \*\*\*", SM( r" \*\*\* SCF run converged in\s+(\d+) steps \*\*\*",
...@@ -154,22 +146,25 @@ class CommonMatcher(object): ...@@ -154,22 +146,25 @@ class CommonMatcher(object):
otherMetaInfo=["single_configuration_calculation_converged"], otherMetaInfo=["single_configuration_calculation_converged"],
adHoc=self.adHoc_single_point_not_converged() adHoc=self.adHoc_single_point_not_converged()
), ),
SM( r" Electronic kinetic energy:\s+(?P<electronic_kinetic_energy__hartree>{})".format(self.regex_f)), SM( r" Electronic kinetic energy:\s+(?P<x_cp2k_electronic_kinetic_energy__hartree>{})".format(self.regex_f)),
SM( r" **************************** NUMERICAL STRESS ********************************".replace("*", "\*"), SM( r" **************************** NUMERICAL STRESS ********************************".replace("*", "\*"),
# endReStr=" **************************** NUMERICAL STRESS END *****************************".replace("*", "\*"),
adHoc=self.adHoc_stress_calculation(), adHoc=self.adHoc_stress_calculation(),
), ),
SM( r" ENERGY\| Total FORCE_EVAL \( \w+ \) energy \(a\.u\.\):\s+(?P<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.regex_f),
otherMetaInfo=["energy_total"],
),
SM( r" ATOMIC FORCES in \[a\.u\.\]"), SM( r" ATOMIC FORCES in \[a\.u\.\]"),
SM( r" # Atom Kind Element X Y Z", SM( r" # Atom Kind Element X Y Z",
adHoc=self.adHoc_atom_forces(), adHoc=self.adHoc_atom_forces(),
otherMetaInfo=["atom_forces"], otherMetaInfo=["atom_forces", "x_cp2k_atom_forces"],
), ),
SM( r" (?:NUMERICAL )?STRESS TENSOR \[GPa\]", SM( r" (?:NUMERICAL )?STRESS TENSOR \[GPa\]",
sections=["section_stress_tensor"], sections=["x_cp2k_section_stress_tensor"],
otherMetaInfo=["stress_tensor"],
subMatchers=[ subMatchers=[
SM( r"\s+X\s+Y\s+Z", SM( r"\s+X\s+Y\s+Z",
adHoc=self.adHoc_stress_tensor() 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( " 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( " Det\(stress tensor\)\s+:\s+(?P<x_cp2k_stress_tensor_determinant__GPa3>{})".format(self.regex_f)),
...@@ -181,7 +176,7 @@ class CommonMatcher(object): ...@@ -181,7 +176,7 @@ class CommonMatcher(object):
) )
# SimpleMatcher for an SCF wavefunction optimization # SimpleMatcher for an SCF wavefunction optimization
def quickstep(self): def quickstep_header(self):
return SM( return SM(
" MODULE QUICKSTEP: ATOMIC COORDINATES IN angstrom", " MODULE QUICKSTEP: ATOMIC COORDINATES IN angstrom",
forwardMatch=True, forwardMatch=True,
...@@ -195,10 +190,6 @@ class CommonMatcher(object): ...@@ -195,10 +190,6 @@ class CommonMatcher(object):
#=========================================================================== #===========================================================================
# onClose triggers # onClose triggers
def onClose_section_scf_iteration(self, backend, gIndex, section):
"""Keep track of how many SCF iteration are made."""
self.cache_service["number_of_scf_iterations"] += 1
def onClose_x_cp2k_section_total_numbers(self, backend, gIndex, section): def onClose_x_cp2k_section_total_numbers(self, backend, gIndex, section):
"""Keep track of how many SCF iteration are made.""" """Keep track of how many SCF iteration are made."""
number_of_atoms = section["x_cp2k_atoms"][0] number_of_atoms = section["x_cp2k_atoms"][0]
...@@ -254,13 +245,14 @@ class CommonMatcher(object): ...@@ -254,13 +245,14 @@ class CommonMatcher(object):
let's get it dynamically just in case there's something wrong. let's get it dynamically just in case there's something wrong.
""" """
self.section_system_index = gIndex self.section_system_index = gIndex
if self.forces is not None: # if self.forces is not None:
backend.addArrayValues("atom_forces", self.forces, unit="forceAu") # backend.addArrayValues("atom_forces", self.forces, unit="forceAu")
self.forces = None # self.forces = None
self.cache_service.push_value("number_of_atoms") self.cache_service.push_value("number_of_atoms")
self.cache_service.push_array_values("simulation_cell", unit="angstrom") self.cache_service.push_array_values("simulation_cell", unit="angstrom")
self.cache_service.push_array_values("configuration_periodic_dimensions") self.cache_service.push_array_values("configuration_periodic_dimensions")
self.cache_service.push_array_values("atom_positions", unit="angstrom") self.cache_service.push_array_values("atom_positions", unit="angstrom")
# self.cache_service.push_array_values("atom_forces", unit="forceAu")
self.cache_service.push_array_values("atom_labels") self.cache_service.push_array_values("atom_labels")
def onClose_section_single_configuration_calculation(self, backend, gIndex, section): def onClose_section_single_configuration_calculation(self, backend, gIndex, section):
...@@ -321,7 +313,8 @@ class CommonMatcher(object): ...@@ -321,7 +313,8 @@ class CommonMatcher(object):
# If anything found, push the results to the correct section # If anything found, push the results to the correct section
if len(force_array) != 0: if len(force_array) != 0:
self.forces = force_array # self.cache_service["atom_forces"] = force_array
self.backend.addArrayValues("x_cp2k_atom_forces", force_array, unit="forceAu")
return wrapper return wrapper
...@@ -334,7 +327,7 @@ class CommonMatcher(object): ...@@ -334,7 +327,7 @@ class CommonMatcher(object):
row2 = [float(x) for x in parser.fIn.readline().split()[-3:]] row2 = [float(x) for x in parser.fIn.readline().split()[-3:]]
row3 = [float(x) for x in parser.fIn.readline().split()[-3:]] row3 = [float(x) for x in parser.fIn.readline().split()[-3:]]
stress_array = np.array([row1, row2, row3]) stress_array = np.array([row1, row2, row3])
parser.backend.addArrayValues("stress_tensor", stress_array, unit="GPa") parser.backend.addArrayValues("x_cp2k_stress_tensor", stress_array, unit="GPa")
return wrapper return wrapper
...@@ -369,14 +362,14 @@ class CommonMatcher(object): ...@@ -369,14 +362,14 @@ class CommonMatcher(object):
"""Called when the SCF cycle of a single point calculation has converged. """Called when the SCF cycle of a single point calculation has converged.
""" """
def wrapper(parser): def wrapper(parser):
parser.backend.addValue("single_configuration_calculation_converged", True) parser.backend.addValue("x_cp2k_quickstep_converged", True)
return wrapper return wrapper
def adHoc_single_point_not_converged(self): def adHoc_single_point_not_converged(self):
"""Called when the SCF cycle of a single point calculation did not converge. """Called when the SCF cycle of a single point calculation did not converge.
""" """
def wrapper(parser): def wrapper(parser):
parser.backend.addValue("single_configuration_calculation_converged", False) parser.backend.addValue("x_cp2k_quickstep_converged", False)
return wrapper return wrapper
def adHoc_x_cp2k_section_quickstep_atom_information(self): def adHoc_x_cp2k_section_quickstep_atom_information(self):
...@@ -420,6 +413,11 @@ class CommonMatcher(object): ...@@ -420,6 +413,11 @@ class CommonMatcher(object):
return wrapper return wrapper
def debug(self):
def wrapper(parser):
print "FOUND"
return wrapper
#=========================================================================== #===========================================================================
def getOnCloseTriggers(self): def getOnCloseTriggers(self):
""" """
......
...@@ -6,6 +6,8 @@ import cp2kparser.generic.csvparsing ...@@ -6,6 +6,8 @@ import cp2kparser.generic.csvparsing
from nomadcore.caching_backend import CachingLevel from nomadcore.caching_backend import CachingLevel
import logging import logging
import ase.io import ase.io
import numpy as np
import math
logger = logging.getLogger("nomad") logger = logging.getLogger("nomad")
...@@ -30,80 +32,83 @@ class CP2KGeoOptParser(MainHierarchicalParser): ...@@ -30,80 +32,83 @@ class CP2KGeoOptParser(MainHierarchicalParser):
# Cache levels # Cache levels
self.caching_level_for_metaname.update({ self.caching_level_for_metaname.update({
'x_cp2k_optimization_energy': CachingLevel.ForwardAndCache, 'x_cp2k_optimization_energy': CachingLevel.ForwardAndCache,
'x_cp2k_optimization_step_size_convergence_limit': CachingLevel.ForwardAndCache, 'x_cp2k_section_geometry_optimization_step': CachingLevel.ForwardAndCache,
'x_cp2k_section_geometry_optimization_information': CachingLevel.ForwardAndCache, 'x_cp2k_section_quickstep_calculation': CachingLevel.ForwardAndCache,
'x_cp2k_section_geometry_optimization': CachingLevel.ForwardAndCache,
'x_cp2k_section_geometry_optimization_energy_reevaluation': CachingLevel.ForwardAndCache,
}) })
#======================================================================= #=======================================================================
# SimpleMatchers # SimpleMatchers
self.geo_opt = SM( self.geo_opt = SM(
" *** STARTING GEOMETRY OPTIMIZATION ***".replace("*", "\*"), " *** STARTING GEOMETRY OPTIMIZATION ***".replace("*", "\*"),
sections=["section_frame_sequence"], sections=["section_frame_sequence", "x_cp2k_section_geometry_optimization"],
subMatchers=[ subMatchers=[
SM( " *** CONJUGATE GRADIENTS ***".replace("*", "\*"), SM( " *** CONJUGATE GRADIENTS ***".replace("*", "\*"),
adHoc=self.adHoc_conjugate_gradient(), adHoc=self.adHoc_conjugate_gradient(),
otherMetaInfo=["geometry_optimization_method"] otherMetaInfo=["geometry_optimization_method"],
), ),
SM( " *** BFGS ***".replace("*", "\*"), SM( " *** BFGS ***".replace("*", "\*"),
adHoc=self.adHoc_bfgs(), adHoc=self.adHoc_bfgs(),
otherMetaInfo=["geometry_optimization_method"] otherMetaInfo=["geometry_optimization_method"],
), ),
SM( " *** L-BFGS ***".replace("*", "\*"), SM( " *** L-BFGS ***".replace("*", "\*"),
adHoc=self.adHoc_bfgs(), adHoc=self.adHoc_bfgs(),
otherMetaInfo=["geometry_optimization_method"] otherMetaInfo=["geometry_optimization_method"],
),
SM( "",
forwardMatch=True,
sections=["section_single_configuration_calculation", "section_system", "x_cp2k_section_geometry_optimization_information"],
subMatchers=[
self.cm.scf(),
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),
otherMetaInfo=["frame_sequence_potential_energy"]
),
],
adHoc=self.adHoc_step()
), ),
# SM( "",
# forwardMatch=True,
# sections=["section_single_configuration_calculation", "section_system", "x_cp2k_section_geometry_optimization_step"],
# 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),
# otherMetaInfo=["frame_sequence_potential_energy"]
# ),
# ],
# otherMetaInfo=["atom_positions"],
# adHoc=self.adHoc_step(),
# ),
SM( " OPTIMIZATION STEP:", SM( " OPTIMIZATION STEP:",
endReStr=" Conv. in RMS gradients =",
name="geooptstep", name="geooptstep",
repeats=True, repeats=True,
sections=["section_single_configuration_calculation", "section_system"], sections=["section_system"],
subMatchers=[ subMatchers=[
SM( "", SM( "",
forwardMatch=True, forwardMatch=True,
sections=["x_cp2k_section_geometry_optimization_information"], sections=["x_cp2k_section_geometry_optimization_step"],
otherMetaInfo=[ otherMetaInfo=[
"atom_positions", "atom_positions",
], ],
subMatchers=[ subMatchers=[
SM( "", # SM( "",
forwardMatch=True, # 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.cm.regex_i),
subMatchers=[ # subMatchers=[
SM(" SCF WAVEFUNCTION OPTIMIZATION", # SM(" SCF WAVEFUNCTION OPTIMIZATION",
forwardMatch=True, # forwardMatch=True,
adHoc=self.debug(), # repeats=True,
repeats=True, # subMatchers=[
subMatchers=[ # self.cm.quickstep_calculation(),
self.cm.scf(), # ]
] # )
) # ]
] # ),
), # SM( "",
SM( "", # forwardMatch=True,
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.cm.regex_i), # subMatchers=[
subMatchers=[ # SM(" SCF WAVEFUNCTION OPTIMIZATION",
SM(" SCF WAVEFUNCTION OPTIMIZATION", # forwardMatch=True,
forwardMatch=True, # repeats=True,
repeats=True, # subMatchers=[
subMatchers=[ # self.cm.quickstep_calculation(),
self.cm.scf(), # ]
] # )
) # ]
] # ),
),
SM( " -------- Informations at step"), SM( " -------- Informations at step"),
SM( " Optimization Method =\s+(?P<x_cp2k_optimization_method>{})".format(self.cm.regex_word)), 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( " Total Energy =\s+(?P<x_cp2k_optimization_energy__hartree>{})".format(self.cm.regex_f),
...@@ -135,6 +140,13 @@ class CP2KGeoOptParser(MainHierarchicalParser): ...@@ -135,6 +140,13 @@ class CP2KGeoOptParser(MainHierarchicalParser):
adHoc=self.adHoc_geo_opt_converged(), adHoc=self.adHoc_geo_opt_converged(),
otherMetaInfo=["geometry_optimization_converged"] otherMetaInfo=["geometry_optimization_converged"]
), ),
SM( " Reevaluating energy at the minimum",
sections=["x_cp2k_section_geometry_optimization_energy_reevaluation", "section_system"],
subMatchers=[
self.cm.quickstep_calculation(),
],
adHoc=self.adHoc_step()
),
], ],
) )
...@@ -150,7 +162,7 @@ class CP2KGeoOptParser(MainHierarchicalParser): ...@@ -150,7 +162,7 @@ class CP2KGeoOptParser(MainHierarchicalParser):
sections=["section_method"], sections=["section_method"],
subMatchers=[ subMatchers=[
self.cm.header(), self.cm.header(),
self.cm.quickstep(), self.cm.quickstep_header(),
], ],
), ),
self.geo_opt self.geo_opt
...@@ -159,11 +171,18 @@ class CP2KGeoOptParser(MainHierarchicalParser): ...@@ -159,11 +171,18 @@ class CP2KGeoOptParser(MainHierarchicalParser):
#=========================================================================== #===========================================================================
# onClose triggers # onClose triggers
def onClose_section_frame_sequence(self, backend, gIndex, section): def onClose_x_cp2k_section_geometry_optimization(self, backend, gIndex, section):
# Get the re-evaluated energy and add it to frame_sequence_potential_energy
reeval = section["x_cp2k_section_geometry_optimization_energy_reevaluation"][0]
quickstep = reeval["x_cp2k_section_quickstep_calculation"][0]
energy = quickstep["x_cp2k_energy_total"]
self.cache_service["frame_sequence_potential_energy"].append(energy[0])
self.cache_service.push_value("number_of_frames_in_sequence") self.cache_service.push_value("number_of_frames_in_sequence")
self.cache_service.push_array_values("frame_sequence_potential_energy") self.cache_service.push_array_values("frame_sequence_potential_energy")
opt_section = section["x_cp2k_section_geometry_optimization_information"] opt_section = section["x_cp2k_section_geometry_optimization_step"]
if opt_section is not None: if opt_section is not None:
opt_section = opt_section[-1] opt_section = opt_section[-1]
geo_limit = opt_section["x_cp2k_optimization_step_size_convergence_limit"] geo_limit = opt_section["x_cp2k_optimization_step_size_convergence_limit"]
...@@ -176,10 +195,10 @@ class CP2KGeoOptParser(MainHierarchicalParser): ...@@ -176,10 +195,10 @@ class CP2KGeoOptParser(MainHierarchicalParser):
def onClose_section_sampling_method(self, backend, gIndex, section): def onClose_section_sampling_method(self, backend, gIndex, section):
self.backend.addValue("sampling_method", "geometry_optimization") self.backend.addValue("sampling_method", "geometry_optimization")
def onClose_x_cp2k_section_geometry_optimization_information(self, backend, gIndex, section): def onClose_x_cp2k_section_geometry_optimization_step(self, backend, gIndex, section):
energy = section["x_cp2k_optimization_energy"][0] energy = section["x_cp2k_optimization_energy"]
# backend.addValue("energy_total", energy) if energy is not None:
self.cache_service["frame_sequence_potential_energy"].append(energy) self.cache_service["frame_sequence_potential_energy"].append(energy[0])
def onClose_section_method(self, backend, gIndex, section): def onClose_section_method(self, backend, gIndex, section):
traj_file = self.file_service.get_file_by_id("trajectory") traj_file = self.file_service.get_file_by_id("trajectory")
...@@ -230,7 +249,6 @@ class CP2KGeoOptParser(MainHierarchicalParser): ...@@ -230,7 +249,6 @@ class CP2KGeoOptParser(MainHierarchicalParser):
output file. Here further information is gathered from external files. output file. Here further information is gathered from external files.
""" """
def wrapper(parser): def wrapper(parser):
# print "STEP"
self.cache_service["number_of_frames_in_sequence"] += 1 self.cache_service["number_of_frames_in_sequence"] += 1
# Get the next position from the trajectory file # Get the next position from the trajectory file
......
from nomadcore.simple_parser import SimpleMatcher as SM from nomadcore.simple_parser import SimpleMatcher as SM
from nomadcore.baseclasses import MainHierarchicalParser from nomadcore.baseclasses import MainHierarchicalParser
from singlepointforceparser import CP2KSinglePointForceParser from singlepointforceparser import CP2KSinglePointForceParser
from nomadcore.caching_backend import CachingLevel
from commonmatcher import CommonMatcher from commonmatcher import CommonMatcher
from cp2kparser.generic.utils import try_to_add_value, try_to_add_array_values
import logging import logging
logger = logging.getLogger("nomad") logger = logging.getLogger("nomad")
...@@ -18,6 +20,16 @@ class CP2KSinglePointParser(MainHierarchicalParser): ...@@ -18,6 +20,16 @@ class CP2KSinglePointParser(MainHierarchicalParser):
super(CP2KSinglePointParser, self).__init__(file_path, parser_context) super(CP2KSinglePointParser, self).__init__(file_path, parser_context)
self.setup_common_matcher(CommonMatcher(parser_context)) self.setup_common_matcher(CommonMatcher(parser_context))
#=======================================================================
# Cache levels
self.caching_level_for_metaname.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,
'x_cp2k_stress_tensor': CachingLevel.ForwardAndCache,
'x_cp2k_section_stress_tensor': CachingLevel.ForwardAndCache,
})
#======================================================================= #=======================================================================
# SimpleMatchers # SimpleMatchers
self.root_matcher = SM("", self.root_matcher = SM("",
...@@ -26,8 +38,8 @@ class CP2KSinglePointParser(MainHierarchicalParser): ...@@ -26,8 +38,8 @@ class CP2KSinglePointParser(MainHierarchicalParser):
otherMetaInfo=["atom_forces"], otherMetaInfo=["atom_forces"],
subMatchers=[ subMatchers=[
self.cm.header(), self.cm.header(),
self.cm.quickstep(), self.cm.quickstep_header(),
self.cm.scf() self.cm.quickstep_calculation(),
] ]
) )
...@@ -51,7 +63,28 @@ class CP2KSinglePointParser(MainHierarchicalParser): ...@@ -51,7 +63,28 @@ class CP2KSinglePointParser(MainHierarchicalParser):
# iterations is given. E.g. in geometry optimization there are multiple # iterations is given. E.g. in geometry optimization there are multiple
# scf calculations so this loses it's meaning sort of. # scf calculations so this loses it's meaning sort of.
self.cache_service.push_value("number_of_scf_iterations") self.cache_service.push_value("number_of_scf_iterations")
self.cache_service["number_of_scf_iterations"] = 0
def onClose_x_cp2k_section_scf_iteration(self, backend, gIndex, section):
"""Keep track of how many SCF iteration are made."""
self.cache_service["number_of_scf_iterations"] += 1
gId = backend.openSection("section_scf_iteration")
try_to_add_value(backend, section, "x_cp2k_energy_total_scf_iteration", "energy_total_scf_iteration")
try_to_add_value(backend, section, "x_cp2k_energy_XC_scf_iteration", "energy_XC_scf_iteration")
try_to_add_value(backend, section, "x_cp2k_energy_change_scf_iteration", "energy_change_scf_iteration")
backend.closeSection("section_scf_iteration", gId)
def onClose_x_cp2k_section_quickstep_calculation(self, backend, gIndex, section):
""""""
try_to_add_value(backend, section, "x_cp2k_energy_total", "energy_total")
try_to_add_value(backend, section, "x_cp2k_electronic_kinetic_energy", "electronic_kinetic_energy")
try_to_add_value(backend, section, "x_cp2k_quickstep_converged", "single_configuration_calculation_converged")
try_to_add_array_values(backend, section, "x_cp2k_atom_forces", "atom_forces")