Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Stub for new function: solve_stoich_mix #130

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions chempy/chemistry.py
Original file line number Diff line number Diff line change
Expand Up @@ -1168,8 +1168,8 @@ def balance_stoichiometry(reactants, products, substances=None,

Returns
-------
balanced reactants : dict
balanced products : dict
balanced reactants : OrderedDict
balanced products : OrderedDict

"""
import sympy
Expand Down Expand Up @@ -1361,3 +1361,13 @@ def mass_fractions(stoichiometries, substances=None, substance_factory=Substance
substances = OrderedDict([(k, substance_factory(k)) for k in stoichiometries])
tot_mass = sum([substances[k].mass*v for k, v in stoichiometries.items()])
return {k: substances[k].mass*v/tot_mass for k, v in stoichiometries.items()}


def solve_stoich_mix(reac_prop, prod):
""" to be documented """
import sympy
reac = list(reac.keys())
prop = list(prop.values())
bal_r, bal_p = balance_stoichiometry(reac, prod)
fact = sympy.Dummy()
eqs = [br - fact*v for br, v in zip(bal_r, prop)]
5 changes: 5 additions & 0 deletions chempy/tests/test_chemistry.py
Original file line number Diff line number Diff line change
Expand Up @@ -432,3 +432,8 @@ def test_balance_stoichiometry__duplicates():
bal_Mn_COx = balance_stoichiometry({'C', 'CO', 'CO2', 'Mn'}, {'C', 'CO2', 'Mn'},
allow_duplicates=True, underdetermined=None)
assert bal_Mn_COx == ({'CO': 2}, {'C': 1, 'CO2': 1})

def test_solve_stoich_mix():
res = solve_stoich_mix({'C3H8': 3.0, 'O2': 5.0}, {'CO', 'H2', 'H2O'})
for k, v in {'CO': 9.0, 'H2O': 1.0, 'H2': 11.0}.items():
assert abs(res[k] - v) < 1e-12