Skip to main content

BioStoch

Simulation in Biology

ssa1.png

Simulated with GillespySimulator: Concentration trajectories of species A and B over time. Ten independent simulations were performed, each represented by a different line color

Overview

  • biostoch is a Python library for simulating chemical and biological models using various deterministic and stochastic methods. It provides implementations of methods such as Euler's method, the Runge-Kutta algorithm, the Stochastic Simulation Algorithm (SSA), Tau-Leaping, and the Chemical Langevin Equation (CLE). These methods can be used to model and analyze the dynamics of biochemical reactions, gene regulatory networks, and other biological systems.

Article

Installation

  • Install biostoch and its dependencies using pip:
pip install numpy matplotlib 
pip install biostoch

Usage

import numpy
import matplotlib
import time
from biostoch.model import Model
from biostoch.ode import EulerSimulator, RungeKuttaSimulator
from biostoch.ssa import GillespieSimulator
from biostoch.tau_leaping import TauLeaping
from biostoch.cle import ChemicalLangevin
from biostoch.visualization import Visualization

# Define a system of reactions, in this case, a simple system with two reactions: A <-> B; with rate constants K1 = 0.1, K2 = 0.05
model = Model() 

# Add rate constants for each reaction in the system
model.parameters({
    "K1": 0.1, 
    "K2": 0.05
})

# Add species and rate of change for each of them
model.species(
    components={
        "A": 100.0, 
        "B": 0.0
    }, 
    rate_change={
        "A": "K2 * B - K1 * A", 
        "B": "K1 * A - K2 * B"
    }
)

# Add reactions and rate for each of them
model.reactions(
    reacts={
        "reaction1": "A -> B", 
        "reaction2": "B -> A"
    },
    rates={
        "reaction1": "K1 * A", 
        "reaction2": "K2 * B"
    }
)

# Simulate the model using ordinary differential equations (ODE) with the Euler method
euler_model = EulerSimulator(
    model=model, 
    start=0, 
    stop=100, 
    epochs=1000
)
euler_model.reset() # Reset the model to initialize if it has been used before
euler_model.simulate() # Simulate the model 
euler_model.species # Print the model species after the simulation, a dictionary containing the change in species concentration during the simulation time
euler_model.time # Show how long the simulation took to complete

# Simulate the model using ordinary differential equations (ODE) with the Runge-Kutta method
runge_model = RungeKuttaSimulator(
    model=model, 
    start=0, 
    stop=100, 
    epochs=1000
)

runge_model.simulate()
runge_model.species
runge_model.time

# Simulate the model using the Stochastic Simulation Algorithm (SSA)
ssa_model = GillespieSimulator(
    model=model, 
    start=0, 
    stop=100, 
    max_epochs=1000
)

ssa_model.simulate()
ssa_model.species
ssa_model.time

# Simulate the model using the Tau-Leaping method
tau_model = TauLeaping(
    model=model, 
    start=0, 
    stop=100, 
    max_epochs=100
)

tau_model.simulate()
tau_model.species
tau_model.time

# Simulate the model using the Chemical Langevin Equation method
cle_model = ChemicalLangevin(
    model=model,
    start=0,
    stop=100, 
    max_epochs=1000
)

cle_model.simulate()
cle_model.species
cle_model.time

# Visualize the simulated models using integrated matplotlib.pyplot in biostoch
euler_plot = Visualization(euler_model)
runge_plot = Visualization(runge_model)
ssa_plot = Visualization(ssa_model)
tau_plot = Visualization(tau_model)
cle_plot = Visualization(cle_model)

euler_plot.plot()
runge_plot.plot()
ssa_plot.plot()
tau_plot.plot()
cle_plot.plot()

License

Metadata

Release files for biostoch 0.0.6

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

Source distribution (sdist)

Source distribution for biostoch 0.0.6
File Size Uploaded
biostoch-0.0.6.tar.gz 13.4 kB Details

Built distribution (wheel)

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

Total release size: 30.4 kB

Release files / biostoch-0.0.6.tar.gz

Download URL biostoch-0.0.6.tar.gz
Size 13.4 kB
Tags Source
SHA-256 checksum
How to use checksums
c1be80a902afe2c93cc961224fb27d01a92a1ad291266db3ddccbfb5cda897c5
BLAKE2b-256 checksum
How to use checksums
a0f8415fd86fa67bcf6b88961a80a57c0d790cdef97a4220b9f93dc19cb6768e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.10.12

Release files / biostoch-0.0.6-py3-none-any.whl

Download URL biostoch-0.0.6-py3-none-any.whl
Size 17.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
dbe8c63fe29ed4e283edfababe2e0044fd4a25076dcd43774f43222b64c476f5
BLAKE2b-256 checksum
How to use checksums
15b18d8fbf8b2eebd2ec4355aaf0de72e23f463b5d5a97f178901152526ece17
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.10.12

Release history Release notifications | RSS feed

This release

0.0.6 This release

2 release files

0.0.5

2 release files

0.0.4

2 release files

0.0.3

2 release files

0.0.2

2 release files

0.0.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