Skip to content

Commit

Permalink
Fix chemical system method for different oxidation states (#3915)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
3 people authored Jul 26, 2024
1 parent 6d2e77e commit d464ad4
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/pymatgen/core/composition.py
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,7 @@ def chemical_system(self) -> str:
sorted alphabetically and joined by dashes, by convention for use
in database keys.
"""
return "-".join(sorted(el.symbol for el in self.elements))
return "-".join(sorted(self.chemical_system_set))

@property
def num_atoms(self) -> float:
Expand Down
1 change: 1 addition & 0 deletions tests/core/test_composition.py
Original file line number Diff line number Diff line change
Expand Up @@ -701,6 +701,7 @@ def test_elements(self):
def test_chemical_system(self):
assert Composition({"Na": 1, "Cl": 1}).chemical_system == "Cl-Na"
assert Composition({"Na+": 1, "Cl-": 1}).chemical_system == "Cl-Na"
assert Composition({"Na+": 1, "Na2+": 1, "Cl-": 1}).chemical_system == "Cl-Na"

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

0 comments on commit d464ad4

Please sign in to comment.