Exploring Chemical Equations

Populating the interactive namespace from numpy and matplotlib

pyndamics3 version 0.0.32


source

ChemSimulation

 ChemSimulation (eqnstr, verbose=True, **kwargs)
sim=ChemSimulation(
"""
D --k1--> D+M
M --k2--> M+P
M --k3--> ϕ
P --k4--> ϕ
""",D=1,M=0=0,P=0,k1=.01,k3=0.00577,k4=0.0001925,k2=20*0.00577)
pyndamics3  version  0.0.27
['D'] k1 ['D', 'M']
['M'] k2 ['M', 'P']
['M'] k3 ['ϕ']
['P'] k4 ['ϕ']
Components ['D', 'M', 'P', 'ϕ']
Parameters ['k1', 'k2', 'k3', 'k4']
diffeqs ["D' = 0", "M' =  +k1*D -k3*M", "P' =  +k2*M -k4*P"]
sim=ChemSimulation("""
A   -->k1->   B
B   -->k_1->  A
A+B -->k2->   C
C   -->k_2->  A+B
""",A=1,B=1,C=0,k1=1,k_1=2,k2=3,k_2=4)

print()

print(sim.equations())
['A'] k1 ['B']
['B'] k_1 ['A']
['A', 'B'] k2 ['C']
['C'] k_2 ['A', 'B']
Components ['A', 'B', 'C']
Parameters ['k1', 'k2', 'k_1', 'k_2']
diffeqs ["A' =  -k1*A +k_1*B -k2*A*B +k_2*C", "B' =  +k1*A -k_1*B -k2*A*B +k_2*C", "C' =  +2*k2*A*B -2*k_2*C"]

A'=-k1*A +k_1*B -k2*A*B +k_2*C
B'=+k1*A -k_1*B -k2*A*B +k_2*C
C'=+2*k2*A*B -2*k_2*C
k1=1
k2=3
k_1=2
k_2=4
sim.params()
assert sim.equations()=="""
A'=-k1*A +k_1*B -k2*A*B +k_2*C
B'=+k1*A -k_1*B -k2*A*B +k_2*C
C'=+2*k2*A*B -2*k_2*C
k1=1
k2=3
k_1=2
k_2=4
""".lstrip()
for c in sim.components:
    c.plot=1
sim.run(10)

<Figure size 864x576 with 0 Axes>
sim=ChemSimulation(
"""
D --k1--> D+M
M --k2--> M+P
M --k3--> ϕ
P --k4--> ϕ
""",D=1,M=0=0,P=0,k1=.01,k3=0.00577,k4=0.0001925,k2=20*0.00577)
['D'] k1 ['D', 'M']
['M'] k2 ['M', 'P']
['M'] k3 ['ϕ']
['P'] k4 ['ϕ']
print(sim.equations())
D'=0
M'=+k1*D -k3*M
P'=+k2*M -k4*P
k1=0.01
k2=0.1154
k3=0.00577
k4=0.0001925

These are wrong – need to deal with squares

sim=ChemSimulation("""
A   -->k1->   X
B+X   -->k2->  Y+D
2*X+Y -->k3->   3*X
X   -->k4->  E
""",A=1,B=2,D=3,X=0,Y=1,k1=1,k2=1,k3=1,k4=1)

print()

print(sim.equations())
['A'] k1 ['X']
['B', 'X'] k2 ['Y', 'D']
['2*X', 'Y'] k3 ['3*X']
['X'] k4 ['E']
Components ['2*X', '3*X', 'A', 'B', 'D', 'E', 'X', 'Y']
Parameters ['k1', 'k2', 'k3', 'k4']
diffeqs ["2*X' =  -k3*2*X*Y", "3*X' =  +2*k3*2*X*Y", "A' =  -k1*A", "B' =  -2*k2*B*X", "D' =  +2*k2*B*X", "E' =  +k4*X", "X' =  +k1*A -2*k2*B*X -k4*X", "Y' =  +2*k2*B*X -k3*2*X*Y"]

2*X'=-k3*2*X*Y
3*X'=+2*k3*2*X*Y
A'=-k1*A
B'=-2*k2*B*X
D'=+2*k2*B*X
E'=+k4*X
X'=+k1*A -2*k2*B*X -k4*X
Y'=+2*k2*B*X -k3*2*X*Y
k1=1
k2=1
k3=1
k4=1