#model #observation #ode #equation #cov #analytical #analytic

pharmsol

Rust library for solving analytic and ode-defined pharmacometric models

20 releases

0.2.4 Jun 26, 2024
0.2.3 Jun 25, 2024
0.1.15 Jun 7, 2024
0.1.12 May 31, 2024

#9 in Simulation

Download history 203/week @ 2024-05-08 148/week @ 2024-05-15 609/week @ 2024-05-22 870/week @ 2024-05-29 214/week @ 2024-06-05 30/week @ 2024-06-12 508/week @ 2024-06-19 223/week @ 2024-06-26

1,007 downloads per month
Used in pmcore

GPL-3.0 license

85KB
2K SLoC

Pharmsol

Build Documentation crates.io

Simulate PK/PD profiles using ODE and analytical models.

Example

ODE based model.

use pharmsol::*;

let subject = data::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)
    .build();
println!("{subject:#?}");
let ode = simulator::Equation::new_ode(
    //Difussion Equations
    |x, p, _t, dx, _rateiv, _cov| {
        fetch_cov!(cov, t,);
        fetch_params!(p, ka, ke, _tlag, _v);
        dx[0] = -ka * x[0];
        dx[1] = ka * x[0] - ke * x[1];
    },
    // Lag definition (In this case boluses on dx[0] will be delayed by `tlag`)
    |p| {
        fetch_params!(p, _ka, _ke, tlag, _v);
        lag! {0=>tlag}
    },
    // No bio-availability
    |_p| fa! {},
    // Default initial conditions (0.0,0.0)
    |_p, _t, _cov, _x| {},
    // Output Equations
    |x, p, _t, _cov, y| {
        fetch_params!(p, _ka, _ke, _tlag, v);
        y[0] = x[1] / v;
    },
    (2, 1),
);

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

Analytic based model.

...
let analytical = simulator::Equation::new_analytical(
    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

Dependencies

~20–27MB
~429K SLoC