-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathtutorial01.html
542 lines (507 loc) · 35.7 KB
/
tutorial01.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>1. Brief Tour of E-Cell4 Simulations — E-Cell4 latest documentation</title>
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto:300,400,500,700">
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto+Mono"><link rel="stylesheet" href="../_static/typlog.css?v=0.7.3" type="text/css" />
<link rel="stylesheet" href="../_static/theme.css?v=0.7.3" type="text/css" />
<link rel="index" title="Index" href="../genindex.html"/>
<link rel="search" title="Search" href="../search.html"/>
<link rel="top" title="E-Cell4 latest documentation" href="../index.html"/>
<link rel="up" title="<no title>" href="index.html"/>
<link rel="next" title="2. How to Build a Model" href="tutorial02.html"/>
<link rel="prev" title="<no title>" href="index.html"/>
<script>(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)})(window,document,'script','https://www.google-analytics.com/analytics.js','ga');ga('create', '');ga('send', 'pageview');</script>
<script type="text/javascript" id="documentation_options" data-url_root="../" src="../_static/documentation_options.js"></script>
<script src="../_static/jquery.js"></script>
<script src="../_static/underscore.js"></script>
<script src="../_static/doctools.js"></script>
<script src="../_static/language_data.js"></script>
<script crossorigin="anonymous" integrity="sha256-Ae2Vz/4ePdIu6ZyI/5ZGsYnb+m0JlOmKPjt6XZ9JJkA=" src="https://cdnjs.cloudflare.com/ajax/libs/require.js/2.3.4/require.min.js"></script>
<script async="async" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/latest.js?config=TeX-AMS-MML_HTMLorMML"></script>
<script type="text/x-mathjax-config">MathJax.Hub.Config({"tex2jax": {"inlineMath": [["$", "$"], ["\\(", "\\)"]], "processEscapes": true, "ignoreClass": "document", "processClass": "math|output_area"}})</script>
<meta property="og:type" content="website">
<meta property="og:site_name" content="E-Cell4">
<meta property="og:title" content="1. Brief Tour of E-Cell4 Simulations">
<meta property="og:description" content="A software platform for modeling, simulation and analysis of a cell">
<meta name="twitter:card" content="summary">
</head>
<body role="document" data-page="tutorials/tutorial01">
<header class="t-head">
<div class="t-head_menu"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><path d="M64 384h384v-42.666H64V384zm0-106.666h384v-42.667H64v42.667zM64 128v42.665h384V128H64z"/></svg></div>
<a class="t-head_logo" href="../index.html">E-Cell4
</a>
</header>
<aside class="t-sidebar">
<div class="t-sidebar_close">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><path d="M405 136.798L375.202 107 256 226.202 136.798 107 107 136.798 226.202 256 107 375.202 136.798 405 256 285.798 375.202 405 405 375.202 285.798 256z"/></svg>
</div>
<div class="inner">
<a class="logo" href="../index.html">
ecell4
</a><div class="logo_desc">A software platform for modeling, simulation and analysis of a cell</div><div class="globaltoc">
<ul>
<li><a class="reference internal" href="#">1. Brief Tour of E-Cell4 Simulations</a><ul>
<li><a class="reference internal" href="#1.1.-Quick-Demo">1.1. Quick Demo</a></li>
<li><a class="reference internal" href="#1.2.-Spatial-Simulation-and-Visualization">1.2. Spatial Simulation and Visualization</a></li>
</ul>
</li>
</ul>
</div>
<div id="searchbox">
<form class="search" action="../search.html" method="get">
<div class="input-group">
<input type="text" name="q" placeholder="Search" />
<button type="submit">Go</button>
</div>
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
</div>
</div>
</aside>
<div class="t-content">
<div class="t-body yue">
<style>
/* CSS for nbsphinx extension */
/* remove conflicting styling from Sphinx themes */
div.nbinput.container,
div.nbinput.container div.prompt,
div.nbinput.container div.input_area,
div.nbinput.container div[class*=highlight],
div.nbinput.container div[class*=highlight] pre,
div.nboutput.container,
div.nboutput.container div.prompt,
div.nboutput.container div.output_area,
div.nboutput.container div[class*=highlight],
div.nboutput.container div[class*=highlight] pre {
background: none;
border: none;
padding: 0 0;
margin: 0;
box-shadow: none;
}
/* avoid gaps between output lines */
div.nboutput.container div[class*=highlight] pre {
line-height: normal;
}
/* input/output containers */
div.nbinput.container,
div.nboutput.container {
display: -webkit-flex;
display: flex;
align-items: flex-start;
margin: 0;
width: 100%;
}
@media (max-width: 540px) {
div.nbinput.container,
div.nboutput.container {
flex-direction: column;
}
}
/* input container */
div.nbinput.container {
padding-top: 5px;
}
/* last container */
div.nblast.container {
padding-bottom: 5px;
}
/* input prompt */
div.nbinput.container div.prompt pre {
color: #307FC1;
}
/* output prompt */
div.nboutput.container div.prompt pre {
color: #BF5B3D;
}
/* all prompts */
div.nbinput.container div.prompt,
div.nboutput.container div.prompt {
width: 4.5ex;
padding-top: 5px;
position: relative;
user-select: none;
}
div.nbinput.container div.prompt > div,
div.nboutput.container div.prompt > div {
position: absolute;
right: 0;
margin-right: 0.3ex;
}
@media (max-width: 540px) {
div.nbinput.container div.prompt,
div.nboutput.container div.prompt {
width: unset;
text-align: left;
padding: 0.4em;
}
div.nboutput.container div.prompt.empty {
padding: 0;
}
div.nbinput.container div.prompt > div,
div.nboutput.container div.prompt > div {
position: unset;
}
}
/* disable scrollbars on prompts */
div.nbinput.container div.prompt pre,
div.nboutput.container div.prompt pre {
overflow: hidden;
}
/* input/output area */
div.nbinput.container div.input_area,
div.nboutput.container div.output_area {
-webkit-flex: 1;
flex: 1;
overflow: auto;
}
@media (max-width: 540px) {
div.nbinput.container div.input_area,
div.nboutput.container div.output_area {
width: 100%;
}
}
/* input area */
div.nbinput.container div.input_area {
border: 1px solid #e0e0e0;
border-radius: 2px;
background: #f5f5f5;
}
/* override MathJax center alignment in output cells */
div.nboutput.container div[class*=MathJax] {
text-align: left !important;
}
/* override sphinx.ext.imgmath center alignment in output cells */
div.nboutput.container div.math p {
text-align: left;
}
/* standard error */
div.nboutput.container div.output_area.stderr {
background: #fdd;
}
/* ANSI colors */
.ansi-black-fg { color: #3E424D; }
.ansi-black-bg { background-color: #3E424D; }
.ansi-black-intense-fg { color: #282C36; }
.ansi-black-intense-bg { background-color: #282C36; }
.ansi-red-fg { color: #E75C58; }
.ansi-red-bg { background-color: #E75C58; }
.ansi-red-intense-fg { color: #B22B31; }
.ansi-red-intense-bg { background-color: #B22B31; }
.ansi-green-fg { color: #00A250; }
.ansi-green-bg { background-color: #00A250; }
.ansi-green-intense-fg { color: #007427; }
.ansi-green-intense-bg { background-color: #007427; }
.ansi-yellow-fg { color: #DDB62B; }
.ansi-yellow-bg { background-color: #DDB62B; }
.ansi-yellow-intense-fg { color: #B27D12; }
.ansi-yellow-intense-bg { background-color: #B27D12; }
.ansi-blue-fg { color: #208FFB; }
.ansi-blue-bg { background-color: #208FFB; }
.ansi-blue-intense-fg { color: #0065CA; }
.ansi-blue-intense-bg { background-color: #0065CA; }
.ansi-magenta-fg { color: #D160C4; }
.ansi-magenta-bg { background-color: #D160C4; }
.ansi-magenta-intense-fg { color: #A03196; }
.ansi-magenta-intense-bg { background-color: #A03196; }
.ansi-cyan-fg { color: #60C6C8; }
.ansi-cyan-bg { background-color: #60C6C8; }
.ansi-cyan-intense-fg { color: #258F8F; }
.ansi-cyan-intense-bg { background-color: #258F8F; }
.ansi-white-fg { color: #C5C1B4; }
.ansi-white-bg { background-color: #C5C1B4; }
.ansi-white-intense-fg { color: #A1A6B2; }
.ansi-white-intense-bg { background-color: #A1A6B2; }
.ansi-default-inverse-fg { color: #FFFFFF; }
.ansi-default-inverse-bg { background-color: #000000; }
.ansi-bold { font-weight: bold; }
.ansi-underline { text-decoration: underline; }
div.nbinput.container div.input_area div[class*=highlight] > pre,
div.nboutput.container div.output_area div[class*=highlight] > pre,
div.nboutput.container div.output_area div[class*=highlight].math,
div.nboutput.container div.output_area.rendered_html,
div.nboutput.container div.output_area > div.output_javascript,
div.nboutput.container div.output_area:not(.rendered_html) > img{
padding: 5px;
}
/* fix copybtn overflow problem in chromium (needed for 'sphinx_copybutton') */
div.nbinput.container div.input_area > div[class^='highlight'],
div.nboutput.container div.output_area > div[class^='highlight']{
overflow-y: hidden;
}
/* hide copybtn icon on prompts (needed for 'sphinx_copybutton') */
.prompt a.copybtn {
display: none;
}
/* Some additional styling taken form the Jupyter notebook CSS */
div.rendered_html table {
border: none;
border-collapse: collapse;
border-spacing: 0;
color: black;
font-size: 12px;
table-layout: fixed;
}
div.rendered_html thead {
border-bottom: 1px solid black;
vertical-align: bottom;
}
div.rendered_html tr,
div.rendered_html th,
div.rendered_html td {
text-align: right;
vertical-align: middle;
padding: 0.5em 0.5em;
line-height: normal;
white-space: normal;
max-width: none;
border: none;
}
div.rendered_html th {
font-weight: bold;
}
div.rendered_html tbody tr:nth-child(odd) {
background: #f5f5f5;
}
div.rendered_html tbody tr:hover {
background: rgba(66, 165, 245, 0.2);
}
</style>
<script src='http://cdnjs.cloudflare.com/ajax/libs/require.js/2.1.10/require.min.js'></script>
<script>require=requirejs;</script><div class="admonition seealso">
<p class="admonition-title">See also</p>
<p>This page was generated from <a class="reference external" href="https://github.com/kaizu/ecell4_docs/blob/latest/en/tutorials/tutorial01.ipynb">tutorials/tutorial01.ipynb</a>.</p>
<p>Download the <a class="reference external" href="https://jupyter.org/">Jupyter Notebook</a> for this section: <a class="reference download internal" download="" href="../_downloads/84c8e8cd5722cb450d4d22151cb56e63/tutorial01.ipynb"><code class="xref download docutils literal notranslate"><span class="pre">tutorial01.ipynb</span></code></a>. <a class="reference external" href="https://nbviewer.jupyter.org/github/kaizu/ecell4_docs/blob/latest/en/tutorials/tutorial01.ipynb">View in nbviewer</a>.</p>
<a class="reference external image-reference" href="https://colab.research.google.com/github/kaizu/ecell4_docs/blob/latest/en/tutorials/tutorial01.ipynb"><img alt="https://colab.research.google.com/assets/colab-badge.svg" src="https://colab.research.google.com/assets/colab-badge.svg" /></a>
<a class="reference external image-reference" href="https://mybinder.org/v2/gh/kaizu/ecell4_docs/latest?filepath=en/tutorials/tutorial01.ipynb"><img alt="https://mybinder.org/badge_logo.svg" src="https://mybinder.org/badge_logo.svg" /></a>
</div>
<div class="section" id="1.-Brief-Tour-of-E-Cell4-Simulations">
<h1>1. Brief Tour of E-Cell4 Simulations<a class="headerlink" href="#1.-Brief-Tour-of-E-Cell4-Simulations" title="Permalink to this headline">¶</a></h1>
<p>First of all, you have to load the E-Cell4 library:</p>
<div class="nbinput nblast docutils container">
<div class="prompt highlight-none notranslate"><div class="highlight"><pre><span></span>[14]:
</pre></div>
</div>
<div class="input_area highlight-ipython3 notranslate"><div class="highlight"><pre>
<span></span><span class="o">%</span><span class="k">matplotlib</span> inline
</pre></div>
</div>
</div>
<div class="nbinput nblast docutils container">
<div class="prompt highlight-none notranslate"><div class="highlight"><pre><span></span>[15]:
</pre></div>
</div>
<div class="input_area highlight-ipython3 notranslate"><div class="highlight"><pre>
<span></span><span class="kn">from</span> <span class="nn">ecell4.prelude</span> <span class="kn">import</span> <span class="o">*</span>
</pre></div>
</div>
</div>
<div class="section" id="1.1.-Quick-Demo">
<h2>1.1. Quick Demo<a class="headerlink" href="#1.1.-Quick-Demo" title="Permalink to this headline">¶</a></h2>
<p>There are three fundamental components consisting of E-Cell System version 4, which are <code class="docutils literal notranslate"><span class="pre">Model</span></code>, <code class="docutils literal notranslate"><span class="pre">World</span></code>, and <code class="docutils literal notranslate"><span class="pre">Simulator</span></code>. These components describe concepts in simulation.</p>
<ul class="simple">
<li><p><code class="docutils literal notranslate"><span class="pre">Model</span></code> describes a problem to simulate as its name suggests.</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">World</span></code> describes a state, e.g. an initial state and a state at a time-point.</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">Simulator</span></code> describes a solver.</p></li>
</ul>
<p><code class="docutils literal notranslate"><span class="pre">Model</span></code> is independent from solvers. Every solver can share a single <code class="docutils literal notranslate"><span class="pre">Model</span></code> instance. Each solver alogrithm has a corresponding pair of <code class="docutils literal notranslate"><span class="pre">World</span></code> and <code class="docutils literal notranslate"><span class="pre">Simulator</span></code> (these pairs are capsulized into <code class="docutils literal notranslate"><span class="pre">Factory</span></code> class). <code class="docutils literal notranslate"><span class="pre">World</span></code> is not necessarily needed to be bound to <code class="docutils literal notranslate"><span class="pre">Model</span></code> and <code class="docutils literal notranslate"><span class="pre">Simulator</span></code>, but <code class="docutils literal notranslate"><span class="pre">Simulator</span></code> needs both <code class="docutils literal notranslate"><span class="pre">Model</span></code> and <code class="docutils literal notranslate"><span class="pre">World</span></code>.</p>
<p>Before running a simulation, you have to make a <code class="docutils literal notranslate"><span class="pre">Model</span></code>. E-Cell4 supports multiple ways to buld a <code class="docutils literal notranslate"><span class="pre">Model</span></code> (See <a class="reference external" href="tutorial02.html">2. How to Build a Model</a>). Here, we explain the simplest way using the <code class="docutils literal notranslate"><span class="pre">with</span></code> statement with <code class="docutils literal notranslate"><span class="pre">reaction_rules</span></code>:</p>
<div class="nbinput docutils container">
<div class="prompt highlight-none notranslate"><div class="highlight"><pre><span></span>[16]:
</pre></div>
</div>
<div class="input_area highlight-ipython3 notranslate"><div class="highlight"><pre>
<span></span><span class="k">with</span> <span class="n">reaction_rules</span><span class="p">():</span>
<span class="n">A</span> <span class="o">+</span> <span class="n">B</span> <span class="o">></span> <span class="n">C</span> <span class="o">|</span> <span class="mf">0.01</span> <span class="c1"># equivalent to create_binding_reaction_rule</span>
<span class="n">C</span> <span class="o">></span> <span class="n">A</span> <span class="o">+</span> <span class="n">B</span> <span class="o">|</span> <span class="mf">0.3</span> <span class="c1"># equivalent to create_unbinding_reaction_rule</span>
<span class="n">m1</span> <span class="o">=</span> <span class="n">get_model</span><span class="p">()</span>
<span class="n">show</span><span class="p">(</span><span class="n">m1</span><span class="p">)</span>
</pre></div>
</div>
</div>
<div class="nboutput nblast docutils container">
<div class="prompt empty docutils container">
</div>
<div class="output_area docutils container">
<div class="highlight"><pre>
A + B > C | 0.01
C > A + B | 0.3
</pre></div></div>
</div>
<p>Please remember to write parentheses <code class="docutils literal notranslate"><span class="pre">()</span></code> after <code class="docutils literal notranslate"><span class="pre">reaction_rules</span></code>. Here, a <code class="docutils literal notranslate"><span class="pre">Model</span></code> with two <code class="docutils literal notranslate"><span class="pre">ReactionRule</span></code>s named <code class="docutils literal notranslate"><span class="pre">m1</span></code> was built. Lines in the <code class="docutils literal notranslate"><span class="pre">with</span></code> block describe <code class="docutils literal notranslate"><span class="pre">ReactionRule</span></code>s, a binding and unbinding reaction respectively. A kinetic rate for the mass action reaction is defined after a separator <code class="docutils literal notranslate"><span class="pre">|</span></code>, i.e. <code class="docutils literal notranslate"><span class="pre">0.01</span></code> or <code class="docutils literal notranslate"><span class="pre">0.3</span></code>. In the form of ordinary differential equations, this model can be described as:</p>
<div class="math notranslate nohighlight">
\[[\mathrm{A}]'=[\mathrm{B}]'=-[\mathrm{C}]=-0.01[\mathrm{A}][\mathrm{B}]+0.3[\mathrm{C}]\]</div>
<p>For more compact description, <code class="docutils literal notranslate"><span class="pre">A</span> <span class="pre">+</span> <span class="pre">B</span> <span class="pre">==</span> <span class="pre">C</span> <span class="pre">|</span> <span class="pre">(0.01,</span> <span class="pre">0.3)</span></code> is also acceptable.</p>
<p>E-Cell4 has a simple interface for running simulation on a given model, called <code class="docutils literal notranslate"><span class="pre">run_simulation</span></code>. This enables for you to run simulations without instanciate <code class="docutils literal notranslate"><span class="pre">World</span></code> and <code class="docutils literal notranslate"><span class="pre">Simulator</span></code> by yourself. To solve this model, you have to give a volume, an initial value for each <code class="docutils literal notranslate"><span class="pre">Species</span></code> and duration of time:</p>
<div class="nbinput docutils container">
<div class="prompt highlight-none notranslate"><div class="highlight"><pre><span></span>[17]:
</pre></div>
</div>
<div class="input_area highlight-ipython3 notranslate"><div class="highlight"><pre>
<span></span><span class="n">run_simulation</span><span class="p">(</span><span class="mf">10.0</span><span class="p">,</span> <span class="n">model</span><span class="o">=</span><span class="n">m1</span><span class="p">,</span> <span class="n">y0</span><span class="o">=</span><span class="p">{</span><span class="s1">'A'</span><span class="p">:</span> <span class="mi">60</span><span class="p">,</span> <span class="s1">'B'</span><span class="p">:</span> <span class="mi">60</span><span class="p">},</span> <span class="n">volume</span><span class="o">=</span><span class="mf">1.0</span><span class="p">)</span>
</pre></div>
</div>
</div>
<div class="nboutput nblast docutils container">
<div class="prompt empty docutils container">
</div>
<div class="output_area docutils container">
<img alt="../_images/tutorials_tutorial01_7_0.png" src="../_images/tutorials_tutorial01_7_0.png" />
</div>
</div>
<p>To switch simulation algorithm, you only need to give the type of solver (<code class="docutils literal notranslate"><span class="pre">ode</span></code> is used as a default) as follows:</p>
<div class="nbinput docutils container">
<div class="prompt highlight-none notranslate"><div class="highlight"><pre><span></span>[18]:
</pre></div>
</div>
<div class="input_area highlight-ipython3 notranslate"><div class="highlight"><pre>
<span></span><span class="n">run_simulation</span><span class="p">(</span><span class="mf">10.0</span><span class="p">,</span> <span class="n">model</span><span class="o">=</span><span class="n">m1</span><span class="p">,</span> <span class="n">y0</span><span class="o">=</span><span class="p">{</span><span class="s1">'A'</span><span class="p">:</span> <span class="mi">60</span><span class="p">,</span> <span class="s1">'B'</span><span class="p">:</span> <span class="mi">60</span><span class="p">},</span> <span class="n">solver</span><span class="o">=</span><span class="s1">'gillespie'</span><span class="p">)</span>
</pre></div>
</div>
</div>
<div class="nboutput nblast docutils container">
<div class="prompt empty docutils container">
</div>
<div class="output_area docutils container">
<img alt="../_images/tutorials_tutorial01_9_0.png" src="../_images/tutorials_tutorial01_9_0.png" />
</div>
</div>
</div>
<div class="section" id="1.2.-Spatial-Simulation-and-Visualization">
<h2>1.2. Spatial Simulation and Visualization<a class="headerlink" href="#1.2.-Spatial-Simulation-and-Visualization" title="Permalink to this headline">¶</a></h2>
<p>E-Cell4 now supports multiple spatial simulation algorithms, <code class="docutils literal notranslate"><span class="pre">egfrd</span></code>, <code class="docutils literal notranslate"><span class="pre">spatiocyte</span></code> and <code class="docutils literal notranslate"><span class="pre">meso</span></code>. In addition to the model used in non-spatial solvers (<code class="docutils literal notranslate"><span class="pre">ode</span></code> and <code class="docutils literal notranslate"><span class="pre">gillespie</span></code>), these spatial solvers need extra information about each <code class="docutils literal notranslate"><span class="pre">Species</span></code>, i.e. a diffusion coefficient and radius.</p>
<p>The <code class="docutils literal notranslate"><span class="pre">with</span></code> statement with <code class="docutils literal notranslate"><span class="pre">species_attributes</span></code> is available to describe these properties:</p>
<div class="nbinput nblast docutils container">
<div class="prompt highlight-none notranslate"><div class="highlight"><pre><span></span>[19]:
</pre></div>
</div>
<div class="input_area highlight-ipython3 notranslate"><div class="highlight"><pre>
<span></span><span class="k">with</span> <span class="n">species_attributes</span><span class="p">():</span>
<span class="n">A</span> <span class="o">|</span> <span class="n">B</span> <span class="o">|</span> <span class="n">C</span> <span class="o">|</span> <span class="p">{</span><span class="s1">'radius'</span><span class="p">:</span> <span class="mf">0.005</span><span class="p">,</span> <span class="s1">'D'</span><span class="p">:</span> <span class="mi">1</span><span class="p">}</span> <span class="c1"># 'D' is for the diffusion coefficient</span>
<span class="k">with</span> <span class="n">reaction_rules</span><span class="p">():</span>
<span class="n">A</span> <span class="o">+</span> <span class="n">B</span> <span class="o">==</span> <span class="n">C</span> <span class="o">|</span> <span class="p">(</span><span class="mf">0.01</span><span class="p">,</span> <span class="mf">0.3</span><span class="p">)</span>
<span class="n">m2</span> <span class="o">=</span> <span class="n">get_model</span><span class="p">()</span>
</pre></div>
</div>
</div>
<p>Species attributes could be a string, boolean, integer or floating number.</p>
<p>Now you can run a spatial simulation in the same way as above (in the case of <code class="docutils literal notranslate"><span class="pre">egfrd</span></code>, the time it takes to finish the simulation will be longer):</p>
<div class="nbinput docutils container">
<div class="prompt highlight-none notranslate"><div class="highlight"><pre><span></span>[20]:
</pre></div>
</div>
<div class="input_area highlight-ipython3 notranslate"><div class="highlight"><pre>
<span></span><span class="n">run_simulation</span><span class="p">(</span><span class="mf">10.0</span><span class="p">,</span> <span class="n">model</span><span class="o">=</span><span class="n">m2</span><span class="p">,</span> <span class="n">y0</span><span class="o">=</span><span class="p">{</span><span class="s1">'A'</span><span class="p">:</span> <span class="mi">60</span><span class="p">,</span> <span class="s1">'B'</span><span class="p">:</span> <span class="mi">60</span><span class="p">},</span> <span class="n">solver</span><span class="o">=</span><span class="s1">'meso'</span><span class="p">)</span>
</pre></div>
</div>
</div>
<div class="nboutput nblast docutils container">
<div class="prompt empty docutils container">
</div>
<div class="output_area docutils container">
<img alt="../_images/tutorials_tutorial01_13_0.png" src="../_images/tutorials_tutorial01_13_0.png" />
</div>
</div>
<p>Structure (e.g. membrane, cytoplasm and nucleus) is only supported by <code class="docutils literal notranslate"><span class="pre">spatiocyte</span></code> and <code class="docutils literal notranslate"><span class="pre">meso</span></code> for now. For the simulation, <code class="docutils literal notranslate"><span class="pre">location</span></code> and <code class="docutils literal notranslate"><span class="pre">dimension</span></code> that each species belongs to must be specified in its attribute.</p>
<div class="nbinput nblast docutils container">
<div class="prompt highlight-none notranslate"><div class="highlight"><pre><span></span>[21]:
</pre></div>
</div>
<div class="input_area highlight-ipython3 notranslate"><div class="highlight"><pre>
<span></span><span class="k">with</span> <span class="n">species_attributes</span><span class="p">():</span>
<span class="n">A</span> <span class="o">|</span> <span class="p">{</span><span class="s1">'D'</span><span class="p">:</span> <span class="mi">1</span><span class="p">,</span> <span class="s1">'location'</span><span class="p">:</span> <span class="s1">'S'</span><span class="p">,</span> <span class="s1">'dimension'</span><span class="p">:</span> <span class="mi">3</span><span class="p">}</span> <span class="c1"># 'S' is a name of the structure</span>
<span class="n">S</span> <span class="o">|</span> <span class="p">{</span><span class="s1">'dimension'</span><span class="p">:</span> <span class="mi">3</span><span class="p">}</span>
<span class="n">m3</span> <span class="o">=</span> <span class="n">get_model</span><span class="p">()</span> <span class="c1"># with no reactions</span>
</pre></div>
</div>
</div>
<p>E-Cell4 supports primitive shapes as a structure like <code class="docutils literal notranslate"><span class="pre">Sphere</span></code>:</p>
<div class="nbinput nblast docutils container">
<div class="prompt highlight-none notranslate"><div class="highlight"><pre><span></span>[22]:
</pre></div>
</div>
<div class="input_area highlight-ipython3 notranslate"><div class="highlight"><pre>
<span></span><span class="n">sphere</span> <span class="o">=</span> <span class="n">Sphere</span><span class="p">(</span><span class="n">Real3</span><span class="p">(</span><span class="mf">0.5</span><span class="p">,</span> <span class="mf">0.5</span><span class="p">,</span> <span class="mf">0.5</span><span class="p">),</span> <span class="mf">0.48</span><span class="p">)</span> <span class="c1"># a center position and radius</span>
</pre></div>
</div>
</div>
<p>E-Cell4 provides various kinds of <code class="docutils literal notranslate"><span class="pre">Observer</span></code>s which log the state during a simulation. In the following two observers are declared to record the position of the molecule. <code class="docutils literal notranslate"><span class="pre">FixedIntervalTrajectoryObserver</span></code> logs a trajectory of a molecule, and <code class="docutils literal notranslate"><span class="pre">FixedIntervalHDF5Observer</span></code> saves <code class="docutils literal notranslate"><span class="pre">World</span></code> to a HDF5 file at the given time interval:</p>
<div class="nbinput nblast docutils container">
<div class="prompt highlight-none notranslate"><div class="highlight"><pre><span></span>[23]:
</pre></div>
</div>
<div class="input_area highlight-ipython3 notranslate"><div class="highlight"><pre>
<span></span><span class="n">obs1</span> <span class="o">=</span> <span class="n">FixedIntervalTrajectoryObserver</span><span class="p">(</span><span class="mf">1e-3</span><span class="p">)</span>
<span class="n">obs2</span> <span class="o">=</span> <span class="n">FixedIntervalHDF5Observer</span><span class="p">(</span><span class="mf">0.1</span><span class="p">,</span> <span class="s1">'test</span><span class="si">%02d</span><span class="s1">.h5'</span><span class="p">)</span>
</pre></div>
</div>
</div>
<p><code class="docutils literal notranslate"><span class="pre">run_simulation</span></code> can accept structures and observers as arguments <code class="docutils literal notranslate"><span class="pre">structure</span></code> and <code class="docutils literal notranslate"><span class="pre">observers</span></code> (see also <code class="docutils literal notranslate"><span class="pre">help(run_simulation)</span></code>):</p>
<div class="nbinput nblast docutils container">
<div class="prompt highlight-none notranslate"><div class="highlight"><pre><span></span>[24]:
</pre></div>
</div>
<div class="input_area highlight-ipython3 notranslate"><div class="highlight"><pre>
<span></span><span class="n">_</span> <span class="o">=</span> <span class="n">run_simulation</span><span class="p">(</span><span class="mf">1.0</span><span class="p">,</span> <span class="n">model</span><span class="o">=</span><span class="n">m3</span><span class="p">,</span> <span class="n">y0</span><span class="o">=</span><span class="p">{</span><span class="s1">'A'</span><span class="p">:</span> <span class="mi">60</span><span class="p">},</span> <span class="n">structures</span><span class="o">=</span><span class="p">{</span><span class="s1">'S'</span><span class="p">:</span> <span class="n">sphere</span><span class="p">},</span> <span class="n">solver</span><span class="o">=</span><span class="s1">'spatiocyte'</span><span class="p">,</span> <span class="n">observers</span><span class="o">=</span><span class="p">(</span><span class="n">obs1</span><span class="p">,</span> <span class="n">obs2</span><span class="p">))</span>
</pre></div>
</div>
</div>
<p>E-Cell4 has a function to visualize the world which is also capable of interactive visualization named <code class="docutils literal notranslate"><span class="pre">plotting.plot_world</span></code>. <code class="docutils literal notranslate"><span class="pre">plotting.plot_world</span></code> plots positions of molecules in 3D. In addition, by using <code class="docutils literal notranslate"><span class="pre">load_world</span></code>, you can easily restore the state of <code class="docutils literal notranslate"><span class="pre">World</span></code> from a HDF5 file:</p>
<div class="nbinput docutils container">
<div class="prompt highlight-none notranslate"><div class="highlight"><pre><span></span>[25]:
</pre></div>
</div>
<div class="input_area highlight-ipython3 notranslate"><div class="highlight"><pre>
<span></span><span class="n">plotting</span><span class="o">.</span><span class="n">plot_world</span><span class="p">(</span><span class="n">load_world</span><span class="p">(</span><span class="s1">'test00.h5'</span><span class="p">),</span> <span class="n">species_list</span><span class="o">=</span><span class="p">[</span><span class="s1">'A'</span><span class="p">])</span>
</pre></div>
</div>
</div>
<div class="nboutput nblast docutils container">
<div class="prompt empty docutils container">
</div>
<div class="output_area docutils container">
<img alt="../_images/tutorials_tutorial01_23_0.png" src="../_images/tutorials_tutorial01_23_0.png" />
</div>
</div>
<p>Also, for <code class="docutils literal notranslate"><span class="pre">FixedIntervalTrajectoryObserver</span></code>,<code class="docutils literal notranslate"><span class="pre">viz.plot_trajectory</span></code> generates a plot of the trajectory. (Again, it is possible to generate interactive plots.):</p>
<div class="nbinput docutils container">
<div class="prompt highlight-none notranslate"><div class="highlight"><pre><span></span>[26]:
</pre></div>
</div>
<div class="input_area highlight-ipython3 notranslate"><div class="highlight"><pre>
<span></span><span class="n">plotting</span><span class="o">.</span><span class="n">plot_trajectory</span><span class="p">(</span><span class="n">obs1</span><span class="p">)</span>
</pre></div>
</div>
</div>
<div class="nboutput nblast docutils container">
<div class="prompt empty docutils container">
</div>
<div class="output_area docutils container">
<img alt="../_images/tutorials_tutorial01_25_0.png" src="../_images/tutorials_tutorial01_25_0.png" />
</div>
</div>
<p>For more details, see <a class="reference external" href="tutorial05.html">5. How to Log and Visualize Simulations</a>.</p>
</div>
</div>
<div class="t-pagination clearfix">
<span>
← <a href="index.html" title="<no title>"><no title></a>
</span>
<span style="float:right">
<a href="tutorial02.html" title="2. How to Build a Model">2. How to Build a Model</a> →
</span>
</div>
</div><footer class="t-foot">
© Copyright 2015-, E-Cell project.
<br>
A <a href="https://typlog.com/">typlog</a> <a href="https://github.com/typlog/sphinx-typlog-theme">sphinx theme</a>,
designed by <a href="https://lepture.com/">Hsiaoming Yang</a>.
</footer>
</div>
<script>$(function(){$(".t-head_menu").on("click",function(){$("body").addClass("_expand")});$(".t-body").on("click",function(){$("body").removeClass("_expand")});$(".t-sidebar_close").on("click",function(){$("body").removeClass("_expand")});$("a.footnote-reference").on("click",function(e){e.preventDefault();var id=$(this).attr("href");var html=$(id).find("td.label + td").html();var w=Math.max(document.documentElement.clientWidth,window.innerWidth||0);var style="top:"+e.pageY+"px;";if(w>560){style+="width:480px;";if(e.pageX>240&&e.pageX+240<w){style+="left:"+(e.pageX-240)+"px;"}else if(e.pageX<=240){style+="left:20px;"}else{style+="right:20px;"}}showFootnote(html,style)});function showFootnote(html,style){var CONTENT_ID="typlog-footnote-content";var content=document.getElementById(CONTENT_ID);if(!content){content=document.createElement("div");content.id=CONTENT_ID;$(".t-body").append(content)}var MASK_ID="typlog-footnote-mask";var mask=document.getElementById(MASK_ID);if(!mask){mask=document.createElement("div");mask.id=MASK_ID;document.body.appendChild(mask);mask.addEventListener("click",function(){content.className="";mask.className=""})}content.innerHTML=html;content.setAttribute("style",style);content.className="_active";mask.className="_active"}function fetchGitHubRepo(repo){var url="https://api.github.com/repos/"+repo;$.getJSON(url,function(data){var counts=[+new Date,data.stargazers_count,data.forks_count];localStorage.setItem("gh:"+repo,JSON.stringify(counts));updateGitHubStats(counts[1],counts[2])})}function updateGitHubStats(stars,forks){$(".github_stars strong").text(stars);$(".github_forks strong").text(forks)}function initGitHub(url){if(!url){return}var repo=url.replace("https://github.com/","");var cache=localStorage.getItem("gh:"+repo);if(cache){try{var counts=JSON.parse(cache);updateGitHubStats(counts[1],counts[2]);var delta=new Date-counts[0];if(delta<0||delta>9e5){fetchGitHubRepo(repo)}}catch(error){fetchGitHubRepo(repo)}}else{fetchGitHubRepo(repo)}}initGitHub($(".github").attr("href"))});</script>
</body>
</html>