Skip to main content

pyKES

Kinetic Evaluation and Simulation for chemical reaction networks

Documentation PyPI Python License: MIT Code style: NumPy docstrings

Documentation · Quickstart · User guide · API reference · Changelog


pyKES is a Python package for the kinetic modelling of chemical reaction networks, built around the needs of photocatalysis research: light-driven reaction networks, noisy sensor traces of evolved gas, and datasets of hundreds of experiments that all have to be processed the same way.

It covers the whole path from a raw instrument file to a mechanistic conclusion.

pip install pyKES

Simulate a reaction network

Write the mechanism the way you would on a whiteboard. Species go in square brackets, the rate constant follows a comma, and anything after a semicolon is an extra multiplier — which is how light enters.

import numpy as np
from pyKES.reaction_model import Reaction_Model

model = Reaction_Model(
    reaction_network=['[RuII] > [RuII-ex], k1 ; hv_functionA',
                      '[RuII-ex] > [RuII], k8',
                      '[RuII-ex] + [S2O8] > [RuIII] + [SO4], k7',
                      '[RuIII] > [H2O2] + [RuII], k2 ; hv_functionB',
                      '2 [RuIII] > [Ru-Dimer], k3',
                      '[H2O2] > [O2], k5',
                      '[RuIII] > [Inactive], k6'],
    rate_constants=RATE_CONSTANTS,
    initial_conditions={'[RuII]': 10, '[S2O8]': 6000},
    other_multipliers=OTHER_MULTIPLIERS,
    times=np.linspace(0, 300, 1000))

model.solve_ode()
model.plot_solution(exclude_species=['[S2O8]', '[SO4]'])
Simulated concentration-time traces of Ru(bpy)3-photosensitized water oxidation

Both light-driven steps carry a competitive-absorption multiplier, resolved against the current concentrations at every integration step — so the strongly absorbing Ru(II) and the weakly absorbing Ru(III) compete for the incident photons as their ratio shifts. O₂ evolution tails off long before the persulfate is exhausted, because the photosensitizer is being consumed by the loss channels.


Fit rate constants across a whole dataset

A single curve rarely constrains a mechanism. pyKES fits one parameter set to many experiments at once, reading each experiment's own concentrations, light intensity and time grid out of the experiment itself.

from pyKES.fitting_ODE import Fitting_Model, square_loss_time_series

model = Fitting_Model(['[A] > [B], k1',
                       '[B] > [C], k2'])

model.experiments = list(dataset.experiments.values())
model.rate_constants_to_optimize = {'k1': (1e-3, 5e-1),
                                    'k2': (1e-3, 5e-1)}

# A path, not a number — resolved per experiment.
model.initial_conditions = {'[A]': 'metadata/initial_concentration_uM'}
model.data_to_be_fitted = {'[B]': {'x': 'processed_data/intermediate/x',
                                   'y': 'processed_data/intermediate/y'}}
model.times = {'times': 'processed_data/times'}
model.loss_function = square_loss_time_series

model.optimize()
model.visualize_optimization_results()
Three experiments fitted simultaneously with one set of rate constants

Three starting concentrations, one mechanism, one pair of rate constants — recovered to better than 0.5 % of the values the data was generated from.


Extract maximum rates from noisy traces

Real sensor data carries bubbles, thermal drift and stirring beats. Differencing neighbouring points reports the largest disturbance, not the largest rate.

from pyKES.utilities.max_rate import extract_max_rate, plot_max_rate
from pyKES.utilities.unit_handler import Quantity

result = extract_max_rate(Quantity(time_seconds, 's'),
                          Quantity(evolved_h2_umol, 'umol'))

print(result.max_rate.unit['umol / h'])   # read it in whatever unit you want
print(result.max_rate_std)                # its standard deviation
print(result.flags)                       # empty list = nothing suspicious
Maximum-rate diagnostic showing a rejected bubble artifact and the fitted rate

The trace above carries a baseline wave whose local slope rivals the true rate and a bubble whose instantaneous slope is 75× it. Separating them by structure rather than amplitude — a Matérn-5/2 kinetic component, a short-correlation nuisance component and two-sided excursion rejection, fitted by exact O(n) Kalman smoothing — recovers the rate to within 8 % and flags the disturbances it found. Full write-up →


Trace where the light goes

Concentration traces do not say which fraction of the absorbed light reached the product. Freezing the network at one point in time does.

