/
bokeh_interactive_robertson.py
36 lines (31 loc) · 1.2 KB
/
bokeh_interactive_robertson.py
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
"""
Interactive kinetics app with sliders.
Start by runing:
$ bokeh serve interactive.py
Add --show argument or navigate to:
http://localhost:5006/interactive
"""
from collections import defaultdict
import sys
from chempy import Reaction, ReactionSystem
from chempy.kinetics.rates import MassAction
from chempy.util.bkh import integration_with_sliders
def get_rsys():
r1 = Reaction({'A'}, {'B'}, MassAction([4./100], unique_keys=['k1']), name='R1: A cons.')
r2 = Reaction({'B', 'C'}, {'A', 'C'}, MassAction([1e4], unique_keys=['k2']), name='R2: A reform.')
r3 = Reaction({'B': 2}, {'B', 'C'}, MassAction([3e7], unique_keys=['k3']), name='R3: C form.')
return ReactionSystem([r1, r2, r3])
if __name__.startswith('bk_'):
# TODO: better xlim, ylim, ranges for c0
from bokeh.io import curdoc
curdoc().add_root(integration_with_sliders(
get_rsys(), tend=1e3,
c0=defaultdict(float, {'A': 1}),
parameters={'k1': 4./100, 'k2': 1e4, 'k3': 3e7},
x_axis_type='log', y_axis_type='log',
integrate_kwargs=dict(integrator='cvode')
))
elif __name__ == '__main__':
import warnings
warnings.warn("Run using 'bokeh serve %s'" % __file__)
sys.exit(1)