Skip to content
Find file
Fetching contributors…
Cannot retrieve contributors at this time
417 lines (306 sloc) 36.5 KB
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<title>eGFRD simulation</title>
<link rel="stylesheet" href="/css/reset.css" type="text/css"/>
<link rel="stylesheet" href="/css/style.css" type="text/css"/>
<link rel="stylesheet" href="/css/syntax.css" type="text/css"/>
<link rel="stylesheet" href="/css/menu.css" type="text/css"/>
<link rel="stylesheet" href="/css/footer.css" type="text/css"/>
<!--[if lt IE 9]>
<script src="/ie7/IE9.js"></script>
<![endif]-->
</head>
<body>
<div id="globalheader">
<!--googleoff: all-->
<ul id="globalnav">
<li id="gn-home"><a href="/">Home</a></li>
<li id="gn-algorithm"><a href="/algorithm">Algorithm</a></li>
<li id="gn-background"><a href="/background">Background</a></li>
<li id="gn-downloads"><a href="/downloads">Downloads</a></li>
<li id="gn-documentation"><a href="/documentation">Documentation</a></li>
<li id="gn-support"><a href="/support">Support</a></li>
<li class="gn-empty"><a></a></li>
</ul>
<!--googleon: all-->
<div id="lastbutton"> </div>
</div>
<h1>Running a simulation</h1>
<div id="container">
<ul>
<li>Go to the directory containing your simulation script.</li>
</ul>
<div class="highlight"><pre><code class="bash"><span class="nv">$ </span><span class="nb">cd</span> &lt;egfrd_directory&gt;/samples/example
</code></pre>
</div>
<ul>
<li>Run the simulation script writing output to stdout for each step.</li>
</ul>
<div class="highlight"><pre><code class="bash"><span class="nv">$ PYTHONPATH</span><span class="o">=</span>../../ python example.py
</code></pre>
</div>
<ul>
<li>Run the simulation writing output to stdout only if an error occurs.</li>
</ul>
<div class="highlight"><pre><code class="bash"><span class="nv">$ LOGLEVEL</span><span class="o">=</span>ERROR <span class="nv">PYTHONPATH</span><span class="o">=</span>../../ python -O example.py
</code></pre>
</div>
<p>Below you find a simulation
<a href="http://github.com/gfrd/gfrd/tree/develop/samples/example/example.py">script</a>,
with comments explaining each step. More example scripts can be found in the
<a href="http://github.com/gfrd/egfrd/tree/develop/samples">samples</a> directory of the
code.</p>
<div class="highlight"><pre><code class="python"><span class="c">#!/usr/bin/env python</span>
<span class="sd">&#39;&#39;&#39;</span>
<span class="sd">To run this script:</span>
<span class="sd">PYTHONPATH=../../ python example.py</span>
<span class="sd">&#39;&#39;&#39;</span>
<span class="kn">from</span> <span class="nn">egfrd</span> <span class="kn">import</span> <span class="o">*</span>
<span class="kn">from</span> <span class="nn">vtklogger</span> <span class="kn">import</span> <span class="n">VTKLogger</span>
<span class="sd">&#39;&#39;&#39;</span>
<span class="sd">The reaction network:</span>
<span class="sd">A &lt;-&gt; B</span>
<span class="sd">A + B &lt;-&gt; C</span>
<span class="sd">C -&gt; 0</span>
<span class="sd">&#39;&#39;&#39;</span>
<span class="k">def</span> <span class="nf">run</span><span class="p">(</span> <span class="p">):</span>
<span class="sd">&#39;&#39;&#39; Dimensions.</span>
<span class="sd"> &#39;&#39;&#39;</span>
<span class="n">L</span> <span class="o">=</span> <span class="mi">1e-6</span> <span class="c"># Size of simulation box.</span>
<span class="n">D</span> <span class="o">=</span> <span class="mi">1e-12</span> <span class="c"># Diffusion constant.</span>
<span class="n">radius</span> <span class="o">=</span> <span class="mi">2.5e-8</span> <span class="c"># Radius of particles.</span>
<span class="sd">&#39;&#39;&#39; Simulator.</span>
<span class="sd"> A cube of dimension (L x L x L) is created, with periodic boundary </span>
<span class="sd"> conditions.</span>
<span class="sd"> &#39;&#39;&#39;</span>
<span class="n">s</span> <span class="o">=</span> <span class="n">EGFRDSimulator</span><span class="p">(</span> <span class="n">worldSize</span><span class="o">=</span><span class="n">L</span> <span class="p">)</span>
<span class="sd">&#39;&#39;&#39; Adding surfaces. </span>
<span class="sd"> Define the surfaces to add to the simulator.</span>
<span class="sd"> Usage:</span>
<span class="sd"> s.addPlanarSurface( origin, vectorX, vectorY, Lx, Ly, Lz, name )</span>
<span class="sd"> s.addCylindricalSurface( origin, radius, orientation, size, name )</span>
<span class="sd"> See the docstrings. </span>
<span class="sd"> Note that surface are not allowed to touch or overlap. Surfaces should </span>
<span class="sd"> extend over the whole simulation box, so finite surfaces are not </span>
<span class="sd"> supported.</span>
<span class="sd"> Both methods return the surface they create. Assign it </span>
<span class="sd"> to some variable, so it can be used when adding species.</span>
<span class="sd"> &#39;&#39;&#39;</span>
<span class="n">WORLD</span> <span class="o">=</span> <span class="bp">True</span>
<span class="n">MEMBRANE1</span> <span class="o">=</span> <span class="bp">True</span>
<span class="n">MEMBRANE2</span> <span class="o">=</span> <span class="bp">True</span>
<span class="n">DNA</span> <span class="o">=</span> <span class="bp">True</span>
<span class="k">if</span> <span class="n">MEMBRANE1</span><span class="p">:</span>
<span class="n">m1</span> <span class="o">=</span> <span class="n">s</span><span class="o">.</span><span class="n">addPlanarSurface</span><span class="p">(</span><span class="n">origin</span><span class="o">=</span><span class="p">[</span> <span class="n">L</span> <span class="o">/</span> <span class="mi">2</span><span class="p">,</span> <span class="n">L</span> <span class="o">/</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">2</span> <span class="o">*</span> <span class="n">L</span> <span class="o">/</span> <span class="mi">10</span> <span class="p">],</span>
<span class="n">vectorX</span><span class="o">=</span><span class="p">[</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span> <span class="p">],</span>
<span class="n">vectorY</span><span class="o">=</span><span class="p">[</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">0</span> <span class="p">],</span>
<span class="n">Lx</span><span class="o">=</span><span class="p">(</span><span class="n">L</span> <span class="o">/</span> <span class="mi">2</span><span class="p">),</span>
<span class="n">Ly</span><span class="o">=</span><span class="p">(</span><span class="n">L</span> <span class="o">/</span> <span class="mi">2</span><span class="p">),</span>
<span class="n">Lz</span><span class="o">=</span><span class="n">radius</span><span class="p">,</span>
<span class="n">name</span><span class="o">=</span><span class="s">&#39;m1&#39;</span><span class="p">)</span>
<span class="k">if</span> <span class="n">MEMBRANE2</span><span class="p">:</span>
<span class="n">m2</span> <span class="o">=</span> <span class="n">s</span><span class="o">.</span><span class="n">addPlanarSurface</span><span class="p">(</span> <span class="n">origin</span><span class="o">=</span><span class="p">[</span> <span class="n">L</span> <span class="o">/</span> <span class="mi">2</span><span class="p">,</span> <span class="n">L</span> <span class="o">/</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">8</span> <span class="o">*</span> <span class="n">L</span> <span class="o">/</span> <span class="mi">10</span> <span class="p">],</span>
<span class="n">vectorX</span><span class="o">=</span><span class="p">[</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span> <span class="p">],</span>
<span class="n">vectorY</span><span class="o">=</span><span class="p">[</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">0</span> <span class="p">],</span>
<span class="n">Lx</span><span class="o">=</span><span class="p">(</span><span class="n">L</span> <span class="o">/</span> <span class="mi">2</span><span class="p">),</span>
<span class="n">Ly</span><span class="o">=</span><span class="p">(</span><span class="n">L</span> <span class="o">/</span> <span class="mi">2</span><span class="p">),</span>
<span class="n">Lz</span><span class="o">=</span><span class="n">radius</span><span class="p">,</span>
<span class="n">name</span><span class="o">=</span><span class="s">&#39;m2&#39;</span> <span class="p">)</span>
<span class="k">if</span> <span class="n">DNA</span><span class="p">:</span>
<span class="n">d</span> <span class="o">=</span> <span class="n">s</span><span class="o">.</span><span class="n">addCylindricalSurface</span><span class="p">(</span> <span class="n">origin</span><span class="o">=</span><span class="p">[</span> <span class="n">L</span> <span class="o">/</span> <span class="mi">2</span><span class="p">,</span> <span class="n">L</span> <span class="o">/</span> <span class="mi">2</span><span class="p">,</span> <span class="n">L</span> <span class="o">/</span> <span class="mi">2</span> <span class="p">],</span>
<span class="n">radius</span><span class="o">=</span><span class="n">radius</span><span class="p">,</span>
<span class="n">orientation</span><span class="o">=</span><span class="p">[</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">0</span> <span class="p">],</span>
<span class="n">size</span><span class="o">=</span><span class="p">(</span><span class="n">L</span> <span class="o">/</span> <span class="mi">2</span><span class="p">),</span>
<span class="n">name</span><span class="o">=</span><span class="s">&#39;d&#39;</span> <span class="p">)</span>
<span class="sd">&#39;&#39;&#39; Defining species.</span>
<span class="sd"> Define the type of particles that can exist.</span>
<span class="sd"> Usage:</span>
<span class="sd"> species = Species( &#39;name&#39;, D, radius )</span>
<span class="sd"> If no D or radius is specified, it has to be specified when adding it to a </span>
<span class="sd"> specific surface.</span>
<span class="sd"> &#39;&#39;&#39;</span>
<span class="n">A</span> <span class="o">=</span> <span class="n">Species</span><span class="p">(</span> <span class="s">&#39;A&#39;</span><span class="p">,</span> <span class="n">D</span><span class="p">,</span> <span class="n">radius</span> <span class="p">)</span>
<span class="n">B</span> <span class="o">=</span> <span class="n">Species</span><span class="p">(</span> <span class="s">&#39;B&#39;</span><span class="p">,</span> <span class="n">D</span><span class="p">,</span> <span class="n">radius</span> <span class="p">)</span>
<span class="n">C</span> <span class="o">=</span> <span class="n">Species</span><span class="p">(</span> <span class="s">&#39;C&#39;</span><span class="p">,</span> <span class="n">D</span><span class="p">,</span> <span class="n">radius</span> <span class="p">)</span>
<span class="sd">&#39;&#39;&#39; Adding species to 3D space.</span>
<span class="sd"> Usage:</span>
<span class="sd"> s.addSpecies( species )</span>
<span class="sd"> When adding a species to the system without explicitly assigning the </span>
<span class="sd"> surface it can live on, it is assumed to be in the &#39;world&#39;. The &#39;world&#39; is </span>
<span class="sd"> a 3D space, also referred to as the &#39;bulk&#39; or &#39;cytoplasm&#39;.</span>
<span class="sd"> &#39;&#39;&#39;</span>
<span class="k">if</span> <span class="n">WORLD</span><span class="p">:</span>
<span class="n">s</span><span class="o">.</span><span class="n">addSpecies</span><span class="p">(</span> <span class="n">A</span> <span class="p">)</span>
<span class="n">s</span><span class="o">.</span><span class="n">addSpecies</span><span class="p">(</span> <span class="n">B</span> <span class="p">)</span>
<span class="n">s</span><span class="o">.</span><span class="n">addSpecies</span><span class="p">(</span> <span class="n">C</span> <span class="p">)</span>
<span class="sd">&#39;&#39;&#39; Adding species to surfaces.</span>
<span class="sd"> Specify which species can exist on which surface.</span>
<span class="sd"> Usage:</span>
<span class="sd"> s.addSpecies( species, surface, D, radius )</span>
<span class="sd"> See the docstring.</span>
<span class="sd"> Per surface a different diffusion constant D and radius can be specified. </span>
<span class="sd"> By default the ones for the &#39;world&#39; are used. </span>
<span class="sd"> Note: if particles of species &#39;A&#39; should be able to exist in the world as </span>
<span class="sd"> well as on one of the previously added surfaces, then it should be added </span>
<span class="sd"> twice. Ones with and ones without an explicit surface argument.</span>
<span class="sd"> &#39;&#39;&#39;</span>
<span class="k">if</span> <span class="n">MEMBRANE1</span><span class="p">:</span>
<span class="n">s</span><span class="o">.</span><span class="n">addSpecies</span><span class="p">(</span> <span class="n">A</span><span class="p">,</span> <span class="n">m1</span> <span class="p">)</span>
<span class="n">s</span><span class="o">.</span><span class="n">addSpecies</span><span class="p">(</span> <span class="n">B</span><span class="p">,</span> <span class="n">m1</span> <span class="p">)</span>
<span class="n">s</span><span class="o">.</span><span class="n">addSpecies</span><span class="p">(</span> <span class="n">C</span><span class="p">,</span> <span class="n">m1</span> <span class="p">)</span>
<span class="k">if</span> <span class="n">MEMBRANE2</span><span class="p">:</span>
<span class="c"># No species can live on membrane 2.</span>
<span class="k">pass</span>
<span class="k">if</span> <span class="n">DNA</span><span class="p">:</span>
<span class="n">s</span><span class="o">.</span><span class="n">addSpecies</span><span class="p">(</span> <span class="n">A</span><span class="p">,</span> <span class="n">d</span> <span class="p">)</span>
<span class="n">s</span><span class="o">.</span><span class="n">addSpecies</span><span class="p">(</span> <span class="n">B</span><span class="p">,</span> <span class="n">d</span><span class="p">,</span> <span class="n">D</span> <span class="o">*</span> <span class="mi">2</span> <span class="p">)</span>
<span class="n">s</span><span class="o">.</span><span class="n">addSpecies</span><span class="p">(</span> <span class="n">C</span><span class="p">,</span> <span class="n">d</span><span class="p">,</span> <span class="n">D</span> <span class="o">*</span> <span class="mi">2</span><span class="p">,</span> <span class="n">radius</span> <span class="o">*</span> <span class="mi">2</span> <span class="p">)</span>
<span class="sd">&#39;&#39;&#39; Adding reactions in 3D.</span>
<span class="sd"> Usage:</span>
<span class="sd"> s.addReaction( [reactants], [products], rate )</span>
<span class="sd"> For now: a bimolecular reaction can only have 1 product species.</span>
<span class="sd"> Units for the rate of a bimolecular reaction:</span>
<span class="sd"> [kf] = meters^3 / (molecules * second)</span>
<span class="sd"> (Order of magnitude kf: 1e-18)</span>
<span class="sd"> &#39;&#39;&#39;</span>
<span class="n">sigma</span> <span class="o">=</span> <span class="mi">2</span> <span class="o">*</span> <span class="n">radius</span>
<span class="n">D_tot</span> <span class="o">=</span> <span class="n">D</span>
<span class="n">tau</span> <span class="o">=</span> <span class="n">sigma</span> <span class="o">*</span> <span class="n">sigma</span> <span class="o">/</span> <span class="n">D_tot</span>
<span class="c"># Bimolecular. </span>
<span class="n">kf_2</span> <span class="o">=</span> <span class="mi">100</span> <span class="o">*</span> <span class="n">sigma</span> <span class="o">*</span> <span class="n">D_tot</span>
<span class="n">kb_2</span> <span class="o">=</span> <span class="mi">0.1</span> <span class="o">/</span> <span class="n">tau</span>
<span class="c"># Unimolecular.</span>
<span class="n">kf_1</span> <span class="o">=</span> <span class="mi">0.1</span> <span class="o">/</span> <span class="n">tau</span>
<span class="n">kb_1</span> <span class="o">=</span> <span class="mi">0.1</span> <span class="o">/</span> <span class="n">tau</span>
<span class="k">if</span> <span class="n">WORLD</span><span class="p">:</span>
<span class="c"># A &lt;-&gt; B</span>
<span class="c"># A + B &lt;-&gt; C</span>
<span class="c"># C -&gt; 0</span>
<span class="n">s</span><span class="o">.</span><span class="n">addReaction</span><span class="p">(</span> <span class="p">[</span> <span class="n">A</span> <span class="p">],</span> <span class="p">[</span> <span class="n">B</span> <span class="p">],</span> <span class="n">kf_1</span> <span class="p">)</span>
<span class="n">s</span><span class="o">.</span><span class="n">addReaction</span><span class="p">(</span> <span class="p">[</span> <span class="n">B</span> <span class="p">],</span> <span class="p">[</span> <span class="n">A</span> <span class="p">],</span> <span class="n">kb_1</span> <span class="p">)</span>
<span class="n">s</span><span class="o">.</span><span class="n">addReaction</span><span class="p">(</span> <span class="p">[</span> <span class="n">A</span><span class="p">,</span> <span class="n">B</span> <span class="p">],</span> <span class="p">[</span> <span class="n">C</span> <span class="p">],</span> <span class="n">kf_2</span> <span class="p">)</span>
<span class="n">s</span><span class="o">.</span><span class="n">addReaction</span><span class="p">(</span> <span class="p">[</span> <span class="n">C</span> <span class="p">],</span> <span class="p">[</span> <span class="n">A</span><span class="p">,</span> <span class="n">B</span> <span class="p">],</span> <span class="n">kb_2</span> <span class="p">)</span>
<span class="n">s</span><span class="o">.</span><span class="n">addReaction</span><span class="p">(</span> <span class="p">[</span> <span class="n">C</span> <span class="p">],</span> <span class="p">[</span> <span class="p">],</span> <span class="n">kf_1</span> <span class="p">)</span>
<span class="sd">&#39;&#39;&#39; Adding reactions on surfaces.</span>
<span class="sd"> Usage:</span>
<span class="sd"> s.addReaction( [reactants], [products], rate )</span>
<span class="sd"> , where one reactant or product is a tuple: (species, surface).</span>
<span class="sd"> Combinations of species which do not appear together as reactants in any </span>
<span class="sd"> reaction are made repulsive by default on every surface.</span>
<span class="sd"> &#39;&#39;&#39;</span>
<span class="k">if</span> <span class="n">MEMBRANE1</span><span class="p">:</span>
<span class="c"># A &lt;-&gt; B</span>
<span class="c"># A + B &lt;-&gt; C</span>
<span class="c"># C -&gt; 0</span>
<span class="n">s</span><span class="o">.</span><span class="n">addReaction</span><span class="p">(</span> <span class="p">[</span> <span class="p">(</span><span class="n">A</span><span class="p">,</span> <span class="n">m1</span><span class="p">),</span> <span class="p">],</span> <span class="p">[</span> <span class="p">(</span><span class="n">B</span><span class="p">,</span> <span class="n">m1</span><span class="p">)</span> <span class="p">],</span> <span class="n">kf_1</span> <span class="p">)</span>
<span class="n">s</span><span class="o">.</span><span class="n">addReaction</span><span class="p">(</span> <span class="p">[</span> <span class="p">(</span><span class="n">B</span><span class="p">,</span> <span class="n">m1</span><span class="p">),</span> <span class="p">],</span> <span class="p">[</span> <span class="p">(</span><span class="n">A</span><span class="p">,</span> <span class="n">m1</span><span class="p">)</span> <span class="p">],</span> <span class="n">kb_1</span> <span class="p">)</span>
<span class="n">s</span><span class="o">.</span><span class="n">addReaction</span><span class="p">(</span> <span class="p">[</span> <span class="p">(</span><span class="n">A</span><span class="p">,</span> <span class="n">m1</span><span class="p">),</span> <span class="p">(</span><span class="n">B</span><span class="p">,</span> <span class="n">m1</span><span class="p">)</span> <span class="p">],</span> <span class="p">[</span> <span class="p">(</span><span class="n">C</span><span class="p">,</span> <span class="n">m1</span><span class="p">)</span> <span class="p">],</span> <span class="n">kf_2</span> <span class="p">)</span>
<span class="n">s</span><span class="o">.</span><span class="n">addReaction</span><span class="p">(</span> <span class="p">[</span> <span class="p">(</span><span class="n">C</span><span class="p">,</span> <span class="n">m1</span><span class="p">)</span> <span class="p">],</span> <span class="p">[</span> <span class="p">(</span><span class="n">A</span><span class="p">,</span> <span class="n">m1</span><span class="p">),</span> <span class="p">(</span><span class="n">B</span><span class="p">,</span> <span class="n">m1</span><span class="p">)</span> <span class="p">],</span> <span class="n">kb_2</span> <span class="p">)</span>
<span class="n">s</span><span class="o">.</span><span class="n">addReaction</span><span class="p">(</span> <span class="p">[</span> <span class="p">(</span><span class="n">C</span><span class="p">,</span> <span class="n">m1</span><span class="p">),</span> <span class="p">],</span> <span class="p">[</span> <span class="p">],</span> <span class="n">kf_1</span> <span class="p">)</span>
<span class="k">if</span> <span class="n">MEMBRANE2</span><span class="p">:</span>
<span class="c"># No particles can live on membrane2.</span>
<span class="k">pass</span>
<span class="k">if</span> <span class="n">DNA</span><span class="p">:</span>
<span class="c"># A &lt;-&gt; B</span>
<span class="c"># A + B &lt;-&gt; C</span>
<span class="c"># C -&gt; 0</span>
<span class="n">s</span><span class="o">.</span><span class="n">addReaction</span><span class="p">(</span> <span class="p">[</span> <span class="p">(</span><span class="n">A</span><span class="p">,</span> <span class="n">d</span><span class="p">),</span> <span class="p">],</span> <span class="p">[</span> <span class="p">(</span><span class="n">B</span><span class="p">,</span> <span class="n">d</span><span class="p">)</span> <span class="p">],</span> <span class="n">kf_1</span> <span class="p">)</span>
<span class="n">s</span><span class="o">.</span><span class="n">addReaction</span><span class="p">(</span> <span class="p">[</span> <span class="p">(</span><span class="n">B</span><span class="p">,</span> <span class="n">d</span><span class="p">),</span> <span class="p">],</span> <span class="p">[</span> <span class="p">(</span><span class="n">A</span><span class="p">,</span> <span class="n">d</span><span class="p">)</span> <span class="p">],</span> <span class="n">kb_1</span> <span class="p">)</span>
<span class="n">s</span><span class="o">.</span><span class="n">addReaction</span><span class="p">(</span> <span class="p">[</span> <span class="p">(</span><span class="n">A</span><span class="p">,</span> <span class="n">d</span><span class="p">),</span> <span class="p">(</span><span class="n">B</span><span class="p">,</span> <span class="n">d</span><span class="p">)</span> <span class="p">],</span> <span class="p">[</span> <span class="p">(</span><span class="n">C</span><span class="p">,</span> <span class="n">d</span><span class="p">)</span> <span class="p">],</span> <span class="n">kf_2</span> <span class="p">)</span>
<span class="n">s</span><span class="o">.</span><span class="n">addReaction</span><span class="p">(</span> <span class="p">[</span> <span class="p">(</span><span class="n">C</span><span class="p">,</span> <span class="n">d</span><span class="p">)</span> <span class="p">],</span> <span class="p">[</span> <span class="p">(</span><span class="n">A</span><span class="p">,</span> <span class="n">d</span><span class="p">),</span> <span class="p">(</span><span class="n">B</span><span class="p">,</span> <span class="n">d</span><span class="p">)</span> <span class="p">],</span> <span class="n">kb_2</span> <span class="p">)</span>
<span class="n">s</span><span class="o">.</span><span class="n">addReaction</span><span class="p">(</span> <span class="p">[</span> <span class="p">(</span><span class="n">C</span><span class="p">,</span> <span class="n">d</span><span class="p">),</span> <span class="p">],</span> <span class="p">[</span> <span class="p">],</span> <span class="n">kf_1</span> <span class="p">)</span>
<span class="sd">&#39;&#39;&#39; Surface binding reactions.</span>
<span class="sd"> Usage:</span>
<span class="sd"> s.addReaction( [reactant], [product], rate ) )</span>
<span class="sd"> , where product is a tuple: (species, surface).</span>
<span class="sd"> The reactant species for every surface binding reaction is always a </span>
<span class="sd"> species that can only exist in the &#39;world&#39;, so no surface has to be </span>
<span class="sd"> specified there.</span>
<span class="sd"> If a surface should be absorbive, specify (0, surface) as the product.</span>
<span class="sd"> When no surface binding reaction is defined for a combination of a species </span>
<span class="sd"> and a surface, they are made repulsive by default.</span>
<span class="sd"> &#39;&#39;&#39;</span>
<span class="c"># Molecule + surface.</span>
<span class="n">kon</span> <span class="o">=</span> <span class="n">kf_2</span>
<span class="k">if</span> <span class="n">MEMBRANE1</span> <span class="ow">and</span> <span class="n">WORLD</span><span class="p">:</span>
<span class="c"># Species C can bind to the membrane. The membrane is reflective, by </span>
<span class="c"># default, to species A and B.</span>
<span class="n">s</span><span class="o">.</span><span class="n">addReaction</span><span class="p">(</span> <span class="p">[</span> <span class="n">C</span> <span class="p">],</span> <span class="p">[</span> <span class="p">(</span><span class="n">C</span><span class="p">,</span> <span class="n">m1</span><span class="p">)</span> <span class="p">],</span> <span class="n">kon</span> <span class="p">)</span>
<span class="k">if</span> <span class="n">MEMBRANE2</span> <span class="ow">and</span> <span class="n">WORLD</span><span class="p">:</span>
<span class="c"># Membrane 2 absorbs all particles.</span>
<span class="n">s</span><span class="o">.</span><span class="n">addReaction</span><span class="p">(</span> <span class="p">[</span> <span class="n">A</span> <span class="p">],</span> <span class="p">[</span> <span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="n">m2</span><span class="p">)</span> <span class="p">],</span> <span class="n">kon</span> <span class="p">)</span>
<span class="n">s</span><span class="o">.</span><span class="n">addReaction</span><span class="p">(</span> <span class="p">[</span> <span class="n">B</span> <span class="p">],</span> <span class="p">[</span> <span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="n">m2</span><span class="p">)</span> <span class="p">],</span> <span class="n">kon</span> <span class="p">)</span>
<span class="n">s</span><span class="o">.</span><span class="n">addReaction</span><span class="p">(</span> <span class="p">[</span> <span class="n">C</span> <span class="p">],</span> <span class="p">[</span> <span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="n">m2</span><span class="p">)</span> <span class="p">],</span> <span class="n">kon</span> <span class="p">)</span>
<span class="k">pass</span>
<span class="k">if</span> <span class="n">DNA</span> <span class="ow">and</span> <span class="n">WORLD</span><span class="p">:</span>
<span class="c"># Species C can bind to the dna. The dna is reflective, by default, to </span>
<span class="c"># species A and B.</span>
<span class="n">s</span><span class="o">.</span><span class="n">addReaction</span><span class="p">(</span> <span class="p">[</span> <span class="n">C</span> <span class="p">],</span> <span class="p">[</span> <span class="p">(</span><span class="n">C</span><span class="p">,</span> <span class="n">d</span><span class="p">)</span> <span class="p">],</span> <span class="n">kon</span> <span class="p">)</span>
<span class="sd">&#39;&#39;&#39; Surface unbinding reactions.</span>
<span class="sd"> Usage:</span>
<span class="sd"> s.addReaction( [reactant], [product], k ) )</span>
<span class="sd"> , where reactant is a tuple: (species, surface).</span>
<span class="sd"> Unbinding is a Poissonian reaction, from a surface to the &#39;world&#39;.</span>
<span class="sd"> The product species for every surface binding reaction is always a </span>
<span class="sd"> species that can only exist in the &#39;world&#39;, so no surface has to be </span>
<span class="sd"> specified there.</span>
<span class="sd"> &#39;&#39;&#39;</span>
<span class="c"># Unimolecular.</span>
<span class="n">koff</span> <span class="o">=</span> <span class="n">kb_1</span>
<span class="k">if</span> <span class="n">MEMBRANE1</span> <span class="ow">and</span> <span class="n">WORLD</span><span class="p">:</span>
<span class="c"># Species C can unbind to the &#39;world&#39;.</span>
<span class="n">s</span><span class="o">.</span><span class="n">addReaction</span><span class="p">(</span> <span class="p">[</span> <span class="p">(</span><span class="n">C</span><span class="p">,</span> <span class="n">m1</span><span class="p">)</span> <span class="p">],</span> <span class="p">[</span> <span class="n">C</span> <span class="p">],</span> <span class="n">koff</span> <span class="p">)</span>
<span class="k">if</span> <span class="n">MEMBRANE2</span> <span class="ow">and</span> <span class="n">WORLD</span><span class="p">:</span>
<span class="c"># No particles can live on membrane2.</span>
<span class="k">pass</span>
<span class="k">if</span> <span class="n">DNA</span> <span class="ow">and</span> <span class="n">WORLD</span><span class="p">:</span>
<span class="c"># Species C can unbind to the &#39;world&#39;.</span>
<span class="n">s</span><span class="o">.</span><span class="n">addReaction</span><span class="p">(</span> <span class="p">[</span> <span class="p">(</span><span class="n">C</span><span class="p">,</span> <span class="n">d</span><span class="p">)</span> <span class="p">],</span> <span class="p">[</span> <span class="n">C</span> <span class="p">],</span> <span class="n">koff</span> <span class="p">)</span>
<span class="sd">&#39;&#39;&#39;</span>
<span class="sd"> Particles.</span>
<span class="sd"> &#39;&#39;&#39;</span>
<span class="k">if</span> <span class="n">WORLD</span><span class="p">:</span>
<span class="k">if</span> <span class="n">MEMBRANE1</span> <span class="ow">and</span> <span class="n">MEMBRANE2</span><span class="p">:</span>
<span class="c"># Add world particles inside the two planes.</span>
<span class="c"># Note that a CuboidalRegion is defined by 2 corners.</span>
<span class="n">box1</span> <span class="o">=</span> <span class="n">CuboidalRegion</span><span class="p">(</span> <span class="p">[</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">2</span> <span class="o">*</span> <span class="n">L</span> <span class="o">/</span> <span class="mi">10</span> <span class="p">],</span> <span class="p">[</span> <span class="n">L</span><span class="p">,</span> <span class="n">L</span><span class="p">,</span> <span class="mi">8</span> <span class="o">*</span> <span class="n">L</span> <span class="o">/</span> <span class="mi">10</span> <span class="p">]</span> <span class="p">)</span>
<span class="n">s</span><span class="o">.</span><span class="n">throwInParticles</span><span class="p">(</span> <span class="n">C</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="n">box1</span> <span class="p">)</span>
<span class="k">else</span><span class="p">:</span>
<span class="c"># Particles are added to world (3D) by default.</span>
<span class="n">s</span><span class="o">.</span><span class="n">throwInParticles</span><span class="p">(</span> <span class="n">C</span><span class="p">,</span> <span class="mi">2</span> <span class="p">)</span>
<span class="k">if</span> <span class="n">MEMBRANE1</span><span class="p">:</span> <span class="n">s</span><span class="o">.</span><span class="n">throwInParticles</span><span class="p">(</span> <span class="n">C</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="n">m1</span> <span class="p">)</span>
<span class="k">if</span> <span class="n">MEMBRANE2</span><span class="p">:</span> <span class="k">pass</span>
<span class="k">if</span> <span class="n">DNA</span><span class="p">:</span> <span class="n">s</span><span class="o">.</span><span class="n">throwInParticles</span><span class="p">(</span> <span class="n">C</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="n">d</span> <span class="p">)</span>
<span class="sd">&#39;&#39;&#39;</span>
<span class="sd"> Simulation.</span>
<span class="sd"> &#39;&#39;&#39;</span>
<span class="n">s</span><span class="o">.</span><span class="n">initialize</span><span class="p">()</span>
<span class="k">print</span> <span class="n">s</span><span class="o">.</span><span class="n">dumpReactions</span><span class="p">()</span>
<span class="c"># Write vtk files for last 100 steps only. Use VTK or Paraview to</span>
<span class="c"># visualize.</span>
<span class="n">vtklogger</span> <span class="o">=</span> <span class="n">VTKLogger</span><span class="p">(</span> <span class="n">s</span><span class="p">,</span> <span class="s">&#39;run&#39;</span><span class="p">,</span> <span class="mi">100</span> <span class="p">)</span>
<span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span> <span class="mi">200</span> <span class="p">):</span>
<span class="k">try</span><span class="p">:</span>
<span class="n">vtklogger</span><span class="o">.</span><span class="n">log</span><span class="p">()</span>
<span class="n">s</span><span class="o">.</span><span class="n">step</span><span class="p">()</span>
<span class="k">except</span> <span class="ne">RuntimeError</span><span class="p">,</span> <span class="n">message</span><span class="p">:</span>
<span class="k">print</span> <span class="n">message</span>
<span class="k">break</span>
<span class="n">vtklogger</span><span class="o">.</span><span class="n">stop</span><span class="p">()</span>
<span class="n">s</span><span class="o">.</span><span class="n">stop</span><span class="p">(</span> <span class="n">s</span><span class="o">.</span><span class="n">t</span> <span class="p">)</span>
<span class="k">if</span> <span class="n">__name__</span> <span class="o">==</span> <span class="s">&#39;__main__&#39;</span><span class="p">:</span>
<span class="n">run</span><span class="p">(</span> <span class="p">)</span>
</code></pre>
</div>
</div>
<div id="globalfooter">
<p>Copyright &copy; 2012 FOM institute AMOLF</p>
<ul class="piped">
<li><a href="/about">About</a></li>
<li><a href="/credits">Credits</a></li>
</ul>
</div>
</body>
</html>
Something went wrong with that request. Please try again.