From 8662321718b0f3a264a2a7078a243b573f01568b Mon Sep 17 00:00:00 2001 From: Ryan Date: Wed, 30 Aug 2023 12:54:19 -0400 Subject: [PATCH] changes following update to pmg.Ion --- setup.cfg | 2 +- src/pyEQL/solute.py | 4 +++- src/pyEQL/utils.py | 6 +----- 3 files changed, 5 insertions(+), 7 deletions(-) diff --git a/setup.cfg b/setup.cfg index 992fb05a..ed423f40 100644 --- a/setup.cfg +++ b/setup.cfg @@ -54,7 +54,7 @@ install_requires = numpy scipy pint - pymatgen>=2022.0.17 + pymatgen>2022.8.10 iapws monty maggma diff --git a/src/pyEQL/solute.py b/src/pyEQL/solute.py index ed01abfd..52bf616d 100644 --- a/src/pyEQL/solute.py +++ b/src/pyEQL/solute.py @@ -19,6 +19,8 @@ import numpy as np from pymatgen.core.ion import Ion +from pyEQL.utils import standardize_formula + @dataclass class Datum: @@ -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 diff --git a/src/pyEQL/utils.py b/src/pyEQL/utils.py index 7313a0d3..9b49a1c8 100644 --- a/src/pyEQL/utils.py +++ b/src/pyEQL/utils.py @@ -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):