Skip to content

Commit 8990032

Browse files
authored
Improve Structure tests (#3197)
* add Structure/Molecule.sites setter, move @Property to SiteCollection * don't use implementation detail (Structure|Molecule)._sites instead use public setter (Structure|Molecule).sites * rename StructureTest.structure attr to struct * add IStructureTest.test_sites_setter * fix mypy * test translate/rotate_sites IndexError if list index out of range * tweak doc strings * test inverse translate_sites operations leave structure unchanged * Structure.make_supercell() add in_place: bool = True keyword and return supercell structure * test make_supercell in_place=True and False * fix mypy * fix Structure.insert not returning as doc str says * fix @sites.setter check if is mutable class
1 parent 71b7aec commit 8990032

File tree

4 files changed

+273
-247
lines changed

4 files changed

+273
-247
lines changed

pymatgen/analysis/local_env.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3649,12 +3649,13 @@ def get_nn_info(self, structure: Structure, n: int):
36493649
site = structure[n]
36503650
neighbors = structure.get_neighbors(site, self.cutoff)
36513651

3652-
if self.cation_anion and hasattr(site.specie, "oxi_state"):
3652+
oxi_state = getattr(site.specie, "oxi_state", None)
3653+
if self.cation_anion and oxi_state is not None:
36533654
# filter out neighbor of like charge (except for neutral sites)
3654-
if site.specie.oxi_state >= 0:
3655+
if oxi_state >= 0:
36553656
neighbors = [n for n in neighbors if n.oxi_state <= 0]
3656-
elif site.specie.oxi_state <= 0:
3657-
neighbors = [n for n in neighbors if n.oxi_state >= 0]
3657+
elif oxi_state < 0:
3658+
neighbors = [nghbr for nghbr in neighbors if nghbr.oxi_state >= 0]
36583659

36593660
if self.use_fictive_radius:
36603661
# calculate fictive ionic radii
@@ -3882,7 +3883,8 @@ def get_nn_data(self, structure: Structure, n: int, length=None):
38823883
target = []
38833884
m_oxi = structure[n].specie.oxi_state
38843885
for site in structure:
3885-
if site.specie.oxi_state * m_oxi <= 0: # opposite charge
3886+
oxi_state = getattr(site.specie, "oxi_state", None)
3887+
if oxi_state is not None and oxi_state * m_oxi <= 0: # opposite charge
38863888
target.append(site.specie)
38873889
if not target:
38883890
raise ValueError("No valid targets for site within cation_anion constraint!")

0 commit comments

Comments
 (0)