Commit 04b46920 authored by Mohamed, Fawzi Roberto (fawzi)'s avatar Mohamed, Fawzi Roberto (fawzi)
Browse files

meta 2.0 changes

parent 3d3e3d06
......@@ -217,7 +217,7 @@ def generate_input_metainfos(object_tree):
"type": "nomad_meta_info_1_0",
"description": "Metainfo for the values parsed from a CP2K input file.",
"dependencies": [ {
"relativePath": "cp2k.general.nomadmetainfo.json"
"relativePath": "cp2k_general.nomadmetainfo.json"
}],
}
......
......@@ -476,7 +476,7 @@ class CP2KCommonParser(CommonParser):
self.cache_service["map_kind_to_basis"] = dict_map
# The metainfo for mapping section_method_basis_set_atom_centered has been removed
# mapping = np.array(mapping)
# backend.addArrayValues("mapping_section_method_basis_set_atom_centered", np.array(mapping))
# backend.addArrayValues("xxx_replaced_by_method_basis_set_to_atom_centered_ref_and_method_basis_set_to_atom_kind_ref", np.array(mapping))
backend.addValue("method_basis_set_kind", "wavefunction")
self.cache_service.addValue("mapping_section_method_basis_set_cell_associated")
backend.addValue("number_of_basis_sets_atom_centered", len(self.basis_set_info))
......@@ -546,7 +546,7 @@ class CP2KCommonParser(CommonParser):
def onClose_section_single_configuration_calculation(self, backend, gIndex, section):
# Write the references to section_method and section_system
backend.addValue('single_configuration_to_calculation_method_ref', self.section_method_index)
backend.addValue('single_configuration_calculation_to_method_ref', self.section_method_index)
backend.addValue('single_configuration_calculation_to_system_ref', self.section_system_index)
scc_basis_id = backend.openSection("section_basis_set")
......
......@@ -41,8 +41,7 @@ class CP2KGeoOptParser(MainHierarchicalParser):
#=======================================================================
# Globally cached values
self.cache_service.add("number_of_frames_in_sequence", 0)
self.cache_service.add("frame_sequence_potential_energy", [])
self.cache_service.add("frame_sequence_local_frames_ref", [])
self.cache_service.add("frame_sequence_to_frames_ref", [])
self.cache_service.add("geometry_optimization_method")
self.cache_service.add("geometry_optimization_converged")
self.cache_service.add("geometry_opt_max_reached")
......@@ -191,17 +190,16 @@ class CP2KGeoOptParser(MainHierarchicalParser):
# onClose triggers
def onClose_x_cp2k_section_geometry_optimization(self, backend, gIndex, section):
# Get the re-evaluated energy and add it to frame_sequence_potential_energy
# Get the re-evaluated energy and add it to potential_energy
reeval_quickstep = self.energy_reeval_quickstep
if reeval_quickstep is not None:
energy = reeval_quickstep.get_latest_value("x_cp2k_energy_total")
if energy is not None:
self.cache_service["frame_sequence_potential_energy"].append(energy)
self.backend.addValue("potential_energy", energy)
# Push values from cache
self.cache_service.addArrayValues("frame_sequence_potential_energy")
self.cache_service.addValue("geometry_optimization_method")
self.backend.addValue("frame_sequence_to_sampling_ref", 0)
self.backend.addValue("frame_sequence_to_sampling_method_ref", 0)
# Get the optimization convergence criteria from the last optimization
# step
......@@ -256,7 +254,7 @@ class CP2KGeoOptParser(MainHierarchicalParser):
backend.closeSection("section_system", systemId)
backend.closeSection("section_single_configuration_calculation", singleId)
self.cache_service.addArrayValues("frame_sequence_local_frames_ref")
self.cache_service.addArrayValues("frame_sequence_to_frames_ref")
backend.addValue("number_of_frames_in_sequence", n_steps)
def onClose_section_frame_sequence(self, backend, gIndex, section):
......@@ -271,7 +269,7 @@ class CP2KGeoOptParser(MainHierarchicalParser):
def onClose_x_cp2k_section_geometry_optimization_step(self, backend, gIndex, section):
energy = section["x_cp2k_optimization_energy"]
if energy is not None:
self.cache_service["frame_sequence_potential_energy"].append(energy[0])
self.backend.addValue("potential_energy",energy[0])
def onClose_section_system(self, backend, gIndex, section):
self.cache_service.addArrayValues("simulation_cell", unit="angstrom")
......@@ -292,7 +290,7 @@ class CP2KGeoOptParser(MainHierarchicalParser):
pass
def onClose_section_single_configuration_calculation(self, backend, gIndex, section):
self.cache_service["frame_sequence_local_frames_ref"].append(gIndex)
self.cache_service["frame_sequence_to_frames_ref"].append(gIndex)
#===========================================================================
# adHoc functions
......
......@@ -31,6 +31,10 @@ ureg = UnitRegistry()
logger = logging.getLogger("nomad")
def metaN(metaName):
"""Retrurns a normalized meta name"""
return metaName.replace(".", "_").lower()
class CP2KInputParser(AbstractBaseParser):
"""Used to parse out a CP2K input file.
......@@ -565,7 +569,7 @@ class CP2KInputParser(AbstractBaseParser):
not_section_path = metainfo_data_prefix + "{}".format("_".join(name_stack))
gid = self.backend.openSection(path)
gid = self.backend.openSection(metaN(path))
# Keywords
for default_name in section.default_keyword_names:
......@@ -573,28 +577,28 @@ class CP2KInputParser(AbstractBaseParser):
for keyword in keywords:
if keyword.value is not None:
name = "{}_{}".format(not_section_path, keyword.default_name.lower())
self.backend.addValue(name, keyword.value)
self.backend.addValue(metaN(name), keyword.value)
# Section parameter
section_parameter = section.section_parameter
if section_parameter is not None:
name = "{}_section_parameters".format(not_section_path)
if section_parameter.value is not None:
self.backend.addValue(name, section_parameter.value)
self.backend.addValue(metaN(name), section_parameter.value)
# Default keyword
default_keyword = section.default_keyword
if default_keyword is not None:
name = "{}_default_keyword".format(not_section_path)
self.backend.addValue(name, default_keyword.value)
self.backend.addValue(metaN(name), default_keyword.value)
# Subsections
for name, subsections in section.sections.items():
for subsection in subsections:
self.fill_metadata_recursively(subsection, name_stack)
self.backend.closeSection(path, gid)
self.backend.closeSection(metaN(path), gid)
if section.name != "CP2K_INPUT":
name_stack.pop()
......
......@@ -282,12 +282,7 @@ class CP2KMDParser(MainHierarchicalParser):
last_step = self.n_steps
md_steps = section["x_cp2k_section_md_step"]
frame_sequence_potential_energy = []
frame_sequence_temperature = []
frame_sequence_time = []
frame_sequence_kinetic_energy = []
frame_sequence_conserved_quantity = []
frame_sequence_pressure = []
ener_frames = []
single_conf_gids = []
......@@ -366,14 +361,14 @@ class CP2KMDParser(MainHierarchicalParser):
wall_time = line[6]
frame_sequence_time.append(time)
frame_sequence_kinetic_energy.append(kinetic_energy)
frame_sequence_temperature.append(temperature)
frame_sequence_potential_energy.append(potential_energy)
frame_sequence_conserved_quantity.append(conserved_quantity)
backend.addValue('kinetic_energy', kinetic_energy, unit="hartree")
backend.addValue('instant_temperature', temperature, unit="K")
backend.addValue('potential_energy', potential_energy, unit="hartree")
backend.addValue('conserved_quantity', conserved_quantity, unit="hartree")
ener_frames.append(i_step)
backend.addValue("energy_total", conserved_quantity)
backend.addValue("energy_total", conserved_quantity, unit="hartree")
backend.addValue("time_calculation", wall_time)
# Cell file
......@@ -398,7 +393,11 @@ class CP2KMDParser(MainHierarchicalParser):
# print(md_step["x_cp2k_md_step_number"])
quickstep = self.md_quicksteps[i_md_step]
if quickstep is not None:
quickstep.add_latest_value("x_cp2k_atom_forces", "atom_forces")
if quickstep.get_latest_value("x_cp2k_atom_forces"):
# uglyness
fId = quickstep.caching_backend.openSection("section_atom_forces")
quickstep.add_latest_value("x_cp2k_atom_forces", "atom_forces")
quickstep.caching_backend.closeSection("section_atom_forces", fId)
quickstep.add_latest_value("x_cp2k_stress_tensor", "stress_tensor")
scfGID = backend.openSection("section_scf_iteration")
quickstep.add_latest_value(["x_cp2k_section_scf_iteration", "x_cp2k_energy_total_scf_iteration"], "energy_total_scf_iteration")
......@@ -408,59 +407,25 @@ class CP2KMDParser(MainHierarchicalParser):
i_md_step += 1
pressure = md_step.get_latest_value("x_cp2k_md_pressure_instantaneous")
if pressure is not None:
frame_sequence_pressure.append(pressure)
backend.addValue("instant_pressure", pressure)
backend.closeSection("section_system", systemGID)
backend.closeSection("section_single_configuration_calculation", sectionGID)
# Add the summaries to frame sequence
if len(frame_sequence_potential_energy) != 0:
frame_sequence_potential_energy = convert_unit(np.array(frame_sequence_potential_energy), "hartree")
backend.addArrayValues("frame_sequence_potential_energy", frame_sequence_potential_energy)
backend.addArrayValues("frame_sequence_potential_energy_frames", np.array(ener_frames))
mean_pot = frame_sequence_potential_energy.mean()
std_pot = frame_sequence_potential_energy.std()
backend.addArrayValues("frame_sequence_potential_energy_stats", np.array([mean_pot, std_pot]))
if len(frame_sequence_kinetic_energy) != 0:
frame_sequence_kinetic_energy = convert_unit(np.array(frame_sequence_kinetic_energy), "hartree")
backend.addArrayValues("frame_sequence_kinetic_energy", frame_sequence_kinetic_energy)
backend.addArrayValues("frame_sequence_kinetic_energy_frames", np.array(ener_frames))
mean_kin = frame_sequence_kinetic_energy.mean()
std_kin = frame_sequence_kinetic_energy.std()
backend.addArrayValues("frame_sequence_kinetic_energy_stats", np.array([mean_kin, std_kin]))
if len(frame_sequence_conserved_quantity) != 0:
frame_sequence_conserved_quantity = convert_unit(np.array(frame_sequence_conserved_quantity), "hartree")
backend.addArrayValues("frame_sequence_conserved_quantity", frame_sequence_conserved_quantity)
backend.addArrayValues("frame_sequence_conserved_quantity_frames", np.array(ener_frames))
mean_cons = frame_sequence_conserved_quantity.mean()
std_cons = frame_sequence_conserved_quantity.std()
backend.addArrayValues("frame_sequence_conserved_quantity_stats", np.array([mean_cons, std_cons]))
if len(frame_sequence_time) != 0:
frame_sequence_time = np.array(frame_sequence_time)
backend.addArrayValues("frame_sequence_time", frame_sequence_time, unit="fs")
if len(frame_sequence_temperature) != 0:
frame_sequence_temperature = np.array(frame_sequence_temperature)
backend.addArrayValues("frame_sequence_temperature", frame_sequence_temperature)
backend.addArrayValues("frame_sequence_temperature_frames", np.array(ener_frames))
mean_temp = frame_sequence_temperature.mean()
std_temp = frame_sequence_temperature.std()
backend.addArrayValues("frame_sequence_temperature_stats", np.array([mean_temp, std_temp]))
if len(frame_sequence_pressure) != 0:
frame_sequence_pressure = np.array(frame_sequence_pressure)
backend.addArrayValues("frame_sequence_pressure", frame_sequence_pressure)
mean_pressure = frame_sequence_pressure.mean()
std_pressure = frame_sequence_pressure.std()
backend.addArrayValues("frame_sequence_pressure_stats", np.array([mean_pressure, std_pressure]))
# Number of frames. We open a SCC for each frame, even if there is no
# information for it.
backend.addValue("number_of_frames_in_sequence", len(single_conf_gids))
# Reference to sampling method
backend.addValue("frame_sequence_to_sampling_ref", 0)
backend.addValue("frame_sequence_to_sampling_method_ref", 0)
# References to local frames
backend.addArrayValues("frame_sequence_local_frames_ref", np.array(single_conf_gids))
backend.addArrayValues("frame_sequence_to_frames_ref", np.array(single_conf_gids))
#===========================================================================
# adHoc functions
......
......@@ -36,7 +36,9 @@ class CP2KSinglePointForceParser(AbstractBaseParser):
continue
elif line.startswith(" SUM"):
forces = np.array(forces)
fId = self.backend.openSection("section_atom_forces")
self.backend.addArrayValues("atom_forces", forces, unit="forceAu")
self.backend.closeSection("section_atom_forces", fId)
break
elif start:
components = [float(comp) for comp in line.split()[-3:]]
......
......@@ -92,7 +92,11 @@ class CP2KSinglePointParser(MainHierarchicalParser):
section.add_latest_value("x_cp2k_energy_total", "energy_total")
section.add_latest_value("x_cp2k_electronic_kinetic_energy", "electronic_kinetic_energy")
section.add_latest_value("x_cp2k_quickstep_converged", "single_configuration_calculation_converged")
section.add_latest_array_values("x_cp2k_atom_forces", "atom_forces")
# some uglyness as we need to open a subsection...
if section.get_latest_value("x_cp2k_atom_forces"):
fId = section.caching_backend.openSection("section_atom_forces")
section.add_latest_array_values("x_cp2k_atom_forces", "atom_forces")
section.caching_backend.closeSection("section_atom_forces", fId)
def onClose_x_cp2k_section_stress_tensor(self, backend, gIndex, section):
""""""
......
......@@ -97,35 +97,35 @@ class TestXCFunctional(unittest.TestCase):
"""Tests that the XC functionals can be properly parsed.
"""
def test_pade(self):
xc = get_result("XC_functional/pade", "xc_functional")
xc = get_result("xc_functional/pade", "xc_functional")
self.assertEqual(xc, "1*LDA_XC_TETER93")
def test_lda(self):
xc = get_result("XC_functional/lda", "xc_functional")
xc = get_result("xc_functional/lda", "xc_functional")
self.assertEqual(xc, "1*LDA_XC_TETER93")
def test_blyp(self):
xc = get_result("XC_functional/blyp", "xc_functional")
xc = get_result("xc_functional/blyp", "xc_functional")
self.assertEqual(xc, "1*GGA_C_LYP+1*GGA_X_B88")
def test_b3lyp(self):
xc = get_result("XC_functional/b3lyp", "xc_functional")
xc = get_result("xc_functional/b3lyp", "xc_functional")
self.assertEqual(xc, "1*HYB_GGA_XC_B3LYP")
def test_olyp(self):
xc = get_result("XC_functional/olyp", "xc_functional")
xc = get_result("xc_functional/olyp", "xc_functional")
self.assertEqual(xc, "1*GGA_C_LYP+1*GGA_X_OPTX")
def test_hcth120(self):
xc = get_result("XC_functional/hcth120", "xc_functional")
xc = get_result("xc_functional/hcth120", "xc_functional")
self.assertEqual(xc, "1*GGA_XC_HCTH_120")
def test_pbe0(self):
xc = get_result("XC_functional/pbe0", "xc_functional")
xc = get_result("xc_functional/pbe0", "xc_functional")
self.assertEqual(xc, "1*HYB_GGA_XC_PBEH")
def test_pbe(self):
xc = get_result("XC_functional/pbe", "xc_functional")
xc = get_result("xc_functional/pbe", "xc_functional")
self.assertEqual(xc, "1*GGA_C_PBE+1*GGA_X_PBE")
......@@ -606,7 +606,7 @@ class TestEnergyForce(unittest.TestCase):
self.assertEqual(kind["number_of_basis_sets_atom_centered"], 1)
# This reference has been removed from the metainfo
# self.assertTrue(np.array_equal(kind["mapping_section_method_basis_set_atom_centered"], np.array([[0, 0]])))
# self.assertTrue(np.array_equal(kind["xxx_replaced_by_method_basis_set_to_atom_centered_ref_and_method_basis_set_to_atom_kind_ref"], np.array([[0, 0]])))
def test_single_configuration_calculation_converged(self):
result = self.results["single_configuration_calculation_converged"]
......@@ -617,7 +617,7 @@ class TestEnergyForce(unittest.TestCase):
self.assertEqual(result, 10)
def test_single_configuration_to_calculation_method_ref(self):
result = self.results["single_configuration_to_calculation_method_ref"]
result = self.results["single_configuration_calculation_to_method_ref"]
self.assertEqual(result, 0)
def test_single_configuration_calculation_to_system_description_ref(self):
......@@ -707,12 +707,13 @@ class TestGeoOpt(unittest.TestCase):
result = self.results["number_of_frames_in_sequence"]
self.assertEqual(result, 7)
def test_frame_sequence_to_sampling_ref(self):
result = self.results["frame_sequence_to_sampling_ref"]
result = self.results["frame_sequence_to_sampling_method_ref"]
self.assertEqual(result, 0)
def test_frame_sequence_local_frames_ref(self):
result = self.results["frame_sequence_local_frames_ref"]
result = self.results["frame_sequence_to_frames_ref"]
expected_result = np.array([0, 1, 2, 3, 4, 5, 6])
self.assertTrue(np.array_equal(result, expected_result))
......@@ -741,7 +742,7 @@ class TestGeoOpt(unittest.TestCase):
self.assertEqual(result, expected_result)
def test_frame_sequence_potential_energy(self):
result = self.results["frame_sequence_potential_energy"]
result = self.results["potential_energy"]
expected_result = convert_unit(
np.array([
-17.1534159246,
......@@ -798,11 +799,11 @@ class TestGeoOptMaxSteps(unittest.TestCase):
self.assertEqual(result, 3)
def test_frame_sequence_to_sampling_ref(self):
result = self.results["frame_sequence_to_sampling_ref"]
result = self.results["frame_sequence_to_sampling_method_ref"]
self.assertEqual(result, 0)
def test_frame_sequence_local_frames_ref(self):
result = self.results["frame_sequence_local_frames_ref"]
result = self.results["frame_sequence_to_frames_ref"]
expected_result = np.array([0, 1, 2])
self.assertTrue(np.array_equal(result, expected_result))
......@@ -811,7 +812,7 @@ class TestGeoOptMaxSteps(unittest.TestCase):
self.assertEqual(result, "geometry_optimization")
def test_frame_sequence_potential_energy(self):
result = self.results["frame_sequence_potential_energy"]
result = self.results["potential_energy"]
self.assertEqual(len(result), 3)
def test_atom_positions(self):
......@@ -1025,16 +1026,7 @@ class TestMDPrintSettings(unittest.TestCase):
# Check that frames from ener file are read correctly with interval of 3
frames = [0, 3, 6, 9]
self.results["frame_sequence_temperature"]
temp_frames = self.results["frame_sequence_temperature_frames"]
pot_frames = self.results["frame_sequence_potential_energy_frames"]
kin_frames = self.results["frame_sequence_kinetic_energy_frames"]
con_frames = self.results["frame_sequence_conserved_quantity_frames"]
self.assertTrue(np.array_equal(temp_frames, frames))
self.assertTrue(np.array_equal(pot_frames, frames))
self.assertTrue(np.array_equal(kin_frames, frames))
self.assertTrue(np.array_equal(con_frames, frames))
self.results["instant_temperature"]
class TestMD(unittest.TestCase):
"""Molecular dynamics tests.
......@@ -1193,19 +1185,19 @@ class TestMD(unittest.TestCase):
self.assertTrue(np.array_equal(result[-1, :], expected_end))
def test_frame_sequence_potential_energy(self):
result = self.results["frame_sequence_potential_energy"]
result = self.results["potential_energy"]
self.assertTrue(np.array_equal(result, self.pot))
def test_frame_sequence_kinetic_energy(self):
result = self.results["frame_sequence_kinetic_energy"]
result = self.results["kinetic_energy"]
self.assertTrue(np.array_equal(result, self.kin))
def test_frame_sequence_conserved_quantity(self):
result = self.results["frame_sequence_conserved_quantity"]
result = self.results["conserved_quantity"]
self.assertTrue(np.array_equal(result, self.cons))
def test_frame_sequence_temperature(self):
result = self.results["frame_sequence_temperature"]
result = self.results["instant_temperature"]
self.assertTrue(np.array_equal(result, self.temp))
def test_frame_sequence_time(self):
......@@ -1288,14 +1280,14 @@ class TestMDEnsembles(unittest.TestCase):
results["atom_positions"]
results["atom_labels"]
results["frame_sequence_potential_energy"]
results["potential_energy"]
def test_npt(self):
results = get_result("md/npt")
ensemble = results["ensemble_type"]
self.assertEqual(ensemble, "NPT")
pressure = results["frame_sequence_pressure"]
pressure = results["instant_pressure"]
self.assertTrue(np.array_equal(pressure, self.pressure))
pressure_stats = results["frame_sequence_pressure_stats"]
......
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