Tutorial 8 (Rule-based Modeling)

This is a tutorial for E-Cell4.


In [1]:
from ecell4.core import *

In [2]:
sp1 = Species("A(b^1).B(b^1)")
sp2 = Species("A(b^1).A(b^1)")
print(sp1.count(Species("A")))
print(sp2.count(Species("A")))
print(sp1.count(Species("A(b)")))
print(sp1.count(Species("_")))


1
2
0
2

In [3]:
rr1 = create_unbinding_reaction_rule(Species("A(b^1).B(b^1)"), Species("A(b)"), Species("B(b)"), 1.0)
rr2 = create_binding_reaction_rule(Species("A(b)"), Species("B(b)"), Species("A(b^1).B(b^1)"), 1.0)
print(rr1.count([Species("A(b^1).B(b^1)")]))
print(rr1.count([Species("A(b^1,c).A(b^2,c^1).B(b^2,c^3).A(b^3,c)")]))
print(rr2.count([Species("A(b,c^1).A(b,c^1)"), Species("B(b,c^1).B(b,c^1)")]))


1
1
4

In [4]:
print([rr.as_string() for rr in rr1.generate([Species("A(b^1).B(b^1)")])])
print([rr.as_string() for rr in rr2.generate([Species("A(b,c=u^1).A(b,c=p^1)"), Species("B(b,c=u^1).B(b,c=p^1)")])])


['A(b^1).B(b^1)>A(b)+B(b)|1']
['A(b,c=u^1).A(b,c=p^1)+B(b,c=u^1).B(b,c=p^1)>A(b,c=p^1).A(b^2,c=u^1).B(b^2,c=u^3).B(b,c=p^3)|1', 'A(b,c=u^1).A(b,c=p^1)+B(b,c=u^1).B(b,c=p^1)>A(b,c=p^1).A(b^2,c=u^1).B(b^2,c=p^3).B(b,c=u^3)|1', 'A(b,c=u^1).A(b,c=p^1)+B(b,c=u^1).B(b,c=p^1)>A(b,c=u^1).A(b^2,c=p^1).B(b^2,c=u^3).B(b,c=p^3)|1', 'A(b,c=u^1).A(b,c=p^1)+B(b,c=u^1).B(b,c=p^1)>A(b,c=u^1).A(b^2,c=p^1).B(b^2,c=p^3).B(b,c=u^3)|1']

In [5]:
sp3 = Species("_1._1")
print(Species("A(b^1,c).B(b^1,c^2).A(b,c^2)").count(sp3))
print(Species("A(b^1,c^3).B(b^1,c^2).A(b,c^2).B(b^3,c)").count(sp3))


2
4

In [6]:
rr3 = create_binding_reaction_rule(Species("_1(b)"), Species("_1(b)"), Species("_1(b^1)._1(b^1)"), 1.0)
rr4 = create_unbinding_reaction_rule(Species("A(c1=_1,c2=_2)"), Species("B(c=_2)"), Species("C(c=_1)"), 1.0)
print([rr.as_string() for rr in rr3.generate([Species("A(b,c=u^1).B(b,c=p^1)"), Species("A(b,c=p^1).B(b,c=u^1)")])])
print([rr.as_string() for rr in rr4.generate([Species("A(c1=c12, c2=c13)")])])
print([rr.as_string() for rr in rr4.generate([Species("A(c1=c13, c2=c12)")])])


['A(b,c=u^1).B(b,c=p^1)+A(b,c=p^1).B(b,c=u^1)>A(b^1,c=p^2).A(b^1,c=u^3).B(b,c=p^3).B(b,c=u^2)|1', 'A(b,c=u^1).B(b,c=p^1)+A(b,c=p^1).B(b,c=u^1)>A(b,c=p^1).B(b^2,c=u^1).B(b^2,c=p^3).A(b,c=u^3)|1']
['A(c1=c12,c2=c13)>B(c=c13)+C(c=c12)|1']
['A(c1=c13,c2=c12)>B(c=c12)+C(c=c13)|1']

In [7]:
rr5 = create_unimolecular_reaction_rule(Species("A(p=u^_)"), Species("A(p=p^_)"), 1.0)
print([rr.as_string() for rr in rr5.generate([Species("A(p=u^1).KK(b^1)")])])


['A(p=u^1).KK(b^1)>A(p=p^1).KK(b^1)|1']

In [7]: