Skip to content

Commit ee0ca89

Browse files
pxlxingliangaboys-cbpre-commit-ci[bot]
authored
abaucs/stru: add UT for the case of chaotic atomic species (#854)
Add UT for PR #852 <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Bug Fixes** * Corrected the handling of per-atom properties to ensure they are accurately matched to the correct atom indices when exporting structure files. * **Tests** * Added a new test to verify proper output formatting and grouping of atomic species, even when atomic species indices are unordered. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Signed-off-by: SuperBing <[email protected]> Co-authored-by: SuperBing <[email protected]> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: root <pxlxingliang>
1 parent a939ee4 commit ee0ca89

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed

tests/test_abacus_stru_dump.py

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,61 @@ def test_dump_move_from_vasp(self):
206206
"""
207207
self.assertTrue(stru_ref in c)
208208

209+
def test_dump_chaotic_atomic_species(self):
210+
import copy
211+
212+
import numpy as np
213+
214+
temp_system = copy.deepcopy(self.system_ch4)
215+
temp_system.data["atom_types"] = np.array([1, 0, 1, 1, 1])
216+
temp_system.data["coords"] = np.array(
217+
[[[1, 1, 1], [0, 0, 0], [2, 2, 2], [3, 3, 3], [4, 4, 4]]]
218+
)
219+
temp_system.data["move"] = np.array(
220+
[[[1, 0, 0], [0, 1, 1], [1, 1, 1], [1, 1, 1], [1, 1, 1]]]
221+
)
222+
velocity = np.array([[1, 1, 1], [2, 2, 2], [3, 3, 3], [4, 4, 4], [5, 5, 5]])
223+
mag = np.array(
224+
[[11, 11, 11], [22, 22, 22], [33, 33, 33], [44, 44, 44], [55, 55, 55]]
225+
)
226+
constrain = np.array([1, 0, 1, 0, 1])
227+
sc = np.array([[0, 1, 1], [0, 0, 1], [1, 1, 1], [1, 1, 1], [1, 1, 1]])
228+
lambda_ = np.array(
229+
[
230+
[0.1, 0.2, 0.3],
231+
[0.4, 0.5, 0.6],
232+
[0.7, 0.8, 0.9],
233+
[1.0, 1.1, 1.2],
234+
[1.3, 1.4, 1.5],
235+
]
236+
)
237+
temp_system.to(
238+
"stru",
239+
"STRU_tmp",
240+
velocity=velocity,
241+
mag=mag,
242+
constrain=constrain,
243+
sc=sc,
244+
lambda_=lambda_,
245+
)
246+
247+
assert os.path.isfile("STRU_tmp")
248+
with open("STRU_tmp") as f:
249+
lines = f.read()
250+
ref_c = """C
251+
0.0
252+
1
253+
0.000000000000 0.000000000000 0.000000000000 0 1 1 v 2.000000000000 2.000000000000 2.000000000000 mag 22.000000000000 22.000000000000 22.000000000000 sc 0 0 1 lambda 0.400000000000 0.500000000000 0.600000000000
254+
H
255+
0.0
256+
4
257+
1.000000000000 1.000000000000 1.000000000000 1 0 0 v 1.000000000000 1.000000000000 1.000000000000 mag 11.000000000000 11.000000000000 11.000000000000 sc 0 1 1 lambda 0.100000000000 0.200000000000 0.300000000000
258+
2.000000000000 2.000000000000 2.000000000000 1 1 1 v 3.000000000000 3.000000000000 3.000000000000 mag 33.000000000000 33.000000000000 33.000000000000 sc 1 1 1 lambda 0.700000000000 0.800000000000 0.900000000000
259+
3.000000000000 3.000000000000 3.000000000000 1 1 1 v 4.000000000000 4.000000000000 4.000000000000 mag 44.000000000000 44.000000000000 44.000000000000 sc 1 1 1 lambda 1.000000000000 1.100000000000 1.200000000000
260+
4.000000000000 4.000000000000 4.000000000000 1 1 1 v 5.000000000000 5.000000000000 5.000000000000 mag 55.000000000000 55.000000000000 55.000000000000 sc 1 1 1 lambda 1.300000000000 1.400000000000 1.500000000000"""
261+
262+
self.assertTrue(ref_c in lines)
263+
209264

210265
class TestABACUSParseStru(unittest.TestCase):
211266
def test_parse_pos_oneline(self):

0 commit comments

Comments
 (0)