Commit e4cc2ecd authored by Lauri Himanen's avatar Lauri Himanen

Fixed issue with MD parsing not outputting the simulation cell.

parent 9e2f9716
......@@ -15,6 +15,7 @@ import unittest
import logging
import numpy as np
from cp2kparser import CP2KParser
from nomadcore.local_backend import ParserKeyError
from nomadcore.unit_conversion.unit_conversion import convert_unit
......@@ -423,7 +424,7 @@ class TestEnergyForce(unittest.TestCase):
kind = self.results["section_method_basis_set"][0]
self.assertEqual(kind["method_basis_set_kind"], "wavefunction")
self.assertEqual(kind["number_of_basis_sets_atom_centered"], 1)
self.assertTrue(np.array_equal(kind["mapping_section_method_basis_set_atom_centered"], np.array([[0,0]])))
self.assertTrue(np.array_equal(kind["mapping_section_method_basis_set_atom_centered"], np.array([[0, 0]])))
def test_single_configuration_calculation_converged(self):
result = self.results["single_configuration_calculation_converged"]
......@@ -589,8 +590,8 @@ class TestGeoOpt(unittest.TestCase):
]),
"angstrom"
)
result_start = result[0,:,:]
result_end = result[-1,:,:]
result_start = result[0, :, :]
result_end = result[-1, :, :]
self.assertTrue(np.array_equal(result_start, expected_start))
self.assertTrue(np.array_equal(result_end, expected_end))
......@@ -617,8 +618,8 @@ class TestGeoOptTrajFormats(unittest.TestCase):
]),
"angstrom"
)
result_start = result[0,:,:]
result_end = result[-1,:,:]
result_start = result[0, :, :]
result_end = result[-1, :, :]
self.assertTrue(np.array_equal(result_start, expected_start))
self.assertTrue(np.array_equal(result_end, expected_end))
......@@ -640,8 +641,8 @@ class TestGeoOptTrajFormats(unittest.TestCase):
]),
"angstrom"
)
result_start = result[0,:,:]
result_end = result[-1,:,:]
result_start = result[0, :, :]
result_end = result[-1, :, :]
self.assertTrue(np.array_equal(result_start, expected_start))
self.assertTrue(np.array_equal(result_end, expected_end))
......@@ -676,13 +677,13 @@ class TestGeoOptTrajectory(unittest.TestCase):
systems = results["section_system"]
i_conf = 0
for calc in single_conf.values():
for calc in single_conf:
system_index = calc["single_configuration_calculation_to_system_ref"]
system = systems[system_index]
pos = system["atom_positions"]
if i_conf == 0 or i_conf == 2 or i_conf == 4:
self.assertEqual(pos, None)
with self.assertRaises(ParserKeyError):
pos = system["atom_positions"]
else:
pos = system["atom_positions"]
if i_conf == 1:
......@@ -806,6 +807,19 @@ class TestMD(unittest.TestCase):
expected_result = np.array(11*[6])
self.assertTrue(np.array_equal(result, expected_result))
def test_simulation_cell(self):
result = self.results["simulation_cell"]
self.assertEqual(len(result), 11)
expected_start = convert_unit(
np.array([
[9.853, 0, 0],
[0, 9.853, 0],
[0, 0, 9.853],
]),
"angstrom"
)
self.assertTrue(np.array_equal(result[0], expected_start))
def test_ensemble_type(self):
result = self.results["ensemble_type"]
self.assertEqual(result, "NVE")
......@@ -842,8 +856,8 @@ class TestMD(unittest.TestCase):
]),
"angstrom"
)
self.assertTrue(np.array_equal(result[0,:], expected_start))
self.assertTrue(np.array_equal(result[-1,:], expected_end))
self.assertTrue(np.array_equal(result[0, :], expected_start))
self.assertTrue(np.array_equal(result[-1, :], expected_end))
def test_atom_velocities(self):
result = self.results["atom_velocities"]
......@@ -870,8 +884,8 @@ class TestMD(unittest.TestCase):
"bohr*(hbar/hartree)^-1"
)
self.assertTrue(np.array_equal(result[0,:], expected_start))
self.assertTrue(np.array_equal(result[-1,:], expected_end))
self.assertTrue(np.array_equal(result[0, :], expected_start))
self.assertTrue(np.array_equal(result[-1, :], expected_end))
def test_frame_sequence_potential_energy(self):
result = self.results["frame_sequence_potential_energy"]
......
......@@ -126,19 +126,9 @@ class CP2KCommonParser(CommonParser):
SM( " GLOBAL\| Number of threads for this process"),
SM( " GLOBAL\| This output is from process"),
],
otherMetaInfo=[
"section_XC_functionals",
'XC_functional_name',
'XC_functional_weight',
'XC_functional',
'configuration_periodic_dimensions',
"stress_tensor_method",
"atom_positions",
],
),
SM( " CELL\|",
adHoc=self.adHoc_x_cp2k_section_cell(),
otherMetaInfo=["simulation_cell"]
),
]
)
......@@ -179,11 +169,9 @@ class CP2KCommonParser(CommonParser):
]
),
SM( r" \*\*\* SCF run converged in\s+(\d+) steps \*\*\*",
otherMetaInfo=["single_configuration_calculation_converged"],
adHoc=self.adHoc_single_point_converged()
),
SM( r" \*\*\* SCF run NOT converged \*\*\*",
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.regexs.float)),
......@@ -192,19 +180,16 @@ class CP2KCommonParser(CommonParser):
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.regexs.float),
otherMetaInfo=["energy_total"],
),
SM( r" ATOMIC FORCES in \[a\.u\.\]"),
SM( r" # Atom Kind Element X Y Z",
adHoc=self.adHoc_atom_forces(),
otherMetaInfo=["atom_forces", "x_cp2k_atom_forces"],
),
SM( r" (?:NUMERICAL )?STRESS TENSOR \[GPa\]",
sections=["x_cp2k_section_stress_tensor"],
subMatchers=[
SM( r"\s+X\s+Y\s+Z",
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.regexs.float)),
SM( " Det\(stress tensor\)\s+:\s+(?P<x_cp2k_stress_tensor_determinant__GPa3>{})".format(self.regexs.float)),
......@@ -230,7 +215,6 @@ class CP2KCommonParser(CommonParser):
SM( " DFT\| Charge\s+(?P<total_charge>{})".format(self.regexs.int)),
SM( " DFT\| Self-interaction correction \(SIC\)\s+(?P<self_interaction_correction_method>[^\n]+)"),
],
otherMetaInfo=["self_interaction_correction_method"],
),
SM( " DFT\+U\|",
adHoc=self.adHoc_dft_plus_u(),
......@@ -282,9 +266,7 @@ class CP2KCommonParser(CommonParser):
sections=["x_cp2k_section_total_numbers"],
subMatchers=[
SM( " Total number of - Atomic kinds:\s+(?P<x_cp2k_atomic_kinds>\d+)"),
SM( "\s+- Atoms:\s+(?P<x_cp2k_atoms>\d+)",
otherMetaInfo=["number_of_atoms"],
),
SM( "\s+- Atoms:\s+(?P<x_cp2k_atoms>\d+)"),
SM( "\s+- Shell sets:\s+(?P<x_cp2k_shell_sets>\d+)"),
SM( "\s+- Shells:\s+(?P<x_cp2k_shells>\d+)"),
SM( "\s+- Primitive Cartesian functions:\s+(?P<x_cp2k_primitive_cartesian_functions>\d+)"),
......@@ -306,7 +288,6 @@ class CP2KCommonParser(CommonParser):
subMatchers=[
SM( " MODULE QUICKSTEP: ATOMIC COORDINATES IN angstrom",
adHoc=self.adHoc_x_cp2k_section_quickstep_atom_information(),
otherMetaInfo=["atom_labels", "atom_positions"]
)
]
),
......
......@@ -273,6 +273,7 @@ class CP2KMDParser(MainHierarchicalParser):
single_conf_gids = []
i_md_step = 0
for i_step in range(self.n_steps + 1):
sectionGID = backend.openSection("section_single_configuration_calculation")
......@@ -284,6 +285,10 @@ class CP2KMDParser(MainHierarchicalParser):
if i_step == 0 and self.ensemble == "NPT" and self.cell_iterator is None:
self.cache_service.addArrayValues("simulation_cell", unit="angstrom")
# Unchanging cell
if self.ensemble != "NPT":
self.cache_service.addArrayValues("simulation_cell", unit="angstrom")
# Trajectory
if freqs["trajectory"][1] and self.traj_iterator is not None:
if (i_step + 1) % freqs["trajectory"][0] == 0 or (i_step == last_step and add_last_traj):
......@@ -331,7 +336,6 @@ class CP2KMDParser(MainHierarchicalParser):
line = next(self.cell_iterator)
cell = np.reshape(line, (3, 3))
self.backend.addArrayValues("simulation_cell", cell, unit="angstrom")
# self.cache_service["simulation_cell"] = cell
# Output file
if md_steps:
......
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