Demo Notebook

pyeql-logo.png

pyEQL is an open-source python library for solution chemistry calculations and ion properties

Documentation

GitHub

Installation

>>> pip install pyEQL

Main feature: The Solution class

[1]:
from pyEQL import Solution
/home/ryan/mambaforge/envs/pbx/code/pyEQL/src/pyEQL/__init__.py:52: FutureWarning: unitdeprecator is deprecated
The pyEQL UnitRegistry has been renamed from unit to ureg. Change 'from pyEQL import unit' to 'from pyEQL import ureg'!
  globals()["unit"] = unitdeprecator()
[2]:
s1 = Solution({"Mg+2": "0.2 mol/L", "Cl-1": "0.4 mol/L"}, temperature='20 degC')
WARNING 2023-10-17 09:36:21,530 solution.py _get_property 2089 Partial molar volume for species H[+1] not corrected for temperature
WARNING 2023-10-17 09:36:21,538 solution.py _get_property 2089 Partial molar volume for species OH[-1] not corrected for temperature
WARNING 2023-10-17 09:36:21,788 solution.py _get_property 2089 Partial molar volume for species Mg[+2] not corrected for temperature
WARNING 2023-10-17 09:36:21,818 activity_correction.py _debye_parameter_volume 231 Debye-Huckel limiting slope for volume is approximate when T is not equal to 25 degC

Bulk Properties

[3]:
s1.density
[3]:
1.0138757383570756 kg/l
[4]:
s1.conductivity
WARNING 2023-10-17 09:36:21,869 solution.py viscosity_kinematic 599 Viscosity coefficients for MgCl2 not found. Viscosity will be approximate.
WARNING 2023-10-17 09:36:21,906 solution.py viscosity_kinematic 599 Viscosity coefficients for MgCl2 not found. Viscosity will be approximate.
WARNING 2023-10-17 09:36:21,944 solution.py viscosity_kinematic 599 Viscosity coefficients for MgCl2 not found. Viscosity will be approximate.
WARNING 2023-10-17 09:36:21,970 engines.py get_activity_coefficient 314 Ionic strength too high to estimate activity for species H[+1]. Specify parameters for Pitzer model. Returning unit activity coefficient
WARNING 2023-10-17 09:36:21,985 solution.py viscosity_kinematic 599 Viscosity coefficients for MgCl2 not found. Viscosity will be approximate.
WARNING 2023-10-17 09:36:22,008 engines.py get_activity_coefficient 314 Ionic strength too high to estimate activity for species OH[-1]. Specify parameters for Pitzer model. Returning unit activity coefficient
[4]:
3.299995263108894 S/m
[5]:
s1.volume
[5]:
1 l
[6]:
s1.pressure
[6]:
1 atm
[7]:
s1.temperature
[7]:
293.15 K
[8]:
s1.osmotic_pressure
[8]:
1286752.4185332006 Pa

Composition

[9]:
s1.components
[9]:
{'H2O(aq)': 55.221652761186476, 'Cl[-1]': 0.4, 'Mg[+2]': 0.2, 'H[+1]': 1e-07, 'OH[-1]': 1e-07}
[10]:
s1.solvent
[10]:
'H2O(aq)'
[11]:
s1.cations
[11]:
{'Mg[+2]': 0.2, 'H[+1]': 1e-07}
[12]:
s1.anions
[12]:
{'Cl[-1]': 0.4, 'OH[-1]': 1e-07}
[13]:
s1.neutrals
[13]:
{'H2O(aq)': 55.221652761186476}

Species Concentrations

[14]:
s1.get_amount('Mg+2', 'M')
[14]:
0.20000000000000007 M
[15]:
s1.get_amount('Cl-', '%')
[15]:
1.3987118404647676
[16]:
s1.get_amount('Mg+2', 'eq/L')
[16]:
0.4 mol/l
[17]:
s1.get_amount('Mg+2', 'ug/kg')
[17]:
4886244.60412788 µg/kg

Transport

[18]:
s1.get_transport_number('Na+')
[18]:
0.0
[19]:
s1.get_transport_number('Mg+2')
[19]:
0.4099879515632778
[20]:
s1.get_transport_number('Cl-')
[20]:
0.5900109897851136

