From 820a1624ea7f530d6187fa8abae584e94892a879 Mon Sep 17 00:00:00 2001 From: Jinzhe Zeng Date: Tue, 13 Jun 2023 16:29:40 -0400 Subject: [PATCH 1/2] avoid modifying appended system When sys1.append(sys2), we do not hope that sys2 to be modified in any way. Signed-off-by: Jinzhe Zeng --- dpdata/system.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/dpdata/system.py b/dpdata/system.py index 743f3d057..f0eb6f991 100644 --- a/dpdata/system.py +++ b/dpdata/system.py @@ -3,7 +3,7 @@ import os from copy import deepcopy from enum import Enum, unique -from typing import Any, Dict, Optional, Tuple, Union +from typing import Any, Dict, List, Optional, Tuple, Union import numpy as np from monty.json import MSONable @@ -521,17 +521,21 @@ def append(self, system): return False elif not len(self.data["atom_numbs"]): # this system is non-converged but the system to append is converged - self.data = system.data + self.data = system.data.copy() return False if system.uniq_formula != self.uniq_formula: raise RuntimeError( f"systems with inconsistent formula could not be append: {self.uniq_formula} v.s. {system.uniq_formula}" ) if system.data["atom_names"] != self.data["atom_names"]: + # prevent original system to be modified + system = system.copy() # allow to append a system with different atom_names order system.sort_atom_names() self.sort_atom_names() if (system.data["atom_types"] != self.data["atom_types"]).any(): + # prevent original system to be modified + system = system.copy() # allow to append a system with different atom_types order system.sort_atom_types() self.sort_atom_types() @@ -1440,6 +1444,8 @@ def append(self, *systems): def __append(self, system): if not system.formula: return + # prevent changing the original system + system = system.copy() self.check_atom_names(system) formula = system.formula if formula in self.systems: From 663d9e8b83423467e028c33da7f092855e68ac17 Mon Sep 17 00:00:00 2001 From: Jinzhe Zeng Date: Tue, 13 Jun 2023 16:32:52 -0400 Subject: [PATCH 2/2] Update system.py --- dpdata/system.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dpdata/system.py b/dpdata/system.py index f0eb6f991..6fdac2044 100644 --- a/dpdata/system.py +++ b/dpdata/system.py @@ -3,7 +3,7 @@ import os from copy import deepcopy from enum import Enum, unique -from typing import Any, Dict, List, Optional, Tuple, Union +from typing import Any, Dict, Optional, Tuple, Union import numpy as np from monty.json import MSONable