Commit 1668499d authored by Lauri Himanen's avatar Lauri Himanen
Browse files

Added tests for SCF total energy, cleaned the outputparsing tree.

parent 0c16bc9c
......@@ -50,9 +50,9 @@ class CP2KOutputParser(FileParser):
]
),
SM(
# sections=["cp2k_section_cell"],
startReStr=" CELL\|",
adHoc=self.adHoc_cp2k_section_cell()
adHoc=self.adHoc_cp2k_section_cell(),
otherMetaInfo=["section_system_description", "simulation_cell"]
),
SM(
sections=["cp2k_section_functional"],
......@@ -71,8 +71,8 @@ class CP2KOutputParser(FileParser):
startReStr=" TOTAL NUMBERS AND MAXIMUM NUMBERS",
subMatchers=[
SM(
sections=["section_system_description"],
startReStr="\s+- Atoms:\s+(?P<number_of_atoms>\d+)",
sections=["section_system_description"]
),
SM(
startReStr="\s+- Shell sets:\s+(?P<cp2k_shell_sets>\d+)"
......@@ -80,8 +80,10 @@ class CP2KOutputParser(FileParser):
]
),
SM(
sections=["section_system_description"],
startReStr=" MODULE QUICKSTEP: ATOMIC COORDINATES IN angstrom",
adHoc=self.adHoc_cp2k_section_quickstep_atom_information(),
otherMetaInfo=["atom_label", "atom_position"]
),
# SCF
SM(
......@@ -90,7 +92,7 @@ class CP2KOutputParser(FileParser):
subMatchers=[
SM(
sections=["section_scf_iteration"],
startReStr=r"\s+\d+\s+\S+\s+{f}\s+{f}\s+{f}\s+(?P<energy_total_scf_iteration>{f})\s+{f}".format(f=self.f_regex),
startReStr=r"\s+\d+\s+\S+\s+{f}\s+{f}\s+{f}\s+(?P<energy_total_scf_iteration__hartree>{f})\s+{f}".format(f=self.f_regex),
repeats=True,
),
]
......@@ -293,9 +295,9 @@ class CP2KOutputParser(FileParser):
# If anything found, push the results to the correct section
if len(coordinates) != 0:
gIndex = parser.backend.openSection("section_system_description")
# gIndex = parser.backend.openSection("section_system_description")
parser.backend.addArrayValues("atom_position", coordinates, unit="angstrom")
parser.backend.addArrayValues("atom_label", labels)
parser.backend.closeSection("section_system_description", gIndex)
# parser.backend.closeSection("section_system_description", gIndex)
return wrapper
......@@ -13,7 +13,7 @@ from nomadcore.unit_conversion.unit_conversion import convert_unit
#===============================================================================
def get_result(folder, metaname):
def get_results(folder, metainfo_to_keep=None):
"""Get the given result from the calculation in the given folder by using
the Analyzer in the nomadtoolkit package. Tries to optimize the parsing by
giving the metainfo_to_keep argument.
......@@ -25,9 +25,15 @@ def get_result(folder, metaname):
"""
dirname = os.path.dirname(__file__)
folder = os.path.join(dirname, folder)
parser = CP2KParser(contents=folder, metainfo_to_keep=[metaname])
parser = CP2KParser(folder, metainfo_to_keep)
analyzer = Analyzer(parser)
results = analyzer.parse()
return results
#===============================================================================
def get_result(folder, metaname):
results = get_results(folder, metaname)
result = results[metaname]
return result.value
......@@ -90,16 +96,43 @@ class TestAtomLabels(unittest.TestCase):
expected_labels = np.array(["Si"])
self.assertTrue(np.array_equal(atom_labels, expected_labels))
#===============================================================================
class TestSectionSCFIteration(unittest.TestCase):
results = get_results("section_scf_iteration", "section_scf_iteration")
def test_energy_total(self):
energy_total = self.results["energy_total_scf_iteration"].value
expected_result = convert_unit(np.array(-32.2320848878), "hartree")
self.assertTrue(np.array_equal(energy_total[0], expected_result))
#===============================================================================
class TestSectionSystemDescription(unittest.TestCase):
results = get_results("section_system_description", "section_system_description")
def test_atom_label(self):
for item in self.results.itervalues():
print item
print item.value
# atom_labels = self.results["atom_label"].value
# expected_labels = np.array(8*["Si"])
# self.assertTrue(np.array_equal(atom_labels, expected_labels))
#===============================================================================
if __name__ == '__main__':
logger = logging.getLogger("cp2kparser")
logger.setLevel(logging.ERROR)
suites = []
suites.append(unittest.TestLoader().loadTestsFromTestCase(TestXCFunctional))
suites.append(unittest.TestLoader().loadTestsFromTestCase(TestSimulationCell))
suites.append(unittest.TestLoader().loadTestsFromTestCase(TestNumberOfAtoms))
suites.append(unittest.TestLoader().loadTestsFromTestCase(TestAtomPosition))
suites.append(unittest.TestLoader().loadTestsFromTestCase(TestAtomLabels))
# suites.append(unittest.TestLoader().loadTestsFromTestCase(TestXCFunctional))
# suites.append(unittest.TestLoader().loadTestsFromTestCase(TestSimulationCell))
# suites.append(unittest.TestLoader().loadTestsFromTestCase(TestNumberOfAtoms))
# suites.append(unittest.TestLoader().loadTestsFromTestCase(TestAtomPosition))
# suites.append(unittest.TestLoader().loadTestsFromTestCase(TestAtomLabels))
# suites.append(unittest.TestLoader().loadTestsFromTestCase(TestSectionSCFIteration))
suites.append(unittest.TestLoader().loadTestsFromTestCase(TestSectionSystemDescription))
alltests = unittest.TestSuite(suites)
unittest.TextTestRunner(verbosity=0).run(alltests)
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