Commit 3f266a2e authored by Mohamed, Fawzi Roberto (fawzi)'s avatar Mohamed, Fawzi Roberto (fawzi)
Browse files

meta 2.0 changes

parent b0e94083
......@@ -33,7 +33,7 @@ class NWChemMainParser(MainHierarchicalParser):
# Cache for storing current method settings
self.method_cache = CacheService(self.parser_context)
self.method_cache.add("single_configuration_to_calculation_method_ref", single=False, update=False)
self.method_cache.add("single_configuration_calculation_to_method_ref", single=False, update=False)
self.method_cache.add("program_basis_set_type", single=True, update=False)
# Cache for storing current sampling method settings
......@@ -44,13 +44,10 @@ class NWChemMainParser(MainHierarchicalParser):
# Cache for storing frame sequence information
self.frame_sequence_cache = CacheService(self.parser_context)
self.frame_sequence_cache.add("number_of_frames_in_sequence", 0, single=False, update=True)
self.frame_sequence_cache.add("frame_sequence_local_frames_ref", [], single=False, update=True)
self.frame_sequence_cache.add("frame_sequence_potential_energy", [], single=False, update=True)
self.frame_sequence_cache.add("frame_sequence_kinetic_energy", [], single=False, update=True)
self.frame_sequence_cache.add("frame_sequence_temperature", [], single=False, update=True)
self.frame_sequence_cache.add("frame_sequence_to_frames_ref", [], single=False, update=True)
self.frame_sequence_cache.add("frame_sequence_time", [], single=False, update=True)
self.frame_sequence_cache.add("frame_sequence_to_sampling_ref", single=False, update=True)
self.frame_sequence_cache.add("frame_sequence_to_sampling_method_ref", single=False, update=True)
# Cache for storing system information
self.system_cache = CacheService(self.parser_context)
self.system_cache.add("initial_positions", single=False, update=False)
......@@ -257,8 +254,8 @@ class NWChemMainParser(MainHierarchicalParser):
SM(" NWChem DFT Module",
repeats=True,
sections=[
"x_nwchem_section_qmd_step",
"section_single_configuration_calculation",
"x_nwchem_section_qmd_step",
"section_system"
],
onClose={
......@@ -272,7 +269,7 @@ class NWChemMainParser(MainHierarchicalParser):
SM(" Total DFT energy =\s+(?P<energy_total__hartree>{})".format(self.regexs.float)),
SM(" One electron energy =\s+(?P<x_nwchem_energy_one_electron__hartree>{})".format(self.regexs.float)),
SM(" Coulomb energy =\s+(?P<x_nwchem_energy_coulomb__hartree>{})".format(self.regexs.float)),
SM(" Exchange-Corr\. energy =\s+(?P<energy_XC__hartree>{})".format(self.regexs.float)),
SM(" Exchange-Corr\. energy =\s+(?P<energy_xc__hartree>{})".format(self.regexs.float)),
SM(" Nuclear repulsion energy =\s+(?P<x_nwchem_energy_nuclear_repulsion__hartree>{})".format(self.regexs.float)),
SM(" Numeric\. integr\. density =\s+{}".format(self.regexs.float)),
SM(" Total iterative time =\s+(?P<time_calculation__s>{})".format(self.regexs.float)),
......@@ -287,11 +284,11 @@ class NWChemMainParser(MainHierarchicalParser):
SM(" QMD Run Information",
subMatchers=[
SM(" Time elapsed \(fs\) :\s+(?P<x_nwchem_qmd_step_time__fs>{})".format(self.regexs.float)),
SM(" Kin. energy \(a\.u\.\):\s+{}\s+(?P<x_nwchem_qmd_step_kinetic_energy__hartree>{})".format(self.regexs.int, self.regexs.float)),
SM(" Pot. energy \(a\.u\.\):\s+{}\s+(?P<x_nwchem_qmd_step_potential_energy__hartree>{})".format(self.regexs.int, self.regexs.float)),
SM(" Kin. energy \(a\.u\.\):\s+{}\s+(?P<kinetic_energy__hartree>{})".format(self.regexs.int, self.regexs.float)),
SM(" Pot. energy \(a\.u\.\):\s+{}\s+(?P<potential_energy__hartree>{})".format(self.regexs.int, self.regexs.float)),
SM(" Tot. energy \(a\.u\.\):\s+{}\s+(?P<x_nwchem_qmd_step_total_energy__hartree>{})".format(self.regexs.int, self.regexs.float)),
SM(" Target temp\. \(K\) :\s+{}\s+(?P<x_nwchem_qmd_step_target_temperature__K>{})".format(self.regexs.int, self.regexs.float)),
SM(" Current temp\. \(K\) :\s+{}\s+(?P<x_nwchem_qmd_step_temperature__K>{})".format(self.regexs.int, self.regexs.float)),
SM(" Current temp\. \(K\) :\s+{}\s+(?P<instant_temperature__K>{})".format(self.regexs.int, self.regexs.float)),
SM(" Dipole \(a\.u\.\) :\s+{0}\s+({1}\s+{1}\s+{1})".format(self.regexs.int, self.regexs.float), startReAction=self.transform_dipole)
]
)
......@@ -419,8 +416,8 @@ class NWChemMainParser(MainHierarchicalParser):
SM( r" Total DFT energy =\s+(?P<energy_total__hartree>{})".format(self.regexs.float)),
SM( r" One electron energy =\s+(?P<x_nwchem_energy_one_electron__hartree>{})".format(self.regexs.float)),
SM( r" Coulomb energy =\s+(?P<x_nwchem_energy_coulomb__hartree>{})".format(self.regexs.float)),
SM( r" Exchange energy =\s+(?P<energy_X__hartree>{})".format(self.regexs.float)),
SM( r" Correlation energy =\s+(?P<energy_C__hartree>{})".format(self.regexs.float)),
SM( r" Exchange energy =\s+(?P<energy_x__hartree>{})".format(self.regexs.float)),
SM( r" Correlation energy =\s+(?P<energy_c__hartree>{})".format(self.regexs.float)),
SM( r" Nuclear repulsion energy =\s+(?P<x_nwchem_energy_nuclear_repulsion__hartree>{})".format(self.regexs.float)),
self.dft_gradient_module(),
]
......@@ -445,10 +442,11 @@ class NWChemMainParser(MainHierarchicalParser):
def onClose_section_single_configuration_calculation(self, backend, gIndex, section):
self.scc_cache.addValue("single_configuration_calculation_to_system_ref")
self.method_cache.addValue("single_configuration_to_calculation_method_ref")
self.method_cache.addValue("single_configuration_calculation_to_method_ref")
if self.scc_cache["atom_forces"] is not None:
fId = backend.openSection("section_atom_forces")
self.scc_cache.addArrayValues("atom_forces", unit="forceAu")
backend.closeSection("section_atom_forces", fId)
if self.scc_cache["number_of_scf_iterations"]:
self.scc_cache.addValue("number_of_scf_iterations")
......@@ -569,15 +567,15 @@ class NWChemMainParser(MainHierarchicalParser):
xc_summary += "{}*{}".format(xc.weight, xc.name)
# Push the XC sections
id_xc = backend.openSection("section_XC_functionals")
backend.addValue("XC_functional_name", xc.name)
id_xc = backend.openSection("section_xc_functionals")
backend.addValue("xc_functional_name", xc.name)
if xc.weight is not None:
backend.addValue("XC_functional_weight", xc.weight)
backend.closeSection("section_XC_functionals", id_xc)
backend.addValue("xc_functional_weight", xc.weight)
backend.closeSection("section_xc_functionals", id_xc)
# Push the summary string
if xc_summary is not "":
self.backend.addValue("XC_functional", xc_summary)
self.backend.addValue("xc_functional", xc_summary)
def onClose_section_sampling_method(self, backend, gIndex, section):
......@@ -600,29 +598,11 @@ class NWChemMainParser(MainHierarchicalParser):
def onClose_section_frame_sequence(self, backend, gIndex, section):
self.frame_sequence_cache.addValue("number_of_frames_in_sequence")
frame_sequence = self.frame_sequence_cache["frame_sequence_local_frames_ref"]
frame_sequence = self.frame_sequence_cache["frame_sequence_to_frames_ref"]
if frame_sequence:
frame_sequence = np.array(frame_sequence)
self.backend.addArrayValues("frame_sequence_local_frames_ref", frame_sequence)
self.frame_sequence_cache.addValue("frame_sequence_to_sampling_ref")
potential_energy = self.frame_sequence_cache["frame_sequence_potential_energy"]
if potential_energy:
potential_energy = np.array(potential_energy)
backend.addArrayValues("frame_sequence_potential_energy", potential_energy)
backend.addArrayValues("frame_sequence_potential_energy_stats", np.array([potential_energy.mean(), potential_energy.std()]))
kin_energy = self.frame_sequence_cache["frame_sequence_kinetic_energy"]
if kin_energy:
kin_energy = np.array(kin_energy)
backend.addArrayValues("frame_sequence_kinetic_energy", kin_energy)
backend.addArrayValues("frame_sequence_kinetic_energy_stats", np.array([kin_energy.mean(), kin_energy.std()]))
temp = self.frame_sequence_cache["frame_sequence_temperature"]
if temp:
temp = np.array(temp)
backend.addArrayValues("frame_sequence_temperature", temp)
backend.addArrayValues("frame_sequence_temperature_stats", np.array([temp.mean(), temp.std()]))
self.backend.addArrayValues("frame_sequence_to_frames_ref", frame_sequence)
self.frame_sequence_cache.addValue("frame_sequence_to_sampling_method_ref")
time = self.frame_sequence_cache["frame_sequence_time"]
if time:
......@@ -637,18 +617,6 @@ class NWChemMainParser(MainHierarchicalParser):
def onClose_x_nwchem_section_qmd_step(self, backend, gIndex, section):
self.frame_sequence_cache["number_of_frames_in_sequence"] += 1
potential_energy = section.get_latest_value("x_nwchem_qmd_step_potential_energy")
if potential_energy is not None:
self.frame_sequence_cache["frame_sequence_potential_energy"].append(potential_energy)
kin_energy = section.get_latest_value("x_nwchem_qmd_step_kinetic_energy")
if kin_energy is not None:
self.frame_sequence_cache["frame_sequence_kinetic_energy"].append(kin_energy)
temp = section.get_latest_value("x_nwchem_qmd_step_temperature")
if temp is not None:
self.frame_sequence_cache["frame_sequence_temperature"].append(temp)
time = section.get_latest_value("x_nwchem_qmd_step_time")
if time is not None:
self.frame_sequence_cache["frame_sequence_time"].append(time)
......@@ -656,19 +624,19 @@ class NWChemMainParser(MainHierarchicalParser):
def onClose_x_nwchem_section_geo_opt_step(self, backend, gIndex, section):
self.frame_sequence_cache["number_of_frames_in_sequence"] += 1
pot_ener = section.get_latest_value("x_nwchem_geo_opt_step_energy")
if pot_ener is not None:
self.frame_sequence_cache["frame_sequence_potential_energy"].append(pot_ener)
# too late to add to section_single_configuration_calculation as potential_energy without reopening it
# should open the section_single_configuration_calculation one level higher
#=======================================================================
# onOpen triggers
def onOpen_section_method(self, backend, gIndex, section):
self.method_cache["single_configuration_to_calculation_method_ref"] = gIndex
self.method_cache["single_configuration_calculation_to_method_ref"] = gIndex
def onOpen_section_system(self, backend, gIndex, section):
self.scc_cache["single_configuration_calculation_to_system_ref"] = gIndex
def onOpen_section_sampling_method(self, backend, gIndex, section):
self.frame_sequence_cache["frame_sequence_to_sampling_ref"] = gIndex
self.frame_sequence_cache["frame_sequence_to_sampling_method_ref"] = gIndex
def onOpen_x_nwchem_section_qmd_module(self, backend, gIndex, section):
self.sampling_method_cache["sampling_method"] = "molecular_dynamics"
......@@ -752,10 +720,10 @@ class NWChemMainParser(MainHierarchicalParser):
#=======================================================================
# SimpleMatcher specific onClose
def save_geo_opt_sampling_id(self, backend, gIndex, section):
backend.addValue("frame_sequence_to_sampling_ref", gIndex)
backend.addValue("frame_sequence_to_sampling_method_ref", gIndex)
def add_frame_reference(self, backend, gIndex, section):
self.frame_sequence_cache["frame_sequence_local_frames_ref"].append(gIndex)
self.frame_sequence_cache["frame_sequence_to_frames_ref"].append(gIndex)
def push_no_periodicity(self, backend, gIndex, section):
self.system_cache["configuration_periodic_dimensions"] = np.array([False, False, False])
......
......@@ -65,7 +65,7 @@ class TestDFTGaussianEnergy(unittest.TestCase):
self.assertEqual(result, "gaussians")
def test_xc_functional(self):
result = self.results["XC_functional"]
result = self.results["xc_functional"]
self.assertEqual(result, "1.0*MGGA_C_TPSS+1.0*MGGA_X_TPSS")
def test_atom_labels(self):
......@@ -98,12 +98,12 @@ class TestDFTGaussianEnergy(unittest.TestCase):
self.assertTrue(np.array_equal(result, expected_result))
def test_energy_x(self):
result = self.results["energy_X"]
result = self.results["energy_x"]
expected_result = convert_unit(np.array(-9.025345841743), "hartree")
self.assertTrue(np.array_equal(result, expected_result))
def test_energy_c(self):
result = self.results["energy_C"]
result = self.results["energy_c"]
expected_result = convert_unit(np.array(-0.328011552453), "hartree")
self.assertTrue(np.array_equal(result, expected_result))
......@@ -147,7 +147,7 @@ class TestDFTGaussianEnergy(unittest.TestCase):
self.assertEqual(multiplicity, 1)
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):
......@@ -211,7 +211,7 @@ class TestDFTGaussianForce(unittest.TestCase):
self.assertEqual(result, "DFT")
def test_xc_functional(self):
result = self.results["XC_functional"]
result = self.results["xc_functional"]
self.assertEqual(result, "1.0*MGGA_C_TPSS+1.0*MGGA_X_TPSS")
def test_atom_forces(self):
......@@ -243,7 +243,7 @@ class TestDFTGaussianGeoOpt(unittest.TestCase):
self.assertTrue(np.array_equal(result, np.array([False, False, False])))
def test_xc_functional(self):
result = self.results["XC_functional"]
result = self.results["xc_functional"]
self.assertEqual(result, "1.0*MGGA_C_TPSS+1.0*MGGA_X_TPSS")
def test_electronic_structure_method(self):
......@@ -254,11 +254,11 @@ class TestDFTGaussianGeoOpt(unittest.TestCase):
sequence = self.results["section_frame_sequence"][0]
# Number of frames
n_frames = self.results["number_of_frames_in_sequence"]
n_frames = self.results["xxx_to_rm_number_of_frames_in_sequence"]
self.assertEqual(n_frames, 4)
# Potential energy
pot_ener = sequence["frame_sequence_potential_energy"]
pot_ener = sequence["potential_energy"]
expected_pot_ener = convert_unit(
np.array([
-76.42941861,
......@@ -290,7 +290,7 @@ class TestDFTGaussianGeoOpt(unittest.TestCase):
self.assertTrue(np.array_equal(np.array([positions[0], positions[-1]]), expected_pos))
# Test labels
scc_indices = self.results["frame_sequence_local_frames_ref"]
scc_indices = self.results["frame_sequence_to_frames_ref"]
sccs = self.results["section_single_configuration_calculation"]
systems = self.results["section_system"]
labels = []
......@@ -351,11 +351,11 @@ class TestDFTGaussianGeoOpt(unittest.TestCase):
self.assertTrue(np.array_equal(result[0], expected_start))
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, 2, 4, 6])
self.assertTrue(np.array_equal(result, expected_result))
......@@ -426,7 +426,7 @@ class TestDFTGaussianMD(unittest.TestCase):
return system
def get_scc(self, index):
sample_refs = self.results["frame_sequence_local_frames_ref"]
sample_refs = self.results["frame_sequence_to_frames_ref"]
sccs = self.results["section_single_configuration_calculation"]
scc = sccs[sample_refs[index]]
return scc
......@@ -436,7 +436,7 @@ class TestDFTGaussianMD(unittest.TestCase):
self.assertTrue(np.array_equal(result, np.array([False, False, False])))
def test_single_configuration_to_calculation_method(self):
result = self.results["single_configuration_to_calculation_method_ref"]
result = self.results["single_configuration_calculation_to_method_ref"]
self.assertTrue(np.array_equal(result, np.array(6*[0])))
def test_electronic_structure_method(self):
......@@ -444,7 +444,7 @@ class TestDFTGaussianMD(unittest.TestCase):
self.assertEqual(result, "DFT")
def test_xc_functional(self):
result = self.results["XC_functional"]
result = self.results["xc_functional"]
self.assertEqual(result, "1.0*HYB_GGA_XC_PBEH")
def test_sampling_method(self):
......@@ -456,27 +456,27 @@ class TestDFTGaussianMD(unittest.TestCase):
self.assertEqual(result, "NVT")
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"]
self.assertTrue(np.array_equal(result, np.array(range(1, 6))))
def test_number_of_frames_in_sequence(self):
result = self.results["number_of_frames_in_sequence"]
result = self.results["xxx_to_rm_number_of_frames_in_sequence"]
self.assertEqual(result, 5)
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_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):
......@@ -574,59 +574,59 @@ class TestDFTGaussianXCFunctional(unittest.TestCase):
"""Tests that the XC functionals can be properly parsed.
"""
def test_blyp(self):
xc = get_result("dft_gaussian/functionals/blyp", "XC_functional")
xc = get_result("dft_gaussian/functionals/blyp", "xc_functional")
self.assertEqual(xc, "1.0*GGA_C_LYP+1.0*GGA_X_B88")
def test_b3lyp(self):
xc = get_result("dft_gaussian/functionals/b3lyp", "XC_functional")
xc = get_result("dft_gaussian/functionals/b3lyp", "xc_functional")
self.assertEqual(xc, "1.0*HYB_GGA_XC_B3LYP")
def test_pbe(self):
xc = get_result("dft_gaussian/functionals/pbe", "XC_functional")
xc = get_result("dft_gaussian/functionals/pbe", "xc_functional")
self.assertEqual(xc, "1.0*GGA_C_PBE+1.0*GGA_X_PBE")
def test_pbe0(self):
xc = get_result("dft_gaussian/functionals/pbe0", "XC_functional")
xc = get_result("dft_gaussian/functionals/pbe0", "xc_functional")
self.assertEqual(xc, "1.0*HYB_GGA_XC_PBEH")
def test_bp86(self):
xc = get_result("dft_gaussian/functionals/bp86", "XC_functional")
xc = get_result("dft_gaussian/functionals/bp86", "xc_functional")
self.assertEqual(xc, "1.0*GGA_C_P86+1.0*GGA_X_B88")
def test_bp91(self):
xc = get_result("dft_gaussian/functionals/bp91", "XC_functional")
xc = get_result("dft_gaussian/functionals/bp91", "xc_functional")
self.assertEqual(xc, "1.0*GGA_C_PW91+1.0*GGA_X_B88")
def test_pw91(self):
xc = get_result("dft_gaussian/functionals/pw91", "XC_functional")
xc = get_result("dft_gaussian/functionals/pw91", "xc_functional")
self.assertEqual(xc, "1.0*GGA_C_PW91+1.0*GGA_X_PW91")
def test_bechehandh(self):
xc = get_result("dft_gaussian/functionals/beckehandh", "XC_functional")
xc = get_result("dft_gaussian/functionals/beckehandh", "xc_functional")
self.assertEqual(xc, "1.0*HYB_GGA_XC_BHANDH")
def test_olyp(self):
xc = get_result("dft_gaussian/functionals/olyp", "XC_functional")
xc = get_result("dft_gaussian/functionals/olyp", "xc_functional")
self.assertEqual(xc, "1.0*GGA_C_LYP+1.0*GGA_X_OPTX")
def test_hcth120(self):
xc = get_result("dft_gaussian/functionals/hcth120", "XC_functional")
xc = get_result("dft_gaussian/functionals/hcth120", "xc_functional")
self.assertEqual(xc, "1.0*GGA_XC_HCTH_120")
def test_hcth147(self):
xc = get_result("dft_gaussian/functionals/hcth147", "XC_functional")
xc = get_result("dft_gaussian/functionals/hcth147", "xc_functional")
self.assertEqual(xc, "1.0*GGA_XC_HCTH_147")
def test_hcth407(self):
xc = get_result("dft_gaussian/functionals/hcth407", "XC_functional")
xc = get_result("dft_gaussian/functionals/hcth407", "xc_functional")
self.assertEqual(xc, "1.0*GGA_XC_HCTH_407")
def test_tpss(self):
xc = get_result("dft_gaussian/functionals/tpss", "XC_functional")
xc = get_result("dft_gaussian/functionals/tpss", "xc_functional")
self.assertEqual(xc, "1.0*MGGA_C_TPSS+1.0*MGGA_X_TPSS")
def test_slater_vwn5(self):
xc = get_result("dft_gaussian/functionals/slater_vwn5", "XC_functional")
xc = get_result("dft_gaussian/functionals/slater_vwn5", "xc_functional")
self.assertEqual(xc, "1.0*LDA_C_VWN+1.0*LDA_X")
......@@ -699,12 +699,12 @@ class TestDFTPWEnergy(unittest.TestCase):
# self.assertTrue(np.array_equal(result, expected_result))
# def test_energy_x(self):
# result = self.results["energy_X"]
# result = self.results["energy_x"]
# expected_result = convert_unit(np.array(-9.025345841743), "hartree")
# self.assertTrue(np.array_equal(result, expected_result))
# def test_energy_c(self):
# result = self.results["energy_C"]
# result = self.results["energy_c"]
# expected_result = convert_unit(np.array(-0.328011552453), "hartree")
# self.assertTrue(np.array_equal(result, expected_result))
......@@ -744,7 +744,7 @@ class TestDFTPWEnergy(unittest.TestCase):
# self.assertEqual(multiplicity, 1)
# 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):
......
......@@ -57,7 +57,7 @@ object NWChemParser extends SimpleExternalParserGenerator(
"parser-nwchem/nwchemparser/versions/nwchem66/mainparser.py",
"nomad_meta_info/public.nomadmetainfo.json",
"nomad_meta_info/common.nomadmetainfo.json",
"nomad_meta_info/meta_types.nomadmetainfo.json",
"nomad_meta_info/meta.nomadmetainfo.json",
"nomad_meta_info/nwchem.nomadmetainfo.json"
) ++ DefaultPythonInterpreter.commonFiles(),
dirMap = Map(
......
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