pharmsol
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 your Cargo.toml, either manually or using
Quick Start
use *;
// Create a subject with an IV infusion and observations
let subject = builder
.infusion // 500 units over 0.5 hours
.observation
.observation
.observation
.observation
.build;
// Define parameters: ke (elimination rate), v (volume)
let ke = 1.022;
let v = 194.0;
// Use the built-in one-compartment analytical solution
let analytical = new;
// Get predictions
let predictions = analytical.estimate_predictions.unwrap;
ODE-Based Models
For custom or complex models, define your own ODEs:
use *;
let ode = ODEnew;
Supported 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-compartment with IV infusion
- Three-compartment with IV infusion and oral absorption
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 *;
use NCAOptions;
let subject = builder
.bolus // 100 mg oral dose
.observation
.observation
.observation
.observation
.observation
.build;
let result = subject.nca.expect;
println!;
println!;
println!;
if let Some = result.terminal
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