model.calculate_reaction_network_propopagation(
    timepoint=10,
    absorbing_species_with_extinction_coefficients={
        '[A]': {'excited_name': '[A-excited]', 'extinction_coefficient': 8500},
        '[B]': {'excited_name': '[B-excited]', 'extinction_coefficient': 5400}},
    photon_flux=1e17,
    pathlength=2.25,
    concentration_unit='uM')

model.plot_reaction_network_propagation()
Pathway diagram of the photon budget of a two-chromophore cascade

Of every 100 incident photons, 66 pass straight through, 33 are absorbed by [A], and 25 of those decay unproductively — so roughly 8 photons in 100 do useful work. That number is the one worth optimizing, and it appears nowhere in the kinetic traces. Bar heights are log-scaled so a pathway carrying a thousandth of the light stays visible next to one carrying a third.


What else is in the box

HDF5 datasets ExperimentalDataset keeps raw data, metadata and results in one file, with provenance stamps and parallel ingestion. Because the raw data stays in the file, an improved algorithm can be applied to a finished dataset years later — without the original instrument files.
Streamlit pages Five reusable pages an external repository configures rather than forks: dataset loading, upload and processing, analysis results, time series and a results table. Deployable to a server or, via stlite, straight into the browser as a static site.
Units A lightweight Quantity type so a rate in mol/h can be read as umol/s without a hand-written conversion factor — and so reading an O₂ rate as if it were H₂ raises instead of silently succeeding.
Efficiencies Apparent quantum yield and light-to-hydrogen efficiency, computed in explicit units from measured rates.

Documentation

Full documentation lives at pykes.readthedocs.io.

Section
Installation Getting set up, extras, editable installs alongside an embedding repo
Quickstart Four self-contained examples, one per part of the package
Architecture How the pieces fit together, with code-flow diagrams
Reaction networks Mechanism syntax, rate law, multipliers, stiffness
Light absorption Competitive absorption, and wiring it into a mechanism
Fitting Loss functions, weighting, bounds, diagnosing a bad fit
Pathways Photon budgets, cycles, reconvergence, reading the diagram
Maximum rates The algorithm stage by stage, with parameter guidance
Datasets Ingestion, storage, reprocessing, provenance
Streamlit app Embedding and configuring the pages
API reference Generated from the docstrings

Development

git clone https://github.com/jschneidewind/pyKES.git
cd pyKES
pip install -e '.[dev]'
pytest

Build the documentation locally:

sphinx-build -b html docs docs/_build/html

Regenerate the figures above (they are produced by the package itself, so a change in behaviour shows up here):

python docs/generate_example_figures.py

Using pyKES from another repository

Depend on a released version:

dependencies = ["pyKES>=0.2.4"]

or, while developing both side by side:

pip install -e /path/to/pyKES

After a pyKES version bump, refresh the embedding repository's lock file with uv lock --refresh && uv sync.


Contributing

Contributions are welcome — please open an issue or a pull request. See the contributing guide for the coding conventions this repository follows.

License

MIT. See LICENSE.

pyKES is developed in the Water Splitting Group and shares its outlook with pyH2A, which covers the techno-economic side of the same research.

Metadata

Release files for pyKES 1.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pyKES 1.0.0
File Size Uploaded Provenance Actions
pykes-1.0.0.tar.gz 136.1 kB Without provenance Details for pykes-1.0.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for pyKES 1.0.0
File Interpreter ABI Platform Actions
pykes-1.0.0-py3-none-any.whl Python 3 none any Details for pykes-1.0.0-py3-none-any.whl

Total release size: 291.1 kB

Release files / pykes-1.0.0.tar.gz

Download URL pykes-1.0.0.tar.gz
Size 136.1 kB
Tags Source
SHA-256 checksum
How to use checksums
42a718c2ddfedadd0814e3fd2331ffb5ea197320c3ffdfb38f22ef2cef079555
BLAKE2b-256 checksum
How to use checksums
d954b99f31c3593cb58b7485df529129dbb9971704f3a2a78de0968af967d606
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.11.13 {"installer":{"name":"uv","version":"0.11.13","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / pykes-1.0.0-py3-none-any.whl

Download URL pykes-1.0.0-py3-none-any.whl
Size 154.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
3076cea89119b450106ae85257655a053904bf0331b1b449d0f1dc011eab7e68
BLAKE2b-256 checksum
How to use checksums
b93c95e3fd6d1d090308ede7b1aa93a4ba89e3005275fdec596a2631506aa551
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.11.13 {"installer":{"name":"uv","version":"0.11.13","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Security for pyKES 1.0.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page