Code
import matplotlib.pyplot as plt
from math import exp
from scipy.integrate import odeint
import numpy as np
This notebook accompanies chapter 6 of the lecture notes. In this notebook, we will take a look at:
Below the packages we will use in this notebook are imported.
A simple kinetic model for a whole-body system is given by the following set of ODEs:
\[\begin{align} \frac{\mathrm{d}C_1}{\mathrm{d}t} &= -(k_1 + k_0) C_1 + k_2 C_2 \\ \frac{\mathrm{d}C_2}{\mathrm{d}t} &= k_1 C_1 - k_2 C_2 \end{align}\]
where \(C_1\) and \(C_2\) are the concentrations in compartment 1 and compartment 2, and \(k_0\), \(k_1\), and \(k_2\) are rate constants. This model can be implemented in Python as follows:
We may want to extend this model, for example, a first-order appearance term of \(C_1\) from a new compartment \(C_0\). The model then becomes:
\[\begin{align} \frac{\mathrm{d}C_0}{\mathrm{d}t} &= -k_3 C_0 \\ \frac{\mathrm{d}C_1}{\mathrm{d}t} &= -k_0 C_1 - k_1 C_1 + k_2 C_2 + k_3 C_0 \\ \frac{\mathrm{d}C_2}{\mathrm{d}t} &= k_1 C_1 - k_2 C_2 \end{align}\]
A way to extend the current model in Python, is to build a new function of the extended model, that calls the original model function. This is shown in the code below.
We can then use the odeint
function from the scipy.integrate
module to solve the ODEs, which is similar to the previous notebook.
Simulate the compartment model and the extended compartment model for the following parameters: - \(k_0 = 0.1\) - \(k_1 = 0.15\) - \(k_2 = 0.32\) - \(k_3 = 0.2\)
Use the initial conditions \(C_0(0) = 1\), \(C_1(0) = 1\), and \(C_2(0) = 0\). Plot the concentrations as a function of time.
In the lecture notes and in the lectures, delay compartments were introduced. Delay compartments are implemented in the same way as a normal equation. Consider the model:
\[ \begin{align} \frac{\mathrm{d}C_0}{\mathrm{d}t} &= -k_0 C_0 \\ \frac{\mathrm{d}C_{\text{end}}}{\mathrm{d}t} &= k_0 C_0 - k_{\text{end}} C_1 \end{align} \]
where \(C_0\) is the input compartment, and \(C_{\text{end}}\) is the output compartment. We can add a delay compartment \(C_1\), which is a first-order compartment with a rate constant \(k_1\). The model then becomes:
\[ \begin{align} \frac{\mathrm{d}C_0}{\mathrm{d}t} &= -k_0 C_0 \\ \frac{\mathrm{d}C_1}{\mathrm{d}t} &= k_0 C_0 - k_1 C_1 \\ \frac{\mathrm{d}C_{\text{end}}}{\mathrm{d}t} &= k_1 C_1 - k_{\text{end}} C_{\text{end}} \end{align} \]
We can implement this model in Python in the same way as the previous models. The code below shows how to implement this model.
Simulate the delay compartment model for the following parameters: - \(k_0 = 0.1\) - \(k_1 = 0.15\)
Use the initial conditions \(C_0(0) = 1\), \(C_1(0) = 0\), and \(C_{\text{end}}(0) = 0\). Plot the concentrations of \(C_{\text{end}}\) as a function of time. Compare the results with the model without the delay compartment.
Create a model with two, three and four delay compartments. Each delay compartment has the same rate constant \(k_1\). Simulate the model for the parameters given in exercise 2. Plot the concentrations of \(C_{\text{end}}\) as a function of time for each model in one plot. Explain the effect of the number of delay compartments on the output.
For example, when modeling multiple subsequent bolus injections at different times, we need to combine different simulations into one. This can be done by running the simulation for the first perturbation, and then using the final concentrations as initial conditions for the next simulation. The code below shows how to do this.
An example the following simple system can be:
\[\frac{\mathrm{d}x}{\mathrm{d}t} = -kx \]
Where we have an initial value of \(x = 2.0\) at \(t = 0\), and add another dose of \(2.0\) at \(t = 4\).
We can first implement the model:
We can then do the first simulation, up to \(t=4.0\)
We can then do the second simulation, taking the final timepoint of the first as initial condition and adding the second dose.
We can then combine both simulations and visualize the result.
Combine three simulations of the previous model with the following perturbations: - \(x = 2.0\) at \(t = 0\) - \(x = x + 2.0\) at \(t = 4\) - \(x = x + 2.0\) at \(t = 8\)