Skip to content

Commit a90c69e

Browse files
authored
Fix CifParser.get_structures(check_occu=False) (#3272)
* cif.py remove unintentional duplicate line * fix mypy * test_no_check_occu() try multiple occupancy_tolerance
1 parent 8b1318a commit a90c69e

File tree

3 files changed

+9
-9
lines changed

3 files changed

+9
-9
lines changed

pymatgen/core/structure.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -455,7 +455,7 @@ def from_file(cls, filename: str):
455455
"""Reads in SiteCollection from a filename."""
456456
raise NotImplementedError
457457

458-
def add_site_property(self, property_name: str, values: Sequence | ArrayLike):
458+
def add_site_property(self, property_name: str, values: Sequence | np.ndarray):
459459
"""Adds a property to a site. Note: This is the preferred method
460460
for adding magnetic moments, selective dynamics, and related
461461
site-specific properties to a structure/molecule object.

pymatgen/io/cif.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1115,7 +1115,6 @@ def get_matching_coord(coord):
11151115
struct = SymmetrizedStructure(struct, sg, equivalent_indices, wyckoffs)
11161116

11171117
if not check_occu:
1118-
struct = Structure(lattice, all_species, all_coords, site_properties=site_properties, labels=all_labels)
11191118
for idx in range(len(struct)):
11201119
struct[idx] = PeriodicSite(
11211120
all_species_noedit[idx], all_coords[idx], lattice, properties=site_properties, skip_checks=True

tests/io/test_cif.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -914,18 +914,19 @@ def test_empty_deque(self):
914914
with pytest.raises(ValueError, match="Invalid CIF file with no structures"):
915915
parser.get_structures()
916916

917-
def test_skip_checks(self):
918-
with open(f"{TEST_FILES_DIR}/site_type_symbol_test.cif") as c:
919-
cif_str = c.read()
917+
def test_no_check_occu(self):
918+
with open(f"{TEST_FILES_DIR}/site_type_symbol_test.cif") as cif_file:
919+
cif_str = cif_file.read()
920920
cif_str = cif_str.replace("Te Te 1.0000", "Te Te 1.5000", 1)
921921

922922
with pytest.raises(ValueError, match="Invalid CIF file with no structures"):
923923
# should fail without setting custom occupancy tolerance
924-
CifParser.from_string(cif_str).get_structures()
924+
CifParser.from_str(cif_str).get_structures()
925925

926-
parser = CifParser.from_string(cif_str, occupancy_tolerance=1.5)
927-
structs = parser.get_structures(primitive=False, symmetrized=True, check_occu=False)[0]
928-
assert structs[0].species.as_dict()["Te"] == 1.5
926+
for tol in (1.5, 10):
927+
parser = CifParser.from_str(cif_str, occupancy_tolerance=tol)
928+
structs = parser.get_structures(primitive=False, check_occu=False)[0]
929+
assert structs[0].species.as_dict()["Te"] == 1.5
929930

930931

931932
class TestMagCif(PymatgenTest):

0 commit comments

Comments
 (0)