Skip to main content

biolgca

CI Python 3.11–3.14 License: BSD-3-Clause PyPI DOI

Simulate how cells move, align, grow and evolve, in a few lines of Python.

Cells with random headings align with their neighbours and form moving flocks

biolgca implements biological lattice-gas cellular automata (BIO-LGCA). Each lattice site, or node, has one channel per direction of movement and optional rest channels, so the model tracks how many cells are at each node and where they are heading. The rules are local and stochastic, so simulations of large lattices are fast and the models can be analysed with mean-field and stability methods (Deutsch et al. 2021).

biolgca is for researchers and students in mathematical and theoretical biology who model collective cell migration, tissue growth, pattern formation or the evolution of cell populations, and for courses that teach these topics.

With biolgca you can:

  • combine built-in mechanisms: random walk, alignment, chemotaxis, contact guidance, aggregation, birth and death, go-or-grow and phenotype switching;
  • write a new interaction as a decorated Python function and use it like a built-in;
  • track individual cells with heritable traits to study evolution;
  • watch a model run in a notebook while you change its parameters with sliders;
  • run on 1D, square, hexagonal and 3D lattices; and
  • save every model as a JSON file that reruns from its seed with the same data (given the same biolgca and dependency versions).

Why biolgca

General-purpose frameworks for cell-based models couple cells to fields in many ways: Morpheus and CompuCell3D (cellular Potts models), PhysiCell (off-lattice agents) and Chaste (several cell-based model types, including an on-lattice cellular automaton). They do not offer the velocity-channel state space of LGCA. In this state space, alignment, chemotaxis and go-or-grow switching are rules for the reorientation of channel states, and mean-field equations can be derived systematically from the rules. biolgca provides this model class as a library: the rules of the BIO-LGCA literature as composable building blocks, a checked contract for new rules, model files that rerun from their seed, parameter sweeps, and a model zoo that reproduces published LGCA models with these rules.

Quick start

  1. Install uv, which manages Python and all dependencies for you:

    # macOS and Linux
    curl -LsSf https://astral.sh/uv/install.sh | sh
    # Windows (PowerShell)
    powershell -ExecutionPolicy ByPass -c "irm https://astral.sh/uv/install.ps1 | iex"
    
  2. Get biolgca and open JupyterLab:

    git clone https://github.com/sisyga/biolgca.git
    cd biolgca
    uv sync
    uv run jupyter lab
    

    If uv reports that it cannot find Python (some Linux distribution packages do not download it automatically), run uv python install first.

  3. Paste this into a notebook cell to produce the flocks shown above:

    from lgca import get_lgca
    
    lgca = get_lgca(geometry="hex", dims=(50, 50), interaction="alignment",
                    beta=3, density=0.5, seed=2)
    lgca.timeevo(timesteps=100, record=True)
    lgca.plot_flux()  # colour shows the direction of motion
    

    beta sets how strongly cells align with their neighbours. Try beta=0 (no alignment) or density=0.2 (sparser cells) and run again.

Build a model from mechanisms

For a study you will want every assumption written down. A ModelSpec describes the lattice, initial state, time and seed, and the list of interactions. Here cells align with their neighbours and follow an attractant gradient; both cues enter one stochastic decision per node:

Cells accumulate where the attractant peaks, near x = 40

import numpy as np
from lgca.model import AnalysisSpec, ModelSpec, SpaceSpec, StateSpec, TimeSpec, run_model
from lgca.pipeline import (InteractionPipelineSpec, ReorientationSpec,
                           ReorientationTermSpec)
from lgca.simulation import DensityRecorder

x = np.arange(50)[:, None] * np.ones((50, 50))
signal = np.exp(-((x - 40) / 15) ** 2)  # attractant peaks at x = 40

spec = ModelSpec(
    space=SpaceSpec(geometry="square", dims=(50, 50), boundary="reflecting"),
    state=StateSpec(density=0.5, fields={"signal": signal}),
    time=TimeSpec(steps=100, seed=1),
    dynamics=InteractionPipelineSpec(operators=[
        ReorientationSpec(terms=[  # both cues enter one stochastic decision
            ReorientationTermSpec(name="polar_alignment", beta=1.5),
            ReorientationTermSpec(name="chemotaxis", beta=20, parameters={"field": "signal"}),
        ]),
    ]),
    analysis=AnalysisSpec(observers=[DensityRecorder()]),  # what to record
)
result = run_model(spec)
result.lgca.plot_density()

