From 00da9c80a9b71a0a1d2e68357303f24a4a8b7f5e Mon Sep 17 00:00:00 2001 From: Janosh Riebesell Date: Mon, 21 Aug 2023 19:49:35 -0700 Subject: [PATCH] forgot to negate check_occu after inverting semantics from skip_occu_checks initialize PymatgenTest.TEST_STRUCTURES as dict[Path, None] --- pymatgen/io/cif.py | 10 +++++----- pymatgen/util/testing.py | 7 ++++--- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/pymatgen/io/cif.py b/pymatgen/io/cif.py index bbb585a9fef..d3bf6ddd591 100644 --- a/pymatgen/io/cif.py +++ b/pymatgen/io/cif.py @@ -983,7 +983,7 @@ def get_matching_coord(coord): except (KeyError, ValueError): occu = 1 # If check_occu is True or the occupancy is greater than 0, create comp_d - if check_occu or occu > 0: + if not check_occu or occu > 0: coord = (x, y, z) match = get_matching_coord(coord) comp_dict = {el: max(occu, 1e-8)} @@ -1078,7 +1078,7 @@ def get_matching_coord(coord): all_labels.extend(new_labels) # rescale occupancies if necessary - all_species_noedit = all_species[:] # save copy before scaling in case of check_occu=True, used below + all_species_noedit = all_species[:] # save copy before scaling in case of check_occu=False, used below for idx, species in enumerate(all_species): total_occu = sum(species.values()) if 1 < total_occu <= self._occupancy_tolerance: @@ -1114,14 +1114,14 @@ def get_matching_coord(coord): sg = SpacegroupOperations("Not Parsed", -1, self.symmetry_operations) struct = SymmetrizedStructure(struct, sg, equivalent_indices, wyckoffs) - if check_occu: + if not check_occu: struct = Structure(lattice, all_species, all_coords, site_properties=site_properties, labels=all_labels) for idx in range(len(struct)): struct[idx] = PeriodicSite( all_species_noedit[idx], all_coords[idx], lattice, properties=site_properties, skip_checks=True ) - if symmetrized or check_occu: + if symmetrized or not check_occu: return struct struct = struct.get_sorted_structure() @@ -1166,7 +1166,7 @@ def get_structures( Returns: list[Structure]: All structures in CIF file. """ - if check_occu: # added in https://github.com/materialsproject/pymatgen/pull/2836 + if not check_occu: # added in https://github.com/materialsproject/pymatgen/pull/2836 warnings.warn("Structures with unphysical site occupancies are not compatible with many pymatgen features.") if primitive and symmetrized: raise ValueError( diff --git a/pymatgen/util/testing.py b/pymatgen/util/testing.py index 2c6dbf98baf..d41a174875e 100644 --- a/pymatgen/util/testing.py +++ b/pymatgen/util/testing.py @@ -31,7 +31,8 @@ class PymatgenTest(unittest.TestCase): _multiprocess_shared_ = True STRUCTURES_DIR = MODULE_DIR / "structures" - TEST_STRUCTURES: ClassVar[dict[str, Structure]] = {} # Dict for test structures to aid testing. + # dict of lazily-loaded test structures (initialized to None) + TEST_STRUCTURES: ClassVar[dict[str | Path, Structure | None]] = {key: None for key in STRUCTURES_DIR.glob("*")} @pytest.fixture(autouse=True) # make all tests run a in a temporary directory accessible via self.tmp_path def _tmp_dir(self, tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None: @@ -50,8 +51,8 @@ def get_structure(cls, name: str) -> Structure: Structure """ if name not in cls.TEST_STRUCTURES: - cls.TEST_STRUCTURES[name] = loadfn(cls.STRUCTURES_DIR / f"{name}.json") - return cls.TEST_STRUCTURES[name].copy() + struct = cls.TEST_STRUCTURES[name] = loadfn(f"{cls.STRUCTURES_DIR}/{name}.json") + return struct.copy() @staticmethod def assert_str_content_equal(actual, expected):