Skip to content

Commit

Permalink
changes following update to pmg.Ion
Browse files Browse the repository at this point in the history
  • Loading branch information
rkingsbury committed Sep 10, 2023
1 parent 8fb4ce8 commit 8662321
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 7 deletions.
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ install_requires =
numpy
scipy
pint
pymatgen>=2022.0.17
pymatgen>2022.8.10
iapws
monty
maggma
Expand Down
4 changes: 3 additions & 1 deletion src/pyEQL/solute.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
import numpy as np
from pymatgen.core.ion import Ion

from pyEQL.utils import standardize_formula


@dataclass
class Datum:
Expand Down Expand Up @@ -105,8 +107,8 @@ def from_formula(cls, formula: str):
of the IonDoc.
"""
pmg_ion = Ion.from_formula(formula)
rform = pmg_ion.reduced_formula
f, factor = pmg_ion.get_reduced_formula_and_factor()
rform = standardize_formula(formula)
charge = int(pmg_ion.charge)
els = [str(el) for el in pmg_ion.elements]
mw = f"{float(pmg_ion.weight / factor)} g/mol" # weight is a FloatWithUnit
Expand Down
6 changes: 1 addition & 5 deletions src/pyEQL/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,7 @@ def standardize_formula(formula: str):
charge number will always be listed explicitly and 2) the charge number will be enclosed in square brackets to remove any ambiguity in the meaning of the formula. For example, 'Na+', 'Na+1', and 'Na[+]' will all
standardize to "Na[+1]"
"""
rform = Ion.from_formula(formula).reduced_formula
# TODO - this is a workaround for a shortcoming of Ion that I would like to fix in pymatgen
if rform.split("(aq)")[0] in ["H", "O", "N", "F", "Cl"]:
rform = rform.split("(aq)")[0] + "2(aq)"
return rform
return Ion.from_formula(formula).reduced_formula


class FormulaDict(UserDict):
Expand Down

0 comments on commit 8662321

Please sign in to comment.