|
8 | 8 | import warnings
|
9 | 9 | from importlib.metadata import PackageNotFoundError
|
10 | 10 | from typing import TYPE_CHECKING
|
| 11 | +import copy |
11 | 12 |
|
12 | 13 | import numpy as np
|
13 | 14 | from monty.json import MontyDecoder, MSONable, jsanitize
|
@@ -204,7 +205,7 @@ def get_atoms(structure: SiteCollection, msonable: bool = True, **kwargs) -> MSO
|
204 | 205 |
|
205 | 206 | # Atoms.info <---> Structure.properties
|
206 | 207 | if properties := structure.properties:
|
207 |
| - atoms.info = properties |
| 208 | + atoms.info = copy.deepcopy(properties) |
208 | 209 |
|
209 | 210 | # Regenerate Spacegroup object from `.todict()` representation
|
210 | 211 | if isinstance(atoms.info.get("spacegroup"), dict):
|
@@ -298,10 +299,11 @@ def get_structure(atoms: Atoms, cls: type[Structure] = Structure, **cls_kwargs)
|
298 | 299 | sel_dyn = None
|
299 | 300 |
|
300 | 301 | # Atoms.info <---> Structure.properties
|
301 |
| - # But first make sure `spacegroup` is JSON serializable |
302 |
| - if atoms.info.get("spacegroup") and isinstance(atoms.info["spacegroup"], Spacegroup): |
303 |
| - atoms.info["spacegroup"] = atoms.info["spacegroup"].todict() |
304 |
| - properties = getattr(atoms, "info", {}) |
| 302 | + properties = copy.deepcopy(getattr(atoms, "info", {})) |
| 303 | + # If present, convert Spacegroup object to JSON-serializable dict |
| 304 | + if properties.get("spacegroup") and isinstance(properties["spacegroup"], Spacegroup): |
| 305 | + properties["spacegroup"] = properties["spacegroup"].todict() |
| 306 | + |
305 | 307 |
|
306 | 308 | # Return a Molecule object if that was specifically requested;
|
307 | 309 | # otherwise return a Structure object as expected
|
|
0 commit comments