Skip to main content

Numerical solution of mass-action laws

Project description

PyPI version CI Status code coverage

massaction

A python package for the numerical solution of mass-action laws with constraints for the description of chemical reactions.

Installation

The easiest way to install massaction is from PyPi using pip.

pip install massaction

Usage

The major perk of massaction is the simple syntax in which one can set up the description of a chemical equilibrium. For instance, the mass-action law for the oxyhydrogen reaction may be set up in just a few lines of Python code:

from massaction.model import ChemModel

mymodel = ChemModel(3) # set up a model with 3 chemical species
h2o, h2, o2 = mymodel.get_all_species() # give names to the species objects

# first set up the reaction equation, then define constraints to ensure atom balance
reaction = h2 + o2 >> 2*h2o
ln_equilibrium_constant = 20. # arbitrary units
constraint_hydrogen = 2*h2 + 2*h2o == 1.0 # arbitrary units
constraint_oxygen = h2o + 2*o2 == 10.0 # arbitrary units

# now solve the system of equations to obtain an array with the natural logarithm of the concentrations
ln_concentrations = mymodel.solve( [reaction], [ln_equilibrium_constant], [constraint_hydrogen, constraint_oxygen] )

The resulting array ln_concentrations is array([ -0.69314718, -22.94443898, 1.55814462]), which contains the entries $\ln\left(c(\mathrm{H_2O})\right)$, $\ln\left(c(\mathrm{H_2})\right)$, and $\ln\left(c(\mathrm{O_2})\right)$, respectively.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

massaction-0.1.1.tar.gz (10.3 kB view details)

Uploaded Source

Built Distribution

massaction-0.1.1-py3-none-any.whl (8.0 kB view details)

Uploaded Python 3

File details

Details for the file massaction-0.1.1.tar.gz.

File metadata

  • Download URL: massaction-0.1.1.tar.gz
  • Upload date:
  • Size: 10.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.12.5

File hashes

Hashes for massaction-0.1.1.tar.gz
Algorithm Hash digest
SHA256 0960df7226b5c8287f1cd2ba34f20d008d3f3bfed0e947d83362c55b5f4a3721
MD5 7ae392b0a6e89844805c1565f2b36640
BLAKE2b-256 dfab8bc5f9b48255d609b47e4b2b67b7734ea3bb90d27eb4731c115565c6815b

See more details on using hashes here.

File details

Details for the file massaction-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: massaction-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 8.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.12.5

File hashes

Hashes for massaction-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 26e467409f9aa4bb9d292efa99e9cee1d643c3836b8c746a1cf2d6942b24a536
MD5 5058182905d7ece1ff5bc8e99a3fdf10
BLAKE2b-256 271fca422bbffefb6d53c11fd2f04f2bd1bff080d2380279dfac4c737f41befd

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page