Skip to content

Commit

Permalink
fix: the replicate will fail if the atom types of system is not sorted
Browse files Browse the repository at this point in the history
  • Loading branch information
Han Wang committed Jun 5, 2024
1 parent 199afc1 commit 2e1e993
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
6 changes: 3 additions & 3 deletions dpdata/system.py
Original file line number Diff line number Diff line change
Expand Up @@ -776,9 +776,9 @@ def replicate(self, ncopy: list[int] | tuple[int, int, int]):
tmp.data["atom_numbs"] = list(
np.array(np.copy(data["atom_numbs"])) * np.prod(ncopy)
)
tmp.data["atom_types"] = np.sort(
np.tile(np.copy(data["atom_types"]), np.prod(ncopy).item()), kind="stable"
)
tmp.data["atom_types"] = np.tile(np.copy(data["atom_types"]), (np.prod(ncopy),) + (1,))

Check failure on line 779 in dpdata/system.py

View workflow job for this annotation

GitHub Actions / pyright

No overloads for "tile" match the provided arguments (reportCallIssue)

Check failure on line 779 in dpdata/system.py

View workflow job for this annotation

GitHub Actions / pyright

Argument of type "tuple[int64, Literal[1]]" cannot be assigned to parameter "reps" of type "int | Sequence[int]" in function "tile"   Type "tuple[int64, Literal[1]]" is incompatible with type "int | Sequence[int]"     "tuple[int64, Literal[1]]" is incompatible with "int"     "tuple[int64, Literal[1]]" is incompatible with "Sequence[int]"       Type parameter "_T_co@Sequence" is covariant, but "int64 | Literal[1]" is not a subtype of "int"         Type "int64 | Literal[1]" is incompatible with type "int"           "signedinteger[_64Bit]" is incompatible with "int" (reportArgumentType)
tmp.data["atom_types"] = np.transpose(tmp.data["atom_types"]).reshape([-1])

tmp.data["cells"] = np.copy(data["cells"])
for ii in range(3):
tmp.data["cells"][:, ii, :] *= ncopy[ii]
Expand Down
19 changes: 19 additions & 0 deletions tests/test_replicate.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import unittest

import numpy as np
from comp_sys import CompSys, IsPBC
from context import dpdata

Expand Down Expand Up @@ -35,6 +36,24 @@ def setUp(self):
self.system_2 = dpdata.System("poscars/POSCAR.SiC", fmt="vasp/poscar")
self.places = 6

class TestReplicateTriclinicBox(unittest.TestCase, CompSys, IsPBC):
def setUp(self):
self.system_1 = dpdata.System()
self.system_1.data["atom_names"] = ["foo", "bar"]
self.system_1.data["atom_types"] = np.array([1, 0], dtype=int)
self.system_1.data["atom_numbs"] = [1, 1]
self.system_1.data["cells"] = np.array([10, 0, 0, 0, 10, 0, 0, 0, 10], dtype=float).reshape(1,3,3)
self.system_1.data["coords"] = np.array([0, 0, 0, 0, 0, 1], dtype=float).reshape(1,2,3)
self.system_1 = self.system_1.replicate([2,1,1])

self.system_2 = dpdata.System()
self.system_2.data["atom_names"] = ["foo", "bar"]
self.system_2.data["atom_types"] = np.array([1, 1, 0, 0], dtype=int)
self.system_2.data["atom_numbs"] = [2, 2]
self.system_2.data["cells"] = np.array([20, 0, 0, 0, 10, 0, 0, 0, 10], dtype=float).reshape(1,3,3)
self.system_2.data["coords"] = np.array([0, 0, 0, 10, 0, 0, 0, 0, 1, 10, 0, 1], dtype=float).reshape(1,4,3)
self.places = 6


if __name__ == "__main__":
unittest.main()

0 comments on commit 2e1e993

Please sign in to comment.