Skip to content

Commit

Permalink
Solute: include factor in from_formula
Browse files Browse the repository at this point in the history
  • Loading branch information
rkingsbury committed Sep 10, 2023
1 parent 474cbc0 commit 8fb4ce8
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/pyEQL/solute.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
3 changes: 3 additions & 0 deletions tests/test_solute.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"

0 comments on commit 8fb4ce8

Please sign in to comment.