From 1911784599024f43c75ee89f871c92f52e4b3f8f Mon Sep 17 00:00:00 2001 From: Guido Petretto Date: Tue, 6 Sep 2022 23:53:10 +0200 Subject: [PATCH] add outcar tests --- pymatgen/io/vasp/tests/test_outputs.py | 28 ++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/pymatgen/io/vasp/tests/test_outputs.py b/pymatgen/io/vasp/tests/test_outputs.py index a370d239f0d..5ee650ff4f5 100644 --- a/pymatgen/io/vasp/tests/test_outputs.py +++ b/pymatgen/io/vasp/tests/test_outputs.py @@ -1543,6 +1543,34 @@ def test_energies(self): self.assertAlmostEqual(o.final_energy_wo_entrp, -15.83863167) self.assertAlmostEqual(o.final_fr_energy, -15.92115453) + def test_read_table_pattern(self): + outcar = Outcar(self.TEST_FILES_DIR / "OUTCAR") + + header_pattern = r"\(the norm of the test charge is\s+[\.\-\d]+\)" + table_pattern = r"((?:\s+\d+\s*[\.\-\d]+)+)" + footer_pattern = r"\s+E-fermi :" + + pots = outcar.read_table_pattern(header_pattern, table_pattern, footer_pattern, last_one_only=True) + ref_last = [ + [" 1 -26.0704 2 -45.5046 3 -45.5046 4 -72.9539 5 -73.0621"], + [" 6 -72.9539 7 -73.0621"], + ] + self.assertEqual(pots, ref_last) + + pots = outcar.read_table_pattern( + header_pattern, table_pattern, footer_pattern, last_one_only=False, first_one_only=True + ) + ref_first = [ + [" 1 -26.1149 2 -45.5359 3 -45.5359 4 -72.9831 5 -73.1068"], + [" 6 -72.9831 7 -73.1068"], + ] + self.assertEqual(pots, ref_first) + + with self.assertRaises(ValueError): + outcar.read_table_pattern( + header_pattern, table_pattern, footer_pattern, last_one_only=True, first_one_only=True + ) + class BSVasprunTest(PymatgenTest): _multiprocess_shared_ = True