This library is in ALPHA version. The API is defined but subject to change as we further develop the functionality and our understanding of the product.
This repository contains a Python library for specifying, solving and visualising a pharmacokinetic model.
PK Model is a useful library for quantitatively describing the absorption, distribution, metabolism, and excretion of a drug through a patient's system.
The patient's body is modelled as one or more kinetically homogenous compartments: a primary central compartment into which the drug is administered and excreted, and zero or more peripheral compartments into which the drug may be distributed to/from. For example:
Where:
- Dose(t) is the drug dose function (dosage with respect to time)
- Vc [mL] is the volume of the central compartment
- qc [ng] is the amount of drug in the central compartment
- Vp1 [mL] is the volume of the first peripheral compartment
- qp1 [ng] is the amount of drug in the first peripheral compartment
- CL [mL/h] is the clearance/elimination rate from the central compartment
- Qp1 [mL/h] is the transition rate between central compartment and peripheral compartment
This easy-to-use package enables the drug quantity in each comparment to be tracked and visualised at different time points. It is highly versatile, enabling users to alter parameters such as the number of peripheral compartments, the type of dosing, the dosing protocol, and more.
PK Model is an up-and-coming Python package that strives to make pharmacokinetic modelling intuitive and user-friendly by providing a simple yet powerful model of drug delivery.
Figure 1: A side-by-side plot generated by the usage example.
Below is a helpful example to get you started.
import pkmodel as pk
# Create a protocol object describing how the dose of drug is delivered
# Set the initial dose to the patient to 100
protocol = pk.Protocol(initial_dose=100)
# Now specify how the drug is delivered dynamically,
# with a function describing the rate of drug addition over time
protocol.add_dose_function(lambda t, y: - 1 / (t + 1))
# Now create a model object
# Specify the drug is delivered intravenously with 'iv'.
model = pk.Model('iv')
# Add peripheral compartments to this model.
# Specify the V_{p} and Q_{p} for each of these:
model.add_compartment(V_p_new=2, Q_p_new=3)
model.add_compartment(V_p_new=8, Q_p_new=0.5)
# Now we want to visualise these.
# Create a Solution object:
solution = pk.Solution()
# Add the protocol and model to this solution:
solution.add(model, protocol)
# Now visualise the solution of these two
solution.visualise()
# We can also compare multiple protocol and model pairs using this method.
# Create a new protocol, with the same initial dose:
protocol2 = pk.Protocol(initial_dose=100)
# We will not input our own dosage function this time,
# instead we use the default instantaneous dose function
# Add model and this new protocol to the solution object for comparison:
solution.add(model, protocol2)
# Now visualise, choosing to either overlay the two graphs on the same plot:
solution.visualise(layout='overlay')
# Or have two plots side-by-side:
solution.visualise(layout='side_by_side')
# The outputs of these can be seen below.
Figure 2: Plot of model with protocol 1. Details of the model and protocol will be printed to the terminal as labels.
Figure 3: Plot of model with protocol 1 and model with protocol 2 overlay. Details of model and protocol will be printed to the terminal as labels.
Figure 4: Plot of model and protocol 1 and model with protocol 2 side by side. Details of model and protocol will be printed to the terminal as labels.
You now have everything you need to start pkmodelling! Feel free to refer to our documentation for further details.
PK Model is compatible with Python versions 3.6+.
To install the latest release of the PK Model library, simply type the following command into the console:
python -m pip install --extra-index-url https://test.pypi.org/simple/ pkmodel
If you wish to uninstall the library, you can do so using the following command:
pip uninstall PKModel
Our API Reference and User Guide is available on Read the Docs.
The dependencies for this package can be found in the list of Requirements. Note: all dependencies are automatically installed when the PK Model package is installed.
For instructions on how to contribute to PK model, see the Contributor README.