Within SciPy, odeint is used to integrate systems of (first-order) ordinary differential equations. In IPython, we must first import the command:
from scipy.integrate import odeint
We can then use, for example,
y= odeint(model, initial_values, t)
to simulate a model of k variables or chemical species. The model is specifed by the function model, which returns a list where each item in the list is the time-derivative of one of the variables. This function must be a function of y and of t in that order:
def model(y, t):
For example, to simulate the inactivation of a protein from its activate state Aa to its inactive state Ai, we would use:
import numpy as np
def model(y,t):
dydt= np.empty(len(y))
dydt[0]= -k*y[0] # rate equation for Aa
dydt[1]= k*y[0] # rate equation for Ai
return dydt
The initial values of the variables to be simulated are specified in the list initial_values (and would be the initial numbers of Aa and Ai in our example), and the time points for which values of the variables should be returned are given in the array t. For example,
t= np.arange(0, 1000, 10)
The SciPy function odeint returns a matrix which has k columns, one for each of the k variables, and a row for each time point specified in t.
If you wish to define the model function to depend on variables other than y and t, then these variables should be passed from odeint in a tuple using the args= option. Typically, these variables would be parameters for the model, such as k in the inactivation example above. If the model function has, for example, two additional parameters, such as
def model(y, t, a, b):
where a and b are the additional parameters, then we call odeint with
parameters= (0.1, 0.001)
y= odeint(model, init, t, args= parameters)
or
y= odeint(model, init, t, args= (0.1, 0.001))
more succinctly. Specifying just one parameter requiresy= odeint(model, init, t, args= (0.1,))
with a trailing comma to denote a tuple. Note that these parameters must be specified after t in the definition of the model function.
In this example, we will draw the nullclines and direction arrows, find the steady-states, and give a sample trajectory for a two-variable model of a genetic switch. We will consider positive autoregulation and the variables are protein, $P$, and mRNA, $M$.
The differential equations are
$${dP}/{dt} = M - d_P P$$and
$${dM}/{dt} = v + u P^4/{K^4 + P^4} - d_M M$$with basal transcription, $v$, and positive feedback of strength determined by $u$.
The script to generate the figure is: