Skip to content

Commit

Permalink
fix re pattern
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielYang59 committed Dec 24, 2024
1 parent 3474e79 commit d714101
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
10 changes: 5 additions & 5 deletions src/pymatgen/analysis/pourbaix_diagram.py
Original file line number Diff line number Diff line change
Expand Up @@ -411,14 +411,14 @@ def ion_or_solid_comp_object(formula: str) -> Composition | Ion:
Composition/Ion object
"""
# Formula for ion
try:
if formula.endswith("(aq)") or re.search(r"\[.*\]$", formula) or "-" in formula or "+" in formula:
return Ion.from_formula(formula)

# Formula for solid
except ValueError:
if formula.endswith("(s)"):
return Composition(formula[:-3])
return Composition(formula)
if formula.endswith("(s)"):
return Composition(formula[:-3])

return Composition(formula)


# TODO: the solids filter breaks some of the functionality of the
Expand Down
1 change: 0 additions & 1 deletion tests/analysis/test_pourbaix_diagram.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,6 @@ def test_ion(self):
assert ion_or_solid_comp_object("Ca[++]").charge == 2
assert ion_or_solid_comp_object("Ca2+").charge == 1
assert ion_or_solid_comp_object("C2O4-2").charge == -2
assert ion_or_solid_comp_object("CO2").charge == 0

# Test anions
assert ion_or_solid_comp_object("Cl-").charge == -1
Expand Down

0 comments on commit d714101

Please sign in to comment.