Skip to content

Commit 742c2ad

Browse files
authored
test: add UT for to_system for abacus interface (#334)
* test: add UT for to_system for abacus interface * update atomic mass in abacus.scf/stru_test
1 parent c72b05d commit 742c2ad

File tree

3 files changed

+24
-4
lines changed

3 files changed

+24
-4
lines changed

dpdata/abacus/scf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ def make_unlabeled_stru(data, frame_idx, pp_file=None, numerical_orbital=None, n
233233
for iele in range(len(data['atom_names'])):
234234
out += data['atom_names'][iele] + " "
235235
if mass is not None:
236-
out += "%d "%mass[iele]
236+
out += "%.3f "%mass[iele]
237237
else:
238238
out += "1 "
239239
if pp_file is not None:

tests/abacus.scf/stru_test

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
ATOMIC_SPECIES
2-
C 12 C.upf
3-
H 1 H.upf
2+
C 12.000 C.upf
3+
H 1.000 H.upf
44

55
NUMERICAL_ORBITAL
66
C.orb

tests/test_abacus_md.py

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,12 +85,32 @@ def test_energy(self) :
8585
np.testing.assert_almost_equal(self.system_water.data['energies'], ref_energy)
8686
np.testing.assert_almost_equal(self.system_Si.data['energies'], ref_energy2)
8787

88+
def test_to_system(self):
89+
pp_file=["H.upf","O.upf"]
90+
numerical_orbital=["H.upf","O.upf"]
91+
numerical_descriptor="jle.orb"
92+
mass=[1.008,15.994]
93+
self.system_water.to(file_name="abacus.md/water_stru",fmt='abacus/stru',pp_file=pp_file,\
94+
numerical_orbital=numerical_orbital,numerical_descriptor=numerical_descriptor,\
95+
mass=mass)
96+
self.assertTrue(os.path.isfile('abacus.md/water_stru'))
97+
if os.path.isfile('abacus.md/water_stru'):
98+
with open('abacus.md/water_stru') as f:
99+
iline=0
100+
for iline,l in enumerate(f):
101+
iline += 1
102+
self.assertEqual(iline,30)
103+
88104

89105
class TestABACUSMDLabeledOutput(unittest.TestCase, TestABACUSMD):
90106

91107
def setUp(self):
92108
self.system_water = dpdata.LabeledSystem('abacus.md',fmt='abacus/md') # system with stress
93109
self.system_Si = dpdata.LabeledSystem('abacus.md.nostress',fmt='abacus/md') # system without stress
94110

111+
def tearDown(self):
112+
if os.path.isfile('abacus.md/water_stru'):
113+
os.remove('abacus.md/water_stru')
114+
95115
if __name__ == '__main__':
96-
unittest.main()
116+
unittest.main()

0 commit comments

Comments
 (0)