GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - LAPKB/pharmsol: Rust library for solving pharmacometric models

BranchesTags
Open more actions menu

Latest commit

 

History

461 Commits
461 Commits

Folders and files

NameName
Last commit message
Last commit date
.github
.github
 
 
benches
benches
 
 
examples
examples
 
 
joss
joss
 
 
pharmsol-dsl
pharmsol-dsl
 
 
pharmsol-macros
pharmsol-macros
 
 
src
src
 
 
tests
tests
 
 
.gitignore
.gitignore
 
 
.zenodo.json
.zenodo.json
 
 
CHANGELOG.md
CHANGELOG.md
 
 
CITATION.cff
CITATION.cff
 
 
CONTRIBUTING.md
CONTRIBUTING.md
 
 
Cargo.toml
Cargo.toml
 
 
LICENSE
LICENSE
 
 
README.md
README.md
 
 
codecov.yml
codecov.yml
 
 
release-plz.toml
release-plz.toml
 
 

Repository files navigation

pharmsol

Build Documentation DOI crates.io codecov

A high-performance Rust library for pharmacokinetic/pharmacodynamic (PK/PD) simulation using analytical solutions, ordinary differential equations (ODEs), or stochastic differential equations (SDEs).

Installation

Add pharmsol to Cargo.toml:

cargo add pharmsol

Quick Start

Most Rust-first workflows start with one of the equation macros: analytical!, ode!, or sde!. Here is a one-compartment oral model using analytical! with a derived analytical structure input:

use pharmsol::{Parameters, prelude::*};

let analytical = analytical! {
    name: "one_cmt_oral",
    params: [ka, ke0, v],
    derived: [ke],
    covariates: [wt],
    states: [gut, central],
    outputs: [cp],
    routes: [
        bolus(oral) -> gut,
    ],
    structure: one_compartment_with_absorption,
    derive: |_t| {
        ke = ke0 * (wt / 70.0).powf(0.75);
    },
    out: |x, _t, y| {
        y[cp] = x[central] / v;
    },
};

let subject = Subject::builder("patient_001")
    .bolus(0.0, 500.0, "oral")
    .missing_observation(0.5, "cp")
    .missing_observation(1.0, "cp")
    .missing_observation(2.0, "cp")
    .missing_observation(4.0, "cp")
    .covariate("wt", 0.0, 75.0)
    .build();

let parameters = Parameters::with_model(
    &analytical,
    [("ka", 1.2), ("ke0", 0.08), ("v", 194.0)],
)
.unwrap();

let predictions = analytical
    .predict(&subject, &parameters)
    .unwrap();

Modeling Surfaces

Here is the same one-compartment IV setup written as an ODE:

use pharmsol::prelude::*;

let ode = ode! {
    name: "one_cmt_iv",
    params: [ke, v],
    states: [central],
    outputs: [cp],
    diffeq: |x, _p, _t, dx, _cov| {
        dx[central] = infusion[iv] - ke * x[central];
    },
    out: |x, _p, _t, _cov, y| {
        y[cp] = x[central] / v;
    },
};

See examples/analytical_readme.rs, examples/ode_readme.rs, examples/sde_readme.rs, examples/dsl_analytical_covariates.rs, examples/analytical_vs_ode.rs, and examples/compare_solvers.rs.

Built-In Analytical Kernels

  • One-compartment with IV infusion
  • One-compartment with IV infusion and oral absorption
  • Two-compartment with IV infusion
  • Two-compartment with IV infusion and oral absorption
  • Three-compartment with IV infusion
  • Three-compartment with IV infusion and oral absorption

DSL and Runtime Targets

If the model needs to be loaded or compiled at runtime, pharmsol also provides a DSL with the same broad modeling coverage: ODE, analytical, and SDE authoring. Enable the dsl feature to compile DSL source into a runtime model inside the current process.

See examples/dsl_runtime.rs for the in-repo JIT flow and examples/dsl_analytical_covariates.rs for a small analytical covariate example written both as DSL JIT source and as an analytical! model.

Performance

Analytical solutions provide 20-33× speedups compared to equivalent ODE formulations. See benchmarks for details.

Non-Compartmental Analysis (NCA)

pharmsol includes a complete NCA module for calculating standard pharmacokinetic parameters.

use pharmsol::prelude::*;
use pharmsol::nca::NCAOptions;

let subject = Subject::builder("patient_001")
    .bolus(0.0, 100.0, "oral")  // 100 mg oral dose
    .observation(0.5, 5.0, "cp")
    .observation(1.0, 10.0, "cp")
    .observation(2.0, 8.0, "cp")
    .observation(4.0, 4.0, "cp")
    .observation(8.0, 2.0, "cp")
    .build();

let result = subject.nca(&NCAOptions::default()).expect("NCA failed");

println!("Cmax: {:.2}", result.exposure.cmax);
println!("Tmax: {:.2} h", result.exposure.tmax);
println!("AUClast: {:.2}", result.exposure.auc_last);

if let Some(ref term) = result.terminal {
    println!("Half-life: {:.2} h", term.half_life);
}

Supported NCA Parameters:

  • Exposure: Cmax, Tmax, Clast, Tlast, AUClast, AUCinf, tlag
  • Terminal: λz, t½, MRT
  • Clearance: CL/F, Vz/F, Vss
  • IV-specific: C0 (back-extrapolation), Vd
  • Steady-state: AUCtau, Cmin, Cavg, fluctuation, swing

Links

  • API Documentation
  • Examples

About

Rust library for solving pharmacometric models

lapkb.github.io/pharmsol/

Topics

pharmacokineticspharmacometricsrust

Resources

Readme
GPL-3.0 license

Contributing

Contributing
Activity
Custom properties

Stars

6 stars

Watchers

5 watching

Forks

1 fork
Report repository

Releases

Packages

Used by

Contributors

Languages

You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.