This is a case-study for the API and not yet a ready demo.


In [ ]:
from __future__ import print_function, division
from collections import defaultdict
from chempy import Species, Equilibrium, Henry
from chempy.equilibria import EqSystem
from chempy.units import default_units as u

In [ ]:
species_keys = 'CO2(g) CO2(aq) H2O H2CO3 H+ HCO3- CO3-2 Ca+2 CaCO3(s)'.split()
eq_str = """
CO2(aq) = CO2(g); chempy.henry.HenryWithUnits(3.3e-4 * molar / Pa, 2400 * K)
CO2(aq) + H2O = H2CO3; 1.7e-3/55.4
H2CO3 = H+ + HCO3-; 10**-3.6
HCO3- = H+ + CO3-2; 10**-10.329
CaCO3(s) = Ca+2 + CO3-2; 3.3e-9
"""  # eventually: 55.4 <- [H2O]

In [ ]:
species = [Species.from_formula(s) for s in species_keys]
reactions = [Equilibrium.from_string(s, species_keys) for s in eq_str.split('\n')[1:-1]]
print('\n'.join(map(str , reactions)))

In [ ]:
#init_conc = defaultdict(lambda: 0*u.molar, {'H2O': 55.5*u.molar, 'CO2(g)': 1*u.atm})
#eqsys = EqSystem(reactions, species)
#eqsys

# Before this works, mass conservation equations must be adjusted to deal with an "inifinte" amount of gas:
#eqsys.root(init_conc, state=298.15*u.K)