Skip to content

Commit d464ad4

Browse files
danielzuegnerpre-commit-ci[bot]mkhorton
authored
Fix chemical system method for different oxidation states (#3915)
* Fix chemical system when the same element appears in multiple oxidation states --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Matthew Horton <[email protected]>
1 parent 6d2e77e commit d464ad4

File tree

2 files changed

+2
-1
lines changed

2 files changed

+2
-1
lines changed

src/pymatgen/core/composition.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -487,7 +487,7 @@ def chemical_system(self) -> str:
487487
sorted alphabetically and joined by dashes, by convention for use
488488
in database keys.
489489
"""
490-
return "-".join(sorted(el.symbol for el in self.elements))
490+
return "-".join(sorted(self.chemical_system_set))
491491

492492
@property
493493
def num_atoms(self) -> float:

tests/core/test_composition.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -701,6 +701,7 @@ def test_elements(self):
701701
def test_chemical_system(self):
702702
assert Composition({"Na": 1, "Cl": 1}).chemical_system == "Cl-Na"
703703
assert Composition({"Na+": 1, "Cl-": 1}).chemical_system == "Cl-Na"
704+
assert Composition({"Na+": 1, "Na2+": 1, "Cl-": 1}).chemical_system == "Cl-Na"
704705

705706
def test_chemical_system_set(self):
706707
assert Composition({"Na": 1, "Cl": 1}).chemical_system_set == {"Cl", "Na"}

0 commit comments

Comments
 (0)