@@ -21,7 +21,6 @@ export prob_jump_dnarepressor, prob_jump_constproduct, prob_jump_nonlinrxs,
2121 the JumpProblem constructor requires the algorithm, so we
2222 don't create the JumpProblem here.
2323"""
24-
2524struct JumpProblemNetwork
2625 network:: Any # Catalyst network
2726 rates:: Any # vector of rate constants or nothing
@@ -39,9 +38,14 @@ dna_rs = @reaction_network begin
3938 k5, DNA + P --> DNAR
4039 k6, DNAR --> DNA + P
4140end
42- rates = [0.5 , (20 * log (2.0 ) / 120.0 ), (log (2.0 ) / 120.0 ), (log (2.0 ) / 600.0 ), 0.025 , 1.0 ]
41+ rates = [:k1 => 0.5 ,
42+ :k2 => (20 * log (2.0 ) / 120.0 ),
43+ :k3 => (log (2.0 ) / 120.0 ),
44+ :k4 => (log (2.0 ) / 600.0 ),
45+ :k5 => 0.025 ,
46+ :k6 => 1.0 ]
4347tf = 1000.0
44- u0 = [1 , 0 , 0 , 0 ]
48+ u0 = [:DNA => 1 , :mRNA => 0 , :P => 0 , :DNAR => 0 ]
4549prob = DiscreteProblem (dna_rs, u0, (0.0 , tf), rates, eval_module = @__MODULE__ )
4650Nsims = 8000
4751expected_avg = 5.926553750000000e+02
@@ -55,9 +59,9 @@ bd_rs = @reaction_network begin
5559 k1, 0 --> A
5660 k2, A --> 0
5761end
58- rates = [1000.0 , 10.0 ]
62+ rates = [:k1 => 1000.0 , :k2 => 10.0 ]
5963tf = 1.0
60- u0 = [0 ]
64+ u0 = [:A => 0 ]
6165prob = DiscreteProblem (bd_rs, u0, (0.0 , tf), rates, eval_module = @__MODULE__ )
6266Nsims = 16000
6367expected_avg = t -> rates[1 ] / rates[2 ] .* (1.0 - exp .(- rates[2 ] * t))
@@ -74,9 +78,9 @@ nonlin_rs = @reaction_network begin
7478 k4, C --> A + B
7579 k5, 3 C --> 3 A
7680end
77- rates = [1.0 , 2.0 , 0.5 , 0.75 , 0.25 ]
81+ rates = [:k1 => 1.0 , :k2 => 2.0 , :k3 => 0.5 , :k4 => 0.75 , :k5 => 0.25 ]
7882tf = 0.01
79- u0 = [200 , 100 , 150 ]
83+ u0 = [:A => 200 , :B => 100 , :C => 150 ]
8084prob = DiscreteProblem (nonlin_rs, u0, (0.0 , tf), rates, eval_module = @__MODULE__ )
8185Nsims = 32000
8286expected_avg = 84.876015624999994
@@ -98,7 +102,8 @@ oscil_rs = @reaction_network begin
98102 0.01 , SP + SP --> SP2
99103 0.05 , SP2 --> 0
100104end
101- u0 = [200.0 , 60.0 , 120.0 , 100.0 , 50.0 , 50.0 , 50.0 ] # Hill equations force use of floats!
105+ u0 = [:X => 200.0 , :Y => 60.0 , :Z => 120.0 , :R => 100.0 , :S => 50.0 , :SP => 50.0 ,
106+ :SP2 => 50.0 ] # Hill equations force use of floats!
102107tf = 4000.0
103108prob = DiscreteProblem (oscil_rs, u0, (0.0 , tf), eval_module = @__MODULE__ )
104109"""
@@ -115,9 +120,9 @@ specs_sym_to_name = Dict(:S1 => "R(a,l)",
115120 :S7 => " A(Y~P,r!1).L(r!2).R(a!1,l!2)" ,
116121 :S8 => " A(Y~P,r!1).R(a!1,l)" ,
117122 :S9 => " A(Y~P,r)" )
118- rates_sym_to_idx = Dict (:R0 => 1 , :L0 => 2 , :A0 => 3 , :kon => 4 , :koff => 5 ,
119- :kAon => 6 , :kAoff => 7 , :kAp => 8 , :kAdp => 9 )
120- params = [ 5360 , 1160 , 5360 , 0.01 , 0.1 , 0.01 , 0.1 , 0.01 , 0.1 ]
123+ rsi = Dict (:R0 => 1 , :L0 => 2 , :A0 => 3 , :kon => 4 , :koff => 5 ,
124+ :kAon => 6 , :kAoff => 7 , :kAp => 8 , :kAdp => 9 )
125+ params = ( 5360 , 1160 , 5360 , 0.01 , 0.1 , 0.01 , 0.1 , 0.01 , 0.1 )
121126rs = @reaction_network begin
122127 kon, S1 + S2 --> S4
123128 kAon, S1 + S3 --> S5
@@ -138,13 +143,10 @@ rs = @reaction_network begin
138143 kAdp, S8 --> S5
139144 kAdp, S9 --> S3
140145end
141- rsi = rates_sym_to_idx
142- rates = params[[rsi[:kon ], rsi[:kAon ], rsi[:koff ], rsi[:kAoff ], rsi[:kAp ], rsi[:kAdp ]]]
143- u0 = zeros (Int, 9 )
144- statesyms = ModelingToolkit. tosymbol .(ModelingToolkit. operation .(unknowns (rs)))
145- u0[findfirst (isequal (:S1 ), statesyms)] = params[1 ]
146- u0[findfirst (isequal (:S2 ), statesyms)] = params[2 ]
147- u0[findfirst (isequal (:S3 ), statesyms)] = params[3 ]
146+ rates = [:kon , :kAon , :koff , :kAoff , :kAp , :kAdp ] .=>
147+ params[[rsi[:kon ], rsi[:kAon ], rsi[:koff ], rsi[:kAoff ], rsi[:kAp ], rsi[:kAdp ]]]
148+ u0 = [:S1 => params[1 ], :S2 => params[2 ], :S3 => params[3 ], :S4 => 0 , :S5 => 0 ,
149+ :S6 => 0 , :S7 => 0 , :S8 => 0 , :S9 => 0 ]
148150tf = 100.0
149151prob = DiscreteProblem (rs, u0, (0.0 , tf), rates, eval_module = @__MODULE__ )
150152"""
@@ -155,57 +157,47 @@ prob = DiscreteProblem(rs, u0, (0.0, tf), rates, eval_module = @__MODULE__)
155157"""
156158prob_jump_multistate = JumpProblemNetwork (rs, rates, tf, u0, prob,
157159 Dict (" specs_to_sym_name" => specs_sym_to_name,
158- " rates_sym_to_idx" => rates_sym_to_idx,
159- " params" => params))
160+ " rates_sym_to_idx" => rsi, " params" => params))
160161
161162# generate the network
162163N = 10 # number of genes
163- @variables t
164+ t = Catalyst . default_t ()
164165@species (G (t))[1 : (2 N)] (M (t))[1 : (2 N)] (P (t))[1 : (2 N)] (G_ind (t))[1 : (2 N)]
165166
166167function construct_genenetwork (N)
167- genenetwork = make_empty_network ()
168+ rxs = Reaction[]
168169 for i in 1 : N
169- addspecies! (genenetwork, G[2 * i - 1 ])
170- addspecies! (genenetwork, M[2 * i - i])
171- addspecies! (genenetwork, P[2 * i - i])
172- addreaction! (genenetwork,
173- Reaction (10.0 , [G[2 * i - i]], [G[2 * i - i], M[2 * i - i]]))
174- addreaction! (genenetwork,
175- Reaction (10.0 , [M[2 * i - i]], [M[2 * i - i], P[2 * i - i]]))
176- addreaction! (genenetwork, Reaction (1.0 , [M[2 * i - i]], nothing ))
177- addreaction! (genenetwork, Reaction (1.0 , [P[2 * i - i]], nothing ))
170+ push! (rxs, Reaction (10.0 , [G[2 * i - i]], [G[2 * i - i], M[2 * i - i]]))
171+ push! (rxs, Reaction (10.0 , [M[2 * i - i]], [M[2 * i - i], P[2 * i - i]]))
172+ push! (rxs, Reaction (1.0 , [M[2 * i - i]], nothing ))
173+ push! (rxs, Reaction (1.0 , [P[2 * i - i]], nothing ))
178174 # genenetwork *= "\t 10.0, G$(2*i-1) --> G$(2*i-1) + M$(2*i-1)\n"
179175 # genenetwork *= "\t 10.0, M$(2*i-1) --> M$(2*i-1) + P$(2*i-1)\n"
180176 # genenetwork *= "\t 1.0, M$(2*i-1) --> 0\n"
181177 # genenetwork *= "\t 1.0, P$(2*i-1) --> 0\n"
182178
183- addspecies! (genenetwork, G[2 * i])
184- addspecies! (genenetwork, M[2 * i])
185- addspecies! (genenetwork, P[2 * i])
186- addreaction! (genenetwork, Reaction (5.0 , [G[2 * i]], [G[2 * i], M[2 * i]]))
187- addreaction! (genenetwork, Reaction (5.0 , [M[2 * i]], [M[2 * i], P[2 * i]]))
188- addreaction! (genenetwork, Reaction (1.0 , [M[2 * i]], nothing ))
189- addreaction! (genenetwork, Reaction (1.0 , [P[2 * i]], nothing ))
179+ push! (rxs, Reaction (5.0 , [G[2 * i]], [G[2 * i], M[2 * i]]))
180+ push! (rxs, Reaction (5.0 , [M[2 * i]], [M[2 * i], P[2 * i]]))
181+ push! (rxs, Reaction (1.0 , [M[2 * i]], nothing ))
182+ push! (rxs, Reaction (1.0 , [P[2 * i]], nothing ))
190183 # genenetwork *= "\t 5.0, G$(2*i) --> G$(2*i) + M$(2*i)\n"
191184 # genenetwork *= "\t 5.0, M$(2*i) --> M$(2*i) + P$(2*i)\n"
192185 # genenetwork *= "\t 1.0, M$(2*i) --> 0\n"
193186 # genenetwork *= "\t 1.0, P$(2*i) --> 0\n"
194187
195- addspecies! (genenetwork, G_ind[2 * i])
196- addreaction! (genenetwork,
197- Reaction (0.0001 , [G[2 * i], P[2 * i - i]], [G_ind[2 * i]]))
198- addreaction! (genenetwork, Reaction (100.0 , [G_ind[2 * i]], [G_ind[2 * i], M[2 * i]]))
188+ push! (rxs, Reaction (0.0001 , [G[2 * i], P[2 * i - i]], [G_ind[2 * i]]))
189+ push! (rxs, Reaction (100.0 , [G_ind[2 * i]], [G_ind[2 * i], M[2 * i]]))
199190 # genenetwork *= "\t 0.0001, G$(2*i) + P$(2*i-1) --> G$(2*i)_ind \n"
200191 # genenetwork *= "\t 100., G$(2*i)_ind --> G$(2*i)_ind + M$(2*i)\n"
201192 end
202- genenetwork
193+ spcs = reduce (vcat, collect .((G, M, P, G_ind)))
194+ @named genenetwork = ReactionSystem (rxs, t, spcs, [])
195+ complete (genenetwork)
203196end
204197rs = construct_genenetwork (N)
205- u0 = zeros (Int, length (unknowns (rs)))
206- statesyms = ModelingToolkit. tosymbol .(ModelingToolkit. operation .(unknowns (rs)))
198+ u0 = Num .(unknowns (rs)) .=> zeros (Int, length (unknowns (rs)))
207199for i in 1 : (2 * N)
208- u0[findfirst (isequal (G[i]), unknowns (rs))] = 1
200+ u0[findfirst (isequal (G[i]), unknowns (rs))] = (G[i] => 1 )
209201end
210202tf = 2000.0
211203prob = DiscreteProblem (rs, u0, (0.0 , tf), eval_module = @__MODULE__ )
@@ -227,9 +219,10 @@ rn = @reaction_network begin
227219 c7, P2 + G --> P2G
228220 c8, P2G --> P2 + G
229221end
230- rnpar = [0.09 , 0.05 , 0.001 , 0.0009 , 0.00001 , 0.0005 , 0.005 , 0.9 ]
222+ rnpar = [:c1 => 0.09 , :c2 => 0.05 , :c3 => 0.001 , :c4 => 0.0009 , :c5 => 0.00001 ,
223+ :c6 => 0.0005 , :c7 => 0.005 , :c8 => 0.9 ]
231224varlabels = [" G" , " M" , " P" , " P2" , " P2G" ]
232- u0 = [1000 , 0 , 0 , 0 , 0 ]
225+ u0 = [:G => 1000 , :M => 0 , :P => 0 , :P2 => 0 , :P2G => 0 ]
233226tf = 4000.0
234227prob = DiscreteProblem (rn, u0, (0.0 , tf), rnpar, eval_module = @__MODULE__ )
235228"""
@@ -245,21 +238,19 @@ prob_jump_dnadimer_repressor = JumpProblemNetwork(rn, rnpar, tf, u0, prob,
245238function getDiffNetwork (N)
246239 diffnetwork = make_empty_network ()
247240 @parameters K
248- @variables t
241+ t = default_t ()
249242 @species (X (t))[1 : N]
250- for i in 1 : N
251- addspecies! (diffnetwork, X[i])
252- end
253- addparam! (diffnetwork, K)
243+ rxs = Reaction[]
254244 for i in 1 : (N - 1 )
255- addreaction! (diffnetwork , Reaction (K, [X[i]], [X[i + 1 ]]))
256- addreaction! (diffnetwork , Reaction (K, [X[i + 1 ]], [X[i]]))
245+ push! (rxs , Reaction (K, [X[i]], [X[i + 1 ]]))
246+ push! (rxs , Reaction (K, [X[i + 1 ]], [X[i]]))
257247 end
258- diffnetwork
248+ @named diffnetwork = ReactionSystem (rxs, t, collect (X), [K])
249+ complete (diffnetwork)
259250end
260- params = ( 1.0 ,)
261- function getDiffu0 (N)
262- 10 * ones (Int64, N)
251+ params = [ :K => 1.0 ]
252+ function getDiffu0 (diffnetwork, N)
253+ species (diffnetwork) .=> ( 10 * ones (Int64, N) )
263254end
264255tf = 10.0
265256"""
0 commit comments