lmcell guide: the model, its numerics and its limits

This guide explains what an lmcell simulation is, how the host is built, how a program flows from an _lmcode_ block to CSV files, and where the model stops. For commands and copy-ready examples see the skill page; for exact signatures see the reference.

Overview

lmcell is a scripting-only multicellular simulation host. A program builds one simulation in memory with chained builder calls, runs it once, and reads the outcome as numeric matrices. The computing core is serial PhysiCell 1.14.2 with BioFVM, linked statically into a single executable; no XML configuration, kernels or runtime data files are involved. The host follows the common lmcode protocol, so lmscript compiles the block against the schema embedded in the binary, hands the bytecode to the host and receives one result envelope.

The design goal is checkable science: each of the 16 repository examples asserts a known answer (a closed form, a threshold or a conservation law) before it draws anything, and a wrong number stops the run.

Architecture

LayerWhat it does
lmscriptCompiles the _lmcode_ block against the lmcell schema, downloads the release named by install, starts the host through run_lmcode and returns the envelope
lmcell hostRegisters the cell context and the Sim, CellType, Result and Matrix types, validates every argument, enforces object and memory limits, writes CSV
Coordinatorlmcell's own time loop: applies rules, asks PhysiCell for cycle, death and motility decisions, places daughters, moves cells, reflects them at walls
PhysiCellCell objects, the single-phase live cycle, stochastic death checks, apoptosis clearance and the motility vector update
BioFVMImplicit 2D diffusion and decay solver and cell secretion and uptake
lmcode_std_v3Standard library available in every block: strings, math, collections, Json, files and the result sink

OpenMP is disabled through a small serial compatibility header, so runs are single threaded and deterministic for a seed on a given platform. PhysiCell and BioFVM keep process-wide state, which is why one host process can run exactly one simulation.

Workflow

  1. Create the builder with cell.sim(seed). The seed drives both the placement generator and the stochastic cell decisions.
  2. Set the domain. Lengths must be whole multiples of the voxel size. Without a domain call the grid is -100..100 on both axes with 20 micrometer voxels.
  3. Declare substrates, then optional per-side edge values and a diffusion substep.
  4. Declare cell types and chain their phenotype: cycle, death, radius, motility, chemotaxis, exchange and rules.
  5. Place cells with seed, scatter or seed_disk.
  6. Optionally request snapshots with record.
  7. Call run(duration, max_dt). This validates the whole configuration, freezes the builders and returns an immutable Result.
  8. Pull matrices from the result, assert on values, save CSV, and return summary values with lmcode_return_put.
  9. In the outer script, test r.ok and pass the CSV files to a plotting host or to your own analysis.

Configuration errors are detected before any native global state is touched, so a typo in a rule target fails cleanly. A failure during native initialization or stepping consumes the process: the simulation cannot be retried in the same block.

Domain model

Space, time and units

The domain is a rectangle of square voxels, one voxel thick. Lengths are micrometers and times are minutes; rates are per minute and diffusion coefficients are square micrometers per minute. Concentration units are whatever the caller chooses. Nothing is converted automatically.

The requested max_dt is turned into a constant actual step, duration divided by the ceiling of duration over max_dt, so the final step is never a partial one. The counts table therefore has that many steps plus one row.

Cells are point agents

A cell has a position, a type, a radius and an alive flag. Its volume is the sphere volume 4·π·r³/3 even though the domain is 2D, and that volume divided by the voxel volume scales its exchange with the substrate fields. Division places a daughter at the same position. Cells do not push, pull or adhere to each other and do not grow in volume; they reflect at the domain boundary. Crowding can influence behavior only through the neighbors signal.

Apoptotic cells stay in the cell table with alive 0 until PhysiCell's clearance time, so the cells matrix can have more rows than the live count.

Substrates

Each substrate is a field with a uniform initial value, a diffusion coefficient and a decay rate. The boundary argument is either -1 for no flux on all sides or a value at which every edge voxel center is held. edge overrides one side at a time; the global boundary applies first, then edges in call order, so the last call wins at a corner. A domain that is a single row of voxels has only x edges.

Every step the cells first secrete and take up, then BioFVM advances diffusion and decay. Secretion relaxes a voxel toward saturation 1.

Motility and chemotaxis

motility(speed, persistence_time) gives a persistent random walk. With chemotaxis(substrate, bias) each new heading is the normalized blend of a random direction, weighted 1 − bias, and the unit gradient of the substrate in the cell's voxel, weighted bias. Bias 0 is an unbiased walk and bias 1 follows the gradient exactly; a zero gradient falls back to the unbiased walk. In a linear gradient the mean drift speed is 0, 2v/π and v for bias 0, 1/2 and 1.

Hill rules

A rule reads a signal s and computes the Hill response H = s^n / (K^n + s^n) from half_max K and hill n. The signal is a declared substrate, sampled in the cell's voxel, or the reserved name neighbors: the number of other live cells in the same voxel, counted once at the start of the step. A substrate may not be named neighbors.

FormEffect on the target rateNote
rule with effect increasesrate × (1 + H)At most doubles the base rate; cannot lift a zero base rate
rule with effect decreasesrate × (1 − H)Switches the rate off at saturation
rule_towardrate + (saturation − rate) × HReaches any nonnegative rate, also from a zero base

Targets are cycle entry (the division rate), apoptosis (the death rate) and migration speed. Several rules on one type apply in call order, each starting from the result of the previous one, and every step starts again from the type's base rates. This is a builder-level subset of the PhysiCell hypothesis rules grammar, not an importer for rules files.

Results and matrices

run returns a Result that never changes. Each accessor such as counts or profiles copies a table into a new Matrix; the copy is independent of the result. Matrices are zero-based and are saved without a header. Grid rows follow BioFVM ordering with x varying fastest. The record interval produces snapshots at time 0 and at the first step at or after each multiple of the interval.

Numerics and accuracy

Patterns from the examples

QuestionBuilding blocksKnown answer checked
Necrotic core of a spheroidFixed nutrient edges, exchange uptake, two rule_toward rules, seed_disk, recordCore live fraction below 0.45, rim above 0.8
Drug penetration from a vesseledge on xmin, decay, diffusion_dtcosh profile with length √(D/k)
Contact inhibitionrule_toward on neighbors for cycle entry, scatterCarrying capacity 1 + K·√(r/d − 1) per voxel
Chemotactic driftLinear gradient between fixed edges, motility, chemotaxisDrift 0, 2v/π and v
Clonal selection under therapyTwo cell types, type_counts, live_of, two host processesEach clone grows as exp((b − d)·t)
Secreted signalexchange with secretion and uptakeVoxel relaxes toward S/(S + U)

Sweeps over a parameter use one block inside an lmscript function with interpolated parameters, one host process per case. The block language has no arrays of host objects, callbacks or ternary operator; loops and if statements are available, and the standard collections can hold numbers and strings.

Limits

LimitValue
Simulations per host process1
Cell types, substrates32 each
Rules1000
Cells (seeded and total population)100000
Voxels, cell steps1000000 each
Voxels × steps × diffusion substeps200 million
Recorded history values, recorded profile values20 million each
Host objects per kind (Sim, CellType, Result, Matrix)10000
Total memory4096 MiB by default, LMCELL_MAX_MEMORY_MB to change

Outside the model entirely: 3D domains and arbitrary geometry, mechanical interactions and adhesion, continuous volume growth, cell-cell contact such as killing or phagocytosis, intracellular models, PhysiCell XML or rules-file import, checkpoints and MultiCellDS exchange. lmcell is a research modeling host with documented units and step effects; it does not claim a calibrated tissue model from default parameters.

Building from source

scripts/sync-deps.sh
cmake -S . -B build -DCMAKE_BUILD_TYPE=Release
cmake --build build --parallel 4
./test.sh

The build needs CMake 3.24 or newer, a C++17 compiler, git and Python 3; the tests also need lmscript. Dependencies are pinned in deps.lock and the lmcode-cpp SDK in sdk.lock. The host is MIT licensed; PhysiCell and BioFVM are BSD-3-Clause, and lmcell --notices prints all notices.

Where to go next