y_nelson 2.0.7 → 2.0.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -65,7 +65,7 @@
|
|
65
65
|
\begin_body
|
66
66
|
|
67
67
|
\begin_layout Title
|
68
|
-
Hands-on Guide to
|
68
|
+
Hands-on Guide to YNelson
|
69
69
|
\end_layout
|
70
70
|
|
71
71
|
\begin_layout Part*
|
@@ -76,24 +76,43 @@ Introduction
|
|
76
76
|
This document is a hands-on guide to
|
77
77
|
\family typewriter
|
78
78
|
\color blue
|
79
|
-
|
79
|
+
YNelson
|
80
80
|
\family default
|
81
81
|
\color inherit
|
82
82
|
,
|
83
83
|
\emph on
|
84
84
|
\color green
|
85
|
-
|
85
|
+
Nelson nets
|
86
86
|
\emph default
|
87
87
|
\color inherit
|
88
|
-
and
|
88
|
+
and, partially,
|
89
89
|
\color red
|
90
90
|
Ruby
|
91
91
|
\color inherit
|
92
|
-
.
|
92
|
+
language.
|
93
93
|
It is not assumed that the reader is familiar with any of these, though
|
94
|
-
|
94
|
+
familiarity with Ruby syntax would be an advantage.
|
95
|
+
If you have never heard about Nelson nets, do not wonder: it is a semi-novel
|
96
|
+
concept based on
|
97
|
+
\emph on
|
98
|
+
\color green
|
99
|
+
Petri nets
|
100
|
+
\emph default
|
101
|
+
\color inherit
|
102
|
+
crossed with Ted Nelson's
|
103
|
+
\emph on
|
104
|
+
\color green
|
105
|
+
ZZ structures
|
106
|
+
\emph default
|
107
|
+
\color inherit
|
108
|
+
.
|
95
109
|
If you follow this guide closely, you will receive a concise and efficient
|
96
|
-
introduction to each of these three
|
110
|
+
introduction to each of these three (remark:
|
111
|
+
\emph on
|
112
|
+
only the Petri net aspect is covered in this version of this guide.
|
113
|
+
ZZ structure aspect will be covered in the future versions of this manual)
|
114
|
+
\emph default
|
115
|
+
.
|
97
116
|
Newly introduced
|
98
117
|
\color red
|
99
118
|
Ruby keywords and terms
|
@@ -104,7 +123,7 @@ Petri net terms
|
|
104
123
|
\color inherit
|
105
124
|
in green, and
|
106
125
|
\color blue
|
107
|
-
|
126
|
+
YNelson keywords and terms
|
108
127
|
\color inherit
|
109
128
|
in blue throughout this document.
|
110
129
|
\end_layout
|
@@ -113,7 +132,7 @@ YPetri keywords and terms
|
|
113
132
|
|
114
133
|
\family typewriter
|
115
134
|
\color blue
|
116
|
-
|
135
|
+
YNelson
|
117
136
|
\family default
|
118
137
|
\color inherit
|
119
138
|
is a domain model and a simulator of
|
@@ -126,7 +145,18 @@ functional
|
|
126
145
|
Petri nets
|
127
146
|
\emph default
|
128
147
|
\color inherit
|
129
|
-
|
148
|
+
living in the
|
149
|
+
\emph on
|
150
|
+
\color green
|
151
|
+
ZZ space
|
152
|
+
\emph default
|
153
|
+
\color inherit
|
154
|
+
.
|
155
|
+
The Petri net flavor used in
|
156
|
+
\family typewriter
|
157
|
+
YNelson
|
158
|
+
\family default
|
159
|
+
is similar, but not identical with
|
130
160
|
\emph on
|
131
161
|
\color green
|
132
162
|
hybrid functional Petri nets
|
@@ -152,7 +182,7 @@ key "Bos2008mbs"
|
|
152
182
|
.
|
153
183
|
|
154
184
|
\family typewriter
|
155
|
-
|
185
|
+
YNelson
|
156
186
|
\family default
|
157
187
|
is implemented in
|
158
188
|
\emph on
|
@@ -161,21 +191,51 @@ Ruby programming language
|
|
161
191
|
\emph default
|
162
192
|
\color inherit
|
163
193
|
.
|
164
|
-
It
|
194
|
+
It is publicly available as
|
165
195
|
\emph on
|
166
196
|
\color blue
|
167
|
-
|
197
|
+
|
198
|
+
\begin_inset CommandInset href
|
199
|
+
LatexCommand href
|
200
|
+
name "y_nelson gem"
|
201
|
+
target "https://rubygems.org/gems/y_nelson"
|
202
|
+
|
203
|
+
\end_inset
|
204
|
+
|
205
|
+
|
206
|
+
\emph default
|
207
|
+
\color inherit
|
208
|
+
(
|
209
|
+
\emph on
|
210
|
+
\color red
|
211
|
+
gem
|
168
212
|
\emph default
|
169
213
|
\color inherit
|
170
|
-
|
214
|
+
= Ruby library).
|
171
215
|
|
172
216
|
\family typewriter
|
173
|
-
|
217
|
+
YNelson
|
174
218
|
\family default
|
175
|
-
is
|
219
|
+
is one of the series of Ruby gems (
|
176
220
|
\family typewriter
|
177
|
-
|
221
|
+
\color blue
|
222
|
+
|
223
|
+
\begin_inset CommandInset href
|
224
|
+
LatexCommand href
|
225
|
+
name "YPetri"
|
226
|
+
target "https://rubygems.org/gems/y_petri"
|
227
|
+
|
228
|
+
\end_inset
|
229
|
+
|
230
|
+
|
231
|
+
\family default
|
232
|
+
\color inherit
|
233
|
+
,
|
234
|
+
\family typewriter
|
235
|
+
\color blue
|
236
|
+
YChem
|
178
237
|
\family default
|
238
|
+
\color inherit
|
179
239
|
,
|
180
240
|
\family typewriter
|
181
241
|
\color blue
|
@@ -185,36 +245,61 @@ YCell
|
|
185
245
|
,
|
186
246
|
\family typewriter
|
187
247
|
\color blue
|
188
|
-
|
248
|
+
|
249
|
+
\begin_inset CommandInset href
|
250
|
+
LatexCommand href
|
251
|
+
name "Yzz"
|
252
|
+
target "https://rubygems.org/gems/yzz"
|
253
|
+
|
254
|
+
\end_inset
|
255
|
+
|
256
|
+
|
189
257
|
\family default
|
190
258
|
\color inherit
|
191
259
|
, metrology library
|
192
260
|
\family typewriter
|
193
261
|
\color blue
|
194
|
-
|
262
|
+
|
263
|
+
\begin_inset CommandInset href
|
264
|
+
LatexCommand href
|
265
|
+
name "SY"
|
266
|
+
target "https://rubygems.org/gems/sy"
|
267
|
+
|
268
|
+
\end_inset
|
269
|
+
|
270
|
+
|
195
271
|
\family default
|
196
272
|
\color inherit
|
197
|
-
)
|
273
|
+
...), whose design intent is to bring ergonomy to biochemical modeling.
|
198
274
|
Note that
|
199
275
|
\family typewriter
|
276
|
+
YNelson
|
277
|
+
\family default
|
278
|
+
depends on
|
279
|
+
\family typewriter
|
200
280
|
YPetri
|
201
281
|
\family default
|
202
|
-
|
282
|
+
and
|
283
|
+
\family typewriter
|
284
|
+
Yzz
|
285
|
+
\family default
|
286
|
+
gems, its usage together with
|
203
287
|
\family typewriter
|
204
288
|
SY
|
205
289
|
\family default
|
206
|
-
if
|
290
|
+
might be desirable if you are dealing with physical units.
|
207
291
|
Also,
|
208
292
|
\family typewriter
|
209
|
-
|
293
|
+
YNelson
|
210
294
|
\family default
|
211
|
-
is
|
295
|
+
use is not limited to biochemistry, but for all the applications where
|
296
|
+
Petri nets and/or relational databases are used.
|
212
297
|
\end_layout
|
213
298
|
|
214
299
|
\begin_layout Standard
|
215
300
|
|
216
301
|
\family typewriter
|
217
|
-
|
302
|
+
YNelson
|
218
303
|
\family default
|
219
304
|
provides a
|
220
305
|
\emph on
|
@@ -223,8 +308,7 @@ domain-specific language
|
|
223
308
|
\emph default
|
224
309
|
(DSL)
|
225
310
|
\color inherit
|
226
|
-
, which you can access
|
227
|
-
from
|
311
|
+
, which you can use in scripts, or access interactively from
|
228
312
|
\color red
|
229
313
|
inferior Ruby interpreter (
|
230
314
|
\emph on
|
@@ -233,7 +317,7 @@ irb
|
|
233
317
|
)
|
234
318
|
\color inherit
|
235
319
|
.
|
236
|
-
DSLs can be thought of as APIs with user-friendly syntax.
|
320
|
+
A DSLs can be thought of as APIs with user-friendly syntax.
|
237
321
|
As a believer in robot equality, I dislike the distinction between API
|
238
322
|
and UI (user interface), and prefer common textual command interface (CI)
|
239
323
|
for humanoid as well as cybernetic users.
|
@@ -242,11 +326,11 @@ irb
|
|
242
326
|
\begin_layout Standard
|
243
327
|
And why bother learning Ruby syntax and
|
244
328
|
\family typewriter
|
245
|
-
|
329
|
+
YNelson
|
246
330
|
\family default
|
247
331
|
? Half-jokingly,
|
248
332
|
\family typewriter
|
249
|
-
|
333
|
+
YNelson
|
250
334
|
\family default
|
251
335
|
is
|
252
336
|
\emph on
|
@@ -256,26 +340,16 @@ The Simplest Way To Work With Complicated Petri Nets
|
|
256
340
|
Petri net software at higher development stage, or written for a different
|
257
341
|
purpose than
|
258
342
|
\family typewriter
|
259
|
-
|
343
|
+
YNelson
|
260
344
|
\family default
|
261
345
|
, does exist.
|
262
346
|
But none of the programs written for the same purpose as
|
263
347
|
\family typewriter
|
264
|
-
|
265
|
-
\family default
|
266
|
-
can avoid taking the user through the same learning process as
|
267
|
-
\family typewriter
|
268
|
-
YPetri
|
348
|
+
YNelson
|
269
349
|
\family default
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
\family typewriter
|
274
|
-
YPetri
|
275
|
-
\family default
|
276
|
-
, but this ease is skin-deep, and you will realize it once your models get
|
277
|
-
less simple.
|
278
|
-
And if you are serious about modelling, you can bet they will.
|
350
|
+
can avoid taking the user through the process of learning the interface.
|
351
|
+
Advantages of using textual DSL become apparent as soon as the user's models
|
352
|
+
become less simple.
|
279
353
|
\end_layout
|
280
354
|
|
281
355
|
\begin_layout Part*
|
@@ -292,18 +366,28 @@ The Hard Way Is Easier
|
|
292
366
|
|
293
367
|
\begin_layout Standard
|
294
368
|
The phrase above is borrowed from the textbook by Zed Shaw named
|
295
|
-
\begin_inset Quotes
|
369
|
+
\begin_inset Quotes eld
|
296
370
|
\end_inset
|
297
371
|
|
372
|
+
Learn Ruby the Hard Way
|
373
|
+
\begin_inset Quotes erd
|
374
|
+
\end_inset
|
298
375
|
|
376
|
+
(highly recommended,
|
299
377
|
\emph on
|
300
|
-
|
301
|
-
|
378
|
+
\color magenta
|
379
|
+
|
380
|
+
\begin_inset CommandInset href
|
381
|
+
LatexCommand href
|
382
|
+
name "hyperlink here"
|
383
|
+
target "http://ruby.learncodethehardway.org/"
|
302
384
|
|
303
|
-
\begin_inset Quotes eld
|
304
385
|
\end_inset
|
305
386
|
|
306
|
-
|
387
|
+
|
388
|
+
\emph default
|
389
|
+
\color inherit
|
390
|
+
).
|
307
391
|
Apart from being a great shark-jumper, Zed is a great teacher familiar
|
308
392
|
with many programming languages, and I will borrow his teaching method
|
309
393
|
here.
|
@@ -331,7 +415,7 @@ used
|
|
331
415
|
to teach things.
|
332
416
|
|
333
417
|
\family typewriter
|
334
|
-
|
418
|
+
YNelson
|
335
419
|
\family default
|
336
420
|
is a language.
|
337
421
|
To learn it and see its usefulness, you will still need to do the incredibly
|
@@ -360,7 +444,7 @@ very
|
|
360
444
|
difficult at first, but stick with it.
|
361
445
|
It seems stupidly obvious, but, if you have a problem installing
|
362
446
|
\family typewriter
|
363
|
-
|
447
|
+
YNelson
|
364
448
|
\family default
|
365
449
|
, running
|
366
450
|
\emph on
|
@@ -384,7 +468,7 @@ exactly
|
|
384
468
|
The point is to train your hands, your brain, and your mind in how to read,
|
385
469
|
write and see Ruby and
|
386
470
|
\family typewriter
|
387
|
-
|
471
|
+
YNelson
|
388
472
|
\family default
|
389
473
|
code.
|
390
474
|
If you skip, skim and copy-paste, you are cheating yourself out of the
|
@@ -396,27 +480,40 @@ Prerequisites
|
|
396
480
|
\end_layout
|
397
481
|
|
398
482
|
\begin_layout Standard
|
483
|
+
Most importantly, you will need a working installation of Ruby 1.9 on your
|
484
|
+
computer.
|
485
|
+
Once this condition is met, basic
|
486
|
+
\family typewriter
|
487
|
+
YNelson
|
488
|
+
\family default
|
489
|
+
installation is as simple as typing
|
490
|
+
\begin_inset Quotes eld
|
491
|
+
\end_inset
|
492
|
+
|
399
493
|
|
400
494
|
\family typewriter
|
401
|
-
|
495
|
+
gem install y_nelson
|
402
496
|
\family default
|
403
|
-
|
404
|
-
|
405
|
-
|
406
|
-
|
407
|
-
|
497
|
+
|
498
|
+
\begin_inset Quotes erd
|
499
|
+
\end_inset
|
500
|
+
|
501
|
+
in the command prompt.
|
502
|
+
However,
|
408
503
|
\family typewriter
|
409
|
-
|
504
|
+
YNelson
|
410
505
|
\family default
|
411
|
-
|
412
|
-
|
413
|
-
|
414
|
-
\
|
415
|
-
|
506
|
+
currently uses dependencies (gnuplot gem, graphviz gem...), whose installation
|
507
|
+
may pose challenges.
|
508
|
+
Once
|
509
|
+
\family typewriter
|
510
|
+
YNelson
|
511
|
+
\family default
|
512
|
+
is installed, run
|
416
513
|
\emph on
|
417
514
|
irb
|
418
515
|
\emph default
|
419
|
-
|
516
|
+
command interpreter, and type:
|
420
517
|
\end_layout
|
421
518
|
|
422
519
|
\begin_layout LyX-Code
|
@@ -424,7 +521,7 @@ irb
|
|
424
521
|
\color red
|
425
522
|
require
|
426
523
|
\color inherit
|
427
|
-
'
|
524
|
+
'y_nelson'
|
428
525
|
\end_layout
|
429
526
|
|
430
527
|
\begin_layout Standard
|
@@ -440,17 +537,17 @@ require
|
|
440
537
|
\color red
|
441
538
|
include
|
442
539
|
\color inherit
|
443
|
-
|
540
|
+
YNelson
|
444
541
|
\end_layout
|
445
542
|
|
446
543
|
\begin_layout Standard
|
447
544
|
This will augment your irb command session with interactive
|
448
545
|
\family typewriter
|
449
|
-
|
546
|
+
YNelson
|
450
547
|
\family default
|
451
548
|
command interface (
|
452
549
|
\family typewriter
|
453
|
-
|
550
|
+
YNelson
|
454
551
|
\family default
|
455
552
|
DSL CI).
|
456
553
|
You have to re-run
|
@@ -469,7 +566,7 @@ include
|
|
469
566
|
Please, also notice that this guide itself is alpha stage, so the actual
|
470
567
|
|
471
568
|
\family typewriter
|
472
|
-
|
569
|
+
YNelson
|
473
570
|
\family default
|
474
571
|
version you will be using may somewhat differ from this guide.
|
475
572
|
Also, the nucleotide metabolism model in Example 3 is yet to be tuned to
|
@@ -479,20 +576,20 @@ YPetri
|
|
479
576
|
\end_layout
|
480
577
|
|
481
578
|
\begin_layout Part*
|
482
|
-
Example I
|
579
|
+
Example I: Basics
|
483
580
|
\end_layout
|
484
581
|
|
485
582
|
\begin_layout Standard
|
486
583
|
This example is a gentle introduction to Petri net terminology,
|
487
584
|
\family typewriter
|
488
|
-
|
585
|
+
YNelson
|
489
586
|
\family default
|
490
587
|
DSL terminology, and Ruby syntax.
|
491
|
-
The most basic capability that
|
588
|
+
The most basic capability, that
|
492
589
|
\family typewriter
|
493
|
-
|
590
|
+
YNelson
|
494
591
|
\family default
|
495
|
-
offers is that of user-driven
|
592
|
+
offers, is that of user-driven
|
496
593
|
\emph on
|
497
594
|
\color green
|
498
595
|
token game
|
@@ -537,7 +634,7 @@ Place
|
|
537
634
|
\family default
|
538
635
|
' of
|
539
636
|
\family typewriter
|
540
|
-
|
637
|
+
YNelson
|
541
638
|
\family default
|
542
639
|
DSL and assign its
|
543
640
|
\emph on
|
@@ -571,7 +668,7 @@ instance
|
|
571
668
|
of
|
572
669
|
\family typewriter
|
573
670
|
\color blue
|
574
|
-
|
671
|
+
YNelson::Place
|
575
672
|
\family default
|
576
673
|
\color inherit
|
577
674
|
|
@@ -583,7 +680,7 @@ class
|
|
583
680
|
.
|
584
681
|
We say that
|
585
682
|
\family typewriter
|
586
|
-
|
683
|
+
YNelson::Place
|
587
684
|
\family default
|
588
685
|
class
|
589
686
|
\emph on
|
@@ -593,7 +690,7 @@ represents
|
|
593
690
|
\color inherit
|
594
691
|
the concept of Petri net places in
|
595
692
|
\family typewriter
|
596
|
-
|
693
|
+
YNelson
|
597
694
|
\family default
|
598
695
|
|
599
696
|
\emph on
|
@@ -611,7 +708,7 @@ constructor
|
|
611
708
|
\color inherit
|
612
709
|
of
|
613
710
|
\family typewriter
|
614
|
-
|
711
|
+
YNelson::Place
|
615
712
|
\family default
|
616
713
|
, which is not important.).
|
617
714
|
Whole this object has now been assigned to
|
@@ -632,7 +729,7 @@ inspect string
|
|
632
729
|
\color inherit
|
633
730
|
of the object, created by
|
634
731
|
\family typewriter
|
635
|
-
|
732
|
+
YNelson::Place#
|
636
733
|
\color red
|
637
734
|
inspect
|
638
735
|
\family default
|
@@ -698,7 +795,7 @@ name
|
|
698
795
|
These have automatically become part of a default Petri net instance (of
|
699
796
|
|
700
797
|
\family typewriter
|
701
|
-
|
798
|
+
YNelson::Net
|
702
799
|
\family default
|
703
800
|
class; object id may vary):
|
704
801
|
\end_layout
|
@@ -889,7 +986,7 @@ Transition
|
|
889
986
|
\end_layout
|
890
987
|
|
891
988
|
\begin_layout LyX-Code
|
892
|
-
#=> #<Transition: A2B (tS)
|
989
|
+
#=> #<Transition: A2B (tS)>
|
893
990
|
\end_layout
|
894
991
|
|
895
992
|
\begin_layout Standard
|
@@ -1025,7 +1122,7 @@ B
|
|
1025
1122
|
.
|
1026
1123
|
In
|
1027
1124
|
\family typewriter
|
1028
|
-
|
1125
|
+
YNelson
|
1029
1126
|
\family default
|
1030
1127
|
domain model, 'arcs' are not first-class citizens.
|
1031
1128
|
The word is understood simply as a synonym for transitions' connectivity
|
@@ -1278,7 +1375,7 @@ Functional transitions and non-integer marking
|
|
1278
1375
|
So far, all the examples were compatible with classical Petri nets.
|
1279
1376
|
But
|
1280
1377
|
\family typewriter
|
1281
|
-
|
1378
|
+
YNelson
|
1282
1379
|
\family default
|
1283
1380
|
goes beyond – it represents
|
1284
1381
|
\emph on
|
@@ -1294,10 +1391,14 @@ key "Matsuno2011brs"
|
|
1294
1391
|
, which was already mentioned in the introduction.
|
1295
1392
|
|
1296
1393
|
\family typewriter
|
1297
|
-
|
1394
|
+
YNelson
|
1298
1395
|
\family default
|
1299
1396
|
domain model is similar, but not identical.
|
1300
|
-
On the side of similarities,
|
1397
|
+
On the side of similarities,
|
1398
|
+
\family typewriter
|
1399
|
+
YNelson
|
1400
|
+
\family default
|
1401
|
+
allows non-integer marking of places:
|
1301
1402
|
\end_layout
|
1302
1403
|
|
1303
1404
|
\begin_layout LyX-Code
|
@@ -1404,7 +1505,7 @@ rate:
|
|
1404
1505
|
\family default
|
1405
1506
|
' named argument, and have
|
1406
1507
|
\family typewriter
|
1407
|
-
|
1508
|
+
YNelson
|
1408
1509
|
\family default
|
1409
1510
|
create default mass action equation, using the supplied number as its rate
|
1410
1511
|
constant.
|
@@ -1557,113 +1658,800 @@ C.marking
|
|
1557
1658
|
#=> 0.00024457517215434527
|
1558
1659
|
\end_layout
|
1559
1660
|
|
1560
|
-
\begin_layout
|
1561
|
-
|
1661
|
+
\begin_layout Subsection*
|
1662
|
+
Four transition types
|
1562
1663
|
\end_layout
|
1563
1664
|
|
1564
1665
|
\begin_layout Standard
|
1565
|
-
|
1666
|
+
Thus far, we have demonstrated transitions with stoichiometry, which were
|
1667
|
+
either
|
1668
|
+
\emph on
|
1669
|
+
timed
|
1670
|
+
\emph default
|
1671
|
+
or not timed (
|
1672
|
+
\emph on
|
1673
|
+
timeless
|
1674
|
+
\emph default
|
1675
|
+
).
|
1676
|
+
Timed transitions are denoted by capital
|
1677
|
+
\begin_inset Quotes eld
|
1678
|
+
\end_inset
|
1679
|
+
|
1680
|
+
|
1566
1681
|
\family typewriter
|
1567
|
-
|
1682
|
+
T
|
1568
1683
|
\family default
|
1569
|
-
|
1684
|
+
|
1685
|
+
\begin_inset Quotes erd
|
1686
|
+
\end_inset
|
1687
|
+
|
1688
|
+
, timeless transitions by small
|
1689
|
+
\begin_inset Quotes eld
|
1690
|
+
\end_inset
|
1691
|
+
|
1692
|
+
|
1570
1693
|
\family typewriter
|
1571
|
-
|
1572
|
-
YPetri::TimedSimulation
|
1694
|
+
t
|
1573
1695
|
\family default
|
1574
|
-
|
1696
|
+
|
1697
|
+
\begin_inset Quotes erd
|
1698
|
+
\end_inset
|
1699
|
+
|
1575
1700
|
.
|
1576
|
-
|
1577
|
-
\
|
1578
|
-
|
1579
|
-
|
1580
|
-
|
1581
|
-
We will now define 2 places.
|
1582
|
-
Since we are going to use
|
1701
|
+
Similarly, stoichiometric transitions are denoted by capital
|
1702
|
+
\begin_inset Quotes eld
|
1703
|
+
\end_inset
|
1704
|
+
|
1705
|
+
|
1583
1706
|
\family typewriter
|
1584
|
-
|
1707
|
+
S
|
1585
1708
|
\family default
|
1586
|
-
|
1709
|
+
|
1710
|
+
\begin_inset Quotes erd
|
1711
|
+
\end_inset
|
1712
|
+
|
1713
|
+
, while transitions without stoichiometry (
|
1714
|
+
\emph on
|
1715
|
+
non-stoichiometric
|
1716
|
+
\emph default
|
1717
|
+
transitions) by small
|
1718
|
+
\begin_inset Quotes eld
|
1719
|
+
\end_inset
|
1720
|
+
|
1721
|
+
|
1587
1722
|
\family typewriter
|
1588
|
-
|
1723
|
+
s
|
1589
1724
|
\family default
|
1590
|
-
|
1591
|
-
|
1592
|
-
|
1725
|
+
|
1726
|
+
\begin_inset Quotes erd
|
1727
|
+
\end_inset
|
1728
|
+
|
1729
|
+
.
|
1730
|
+
Together, this gives 4 basic types of transitions:
|
1731
|
+
\family typewriter
|
1732
|
+
TS
|
1733
|
+
\family default
|
1734
|
+
,
|
1735
|
+
\family typewriter
|
1736
|
+
tS
|
1737
|
+
\family default
|
1738
|
+
,
|
1739
|
+
\family typewriter
|
1740
|
+
Ts
|
1741
|
+
\family default
|
1742
|
+
, and
|
1743
|
+
\family typewriter
|
1744
|
+
ts
|
1745
|
+
\family default
|
1746
|
+
.
|
1747
|
+
\end_layout
|
1748
|
+
|
1749
|
+
\begin_layout Standard
|
1750
|
+
The user can ask the type of a transition by calling the
|
1593
1751
|
\family typewriter
|
1594
1752
|
\color blue
|
1595
|
-
|
1753
|
+
type
|
1596
1754
|
\family default
|
1597
1755
|
\color inherit
|
1598
|
-
|
1756
|
+
method:
|
1599
1757
|
\end_layout
|
1600
1758
|
|
1601
1759
|
\begin_layout LyX-Code
|
1602
|
-
|
1603
|
-
\color blue
|
1604
|
-
default_marking:
|
1605
|
-
\color inherit
|
1606
|
-
0.5 )
|
1760
|
+
A2B.type
|
1607
1761
|
\end_layout
|
1608
1762
|
|
1609
1763
|
\begin_layout LyX-Code
|
1610
|
-
#=>
|
1764
|
+
#=> :tS
|
1765
|
+
\end_layout
|
1766
|
+
|
1767
|
+
\begin_layout Standard
|
1768
|
+
Or investigate the type with inquirer methods:
|
1611
1769
|
\end_layout
|
1612
1770
|
|
1613
1771
|
\begin_layout LyX-Code
|
1614
|
-
|
1772
|
+
A2B.
|
1773
|
+
\color blue
|
1774
|
+
t?
|
1615
1775
|
\end_layout
|
1616
1776
|
|
1617
1777
|
\begin_layout LyX-Code
|
1618
|
-
#=>
|
1778
|
+
#=> true
|
1619
1779
|
\end_layout
|
1620
1780
|
|
1621
|
-
\begin_layout
|
1622
|
-
|
1623
|
-
\
|
1624
|
-
|
1625
|
-
\family default
|
1626
|
-
out of the system at a constant rate 0.005 per time unit.
|
1781
|
+
\begin_layout LyX-Code
|
1782
|
+
A2B.
|
1783
|
+
\color blue
|
1784
|
+
T?
|
1627
1785
|
\end_layout
|
1628
1786
|
|
1629
1787
|
\begin_layout LyX-Code
|
1630
|
-
|
1788
|
+
#=> false
|
1631
1789
|
\end_layout
|
1632
1790
|
|
1633
1791
|
\begin_layout LyX-Code
|
1634
|
-
|
1792
|
+
A2B.
|
1793
|
+
\color blue
|
1794
|
+
s?
|
1635
1795
|
\end_layout
|
1636
1796
|
|
1637
|
-
\begin_layout
|
1638
|
-
|
1639
|
-
\family typewriter
|
1640
|
-
proc { 0.005 }
|
1641
|
-
\family default
|
1642
|
-
is a closure, that defines the rate function.
|
1643
|
-
Closure
|
1644
|
-
\family typewriter
|
1645
|
-
proc { 0.005 }
|
1646
|
-
\family default
|
1647
|
-
ensures fixed rate 0.005 per time unit regardless of the marking of
|
1648
|
-
\family typewriter
|
1649
|
-
A
|
1650
|
-
\family default
|
1651
|
-
.
|
1652
|
-
You can notice, that this closure expects no arguments and always outputs
|
1653
|
-
0.005 as its return value.
|
1654
|
-
It is the simplest possible way to write a constant function.
|
1655
|
-
For comparison,
|
1797
|
+
\begin_layout LyX-Code
|
1798
|
+
#=> false
|
1656
1799
|
\end_layout
|
1657
1800
|
|
1658
1801
|
\begin_layout LyX-Code
|
1659
|
-
|
1802
|
+
A2B.
|
1803
|
+
\color blue
|
1804
|
+
S?
|
1660
1805
|
\end_layout
|
1661
1806
|
|
1662
1807
|
\begin_layout LyX-Code
|
1663
|
-
#=>
|
1808
|
+
#=> true
|
1664
1809
|
\end_layout
|
1665
1810
|
|
1666
|
-
\begin_layout
|
1811
|
+
\begin_layout LyX-Code
|
1812
|
+
A2B.
|
1813
|
+
\color blue
|
1814
|
+
TS?
|
1815
|
+
\end_layout
|
1816
|
+
|
1817
|
+
\begin_layout LyX-Code
|
1818
|
+
#=> false
|
1819
|
+
\end_layout
|
1820
|
+
|
1821
|
+
\begin_layout LyX-Code
|
1822
|
+
A2B.
|
1823
|
+
\color blue
|
1824
|
+
tS?
|
1825
|
+
\end_layout
|
1826
|
+
|
1827
|
+
\begin_layout LyX-Code
|
1828
|
+
#=> true
|
1829
|
+
\end_layout
|
1830
|
+
|
1831
|
+
\begin_layout LyX-Code
|
1832
|
+
A2B.
|
1833
|
+
\color blue
|
1834
|
+
Ts?
|
1835
|
+
\end_layout
|
1836
|
+
|
1837
|
+
\begin_layout LyX-Code
|
1838
|
+
#=> false
|
1839
|
+
\end_layout
|
1840
|
+
|
1841
|
+
\begin_layout LyX-Code
|
1842
|
+
A2B.
|
1843
|
+
\color blue
|
1844
|
+
ts?
|
1845
|
+
\end_layout
|
1846
|
+
|
1847
|
+
\begin_layout LyX-Code
|
1848
|
+
#=> false
|
1849
|
+
\end_layout
|
1850
|
+
|
1851
|
+
\begin_layout Subsection*
|
1852
|
+
Assignment transitions
|
1853
|
+
\end_layout
|
1854
|
+
|
1855
|
+
\begin_layout Standard
|
1856
|
+
In
|
1857
|
+
\family typewriter
|
1858
|
+
YNelson
|
1859
|
+
\family default
|
1860
|
+
, there is one more transition type: an assignment transition, denoted by
|
1861
|
+
|
1862
|
+
\begin_inset Quotes eld
|
1863
|
+
\end_inset
|
1864
|
+
|
1865
|
+
|
1866
|
+
\family typewriter
|
1867
|
+
A
|
1868
|
+
\family default
|
1869
|
+
|
1870
|
+
\begin_inset Quotes erd
|
1871
|
+
\end_inset
|
1872
|
+
|
1873
|
+
.
|
1874
|
+
Assignment transitions do not add or subtract tokens from their target,
|
1875
|
+
but completely replace the codomain marking with their output.
|
1876
|
+
(Again, in
|
1877
|
+
\family typewriter
|
1878
|
+
YNelson
|
1879
|
+
\family default
|
1880
|
+
transitions,
|
1881
|
+
\emph on
|
1882
|
+
domain
|
1883
|
+
\emph default
|
1884
|
+
and
|
1885
|
+
\emph on
|
1886
|
+
codomain
|
1887
|
+
\emph default
|
1888
|
+
mean respectively upstream and downstream places.) Transitions other than
|
1889
|
+
|
1890
|
+
\family typewriter
|
1891
|
+
A
|
1892
|
+
\family default
|
1893
|
+
transitions can be collectively called non-assignment transitions, denoted
|
1894
|
+
by small
|
1895
|
+
\begin_inset Quotes eld
|
1896
|
+
\end_inset
|
1897
|
+
|
1898
|
+
|
1899
|
+
\family typewriter
|
1900
|
+
a
|
1901
|
+
\family default
|
1902
|
+
|
1903
|
+
\begin_inset Quotes erd
|
1904
|
+
\end_inset
|
1905
|
+
|
1906
|
+
.
|
1907
|
+
Note that assignment action is already achievable with plain
|
1908
|
+
\family typewriter
|
1909
|
+
ts
|
1910
|
+
\family default
|
1911
|
+
transitions (by subtracting away the previous codomain marking), so
|
1912
|
+
\family typewriter
|
1913
|
+
A
|
1914
|
+
\family default
|
1915
|
+
transitions are not strictly needed – their separate existence is just
|
1916
|
+
a syntactic convenience.
|
1917
|
+
\end_layout
|
1918
|
+
|
1919
|
+
\begin_layout Standard
|
1920
|
+
One way to construct assignment transitions is by setting
|
1921
|
+
\family typewriter
|
1922
|
+
:assignment
|
1923
|
+
\family default
|
1924
|
+
named argument to
|
1925
|
+
\emph on
|
1926
|
+
true
|
1927
|
+
\emph default
|
1928
|
+
:
|
1929
|
+
\end_layout
|
1930
|
+
|
1931
|
+
\begin_layout LyX-Code
|
1932
|
+
A_to_42 = Transition codomain: A, assignment: lambda { 42 }
|
1933
|
+
\end_layout
|
1934
|
+
|
1935
|
+
\begin_layout LyX-Code
|
1936
|
+
#=> #<Transition: A_to_42 (A Assign.)>
|
1937
|
+
\end_layout
|
1938
|
+
|
1939
|
+
\begin_layout Standard
|
1940
|
+
Firing this transition results in marking of
|
1941
|
+
\family typewriter
|
1942
|
+
A
|
1943
|
+
\family default
|
1944
|
+
being set to 42:
|
1945
|
+
\end_layout
|
1946
|
+
|
1947
|
+
\begin_layout LyX-Code
|
1948
|
+
A_to_42.fire!
|
1949
|
+
\end_layout
|
1950
|
+
|
1951
|
+
\begin_layout LyX-Code
|
1952
|
+
#=> nil
|
1953
|
+
\end_layout
|
1954
|
+
|
1955
|
+
\begin_layout LyX-Code
|
1956
|
+
A.marking
|
1957
|
+
\end_layout
|
1958
|
+
|
1959
|
+
\begin_layout LyX-Code
|
1960
|
+
#=> 42
|
1961
|
+
\end_layout
|
1962
|
+
|
1963
|
+
\begin_layout Standard
|
1964
|
+
Assignment transitions are of special type
|
1965
|
+
\family typewriter
|
1966
|
+
A
|
1967
|
+
\family default
|
1968
|
+
:
|
1969
|
+
\end_layout
|
1970
|
+
|
1971
|
+
\begin_layout LyX-Code
|
1972
|
+
A_to_42.type
|
1973
|
+
\end_layout
|
1974
|
+
|
1975
|
+
\begin_layout LyX-Code
|
1976
|
+
#=> :A
|
1977
|
+
\end_layout
|
1978
|
+
|
1979
|
+
\begin_layout LyX-Code
|
1980
|
+
A_to_42.A?
|
1981
|
+
\end_layout
|
1982
|
+
|
1983
|
+
\begin_layout LyX-Code
|
1984
|
+
#=> true
|
1985
|
+
\end_layout
|
1986
|
+
|
1987
|
+
\begin_layout LyX-Code
|
1988
|
+
A_to_42.a?
|
1989
|
+
\end_layout
|
1990
|
+
|
1991
|
+
\begin_layout LyX-Code
|
1992
|
+
#=> false
|
1993
|
+
\end_layout
|
1994
|
+
|
1995
|
+
\begin_layout Part*
|
1996
|
+
Example II: Convenience
|
1997
|
+
\end_layout
|
1998
|
+
|
1999
|
+
\begin_layout Standard
|
2000
|
+
So far, we have seen only one
|
2001
|
+
\emph on
|
2002
|
+
constructor method
|
2003
|
+
\emph default
|
2004
|
+
for transitions:
|
2005
|
+
\family typewriter
|
2006
|
+
Transition()
|
2007
|
+
\family default
|
2008
|
+
.
|
2009
|
+
|
2010
|
+
\family typewriter
|
2011
|
+
Transition()
|
2012
|
+
\family default
|
2013
|
+
method accepts several different named arguments (
|
2014
|
+
\family typewriter
|
2015
|
+
:domain
|
2016
|
+
\family default
|
2017
|
+
,
|
2018
|
+
\family typewriter
|
2019
|
+
:codomain
|
2020
|
+
\family default
|
2021
|
+
,
|
2022
|
+
\family typewriter
|
2023
|
+
:stoichiometry
|
2024
|
+
\family default
|
2025
|
+
|
2026
|
+
\family typewriter
|
2027
|
+
:assignment
|
2028
|
+
\family default
|
2029
|
+
,
|
2030
|
+
\family typewriter
|
2031
|
+
:rate
|
2032
|
+
\family default
|
2033
|
+
,
|
2034
|
+
\family typewriter
|
2035
|
+
:action
|
2036
|
+
\family default
|
2037
|
+
,
|
2038
|
+
\family typewriter
|
2039
|
+
:name
|
2040
|
+
\family default
|
2041
|
+
...) and depending on their values, returns a
|
2042
|
+
\family typewriter
|
2043
|
+
YNelson::Transition
|
2044
|
+
\family default
|
2045
|
+
class object of required type and properties.
|
2046
|
+
\end_layout
|
2047
|
+
|
2048
|
+
\begin_layout Standard
|
2049
|
+
Use of whole words in the constructor method makes the
|
2050
|
+
\family typewriter
|
2051
|
+
YNelson
|
2052
|
+
\family default
|
2053
|
+
DSL very explicit.
|
2054
|
+
But for the cases, where trading readability for brevity is desirable,
|
2055
|
+
these syntactic constructs can be shortened.
|
2056
|
+
Actually, we have already used this convenience in the earlier examples.
|
2057
|
+
We didn't type :
|
2058
|
+
\end_layout
|
2059
|
+
|
2060
|
+
\begin_layout LyX-Code
|
2061
|
+
Transition( name:
|
2062
|
+
\begin_inset Quotes eld
|
2063
|
+
\end_inset
|
2064
|
+
|
2065
|
+
A2B
|
2066
|
+
\begin_inset Quotes erd
|
2067
|
+
\end_inset
|
2068
|
+
|
2069
|
+
, codomain: [A, B], stoichiometry: [-1, 1] )
|
2070
|
+
\end_layout
|
2071
|
+
|
2072
|
+
\begin_layout LyX-Code
|
2073
|
+
A2B = transition( :A2B )
|
2074
|
+
\end_layout
|
2075
|
+
|
2076
|
+
\begin_layout Standard
|
2077
|
+
Instead, we just typed
|
2078
|
+
\end_layout
|
2079
|
+
|
2080
|
+
\begin_layout LyX-Code
|
2081
|
+
A2B = Transition( stoichiometry: { A: -1, B: 1 } )
|
2082
|
+
\end_layout
|
2083
|
+
|
2084
|
+
\begin_layout Standard
|
2085
|
+
Even shorter way to express the same would be:
|
2086
|
+
\end_layout
|
2087
|
+
|
2088
|
+
\begin_layout LyX-Code
|
2089
|
+
A2B = Transition s: { A: -1, B: 1 }
|
2090
|
+
\end_layout
|
2091
|
+
|
2092
|
+
\begin_layout Standard
|
2093
|
+
The above is a timeless transition.
|
2094
|
+
But we could think eg.
|
2095
|
+
about a more complicated transition, that would transfer tokens from
|
2096
|
+
\family typewriter
|
2097
|
+
B
|
2098
|
+
\family default
|
2099
|
+
to
|
2100
|
+
\family typewriter
|
2101
|
+
A
|
2102
|
+
\family default
|
2103
|
+
with rate depending on the square root of the product of marking of
|
2104
|
+
\family typewriter
|
2105
|
+
C
|
2106
|
+
\family default
|
2107
|
+
and
|
2108
|
+
\family typewriter
|
2109
|
+
D
|
2110
|
+
\family default
|
2111
|
+
.
|
2112
|
+
Start a new
|
2113
|
+
\family typewriter
|
2114
|
+
irb
|
2115
|
+
\family default
|
2116
|
+
session and type:
|
2117
|
+
\end_layout
|
2118
|
+
|
2119
|
+
\begin_layout LyX-Code
|
2120
|
+
require 'y_nelson'
|
2121
|
+
\end_layout
|
2122
|
+
|
2123
|
+
\begin_layout LyX-Code
|
2124
|
+
include YNelson
|
2125
|
+
\end_layout
|
2126
|
+
|
2127
|
+
\begin_layout LyX-Code
|
2128
|
+
A = Place( default_marking: 5 )
|
2129
|
+
\end_layout
|
2130
|
+
|
2131
|
+
\begin_layout LyX-Code
|
2132
|
+
B = Place m!: 5 # notice
|
2133
|
+
\begin_inset Quotes eld
|
2134
|
+
\end_inset
|
2135
|
+
|
2136
|
+
m!
|
2137
|
+
\begin_inset Quotes erd
|
2138
|
+
\end_inset
|
2139
|
+
|
2140
|
+
alias for
|
2141
|
+
\begin_inset Quotes eld
|
2142
|
+
\end_inset
|
2143
|
+
|
2144
|
+
default marking
|
2145
|
+
\begin_inset Quotes erd
|
2146
|
+
\end_inset
|
2147
|
+
|
2148
|
+
|
2149
|
+
\end_layout
|
2150
|
+
|
2151
|
+
\begin_layout LyX-Code
|
2152
|
+
C = Place m!: 1
|
2153
|
+
\end_layout
|
2154
|
+
|
2155
|
+
\begin_layout LyX-Code
|
2156
|
+
D = Place m!: 1
|
2157
|
+
\end_layout
|
2158
|
+
|
2159
|
+
\begin_layout Standard
|
2160
|
+
Let's check our work:
|
2161
|
+
\end_layout
|
2162
|
+
|
2163
|
+
\begin_layout LyX-Code
|
2164
|
+
places.map &:m
|
2165
|
+
\end_layout
|
2166
|
+
|
2167
|
+
\begin_layout LyX-Code
|
2168
|
+
#=> [5, 5, 1, 1]
|
2169
|
+
\end_layout
|
2170
|
+
|
2171
|
+
\begin_layout Standard
|
2172
|
+
Indeed, the net state has been set according to the default markings of
|
2173
|
+
the places.
|
2174
|
+
Now let's define the transition we want:
|
2175
|
+
\end_layout
|
2176
|
+
|
2177
|
+
\begin_layout LyX-Code
|
2178
|
+
B2A = Transition( stoichiometry: { B: -1, A: 1 },
|
2179
|
+
\end_layout
|
2180
|
+
|
2181
|
+
\begin_layout LyX-Code
|
2182
|
+
domain: [C, D],
|
2183
|
+
\end_layout
|
2184
|
+
|
2185
|
+
\begin_layout LyX-Code
|
2186
|
+
rate: lambda { |x, y| ( x * y ) ** 0.5 } )
|
2187
|
+
\end_layout
|
2188
|
+
|
2189
|
+
\begin_layout LyX-Code
|
2190
|
+
#=> #<Transition: B2A (TS)>
|
2191
|
+
\end_layout
|
2192
|
+
|
2193
|
+
\begin_layout Standard
|
2194
|
+
To prove that it works, let's fire it for 0.1 time units:
|
2195
|
+
\end_layout
|
2196
|
+
|
2197
|
+
\begin_layout LyX-Code
|
2198
|
+
B2A.fire! 0.1
|
2199
|
+
\end_layout
|
2200
|
+
|
2201
|
+
\begin_layout LyX-Code
|
2202
|
+
#=> nil
|
2203
|
+
\end_layout
|
2204
|
+
|
2205
|
+
\begin_layout LyX-Code
|
2206
|
+
places.map &:m
|
2207
|
+
\end_layout
|
2208
|
+
|
2209
|
+
\begin_layout LyX-Code
|
2210
|
+
#=> [5.1, 4.9, 1, 1]
|
2211
|
+
\end_layout
|
2212
|
+
|
2213
|
+
\begin_layout Standard
|
2214
|
+
You can try to change marking of C and D to control the rate:
|
2215
|
+
\end_layout
|
2216
|
+
|
2217
|
+
\begin_layout LyX-Code
|
2218
|
+
[A, B].each &:
|
2219
|
+
\color blue
|
2220
|
+
reset_marking
|
2221
|
+
\end_layout
|
2222
|
+
|
2223
|
+
\begin_layout LyX-Code
|
2224
|
+
C.m = 4
|
2225
|
+
\end_layout
|
2226
|
+
|
2227
|
+
\begin_layout LyX-Code
|
2228
|
+
D.m = 9
|
2229
|
+
\end_layout
|
2230
|
+
|
2231
|
+
\begin_layout LyX-Code
|
2232
|
+
places.map &:m
|
2233
|
+
\end_layout
|
2234
|
+
|
2235
|
+
\begin_layout LyX-Code
|
2236
|
+
#=> [5, 5, 4, 9]
|
2237
|
+
\end_layout
|
2238
|
+
|
2239
|
+
\begin_layout LyX-Code
|
2240
|
+
B2A.fire! 0.1
|
2241
|
+
\end_layout
|
2242
|
+
|
2243
|
+
\begin_layout LyX-Code
|
2244
|
+
places.map &:m
|
2245
|
+
\end_layout
|
2246
|
+
|
2247
|
+
\begin_layout LyX-Code
|
2248
|
+
#=> [5.6, 4.4, 4, 9]
|
2249
|
+
\end_layout
|
2250
|
+
|
2251
|
+
\begin_layout Standard
|
2252
|
+
We can see that the rate of
|
2253
|
+
\family typewriter
|
2254
|
+
B2A
|
2255
|
+
\family default
|
2256
|
+
has risen 6 times as expected (4 * 9 is 36), so
|
2257
|
+
\family typewriter
|
2258
|
+
B2A
|
2259
|
+
\family default
|
2260
|
+
works.
|
2261
|
+
The question is, could we have written
|
2262
|
+
\family typewriter
|
2263
|
+
B2A
|
2264
|
+
\family default
|
2265
|
+
more concisely? For
|
2266
|
+
\family typewriter
|
2267
|
+
TS
|
2268
|
+
\family default
|
2269
|
+
transitions (check
|
2270
|
+
\family typewriter
|
2271
|
+
B2A.type
|
2272
|
+
\family default
|
2273
|
+
to make sure that it's a
|
2274
|
+
\family typewriter
|
2275
|
+
TS
|
2276
|
+
\family default
|
2277
|
+
transition),
|
2278
|
+
\family typewriter
|
2279
|
+
\color blue
|
2280
|
+
TS()
|
2281
|
+
\family default
|
2282
|
+
\color inherit
|
2283
|
+
constructor is available, allowing to express the same transition with
|
2284
|
+
a shorter syntactic construct:
|
2285
|
+
\end_layout
|
2286
|
+
|
2287
|
+
\begin_layout LyX-Code
|
2288
|
+
B2A = TS domain: [C, D], A: 1, B: -1 do |x, y| ( x * y ) ** 0.5 end
|
2289
|
+
\end_layout
|
2290
|
+
|
2291
|
+
\begin_layout Standard
|
2292
|
+
Restart the
|
2293
|
+
\family typewriter
|
2294
|
+
irb
|
2295
|
+
\family default
|
2296
|
+
session again and use this shorter construct to see that the resulting
|
2297
|
+
transition behaves like before.
|
2298
|
+
Note the
|
2299
|
+
\family typewriter
|
2300
|
+
\color red
|
2301
|
+
do ...
|
2302
|
+
end
|
2303
|
+
\family default
|
2304
|
+
\color inherit
|
2305
|
+
part of the construct: Using lambda syntax, it defines the rate function
|
2306
|
+
of the transition.
|
2307
|
+
\end_layout
|
2308
|
+
|
2309
|
+
\begin_layout Standard
|
2310
|
+
One more convenience constructor I want to mention here is
|
2311
|
+
\family typewriter
|
2312
|
+
\color blue
|
2313
|
+
AT()
|
2314
|
+
\family default
|
2315
|
+
\color inherit
|
2316
|
+
constructor for assignment transition.
|
2317
|
+
Earlier, we defined:
|
2318
|
+
\end_layout
|
2319
|
+
|
2320
|
+
\begin_layout LyX-Code
|
2321
|
+
A_to_42 = Transition codomain: A, assignment: lambda { 42 }
|
2322
|
+
\end_layout
|
2323
|
+
|
2324
|
+
\begin_layout Standard
|
2325
|
+
This can be conveniently rewritten using
|
2326
|
+
\family typewriter
|
2327
|
+
AT()
|
2328
|
+
\family default
|
2329
|
+
constructor as:
|
2330
|
+
\end_layout
|
2331
|
+
|
2332
|
+
\begin_layout LyX-Code
|
2333
|
+
A_to_42 = AT A do 42 end
|
2334
|
+
\end_layout
|
2335
|
+
|
2336
|
+
\begin_layout Standard
|
2337
|
+
In short, syntactic shorthands are less readable than full
|
2338
|
+
\family typewriter
|
2339
|
+
Transition()
|
2340
|
+
\family default
|
2341
|
+
statements, but can save a lot of space and typing.
|
2342
|
+
In any case, in Ruby, the user can easily defined new aliases and routines
|
2343
|
+
that make the frequent tasks easier to type.
|
2344
|
+
\end_layout
|
2345
|
+
|
2346
|
+
\begin_layout Part*
|
2347
|
+
Example III: YNelson::Simulation
|
2348
|
+
\end_layout
|
2349
|
+
|
2350
|
+
\begin_layout Standard
|
2351
|
+
So far, we have been defining Petri nets and playing the token game using
|
2352
|
+
|
2353
|
+
\family typewriter
|
2354
|
+
#fire!
|
2355
|
+
\family default
|
2356
|
+
method, let us now simulate a Petri net inside
|
2357
|
+
\family typewriter
|
2358
|
+
YNelson
|
2359
|
+
\color blue
|
2360
|
+
::Simulation
|
2361
|
+
\family default
|
2362
|
+
\color inherit
|
2363
|
+
.
|
2364
|
+
Restart your irb session as described in the
|
2365
|
+
\series bold
|
2366
|
+
Prerequisites
|
2367
|
+
\series default
|
2368
|
+
chapter.
|
2369
|
+
We will now define 2 places.
|
2370
|
+
Since we are going to use
|
2371
|
+
\family typewriter
|
2372
|
+
TimedSimulation
|
2373
|
+
\family default
|
2374
|
+
, the marking owned by
|
2375
|
+
\family typewriter
|
2376
|
+
YNelson::Place
|
2377
|
+
\family default
|
2378
|
+
instances is irrelevant.
|
2379
|
+
We just need to specify the initial state.
|
2380
|
+
One way to do this is by specifying
|
2381
|
+
\family typewriter
|
2382
|
+
\color blue
|
2383
|
+
:default_marking
|
2384
|
+
\family default
|
2385
|
+
\color inherit
|
2386
|
+
named argument:
|
2387
|
+
\end_layout
|
2388
|
+
|
2389
|
+
\begin_layout LyX-Code
|
2390
|
+
A = Place(
|
2391
|
+
\color blue
|
2392
|
+
default_marking:
|
2393
|
+
\color inherit
|
2394
|
+
0.5 )
|
2395
|
+
\end_layout
|
2396
|
+
|
2397
|
+
\begin_layout LyX-Code
|
2398
|
+
#=> #<Place: name: A, marking: 0.5, default_marking: 0.5>
|
2399
|
+
\end_layout
|
2400
|
+
|
2401
|
+
\begin_layout LyX-Code
|
2402
|
+
B = Place( default_marking: 0.5 )
|
2403
|
+
\end_layout
|
2404
|
+
|
2405
|
+
\begin_layout LyX-Code
|
2406
|
+
#=> #<Place: name: B, marking: 0.5, default_marking: 0.5>
|
2407
|
+
\end_layout
|
2408
|
+
|
2409
|
+
\begin_layout Standard
|
2410
|
+
Now let us define a transition corresponding to pumping
|
2411
|
+
\family typewriter
|
2412
|
+
A
|
2413
|
+
\family default
|
2414
|
+
out of the system at a constant rate 0.005 per time unit.
|
2415
|
+
\end_layout
|
2416
|
+
|
2417
|
+
\begin_layout LyX-Code
|
2418
|
+
A_pump = Transition( stoichiometry: { A: -1 }, rate: proc { 0.005 } )
|
2419
|
+
\end_layout
|
2420
|
+
|
2421
|
+
\begin_layout LyX-Code
|
2422
|
+
#=> #<Transition: A_pump (TS)>
|
2423
|
+
\end_layout
|
2424
|
+
|
2425
|
+
\begin_layout Standard
|
2426
|
+
Here,
|
2427
|
+
\family typewriter
|
2428
|
+
proc { 0.005 }
|
2429
|
+
\family default
|
2430
|
+
is a closure, that defines the rate function.
|
2431
|
+
Closure
|
2432
|
+
\family typewriter
|
2433
|
+
proc { 0.005 }
|
2434
|
+
\family default
|
2435
|
+
ensures fixed rate 0.005 per time unit regardless of the marking of
|
2436
|
+
\family typewriter
|
2437
|
+
A
|
2438
|
+
\family default
|
2439
|
+
.
|
2440
|
+
You can notice, that this closure expects no arguments and always outputs
|
2441
|
+
0.005 as its return value.
|
2442
|
+
It is the simplest possible way to write a constant function.
|
2443
|
+
For comparison,
|
2444
|
+
\end_layout
|
2445
|
+
|
2446
|
+
\begin_layout LyX-Code
|
2447
|
+
B_decay = Transition( stoichiometry: { B: -1 }, rate: 0.05 )
|
2448
|
+
\end_layout
|
2449
|
+
|
2450
|
+
\begin_layout LyX-Code
|
2451
|
+
#=> #<Transition: B_decay (TS)>
|
2452
|
+
\end_layout
|
2453
|
+
|
2454
|
+
\begin_layout Standard
|
1667
2455
|
will behind the scenes automatically create a slightly more complicated
|
1668
2456
|
mass action closure, which is logarithmic decay of
|
1669
2457
|
\family typewriter
|
@@ -1700,8 +2488,7 @@ run!
|
|
1700
2488
|
\end_layout
|
1701
2489
|
|
1702
2490
|
\begin_layout LyX-Code
|
1703
|
-
#=>
|
1704
|
-
id: 75530290>
|
2491
|
+
#=> 60
|
1705
2492
|
\end_layout
|
1706
2493
|
|
1707
2494
|
\begin_layout Standard
|
@@ -1731,7 +2518,7 @@ simulation
|
|
1731
2518
|
\end_layout
|
1732
2519
|
|
1733
2520
|
\begin_layout LyX-Code
|
1734
|
-
#=> #<Simulation:
|
2521
|
+
#=> #<Simulation: time: 60, pp: 2, tt: 2, oid: 75530290>
|
1735
2522
|
\end_layout
|
1736
2523
|
|
1737
2524
|
\begin_layout Standard
|
@@ -1746,7 +2533,7 @@ mental image
|
|
1746
2533
|
|
1747
2534
|
of the net, therefore the marking owned by
|
1748
2535
|
\family typewriter
|
1749
|
-
|
2536
|
+
YNelson::Place
|
1750
2537
|
\family default
|
1751
2538
|
instances does not change:
|
1752
2539
|
\end_layout
|
@@ -1786,55 +2573,63 @@ print_recording
|
|
1786
2573
|
\end_layout
|
1787
2574
|
|
1788
2575
|
\begin_layout LyX-Code
|
1789
|
-
#=>
|
2576
|
+
#=> :A :B
|
2577
|
+
\end_layout
|
2578
|
+
|
2579
|
+
\begin_layout LyX-Code
|
2580
|
+
----------------
|
2581
|
+
\end_layout
|
2582
|
+
|
2583
|
+
\begin_layout LyX-Code
|
2584
|
+
0.5000 0.5000
|
1790
2585
|
\end_layout
|
1791
2586
|
|
1792
2587
|
\begin_layout LyX-Code
|
1793
|
-
|
2588
|
+
0.4750 0.3892
|
1794
2589
|
\end_layout
|
1795
2590
|
|
1796
2591
|
\begin_layout LyX-Code
|
1797
|
-
|
2592
|
+
0.4500 0.3029
|
1798
2593
|
\end_layout
|
1799
2594
|
|
1800
2595
|
\begin_layout LyX-Code
|
1801
|
-
|
2596
|
+
0.4250 0.2357
|
1802
2597
|
\end_layout
|
1803
2598
|
|
1804
2599
|
\begin_layout LyX-Code
|
1805
|
-
|
2600
|
+
0.4000 0.1835
|
1806
2601
|
\end_layout
|
1807
2602
|
|
1808
2603
|
\begin_layout LyX-Code
|
1809
|
-
|
2604
|
+
0.3750 0.1428
|
1810
2605
|
\end_layout
|
1811
2606
|
|
1812
2607
|
\begin_layout LyX-Code
|
1813
|
-
|
2608
|
+
0.3500 0.1111
|
1814
2609
|
\end_layout
|
1815
2610
|
|
1816
2611
|
\begin_layout LyX-Code
|
1817
|
-
|
2612
|
+
0.3250 0.0865
|
1818
2613
|
\end_layout
|
1819
2614
|
|
1820
2615
|
\begin_layout LyX-Code
|
1821
|
-
|
2616
|
+
0.3000 0.0673
|
1822
2617
|
\end_layout
|
1823
2618
|
|
1824
2619
|
\begin_layout LyX-Code
|
1825
|
-
|
2620
|
+
0.2750 0.0524
|
1826
2621
|
\end_layout
|
1827
2622
|
|
1828
2623
|
\begin_layout LyX-Code
|
1829
|
-
|
2624
|
+
0.2500 0.0408
|
1830
2625
|
\end_layout
|
1831
2626
|
|
1832
2627
|
\begin_layout LyX-Code
|
1833
|
-
|
2628
|
+
0.2250 0.0317
|
1834
2629
|
\end_layout
|
1835
2630
|
|
1836
2631
|
\begin_layout LyX-Code
|
1837
|
-
|
2632
|
+
0.2000 0.0247
|
1838
2633
|
\end_layout
|
1839
2634
|
|
1840
2635
|
\begin_layout LyX-Code
|
@@ -1861,9 +2656,9 @@ gnuplot
|
|
1861
2656
|
\begin_layout LyX-Code
|
1862
2657
|
|
1863
2658
|
\color blue
|
1864
|
-
|
2659
|
+
recording.plot
|
1865
2660
|
\color inherit
|
1866
|
-
|
2661
|
+
# plots a graph
|
1867
2662
|
\end_layout
|
1868
2663
|
|
1869
2664
|
\begin_layout LyX-Code
|
@@ -1871,39 +2666,54 @@ plot_recording
|
|
1871
2666
|
\end_layout
|
1872
2667
|
|
1873
2668
|
\begin_layout Standard
|
1874
|
-
|
1875
|
-
|
1876
|
-
|
1877
|
-
|
1878
|
-
\begin_layout LyX-Code
|
1879
|
-
simulation.recording.marking.plot
|
2669
|
+
Previous command plots the default feature set, which is marking of the
|
2670
|
+
places.
|
2671
|
+
We can investigate also features of the recording (gradient or delta of
|
2672
|
+
places, firing or flux of the transitions...):
|
1880
2673
|
\end_layout
|
1881
2674
|
|
1882
2675
|
\begin_layout LyX-Code
|
1883
|
-
|
2676
|
+
recording.gradient.plot
|
1884
2677
|
\end_layout
|
1885
2678
|
|
1886
2679
|
\begin_layout LyX-Code
|
1887
|
-
|
2680
|
+
recording.flux.plot
|
1888
2681
|
\end_layout
|
1889
2682
|
|
1890
2683
|
\begin_layout LyX-Code
|
1891
|
-
|
2684
|
+
recording.delta( delta_time: 0.1 ).plot
|
1892
2685
|
\end_layout
|
1893
2686
|
|
1894
2687
|
\begin_layout Standard
|
1895
|
-
|
1896
|
-
|
2688
|
+
The last feature set – delta – requires
|
2689
|
+
\family typewriter
|
2690
|
+
delta_time
|
2691
|
+
\family default
|
2692
|
+
named argument to extrapolate the changes (deltas) of the places in the
|
2693
|
+
given delta time.
|
2694
|
+
As for
|
2695
|
+
\family typewriter
|
2696
|
+
firing
|
2697
|
+
\family default
|
2698
|
+
, a feature of
|
2699
|
+
\family typewriter
|
2700
|
+
tS
|
2701
|
+
\family default
|
2702
|
+
transitions, the plot would show nothing here, as there ar no
|
2703
|
+
\family typewriter
|
2704
|
+
tS
|
2705
|
+
\family default
|
2706
|
+
transitions here.
|
1897
2707
|
\end_layout
|
1898
2708
|
|
1899
2709
|
\begin_layout Part*
|
1900
|
-
Example
|
2710
|
+
Example IV: A real system.
|
1901
2711
|
\end_layout
|
1902
2712
|
|
1903
2713
|
\begin_layout Standard
|
1904
2714
|
A highly simplified cell-biological pathway simulated with
|
1905
2715
|
\family typewriter
|
1906
|
-
|
2716
|
+
YNelson::TimedSimulation
|
1907
2717
|
\family default
|
1908
2718
|
.
|
1909
2719
|
Let's first define some assumptions.
|
@@ -1911,15 +2721,15 @@ YPetri::TimedSimulation
|
|
1911
2721
|
\end_layout
|
1912
2722
|
|
1913
2723
|
\begin_layout LyX-Code
|
1914
|
-
|
2724
|
+
require 'y_nelson' and include YNelson
|
1915
2725
|
\end_layout
|
1916
2726
|
|
1917
2727
|
\begin_layout LyX-Code
|
1918
|
-
|
2728
|
+
|
1919
2729
|
\end_layout
|
1920
2730
|
|
1921
2731
|
\begin_layout LyX-Code
|
1922
|
-
|
2732
|
+
Pieces_per_microM = 100_000
|
1923
2733
|
\end_layout
|
1924
2734
|
|
1925
2735
|
\begin_layout LyX-Code
|
@@ -1927,7 +2737,15 @@ Pieces_per_micromolar = NA / 1_000_000 * Cytoplasm_volume_in_litres
|
|
1927
2737
|
\color blue
|
1928
2738
|
set_step
|
1929
2739
|
\color inherit
|
1930
|
-
|
2740
|
+
10
|
2741
|
+
\end_layout
|
2742
|
+
|
2743
|
+
\begin_layout LyX-Code
|
2744
|
+
|
2745
|
+
\color blue
|
2746
|
+
set_sampling
|
2747
|
+
\color inherit
|
2748
|
+
30
|
1931
2749
|
\end_layout
|
1932
2750
|
|
1933
2751
|
\begin_layout LyX-Code
|
@@ -1935,7 +2753,7 @@ set_step
|
|
1935
2753
|
\color blue
|
1936
2754
|
set_target_time
|
1937
2755
|
\color inherit
|
1938
|
-
|
2756
|
+
30 * 60
|
1939
2757
|
\end_layout
|
1940
2758
|
|
1941
2759
|
\begin_layout Standard
|
@@ -1968,15 +2786,15 @@ ATP = Place m!: 3152.0
|
|
1968
2786
|
\end_layout
|
1969
2787
|
|
1970
2788
|
\begin_layout LyX-Code
|
1971
|
-
|
2789
|
+
DeoxyCytidine = Place m!: 5.0
|
1972
2790
|
\end_layout
|
1973
2791
|
|
1974
2792
|
\begin_layout LyX-Code
|
1975
|
-
DeoxyCTP = Place m!:
|
2793
|
+
DeoxyCTP = Place m!: 20.0
|
1976
2794
|
\end_layout
|
1977
2795
|
|
1978
2796
|
\begin_layout LyX-Code
|
1979
|
-
DeoxyGMP = Place m!:
|
2797
|
+
DeoxyGMP = Place m!: 20.0
|
1980
2798
|
\end_layout
|
1981
2799
|
|
1982
2800
|
\begin_layout LyX-Code
|
@@ -1984,19 +2802,19 @@ UMP_UDP_pool = Place m!: 2737.0
|
|
1984
2802
|
\end_layout
|
1985
2803
|
|
1986
2804
|
\begin_layout LyX-Code
|
1987
|
-
DeoxyUMP_DeoxyUDP_pool = Place m!:
|
2805
|
+
DeoxyUMP_DeoxyUDP_pool = Place m!: 10.0
|
1988
2806
|
\end_layout
|
1989
2807
|
|
1990
2808
|
\begin_layout LyX-Code
|
1991
|
-
DeoxyTMP = Place m!:
|
2809
|
+
DeoxyTMP = Place m!: 50.0
|
1992
2810
|
\end_layout
|
1993
2811
|
|
1994
2812
|
\begin_layout LyX-Code
|
1995
|
-
DeoxyTDP_DeoxyTTP_pool = Place m!:
|
2813
|
+
DeoxyTDP_DeoxyTTP_pool = Place m!: 100.0
|
1996
2814
|
\end_layout
|
1997
2815
|
|
1998
2816
|
\begin_layout LyX-Code
|
1999
|
-
Thymidine = Place m!: 0
|
2817
|
+
Thymidine = Place m!: 10.0
|
2000
2818
|
\end_layout
|
2001
2819
|
|
2002
2820
|
\begin_layout Standard
|
@@ -2005,19 +2823,19 @@ All the places above have their marking in micromolars.
|
|
2005
2823
|
\end_layout
|
2006
2824
|
|
2007
2825
|
\begin_layout LyX-Code
|
2008
|
-
TK1 = Place m!: 100_000
|
2826
|
+
TK1 = Place m!: 100_000 / Pieces_per_microM
|
2009
2827
|
\end_layout
|
2010
2828
|
|
2011
2829
|
\begin_layout LyX-Code
|
2012
|
-
TYMS = Place m!: 100_000
|
2830
|
+
TYMS = Place m!: 100_000 / Pieces_per_microM
|
2013
2831
|
\end_layout
|
2014
2832
|
|
2015
2833
|
\begin_layout LyX-Code
|
2016
|
-
RNR = Place m!: 100_000
|
2834
|
+
RNR = Place m!: 100_000 / Pieces_per_microM
|
2017
2835
|
\end_layout
|
2018
2836
|
|
2019
2837
|
\begin_layout LyX-Code
|
2020
|
-
TMPK = Place m!: 100_000
|
2838
|
+
TMPK = Place m!: 100_000 / Pieces_per_microM
|
2021
2839
|
\end_layout
|
2022
2840
|
|
2023
2841
|
\begin_layout Standard
|
@@ -2041,7 +2859,19 @@ TMPK_kDa = 50.0
|
|
2041
2859
|
\end_layout
|
2042
2860
|
|
2043
2861
|
\begin_layout Standard
|
2044
|
-
Enzyme
|
2862
|
+
Enzyme specific activities (in
|
2863
|
+
\emph on
|
2864
|
+
micromolar
|
2865
|
+
\emph default
|
2866
|
+
/
|
2867
|
+
\emph on
|
2868
|
+
minute
|
2869
|
+
\emph default
|
2870
|
+
/
|
2871
|
+
\emph on
|
2872
|
+
mg
|
2873
|
+
\emph default
|
2874
|
+
):
|
2045
2875
|
\end_layout
|
2046
2876
|
|
2047
2877
|
\begin_layout LyX-Code
|
@@ -2073,7 +2903,7 @@ clamp
|
|
2073
2903
|
\end_layout
|
2074
2904
|
|
2075
2905
|
\begin_layout LyX-Code
|
2076
|
-
clamp
|
2906
|
+
clamp DeoxyCytidine: 0.5, DeoxyCTP: 1.0, DeoxyGMP: 1.0
|
2077
2907
|
\end_layout
|
2078
2908
|
|
2079
2909
|
\begin_layout LyX-Code
|
@@ -2089,314 +2919,309 @@ Before defining transitions, let's define some functions first:
|
|
2089
2919
|
\end_layout
|
2090
2920
|
|
2091
2921
|
\begin_layout LyX-Code
|
2092
|
-
|
2922
|
+
Vmax_per_min_per_enz_molecule =
|
2093
2923
|
\end_layout
|
2094
2924
|
|
2095
2925
|
\begin_layout LyX-Code
|
2096
|
-
lambda { |
|
2926
|
+
lambda { |spec_act_microM_per_min_per_mg, kDa|
|
2097
2927
|
\end_layout
|
2098
2928
|
|
2099
2929
|
\begin_layout LyX-Code
|
2100
|
-
|
2930
|
+
spec_act_microM_per_min_per_mg * kDa }
|
2101
2931
|
\end_layout
|
2102
2932
|
|
2103
2933
|
\begin_layout LyX-Code
|
2104
|
-
|
2934
|
+
Vmax_per_min =
|
2105
2935
|
\end_layout
|
2106
2936
|
|
2107
2937
|
\begin_layout LyX-Code
|
2108
|
-
|
2938
|
+
lambda { |spec_act, kDa, enz_molecules_per_cell|
|
2109
2939
|
\end_layout
|
2110
2940
|
|
2111
2941
|
\begin_layout LyX-Code
|
2112
|
-
|
2942
|
+
Vmax_per_min_per_enz_molecule.( spec_act, kDa ) *
|
2113
2943
|
\end_layout
|
2114
2944
|
|
2115
2945
|
\begin_layout LyX-Code
|
2116
|
-
|
2946
|
+
enz_molecules_per_cell }
|
2117
2947
|
\end_layout
|
2118
2948
|
|
2119
2949
|
\begin_layout LyX-Code
|
2120
|
-
|
2121
|
-
*
|
2950
|
+
Vmax_per_s =
|
2122
2951
|
\end_layout
|
2123
2952
|
|
2124
2953
|
\begin_layout LyX-Code
|
2125
|
-
|
2954
|
+
lambda { |spec_act, kDa, enz_mol_per_cell|
|
2126
2955
|
\end_layout
|
2127
2956
|
|
2128
2957
|
\begin_layout LyX-Code
|
2129
|
-
|
2958
|
+
Vmax_per_min.( spec_act, kDa, enz_mol_per_cell ) / 60 }
|
2130
2959
|
\end_layout
|
2131
2960
|
|
2132
2961
|
\begin_layout LyX-Code
|
2133
|
-
|
2962
|
+
Km_reduced =
|
2134
2963
|
\end_layout
|
2135
2964
|
|
2136
2965
|
\begin_layout LyX-Code
|
2137
|
-
|
2966
|
+
lambda { |km, ki_hash={}|
|
2138
2967
|
\end_layout
|
2139
2968
|
|
2140
2969
|
\begin_layout LyX-Code
|
2141
|
-
|
2970
|
+
ki_hash.map { |c, ki| c / ki }.reduce( 1, :+ ) * km }
|
2142
2971
|
\end_layout
|
2143
2972
|
|
2144
2973
|
\begin_layout LyX-Code
|
2145
|
-
|
2974
|
+
Occupancy =
|
2146
2975
|
\end_layout
|
2147
2976
|
|
2148
2977
|
\begin_layout LyX-Code
|
2149
|
-
lambda { |km,
|
2978
|
+
lambda { |c, km, compet_inh_w_Ki_hash={}|
|
2150
2979
|
\end_layout
|
2151
2980
|
|
2152
2981
|
\begin_layout LyX-Code
|
2153
|
-
|
2982
|
+
c / ( c + Km_reduced.( km, compet_inh_w_Ki_hash ) ) }
|
2154
2983
|
\end_layout
|
2155
2984
|
|
2156
2985
|
\begin_layout LyX-Code
|
2157
|
-
|
2986
|
+
MM_with_inh_microM_per_second =
|
2158
2987
|
\end_layout
|
2159
2988
|
|
2160
2989
|
\begin_layout LyX-Code
|
2161
|
-
|
2990
|
+
lambda { |c, spec_act, kDa, enz_mol_per_cell, km, ki_hash={}|
|
2162
2991
|
\end_layout
|
2163
2992
|
|
2164
2993
|
\begin_layout LyX-Code
|
2165
|
-
|
2994
|
+
Vmax_per_s.( spec_act, kDa, enz_mol_per_cell ) *
|
2166
2995
|
\end_layout
|
2167
2996
|
|
2168
2997
|
\begin_layout LyX-Code
|
2169
|
-
|
2998
|
+
Occupancy.( c, km, ki_hash ) }
|
2170
2999
|
\end_layout
|
2171
3000
|
|
2172
3001
|
\begin_layout LyX-Code
|
2173
|
-
|
3002
|
+
MMi = MM_with_inh_microM_per_second
|
2174
3003
|
\end_layout
|
2175
3004
|
|
2176
|
-
\begin_layout
|
2177
|
-
|
3005
|
+
\begin_layout Standard
|
3006
|
+
Michaelis constants:
|
2178
3007
|
\end_layout
|
2179
3008
|
|
2180
3009
|
\begin_layout LyX-Code
|
2181
|
-
|
3010
|
+
TK1_Thymidine_Km = 5.0
|
2182
3011
|
\end_layout
|
2183
3012
|
|
2184
3013
|
\begin_layout LyX-Code
|
2185
|
-
|
3014
|
+
TYMS_DeoxyUMP_Km = 2.0
|
2186
3015
|
\end_layout
|
2187
3016
|
|
2188
3017
|
\begin_layout LyX-Code
|
2189
|
-
|
3018
|
+
RNR_UDP_Km = 1.0
|
2190
3019
|
\end_layout
|
2191
3020
|
|
2192
3021
|
\begin_layout LyX-Code
|
2193
|
-
|
3022
|
+
DNA_creation_speed = 3_000_000_000 / ( 12 * 3600 )
|
2194
3023
|
\end_layout
|
2195
3024
|
|
2196
3025
|
\begin_layout LyX-Code
|
2197
|
-
|
3026
|
+
TMPK_DeoxyTMP_Km = 12.0
|
2198
3027
|
\end_layout
|
2199
3028
|
|
2200
|
-
\begin_layout
|
2201
|
-
|
3029
|
+
\begin_layout Standard
|
3030
|
+
And finally, let us define the transitions:
|
2202
3031
|
\end_layout
|
2203
3032
|
|
2204
3033
|
\begin_layout LyX-Code
|
2205
|
-
|
3034
|
+
Transition name: :TK1_Thymidine_DeoxyTMP,
|
2206
3035
|
\end_layout
|
2207
3036
|
|
2208
3037
|
\begin_layout LyX-Code
|
2209
|
-
|
3038
|
+
|
3039
|
+
\color blue
|
3040
|
+
domain:
|
3041
|
+
\color inherit
|
3042
|
+
[ Thymidine, TK1, DeoxyTDP_DeoxyTTP_pool, DeoxyCTP,
|
2210
3043
|
\end_layout
|
2211
3044
|
|
2212
3045
|
\begin_layout LyX-Code
|
2213
|
-
|
3046
|
+
DeoxyCytidine, AMP, ADP, ATP ],
|
2214
3047
|
\end_layout
|
2215
3048
|
|
2216
3049
|
\begin_layout LyX-Code
|
2217
|
-
|
3050
|
+
stoichiometry: { Thymidine: -1, DeoxyTMP: 1 },
|
2218
3051
|
\end_layout
|
2219
3052
|
|
2220
3053
|
\begin_layout LyX-Code
|
2221
|
-
|
3054
|
+
rate: proc { |c, e, pool1, ci2, ci3, master1, master2, master3|
|
2222
3055
|
\end_layout
|
2223
3056
|
|
2224
3057
|
\begin_layout LyX-Code
|
2225
|
-
|
3058
|
+
ci1 = pool1 * master3 / ( master2 + master3 )
|
2226
3059
|
\end_layout
|
2227
3060
|
|
2228
3061
|
\begin_layout LyX-Code
|
2229
|
-
|
3062
|
+
MMi.( c, TK1_a, TK1_kDa, e, TK1_Thymidine_Km,
|
2230
3063
|
\end_layout
|
2231
3064
|
|
2232
3065
|
\begin_layout LyX-Code
|
2233
|
-
|
2234
|
-
\end_layout
|
2235
|
-
|
2236
|
-
\begin_layout Standard
|
2237
|
-
Michaelis constants:
|
3066
|
+
ci1 => 13.5, ci2 => 0.8, ci3 => 40.0 ) }
|
2238
3067
|
\end_layout
|
2239
3068
|
|
2240
3069
|
\begin_layout LyX-Code
|
2241
|
-
TK1_Thymidine_Km = 5.0
|
2242
|
-
\end_layout
|
2243
3070
|
|
2244
|
-
\begin_layout LyX-Code
|
2245
|
-
TYMS_DeoxyUMP_Km = 2.0
|
2246
3071
|
\end_layout
|
2247
3072
|
|
2248
3073
|
\begin_layout LyX-Code
|
2249
|
-
|
3074
|
+
Transition name: :TYMS_DeoxyUMP_DeoxyTMP,
|
2250
3075
|
\end_layout
|
2251
3076
|
|
2252
3077
|
\begin_layout LyX-Code
|
2253
|
-
|
3078
|
+
domain: [ DeoxyUMP_DeoxyUDP_pool, TYMS, AMP, ADP, ATP ],
|
2254
3079
|
\end_layout
|
2255
3080
|
|
2256
3081
|
\begin_layout LyX-Code
|
2257
|
-
|
3082
|
+
stoichiometry: { DeoxyUMP_DeoxyUDP_pool: -1, DeoxyTMP: 1 },
|
2258
3083
|
\end_layout
|
2259
3084
|
|
2260
|
-
\begin_layout
|
2261
|
-
|
3085
|
+
\begin_layout LyX-Code
|
3086
|
+
rate: proc { |pool, e, mono, di, tri|
|
2262
3087
|
\end_layout
|
2263
3088
|
|
2264
3089
|
\begin_layout LyX-Code
|
2265
|
-
|
3090
|
+
c = pool * di / ( mono + di )
|
2266
3091
|
\end_layout
|
2267
3092
|
|
2268
3093
|
\begin_layout LyX-Code
|
2269
|
-
|
2270
|
-
|
2271
|
-
domain:
|
2272
|
-
\color inherit
|
2273
|
-
[ Thymidine, TK1, DeoxyTDP_DeoxyTTP_pool,
|
3094
|
+
MMi.( c, TYMS_a, TYMS_kDa, e, TYMS_DeoxyUMP_Km
|
3095
|
+
) }
|
2274
3096
|
\end_layout
|
2275
3097
|
|
2276
3098
|
\begin_layout LyX-Code
|
2277
|
-
|
3099
|
+
|
2278
3100
|
\end_layout
|
2279
3101
|
|
2280
3102
|
\begin_layout LyX-Code
|
2281
|
-
|
3103
|
+
Transition name: :RNR_UDP_DeoxyUDP,
|
2282
3104
|
\end_layout
|
2283
3105
|
|
2284
3106
|
\begin_layout LyX-Code
|
2285
|
-
|
3107
|
+
domain: [ UMP_UDP_pool, RNR, DeoxyUMP_DeoxyUDP_pool, AMP, ADP,
|
3108
|
+
ATP ],
|
2286
3109
|
\end_layout
|
2287
3110
|
|
2288
3111
|
\begin_layout LyX-Code
|
2289
|
-
|
3112
|
+
stoichiometry: { UMP_UDP_pool: -1, DeoxyUMP_DeoxyUDP_pool: 1
|
3113
|
+
},
|
2290
3114
|
\end_layout
|
2291
3115
|
|
2292
3116
|
\begin_layout LyX-Code
|
2293
|
-
|
3117
|
+
rate: proc { |pool, e, mono, di, tri|
|
2294
3118
|
\end_layout
|
2295
3119
|
|
2296
3120
|
\begin_layout LyX-Code
|
2297
|
-
|
3121
|
+
c = pool * di / ( mono + di )
|
2298
3122
|
\end_layout
|
2299
3123
|
|
2300
3124
|
\begin_layout LyX-Code
|
2301
|
-
|
3125
|
+
MMi.( c, RNR_a, RNR_kDa, e, RNR_UDP_Km ) }
|
2302
3126
|
\end_layout
|
2303
3127
|
|
2304
3128
|
\begin_layout LyX-Code
|
2305
|
-
|
3129
|
+
|
2306
3130
|
\end_layout
|
2307
3131
|
|
2308
3132
|
\begin_layout LyX-Code
|
2309
|
-
|
3133
|
+
Transition name: :DNA_polymerase_consumption_of_DeoxyTTP,
|
2310
3134
|
\end_layout
|
2311
3135
|
|
2312
3136
|
\begin_layout LyX-Code
|
2313
|
-
|
3137
|
+
stoichiometry: { DeoxyTDP_DeoxyTTP_pool: -1 },
|
2314
3138
|
\end_layout
|
2315
3139
|
|
2316
3140
|
\begin_layout LyX-Code
|
2317
|
-
|
3141
|
+
rate: proc { DNA_creation_speed / 4 }
|
2318
3142
|
\end_layout
|
2319
3143
|
|
2320
3144
|
\begin_layout LyX-Code
|
2321
|
-
|
2322
|
-
) }
|
3145
|
+
|
2323
3146
|
\end_layout
|
2324
3147
|
|
2325
3148
|
\begin_layout LyX-Code
|
2326
|
-
|
3149
|
+
Transition name: :TMPK_DeoxyTMP_DeoxyTDP,
|
2327
3150
|
\end_layout
|
2328
3151
|
|
2329
3152
|
\begin_layout LyX-Code
|
2330
|
-
|
2331
|
-
ATP ],
|
3153
|
+
domain: [ DeoxyTMP, TMPK, DeoxyTDP_DeoxyTTP_pool, DeoxyGMP, AMP,
|
3154
|
+
ADP, ATP ],
|
2332
3155
|
\end_layout
|
2333
3156
|
|
2334
3157
|
\begin_layout LyX-Code
|
2335
|
-
|
3158
|
+
stoichiometry: { DeoxyTMP: -1, TMPK: 0, DeoxyTDP_DeoxyTTP_pool:
|
2336
3159
|
1 },
|
2337
3160
|
\end_layout
|
2338
3161
|
|
2339
3162
|
\begin_layout LyX-Code
|
2340
|
-
|
3163
|
+
rate: proc { |c, e, pool, ci4, mono, di, tri|
|
2341
3164
|
\end_layout
|
2342
3165
|
|
2343
3166
|
\begin_layout LyX-Code
|
2344
|
-
|
3167
|
+
ci1 = di
|
2345
3168
|
\end_layout
|
2346
3169
|
|
2347
3170
|
\begin_layout LyX-Code
|
2348
|
-
|
3171
|
+
ci2 = pool * di / ( di + tri )
|
2349
3172
|
\end_layout
|
2350
3173
|
|
2351
3174
|
\begin_layout LyX-Code
|
2352
|
-
|
3175
|
+
ci3 = pool * tri / ( di + tri )
|
2353
3176
|
\end_layout
|
2354
3177
|
|
2355
3178
|
\begin_layout LyX-Code
|
2356
|
-
|
3179
|
+
MMi.( c, TMPK_a, TMPK_kDa, e, TMPK_DeoxyTMP_Km,
|
2357
3180
|
\end_layout
|
2358
3181
|
|
2359
3182
|
\begin_layout LyX-Code
|
2360
|
-
|
3183
|
+
ci1 => 250.0, ci2 => 30.0, ci3 => 750, ci4 =>
|
3184
|
+
117 ) }
|
2361
3185
|
\end_layout
|
2362
3186
|
|
2363
3187
|
\begin_layout LyX-Code
|
2364
|
-
|
3188
|
+
# require 'mathn'
|
2365
3189
|
\end_layout
|
2366
3190
|
|
2367
3191
|
\begin_layout LyX-Code
|
2368
|
-
|
2369
|
-
AMP, ATP ],
|
3192
|
+
Transition name: :PhosphataseI,
|
2370
3193
|
\end_layout
|
2371
3194
|
|
2372
3195
|
\begin_layout LyX-Code
|
2373
|
-
|
2374
|
-
1 },
|
3196
|
+
stoichiometry: { DeoxyTMP: -1, Thymidine: 1 },
|
2375
3197
|
\end_layout
|
2376
3198
|
|
2377
3199
|
\begin_layout LyX-Code
|
2378
|
-
|
3200
|
+
rate: 0.04
|
2379
3201
|
\end_layout
|
2380
3202
|
|
2381
3203
|
\begin_layout LyX-Code
|
2382
|
-
|
3204
|
+
|
2383
3205
|
\end_layout
|
2384
3206
|
|
2385
3207
|
\begin_layout LyX-Code
|
2386
|
-
|
3208
|
+
Transition name: :PhosphataseII,
|
2387
3209
|
\end_layout
|
2388
3210
|
|
2389
3211
|
\begin_layout LyX-Code
|
2390
|
-
|
3212
|
+
stoichiometry: { DeoxyTDP_DeoxyTTP_pool: -1, DeoxyTMP: 1 },
|
2391
3213
|
\end_layout
|
2392
3214
|
|
2393
3215
|
\begin_layout LyX-Code
|
2394
|
-
|
3216
|
+
rate: 0.01
|
3217
|
+
\end_layout
|
3218
|
+
|
3219
|
+
\begin_layout Standard
|
3220
|
+
The created net can be visualized by:
|
2395
3221
|
\end_layout
|
2396
3222
|
|
2397
3223
|
\begin_layout LyX-Code
|
2398
|
-
|
2399
|
-
=> 117 ) }
|
3224
|
+
net.visualize
|
2400
3225
|
\end_layout
|
2401
3226
|
|
2402
3227
|
\begin_layout Standard
|
@@ -2407,20 +3232,32 @@ The simulation should work.
|
|
2407
3232
|
run!
|
2408
3233
|
\end_layout
|
2409
3234
|
|
3235
|
+
\begin_layout Standard
|
3236
|
+
State recording can be plotted by:
|
3237
|
+
\end_layout
|
3238
|
+
|
3239
|
+
\begin_layout LyX-Code
|
3240
|
+
recording.plot
|
3241
|
+
\end_layout
|
3242
|
+
|
3243
|
+
\begin_layout Standard
|
3244
|
+
Flux of the transitions can be plotted by:
|
3245
|
+
\end_layout
|
3246
|
+
|
2410
3247
|
\begin_layout LyX-Code
|
2411
|
-
|
3248
|
+
recording.flux.plot
|
2412
3249
|
\end_layout
|
2413
3250
|
|
2414
3251
|
\begin_layout Part*
|
2415
|
-
Example
|
3252
|
+
Example V: Using SY.
|
2416
3253
|
\end_layout
|
2417
3254
|
|
2418
3255
|
\begin_layout Standard
|
2419
|
-
Here,
|
3256
|
+
Here, we'll take a look at using
|
2420
3257
|
\family typewriter
|
2421
|
-
|
3258
|
+
YNelson
|
2422
3259
|
\family default
|
2423
|
-
|
3260
|
+
with
|
2424
3261
|
\family typewriter
|
2425
3262
|
\color blue
|
2426
3263
|
SY
|
@@ -2441,10 +3278,9 @@ Example III
|
|
2441
3278
|
\family typewriter
|
2442
3279
|
SY
|
2443
3280
|
\family default
|
2444
|
-
is to take care of all this, to relieve the modeler from
|
2445
|
-
clean up the model code, and let the modeler concentrate
|
2446
|
-
|
2447
|
-
so far.
|
3281
|
+
is to take care of all this, to relieve the modeler from the task of unit
|
3282
|
+
conversion, to clean up the model code, and let the modeler concentrate
|
3283
|
+
on the real issue.
|
2448
3284
|
\end_layout
|
2449
3285
|
|
2450
3286
|
\begin_layout Subsection*
|
@@ -2529,19 +3365,19 @@ SY::Magnitude
|
|
2529
3365
|
\end_layout
|
2530
3366
|
|
2531
3367
|
\begin_layout LyX-Code
|
2532
|
-
1.m.
|
3368
|
+
1.m.quantity
|
2533
3369
|
\end_layout
|
2534
3370
|
|
2535
3371
|
\begin_layout LyX-Code
|
2536
|
-
#=> Length
|
3372
|
+
#=> #<Quantity:Length±>
|
2537
3373
|
\end_layout
|
2538
3374
|
|
2539
3375
|
\begin_layout LyX-Code
|
2540
|
-
1.cm.min⁻¹.
|
3376
|
+
1.cm.min⁻¹.quantity
|
2541
3377
|
\end_layout
|
2542
3378
|
|
2543
3379
|
\begin_layout LyX-Code
|
2544
|
-
#=> Speed
|
3380
|
+
#=> #<Quantity:Speed±>
|
2545
3381
|
\end_layout
|
2546
3382
|
|
2547
3383
|
\begin_layout Standard
|
@@ -2591,7 +3427,7 @@ SY
|
|
2591
3427
|
\family default
|
2592
3428
|
and
|
2593
3429
|
\family typewriter
|
2594
|
-
|
3430
|
+
YNelson
|
2595
3431
|
\end_layout
|
2596
3432
|
|
2597
3433
|
\begin_layout Standard
|
@@ -2627,7 +3463,11 @@ B_decay = Transition s: { B: -1 }, rate: 0.002.s⁻¹
|
|
2627
3463
|
\end_layout
|
2628
3464
|
|
2629
3465
|
\begin_layout LyX-Code
|
2630
|
-
#=>
|
3466
|
+
#=>
|
3467
|
+
\family typewriter
|
3468
|
+
YNelson
|
3469
|
+
\family default
|
3470
|
+
::Transition[ B_decay: stoichiometric transition with rate ]
|
2631
3471
|
\end_layout
|
2632
3472
|
|
2633
3473
|
\begin_layout Standard
|
@@ -2635,9 +3475,9 @@ Now we have created places and transitions, whose marking and rate closures
|
|
2635
3475
|
are defined in physical units.
|
2636
3476
|
Presently,
|
2637
3477
|
\family typewriter
|
2638
|
-
|
3478
|
+
YNelson::TimedSimulation
|
2639
3479
|
\family default
|
2640
|
-
will not accept such
|
3480
|
+
will not accept such Petri net, so the only thing we can do is play the
|
2641
3481
|
token game ourselves:
|
2642
3482
|
\end_layout
|
2643
3483
|
|
@@ -2747,6 +3587,101 @@ B.marking.in :µM
|
|
2747
3587
|
#=> 5797.976678013365
|
2748
3588
|
\end_layout
|
2749
3589
|
|
3590
|
+
\begin_layout Part*
|
3591
|
+
Example VI: Other simulation methods
|
3592
|
+
\end_layout
|
3593
|
+
|
3594
|
+
\begin_layout Standard
|
3595
|
+
At this moment, the default simulation method is implicit Euler (or
|
3596
|
+
\family typewriter
|
3597
|
+
pseudo_euler
|
3598
|
+
\family default
|
3599
|
+
–
|
3600
|
+
\emph on
|
3601
|
+
pseudo
|
3602
|
+
\emph default
|
3603
|
+
because timeless transitions and assignment transtitions also fire at each
|
3604
|
+
step in time).
|
3605
|
+
From other simulation methods, Gillespie algorithm is available:
|
3606
|
+
\end_layout
|
3607
|
+
|
3608
|
+
\begin_layout LyX-Code
|
3609
|
+
require 'y_nelson' and include YNelson
|
3610
|
+
\end_layout
|
3611
|
+
|
3612
|
+
\begin_layout LyX-Code
|
3613
|
+
|
3614
|
+
\end_layout
|
3615
|
+
|
3616
|
+
\begin_layout LyX-Code
|
3617
|
+
A = Place m!: 10
|
3618
|
+
\end_layout
|
3619
|
+
|
3620
|
+
\begin_layout LyX-Code
|
3621
|
+
B = Place m!: 10
|
3622
|
+
\end_layout
|
3623
|
+
|
3624
|
+
\begin_layout LyX-Code
|
3625
|
+
AB = Place m!: 0
|
3626
|
+
\end_layout
|
3627
|
+
|
3628
|
+
\begin_layout LyX-Code
|
3629
|
+
AB_association = TS A: -1, B: -1, AB: 1, rate: 0.1
|
3630
|
+
\end_layout
|
3631
|
+
|
3632
|
+
\begin_layout LyX-Code
|
3633
|
+
AB_dissociation = TS AB: -1, A: 1, B: 1, rate: 0.1
|
3634
|
+
\end_layout
|
3635
|
+
|
3636
|
+
\begin_layout LyX-Code
|
3637
|
+
A2B = TS A: -1, B: 1, rate: 0.05
|
3638
|
+
\end_layout
|
3639
|
+
|
3640
|
+
\begin_layout LyX-Code
|
3641
|
+
B2A = TS A: 1, B: -1, rate: 0.07
|
3642
|
+
\end_layout
|
3643
|
+
|
3644
|
+
\begin_layout LyX-Code
|
3645
|
+
|
3646
|
+
\end_layout
|
3647
|
+
|
3648
|
+
\begin_layout LyX-Code
|
3649
|
+
set_step 1
|
3650
|
+
\end_layout
|
3651
|
+
|
3652
|
+
\begin_layout LyX-Code
|
3653
|
+
set_target_time 50
|
3654
|
+
\end_layout
|
3655
|
+
|
3656
|
+
\begin_layout LyX-Code
|
3657
|
+
set_sampling 1
|
3658
|
+
\end_layout
|
3659
|
+
|
3660
|
+
\begin_layout LyX-Code
|
3661
|
+
set_simulation_method :gillespie
|
3662
|
+
\end_layout
|
3663
|
+
|
3664
|
+
\begin_layout LyX-Code
|
3665
|
+
|
3666
|
+
\end_layout
|
3667
|
+
|
3668
|
+
\begin_layout LyX-Code
|
3669
|
+
run!
|
3670
|
+
\end_layout
|
3671
|
+
|
3672
|
+
\begin_layout LyX-Code
|
3673
|
+
print_recording
|
3674
|
+
\end_layout
|
3675
|
+
|
3676
|
+
\begin_layout LyX-Code
|
3677
|
+
plot_state
|
3678
|
+
\end_layout
|
3679
|
+
|
3680
|
+
\begin_layout Standard
|
3681
|
+
The state recording should show the random walk of the system state over
|
3682
|
+
50 time units.
|
3683
|
+
\end_layout
|
3684
|
+
|
2750
3685
|
\begin_layout LyX-Code
|
2751
3686
|
|
2752
3687
|
\end_layout
|