Save the model with save_model_spec(spec, "model.json") from lgca.model. Anyone with the same versions of biolgca and its dependencies can then rerun it from the command line and get identical data:

uv run biolgca run model.json --output runs/chemotaxis-001

The run directory contains the resolved model, the biolgca version and the recorded densities in measurements.npz.

Growth and phenotype switching

A dense spheroid of cells grown from one node

Interactions can also create and remove cells. In the go-or-grow model, cells either migrate or rest and divide, and crowding shifts the balance between them. One fully occupied node grows into a spheroid:

spec = ModelSpec(
    space=SpaceSpec(geometry="hex", dims=(60, 60)),
    state=StateSpec(
        restchannels=6,  # resting cells sit in rest channels, moving cells in velocity channels
        initializer={"name": "region", "parameters": {"extent": 1, "density": 12}},
    ),
    time=TimeSpec(steps=90, seed=3),
    dynamics=InteractionPipelineSpec(operators=[
        {"name": "go_or_rest", "parameters": {"kappa": -4, "theta": 0.5}},
        {"name": "go_or_grow.growth", "parameters": {"r_b": 0.2, "r_d": 0.01}},
        {"name": "random_walk", "parameters": {"channels": "velocity"}},
    ]),
)
run_model(spec).lgca.plot_density()

In each step, cells switch between moving and resting and may die; resting cells divide, and moving cells pick new directions. With kappa=-4, crowded cells start moving. With kappa=4 they rest instead, and the same small colony shrinks: growth then needs a minimum population, an Allee effect that emerges from the switching rule.


Write your own interaction

A new rule is a Python function of the lattice state. The state offers operations with a fixed meaning per cell, such as "every cell dies with probability p", which work with and without volume exclusion and for any number of species. The decorator registers the rule under its name, with its parameters taken from the signature. This rule kills cells more often on crowded nodes; the loop compares three death rates:

from lgca import interaction
from lgca.simulation import PopulationRecorder


@interaction(kind="birth_death", families=("classical", "nove"))
def crowding_death(state, r_d=0.1):
    """Each cell dies with probability r_d * (cells on its node) / (node capacity)."""
    state.remove_cells(r_d * state.density / state.capacity)


for r_d in (0.0, 0.2, 0.5):
    spec = ModelSpec(
        space=SpaceSpec(geometry="square", dims=(40, 40)),
        state=StateSpec(density=1, restchannels=2),
        time=TimeSpec(steps=100, seed=1),
        dynamics=InteractionPipelineSpec(operators=[
            {"name": "birth_death", "parameters": {"birth_rate": 0.1}},
            crowding_death(r_d=r_d),
            {"name": "random_walk"},
        ]),
        analysis=AnalysisSpec(observers=[PopulationRecorder()]),
    )
    result = run_model(spec, showprogress=False)
    print(f"r_d = {r_d}: {result.data['population'][-1]} cells after 100 steps")

lgca.testing.check_interaction(crowding_death) runs a rule on every lattice and model family it claims to support and reports what goes wrong, from lost cells to unseeded random numbers. Movement biases are written the same way with @reorientation_term. The custom interaction guide shows growth rules, movement biases and a deterministic collision rule; tutorial 6 shows how to test a rule and share it with a model.

Learn

Eight notebooks take you from the first random walk to a reproducible project and to cells that act on the molecules around them. Each notebook builds its models in visible cells, and CI runs every notebook against the current code.

Lesson You will learn to
1. Fundamentals set up a lattice, run a random walk, compare boundaries and seeds
2. Collective movement compare alignment mechanisms and measure order
3. Combining cues combine alignment, chemotaxis and contact guidance; sweep parameters
4. Population dynamics add birth, death and phenotype switching; go-or-grow
5. Evolutionary LGCA track heritable traits across stochastic replicates
6. Student project write, test and share your own interaction
7. Oxygen-limited growth couple cells to a field they take up; let consumption evolve
8. Aggregation find the onset of chemotactic aggregation toward a secreted signal, and watch it live

The example gallery collects further ready-to-run models, one per question, and an advanced example: a tumour spheroid of proliferating, quiescent and necrotic cells in the oxygen they consume, in 2D and 3D, with parameters from measurements.

Model types

Without identities (cells are counted) Identity-based (individual cell traits)
Volume exclusion (at most one cell per channel) ✓ classical LGCA, also with several species ✓
No volume exclusion (many cells per channel) ✓, also with several species ✓

All model types run on 1D, square and hexagonal lattices, and on cubic and 3D Moore lattices. 3D rendering uses Mayavi, which is optional: install it with uv sync --extra plot3d.

