Skip to content

Commit

Permalink
Add LightStructureEnvironments.from_structure_environments() fallback…
Browse files Browse the repository at this point in the history
… value if `ce_and_neighbors` is None (materialsproject#3002)

* LightStructureEnvironments.from_structure_environments() add fallback value if ce_and_neighbors is None (closes materialsproject#2756)

* add StructureEnvironmentsTest.test_from_structure_environments() to prevent future regression
  • Loading branch information
janosh authored and lbluque committed May 23, 2023
1 parent 6c88280 commit e2bb134
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -1604,7 +1604,7 @@ def from_structure_environments(cls, strategy, structure_environments, valences=
else:
csm = None
ce_dict["csm"] = csm
ce_dict["permutation"] = ce_and_neighbors["ce_dict"]["permutation"]
ce_dict["permutation"] = (ce_and_neighbors.get("ce_dict") or {}).get("permutation")
site_ces.append(ce_dict)
# Neighbors
neighbors = ce_and_neighbors["neighbors"]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,12 @@
MultiWeightsChemenvStrategy,
SimplestChemenvStrategy,
)
from pymatgen.analysis.chemenv.coordination_environments.coordination_geometry_finder import LocalGeometryFinder
from pymatgen.analysis.chemenv.coordination_environments.structure_environments import (
LightStructureEnvironments,
StructureEnvironments,
)
from pymatgen.core import Structure
from pymatgen.core.periodic_table import Species
from pymatgen.util.testing import PymatgenTest

Expand Down Expand Up @@ -250,6 +252,18 @@ def test_light_structure_environments(self):
assert lse_multi.coordination_environments[isite][0]["ce_fraction"] == pytest.approx(1.0)
assert lse_multi.coordination_environments[isite][0]["ce_symbol"] == "T:4"

def test_from_structure_environments(self):
# https://github.com/materialsproject/pymatgen/issues/2756
mp_id = "mp-554015"
struct = Structure.from_file(PymatgenTest.TEST_FILES_DIR / f"{mp_id}.json.gz")
strategy = SimplestChemenvStrategy(distance_cutoff=1.4, angle_cutoff=0.3)
local_geom_finder = LocalGeometryFinder()
local_geom_finder.setup_structure(structure=struct)
envs = local_geom_finder.compute_structure_environments()

lse = LightStructureEnvironments.from_structure_environments(strategy=strategy, structure_environments=envs)
assert len(lse.coordination_environments) == len(struct)


if __name__ == "__main__":
unittest.main()
Binary file added test_files/mp-554015.json.gz
Binary file not shown.

0 comments on commit e2bb134

Please sign in to comment.