Skip to content

Commit

Permalink
Tutorial fixes (#422)
Browse files Browse the repository at this point in the history
* Fix incorrect state (#421)
* Update figure (wrong x-axis)
* Fix observable trajectory
* Correct some indentation

Fixes: #421
  • Loading branch information
alubbock committed Mar 5, 2019
1 parent 01b7874 commit 869e105
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 48 deletions.
Binary file modified doc/examples/fig_mymodel4.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion doc/examples/mymodel1.py
Expand Up @@ -6,6 +6,6 @@

# declare monomers
Monomer('C8', ['b'])
Monomer('Bid', ['b', 'S'], {'S':['u', 't']})
Monomer('Bid', ['b', 'S'], {'S': ['u', 't']})


2 changes: 1 addition & 1 deletion doc/examples/mymodel2.py
Expand Up @@ -6,7 +6,7 @@

# declare monomers
Monomer('C8', ['b'])
Monomer('Bid', ['b', 'S'], {'S':['u', 't']})
Monomer('Bid', ['b', 'S'], {'S': ['u', 't']})

# input the parameter values
Parameter('kf', 1.0e-07)
Expand Down
4 changes: 2 additions & 2 deletions doc/examples/mymodel3.py
Expand Up @@ -6,14 +6,14 @@

# declare monomers
Monomer('C8', ['b'])
Monomer('Bid', ['b', 'S'], {'S':['u', 't']})
Monomer('Bid', ['b', 'S'], {'S': ['u', 't']})

# input the parameter values
Parameter('kf', 1.0e-07)
Parameter('kr', 1.0e-03)
Parameter('kc', 1.0)

# now input the rules
Rule('C8_Bid_bind', C8(b=None) + Bid(b=None, S=None) | C8(b=1) % Bid(b=1, S=None), kf, kr)
Rule('C8_Bid_bind', C8(b=None) + Bid(b=None, S='u') | C8(b=1) % Bid(b=1, S='u'), kf, kr)
Rule('tBid_from_C8Bid', C8(b=1) % Bid(b=1, S='u') >> C8(b=None) + Bid(b=None, S='t'), kc)

2 changes: 1 addition & 1 deletion doc/examples/mymodel4.py
Expand Up @@ -14,7 +14,7 @@
Parameter('kc', 1.0)

# now input the rules
Rule('C8_Bid_bind', C8(b=None) + Bid(b=None, S=None) | C8(b=1) % Bid(b=1, S=None), *[kf, kr])
Rule('C8_Bid_bind', C8(b=None) + Bid(b=None, S='u') | C8(b=1) % Bid(b=1, S='u'), *[kf, kr])
Rule('tBid_from_C8Bid', C8(b=1) % Bid(b=1, S='u') >> C8(b=None) + Bid(b=None, S='t'), kc)

# initial conditions
Expand Down
6 changes: 3 additions & 3 deletions doc/examples/mymodel5.py
Expand Up @@ -4,13 +4,13 @@

def catalyze(enz, sub, site, state1, state2, kf, kr, kc): # function call
"""2-step catalytic process""" # reaction name
r1_name = '%s_assoc_%s' % (enz.name, sub.name) # name of association reaction for rule
r1_name = '%s_assoc_%s' % (enz.name, sub.name) # name of association reaction for rule
r2_name = '%s_diss_%s' % (enz.name, sub.name) # name of dissociation reaction for rule
E = enz(b=None) # define enzyme state in function
S = sub({'b': None, site: state1}) # define substrate state in function
ES = enz(b=1) % sub({'b': 1, site: state1}) # define state of enzyme:substrate complex
P = sub({'b': None, site: state2}) # define state of product
Rule(r1_name, E + S | ES, kf, kr) # rule for enzyme + substrate association (bidirectional)
Rule(r1_name, E + S | ES, kf, kr) # rule for enzyme + substrate association (bidirectional)
Rule(r2_name, ES >> E + P, kc) # rule for enzyme:substrate dissociation (unidirectional)

# instantiate a model
Expand All @@ -26,7 +26,7 @@ def catalyze(enz, sub, site, state1, state2, kf, kr, kc): # function call
Parameter('kc', 1.0)

# OLD RULES
# Rule('C8_Bid_bind', C8(b=None) + Bid(b=None, S=None) | C8(b=1) % Bid(b=1, S=None), *[kf, kr])
# Rule('C8_Bid_bind', C8(b=None) + Bid(b=None, S='u') | C8(b=1) % Bid(b=1, S='u'), *[kf, kr])
# Rule('tBid_from_C8Bid', C8(b=1) % Bid(b=1, S='u') >> C8(b=None) + Bid(b=None, S='t'), kc)
#
# NEW RULES
Expand Down
88 changes: 48 additions & 40 deletions doc/tutorial.rst
Expand Up @@ -355,20 +355,23 @@ python prompts).::

>>> import mymodel as m
>>> m.model.monomers
{'C8': Monomer(name='C8', sites=['b'], site_states={}),
'Bid': Monomer(name='Bid', sites=['b', 'S'], site_states={'S': ['u', 't']})}
ComponentSet([
Monomer('C8', ['b']),
Monomer('Bid', ['b', 'S'], {'S': ['u', 't']}),
])
>>> model.parameters
{'kf': Parameter(name='kf', value=1.0e-07),
'kr': Parameter(name='kr', value=1.0e-03),
'kc': Parameter(name='kc', value=1.0 )}
ComponentSet([
Parameter('kf', 1e-07),
Parameter('kr', 0.001),
Parameter('kc', 1.0),
Parameter('C8_0', 1000.0),
Parameter('Bid_0', 10000.0),
])
>>> m.model.rules
{'C8_Bid_bind': Rule(name='C8_Bid_bind', reactants=C8(b=None) +
Bid(b=None, S='u'), products=C8(b=1) % Bid(b=1, S='u'),
rate_forward=Parameter(name='kf', value=1.0e-07),
rate_reverse=Parameter(name='kr', value=1.0e-03)),
'tBid_from_C8Bid': Rule(name='tBid_from_C8Bid', reactants=C8(b=1) %
Bid(b=1, S='u'u), products=C8(b=None) + Bid(b=None, S=t),
rate_forward=Parameter(name='kc', value=1.0))}
ComponentSet([
Rule('C8_Bid_bind', C8(b=None) + Bid(b=None, S='u') | C8(b=1) % Bid(b=1, S='u'), kf, kr),
Rule('tBid_from_C8Bid', C8(b=1) % Bid(b=1, S='u') >> C8(b=None) + Bid(b=None, S='t'), kc),
])

With this we are almost ready to run a simulation, all we need now is
to specify the initial conditions of the system.
Expand Down Expand Up @@ -440,26 +443,31 @@ one shown (output shown below the ``'>>>'``` prompts)::

>>> import mymodel as m
>>> m.model.monomers
{'C8': Monomer(name='C8', sites=['b'], site_states={}),
'Bid': Monomer(name='Bid', sites=['b', 'S'], site_states={'S': ['u', 't']})}
ComponentSet([
Monomer('C8', ['b']),
Monomer('Bid', ['b', 'S'], {'S': ['u', 't']}),
])
>>> m.model.parameters
{'kf': Parameter(name='kf', value=1.0e-07),
'kr': Parameter(name='kr', value=1.0e-03),
'kc': Parameter(name='kc', value=1.0 ),
'C8_0': Parameter(name='C8_0', value=1000),
'Bid_0': Parameter(name='Bid_0', value=10000)}
ComponentSet([
Parameter('kf', 1e-07),
Parameter('kr', 0.001),
Parameter('kc', 1.0),
Parameter('C8_0', 1000.0),
Parameter('Bid_0', 10000.0),
])
>>> m.model.observables
{'obsC8': <pysb.core.Observable object at 0x104b2c4d0>,
'obsBid': <pysb.core.Observable object at 0x104b2c5d0>,
'obstBid': <pysb.core.Observable object at 0x104b2c6d0>}
ComponentSet([
Observable('obsC8', C8(b=None)),
Observable('obsBid', Bid(b=None, S='u')),
Observable('obstBid', Bid(b=None, S='t')),
])
>>> m.model.initials
[Initial(C8(b=None), C8_0), Initial(Bid(b=None, S='u'), Bid_0)]
>>> m.model.rules
{'C8_Bid_bind': Rule(name='C8_Bid_bind', reactants=C8(b=None) +
Bid(b=None, S=None), products=C8(b=1) % Bid(b=1, S=None),
rate_forward=Parameter(name='kf', value=1.0e-07), rate_reverse=Parameter(name='kr', value=1.0e-03)),
'tBid_from_C8Bid': Rule(name='tBid_from_C8Bid', reactants=C8(b=1)
% Bid(b=1, S=u), products=C8(b=None) + Bid(b=None, S=t), rate_forward=Parameter(name='kc', value=1.0))}
ComponentSet([
Rule('C8_Bid_bind', C8(b=None) + Bid(b=None, S='u') | C8(b=1) % Bid(b=1, S='u'), kf, kr),
Rule('tBid_from_C8Bid', C8(b=1) % Bid(b=1, S='u') >> C8(b=None) + Bid(b=None, S='t'), kc),
])

With this we are now ready to run a simulation! The parameter values
for the simulation were taken directly from typical values in the
Expand Down Expand Up @@ -536,19 +544,19 @@ To verify that the simulation run you can see the content of the
observable defined previously::

>>> yout['obsBid']
array([ 10000. , 9601.77865674, 9224.08135988, 8868.37855506,
8534.45591732, 8221.19944491, 7927.08884234, 7650.48970981,
7389.81105408, 7143.5816199 , 6910.47836131, 6689.32927828,
6479.10347845, 6278.89607041, 6087.91189021, 5905.45001654,
5730.89003662, 5563.68044913, 5403.32856328, 5249.39176146,
5101.47069899, 4959.20384615, 4822.26262101, 4690.34720441,
4563.18294803, 4440.51745347, 4322.11815173, 4207.77021789,
4097.27471952, 3990.44698008, 3887.11517373, 3787.11923497,
3690.30945136, 3596.54594391, 3505.69733323, 3417.64025401,
3332.25897699, 3249.44415872, 3169.09326717, 3091.10923365,
3015.40034777, 2941.87977234, 2870.4652525 , 2801.07879018,
2733.64632469, 2668.09744369, 2604.36497901, 2542.38554596,
2482.09776367, 2423.44473279])
array([10000. , 9600.82692793, 9217.57613337, 8849.61042582,
8496.32045796, 8157.12260855, 7831.45589982, 7518.7808708 ,
7218.58018014, 6930.35656027, 6653.63344844, 6387.95338333,
6132.87596126, 5887.9786933 , 5652.8553495 , 5427.11687478,
5210.38806188, 5002.31066362, 4802.53910592, 4610.74136092,
4426.60062334, 4249.81001719, 4080.07733278, 3917.1205927 ,
3760.66947203, 3610.46475238, 3466.25716389, 3327.80762075,
3194.88629188, 3067.27263727, 2944.75491863, 2827.12948551,
2714.20140557, 2605.78289392, 2501.69402243, 2401.76203172,
2305.8208689 , 2213.71139112, 2125.28052884, 2040.38151896,
1958.87334783, 1880.62057855, 1805.49336521, 1733.36675338,
1664.12107023, 1597.64120743, 1533.81668871, 1472.54158105,
1413.71396601, 1357.23623273])

As you may recall we named some observables in the `Observables`_
section above. The variable *yout* contains an array of all the ODE
Expand Down

0 comments on commit 869e105

Please sign in to comment.