@@ -42,19 +42,6 @@ function oderatelaw(rx; combinatoric_ratelaw = true)
42
42
rl
43
43
end
44
44
45
- function assemble_drift (rs, ispcs; combinatoric_ratelaws = true , as_odes = true ,
46
- include_zero_odes = true , remove_conserved = false )
47
- rhsvec = assemble_oderhs (rs, ispcs; combinatoric_ratelaws, remove_conserved)
48
- if as_odes
49
- D = Differential (get_iv (rs))
50
- eqs = [Equation (D (x), rhs)
51
- for (x, rhs) in zip (ispcs, rhsvec) if (include_zero_odes || (! _iszero (rhs)))]
52
- else
53
- eqs = [Equation (0 , rhs) for rhs in rhsvec if (include_zero_odes || (! _iszero (rhs)))]
54
- end
55
- eqs
56
- end
57
-
58
45
function assemble_oderhs (rs, ispcs; combinatoric_ratelaws = true , remove_conserved = false )
59
46
nps = get_networkproperties (rs)
60
47
species_to_idx = Dict (x => i for (i, x) in enumerate (ispcs))
@@ -98,6 +85,19 @@ function assemble_oderhs(rs, ispcs; combinatoric_ratelaws = true, remove_conserv
98
85
rhsvec
99
86
end
100
87
88
+ function assemble_drift (rs, ispcs; combinatoric_ratelaws = true , as_odes = true ,
89
+ include_zero_odes = true , remove_conserved = false )
90
+ rhsvec = assemble_oderhs (rs, ispcs; combinatoric_ratelaws, remove_conserved)
91
+ if as_odes
92
+ D = Differential (get_iv (rs))
93
+ eqs = [Equation (D (x), rhs)
94
+ for (x, rhs) in zip (ispcs, rhsvec) if (include_zero_odes || (! _iszero (rhs)))]
95
+ else
96
+ eqs = [Equation (0 , rhs) for rhs in rhsvec if (include_zero_odes || (! _iszero (rhs)))]
97
+ end
98
+ eqs
99
+ end
100
+
101
101
# this doesn't work with constraint equations currently
102
102
function assemble_diffusion (rs, sts, ispcs; combinatoric_ratelaws = true ,
103
103
remove_conserved = false )
@@ -258,6 +258,57 @@ function ismassaction(rx, rs; rxvars = get_variables(rx.rate),
258
258
return true
259
259
end
260
260
261
+ @inline function makemajump (rx; combinatoric_ratelaw = true )
262
+ @unpack rate, substrates, substoich, netstoich = rx
263
+ zeroorder = (length (substoich) == 0 )
264
+ reactant_stoch = Vector {Pair{Any, eltype(substoich)}} ()
265
+ @inbounds for (i, spec) in enumerate (substrates)
266
+ # move constant species into the rate
267
+ if isconstant (spec)
268
+ rate *= spec
269
+ isone (substoich[i]) && continue
270
+ for i in 1 : (substoich[i] - 1 )
271
+ rate *= spec - i
272
+ end
273
+ else
274
+ push! (reactant_stoch, substrates[i] => substoich[i])
275
+ end
276
+ end
277
+
278
+ if (! zeroorder) && combinatoric_ratelaw
279
+ coef = prod (factorial, substoich)
280
+ (! isone (coef)) && (rate /= coef)
281
+ end
282
+
283
+ net_stoch = filter (p -> ! drop_dynamics (p[1 ]), netstoich)
284
+ isempty (net_stoch) &&
285
+ error (" $rx has no net stoichiometry change once accounting for constant and boundary condition species. This is not supported." )
286
+
287
+ MassActionJump (Num (rate), reactant_stoch, net_stoch, scale_rates = false ,
288
+ useiszero = false )
289
+ end
290
+
291
+ # recursively visit each neighbor's rooted tree and mark everything in it as vrj
292
+ function dfs_mark! (isvrjvec, visited, depgraph, i)
293
+ visited[i] = true
294
+ nhbrs = depgraph[i]
295
+ for nhbr in nhbrs
296
+ if ! visited[nhbr]
297
+ isvrjvec[nhbr] = true
298
+ dfs_mark! (isvrjvec, visited, depgraph, nhbr)
299
+ end
300
+ end
301
+ nothing
302
+ end
303
+
304
+ # get_depgraph(rs)[i] is the list of reactions with rates depending on species changed by
305
+ # i'th reaction.
306
+ function get_depgraph (rs)
307
+ jdeps = asgraph (rs)
308
+ vdeps = variable_dependencies (rs)
309
+ eqeq_dependencies (jdeps, vdeps). fadjlist
310
+ end
311
+
261
312
function assemble_jumps (rs; combinatoric_ratelaws = true )
262
313
meqs = MassActionJump[]
263
314
ceqs = ConstantRateJump[]
@@ -323,57 +374,6 @@ function assemble_jumps(rs; combinatoric_ratelaws = true)
323
374
vcat (meqs, ceqs, veqs)
324
375
end
325
376
326
- # get_depgraph(rs)[i] is the list of reactions with rates depending on species changed by
327
- # i'th reaction.
328
- function get_depgraph (rs)
329
- jdeps = asgraph (rs)
330
- vdeps = variable_dependencies (rs)
331
- eqeq_dependencies (jdeps, vdeps). fadjlist
332
- end
333
-
334
- # recursively visit each neighbor's rooted tree and mark everything in it as vrj
335
- function dfs_mark! (isvrjvec, visited, depgraph, i)
336
- visited[i] = true
337
- nhbrs = depgraph[i]
338
- for nhbr in nhbrs
339
- if ! visited[nhbr]
340
- isvrjvec[nhbr] = true
341
- dfs_mark! (isvrjvec, visited, depgraph, nhbr)
342
- end
343
- end
344
- nothing
345
- end
346
-
347
- @inline function makemajump (rx; combinatoric_ratelaw = true )
348
- @unpack rate, substrates, substoich, netstoich = rx
349
- zeroorder = (length (substoich) == 0 )
350
- reactant_stoch = Vector {Pair{Any, eltype(substoich)}} ()
351
- @inbounds for (i, spec) in enumerate (substrates)
352
- # move constant species into the rate
353
- if isconstant (spec)
354
- rate *= spec
355
- isone (substoich[i]) && continue
356
- for i in 1 : (substoich[i] - 1 )
357
- rate *= spec - i
358
- end
359
- else
360
- push! (reactant_stoch, substrates[i] => substoich[i])
361
- end
362
- end
363
-
364
- if (! zeroorder) && combinatoric_ratelaw
365
- coef = prod (factorial, substoich)
366
- (! isone (coef)) && (rate /= coef)
367
- end
368
-
369
- net_stoch = filter (p -> ! drop_dynamics (p[1 ]), netstoich)
370
- isempty (net_stoch) &&
371
- error (" $rx has no net stoichiometry change once accounting for constant and boundary condition species. This is not supported." )
372
-
373
- MassActionJump (Num (rate), reactant_stoch, net_stoch, scale_rates = false ,
374
- useiszero = false )
375
- end
376
-
377
377
378
378
# ## Equation Coupling ###
379
379
0 commit comments