Skip to content

Commit 4283c9d

Browse files
refactor(abacus): get energy by keyword "final etot is" in abacus/scf (#417)
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent d7829e5 commit 4283c9d

File tree

2 files changed

+22
-24
lines changed

2 files changed

+22
-24
lines changed

dpdata/abacus/scf.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -109,16 +109,16 @@ def get_coords(celldm, cell, geometry_inlines, inlines=None):
109109

110110
def get_energy(outlines):
111111
Etot = None
112-
for line in outlines:
113-
if "!FINAL_ETOT_IS" in line:
114-
Etot = float(line.split()[1]) # in eV
115-
break
116-
if not Etot:
117-
return Etot, False
118-
for line in outlines:
119-
if "convergence has NOT been achieved!" in line:
112+
for line in reversed(outlines):
113+
if "final etot is" in line:
114+
Etot = float(line.split()[-2]) # in eV
115+
return Etot, True
116+
elif "convergence has NOT been achieved!" in line:
117+
return Etot, False
118+
elif "convergence has not been achieved" in line:
120119
return Etot, False
121-
return Etot, True
120+
121+
return Etot, False
122122

123123

124124
def get_force(outlines, natoms):

tests/test_abacus_pw_scf.py

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,19 @@
77
bohr2ang = LengthConversion("bohr", "angstrom").value()
88

99

10-
class TestABACUSSinglePointEnergy:
10+
class TestABACUSLabeledOutput(unittest.TestCase):
11+
def setUp(self):
12+
shutil.copy("abacus.scf/INPUT.ok", "abacus.scf/INPUT")
13+
self.system_ch4 = dpdata.LabeledSystem("abacus.scf", fmt="abacus/scf")
14+
# self.system_h2o = dpdata.LabeledSystem('qe.scf/02.out',fmt='qe/pw/scf')
15+
self.system_ch4_unlabeled = dpdata.System(
16+
"abacus.scf/STRU.ch4", fmt="abacus/stru"
17+
)
18+
19+
def tearDown(self):
20+
if os.path.isfile("abacus.scf/INPUT"):
21+
os.remove("abacus.scf/INPUT")
22+
1123
def test_atom_names(self):
1224
self.assertEqual(self.system_ch4.data["atom_names"], ["C", "H"])
1325
# self.assertEqual(self.system_h2o.data['atom_names'], ['O','H'])
@@ -112,20 +124,6 @@ def test_energy(self):
112124
# self.assertAlmostEqual(self.system_h2o.data['energies'][0], ref_energy)
113125

114126

115-
class TestABACUSLabeledOutput(unittest.TestCase, TestABACUSSinglePointEnergy):
116-
def setUp(self):
117-
shutil.copy("abacus.scf/INPUT.ok", "abacus.scf/INPUT")
118-
self.system_ch4 = dpdata.LabeledSystem("abacus.scf", fmt="abacus/scf")
119-
# self.system_h2o = dpdata.LabeledSystem('qe.scf/02.out',fmt='qe/pw/scf')
120-
self.system_ch4_unlabeled = dpdata.System(
121-
"abacus.scf/STRU.ch4", fmt="abacus/stru"
122-
)
123-
124-
def tearDown(self):
125-
if os.path.isfile("abacus.scf/INPUT"):
126-
os.remove("abacus.scf/INPUT")
127-
128-
129127
class TestABACUSLabeledOutputFail(unittest.TestCase):
130128
def setUp(self):
131129
shutil.copy("abacus.scf/INPUT.fail", "abacus.scf/INPUT")

0 commit comments

Comments
 (0)