Skip to content

Commit

Permalink
forgot to negate check_occu after inverting semantics from skip_occu_…
Browse files Browse the repository at this point in the history
…checks

initialize PymatgenTest.TEST_STRUCTURES as dict[Path, None]
  • Loading branch information
janosh committed Aug 22, 2023
1 parent bb0be96 commit 00da9c8
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
10 changes: 5 additions & 5 deletions pymatgen/io/cif.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)}
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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(
Expand Down
7 changes: 4 additions & 3 deletions pymatgen/util/testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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):
Expand Down

0 comments on commit 00da9c8

Please sign in to comment.