Skip to content

Commit 1c5b42c

Browse files
Merge pull request #66 from isaacsas/update-for-catalyst
update jump problems for catalyst
2 parents e48b957 + ceca8a5 commit 1c5b42c

File tree

3 files changed

+70
-42
lines changed

3 files changed

+70
-42
lines changed

Project.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,17 @@ authors = ["Chris Rackauckas <[email protected]>"]
44
version = "4.8.1"
55

66
[deps]
7+
Catalyst = "479239e8-5488-4da2-87a7-35f2df7eef83"
78
DiffEqBase = "2b5f629d-d688-5b77-993f-72d75c75574e"
8-
DiffEqBiological = "eb300fae-53e8-50a0-950c-e21f52c2b7e0"
99
DiffEqOperators = "9fdde737-9c7f-55bf-ade8-46b3f136cc48"
1010
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
1111
Markdown = "d6f4376e-aef5-505a-96c1-9c027394607a"
1212
ModelingToolkit = "961ee093-0014-501f-94e3-6117800e7a78"
1313
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
1414

1515
[compat]
16+
Catalyst = "5.0.5"
1617
DiffEqBase = "6"
17-
DiffEqBiological = "4.0"
1818
DiffEqOperators = "4"
1919
ModelingToolkit = "0.9, 0.10, 1.0, 2.0, 3.0"
2020
julia = "1"

src/jump_premade_problems.jl

Lines changed: 67 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using DiffEqBase, DiffEqBiological
1+
using DiffEqBase, Catalyst
22
# Jump Example Problems
33
export prob_jump_dnarepressor, prob_jump_constproduct, prob_jump_nonlinrxs,
44
# examples mixing mass action and constant rate jumps
@@ -13,8 +13,9 @@ export prob_jump_dnarepressor, prob_jump_constproduct, prob_jump_nonlinrxs,
1313
the JumpProblem constructor requires the algorithm, so we
1414
don't create the JumpProblem here.
1515
"""
16+
1617
struct JumpProblemNetwork
17-
network # DiffEqBiological network
18+
network # Catalyst network
1819
rates # vector of rate constants or nothing
1920
tstop # time to end simulation
2021
u0 # initial values
@@ -33,7 +34,7 @@ end k1 k2 k3 k4 k5 k6
3334
rates = [.5, (20*log(2.)/120.), (log(2.)/120.), (log(2.)/600.), .025, 1.]
3435
tf = 1000.0
3536
u0 = [1,0,0,0]
36-
prob = DiscreteProblem(u0, (0.0, tf), rates)
37+
prob = DiscreteProblem(dna_rs, u0, (0.0, tf), rates)
3738
Nsims = 8000
3839
expected_avg = 5.926553750000000e+02
3940
prob_data = Dict("num_sims_for_mean" => Nsims, "expected_mean" => expected_avg)
@@ -49,7 +50,7 @@ end k1 k2
4950
rates = [1000., 10.]
5051
tf = 1.0
5152
u0 = [0]
52-
prob = DiscreteProblem(u0, (0., tf), rates)
53+
prob = DiscreteProblem(bd_rs, u0, (0., tf), rates)
5354
Nsims = 16000
5455
expected_avg = t -> rates[1] / rates[2] .* ( 1. - exp.(-rates[2] * t))
5556
prob_data = Dict("num_sims_for_mean" => Nsims, "expected_mean_at_t" => expected_avg)
@@ -68,7 +69,7 @@ end k1 k2 k3 k4 k5
6869
rates = [1., 2., .5, .75, .25]
6970
tf = .01
7071
u0 = [200, 100, 150]
71-
prob = DiscreteProblem(u0, (0., tf), rates)
72+
prob = DiscreteProblem(nonlin_rs, u0, (0., tf), rates)
7273
Nsims = 32000
7374
expected_avg = 84.876015624999994
7475
prob_data = Dict("num_sims_for_mean" => Nsims, "expected_mean" => expected_avg)
@@ -92,7 +93,7 @@ oscil_rs = @reaction_network begin
9293
end
9394
u0 = [200.,60.,120.,100.,50.,50.,50.] # Hill equations force use of floats!
9495
tf = 4000.
95-
prob = DiscreteProblem(u0, (0.,tf))
96+
prob = DiscreteProblem(oscil_rs, u0, (0.,tf))
9697
"""
9798
Oscillatory system, uses a mixture of jump types.
9899
"""
@@ -136,11 +137,11 @@ end kon kAon koff kAoff kAp kAdp
136137
rsi = rates_sym_to_idx
137138
rates = params[[rsi[:kon], rsi[:kAon], rsi[:koff], rsi[:kAoff], rsi[:kAp], rsi[:kAdp]]]
138139
u0 = zeros(Int,9)
139-
u0[ something(findfirst(isequal(:S1), rs.syms),0)] = params[1]
140-
u0[ something(findfirst(isequal(:S2), rs.syms),0)] = params[2]
141-
u0[ something(findfirst(isequal(:S3), rs.syms),0)] = params[3]
140+
u0[ findfirst(isequal(Variable(:S1)), rs.states)] = params[1]
141+
u0[ findfirst(isequal(Variable(:S2)), rs.states)] = params[2]
142+
u0[ findfirst(isequal(Variable(:S3)), rs.states)] = params[3]
142143
tf = 100.
143-
prob = DiscreteProblem(u0, (0., tf), rates)
144+
prob = DiscreteProblem(rs, u0, (0., tf), rates)
144145
"""
145146
Multistate model from Gupta and Mendes,
146147
"An Overview of Network-Based and -Free Approaches for Stochastic Simulation of Biochemical Systems",
@@ -154,39 +155,62 @@ prob_jump_multistate = JumpProblemNetwork(rs, rates, tf, u0, prob,
154155
# generate the network
155156
N = 10 # number of genes
156157
function construct_genenetwork(N)
157-
genenetwork = "@reaction_network begin\n"
158-
for i in 1:N
159-
genenetwork *= "\t 10.0, G$(2*i-1) --> G$(2*i-1) + M$(2*i-1)\n"
160-
genenetwork *= "\t 10.0, M$(2*i-1) --> M$(2*i-1) + P$(2*i-1)\n"
161-
genenetwork *= "\t 1.0, M$(2*i-1) --> 0\n"
162-
genenetwork *= "\t 1.0, P$(2*i-1) --> 0\n"
163-
164-
genenetwork *= "\t 5.0, G$(2*i) --> G$(2*i) + M$(2*i)\n"
165-
genenetwork *= "\t 5.0, M$(2*i) --> M$(2*i) + P$(2*i)\n"
166-
genenetwork *= "\t 1.0, M$(2*i) --> 0\n"
167-
genenetwork *= "\t 1.0, P$(2*i) --> 0\n"
168-
169-
genenetwork *= "\t 0.0001, G$(2*i) + P$(2*i-1) --> G$(2*i)_ind \n"
170-
genenetwork *= "\t 100., G$(2*i)_ind --> G$(2*i)_ind + M$(2*i)\n"
171-
end
172-
genenetwork *= "end"
158+
genenetwork = make_empty_network()
159+
@parameters t
160+
for i in 1:N
161+
G₂ᵢ₋₁ = Variable(Symbol("G",2*i-1))(t)
162+
M₂ᵢ₋₁ = Variable(Symbol("M",2*i-1))(t)
163+
P₂ᵢ₋₁ = Variable(Symbol("P",2*i-1))(t)
164+
addspecies!(genenetwork,G₂ᵢ₋₁)
165+
addspecies!(genenetwork,M₂ᵢ₋₁)
166+
addspecies!(genenetwork,P₂ᵢ₋₁)
167+
addreaction!(genenetwork, Reaction(10.0, [G₂ᵢ₋₁], [G₂ᵢ₋₁,M₂ᵢ₋₁]))
168+
addreaction!(genenetwork, Reaction(10.0, [M₂ᵢ₋₁], [M₂ᵢ₋₁,P₂ᵢ₋₁]))
169+
addreaction!(genenetwork, Reaction(1.0, [M₂ᵢ₋₁], nothing))
170+
addreaction!(genenetwork, Reaction(1.0, [P₂ᵢ₋₁], nothing))
171+
# genenetwork *= "\t 10.0, G$(2*i-1) --> G$(2*i-1) + M$(2*i-1)\n"
172+
# genenetwork *= "\t 10.0, M$(2*i-1) --> M$(2*i-1) + P$(2*i-1)\n"
173+
# genenetwork *= "\t 1.0, M$(2*i-1) --> 0\n"
174+
# genenetwork *= "\t 1.0, P$(2*i-1) --> 0\n"
175+
176+
G₂ᵢ = Variable(Symbol("G",2*i))(t)
177+
M₂ᵢ = Variable(Symbol("M",2*i))(t)
178+
P₂ᵢ = Variable(Symbol("P",2*i))(t)
179+
addspecies!(genenetwork,G₂ᵢ)
180+
addspecies!(genenetwork,M₂ᵢ)
181+
addspecies!(genenetwork,P₂ᵢ)
182+
addreaction!(genenetwork, Reaction(5.0, [G₂ᵢ], [G₂ᵢ,M₂ᵢ]))
183+
addreaction!(genenetwork, Reaction(5.0, [M₂ᵢ], [M₂ᵢ,P₂ᵢ]))
184+
addreaction!(genenetwork, Reaction(1.0, [M₂ᵢ], nothing))
185+
addreaction!(genenetwork, Reaction(1.0, [P₂ᵢ], nothing))
186+
# genenetwork *= "\t 5.0, G$(2*i) --> G$(2*i) + M$(2*i)\n"
187+
# genenetwork *= "\t 5.0, M$(2*i) --> M$(2*i) + P$(2*i)\n"
188+
# genenetwork *= "\t 1.0, M$(2*i) --> 0\n"
189+
# genenetwork *= "\t 1.0, P$(2*i) --> 0\n"
190+
191+
G₂ᵢ_ind = Variable(Symbol("G",2*i,"_ind"))(t)
192+
addspecies!(genenetwork, G₂ᵢ_ind)
193+
addreaction!(genenetwork, Reaction(0.0001, [G₂ᵢ,P₂ᵢ₋₁], [G₂ᵢ_ind]))
194+
addreaction!(genenetwork, Reaction(100.0, [G₂ᵢ_ind], [G₂ᵢ_ind,M₂ᵢ]))
195+
# genenetwork *= "\t 0.0001, G$(2*i) + P$(2*i-1) --> G$(2*i)_ind \n"
196+
# genenetwork *= "\t 100., G$(2*i)_ind --> G$(2*i)_ind + M$(2*i)\n"
197+
end
198+
genenetwork
173199
end
174-
genenetwork = construct_genenetwork(N)
175-
rs = eval( Meta.parse(genenetwork) )
176-
u0 = zeros(Int, length(rs.syms))
200+
rs = construct_genenetwork(N)
201+
u0 = zeros(Int, length(rs.states))
177202
for i = 1:(2*N)
178-
u0[something(findfirst(isequal(Symbol("G$(i)")),rs.syms),0)] = 1
203+
u0[findfirst(isequal(Variable(Symbol("G$(i)"))),rs.states)] = 1
179204
end
180205
tf = 2000.0
181-
prob = DiscreteProblem(u0, (0.0, tf))
206+
prob = DiscreteProblem(rs, u0, (0.0, tf))
182207
"""
183208
Twenty-gene model from McCollum et al,
184209
"The sorting direct method for stochastic simulation of biochemical systems with varying reaction execution behavior"
185210
Comp. Bio. and Chem., 30, pg. 39-49 (2006).
186211
"""
187212
prob_jump_twentygenes = JumpProblemNetwork(rs, nothing, tf, u0, prob, nothing)
188213

189-
190214
rn = @reaction_network begin
191215
c1, G --> G + M
192216
c2, M --> M + P
@@ -201,7 +225,7 @@ rnpar = [.09, .05, .001, .0009, .00001, .0005, .005, .9]
201225
varlabels = ["G", "M", "P", "P2","P2G"]
202226
u0 = [1000, 0, 0, 0,0]
203227
tf = 4000.
204-
prob = DiscreteProblem(u0, (0.0, tf), rnpar)
228+
prob = DiscreteProblem(rn, u0, (0.0, tf), rnpar)
205229
"""
206230
Negative feedback autoregulatory gene expression model. Dimer is the repressor.
207231
Taken from Marchetti, Priami and Thanh,
@@ -214,14 +238,18 @@ prob_jump_dnadimer_repressor = JumpProblemNetwork(rn, rnpar, tf, u0, prob,
214238

215239
# diffusion model
216240
function getDiffNetwork(N)
217-
diffnetwork = "@reaction_network begin\n"
241+
diffnetwork = make_empty_network()
242+
@parameters t K
243+
for i = 1:N
244+
addspecies!(diffnetwork, Variable("X",i)(t))
245+
end
218246
for i in 1:(N-1)
219-
diffnetwork *= "\t K, X$(i) --> X$(i+1)\n"
220-
diffnetwork *= "\t K, X$(i+1) --> X$(i)\n"
247+
Xᵢ = Variable("X",i)(t)
248+
Xᵢ₊₁ = Variable("X",i+1)(t)
249+
addreaction!(diffnetwork, Reaction(K, [Xᵢ], [Xᵢ₊₁]))
250+
addreaction!(diffnetwork, Reaction(K, [Xᵢ₊₁], [Xᵢ]))
221251
end
222-
diffnetwork *= "end K"
223-
rs = eval( Meta.parse(diffnetwork) )
224-
rs
252+
diffnetwork
225253
end
226254
params = (1.,)
227255
function getDiffu0(N)

src/sde_premade_problems.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using DiffEqBase, DiffEqBiological, Markdown
1+
using DiffEqBase, Catalyst, Markdown
22
#SDE Example Problems
33
export prob_sde_wave, prob_sde_linear, prob_sde_cubic, prob_sde_2Dlinear,
44
prob_sde_lorenz, prob_sde_2Dlinear, prob_sde_additive,

0 commit comments

Comments
 (0)