Skip to content
Snippets Groups Projects
Commit 41dcc781 authored by Lauri Himanen's avatar Lauri Himanen
Browse files

Added modules for vibration and properties calculation, fixed issues with...

Added modules for vibration and properties calculation, fixed issues with global cache having uninitialized values, fixedissues with empty MD information.
parent 0f19740f
Branches
Tags 1.3.0
No related merge requests found
...@@ -38,6 +38,8 @@ class CPMDParser(ParserInterface): ...@@ -38,6 +38,8 @@ class CPMDParser(ParserInterface):
regex_single_point = re.compile(r" SINGLE POINT DENSITY OPTIMIZATION") regex_single_point = re.compile(r" SINGLE POINT DENSITY OPTIMIZATION")
regex_geo_opt = re.compile(r" OPTIMIZATION OF IONIC POSITIONS") regex_geo_opt = re.compile(r" OPTIMIZATION OF IONIC POSITIONS")
regex_md = re.compile(r"( CAR-PARRINELLO MOLECULAR DYNAMICS)|( BORN-OPPENHEIMER MOLECULAR DYNAMICS)") regex_md = re.compile(r"( CAR-PARRINELLO MOLECULAR DYNAMICS)|( BORN-OPPENHEIMER MOLECULAR DYNAMICS)")
regex_vib = re.compile(r" PERFORM A VIBRATIONAL ANALYSIS BY FINITE DIFFERENCES")
regex_prop = re.compile(r" CALCULATE SOME PROPERTIES")
run_type = None run_type = None
n_lines = 1000 n_lines = 1000
version_id = None version_id = None
...@@ -68,6 +70,16 @@ class CPMDParser(ParserInterface): ...@@ -68,6 +70,16 @@ class CPMDParser(ParserInterface):
if result_md: if result_md:
run_type = CPMDRunType(module_name="mdparser", class_name="CPMDMDParser") run_type = CPMDRunType(module_name="mdparser", class_name="CPMDMDParser")
# Look for vibrational analysis
result_vib = regex_vib.match(line)
if result_vib:
run_type = CPMDRunType(module_name="vibrationparser", class_name="CPMDVibrationParser")
# Look for properties calculation
result_prop = regex_prop.match(line)
if result_prop:
run_type = CPMDRunType(module_name="propertiesparser", class_name="CPMDPropertiesParser")
if version_id is None: if version_id is None:
msg = "Could not find a version specification from the given main file." msg = "Could not find a version specification from the given main file."
logger.exception(msg) logger.exception(msg)
......
...@@ -30,6 +30,11 @@ class CPMDCommonParser(CommonParser): ...@@ -30,6 +30,11 @@ class CPMDCommonParser(CommonParser):
self.cache_service.add("ensemble_type") self.cache_service.add("ensemble_type")
self.cache_service.add("time_step_ions") self.cache_service.add("time_step_ions")
self.cache_service.add("trajectory_range", False)
self.cache_service.add("trajectory_sample", False)
self.cache_service.add("print_freq", 1)
self.cache_service.add("configuration_periodic_dimensions", single=False, update=False)
#=========================================================================== #===========================================================================
# Common SimpleMatchers # Common SimpleMatchers
def header(self): def header(self):
......
...@@ -16,10 +16,6 @@ class CPMDInputParser(BasicParser): ...@@ -16,10 +16,6 @@ class CPMDInputParser(BasicParser):
""" """
super(CPMDInputParser, self).__init__(file_path, parser_context) super(CPMDInputParser, self).__init__(file_path, parser_context)
self.input_tree = None self.input_tree = None
self.cache_service.add("trajectory_range", False)
self.cache_service.add("trajectory_sample", False)
self.cache_service.add("print_freq", 1)
self.cache_service.add("configuration_periodic_dimensions", single=False, update=False)
def parse(self): def parse(self):
self.setup_input_tree(self.parser_context.version_id) self.setup_input_tree(self.parser_context.version_id)
......
...@@ -247,14 +247,12 @@ class CPMDMDParser(MainHierarchicalParser): ...@@ -247,14 +247,12 @@ class CPMDMDParser(MainHierarchicalParser):
self.backend.closeSection("section_system", sys_id) self.backend.closeSection("section_system", sys_id)
# Push the summaries # Push the summaries
if potential_energies:
potential_energies = np.array(potential_energies) potential_energies = np.array(potential_energies)
self.backend.addArrayValues("frame_sequence_potential_energy", potential_energies, unit="hartree") self.backend.addArrayValues("frame_sequence_potential_energy", potential_energies, unit="hartree")
if kinetic_energies:
kinetic_energies = np.array(kinetic_energies) kinetic_energies = np.array(kinetic_energies)
self.backend.addArrayValues("frame_sequence_kinetic_energy", kinetic_energies, unit="hartree") self.backend.addArrayValues("frame_sequence_kinetic_energy", kinetic_energies, unit="hartree")
conserved_quantities = np.array(conserved_quantities)
self.backend.addArrayValues("frame_sequence_conserved_quantity", conserved_quantities, unit="hartree")
temperatures = np.array(temperatures)
self.backend.addArrayValues("frame_sequence_temperature", temperatures, unit="K")
# Push the statistics. CPMD prints some statistics at the end, but the # Push the statistics. CPMD prints some statistics at the end, but the
# mean and std of kinetic energy are missing # mean and std of kinetic energy are missing
...@@ -263,3 +261,10 @@ class CPMDMDParser(MainHierarchicalParser): ...@@ -263,3 +261,10 @@ class CPMDMDParser(MainHierarchicalParser):
kin_std = np.sqrt(np.dot(kin_temp, kin_temp)/kinetic_energies.size) kin_std = np.sqrt(np.dot(kin_temp, kin_temp)/kinetic_energies.size)
kin_temp = None kin_temp = None
self.backend.addArrayValues("frame_sequence_kinetic_energy_stats", np.array([kin_mean, kin_std]), unit="hartree") self.backend.addArrayValues("frame_sequence_kinetic_energy_stats", np.array([kin_mean, kin_std]), unit="hartree")
if conserved_quantities:
conserved_quantities = np.array(conserved_quantities)
self.backend.addArrayValues("frame_sequence_conserved_quantity", conserved_quantities, unit="hartree")
if temperatures:
temperatures = np.array(temperatures)
self.backend.addArrayValues("frame_sequence_temperature", temperatures, unit="K")
from __future__ import absolute_import
from nomadcore.simple_parser import SimpleMatcher as SM
from nomadcore.baseclasses import MainHierarchicalParser
import numpy as np
from .commonparser import CPMDCommonParser
import re
import logging
LOGGER = logging.getLogger("nomad")
#===============================================================================
class CPMDPropertiesParser(MainHierarchicalParser):
"""The main parser class that is called for all run types. Parses the CPMD
output file.
"""
def __init__(self, file_path, parser_context):
"""
"""
super(CPMDPropertiesParser, self).__init__(file_path, parser_context)
self.setup_common_matcher(CPMDCommonParser(parser_context))
self.n_frames = 0
self.sampling_method_gid = None
self.frame_refs = []
self.energies = []
#=======================================================================
# Main structure
self.root_matcher = SM("",
forwardMatch=True,
sections=['section_run', "section_method"],
subMatchers=[
self.cm.header(),
self.cm.method(),
self.cm.atoms(),
self.cm.cell(),
self.cm.initialization(),
self.cm.footer(),
]
)
#=======================================================================
# onClose triggers
def onClose_section_system(self, backend, gIndex, section):
self.cache_service.addArrayValues("atom_labels")
self.cache_service.addArrayValues("simulation_cell", unit="bohr")
self.cache_service.addValue("number_of_atoms")
#=======================================================================
# adHoc
from __future__ import absolute_import
from nomadcore.simple_parser import SimpleMatcher as SM
from nomadcore.baseclasses import MainHierarchicalParser
import numpy as np
from .commonparser import CPMDCommonParser
import re
import logging
LOGGER = logging.getLogger("nomad")
#===============================================================================
class CPMDVibrationParser(MainHierarchicalParser):
"""The main parser class that is called for all run types. Parses the CPMD
output file.
"""
def __init__(self, file_path, parser_context):
"""
"""
super(CPMDVibrationParser, self).__init__(file_path, parser_context)
self.setup_common_matcher(CPMDCommonParser(parser_context))
self.n_frames = 0
self.sampling_method_gid = None
self.frame_refs = []
self.energies = []
#=======================================================================
# Main structure
self.root_matcher = SM("",
forwardMatch=True,
sections=['section_run', "section_method"],
subMatchers=[
self.cm.header(),
self.cm.method(),
self.cm.atoms(),
self.cm.cell(),
self.cm.initialization(),
self.cm.footer(),
]
)
#=======================================================================
# onClose triggers
def onClose_section_system(self, backend, gIndex, section):
self.cache_service.addArrayValues("atom_labels")
self.cache_service.addArrayValues("simulation_cell", unit="bohr")
self.cache_service.addValue("number_of_atoms")
#=======================================================================
# adHoc
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment