Module reference

These internal modules are used by Solution but typically are not directly accessed by the user.

Salt Matching module

pyEQL salt matching library.

This file contains functions that allow a pyEQL Solution object composed of individual species (usually ions) to be mapped to a solution of one or more salts. This mapping is necessary because some parameters (such as activity coefficient data) can only be determined for salts (e.g. NaCl) and not individual species (e.g. Na+)

copyright:

2013-2024 by Ryan S. Kingsbury

license:

LGPL, see LICENSE for more details.

class pyEQL.salt_ion_match.Salt(cation, anion)[source]

Class to represent a salt.

get_effective_molality(ionic_strength)[source]

Calculate the effective molality according to [mistry].

\[2 I \over (\nu_+ z_+^2 + \nu_- z_- ^2)\]
Parameters:

ionic_strength – Quantity The ionic strength of the parent solution, mol/kg

Returns:

the effective molality of the salt in the parent solution

Return type:

Quantity

References

[mistry]

Mistry, K. H.; Hunter, H. a.; Lienhard V, J. H. Effect of composition and nonideal solution behavior on desalination calculations for mixed electrolyte solutions with comparison to seawater. Desalination 2013, 318, 34-47.

Modeling Engines module

pyEQL engines for computing aqueous equilibria (e.g., speciation, redox, etc.).

copyright:

2013-2024 by Ryan S. Kingsbury

license:

LGPL, see LICENSE for more details.

class pyEQL.engines.EOS[source]

Abstract base class for pyEQL equation of state classes.

The intent is that concrete implementations of this class make use of the standalone functions available in pyEQL.activity_correction and pyEQL.equilibrium as much as possible. This facilitates robust unit testing while allowing users to “mix and match” or customize the various models as needed.

abstract equilibrate(solution)[source]

Adjust the speciation and pH of a Solution object to achieve chemical equilibrium.

The Solution should be modified in-place, likely using add_moles / set_moles, etc.

Parameters:

solution – pyEQL Solution object

Returns

Nothing. The speciation of the Solution is modified in-place.

Raises:

ValueError if the calculation cannot be completed, e.g. due to insufficient number of parameters or lack of convergence.

abstract get_activity_coefficient(solution, solute)[source]

Return the molal scale activity coefficient of solute, given a Solution object.

Parameters:
  • solution – pyEQL Solution object

  • solute – str identifying the solute of interest

Returns

Quantity: dimensionless quantity object

Raises:

ValueError if the calculation cannot be completed, e.g. due to insufficient number of parameters.

abstract get_osmotic_coefficient(solution)[source]

Return the molal scale osmotic coefficient of a Solution.

Parameters:

solution – pyEQL Solution object

Returns

Quantity: dimensionless molal scale osmotic coefficient

Raises:

ValueError if the calculation cannot be completed, e.g. due to insufficient number of parameters.

abstract get_solute_volume()[source]

Return the volume of only the solutes.

Parameters:

solution – pyEQL Solution object

Returns

Quantity: solute volume in L

Raises:

ValueError if the calculation cannot be completed, e.g. due to insufficient number of parameters.

class pyEQL.engines.IdealEOS[source]

Ideal solution equation of state engine.

equilibrate(solution)[source]

Adjust the speciation of a Solution object to achieve chemical equilibrium.

get_activity_coefficient(solution, solute)[source]

Return the molal scale activity coefficient of solute, given a Solution object.

get_osmotic_coefficient(solution)[source]

Return the molal scale osmotic coefficient of solute, given a Solution object.

get_solute_volume(solution)[source]

Return the volume of the solutes.

class pyEQL.engines.NativeEOS(phreeqc_db: Literal['vitens.dat', 'wateq4f_PWN.dat', 'pitzer.dat', 'llnl.dat', 'geothermal.dat'] = 'llnl.dat')[source]

pyEQL’s native EOS. Uses the Pitzer model when possible, falls back to other models (e.g. Debye-Huckel) based on ionic strength if sufficient parameters are not available.

equilibrate(solution)[source]

Adjust the speciation of a Solution object to achieve chemical equilibrium.

get_activity_coefficient(solution, solute)[source]

Whenever the appropriate parameters are available, the Pitzer model [may] is used. If no Pitzer parameters are available, then the appropriate equations are selected according to the following logic: [stumm].

I <= 0.0005: Debye-Huckel equation 0.005 < I <= 0.1: Guntelberg approximation 0.1 < I <= 0.5: Davies equation I > 0.5: Raises a warning and returns activity coefficient = 1

The ionic strength, activity coefficients, and activities are all calculated based on the molal (mol/kg) concentration scale. If a different scale is given as input, then the molal-scale activity coefficient \(\gamma_\pm\) is converted according to [rbs]

\[f_\pm = \gamma_\pm * (1 + M_w \sum_i \nu_i m_i)\]
\[y_\pm = \frac{m \rho_w}{C \gamma_\pm}\]

where \(f_\pm\) is the rational activity coefficient, \(M_w\) is the molecular weight of water, the summation represents the total molality of all solute species, \(y_\pm\) is the molar activity coefficient, \(\rho_w\) is the density of pure water, \(m\) and \(C\) are the molal and molar concentrations of the chosen salt (not individual solute), respectively.

Parameters:
  • solute – String representing the name of the solute of interest

  • scale – The concentration scale for the returned activity coefficient. Valid options are “molal”, “molar”, and “rational” (i.e., mole fraction). By default, the molal scale activity coefficient is returned.

Returns:

The mean ion activity coefficient of the solute in question on the selected scale.

Notes

For multicomponent mixtures, pyEQL implements the “effective Pitzer model” presented by Mistry et al. [mistry]. In this model, the activity coefficient of a salt in a multicomponent mixture is calculated using an “effective molality,” which is the molality that would result in a single-salt mixture with the same total ionic strength as the multicomponent solution.

\[m_{effective} = \frac{2 I}{(\nu_{+} z_{+}^2 + \nu_{-}- z_{-}^2)}\]

References

[may]
May, P. M., Rowland, D., Hefter, G., & Königsberger, E. (2011).

A Generic and Updatable Pitzer Characterization of Aqueous Binary Electrolyte Solutions at 1 bar and 25 °C.

Journal of Chemical & Engineering Data, 56(12), 5066-5077. doi:10.1021/je2009329

[stumm]

Stumm, Werner and Morgan, James J. Aquatic Chemistry, 3rd ed, pp 165. Wiley Interscience, 1996.

[rbs]

Robinson, R. A.; Stokes, R. H. Electrolyte Solutions: Second Revised Edition; Butterworths: London, 1968, p.32.

[mistry]

Mistry, K. H.; Hunter, H. a.; Lienhard V, J. H. Effect of composition and nonideal solution behavior on desalination calculations for mixed electrolyte solutions with comparison to seawater. Desalination 2013, 318, 34-47.

get_osmotic_coefficient(solution)[source]

Return the molal scale osmotic coefficient of solute, given a Solution object.

Osmotic coefficient is calculated using the Pitzer model. [may] If appropriate parameters for the model are not available, then pyEQL raises a WARNING and returns an osmotic coefficient of 1.

If the ‘rational’ scale is given as input, then the molal-scale osmotic coefficient \(\phi\) is converted according to [rbs]

\[g = - \phi M_{w} \frac{\sum_{i} \nu_{i} m_{i}}{\ln x_{w}}\]

where \(g\) is the rational osmotic coefficient, \(M_{w}\) is the molecular weight of water, the summation represents the total molality of all solute species, and \(x_{w}\) is the mole fraction of water.

Parameters:

scale – The concentration scale for the returned osmotic coefficient. Valid options are “molal”, “rational” (i.e., mole fraction), and “fugacity”. By default, the molal scale osmotic coefficient is returned.

Returns:

The osmotic coefficient

Return type:

Quantity

Notes

For multicomponent mixtures, pyEQL adopts the “effective Pitzer model” presented by Mistry et al. [mstry]. In this approach, the osmotic coefficient of each individual salt is calculated using the normal Pitzer model based on its respective concentration. Then, an effective osmotic coefficient is calculated as the concentration-weighted average of the individual osmotic coefficients.

For example, in a mixture of 0.5 M NaCl and 0.5 M KBr, one would calculate the osmotic coefficient for each salt using a concentration of 0.5 M and an ionic strength of 1 M. Then, one would average the two resulting osmotic coefficients to obtain an effective osmotic coefficient for the mixture.

(Note: in the paper referenced below, the effective osmotic coefficient is determined by weighting using the “effective molality” rather than the true molality. Subsequent checking and correspondence with the author confirmed that the weight factor should be the true molality, and that is what is implemented in pyEQL.)

References

[may]

May, P. M., Rowland, D., Hefter, G., & Königsberger, E. (2011). A Generic and Updatable Pitzer Characterization of Aqueous Binary Electrolyte Solutions at 1 bar and 25 °C. Journal of Chemical & Engineering Data, 56(12), 5066-5077. doi:10.1021/je2009329

[rbs]

Robinson, R. A.; Stokes, R. H. Electrolyte Solutions: Second Revised Edition; Butterworths: London, 1968, p.32.

[mstry]

Mistry, K. H.; Hunter, H. a.; Lienhard V, J. H. Effect of composition and nonideal solution behavior on desalination calculations for mixed electrolyte solutions with comparison to seawater. Desalination 2013, 318, 34-47.

Examples

>>> s1 = pyEQL.Solution({'Na+': '0.2 mol/kg', 'Cl-': '0.2 mol/kg'})
>>> s1.get_osmotic_coefficient()
<Quantity(0.923715281, 'dimensionless')>
>>> s1 = pyEQL.Solution({'Mg+2': '0.3 mol/kg', 'Cl-': '0.6 mol/kg'},temperature='30 degC')
>>> s1.get_osmotic_coefficient()
<Quantity(0.891409618, 'dimensionless')>
get_solute_volume(solution)[source]

Return the volume of the solutes.

class pyEQL.engines.PhreeqcEOS(phreeqc_db: Literal['vitens.dat', 'wateq4f_PWN.dat', 'pitzer.dat', 'llnl.dat', 'geothermal.dat'] = 'phreeqc.dat')[source]

Engine based on the PhreeqC model, as implemented via the phreeqpython package.

get_activity_coefficient(solution, solute)[source]

Return the molal scale activity coefficient of solute, given a Solution object.

get_osmotic_coefficient(solution)[source]

Return the molal scale osmotic coefficient of solute, given a Solution object.

PHREEQC appears to assume a unit osmotic coefficient unless the pitzer database is used. Unfortunately, there is no easy way to access the osmotic coefficient via phreeqcpython

get_solute_volume(solution)[source]

Return the volume of the solutes.

Activity Correction functions

pyEQL activity correction library.

This file contains functions for computing molal-scale activity coefficients of ions and salts in aqueous solution.

Individual functions for activity coefficients are defined here so that they can be used independently of a pyEQL solution object. Normally, these functions are called from within the get_activity_coefficient method of the Solution class.

copyright:

2013-2024 by Ryan S. Kingsbury

license:

LGPL, see LICENSE for more details.

pyEQL.activity_correction._debye_parameter_B(temperature: str = '25 degC') Quantity[source]

Return the constant B used in the extended Debye-Huckel equation.

Parameters:

temperature – The temperature of the solution at which to calculate the constant. Defaults to ‘25 degC’.

Returns:

The parameter B for use in extended Debye-Huckel equation (base e). For base 10, divide the resulting value by 2.303. Note that A is often given in base 10 terms in older textbooks and reference material (0.3281 at 25 degC).

Notes

The parameter B is equal to:

\[B = \bigg( \frac{2 N_A \rho_w e^2}{\epsilon_o \epsilon_r k T} \bigg) ^ {\frac{1}{2}}\]

References

Bockris and Reddy. /Modern Electrochemistry/, vol 1. Plenum/Rosetta, 1977, p.210.

Archer, Donald G. and Wang, Peiming. “The Dielectric Constant of Water and Debye-Huckel Limiting Law Slopes.” /J. Phys. Chem. Ref. Data/ 19(2), 1990.

https://chem.libretexts.org/Bookshelves/Physical_and_Theoretical_Chemistry_Textbook_Maps/Physical_Chemistry_(LibreTexts)/25%3A_Solutions_II_-_Nonvolatile_Solutes/25.06%3A_The_Debye-Huckel_Theory

https://en.wikipedia.org/wiki/Debye%E2%80%93H%C3%BCckel_equation

pyEQL.activity_correction._debye_parameter_activity(temperature: str = '25 degC') Quantity[source]

Return the constant A for use in the Debye-Huckel limiting law (base e).

Parameters:

temperature – The temperature of the solution at which to calculate the constant. Defaults to ‘25 degC’.

Returns:

The parameter A for use in the Debye-Huckel limiting law (base e). For base 10, divide the resulting value by 2.303. Note that A is often given in base 10 terms in older textbooks and reference material (0.509 at 25 degC).

Notes

The parameter A is equal to:

\[A^{\gamma} = \frac{e^3 \big( 2 \pi N_A \rho \big)^{0.5}}{(4 \pi \epsilon_o \epsilon_r k T)^{1.5}}\]

Note that this equation returns the parameter value that can be used to calculate the natural logarithm of the activity coefficient. For base 10, divide the value returned by 2.303.

References

Archer, Donald G. and Wang, Peiming. “The Dielectric Constant of Water and Debye-Huckel Limiting Law Slopes.” /J. Phys. Chem. Ref. Data/ 19(2), 1990.

https://chem.libretexts.org/Bookshelves/Physical_and_Theoretical_Chemistry_Textbook_Maps/Physical_Chemistry_(LibreTexts)/25%3A_Solutions_II_-_Nonvolatile_Solutes/25.06%3A_The_Debye-Huckel_Theory

https://en.wikipedia.org/wiki/Debye%E2%80%93H%C3%BCckel_equation

pyEQL.activity_correction._debye_parameter_osmotic(temperature='25 degC')[source]

Return the constant A_phi for use in calculating the osmotic coefficient according to Debye-Huckel theory.

Parameters:

temperature – String representing the temperature of the solution. Defaults to ‘25 degC’ if not specified.

Notes

Not to be confused with the Debye-Huckel constant used for activity coefficients in the limiting law. Takes the value 0.392 at 25 C. This constant is calculated according to: [kim] [arch]

\[A^{\phi} = {1 \over 3} A^{\gamma}\]

References

[kim]

Kim, Hee-Talk and Frederick, William Jr, 1988. “Evaluation of Pitzer Ion Interaction Parameters of Aqueous Electrolytes at 25 C. 1. Single Salt Parameters,”

J. Chemical Engineering Data 33, pp.177-184.

[arch]

Archer, Donald G. and Wang, Peiming. “The Dielectric Constant of Water

and Debye-Huckel Limiting Law Slopes.” /J. Phys. Chem. Ref. Data/ 19(2), 1990.

Examples

>>> _debye_parameter_osmotic() 
0.3916...
pyEQL.activity_correction._debye_parameter_volume(temperature='25 degC')[source]

Return the constant A_V, the Debye-Huckel limiting slope for apparent molar volume.

Parameters:

temperature – String representing the temperature of the solution. Defaults to ‘25 degC’ if not specified.

Notes

Takes the value 1.8305 cm ** 3 * kg ** 0.5 / mol ** 1.5 at 25 C. This constant is calculated according to: [1]_

\[A_V = -2 A_{\phi} R T \big[ \frac{3}{\epsilon} \frac{\partial \epsilon}{\partial p} \ - \frac{1}{\rho}\frac{\partial \rho}{\partial p} \big]\]

Notes: at this time, the term in brackets (containing the partial derivatives) is approximate. These approximations give the correct value of the slope at 25 degC and produce estimates with less than 10% error between 0 and 60 degC.

The derivative of epsilon with respect to pressure is assumed constant (for atmospheric pressure) at -0.01275 1/MPa. Note that the negative sign does not make sense in light of real data, but is required to give the correct result.

The second term is equivalent to the inverse of the bulk modulus of water, which is taken to be 2.2 GPa. [2]_

References

pyEQL.activity_correction._pitzer_B_MX(ionic_strength, alpha1, alpha2, beta0, beta1, beta2)[source]

Return the B_MX coefficient for the Pitzer ion interaction model.

\[B_MX = \beta_0 + \beta_1 f1(\alpha_1 I ^ {0.5}) + \beta_2 f2(\alpha_2 I ^ {0.5})\]
Parameters:
  • ionic_strength – The ionic strength of the parent solution, mol/kg

  • alpha1 – Coefficients for the Pitzer model, kg ** 0.5 / mol ** 0.5

  • alpha2 – Coefficients for the Pitzer model, kg ** 0.5 / mol ** 0.5

  • beta0 – Coefficients for the Pitzer model. These ion-interaction parameters are specific to each salt system.

  • beta1 – Coefficients for the Pitzer model. These ion-interaction parameters are specific to each salt system.

  • beta2 – Coefficients for the Pitzer model. These ion-interaction parameters are specific to each salt system.

Returns:

The B_MX parameter for the Pitzer ion interaction model.

References

Scharge, T., Munoz, A.G., and Moog, H.C. (2012). Activity Coefficients of Fission Products in Highly Salinary Solutions of Na+, K+, Mg2+, Ca2+, Cl-, and SO42- : Cs+. /Journal of Chemical& Engineering Data (57), p. 1637-1647.

Kim, H., & Jr, W. F. (1988). Evaluation of Pitzer ion interaction parameters of aqueous electrolytes at 25 degree C. 1. Single salt parameters. Journal of Chemical and Engineering Data, (2), 177-184.

See also

_pitzer_f1()

pyEQL.activity_correction._pitzer_B_phi(ionic_strength, alpha1, alpha2, beta0, beta1, beta2)[source]

Returns the B^Phi coefficient for the Pitzer ion interaction model.

This function calculates the B^Phi coefficient using the formula:

\[B^\Phi = \beta_0 + \beta1 \exp(-\alpha_1 I ^{0.5}) + \beta_2 \exp(-\alpha_2 I ^ {0.5})\]

or

\[B^\Phi = B^\gamma - B_{MX}\]
Parameters:
  • ionic_strength – The ionic strength of the parent solution, mol/kg.

  • alpha1 – Coefficients for the Pitzer model, kg ** 0.5 / mol ** 0.5.

  • alpha2 – Coefficients for the Pitzer model, kg ** 0.5 / mol ** 0.5.

  • beta0 – Coefficients for the Pitzer model. These ion-interaction parameters are specific to each salt system.

  • beta1 – Coefficients for the Pitzer model. These ion-interaction parameters are specific to each salt system.

  • beta2 – Coefficients for the Pitzer model. These ion-interaction parameters are specific to each salt system.

Returns:

The B^Phi parameter for the Pitzer ion interaction model.

Return type:

float

References

Scharge, T., Munoz, A.G., and Moog, H.C. (2012). Activity Coefficients of Fission Products in Highly Salinary Solutions of Na+, K+, Mg2+, Ca2+, Cl-, and SO42- : Cs+. /Journal of Chemical& Engineering Data (57), p. 1637-1647.

Kim, H., & Jr, W. F. (1988). Evaluation of Pitzer ion interaction parameters of aqueous electrolytes at 25 degree C. 1. Single salt parameters. Journal of Chemical and Engineering Data, (2), 177-184.

Beyer, R., & Steiger, M. (2010). Vapor Pressure Measurements of NaHCOO + H 2 O and KHCOO + H 2 O from 278 to 308 K and Representation with an Ion Interaction (Pitzer) Model. Journal of Chemical & Engineering Data, 55(2), 830-838. doi:10.1021/je900487a

pyEQL.activity_correction._pitzer_f1(x)[source]

The function of ionic strength used to calculate beta_MX in the Pitzer ion interaction model.

\[f(x) = 2 [ 1- (1+x) \exp(-x)] / x ^ 2\]

References

Scharge, T., Munoz, A.G., and Moog, H.C. (2012). Activity Coefficients of Fission Products in Highly Salinary Solutions of Na+, K+, Mg2+, Ca2+, Cl-, and SO42- : Cs+. /Journal of Chemical& Engineering Data (57), p. 1637-1647.

Kim, H., & Jr, W. F. (1988). Evaluation of Pitzer ion interaction parameters of aqueous electrolytes at 25 degree C. 1. Single salt parameters. Journal of Chemical and Engineering Data, (2), 177-184.

pyEQL.activity_correction._pitzer_f2(x)[source]

The function of ionic strength used to calculate beta_gamma in the Pitzer ion interaction model.

\[f(x) = -\frac{2}{x ^ 2} [ 1 - (\frac{1+x+ x^2}{2}) \exp(-x)]\]

References

Scharge, T., Munoz, A.G., and Moog, H.C. (2012). Activity Coefficients of Fission Products in Highly Salinary Solutions of Na+, K+, Mg2+, Ca2+, Cl-, and SO42- : Cs+. /Journal of Chemical& Engineering Data (57), p. 1637-1647.

Kim, H., & Jr, W. F. (1988). Evaluation of Pitzer ion interaction parameters of aqueous electrolytes at 25 degree C. 1. Single salt parameters. Journal of Chemical and Engineering Data, (2), 177-184.

pyEQL.activity_correction._pitzer_log_gamma(ionic_strength, molality, B_MX, B_phi, C_phi, z_cation, z_anion, nu_cation, nu_anion, temperature='25 degC', b=<Quantity(1.2, 'kilogram ** 0.5 / mole ** 0.5')>)[source]

Returns the natural logarithm of the binary activity coefficient calculated by the Pitzer ion interaction model.

\[\ln \gamma_{MX} = -|z_+ z_-| A^{Phi} ( \frac{I ^ {0.5}}{(1 + b I ^ {0.5})} + \frac{2}{b} \ln{(1 + b I ^ {0.5})} )+ \frac{m (2 \nu_+ \nu_-)}{(\nu_+ + \nu_-)} (B_{MX} + B_{MX}^\Phi) + \frac{m^2(3 (\nu_+ \nu_-)^{1.5}}{(\nu_+ + \nu_-))} C_{MX}^\Phi\]
Parameters:
  • ionic_strength (Quantity) – The ionic strength of the parent solution, mol/kg.

  • molality (Quantity) – The concentration of the salt, mol/kg.

  • B_MX (Quantity) – Calculated parameters for the Pitzer ion interaction model.

  • B_phi (Quantity) – Calculated parameters for the Pitzer ion interaction model.

  • C_phi (Quantity) – Calculated parameters for the Pitzer ion interaction model.

  • z_cation (int) – The formal charge on the cation and anion, respectively.

  • z_anion (int) – The formal charge on the cation and anion, respectively.

  • nu_cation (int) – The stoichiometric coefficient of the cation and anion in the salt.

  • nu_anion (int) – The stoichiometric coefficient of the cation and anion in the salt.

  • temperature (str, Quantity) – String representing the temperature of the solution. Defaults to ‘25 degC’ if not specified.

  • b (number, optional) – Coefficient. Usually set equal to 1.2 kg ** 0.5 / mol ** 0.5 and considered independent of temperature and pressure.

Returns:

The natural logarithm of the binary activity coefficient calculated by the Pitzer ion interaction model.

Return type:

float

References

Kim, H., & Jr, W. F. (1988). Evaluation of Pitzer ion interaction parameters of aqueous electrolytes at 25 degree C. 1. Single salt parameters. Journal of Chemical and Engineering Data, (2), 177-184.

May, P. M., Rowland, D., Hefter, G., & Königsberger, E. (2011). A Generic and Updatable Pitzer Characterization of Aqueous Binary Electrolyte Solutions at 1 bar and 25 °C. Journal of Chemical & Engineering Data, 56(12), 5066-5077. doi:10.1021/je2009329

pyEQL.activity_correction.get_activity_coefficient_davies(ionic_strength, z=1, temperature='25 degC')[source]

Return the activity coefficient of solute in the parent solution according to the Davies equation.

Parameters:
  • ionic_strength (Quantity) – The ionic strength of the parent solution, mol/kg.

  • z (int, optional) – The charge on the solute, including sign. Defaults to +1 if not specified.

  • temperature (str, Quantity, optional) – String representing the temperature of the solution. Defaults to ‘25 degC’ if not specified.

Returns:

The mean molal (mol/kg) scale ionic activity coefficient of solute, dimensionless.

Return type:

Quantity

Notes

Activity coefficient is calculated according to:

\[\ln \gamma = A^{\gamma} z_i^2 ({\sqrt I \over (1 + \sqrt I)} + 0.2 I)\]

Valid for 0.1 < I < 0.5

References

Stumm, Werner and Morgan, James J. Aquatic Chemistry, 3rd ed,

pp 103. Wiley Interscience, 1996.

pyEQL.activity_correction.get_activity_coefficient_debyehuckel(ionic_strength, z=1, temperature='25 degC')[source]

Return the activity coefficient of solute in the parent solution according to the Debye-Huckel limiting law.

Parameters:
  • z (int, optional) – The charge on the solute, including sign. Defaults to +1 if not specified.

  • ionic_strength (Quantity) – The ionic strength of the parent solution, mol/kg.

  • temperature (str, Quantity, optional) – String representing the temperature of the solution. Defaults to ‘25 degC’ if not specified.

Returns:

The mean molal (mol/kg) scale ionic activity coefficient of solute, dimensionless.

Return type:

Quantity

Notes

Activity coefficient is calculated according to:

\[\ln \gamma = A^{\gamma} z_i^2 \sqrt I\]

Valid only for I < 0.005

References

Stumm, Werner and Morgan, James J. Aquatic Chemistry, 3rd ed,

pp 103. Wiley Interscience, 1996.

pyEQL.activity_correction.get_activity_coefficient_guntelberg(ionic_strength, z=1, temperature='25 degC')[source]

Return the activity coefficient of solute in the parent solution according to the Guntelberg approximation.

Parameters:
  • z (int, optional) – The charge on the solute, including sign. Defaults to +1 if not specified.

  • ionic_strength (Quantity) – The ionic strength of the parent solution, mol/kg.

  • temperature (str, Quantity, optional) – String representing the temperature of the solution. Defaults to ‘25 degC’ if not specified.

Returns:

The mean molal (mol/kg) scale ionic activity coefficient of solute, dimensionless.

Return type:

Quantity

Notes

Activity coefficient is calculated according to:

\[\ln \gamma = A^{\gamma} z_i^2 {\sqrt I \over (1 + \sqrt I)}\]

Valid for I < 0.1

References

Stumm, Werner and Morgan, James J. Aquatic Chemistry, 3rd ed,

pp 103. Wiley Interscience, 1996.

pyEQL.activity_correction.get_activity_coefficient_pitzer(ionic_strength, molality, alpha1, alpha2, beta0, beta1, beta2, C_phi, z_cation, z_anion, nu_cation, nu_anion, temperature='25 degC', b=1.2)[source]

Return the activity coefficient of solute in the parent solution according to the Pitzer model.

Parameters:
  • ionic_strength – The ionic strength of the parent solution, mol/kg

  • molality – The molal concentration of the parent salt, mol/kg

  • alpha1 – Coefficients for the Pitzer model. This function assigns the coefficients proper units of kg ** 0.5 / mol ** 0.5 after they are entered.

  • alpha2 – Coefficients for the Pitzer model. This function assigns the coefficients proper units of kg ** 0.5 / mol ** 0.5 after they are entered.

  • beta0 – Coefficients for the Pitzer model. These ion-interaction parameters are specific to each salt system.

  • beta1 – Coefficients for the Pitzer model. These ion-interaction parameters are specific to each salt system.

  • beta2 – Coefficients for the Pitzer model. These ion-interaction parameters are specific to each salt system.

  • C_phi – Coefficients for the Pitzer model. These ion-interaction parameters are specific to each salt system.

  • z_cation – The charge on the cation and anion, respectively

  • z_anion – The charge on the cation and anion, respectively

  • nu_cation – The stoichiometric coefficient of the cation and anion in the salt

  • nu_anion – The stoichiometric coefficient of the cation and anion in the salt

  • temperature – String representing the temperature of the solution. Defaults to ‘25 degC’ if not specified.

  • b – Coefficient. Usually set equal to 1.2 and considered independent of temperature and pressure. If provided, this coefficient is assigned proper units of kg ** 0.5 / mol ** 0.5 after entry.

Returns:

Quantity

The mean molal (mol/kg) scale ionic activity coefficient of solute, dimensionless

Examples

>>> get_activity_coefficient_pitzer(0.5*ureg.Quantity('mol/kg'),0.5*ureg.Quantity('mol/kg'),1,0.5,-.0181191983,-.4625822071,.4682,.000246063,1,-1,1,1,b=1.2)
0.61915...
>>> get_activity_coefficient_pitzer(5.6153*ureg.Quantity('mol/kg'),5.6153*ureg.Quantity('mol/kg'),3,0.5,0.0369993,0.354664,0.0997513,-0.00171868,1,-1,1,1,b=1.2)
0.76331...

Notes: the examples below are for comparison with experimental and modeling data presented in the May et al reference below.

10 mol/kg ammonium nitrate. Estimated result (from graph) = 0.2725

>>> get_activity_coefficient_pitzer(10*ureg.Quantity('mol/kg'),10*ureg.Quantity('mol/kg'),2,0,-0.01709,0.09198,0,0.000419,1,-1,1,1,b=1.2)
0.22595 ...

5 mol/kg ammonium nitrate. Estimated result (from graph) = 0.3011

>>> get_activity_coefficient_pitzer(5*ureg.Quantity('mol/kg'),5*ureg.Quantity('mol/kg'),2,0,-0.01709,0.09198,0,0.000419,1,-1,1,1,b=1.2)
0.30249 ...

18 mol/kg ammonium nitrate. Estimated result (from graph) = 0.1653

>>> get_activity_coefficient_pitzer(18*ureg.Quantity('mol/kg'),18*ureg.Quantity('mol/kg'),2,0,-0.01709,0.09198,0,0.000419,1,-1,1,1,b=1.2)
0.16241 ...

References

Scharge, T., Munoz, A.G., and Moog, H.C. (2012). Activity Coefficients of Fission Products in Highly Salinary Solutions of Na+, K+, Mg2+, Ca2+, Cl-, and SO42- : Cs+. /Journal of Chemical& Engineering Data (57), p. 1637-1647.

Kim, H., & Jr, W. F. (1988). Evaluation of Pitzer ion interaction parameters of aqueous electrolytes at 25 degree C. 1. Single salt parameters. Journal of Chemical and Engineering Data, (2), 177-184.

May, P. M., Rowland, D., Hefter, G., & Königsberger, E. (2011). A Generic and Updatable Pitzer Characterization of Aqueous Binary Electrolyte Solutions at 1 bar and 25 °C. Journal of Chemical & Engineering Data, 56(12), 5066-5077. doi:10.1021/je2009329

Beyer, R., & Steiger, M. (2010). Vapor Pressure Measurements of NaHCOO + H 2 O and KHCOO + H 2 O from 278 to 308 K and Representation with an Ion Interaction (Pitzer) Model. Journal of Chemical & Engineering Data, 55(2), 830-838. doi:10.1021/je900487a

pyEQL.activity_correction.get_apparent_volume_pitzer(ionic_strength, molality, alpha1, alpha2, beta0, beta1, beta2, C_phi, V_o, z_cation, z_anion, nu_cation, nu_anion, temperature='25 degC', b=1.2)[source]

Return the apparent molar volume of solute in the parent solution according to the Pitzer model.

Parameters:
  • ionic_strength (Quantity) – The ionic strength of the parent solution, mol/kg.

  • molality (Quantity) – The molal concentration of the parent salt, mol/kg.

  • alpha1 (number) – Coefficients for the Pitzer model. This function assigns the coefficients proper units of kg ** 0.5 / mol ** 0.5 after they are entered.

  • alpha2 (number) – Coefficients for the Pitzer model. This function assigns the coefficients proper units of kg ** 0.5 / mol ** 0.5 after they are entered.

  • beta0 (number) – Pitzer coefficients for the apparent molar volume. These ion-interaction parameters are specific to each salt system.

  • beta1 (number) – Pitzer coefficients for the apparent molar volume. These ion-interaction parameters are specific to each salt system.

  • beta2 (number) – Pitzer coefficients for the apparent molar volume. These ion-interaction parameters are specific to each salt system.

  • C_phi (number) – Pitzer coefficients for the apparent molar volume. These ion-interaction parameters are specific to each salt system.

  • V_o (number) – The V^o Pitzer coefficient for the apparent molar volume.

  • z_cation (int) – The formal charge on the cation and anion, respectively.

  • z_anion (int) – The formal charge on the cation and anion, respectively.

  • nu_cation (int) – The stoichiometric coefficient of the cation and anion in the salt.

  • nu_anion (int) – The stoichiometric coefficient of the cation and anion in the salt.

  • temperature (str, Quantity) – String representing the temperature of the solution. Defaults to ‘25 degC’ if not specified.

  • b (number, optional) – Coefficient. Usually set equal to 1.2 and considered independent of temperature and pressure. If provided, this coefficient is assigned proper units of kg ** 0.5 / mol ** 0.5 after entry.

Returns:

The apparent molar volume of the solute, cm ** 3 / mol.

Return type:

Quantity

Examples

Notes: the example below is for comparison with experimental and modeling data presented in the Krumgalz et al reference below.

0.25 mol/kg CuSO4. Expected result (from graph) = 0.5 cm ** 3 / mol

>>> get_apparent_volume_pitzer(1.0*ureg.Quantity('mol/kg'),0.25*ureg.Quantity('mol/kg'),1.4,12,0.001499,-0.008124,0.2203,-0.0002589,-6,2,-2,1,1,b=1.2)
0.404...

1.0 mol/kg CuSO4. Expected result (from graph) = 4 cm ** 3 / mol

>>> get_apparent_volume_pitzer(4.0*ureg.Quantity('mol/kg'),1.0*ureg.Quantity('mol/kg'),1.4,12,0.001499,-0.008124,0.2203,-0.0002589,-6,2,-2,1,1,b=1.2)
4.424...

10.0 mol/kg ammonium nitrate. Expected result (from graph) = 50.3 cm ** 3 / mol

>>> get_apparent_volume_pitzer(10.0*ureg.Quantity('mol/kg'),10.0*ureg.Quantity('mol/kg'),2,0,0.000001742,0.0002926,0,0.000000424,46.9,1,-1,1,1,b=1.2)
50.286...

20.0 mol/kg ammonium nitrate. Expected result (from graph) = 51.2 cm ** 3 / mol

>>> get_apparent_volume_pitzer(20.0*ureg.Quantity('mol/kg'),20.0*ureg.Quantity('mol/kg'),2,0,0.000001742,0.0002926,0,0.000000424,46.9,1,-1,1,1,b=1.2)
51.145...

Notes: the examples below are for comparison with experimental and modeling data presented in the Krumgalz et al reference below.

0.8 mol/kg NaF. Expected result = 0.03

>>> get_apparent_volume_pitzer(0.8*ureg.Quantity('mol/kg'),0.8*ureg.Quantity('mol/kg'),2,0,0.000024693,0.00003169,0,-0.000004068,-2.426,1,-1,1,1,b=1.2)
0.22595 ...

References

May, P. M., Rowland, D., Hefter, G., & Königsberger, E. (2011). A Generic and Updatable Pitzer Characterization of Aqueous Binary Electrolyte Solutions at 1 bar and 25 °C. Journal of Chemical & Engineering Data, 56(12), 5066-5077. doi:10.1021/je2009329

Krumgalz, Boris S., Pogorelsky, Rita (1996). Volumetric Properties of Single Aqueous Electrolytes from Zero to Saturation Concentration at 298.15 K Represented by Pitzer’s Ion-Interaction Equations. Journal of Physical Chemical Reference Data, 25(2), 663-689.

pyEQL.activity_correction.get_osmotic_coefficient_pitzer(ionic_strength, molality, alpha1, alpha2, beta0, beta1, beta2, C_phi, z_cation, z_anion, nu_cation, nu_anion, temperature='25 degC', b=1.2)[source]

Return the osmotic coefficient of water in an electrolyte solution according to the Pitzer model.

Parameters:
  • ionic_strength (Quantity) – The ionic strength of the parent solution, mol/kg.

  • molality (Quantity) – The molal concentration of the parent salt, mol/kg.

  • alpha1 (number) – Coefficients for the Pitzer model. This function assigns the coefficients proper units of kg ** 0.5 / mol ** 0.5 after they are entered.

  • alpha2 (number) – Coefficients for the Pitzer model. This function assigns the coefficients proper units of kg ** 0.5 / mol ** 0.5 after they are entered.

  • beta0 – Coefficients for the Pitzer model. These ion-interaction parameters are specific to each salt system.

  • beta1 – Coefficients for the Pitzer model. These ion-interaction parameters are specific to each salt system.

  • beta2 – Coefficients for the Pitzer model. These ion-interaction parameters are specific to each salt system.

  • C_phi – Coefficients for the Pitzer model. These ion-interaction parameters are specific to each salt system.

  • z_cation (int) – The formal charge on the cation and anion, respectively.

  • z_anion (int) – The formal charge on the cation and anion, respectively.

  • nu_cation (int) – The stoichiometric coefficient of the cation and anion in the salt.

  • nu_anion (int) – The stoichiometric coefficient of the cation and anion in the salt.

  • temperature (str, Quantity) – String representing the temperature of the solution. Defaults to ‘25 degC’ if not specified.

  • b (number, optional) – Coefficient. Usually set equal to 1.2 and considered independent of temperature and pressure. If provided, this coefficient is assigned proper units of kg ** 0.5 / mol ** 0.5 after entry.

Returns:

The osmotic coefficient of water, dimensionless.

Return type:

Quantity

Examples

Experimental value according to Beyer and Stieger reference is 1.3550

>>> get_osmotic_coefficient_pitzer(10.175*ureg.Quantity('mol/kg'),10.175*ureg.Quantity('mol/kg'),1,0.5,-.0181191983,-.4625822071,.4682,.000246063,1,-1,1,1,b=1.2)
1.3552 ...

Experimental value according to Beyer and Stieger reference is 1.084

>>> get_osmotic_coefficient_pitzer(5.6153*ureg.Quantity('mol/kg'),5.6153*ureg.Quantity('mol/kg'),3,0.5,0.0369993,0.354664,0.0997513,-0.00171868,1,-1,1,1,b=1.2)
1.0850 ...

Notes: the examples below are for comparison with experimental and modeling data presented in the May et al reference below.

10 mol/kg ammonium nitrate. Estimated result (from graph) = 0.62

>>> get_osmotic_coefficient_pitzer(10*ureg.Quantity('mol/kg'),10*ureg.Quantity('mol/kg'),2,0,-0.01709,0.09198,0,0.000419,1,-1,1,1,b=1.2)
0.6143 ...

5 mol/kg ammonium nitrate. Estimated result (from graph) = 0.7

>>> get_osmotic_coefficient_pitzer(5*ureg.Quantity('mol/kg'),5*ureg.Quantity('mol/kg'),2,0,-0.01709,0.09198,0,0.000419,1,-1,1,1,b=1.2)
0.6925 ...

18 mol/kg ammonium nitrate. Estimated result (from graph) = 0.555

>>> get_osmotic_coefficient_pitzer(18*ureg.Quantity('mol/kg'),18*ureg.Quantity('mol/kg'),2,0,-0.01709,0.09198,0,0.000419,1,-1,1,1,b=1.2)
0.5556 ...

References

Scharge, T., Munoz, A.G., and Moog, H.C. (2012). Activity Coefficients of Fission Products in Highly Salinary Solutions of Na+, K+, Mg2+, Ca2+, Cl-, and SO42- : Cs+. /Journal of Chemical& Engineering Data (57), p. 1637-1647.

Kim, H., & Jr, W. F. (1988). Evaluation of Pitzer ion interaction parameters of aqueous electrolytes at 25 degree C. 1. Single salt parameters. Journal of Chemical and Engineering Data, (2), 177-184.

May, P. M., Rowland, D., Hefter, G., & Königsberger, E. (2011). A Generic and Updatable Pitzer Characterization of Aqueous Binary Electrolyte Solutions at 1 bar and 25 °C. Journal of Chemical & Engineering Data, 56(12), 5066-5077. doi:10.1021/je2009329

Beyer, R., & Steiger, M. (2010). Vapor Pressure Measurements of NaHCOO + H 2 O and KHCOO + H 2 O from 278 to 308 K and Representation with an Ion Interaction (Pitzer) Model. Journal of Chemical & Engineering Data, 55(2), 830-838. doi:10.1021/je900487a

Speciation functions

pyEQL methods for chemical equilibrium calculations (e.g. acid/base, reactions, redox, complexation, etc.).

NOTE: these methods are not currently used but are here for the future.

copyright:

2013-2024 by Ryan S. Kingsbury

license:

LGPL, see LICENSE for more details.

pyEQL.equilibrium.adjust_temp_arrhenius(rate_constant, activation_energy, temperature, reference_temperature=<Quantity(25, 'degree_Celsius')>)[source]

Adjust a reaction equilibrium constant from one temperature to another.

Parameters:
  • rate_constant (Quantity) – The parameter value (usually a rate constant) being adjusted.

  • activation_energy (Quantity) – The activation energy of the process, in kJ/mol.

  • temperature (Quantity) – The desired reaction temperature.

  • reference_temperature (Quantity, optional) – The temperature at which equilibrium_constant is valid. Defaults to 25 degrees C if omitted.

Returns:

The adjusted reaction equilibrium constant.

Return type:

Quantity

Notes

This function implements the Arrhenius equation to adjust measured rate constants to other temperatures. TODO - add better reference

\[ln(\frac{K2}{K1}) = \frac{E_a}{R} ( \frac{1}{T_{1}} - {\frac{1}{T_2}} )\]

References

http://chemwiki.ucdavis.edu/Physical_Chemistry/Kinetics/Reaction_Rates/Temperature_Dependence_of_Reaction_Rates/Arrhenius_Equation

Examples

>>> adjust_temp_arrhenius(7,900*ureg.Quantity('kJ/mol'),37*ureg.Quantity('degC'),97*ureg.Quantity('degC')) 
1.8867225...e-24
pyEQL.equilibrium.adjust_temp_pitzer(c1, c2, c3, c4, c5, temp, temp_ref=<Quantity(298.15, 'kelvin')>)[source]

Calculate a parameter for the Pitzer model based on temperature-dependent coefficients c1,c2,c3,c4,and c5.

Parameters:
  • c1 (float) – Temperature-dependent coefficients for the pitzer parameter of interest.

  • c2 (float) – Temperature-dependent coefficients for the pitzer parameter of interest.

  • c3 (float) – Temperature-dependent coefficients for the pitzer parameter of interest.

  • c4 (float) – Temperature-dependent coefficients for the pitzer parameter of interest.

  • c5 (float) – Temperature-dependent coefficients for the pitzer parameter of interest.

  • temp (Quantity) – The temperature at which the Pitzer parameter is to be calculated.

  • temp_ref (Quantity, optional) – The reference temperature on which the parameters are based. Defaults to 298.15 K if omitted.

Note

As described in the PHREEQC documentation.

pyEQL.equilibrium.adjust_temp_vanthoff(equilibrium_constant, enthalpy, temperature, reference_temperature=<Quantity(25, 'degree_Celsius')>)[source]

Adjust a reaction equilibrium constant from one temperature to another.

Parameters:
  • equilibrium_constant (float) – The reaction equilibrium constant for the reaction.

  • enthalpy (Quantity) – The enthalpy change (delta H) for the reaction in kJ/mol. Assumed independent of temperature (see Notes).

  • temperature (Quantity) – The desired reaction temperature in degrees Celsius.

  • reference_temperature (Quantity, optional) – The temperature at which equilibrium_constant is valid. Defaults to 25 degrees C if omitted.

Returns:

The adjusted reaction equilibrium constant.

Return type:

float

Note

This function implements the Van’t Hoff equation to adjust measured equilibrium constants to other temperatures.

\[ln(K2 / K1) = {\delta H \over R} ( {1 \over T_1} - {1 \over T_2} )\]

This implementation assumes that the enthalpy is independent of temperature over the range of interest.

References

Stumm, Werner and Morgan, James J. Aquatic Chemistry, 3rd ed, pp 53. Wiley Interscience, 1996.

Examples

>>> adjust_temp_vanthoff(0.15,ureg.Quantity('-197.6 kJ/mol'),ureg.Quantity('42 degC'),ureg.Quantity(' 25degC')) 
0.00203566...

If the ‘ref_temperature’ parameter is omitted, a default of 25 C is used.

>>> adjust_temp_vanthoff(0.15,ureg.Quantity('-197.6 kJ/mol'),ureg.Quantity('42 degC')) 
0.00203566...
pyEQL.equilibrium.alpha(n, pH, pKa_list)[source]

Returns the acid-base distribution coefficient (alpha) of an acid in the n-deprotonated form at a given pH.

Parameters:
  • n (int) – The number of protons that have been lost by the desired form of the acid. Also the subscript on the alpha value. E.g. for bicarbonate (HCO3-), n=1 because 1 proton has been lost from the fully-protonated carbonic acid (H2CO3) form.

  • pH (float or int) – The pH of the solution.

  • pKa_list (list of floats or ints) – The pKa values (negative log of equilibrium constants) for the acid of interest. There must be a minimum of n pKa values in the list.

Returns:

The fraction of total acid present in the specified form.

Return type:

float

Notes

The acid-base coefficient is calculated as follows: [stm]

\[\alpha_n = \frac{term_n}{[H+]^n + k_{a1}[H+]^{n-1} + k_{a1}k_{a2}[H+]^{n-2} ... k_{a1}k_{a2}...k_{an} }\]

Where :math: ‘term_n’ refers to the nth term in the denominator, starting from 0

References

Stumm, Werner and Morgan, James J. Aquatic Chemistry, 3rd ed, pp 127-130. Wiley Interscience, 1996.

Examples

>>> alpha(1,8,[4.7]) 
0.999...

The sum of all alpha values should equal 1

>>> alpha(0,8,[6.35,10.33]) 
0.021...
>>> alpha(1,8,[6.35,10.33]) 
0.979...
>>> alpha(2,8,[6.35,10.33]) 
2.043...e-09

If pH is equal to one of the pKa values the function should return 0.5.

>>> alpha(1,6.35,[6.35,10.33])
0.5

Utilities

pyEQL utilities

copyright:

2013-2024 by Ryan S. Kingsbury

license:

LGPL, see LICENSE for more details.

class pyEQL.utils.FormulaDict(dict=None, /, **kwargs)[source]

Automatically converts keys on get/set using pymatgen.core.Ion.from_formula(key).reduced_formula.

This allows getting/setting/updating of Solution.components using flexible formula notation (e.g., “Na+”, “Na+1”, “Na[+]” all have the same effect)

pyEQL.utils.create_water_substance(temperature: float, pressure: float)[source]

Instantiate a water substance model from IAPWS.

Parameters:
  • temperature – the desired temperature in K

  • pressure – the desired pressure in MPa

Notes

The IAPWS97 model is much faster than IAPWS95, but the latter can do temp below zero. See https://github.com/jjgomera/iapws/issues/14. Hence, IAPWS97 will be used except when temperature is less than 0 degC.

Returns:

A IAPWS97 or IAPWS95 instance

pyEQL.utils.format_solutes_dict(solute_dict: dict, units: str)[source]

Formats a dictionary of solutes by converting the amount to a string with the provided units suitable for passing to use with the Solution class. Note that all solutes must be given in the same units.

Parameters:
  • solute_dict – The dictionary to format. This must be of the form dict{str: Number} e.g. {“Na+”: 0.5, “Cl-”: 0.9}

  • units – The units to use for the solute. e.g. “mol/kg”

Returns:

A formatted solute dictionary.

Raises:

TypeError if solute_dict is not a dictionary.

pyEQL.utils.interpret_units(unit: str) str[source]

Translate commonly used environmental units such as ‘ppm’ into strings that pint can understand.

Parameters:

unit – string representing the unit to translate

Returns: a unit that pint can understand

pyEQL.utils.standardize_formula(formula: str)[source]

Convert a chemical formula into standard form.

Parameters:

formula – the chemical formula to standardize.

Returns:

A standardized chemical formula

Raises:

ValueError if formula cannot be processed or is invalid.

Notes

Currently this method standardizes formulae by passing them through pymatgen.core.ion.Ion.reduced_formula(). For ions, this means that 1) the 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]”