Other ways to install

Without uv, install biolgca into any Python 3.11+ environment from PyPI, from a clone, or directly from GitHub:

python -m pip install biolgca             # from PyPI; also "biolgca[notebooks]", "[yaml]" or "[plot3d]"
python -m pip install -e ".[notebooks]"   # in the clone
python -m pip install "biolgca @ git+https://github.com/sisyga/biolgca@develop"   # newest development version

This picks the newest compatible versions of the dependencies. uv sync instead installs the exact versions in uv.lock, which the test suite runs against. The runtime dependencies are NumPy, SciPy, pyamg, threadpoolctl, tqdm, Matplotlib, pandas and ipywidgets. To check that the installation works, run biolgca examples list.

Questions and contributing

  • Questions about using biolgca, and bug reports and ideas: open an issue on the issue tracker, which offers templates for each.
  • Contributions are welcome: CONTRIBUTING.md explains how to set up the development environment, run the tests and the docs build, and propose a new interaction.
  • Everyone taking part follows the code of conduct.

Run the checks from the repository root after uv sync:

uv run pytest -q               # test suite
uv run python docs/build.py    # documentation, executes all tutorials

User-facing changes are recorded in CHANGELOG.md.

History

biolgca has been developed at TU Dresden since 2018. Until version 2.0, the code grew alongside the research that used it, with contributions from the people listed under Acknowledgements; it was modernised in 2025 and is kept on branch v1. Version 2.0 (2026) rewrote the package around declarative model specifications, a rule contract and the model zoo.

Citing

If you use biolgca in published work, please cite:

Syga S, Nava-Sedeño JM, Deutsch A (2026). A novel cellular automaton approach for modeling genotypic and phenotypic heterogeneity in cell systems. The European Physical Journal Special Topics. https://doi.org/10.1140/epjs/s11734-026-02186-1

To cite the software itself, use its Zenodo DOI, which always resolves to the newest version (each release also has a DOI of its own, listed on that page):

Syga S. biolgca: biological lattice-gas cellular automata in Python. Zenodo. https://doi.org/10.5281/zenodo.23944994

The BIO-LGCA modelling class is described in:

Deutsch A, Nava-Sedeño JM, Syga S, Hatzikirou H (2021). BIO-LGCA: A cellular automaton modelling class for analysing collective cell migration. PLoS Computational Biology 17(6): e1009066. https://doi.org/10.1371/journal.pcbi.1009066

Acknowledgements

biolgca is maintained by Simon Syga. Bianca Güttner (@GuettnerBianca) co-authored the code before 2.0. Code was also contributed by @Franzi2729, Marcus Krellner (@krelli89), Harish P Jain (@harishpjain) and Mateo Larralde (@mateolarr). The models build on the BIO-LGCA work of Andreas Deutsch, Josué Manik Nava-Sedeño, Haralampos Hatzikirou and colleagues.

License

BSD 3-clause, see LICENSE.txt. Copyright (c) 2018–2026 Technische Universität Dresden.

Metadata

Release files for biolgca 2.1.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 biolgca 2.1.0
File Size Uploaded Provenance Actions
biolgca-2.1.0.tar.gz 356.1 kB With provenance Details for biolgca-2.1.0.tar.gz

Built distribution (wheel)

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

Total release size: 766.5 kB

Release files / biolgca-2.1.0.tar.gz

Download URL biolgca-2.1.0.tar.gz
Size 356.1 kB
Tags Source
SHA-256 checksum
How to use checksums
0bdf625f5fda12b08200c8973899fe4b61d8292cc2f83cd81fb8d831e68c3e72
BLAKE2b-256 checksum
How to use checksums
d53de58ff42548ad336e861338e8eaf4cf8f9b86bd8b618ee7aa91561c888d62
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 16, 2026.

Transparency log

Release files / biolgca-2.1.0-py3-none-any.whl

Download URL biolgca-2.1.0-py3-none-any.whl
Size 410.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f0228ba1d34847d3d95c1e60dfc541764a57a738258d1f13b7df1714ba6c0d29
BLAKE2b-256 checksum
How to use checksums
67666dddf580ac1a38db690a40809e651b2e144348372f613bf7fa41efaea1c9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 16, 2026.

Transparency log

Security for biolgca 2.1.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.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for biolgca-2.1.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 16, 2026.

Transparency log

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.

Release history Release notifications | RSS feed

This release

2.1.0 This release

2 release files Full provenance

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