Commit b5b624bc authored by Ana Bulovic's avatar Ana Bulovic
Browse files

Few more examples (phase plot, ratios of species)

parent 481c6c63
%% Cell type:markdown id: tags:
# A slightly more complicated example: Lotka-Volterra System
Implement the Lotka-Voltera reactions we already know (at least since Tuesday) in antimony
$$ \begin{align}
r1:& \;\; X \rightarrow 2 X \\
r2:& \;\; X + Y \rightarrow 2 Y \\
r3:& \;\; Y \rightarrow \varnothing
\end{align} $$
Assume that all reactions follow mass-action kinetics with parameters
$$ \begin{align}
k_1 & = 0.1~s^{-1}\\
k_2 & = 0.01~\# / s\\
k_3 & = 0.2~s^{-1}.
\end{align} $$
The initial conditions are : $X(0) = 20,~Y(0) = 5$.
**Excercise:**
1. **Use antimony to write the model structure**
2. **Simulate the model for 100 seconds**
3. **Plot the results as: a) Timecourses and b) Phaseplot**
4. **Simulate the model for a short time (~0.1s) for a range of different initial conditions (vary both X and Y from 0 to 50). Plot all of these short timecourses as a phaseplot and see how the behavior of the system changes depending on the initial values. Over that you can plot a couple of longer trajectories (100s). You should get something similar (but don't identical, don't worry) to [this](https://scipy-cookbook.readthedocs.io/_downloads/rabbits_and_foxes_2v3.png).**
**For the faster Zerglings in the control group:**
* **With the phaseplot you can scan the initial conditions to see if you find a limitcycle. Do you?**
%% Cell type:code id: tags:
``` python
# Import packages
import tellurium as te
import matplotlib.pyplot as plt
import numpy as np
%matplotlib inline
lotka_volterra = """
# Reactions or ODEs
# Species (and Initial values)
# Parameters
"""
# Load the model
# Simulate it (here you choose what to plot)
# Plot and annotate the results (include axis descriptions)
# For the fast coders: Include here a parameter scan
# Comment: Later you can do this in a better and prettier way in matplotlib (Lecture on Friday)
```
%% Cell type:markdown id: tags:
# Lotka-Volterra ... Storymode
Now, obviously this system is not very close to reality. To see this, you can check what happens if you change the integrator to stochastic simulations with ```rr.integrator='gillespie'```.<sup>1</sup> Soooo, let's make it even more magical! For this, we enter **STORY MODE**!!1!<sup>2</sup>
Here is the setting:
Our protagonists (the beautiful sheep of Billy the Squid) are living on a sunny, huuuuge farm.<sup>3</sup> This farm would be very safe and secure, if it wasn't for the big baaaaad wolves in the dark and equally huuuuge woods. They regularly sneak on the farm, wearing self-knitted sheep disguises. In this form they can eat as much sheep as they want on the farm and procreate. Of course, wolves die in all places, since they are not nearly as divine and immortal as the holy white sheep. They can only disappear into wolf stomachs but otherwise will live on forever. Unfortunately, they are quite gullible and stupid and thus get lost in the woods just as often ... a good day for the knitting wolves who then can also procreate.
This story goes on forever and ever and ever ...... and ever after?
**Excercise:**
1. **Find your own version (aka. parametrization) of the story and bring it to paper in an antimony model**
2. **Tell (aka. simulate) the story for an appropriate time frame to tell (aka. plot) it until the 'happily ever after' (or NOT?)**
3. **Introduce Billy the Squid to the story who is cleansing the farm every day at 10am from dressed up wolves**
4. **Do whatever you want with the story, aka. make it your own! Aliens experimenting to create killer sheep that eat wolves? No problemo. Introducing an overcrowding sheep heaven and wolf hell? Easy. Just ... mind the time or continue at home. ;D**
3. **Compute the percentage of lost sheep from the total sheep and plot it as a function of time.**
4. **Introduce Billy the Squid to the story who is cleansing the farm every day at 10am from dressed up wolves**
5. **Do whatever you want with the story, aka. make it your own! Aliens experimenting to create killer sheep that eat wolves? No problemo. Introducing an overcrowding sheep heaven and wolf hell? Easy. Just ... mind the time or continue at home. ;D**
<div class="paragraph"><p>&#160;<br></p></div>
<sup>1</sup> Note that this is only possible if you used reactions to implement the model in antimony.
<sup>2</sup> If you don't like story modes, skip this part and read on below the next cell.
<sup>3</sup> The term 'huuuuge' stands for 100 acres of land.
%% Cell type:code id: tags:
``` python
lotka_volterra = """
# Compartments
# Reactions or ODEs
# Species (and Initial values)
# Parameters
"""
# Load the model
# Simulate it (here you choose what to plot)
# Plot and annotate the results (include axis descriptions)
```
%% Cell type:markdown id: tags:
For the ones who don't like tales:
**Excercise:**
1. **Write an antimony model for an extended Lotka-Volterra equation system:**
* Inlcude two compartments
* Each compartment should comprise one Lotka-Volterra system (this means you will have to double your species and reactions!)
* Define exchange reactions for both X and Y between the two compartments
<div class="paragraph"><p>&#160;<br></p></div>
2. **Simulate and plot it** ... boring, I know.
%% Cell type:code id: tags:
``` python
```
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment