diff --git a/src/pyEQL/solute.py b/src/pyEQL/solute.py index 64bad4b1..ed01abfd 100644 --- a/src/pyEQL/solute.py +++ b/src/pyEQL/solute.py @@ -105,14 +105,15 @@ def from_formula(cls, formula: str): of the IonDoc. """ pmg_ion = Ion.from_formula(formula) - f = pmg_ion.reduced_formula + rform = pmg_ion.reduced_formula + f, factor = pmg_ion.get_reduced_formula_and_factor() charge = int(pmg_ion.charge) els = [str(el) for el in pmg_ion.elements] - mw = f"{float(pmg_ion.weight)} g/mol" # weight is a FloatWithUnit + mw = f"{float(pmg_ion.weight / factor)} g/mol" # weight is a FloatWithUnit chemsys = pmg_ion.chemical_system return cls( - f, + rform, charge=charge, molecular_weight=mw, elements=els, diff --git a/tests/test_solute.py b/tests/test_solute.py index 003a70fd..7b017ed1 100644 --- a/tests/test_solute.py +++ b/tests/test_solute.py @@ -17,3 +17,6 @@ def test_from_formula(): assert s.n_elements == 1 assert s.oxi_state_guesses == ({"Mg": 2.0},) assert s.molecular_weight == "24.305 g/mol" + s2 = Solute.from_formula("O6") + assert s2.formula == "O3(aq)" + assert s2.molecular_weight == "47.9982 g/mol"