Skip to content

Commit 6600998

Browse files
committed
forgot to negate check_occu after inverting semantics from skip_occu_checks
initialize PymatgenTest.TEST_STRUCTURES as dict[Path, None]
1 parent bb0be96 commit 6600998

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

pymatgen/io/cif.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -983,7 +983,7 @@ def get_matching_coord(coord):
983983
except (KeyError, ValueError):
984984
occu = 1
985985
# If check_occu is True or the occupancy is greater than 0, create comp_d
986-
if check_occu or occu > 0:
986+
if not check_occu or occu > 0:
987987
coord = (x, y, z)
988988
match = get_matching_coord(coord)
989989
comp_dict = {el: max(occu, 1e-8)}
@@ -1078,7 +1078,7 @@ def get_matching_coord(coord):
10781078
all_labels.extend(new_labels)
10791079

10801080
# rescale occupancies if necessary
1081-
all_species_noedit = all_species[:] # save copy before scaling in case of check_occu=True, used below
1081+
all_species_noedit = all_species[:] # save copy before scaling in case of check_occu=False, used below
10821082
for idx, species in enumerate(all_species):
10831083
total_occu = sum(species.values())
10841084
if 1 < total_occu <= self._occupancy_tolerance:
@@ -1114,14 +1114,14 @@ def get_matching_coord(coord):
11141114
sg = SpacegroupOperations("Not Parsed", -1, self.symmetry_operations)
11151115
struct = SymmetrizedStructure(struct, sg, equivalent_indices, wyckoffs)
11161116

1117-
if check_occu:
1117+
if not check_occu:
11181118
struct = Structure(lattice, all_species, all_coords, site_properties=site_properties, labels=all_labels)
11191119
for idx in range(len(struct)):
11201120
struct[idx] = PeriodicSite(
11211121
all_species_noedit[idx], all_coords[idx], lattice, properties=site_properties, skip_checks=True
11221122
)
11231123

1124-
if symmetrized or check_occu:
1124+
if symmetrized or not check_occu:
11251125
return struct
11261126

11271127
struct = struct.get_sorted_structure()
@@ -1166,7 +1166,7 @@ def get_structures(
11661166
Returns:
11671167
list[Structure]: All structures in CIF file.
11681168
"""
1169-
if check_occu: # added in https://github.com/materialsproject/pymatgen/pull/2836
1169+
if not check_occu: # added in https://github.com/materialsproject/pymatgen/pull/2836
11701170
warnings.warn("Structures with unphysical site occupancies are not compatible with many pymatgen features.")
11711171
if primitive and symmetrized:
11721172
raise ValueError(

pymatgen/util/testing.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ class PymatgenTest(unittest.TestCase):
3131
_multiprocess_shared_ = True
3232
STRUCTURES_DIR = MODULE_DIR / "structures"
3333

34-
TEST_STRUCTURES: ClassVar[dict[str, Structure]] = {} # Dict for test structures to aid testing.
34+
# dict of lazily-loaded test structures (initialized to None)
35+
TEST_STRUCTURES: ClassVar[dict[str | Path, Structure | None]] = {key: None for key in STRUCTURES_DIR.glob("*")}
3536

3637
@pytest.fixture(autouse=True) # make all tests run a in a temporary directory accessible via self.tmp_path
3738
def _tmp_dir(self, tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None:
@@ -49,9 +50,8 @@ def get_structure(cls, name: str) -> Structure:
4950
Returns:
5051
Structure
5152
"""
52-
if name not in cls.TEST_STRUCTURES:
53-
cls.TEST_STRUCTURES[name] = loadfn(cls.STRUCTURES_DIR / f"{name}.json")
54-
return cls.TEST_STRUCTURES[name].copy()
53+
struct = cls.TEST_STRUCTURES.get(name) or loadfn(f"{cls.STRUCTURES_DIR}/{name}.json")
54+
return struct.copy()
5555

5656
@staticmethod
5757
def assert_str_content_equal(actual, expected):

0 commit comments

Comments
 (0)