lmbio skill: simulate reaction networks from LMScript

Use this page to write, run and verify an lmbio program. Every fact comes from the lmbio repository at main (version 0.1.3); no command output is reproduced here because the published release could not be run with the current lmscript (see Install).

Purpose

lmbio models gene circuits, enzymes, drugs, epidemics and molecular noise as reaction networks. It integrates stiff ODEs with CVODE, finds steady states with KINSOL, runs Gillespie SSA with a seed, computes finite-difference sensitivities and reads and writes an SBML subset. Results are matrices that you check with assertions and save as CSV; lmbio draws nothing itself.

When to use it

Install

npm install -g @lmctl-ai/lmctl
lmscript --version

A block that starts with cli="lmbio" install="github:lmctl-ai/lmbio@latest" makes lmscript download the release binary on first use. Linux binaries require dynamic glibc 2.35 or newer (Ubuntu 22.04+). If an unrelated program called lmbio is already on PATH, lmscript picks it first and schema discovery fails; remove it from PATH or put this host first.

Release status, checked with lmscript 0.2.482: the main branch of the repository (version 0.1.3 in CMakeLists.txt) answers the --lmcode-schema, --lmcode-signatures and --lmcode flags, but the v0.1.3 release binary that install="github:lmctl-ai/lmbio@latest" downloaded on the day this page was written still printed a usage line with the older --dsl-schema, --dsl-signatures and --dsl flags, so current lmscript stopped with a schema host exited 2 error. Until a release built from main is published, build the host from source and put it first on PATH.

git clone https://github.com/lmctl-ai/lmbio
cd lmbio
scripts/sync-deps.sh
cmake -S . -B build -DCMAKE_BUILD_TYPE=Release
cmake --build build --parallel 4

Building requires CMake 3.24+, C++17, git and Python 3.

Commands

CommandUse
lmscript FILE.lmsCompile the block, start the host and return the result envelope to the script
lmscript --check FILE.lmsCompile and type-check the block against the lmbio schema without running
lmctl URLRun an example script from a raw GitHub URL in the current folder
lmbio --version, --noticesVersion and embedded license notices
lmbio --lmcode-schema --jsonEmbedded schema JSON
lmbio --lmcode-signaturesCallable signatures as text
lmbio [--dry-run] --lmcode FILE.dslb ...The host protocol that run_lmcode drives; rarely typed by hand

Inside a block the usual order is: bio.model, compartment, species, param, reactions and rules, optional tol and validate, then simulate, steady_state, ssa or sensitivity, then assertions and save_csv.

Inputs and outputs

Safety rules

Worked examples

First-order conversion with a closed-form check

A converts to B at rate k*A. The run checks exp(-0.7*4) and mass conservation, then saves the time course. This is the model from the repository README, executed with run_lmcode.

prog = _lmcode_ cli="lmbio" install="github:lmctl-ai/lmbio@latest";
let m = bio.model("conversion").compartment("cell", 1.0);
m.species("A", "cell", 1.0).species("B", "cell", 0.0);
m.param("k", 0.7).reaction("convert", "A -> B", "k*A");
let result = m.simulate(0.0, 4.0, 41);
bio.assert_close(result.final("A"), 0.060810062625, 0.000001);
bio.assert_close(result.final("A") + result.final("B"), 1.0, 0.000001);
result.save_csv("conversion.csv");
lmcode_return_put("A", result.final("A"));
lmcode_return_put("rows", result.rows());
end _lmcode_
r = run_lmcode(prog);
println(json_stringify(r));
require(r.ok, "conversion failed");

One seeded Gillespie trajectory

Immigration and loss at low copy number, from examples/stochastic.lms: a source reaction with an empty left side and a sink with an empty right side.

mkdir("build");
prog = _lmcode_ cli="lmbio" install="github:lmctl-ai/lmbio@latest";
let m = bio.model("immigration_death").compartment("cell", 1.0).species("X", "cell", 0.0).param("birth", 3.0).param("death", 1.0).reaction("immigration", " -> X", "birth").reaction("loss", "X ->", "death*X");
let r = m.ssa(10.0, 101, 424242);
bio.assert_true(r.final("X") >= 0.0);
r.save_csv("build/stochastic.csv");
end _lmcode_
r = run_lmcode(prog);
require(r.ok, "ssa failed");

Errors and exit codes

Host exitMeaning
0Success, also for --version, --notices and the schema flags
2Usage error: unknown or missing flags, no file, or an invalid LMBIO_MAX_MEMORY_MB value; the usage text goes to stderr
3Bytecode load error or run error: a host validation message, a failed assertion or an exceeded memory budget

A wrong numerical result is an error by design: a failed bio.assert_close or bio.assert_true stops the run. If lmscript reports unexpected argument '--lmcode-schema', a different program named lmbio is first on PATH. If it reports a usage line that lists --dsl flags, the host binary predates the --lmcode protocol.

How to verify