#models #ode #observation #pharmacometric #analytical #pk-pd

pharmsol

Rust library for solving analytic and ode-defined pharmacometric models

31 releases (6 breaking)

0.7.1 Oct 17, 2024
0.6.3 Sep 28, 2024
0.3.1 Jul 28, 2024

#9 in Simulation

Download history 15/week @ 2024-07-08 126/week @ 2024-07-22 53/week @ 2024-07-29 128/week @ 2024-08-05 10/week @ 2024-08-12 372/week @ 2024-09-02 429/week @ 2024-09-09 231/week @ 2024-09-16 260/week @ 2024-09-23 59/week @ 2024-09-30 11/week @ 2024-10-07 316/week @ 2024-10-14 29/week @ 2024-10-21

442 downloads per month
Used in pmcore

GPL-3.0 license

140KB
3.5K SLoC

pharmsol

Build Documentation crates.io

Simulate PK/PD profiles using ODE and analytical models.

Example

ODE based model.

    use pharmsol::*;

    let subject = Subject::builder("id1")
        .bolus(0.0, 100.0, 0)
        .repeat(2, 0.5)
        .observation(0.5, 0.1, 0)
        .observation(1.0, 0.4, 0)
        .observation(2.0, 1.0, 0)
        .observation(2.5, 1.1, 0)
        .covariate("wt", 0.0, 80.0)
        .covariate("wt", 1.0, 83.0)
        .covariate("age", 0.0, 25.0)
        .build();
    // println!("{subject}");
    let ode = equation::ODE::new(
        |x, p, t, dx, _rateiv, cov| {
            fetch_cov!(cov, t, _wt, _age);
            fetch_params!(p, ka, ke, _tlag, _v);
            // Secondary Eqs
            // let ke = ke * wt.powf(0.75) * (age / 25.0).powf(0.5);

            //Struct
            dx[0] = -ka * x[0];
            dx[1] = ka * x[0] - ke * x[1];
        },
        |p| {
            fetch_params!(p, _ka, _ke, tlag, _v);
            lag! {0=>tlag}
        },
        |_p| fa! {},
        |_p, _t, _cov, _x| {},
        |x, p, _t, _cov, y| {
            fetch_params!(p, _ka, _ke, _tlag, v);
            y[0] = x[1] / v;
        },
        (2, 1),
    );

    let op = ode.estimate_predictions(&subject, &vec![0.3, 0.5, 0.1, 70.0]);
    // println!("{op:#?}");
    let _ = op.run();

Analytic based model.

use pharmsol::*;
let analytical = equation::Analytical::new(
    one_compartment_with_absorption,
    |_p, _cov| {},
    |p| {
        fetch_params!(p, _ka, _ke, tlag, _v);
        lag! {0=>tlag}
    },
    |_p| fa! {},
    |_p, _t, _cov, _x| {},
    |x, p, _t, _cov, y| {
        fetch_params!(p, _ka, _ke, _tlag, v);
        y[0] = x[1] / v;
    },
    (2, 1),
);
let op = analytical.simulate_subject(&subject, &vec![0.3, 0.5, 0.1, 70.0]);
println!("{op:#?}");

Supported analytical models

We are working to support all the standard analytical models.

  • 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-compartmental models

Links

Documentation Benchmarks

Dependencies

~25–36MB
~585K SLoC