Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix chemical system method for different oxidation states #3915

Merged
merged 3 commits into from
Jul 26, 2024

Conversation

danielzuegner
Copy link
Contributor

@danielzuegner danielzuegner commented Jul 10, 2024

Summary

Currently, when the same element occurs in multiple oxidation states in a structure (e.g., Composition({"Na+": 1, "Na2+": 1, "Cl-": 1})), structure.composition.chemical_system yields that element repeated, e.g., Composition({"Na+": 1, "Na2+": 1, "Cl-": 1})), structure.composition.chemical_system == "Cl-Na-Na". My hypothesis is that this was introduced by the fix to this issue: #2248.

This PR fixes the bug by using the newly introduced chemical_system_set property of Composition, and adds the line

assert Composition({"Na+": 1, "Na2+": 1, "Cl-": 1}).chemical_system == "Cl-Na"

to test_composition.py.

Checklist

  • Google format doc strings added. Check with ruff.
  • Type annotations included. Check with mypy.
  • Tests added for new features/fixes.
  • If applicable, new classes/functions/modules have duecredit @due.dcite decorators to reference relevant papers by DOI (example)

@mkhorton
Copy link
Member

mkhorton commented Jul 16, 2024

Thanks for reporting and fixing @danielzuegner, this seems like a clear bug. We should get this merged :)

@mkhorton mkhorton enabled auto-merge (squash) July 16, 2024 15:54
@mkhorton mkhorton merged commit d464ad4 into materialsproject:master Jul 26, 2024
33 checks passed
@janosh janosh added fix Bug fix PRs core Pymatgen core labels Aug 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core Pymatgen core fix Bug fix PRs
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants