From 6934e58b00adf867a12d7fc0176b51cf2a0165cf Mon Sep 17 00:00:00 2001 From: hongriTianqi Date: Tue, 2 Aug 2022 10:32:44 +0800 Subject: [PATCH 1/2] test: add UT for to_system for abacus interface --- dpdata/abacus/scf.py | 2 +- tests/test_abacus_md.py | 22 +++++++++++++++++++++- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/dpdata/abacus/scf.py b/dpdata/abacus/scf.py index ee5208820..0cc9e1cab 100644 --- a/dpdata/abacus/scf.py +++ b/dpdata/abacus/scf.py @@ -233,7 +233,7 @@ def make_unlabeled_stru(data, frame_idx, pp_file=None, numerical_orbital=None, n for iele in range(len(data['atom_names'])): out += data['atom_names'][iele] + " " if mass is not None: - out += "%d "%mass[iele] + out += "%.3f "%mass[iele] else: out += "1 " if pp_file is not None: diff --git a/tests/test_abacus_md.py b/tests/test_abacus_md.py index 14607bbaf..d039211b0 100644 --- a/tests/test_abacus_md.py +++ b/tests/test_abacus_md.py @@ -85,6 +85,22 @@ def test_energy(self) : np.testing.assert_almost_equal(self.system_water.data['energies'], ref_energy) np.testing.assert_almost_equal(self.system_Si.data['energies'], ref_energy2) + def test_to_system(self): + pp_file=["H.upf","O.upf"] + numerical_orbital=["H.upf","O.upf"] + numerical_descriptor="jle.orb" + mass=[1.008,15.994] + self.system_water.to(file_name="abacus.md/water_stru",fmt='abacus/stru',pp_file=pp_file,\ + numerical_orbital=numerical_orbital,numerical_descriptor=numerical_descriptor,\ + mass=mass) + self.assertTrue(os.path.isfile('abacus.md/water_stru')) + if os.path.isfile('abacus.md/water_stru'): + with open('abacus.md/water_stru') as f: + iline=0 + for iline,l in enumerate(f): + iline += 1 + self.assertEqual(iline,30) + class TestABACUSMDLabeledOutput(unittest.TestCase, TestABACUSMD): @@ -92,5 +108,9 @@ def setUp(self): self.system_water = dpdata.LabeledSystem('abacus.md',fmt='abacus/md') # system with stress self.system_Si = dpdata.LabeledSystem('abacus.md.nostress',fmt='abacus/md') # system without stress + def tearDown(self): + if os.path.isfile('abacus.md/water_stru'): + os.remove('abacus.md/water_stru') + if __name__ == '__main__': - unittest.main() \ No newline at end of file + unittest.main() From b04019a465da2c04947351db39db0cec6ae472b8 Mon Sep 17 00:00:00 2001 From: hongriTianqi Date: Tue, 2 Aug 2022 11:46:23 +0800 Subject: [PATCH 2/2] update atomic mass in abacus.scf/stru_test --- tests/abacus.scf/stru_test | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/abacus.scf/stru_test b/tests/abacus.scf/stru_test index 7e7323a1a..22d619c93 100644 --- a/tests/abacus.scf/stru_test +++ b/tests/abacus.scf/stru_test @@ -1,6 +1,6 @@ ATOMIC_SPECIES -C 12 C.upf -H 1 H.upf +C 12.000 C.upf +H 1.000 H.upf NUMERICAL_ORBITAL C.orb