Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions dpdata/abacus/scf.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
28 changes: 13 additions & 15 deletions tests/test_abacus_pw_scf.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'])
Expand Down Expand Up @@ -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")
Expand Down