diff --git a/dpdata/abacus/scf.py b/dpdata/abacus/scf.py index 94f4bf7b4..4bbd7091b 100644 --- a/dpdata/abacus/scf.py +++ b/dpdata/abacus/scf.py @@ -109,16 +109,16 @@ def get_coords(celldm, cell, geometry_inlines, inlines=None): def get_energy(outlines): Etot = None - for line in outlines: - if "!FINAL_ETOT_IS" in line: - Etot = float(line.split()[1]) # in eV - break - if not Etot: - return Etot, False - for line in outlines: - if "convergence has NOT been achieved!" in line: + for line in reversed(outlines): + if "final etot is" in line: + Etot = float(line.split()[-2]) # in eV + return Etot, True + elif "convergence has NOT been achieved!" in line: + return Etot, False + elif "convergence has not been achieved" in line: return Etot, False - return Etot, True + + return Etot, False def get_force(outlines, natoms): diff --git a/tests/test_abacus_pw_scf.py b/tests/test_abacus_pw_scf.py index fc06f2278..6ada7736f 100644 --- a/tests/test_abacus_pw_scf.py +++ b/tests/test_abacus_pw_scf.py @@ -7,7 +7,19 @@ bohr2ang = LengthConversion("bohr", "angstrom").value() -class TestABACUSSinglePointEnergy: +class TestABACUSLabeledOutput(unittest.TestCase): + def setUp(self): + shutil.copy("abacus.scf/INPUT.ok", "abacus.scf/INPUT") + self.system_ch4 = dpdata.LabeledSystem("abacus.scf", fmt="abacus/scf") + # self.system_h2o = dpdata.LabeledSystem('qe.scf/02.out',fmt='qe/pw/scf') + self.system_ch4_unlabeled = dpdata.System( + "abacus.scf/STRU.ch4", fmt="abacus/stru" + ) + + def tearDown(self): + if os.path.isfile("abacus.scf/INPUT"): + os.remove("abacus.scf/INPUT") + def test_atom_names(self): self.assertEqual(self.system_ch4.data["atom_names"], ["C", "H"]) # self.assertEqual(self.system_h2o.data['atom_names'], ['O','H']) @@ -112,20 +124,6 @@ def test_energy(self): # self.assertAlmostEqual(self.system_h2o.data['energies'][0], ref_energy) -class TestABACUSLabeledOutput(unittest.TestCase, TestABACUSSinglePointEnergy): - def setUp(self): - shutil.copy("abacus.scf/INPUT.ok", "abacus.scf/INPUT") - self.system_ch4 = dpdata.LabeledSystem("abacus.scf", fmt="abacus/scf") - # self.system_h2o = dpdata.LabeledSystem('qe.scf/02.out',fmt='qe/pw/scf') - self.system_ch4_unlabeled = dpdata.System( - "abacus.scf/STRU.ch4", fmt="abacus/stru" - ) - - def tearDown(self): - if os.path.isfile("abacus.scf/INPUT"): - os.remove("abacus.scf/INPUT") - - class TestABACUSLabeledOutputFail(unittest.TestCase): def setUp(self): shutil.copy("abacus.scf/INPUT.fail", "abacus.scf/INPUT")