@@ -137,9 +137,10 @@ end kon kAon koff kAoff kAp kAdp
137137rsi = rates_sym_to_idx
138138rates = params[[rsi[:kon ], rsi[:kAon ], rsi[:koff ], rsi[:kAoff ], rsi[:kAp ], rsi[:kAdp ]]]
139139u0 = zeros (Int,9 )
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 ]
140+ statesyms = ModelingToolkit. tosymbol .(ModelingToolkit. operation .(rs. states))
141+ u0[ findfirst (isequal (:S1 ), statesyms)] = params[1 ]
142+ u0[ findfirst (isequal (:S2 ), statesyms)] = params[2 ]
143+ u0[ findfirst (isequal (:S3 ), statesyms)] = params[3 ]
143144tf = 100.
144145prob = DiscreteProblem (rs, u0, (0. , tf), rates)
145146"""
@@ -154,53 +155,49 @@ prob_jump_multistate = JumpProblemNetwork(rs, rates, tf, u0, prob,
154155
155156# generate the network
156157N = 10 # number of genes
158+ @parameters t
159+ @variables G[1 : 2 N](t) M[1 : 2 N](t) P[1 : 2 N](t) G_ind[1 : 2 N](t)
160+
157161function construct_genenetwork (N)
158- genenetwork = make_empty_network ()
159- @parameters t
162+ genenetwork = make_empty_network ()
160163 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 ))
164+ addspecies! (genenetwork,G[2 * i- 1 ])
165+ addspecies! (genenetwork,M[2 * i- i])
166+ addspecies! (genenetwork,P[2 * i- i])
167+ addreaction! (genenetwork, Reaction (10.0 , [G[2 * i- i]], [G[2 * i- i],M[2 * i- i]]))
168+ addreaction! (genenetwork, Reaction (10.0 , [M[2 * i- i]], [M[2 * i- i],P[2 * i- i]]))
169+ addreaction! (genenetwork, Reaction (1.0 , [M[2 * i- i]], nothing ))
170+ addreaction! (genenetwork, Reaction (1.0 , [P[2 * i- i]], nothing ))
171171 # genenetwork *= "\t 10.0, G$(2*i-1) --> G$(2*i-1) + M$(2*i-1)\n"
172172 # genenetwork *= "\t 10.0, M$(2*i-1) --> M$(2*i-1) + P$(2*i-1)\n"
173173 # genenetwork *= "\t 1.0, M$(2*i-1) --> 0\n"
174174 # genenetwork *= "\t 1.0, P$(2*i-1) --> 0\n"
175175
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 ))
176+ addspecies! (genenetwork,G[2 * i])
177+ addspecies! (genenetwork,M[2 * i])
178+ addspecies! (genenetwork,P[2 * i])
179+ addreaction! (genenetwork, Reaction (5.0 , [G[2 * i]], [G[2 * i],M[2 * i]]))
180+ addreaction! (genenetwork, Reaction (5.0 , [M[2 * i]], [M[2 * i],P[2 * i]]))
181+ addreaction! (genenetwork, Reaction (1.0 , [M[2 * i]], nothing ))
182+ addreaction! (genenetwork, Reaction (1.0 , [P[2 * i]], nothing ))
186183 # genenetwork *= "\t 5.0, G$(2*i) --> G$(2*i) + M$(2*i)\n"
187184 # genenetwork *= "\t 5.0, M$(2*i) --> M$(2*i) + P$(2*i)\n"
188185 # genenetwork *= "\t 1.0, M$(2*i) --> 0\n"
189186 # genenetwork *= "\t 1.0, P$(2*i) --> 0\n"
190187
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₂ᵢ]))
188+ addspecies! (genenetwork, G_ind[2 * i])
189+ addreaction! (genenetwork, Reaction (0.0001 , [G[2 * i],P[2 * i- i]], [G_ind[2 * i]]))
190+ addreaction! (genenetwork, Reaction (100.0 , [G_ind[2 * i]], [G_ind[2 * i],M[2 * i]]))
195191 # genenetwork *= "\t 0.0001, G$(2*i) + P$(2*i-1) --> G$(2*i)_ind \n"
196192 # genenetwork *= "\t 100., G$(2*i)_ind --> G$(2*i)_ind + M$(2*i)\n"
197193 end
198194 genenetwork
199195end
200196rs = construct_genenetwork (N)
201197u0 = zeros (Int, length (rs. states))
198+ statesyms = ModelingToolkit. tosymbol .(ModelingToolkit. operation .(rs. states))
202199for i = 1 : (2 * N)
203- u0[findfirst (isequal (Variable ( Symbol ( " G $(i) " )) ),rs. states)] = 1
200+ u0[findfirst (isequal (G[i] ),rs. states)] = 1
204201end
205202tf = 2000.0
206203prob = DiscreteProblem (rs, u0, (0.0 , tf))
@@ -238,16 +235,15 @@ prob_jump_dnadimer_repressor = JumpProblemNetwork(rn, rnpar, tf, u0, prob,
238235
239236# diffusion model
240237function getDiffNetwork (N)
241- diffnetwork = make_empty_network ()
238+ diffnetwork = make_empty_network ()
242239 @parameters t K
240+ @variables X[1 : N](t)
243241 for i = 1 : N
244- addspecies! (diffnetwork, Variable ( " X " ,i)(t) )
242+ addspecies! (diffnetwork, X[i] )
245243 end
246244 for i in 1 : (N- 1 )
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ᵢ]))
245+ addreaction! (diffnetwork, Reaction (K, [X[i]], [X[i+ 1 ]]))
246+ addreaction! (diffnetwork, Reaction (K, [X[i+ 1 ]], [X[i]]))
251247 end
252248 diffnetwork
253249end
0 commit comments