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 ...]
FlagBehavior
--versionPrint the version
--noticesPrint the embedded third-party notices (SUNDIALS, pugixml, toolchain runtimes)
--lmcode-schemaPrint the schema; with --json print the embedded schema JSON. Any other extra argument is a usage error, exit 2
--lmcode-signaturesPrint 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
ItemValue
Schemaschema/lmbio.dsl.json, dsl.schema 2, name lmbio, context bio of type Bio, 3 host types, 37 host methods
Standard librarylmcode_std_v3 with 206 signatures vendored at main (the current catalog in lmcode-cpp has 226)
Exit codes0 success, 2 usage error, 3 bytecode load or run error
Memory budgetLMBIO_MAX_MEMORY_MB, default 4096 MiB on 64-bit

Host API quick reference

CallReturnsPurpose
bio.model(string name)ModelCreate an empty model
bio.load_sbml(string path)ModelImport a model from the supported SBML subset
bio.assert_close(float a, float b, float absolute_tolerance)voidStop the run unless a and b agree within the absolute tolerance
bio.assert_true(bool condition)voidStop the run unless the condition holds
bio.print(string text)voidScript output
model.compartment(string id, float size)ModelFixed, positive compartment volume
model.species(string id, string compartment, float initial)ModelSpecies with an initial concentration
model.param(string id, float value)ModelKinetic parameter
model.reaction(string id, string equation, string rate)ModelStoichiometry 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)ModelAdd a reverse rate to an existing reaction
model.mass_action(string id, string equation, string k)ModelMass-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)ModelThe same with a mass-action reverse rate (added in 0.1.1)
model.rule(string id, string expression)ModelAssignment rule
model.rate_rule(string id, string expression)ModelDifferential rule
model.set(string id, float value)ModelChange an initial species value, a parameter or a compartment size (compartments from 0.1.1)
model.get(string id)floatQuery the same values
model.set_state(Result result)ModelRestart from the last row of a result, for example before a dose (added in 0.1.1)
model.tol(float rtol, float atol)ModelConfigure solver error control
model.validate()ModelValidate the network
model.simulate(float t0, float t1, int points)ResultCVODE BDF time course
model.steady_state()ResultSteady state with residual verification
model.ssa(float t1, int points, int seed)ResultGillespie direct simulation with an integer seed
model.sensitivity(string parameter, float t0, float t1, int points, float relative_step)ResultCentral finite-difference derivatives
model.save_sbml(string path)voidWrite supported semantics as SBML L3V2 MathML
result.value(string id, int row)floatNamed value at a zero-based row
result.final(string id)floatNamed value in the last row
result.rows()intNumber of rows
result.cols()intNumber of columns
result.column(int index)stringColumn name
result.get(int row, int col)floatIndexed value
result.max(string id)floatSampled maximum of a column
result.time_of_max(string id)floatFirst time of the maximum
result.min(string id)floatSampled minimum (added in 0.1.1)
result.integral(string id)floatTrapezoid area under a column, for example drug exposure AUC (added in 0.1.1)
result.crossing(string id, float level)floatFirst time a column reaches a level, linearly interpolated (added in 0.1.1)
result.append(Result next)ResultJoin consecutive runs; a jump at the joint (a dose) keeps both rows (added in 0.1.1)
result.save_csv(string path)voidComma-separated matrix with header

Detail pages