From 54c7c985cfa96eac7ca6aa93f48ff57783e60441 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 5 Jun 2024 14:58:12 +0000 Subject: [PATCH] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- dpdata/system.py | 4 +++- tests/test_replicate.py | 19 ++++++++++++++----- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/dpdata/system.py b/dpdata/system.py index 2de98368..ae5fd97c 100644 --- a/dpdata/system.py +++ b/dpdata/system.py @@ -776,7 +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.tile(np.copy(data["atom_types"]), (np.prod(ncopy),) + (1,)) + tmp.data["atom_types"] = np.tile( + np.copy(data["atom_types"]), (np.prod(ncopy),) + (1,) + ) tmp.data["atom_types"] = np.transpose(tmp.data["atom_types"]).reshape([-1]) tmp.data["cells"] = np.copy(data["cells"]) diff --git a/tests/test_replicate.py b/tests/test_replicate.py index bdd8c5bb..ded164c1 100644 --- a/tests/test_replicate.py +++ b/tests/test_replicate.py @@ -36,22 +36,31 @@ 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_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.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