pyEQL
Overview¶
pyEQL
is an open-source python
library for solution chemistry calculations and ion properties developed by the Kingsbury Lab at Princeton University.
Documentation | How to Install | GitHub
Installation¶
Uncomment and run the code cell below, if you do not already have pyEQL
[1]:
# pip install pyEQL
Main feature: The Solution
class¶
[2]:
from pyEQL import Solution
[3]:
s1 = Solution({"Mg+2": "0.2 mol/L", "Cl-1": "0.4 mol/L"}, temperature="20 degC")
Bulk Properties¶
[4]:
s1.density
[4]:
[5]:
s1.conductivity
[5]:
[6]:
s1.volume
[6]:
[7]:
s1.pressure
[7]:
[8]:
s1.temperature
[8]:
[9]:
s1.osmotic_pressure
[9]:
Composition¶
[10]:
s1.components
[10]:
{'H2O(aq)': 55.22159416581102, 'Cl[-1]': 0.4, 'Mg[+2]': 0.2, 'H[+1]': 1e-07, 'OH[-1]': 1e-07}
[11]:
s1.solvent
[11]:
'H2O(aq)'
[12]:
s1.cations
[12]:
{'Mg[+2]': 0.2, 'H[+1]': 1e-07}
[13]:
s1.anions
[13]:
{'Cl[-1]': 0.4, 'OH[-1]': 1e-07}
[14]:
s1.neutrals
[14]:
{'H2O(aq)': 55.22159416581102}
Species Concentrations¶
[15]:
s1.get_amount("Mg+2", "M")
[15]:
[16]:
s1.get_amount("Cl-", "%")
[16]:
[17]:
s1.get_amount("Mg+2", "eq/L")
[17]:
[18]:
s1.get_amount("Mg+2", "ug/kg")
[18]:
Transport¶
[19]:
s1.get_transport_number("Na+")
[19]:
[20]:
s1.get_transport_number("Mg+2")
[20]:
[21]:
s1.get_transport_number("Cl-")
[21]:
Speciation¶
[22]:
s1.equilibrate()
[23]:
s1.components
[23]:
{'H2O(aq)': 55.22159416581102, 'Cl[-1]': 0.3832398866053062, 'Mg[+2]': 0.18323989223683687, 'MgCl[+1]': 0.0167601067972765, 'H[+1]': 1.2403217124548544e-07, 'OH[-1]': 9.844304910095208e-08, 'HCl(aq)': 5.431779796106619e-09, 'MgOH[+1]': 7.932688947003906e-15, 'O2(aq)': 3.1477611183050287e-26, 'HClO(aq)': 8.450945207723896e-29, 'ClO[-1]': 3.3676720804550185e-29, 'H2(aq)': 5.442721694626408e-35, 'ClO2[-1]': 0.0, 'ClO3[-1]': 0.0, 'ClO4[-1]': 0.0, 'HClO2(aq)': 0.0}
Saving Solution
to a file¶
[24]:
from monty.serialization import dumpfn
dumpfn(s1, "test_solution.json")
[25]:
s1.as_dict()
[25]:
{'@module': 'pyEQL.solution',
'@class': 'Solution',
'@version': '0.14.0.post1.dev19+gbc296a6.d20240313',
'solutes': {'H2O(aq)': '55.22159416581102 mol',
'Cl[-1]': '0.3832398866053062 mol',
'Mg[+2]': '0.18323989223683687 mol',
'MgCl[+1]': '0.0167601067972765 mol',
'H[+1]': '1.2403217124548544e-07 mol',
'OH[-1]': '9.844304910095208e-08 mol',
'HCl(aq)': '5.431779796106619e-09 mol',
'MgOH[+1]': '7.932688947003906e-15 mol',
'O2(aq)': '3.1477611183050287e-26 mol',
'HClO(aq)': '8.450945207723896e-29 mol',
'ClO[-1]': '3.3676720804550185e-29 mol',
'H2(aq)': '5.442721694626408e-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.906465653690637,
'pE': 8.5,
'balance_charge': None,
'solvent': 'H2O(aq)',
'engine': 'native',
'database': {'@module': 'maggma.stores.mongolike',
'@class': 'JSONStore',
'@version': '0.57.8',
'paths': ['/home/ryan/miniconda3/envs/skagit2/code/pyEQL/src/pyEQL/database/pyeql_db.json'],
'read_only': True,
'serialization_option': None,
'serialization_default': None,
'key': 'formula'},
'default_diffusion_coeff': 1.6106e-09,
'log_level': 'ERROR'}
Units-Aware Calculations¶
[26]:
s1.volume.to("mL")
[26]:
[27]:
s1.volume.to("gal")
[27]:
[28]:
s1.osmotic_pressure.to("bar").magnitude
[28]:
12.634083700417097
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