Commit 85e6c71d authored by Lauri Himanen's avatar Lauri Himanen

Fixed the issue with repeating information added to backend.

parent 0d9c5dbd
......@@ -10,7 +10,7 @@ LOGGER = logging.getLogger("nomad")
#===============================================================================
class NWChemMainParser(MainHierarchicalParser):
"""The main parser class that is called for all run types. Parses the CPMD
"""The main parser class that is called for all run types. Parses the NWChem
output file.
"""
def __init__(self, file_path, parser_context):
......@@ -22,6 +22,8 @@ class NWChemMainParser(MainHierarchicalParser):
self.frame_sequence_local_frames_ref = []
self.method_index = None
self.system_index = None
self.electronic_structure_method = None
self.save_method = False
#=======================================================================
# Cache levels
......@@ -239,7 +241,10 @@ class NWChemMainParser(MainHierarchicalParser):
backend.addValue("single_configuration_calculation_to_system_ref", self.system_index)
def onClose_x_nwchem_section_dft(self, backend, gIndex, section):
backend.addValue("electronic_structure_method", "DFT")
self.electronic_structure_method = "DFT"
def onClose_section_method(self, backend, gIndex, section):
backend.addValue("electronic_structure_method", self.electronic_structure_method)
def onClose_x_nwchem_section_geo_opt_task(self, backend, gIndex, section):
steps = section["x_nwchem_section_geo_opt_step"]
......@@ -268,6 +273,7 @@ class NWChemMainParser(MainHierarchicalParser):
# onOpen triggers
def onOpen_section_method(self, backend, gIndex, section):
self.method_index = gIndex
self.save_method = True
#=======================================================================
# adHoc
......@@ -343,12 +349,24 @@ class NWChemMainParser(MainHierarchicalParser):
section.add_latest_value("x_nwchem_dft_energy_total", "energy_total")
section.add_latest_value("x_nwchem_dft_energy_X", "energy_X")
section.add_latest_value("x_nwchem_dft_energy_C", "energy_C")
section.add_latest_value("x_nwchem_dft_spin_multiplicity", "spin_target_multiplicity")
# section.add_latest_value("x_nwchem_dft_spin_multiplicity", "spin_target_multiplicity")
section.add_latest_value("x_nwchem_dft_number_of_atoms", "number_of_atoms")
section.add_latest_value("x_nwchem_dft_total_charge", "total_charge")
section.add_latest_value("x_nwchem_dft_max_iteration", "scf_max_iteration")
section.add_latest_value("x_nwchem_dft_scf_threshold_energy_change", "scf_threshold_energy_change")
# section.add_latest_value("x_nwchem_dft_total_charge", "total_charge")
# section.add_latest_value("x_nwchem_dft_max_iteration", "scf_max_iteration")
# section.add_latest_value("x_nwchem_dft_scf_threshold_energy_change", "scf_threshold_energy_change")
backend.addValue("number_of_scf_iterations", self.n_scf_iterations)
# If a geo opt has just been started, save the general settings
if self.save_method:
section.add_latest_value("x_nwchem_dft_spin_multiplicity", "spin_target_multiplicity")
section.add_latest_value("x_nwchem_dft_total_charge", "total_charge")
section.add_latest_value("x_nwchem_dft_max_iteration", "scf_max_iteration")
section.add_latest_value("x_nwchem_dft_scf_threshold_energy_change", "scf_threshold_energy_change")
self.save_method = False
# print(multiplicity)
# print(energy_total)
self.n_scf_iterations = 0
return wrapper
......@@ -381,3 +399,8 @@ class NWChemMainParser(MainHierarchicalParser):
backend.addArrayValues("frame_sequence_local_frames_ref", np.array(self.frame_sequence_local_frames_ref))
self.frame_sequence_local_frames_ref = []
return wrapper
def save_method(self):
def wrapper(backend, gIndex, section):
self.save_method = True
return wrapper
......@@ -138,7 +138,7 @@ class TestDFTEnergy(unittest.TestCase):
result = self.results["number_of_scf_iterations"]
self.assertEqual(result, 6)
def test_target_multiplicity(self):
def test_spin_target_multiplicity(self):
multiplicity = self.results["spin_target_multiplicity"]
self.assertEqual(multiplicity, 1)
......@@ -146,9 +146,9 @@ class TestDFTEnergy(unittest.TestCase):
result = self.results["single_configuration_to_calculation_method_ref"]
self.assertEqual(result, 0)
# def test_single_configuration_calculation_to_system_description_ref(self):
# result = self.results["single_configuration_calculation_to_system_ref"]
# self.assertEqual(result, 0)
def test_single_configuration_calculation_to_system_description_ref(self):
result = self.results["single_configuration_calculation_to_system_ref"]
self.assertEqual(result, 0)
# def test_single_configuration_calculation_converged(self):
# result = self.results["single_configuration_calculation_converged"]
......@@ -260,7 +260,8 @@ class TestDFTGeoOpt(unittest.TestCase):
self.assertEqual(n_frames, 4)
# Potential energy
pot_ener = sequence["frame_sequence_potential_energy"][0]
pot_ener = sequence["frame_sequence_potential_energy"]
# print(pot_ener)
expected_pot_ener = convert_unit(
np.array([
-76.42941861,
......@@ -1053,9 +1054,9 @@ class TestDFTGeoOpt(unittest.TestCase):
#===============================================================================
if __name__ == '__main__':
suites = []
# suites.append(unittest.TestLoader().loadTestsFromTestCase(TestDFTEnergy))
suites.append(unittest.TestLoader().loadTestsFromTestCase(TestDFTEnergy))
suites.append(unittest.TestLoader().loadTestsFromTestCase(TestDFTForce))
# suites.append(unittest.TestLoader().loadTestsFromTestCase(TestDFTGeoOpt))
suites.append(unittest.TestLoader().loadTestsFromTestCase(TestDFTGeoOpt))
# suites.append(unittest.TestLoader().loadTestsFromTestCase(TestGeoOpt))
# suites.append(unittest.TestLoader().loadTestsFromTestCase(TestInputParser))
......
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