lmbio
lmbio is an LMCode host that simulates gene circuits, enzymes, drugs, epidemics and molecular noise as reaction networks: stiff ODEs with CVODE, steady states with KINSOL, Gillespie SSA, and SBML in and out. You build a model with the bio context inside an _lmcode_ block, check the numbers and save CSV for lmplot and lmdraw.
Install and run
npm install -g @lmctl-ai/lmctl
mkdir try-lmbio && cd try-lmbio
lmctl https://raw.githubusercontent.com/lmctl-ai/lmbio/main/examples/toggle_switch.lms
The example downloads the lmbio, lmplot and lmdraw release binaries on first use (Linux needs dynamic glibc 2.35 or newer). The animated examples also write a GIF when ffmpeg is on PATH.
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.
Minimal runnable example
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");
Host CLI and protocol
usage: lmbio --version | --notices | --lmcode-schema [--json] | --lmcode-signatures | [--dry-run] --lmcode FILE [FILE ...]
| Flag | Behavior |
|---|---|
| --version | Print the version |
| --notices | Print the embedded third-party notices (SUNDIALS, pugixml, toolchain runtimes) |
| --lmcode-schema | Print the schema; with --json print the embedded schema JSON. Any other extra argument is a usage error, exit 2 |
| --lmcode-signatures | Print the callable signatures |
| --lmcode FILE [FILE ...] | Load every compiled .dslb program, then run them in order, stopping at the first failure |
| --dry-run --lmcode FILE ... | Check bytecode without running the model or writing files |
| Item | Value |
|---|---|
| Schema | schema/lmbio.dsl.json, dsl.schema 2, name lmbio, context bio of type Bio, 3 host types, 37 host methods |
| Standard library | lmcode_std_v3 with 206 signatures vendored at main (the current catalog in lmcode-cpp has 226) |
| Exit codes | 0 success, 2 usage error, 3 bytecode load or run error |
| Memory budget | LMBIO_MAX_MEMORY_MB, default 4096 MiB on 64-bit |
Host API quick reference
| Call | Returns | Purpose |
|---|---|---|
| bio.model(string name) | Model | Create an empty model |
| bio.load_sbml(string path) | Model | Import a model from the supported SBML subset |
| bio.assert_close(float a, float b, float absolute_tolerance) | void | Stop the run unless a and b agree within the absolute tolerance |
| bio.assert_true(bool condition) | void | Stop the run unless the condition holds |
| bio.print(string text) | void | Script output |
| model.compartment(string id, float size) | Model | Fixed, positive compartment volume |
| model.species(string id, string compartment, float initial) | Model | Species with an initial concentration |
| model.param(string id, float value) | Model | Kinetic parameter |
| model.reaction(string id, string equation, string rate) | Model | Stoichiometry such as A + B -> 2 C and a rate expression such as k*A*B; empty sides give sources and sinks |
| model.reversible(string id, string reverse_rate) | Model | Add a reverse rate to an existing reaction |
| model.mass_action(string id, string equation, string k) | Model | Mass-action law k*V*A^2 for ODEs and propensity k*A*(A-1) for SSA from one call (added in 0.1.1) |
| model.mass_action_reversible(string id, string equation, string kf, string kr) | Model | The same with a mass-action reverse rate (added in 0.1.1) |
| model.rule(string id, string expression) | Model | Assignment rule |
| model.rate_rule(string id, string expression) | Model | Differential rule |
| model.set(string id, float value) | Model | Change an initial species value, a parameter or a compartment size (compartments from 0.1.1) |
| model.get(string id) | float | Query the same values |
| model.set_state(Result result) | Model | Restart from the last row of a result, for example before a dose (added in 0.1.1) |
| model.tol(float rtol, float atol) | Model | Configure solver error control |
| model.validate() | Model | Validate the network |
| model.simulate(float t0, float t1, int points) | Result | CVODE BDF time course |
| model.steady_state() | Result | Steady state with residual verification |
| model.ssa(float t1, int points, int seed) | Result | Gillespie direct simulation with an integer seed |
| model.sensitivity(string parameter, float t0, float t1, int points, float relative_step) | Result | Central finite-difference derivatives |
| model.save_sbml(string path) | void | Write supported semantics as SBML L3V2 MathML |
| result.value(string id, int row) | float | Named value at a zero-based row |
| result.final(string id) | float | Named value in the last row |
| result.rows() | int | Number of rows |
| result.cols() | int | Number of columns |
| result.column(int index) | string | Column name |
| result.get(int row, int col) | float | Indexed value |
| result.max(string id) | float | Sampled maximum of a column |
| result.time_of_max(string id) | float | First time of the maximum |
| result.min(string id) | float | Sampled minimum (added in 0.1.1) |
| result.integral(string id) | float | Trapezoid area under a column, for example drug exposure AUC (added in 0.1.1) |
| result.crossing(string id, float level) | float | First time a column reaches a level, linearly interpolated (added in 0.1.1) |
| result.append(Result next) | Result | Join consecutive runs; a jump at the joint (a dose) keeps both rows (added in 0.1.1) |
| result.save_csv(string path) | void | Comma-separated matrix with header |