Speciation

[21]:
s1.equilibrate()
[22]:
s1.components
[22]:
{'H2O(aq)': 55.238455538403954, 'Cl[-1]': 0.38323989957700755, 'Mg[+2]': 0.18323990520853942, 'MgCl[+1]': 0.016760093825573405, 'H[+1]': 1.2403230417432767e-07, 'OH[-1]': 9.844314720800745e-08, 'HCl(aq)': 5.431780489909693e-09, 'MgOH[+1]': 7.932661202804441e-15, 'O2(aq)': 3.1477649388058775e-26, 'HClO(aq)': 8.450946375546259e-29, 'ClO[-1]': 3.367672345557701e-29, 'H2(aq)': 5.442728186726209e-35, 'ClO2[-1]': 0.0, 'ClO3[-1]': 0.0, 'ClO4[-1]': 0.0, 'HClO2(aq)': 0.0}

Saving Solution to a file

[23]:
from monty.serialization import dumpfn
dumpfn(s1, 'test_solution.json')
[24]:
s1.as_dict()
[24]:
{'@module': 'pyEQL.solution',
 '@class': 'Solution',
 '@version': '0.6.0.post1.dev23+g090ac81',
 'solutes': {'H2O(aq)': '55.238455538403954 mol',
  'Cl[-1]': '0.38323989957700755 mol',
  'Mg[+2]': '0.18323990520853942 mol',
  'MgCl[+1]': '0.016760093825573405 mol',
  'H[+1]': '1.2403230417432767e-07 mol',
  'OH[-1]': '9.844314720800745e-08 mol',
  'HCl(aq)': '5.431780489909693e-09 mol',
  'MgOH[+1]': '7.932661202804441e-15 mol',
  'O2(aq)': '3.1477649388058775e-26 mol',
  'HClO(aq)': '8.450946375546259e-29 mol',
  'ClO[-1]': '3.367672345557701e-29 mol',
  'H2(aq)': '5.442728186726209e-35 mol',
  'ClO2[-1]': '0.0 mol',
  'ClO3[-1]': '0.0 mol',
  'ClO4[-1]': '0.0 mol',
  'HClO2(aq)': '0.0 mol'},
 'volume': '1 l',
 'temperature': '293.15 K',
 'pressure': '1 atm',
 'pH': 6.90646518824501,
 'pE': 8.5,
 'balance_charge': None,
 'solvent': 'H2O(aq)',
 'engine': 'native',
 'database': {'@module': 'maggma.stores.mongolike',
  '@class': 'JSONStore',
  '@version': '0.19.1.post1.dev1792+g0517496',
  'paths': ['/home/ryan/mambaforge/envs/pbx/code/pyEQL/src/pyEQL/database/pyeql_db.json'],
  'read_only': True,
  'serialization_option': None,
  'serialization_default': None,
  'key': 'formula'}}

Units-Aware Calculations

[25]:
s1.volume.to('mL')
[25]:
1000.0000000000001 ml
[26]:
s1.volume.to('gal')
[26]:
0.26417205235814856 gal
[27]:
s1.osmotic_pressure.to('bar').magnitude
WARNING 2023-10-17 09:36:22,373 engines.py get_osmotic_coefficient 462 Cannot calculate osmotic coefficient because Pitzer parameters for salt HClO3 are not specified. Returning unit osmotic coefficient
WARNING 2023-10-17 09:36:22,384 engines.py get_osmotic_coefficient 462 Cannot calculate osmotic coefficient because Pitzer parameters for salt HClO2 are not specified. Returning unit osmotic coefficient
[27]:
12.630074635540739

Contribution Opportunities

Benchmarking - Compiling additional validation data for activity, conductivity, etc. - Quantifying error associated with different models - Refactoring unit tests suite to separate benchmarking

Documentation - Writing tutorials - Writing expanded docs - Cleaning up / updating docstrings

New Features - Better viscosity model - Expanded unit testing (increase test coverage to 90%) - Additional properties - Additional mixing rules / models for mixed electrolytes

Database - Expand database doverage to include additional species - More viscosity coefficients - Add ‘sho’ parameter - More diffusion coefficients

Software Engineering - Additional refactoring (e.g., mypy linting for robustness) - Bugfixes