Skip to main content

AbStochKin: Agent-based Stochastic Kinetics

DOI PyPI package version Python versions Documentation GitHub license

Alternate name: PyStochKin (Particle-based Stochastic Kinetics)

AbStochKin is an agent-based (or particle-based) Monte-Carlo simulator of the time evolution of systems composed of species that participate in coupled processes. The population of a species is considered as composed of distinct individuals, termed agents, or particles. This allows for the specification of the kinetic parameters describing the propensity of each agent to participate in a given process.

Although the algorithm was originally conceived for simulating biochemical systems, it is applicable to other disciplines where there is a need to model how populations change over time and to study the effects of heterogeneity, or diversity, in the composition of species populations on the dynamics of a system.

Installation

The abstochkin package can be installed via pip in an environment with Python 3.12+.

$ pip install abstochkin

Requirements

The package relies only on Python's scientific ecosystem libraries (numpy, scipy, sympy, matplotlib) and the standard library for implementing the core components of the algorithm. These requirements can be easily met in any Python (version 3.12+) environment.

What processes can be modeled?

  • Simple processes (0th, 1st, 2nd order).
  • Processes obeying Michaelis-Menten kinetics (1st order).
  • Processes that are regulated by one or more species through activation or repression (0th, 1st, 2nd order).
  • Processes that are regulated and obey Michaelis-Menten kinetics (1st order).

Usage

Here is a simple example of how to run a simulation: consider the process $A \rightarrow B$, the conversion of agents of species $A$ to agents of species $B$. Notice that we represent the process in standard chemical notation, therefore there are 'reactants' and 'products' and each species has a stoichiometric coefficient associated with it (implied to be $1$ if it is not explicitly written). The rate constant for this process is specified to be $k=0.2$ and has units of reciprocal seconds. Here, we assume a homogeneous population; that is, all agents of species $A$ have the same propensity to 'transition' to species $B$. Thus, the value $k=0.2$ applies to all $A$ agents when determining the transition probability within a given time step.

We then run an ensemble of simulations by specifying the initial population sizes ($A$: $100$ agents, $B$: $0$ agents) and the simulated time of $10$ seconds. Behind the scenes, default values for unspecified but necessary arguments are used (specifically, the number of simulations that comprise the ensemble, $n=100$, and the duration of the fixed time interval for each step in the simulation, $dt=0.01$ seconds).

from abstochkin import AbStochKin

sim = AbStochKin()
sim.add_process_from_str('A -> B', k=0.2)
sim.simulate(p0={'A': 100, 'B': 0}, t_max=10)

When the simulation is completed, the results are presented in graphical form.

Concurrency

The algorithm performs an ensemble of simulations to obtain the mean time trajectory of all species and statistical measures of the uncertainty thereof. To facilitate the rapid execution of the simulation, multithreading is enabled by default. This is done because numpy, whose core algorithms can bypass the Global Interpreter Lock (GIL), is used extensively during the algorithm's runtime. For instance, the simple usage example presented above uses multithreading.

When running a series of jobs (each with its own ensemble of simulations) where a parameter is varied (e.g., a parameter sweep), process-based parallellism can be used. The user does not have to worry about the details of setting up the code for multiprocessing. Instead, they can simply call a method of the base class.

from abstochkin import AbStochKin

sim = AbStochKin()
# Define a process that obeys Michaelis-Menten kinetics:
sim.add_process_from_str("A -> B", k=0.3, catalyst='E', Km=10)
# Vary the initial population size of species A:
series_kwargs = [{"p0": {'A': a, 'B': 0, 'E': 10}, "t_max": 10} for a in range(40, 51)]
sim.simulate_series_in_parallel(series_kwargs)

Documentation

See the documentation here.

A monograph detailing the theoretical underpinnings of the Agent-based Kinetics algorithm and a multitude of case studies highlighting its use can be found here.

Contributing

We welcome any contributions to the project in the form of bug reports, feature requests, and pull requests. Feel free to contact the core developer and maintainer at alex dot plaka at alumni dot princeton.edu to introduce yourself and discuss possible ways to contribute.

Metadata

Release files for abstochkin 0.3.1

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

Source distribution (sdist)

Source distribution for abstochkin 0.3.1
File Size Uploaded
abstochkin-0.3.1.tar.gz 21.7 MB Details

Built distribution (wheel)

Table of built distributions (wheels) for abstochkin 0.3.1
File Interpreter ABI Platform
abstochkin-0.3.1-py3-none-any.whl Python 3 none any Details

Total release size: 21.8 MB

Release files / abstochkin-0.3.1.tar.gz

Download URL abstochkin-0.3.1.tar.gz
Size 21.7 MB
Tags Source
SHA-256 checksum
How to use checksums
92ccb18b35699135b2c1f94512e10e06f5130cb89aa251f18b91f5e8ab493083
BLAKE2b-256 checksum
How to use checksums
45898000cf52072c180c17d32dbae8bde78d0271a4a43048703acbc9186a5b46
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.6

Release files / abstochkin-0.3.1-py3-none-any.whl

Download URL abstochkin-0.3.1-py3-none-any.whl
Size 77.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
21b4f2c2c1ed8f30b370f90c2c40aaa07b263118b7650fd32c7e05a303733979
BLAKE2b-256 checksum
How to use checksums
199312e433fca6bfa4e0ecb1344db992a2d20544320f8dde29841ec060c1820e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.6

Release history Release notifications | RSS feed

This release

0.3.1 This release

2 release files

0.3.0

2 release files

0.2

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

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