@@ -187,10 +187,11 @@ function oderatelaw(rx; combinatoric_ratelaw=true)
187
187
end
188
188
189
189
function assemble_oderhs (rs; combinatoric_ratelaws= true )
190
- species_to_idx = Dict ((x => i for (i,x) in enumerate (rs. states)))
191
- rhsvec = Any[0 for i in eachindex (rs. states)]
190
+ sts = states (rs)
191
+ species_to_idx = Dict ((x => i for (i,x) in enumerate (sts)))
192
+ rhsvec = Any[0 for i in eachindex (sts)]
192
193
193
- for rx in rs . eqs
194
+ for rx in equations (rs)
194
195
rl = oderatelaw (rx; combinatoric_ratelaw= combinatoric_ratelaws)
195
196
for (spec,stoich) in rx. netstoich
196
197
i = species_to_idx[spec]
@@ -210,20 +211,21 @@ end
210
211
function assemble_drift (rs; combinatoric_ratelaws= true , as_odes= true )
211
212
rhsvec = assemble_oderhs (rs; combinatoric_ratelaws= combinatoric_ratelaws)
212
213
if as_odes
213
- D = Differential (rs . iv )
214
- eqs = [Equation (D (x),rhs) for (x,rhs) in zip (rs . states,rhsvec)]
214
+ D = Differential (get_iv (rs) )
215
+ eqs = [Equation (D (x),rhs) for (x,rhs) in zip (states (rs) ,rhsvec)]
215
216
else
216
217
eqs = [Equation (0 ,rhs) for rhs in rhsvec]
217
218
end
218
219
eqs
219
220
end
220
221
221
222
function assemble_diffusion (rs, noise_scaling; combinatoric_ratelaws= true )
222
- eqs = Matrix {Any} (undef, length (rs. states), length (rs. eqs))
223
+ sts = states (rs)
224
+ eqs = Matrix {Any} (undef, length (sts), length (equations (rs)))
223
225
eqs .= 0
224
- species_to_idx = Dict ((x => i for (i,x) in enumerate (rs . states )))
226
+ species_to_idx = Dict ((x => i for (i,x) in enumerate (sts )))
225
227
226
- for (j,rx) in enumerate (rs . eqs )
228
+ for (j,rx) in enumerate (equations (rs) )
227
229
rlsqrt = sqrt (abs (oderatelaw (rx; combinatoric_ratelaw= combinatoric_ratelaws)))
228
230
(noise_scaling!= = nothing ) && (rlsqrt *= noise_scaling[j])
229
231
for (spec,stoich) in rx. netstoich
283
285
"""
284
286
```julia
285
287
ismassaction(rx, rs; rxvars = get_variables(rx.rate),
286
- haveivdep = any(var -> isequal(rs.iv ,var), rxvars),
288
+ haveivdep = any(var -> isequal(get_iv(rs) ,var), rxvars),
287
289
stateset = Set(states(rs)))
288
290
```
289
291
@@ -299,7 +301,7 @@ explicitly on the independent variable (usually time).
299
301
- Optional: `stateset`, set of states which if the rxvars are within mean rx is non-mass action.
300
302
"""
301
303
function ismassaction (rx, rs; rxvars = get_variables (rx. rate),
302
- haveivdep = any (var -> isequal (rs . iv ,var), rxvars),
304
+ haveivdep = any (var -> isequal (get_iv (rs) ,var), rxvars),
303
305
stateset = Set (states (rs)))
304
306
# if no dependencies must be zero order
305
307
(length (rxvars)== 0 ) && return true
@@ -332,15 +334,15 @@ function assemble_jumps(rs; combinatoric_ratelaws=true)
332
334
stateset = Set (states (rs))
333
335
# rates = []; rstoich = []; nstoich = []
334
336
rxvars = []
335
- ivname = rs . iv . name
337
+ ivname = nameof ( get_iv (rs))
336
338
337
339
isempty (equations (rs)) && error (" Must give at least one reaction before constructing a JumpSystem." )
338
340
for rx in equations (rs)
339
341
empty! (rxvars)
340
342
(rx. rate isa Symbolic) && get_variables! (rxvars, rx. rate)
341
343
haveivdep = false
342
344
@inbounds for i = 1 : length (rxvars)
343
- if isequal (rxvars[i], rs . iv )
345
+ if isequal (rxvars[i], get_iv (rs) )
344
346
haveivdep = true
345
347
break
346
348
end
@@ -378,8 +380,8 @@ ignored.
378
380
"""
379
381
function Base. convert (:: Type{<:ODESystem} , rs:: ReactionSystem ; combinatoric_ratelaws= true )
380
382
eqs = assemble_drift (rs; combinatoric_ratelaws= combinatoric_ratelaws)
381
- ODESystem (eqs,rs . iv,rs . states,rs . ps ,name= rs . name ,
382
- systems= convert .(ODESystem,rs . systems ))
383
+ ODESystem (eqs,get_iv (rs), states (rs), get_ps (rs) ,name= nameof (rs) ,
384
+ systems= convert .(ODESystem,get_systems (rs) ))
383
385
end
384
386
385
387
"""
@@ -397,7 +399,7 @@ ignored.
397
399
"""
398
400
function Base. convert (:: Type{<:NonlinearSystem} ,rs:: ReactionSystem ; combinatoric_ratelaws= true )
399
401
eqs = assemble_drift (rs; combinatoric_ratelaws= combinatoric_ratelaws, as_odes= false )
400
- NonlinearSystem (eqs,rs . states,rs . ps ,name= rs . name ,systems= convert .(NonlinearSystem,rs . systems ))
402
+ NonlinearSystem (eqs,states (rs), get_ps (rs) ,name= nameof (rs) ,systems= convert .(NonlinearSystem,get_systems (rs) ))
401
403
end
402
404
403
405
"""
@@ -424,12 +426,12 @@ This input may contain repeat parameters.
424
426
function Base. convert (:: Type{<:SDESystem} ,rs:: ReactionSystem , combinatoric_ratelaws= true ; noise_scaling= nothing )
425
427
426
428
if noise_scaling isa Vector
427
- (length (noise_scaling)!= length (rs . eqs )) &&
429
+ (length (noise_scaling)!= length (equations (rs) )) &&
428
430
error (" The number of elements in 'noise_scaling' must be equal " *
429
431
" to the number of reactions in the reaction system." )
430
432
noise_scaling = value .(noise_scaling)
431
433
elseif ! isnothing (noise_scaling)
432
- noise_scaling = fill (value (noise_scaling),length (rs . eqs ))
434
+ noise_scaling = fill (value (noise_scaling),length (equations (rs) ))
433
435
end
434
436
435
437
eqs = assemble_drift (rs; combinatoric_ratelaws= combinatoric_ratelaws)
@@ -439,12 +441,12 @@ function Base.convert(::Type{<:SDESystem},rs::ReactionSystem, combinatoric_ratel
439
441
440
442
SDESystem (eqs,
441
443
noiseeqs,
442
- rs . iv ,
443
- rs . states,
444
+ get_iv (iv) ,
445
+ states (rs) ,
444
446
(noise_scaling=== nothing ) ?
445
- rs . ps :
446
- union (rs . ps ,toparam .(noise_scaling)),
447
- name= rs. name,systems= convert .(SDESystem,rs . systems ))
447
+ get_ps (rs) :
448
+ union (get_ps (rs) ,toparam .(noise_scaling)),
449
+ name= rs. name,systems= convert .(SDESystem,get_systems (rs) ))
448
450
end
449
451
450
452
"""
@@ -462,8 +464,8 @@ Notes:
462
464
"""
463
465
function Base. convert (:: Type{<:JumpSystem} ,rs:: ReactionSystem ; combinatoric_ratelaws= true )
464
466
eqs = assemble_jumps (rs; combinatoric_ratelaws= combinatoric_ratelaws)
465
- JumpSystem (eqs,rs . iv,rs . states,rs . ps ,name= rs . name ,
466
- systems= convert .(JumpSystem,rs . systems ))
467
+ JumpSystem (eqs,get_iv (rs), states (rs), get_ps (rs) ,name= nameof (rs) ,
468
+ systems= convert .(JumpSystem,get_systems (rs) ))
467
469
end
468
470
469
471
484
486
# SDEProblem from AbstractReactionNetwork
485
487
function DiffEqBase. SDEProblem (rs:: ReactionSystem , u0, tspan, p= DiffEqBase. NullParameters (), args... ; noise_scaling= nothing , kwargs... )
486
488
sde_sys = convert (SDESystem,rs,noise_scaling= noise_scaling)
487
- p_matrix = zeros (length (rs . states) , length (rs . eqs ))
489
+ p_matrix = zeros (length (states (rs)) , length (equations (rs) ))
488
490
return SDEProblem (sde_sys,u0,tspan,p,args... ; noise_rate_prototype= p_matrix,kwargs... )
489
491
end
490
492
0 commit comments