From f14fda7f05de8804fea598c76e9a44428477db2c Mon Sep 17 00:00:00 2001 From: Duo <50307526+iProzd@users.noreply.github.com> Date: Thu, 6 Jun 2024 17:11:10 +0800 Subject: [PATCH 1/4] fix: use deepcopy when dumping mixed types --- dpdata/deepmd/mixed.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/dpdata/deepmd/mixed.py b/dpdata/deepmd/mixed.py index b25107dbc..2af665dad 100644 --- a/dpdata/deepmd/mixed.py +++ b/dpdata/deepmd/mixed.py @@ -3,6 +3,7 @@ import glob import os import shutil +import copy import numpy as np @@ -159,6 +160,8 @@ def dump(folder, data, set_size=2000, comp_prec=np.float32, remove_sets=True): # if not converted to mixed if "real_atom_types" not in data: from dpdata import LabeledSystem, System + # not change the original content + data = copy.deepcopy(data) if "energies" in data: temp_sys = LabeledSystem(data=data) From c58a87f8c93af4a83aaa6059e689568272b7126d Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 6 Jun 2024 09:18:39 +0000 Subject: [PATCH 2/4] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- dpdata/deepmd/mixed.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/dpdata/deepmd/mixed.py b/dpdata/deepmd/mixed.py index 2af665dad..ccf9b2f58 100644 --- a/dpdata/deepmd/mixed.py +++ b/dpdata/deepmd/mixed.py @@ -1,9 +1,9 @@ from __future__ import annotations +import copy import glob import os import shutil -import copy import numpy as np @@ -160,6 +160,7 @@ def dump(folder, data, set_size=2000, comp_prec=np.float32, remove_sets=True): # if not converted to mixed if "real_atom_types" not in data: from dpdata import LabeledSystem, System + # not change the original content data = copy.deepcopy(data) From 172f54d70842d51e747c3c5a789ae3d3008b1562 Mon Sep 17 00:00:00 2001 From: Duo <50307526+iProzd@users.noreply.github.com> Date: Thu, 6 Jun 2024 17:45:59 +0800 Subject: [PATCH 3/4] add ut --- tests/test_deepmd_mixed.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/tests/test_deepmd_mixed.py b/tests/test_deepmd_mixed.py index 02044932e..519293d52 100644 --- a/tests/test_deepmd_mixed.py +++ b/tests/test_deepmd_mixed.py @@ -314,5 +314,29 @@ def test_str(self): ) +class TestMixedSingleSystemsDump( + unittest.TestCase, CompLabeledSys, IsNoPBC +): + def setUp(self): + self.places = 6 + self.e_places = 6 + self.f_places = 6 + self.v_places = 6 + + # C1H4 + self.system_1 = dpdata.LabeledSystem( + "gaussian/methane.gaussianlog", fmt="gaussian/log" + ) + self.system_2 = dpdata.LabeledSystem( + "gaussian/methane.gaussianlog", fmt="gaussian/log" + ) + # test dump + self.system_1.to('deepmd/npy/mixed', "tmp.deepmd.mixed.single") + + def tearDown(self): + if os.path.exists("tmp.deepmd.mixed.single"): + shutil.rmtree("tmp.deepmd.mixed.single") + + if __name__ == "__main__": unittest.main() From 29bcf6a46e9fa968f005d1ce33997fa671a0db78 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 6 Jun 2024 09:47:46 +0000 Subject: [PATCH 4/4] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- tests/test_deepmd_mixed.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/tests/test_deepmd_mixed.py b/tests/test_deepmd_mixed.py index 519293d52..70a09dbe8 100644 --- a/tests/test_deepmd_mixed.py +++ b/tests/test_deepmd_mixed.py @@ -314,9 +314,7 @@ def test_str(self): ) -class TestMixedSingleSystemsDump( - unittest.TestCase, CompLabeledSys, IsNoPBC -): +class TestMixedSingleSystemsDump(unittest.TestCase, CompLabeledSys, IsNoPBC): def setUp(self): self.places = 6 self.e_places = 6 @@ -331,7 +329,7 @@ def setUp(self): "gaussian/methane.gaussianlog", fmt="gaussian/log" ) # test dump - self.system_1.to('deepmd/npy/mixed', "tmp.deepmd.mixed.single") + self.system_1.to("deepmd/npy/mixed", "tmp.deepmd.mixed.single") def tearDown(self): if os.path.exists("tmp.deepmd.mixed.single"):