# StochPy Basics¶

In [8]:
"""
Written by TR Maarleveld, Amsterdam, The Netherlands
E-mail: [email protected]/* <![CDATA[ */!function(t,e,r,n,c,a,p){try{t=document.currentScript||function(){for(t=document.getElementsByTagName('script'),e=t.length;e--;)if(t[e].getAttribute('data-cfhash'))return t[e]}();if(t&&(c=t.previousSibling)){p=t.parentNode;if(a=c.getAttribute('data-cfemail')){for(e='',r='0x'+a.substr(0,2)|0,n=2;a.length-n;n+=2)e+='%'+('0'+('0x'+a.substr(n,2)^r).toString(16)).slice(-2);p.replaceChild(document.createTextNode(decodeURIComponent(e)),c)}p.removeChild(t)}}catch(u){}}()/* ]]> */
Last Change: August 10, 2015
"""

import stochpy
smod = stochpy.SSA()
# required for iPython Notebook inline plotting
%matplotlib inline


### Do your first Stochastic simulation¶

We start by doing a stochastic simulation with the default StochPy settings. This means we start by simulating the Immigration Death model with the direct method for 1000 time steps.
In [9]:
smod.DoStochSim()
smod.PlotSpeciesTimeSeries()


### Modify parameters¶

StochPy allows interactive modification of model parameters, which we illustrate here. It is of course also possible to modify the model file and reload the model.
In [10]:
smod.ChangeInitialSpeciesCopyNumbers('mRNA',100)
smod.DoStochSim()
smod.PlotSpeciesTimeSeries()

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-10-74460e643266> in <module>()
----> 1 smod.ChangeInitialSpeciesCopyNumbers('mRNA',100)
2 smod.DoStochSim()
3 smod.PlotSpeciesTimeSeries()

AttributeError: SSA instance has no attribute 'ChangeInitialSpeciesCopyNumbers'
In [*]:
smod.ChangeParameter('Ksyn',10)
smod.ChangeParameter('Kdeg',0.1)
smod.DoStochSim()
smod.PlotSpeciesTimeSeries()

Info: 1 trajectory is generated
simulation done!
Info: Number of time steps 1000 End time 54.9530559957
Info: Simulation time 0.101769924164


### Select a different algorithm and model¶

StochPy provides many different stochastic simulation algorithms which we can divide in the following categories: 1) exact SSAs 2) inexact SSA 3) exact SSAs with delay 4) single molecule methods The exact SSAs are most used, but suffer typically from extensive running times. Inexaxt SSAs (i.e. tau-leaping) can be an outcome when exact SSAs are too slow for the job. We illustrate this here for the "DecayingDimerizing" model. The simulation with an exact solver is about 50 times slower. Remember that using tau-leaping methods result in loss of information (e.g. waiting times cannot be calculated). Exact SSAs with delay and single molecule methods are discussed in a different iPython notebook
In [11]:
smod.Model('DecayingDimerizing.psc')
smod.DoStochSim(method='tauleaping',end=50,mode='time')
smod.PlotSpeciesTimeSeries()

In [17]:


In [ ]: