| Title: | Connect Systems Biology and Pharmacology Formats to Simulation Backends |
|---|---|
| Description: | Provides a convenient R interface for systems-biology and systems-pharmacology models in Heta, SBML (Systems Biology Markup Language), and DynMS (Dynamic Model Specification) formats. DynMS JSON files are loaded directly; Heta projects and SBML files are converted to DynMS by an optional compatible installation of 'heta-compiler'. Models can be validated, selected from a platform, and generated or built for simulation with 'mrgsolve' as a backend. |
| Authors: | Evgeny Metelkin [aut, cre] |
| Maintainer: | Evgeny Metelkin <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.1.1 |
| Built: | 2026-10-27 20:21:47 UTC |
| Source: | https://github.com/cran/DynMSR |
Generates an mrgsolve model source file and compiles it with mrgsolve.
The mrgsolve package is optional and is required only when this function is
called.
build_mrgsolve(model, filepath = NULL, observables = NULL, ...)build_mrgsolve(model, filepath = NULL, observables = NULL, ...)
model |
A model list, such as one element of |
filepath |
Optional path for the intermediate mrgsolve model source. If omitted, it is written to a temporary file. |
observables |
Optional character vector of additional model symbols to
return from mrgsolve. Dynamic states and symbols already listed in the
DynMS model's |
... |
Additional arguments passed to |
A compiled mrgsolve model object.
if (requireNamespace("mrgsolve", quietly = TRUE)) { model <- get_model(dynms_load(dynms_lib("repeated-dose")), 1) compiled <- build_mrgsolve(model, observables = "ke", quiet = TRUE) simulation <- mrgsolve::mrgsim_df(compiled, end = 48, delta = 0.1) }if (requireNamespace("mrgsolve", quietly = TRUE)) { model <- get_model(dynms_load(dynms_lib("repeated-dose")), 1) compiled <- build_mrgsolve(model, observables = "ke", quiet = TRUE) simulation <- mrgsolve::mrgsim_df(compiled, end = 48, delta = 0.1) }
Returns the available example names or the path to one bundled DynMS JSON
file. Use dynms_load() to load the selected example.
dynms_lib(name = NULL)dynms_lib(name = NULL)
name |
Name of a bundled example. If |
If name is NULL, a character vector of example names. Otherwise,
the path to the selected DynMS JSON file.
dynms_lib() platform <- dynms_load(dynms_lib("first-order-decay"))dynms_lib() platform <- dynms_load(dynms_lib("first-order-decay"))
Reads a DynMS JSON file, validates it against the bundled schema, runs backend-independent semantic validation, and returns a platform list.
dynms_load(path)dynms_load(path)
path |
Path to a DynMS JSON file. |
Schema and semantic validation are both attempted before loading fails.
Validation messages are reported with message(), followed by one final
error when any validation issue is found.
DynMSR currently supports only expressions with format: "math-json".
A platform list. Use platform$models[[i]] to select one model for
backend-specific operations.
platform <- dynms_load(dynms_lib("two-state-conversion")) platformplatform <- dynms_load(dynms_lib("two-state-conversion")) platform
Reads a DynMS JSON file into an R list. DynMS documents are parsed with
jsonlite::fromJSON(..., simplifyVector = FALSE) to preserve the document
structure.
dynms_read(path)dynms_read(path)
path |
Path to a DynMS JSON file. |
An R list parsed from JSON.
path <- dynms_lib("first-order-decay") dynms_read(path)path <- dynms_lib("first-order-decay") dynms_read(path)
Validates a DynMS document against a JSON Schema. The document can be passed
as a file path or as the raw R list returned by dynms_read(). Validation
always uses the schema bundled with DynMSR. It uses the ajv engine
because the bundled schema uses modern JSON Schema features.
dynms_validate_schema(x, error = FALSE)dynms_validate_schema(x, error = FALSE)
x |
Path to a DynMS JSON file, or the raw R list returned by
|
error |
Whether schema validation errors should be raised as one R error after all available issues are collected. |
A list with valid, errors, and warnings fields.
validation <- dynms_validate_schema(dynms_lib("first-order-decay")) validation$validvalidation <- dynms_validate_schema(dynms_lib("first-order-decay")) validation$valid
Validates backend-independent semantic consistency of a schema-valid raw
DynMS platform object. Unlike schema validation, this function collects all
currently known semantic issues before returning. It does not validate the
document structure; use dynms_validate_schema() first when the input has
not already passed schema validation.
dynms_validate_semantic(raw_platform, error = FALSE)dynms_validate_semantic(raw_platform, error = FALSE)
raw_platform |
Raw DynMS platform object, typically returned by
|
error |
Whether semantic validation errors should be raised as one R error after all issues are collected. |
A list with valid, errors, and warnings fields.
raw_platform <- dynms_read(dynms_lib("first-order-decay")) validation <- dynms_validate_semantic(raw_platform) validation$validraw_platform <- dynms_read(dynms_lib("first-order-decay")) validation <- dynms_validate_semantic(raw_platform) validation$valid
Selects one model from a DynMS platform by numeric index or by name.
get_model(platform, model)get_model(platform, model)
platform |
A platform object returned by |
model |
A single model index or model name. |
A model list.
dynms_path <- dynms_lib("repeated-dose") platform <- dynms_load(dynms_path) model <- get_model(platform, 1)dynms_path <- dynms_lib("repeated-dose") platform <- dynms_load(dynms_path) model <- get_model(platform, 1)
Runs heta build for a Heta project directory. The arguments map directly
to Heta compiler CLI options, for example units_check = TRUE adds
--units-check.
heta_build( dir, output_dir, source = NULL, type = NULL, debug = FALSE, units_check = FALSE, log_mode = NULL, declaration = NULL, log_level = NULL, skip_updates = FALSE, export = NULL )heta_build( dir, output_dir, source = NULL, type = NULL, debug = FALSE, units_check = FALSE, log_mode = NULL, declaration = NULL, log_level = NULL, skip_updates = FALSE, export = NULL )
dir |
Project working directory passed as the final CLI argument. |
output_dir |
Directory for all compiler output. Required. Use
|
source |
Path to the main source file, passed as |
type |
Source file type, passed as |
debug |
If |
units_check |
If |
log_mode |
Log file saving mode, passed as |
declaration |
Declaration file path without extension, passed as
|
log_level |
Log level, passed as |
skip_updates |
If |
export |
Export format specification, passed as |
Requires a heta command that satisfies DynMSR's bundled compatibility
rule. Use heta_check() to inspect availability and the supported version
range before building. Compiler output paths are placed under output_dir:
dist/, meta/, and, when selected by log_mode, build.log. The output
directory must be supplied explicitly and remains available after the build.
Invisibly returns a list with the command, arguments, exit status,
captured output, and output_dir.
## Not run: project_dir <- "path/to/your/heta-project" output_dir <- tempfile("dynmsr-heta-output-") heta_build(project_dir, output_dir, export = "SBML", log_mode = "always") ## End(Not run)## Not run: project_dir <- "path/to/your/heta-project" output_dir <- tempfile("dynmsr-heta-output-") heta_build(project_dir, output_dir, export = "SBML", log_mode = "always") ## End(Not run)
Checks whether the heta command is available, can report its version with
heta --version, and satisfies the bundled DynMSR compatibility rule.
heta_check()heta_check()
A list with available, supported, command, version,
supported_version, installation_url, output, and message fields.
heta_check()heta_check()
Builds a Heta project with the DynMS export enabled, reads the generated DynMS JSON file, and returns a DynMS platform object.
heta_load( dir, output_dir = NULL, source = NULL, type = NULL, debug = FALSE, units_check = FALSE, log_mode = NULL, declaration = NULL, log_level = NULL, skip_updates = FALSE )heta_load( dir, output_dir = NULL, source = NULL, type = NULL, debug = FALSE, units_check = FALSE, log_mode = NULL, declaration = NULL, log_level = NULL, skip_updates = FALSE )
dir |
Heta project working directory. |
output_dir |
Optional directory for compiler output. If omitted, a temporary directory is used and removed after loading. |
source |
Path to the main source file, passed to |
type |
Source file type, passed to |
debug |
If |
units_check |
If |
log_mode |
Log file saving mode, passed to |
declaration |
Declaration file path without extension, passed to
|
log_level |
Log level, passed to |
skip_updates |
If |
Requires a compatible heta-compiler installation. Compiler output is
placed under output_dir in dist/, meta/, and, when selected by
log_mode, build.log. When output_dir is omitted, a temporary directory
is removed after loading.
A platform list. Use get_model() or ordinary list access such as
platform$models[[1]] to select one model.
## Not run: platform <- heta_load("path/to/your/heta-project") model <- get_model(platform, 1) compiled <- build_mrgsolve(model, quiet = TRUE) simulation <- mrgsolve::mrgsim_df(compiled, end = 24, delta = 0.1) ## End(Not run)## Not run: platform <- heta_load("path/to/your/heta-project") model <- get_model(platform, 1) compiled <- build_mrgsolve(model, quiet = TRUE) simulation <- mrgsolve::mrgsim_df(compiled, end = 24, delta = 0.1) ## End(Not run)
Displays a compact inventory of model components and their identifiers.
## S3 method for class 'model' print(x, ...)## S3 method for class 'model' print(x, ...)
x |
A DynMS model object. |
... |
Unused. |
x, invisibly.
model <- get_model(dynms_load(dynms_lib("first-order-decay")), 1) print(model)model <- get_model(dynms_load(dynms_lib("first-order-decay")), 1) print(model)
Displays the DynMS version and a compact summary of each model in a platform.
## S3 method for class 'platform' print(x, ...)## S3 method for class 'platform' print(x, ...)
x |
A DynMS platform object. |
... |
Unused. |
x, invisibly.
platform <- dynms_load(dynms_lib("first-order-decay")) print(platform)platform <- dynms_load(dynms_lib("first-order-decay")) print(platform)
Builds one SBML file through Heta compiler with the DynMS export enabled, reads the generated DynMS JSON file, and returns a DynMS platform object.
sbml_load( path, output_dir = NULL, debug = FALSE, units_check = FALSE, log_mode = NULL, declaration = NULL, log_level = NULL, skip_updates = FALSE )sbml_load( path, output_dir = NULL, debug = FALSE, units_check = FALSE, log_mode = NULL, declaration = NULL, log_level = NULL, skip_updates = FALSE )
path |
Path to an SBML file. |
output_dir |
Optional directory for compiler output, passed to
|
debug |
If |
units_check |
If |
log_mode |
Log file saving mode, passed to |
declaration |
Declaration file path without extension, passed to
|
log_level |
Log level, passed to |
skip_updates |
If |
Requires a compatible heta-compiler installation. The generated DynMS
export is written to a temporary directory and removed after loading unless
output_dir is supplied.
A platform list. Use get_model() or ordinary list access such as
platform$models[[1]] to select one model.
## Not run: sbml_path <- "path/to/your/model.xml" platform <- sbml_load(sbml_path) model <- get_model(platform, 1) compiled <- build_mrgsolve(model, quiet = TRUE) simulation <- mrgsolve::mrgsim_df(compiled, end = 24, delta = 0.1) ## End(Not run)## Not run: sbml_path <- "path/to/your/model.xml" platform <- sbml_load(sbml_path) model <- get_model(platform, 1) compiled <- build_mrgsolve(model, quiet = TRUE) simulation <- mrgsolve::mrgsim_df(compiled, end = 24, delta = 0.1) ## End(Not run)
Generates mrgsolve source from one DynMS model.
write_mrgsolve(model, filepath)write_mrgsolve(model, filepath)
model |
A model list, such as one element of |
filepath |
Path where the generated model source should be written. |
The exporter warns and ignores unsupported DynMS features: algebraic dynamic
states, stopSimulation, and state-event trigger detection. Algebraic
states are emitted as ordinary ODE states; state-event conditions are
evaluated in generated code without root finding. The current exporter
evaluates state-event conditions in $ODE, which mrgsolve may call at
internal trial times. The resulting state update can therefore occur at an
output record before or after the true threshold crossing. Smaller delta
or hmax values can sometimes make the approximation closer, but cannot
reproduce the exact root-crossing time or guarantee which side of the
threshold an event will be placed.
Identifiers reserved by mrgsolve are renamed with an _rnm_ suffix. Further
numeric suffixes are added when needed to avoid collisions. The exporter
emits one warning and records the complete mapping in the generated model.
The DynMS time symbol t is emitted as SOLVERTIME in $ODE and as TIME
in other blocks.
The path to the generated model file.
model <- get_model(dynms_load(dynms_lib("first-order-decay")), 1) path <- tempfile(fileext = ".mod") write_mrgsolve(model, path) unlink(path)model <- get_model(dynms_load(dynms_lib("first-order-decay")), 1) path <- tempfile(fileext = ".mod") write_mrgsolve(model, path) unlink(path)