@@ -187,7 +187,7 @@ function oderatelaw(rx; combinatoric_ratelaw=true)
187
187
end
188
188
189
189
function assemble_oderhs (rs; combinatoric_ratelaws= true )
190
- sts = states (rs)
190
+ sts = get_states (rs)
191
191
species_to_idx = Dict ((x => i for (i,x) in enumerate (sts)))
192
192
rhsvec = Any[0 for i in eachindex (sts)]
193
193
@@ -212,16 +212,16 @@ function assemble_drift(rs; combinatoric_ratelaws=true, as_odes=true)
212
212
rhsvec = assemble_oderhs (rs; combinatoric_ratelaws= combinatoric_ratelaws)
213
213
if as_odes
214
214
D = Differential (get_iv (rs))
215
- eqs = [Equation (D (x),rhs) for (x,rhs) in zip (states (rs),rhsvec)]
215
+ eqs = [Equation (D (x),rhs) for (x,rhs) in zip (get_states (rs),rhsvec)]
216
216
else
217
217
eqs = [Equation (0 ,rhs) for rhs in rhsvec]
218
218
end
219
219
eqs
220
220
end
221
221
222
222
function assemble_diffusion (rs, noise_scaling; combinatoric_ratelaws= true )
223
- sts = states (rs)
224
- eqs = Matrix {Any} (undef, length (sts), length (equations (rs)))
223
+ sts = get_states (rs)
224
+ eqs = Matrix {Any} (undef, length (sts), length (get_eqs (rs)))
225
225
eqs .= 0
226
226
species_to_idx = Dict ((x => i for (i,x) in enumerate (sts)))
227
227
@@ -302,7 +302,7 @@ explicitly on the independent variable (usually time).
302
302
"""
303
303
function ismassaction (rx, rs; rxvars = get_variables (rx. rate),
304
304
haveivdep = any (var -> isequal (get_iv (rs),var), rxvars),
305
- stateset = Set (states (rs)))
305
+ stateset = Set (get_states (rs)))
306
306
# if no dependencies must be zero order
307
307
(length (rxvars)== 0 ) && return true
308
308
haveivdep && return false
331
331
332
332
function assemble_jumps (rs; combinatoric_ratelaws= true )
333
333
meqs = MassActionJump[]; ceqs = ConstantRateJump[]; veqs = VariableRateJump[]
334
- stateset = Set (states (rs))
334
+ stateset = Set (get_states (rs))
335
335
# rates = []; rstoich = []; nstoich = []
336
336
rxvars = []
337
337
ivname = nameof (get_iv (rs))
@@ -378,10 +378,11 @@ law, i.e. for `2S -> 0` at rate `k` the ratelaw would be `k*S^2/2!`. If
378
378
`combinatoric_ratelaws=false` then the ratelaw is `k*S^2`, i.e. the scaling factor is
379
379
ignored.
380
380
"""
381
- function Base. convert (:: Type{<:ODESystem} , rs:: ReactionSystem ; combinatoric_ratelaws= true )
382
- eqs = assemble_drift (rs; combinatoric_ratelaws= combinatoric_ratelaws)
383
- ODESystem (eqs,get_iv (rs),states (rs),get_ps (rs),name= nameof (rs),
384
- systems= convert .(ODESystem,get_systems (rs)))
381
+ function Base. convert (:: Type{<:ODESystem} , rs:: ReactionSystem ;
382
+ name= nameof (rs), combinatoric_ratelaws= true , kwargs... )
383
+ eqs = assemble_drift (rs; combinatoric_ratelaws= combinatoric_ratelaws)
384
+ systems = convert .(ODESystem, get_systems (rs))
385
+ ODESystem (eqs, get_iv (rs), get_states (rs), get_ps (rs), name= name, systems= systems)
385
386
end
386
387
387
388
"""
@@ -397,9 +398,11 @@ law, i.e. for `2S -> 0` at rate `k` the ratelaw would be `k*S^2/2!`. If
397
398
`combinatoric_ratelaws=false` then the ratelaw is `k*S^2`, i.e. the scaling factor is
398
399
ignored.
399
400
"""
400
- function Base. convert (:: Type{<:NonlinearSystem} ,rs:: ReactionSystem ; combinatoric_ratelaws= true )
401
- eqs = assemble_drift (rs; combinatoric_ratelaws= combinatoric_ratelaws, as_odes= false )
402
- NonlinearSystem (eqs,states (rs),get_ps (rs),name= nameof (rs),systems= convert .(NonlinearSystem,get_systems (rs)))
401
+ function Base. convert (:: Type{<:NonlinearSystem} ,rs:: ReactionSystem ;
402
+ name= nameof (rs), combinatoric_ratelaws= true , kwargs... )
403
+ eqs = assemble_drift (rs; combinatoric_ratelaws= combinatoric_ratelaws, as_odes= false )
404
+ systems = convert .(NonlinearSystem, get_systems (rs))
405
+ NonlinearSystem (eqs, get_states (rs), get_ps (rs), name= name, systems= systems)
403
406
end
404
407
405
408
"""
@@ -423,7 +426,8 @@ Finally, a `Vector{Operation}` can be provided (the length must be equal to the
423
426
Here the noise for each reaction is scaled by the corresponding parameter in the input vector.
424
427
This input may contain repeat parameters.
425
428
"""
426
- function Base. convert (:: Type{<:SDESystem} ,rs:: ReactionSystem , combinatoric_ratelaws= true ; noise_scaling= nothing )
429
+ function Base. convert (:: Type{<:SDESystem} , rs:: ReactionSystem ;
430
+ noise_scaling= nothing , name= nameof (rs), combinatoric_ratelaws= true , kwargs... )
427
431
428
432
if noise_scaling isa Vector
429
433
(length (noise_scaling)!= length (equations (rs))) &&
@@ -434,19 +438,14 @@ function Base.convert(::Type{<:SDESystem},rs::ReactionSystem, combinatoric_ratel
434
438
noise_scaling = fill (value (noise_scaling),length (equations (rs)))
435
439
end
436
440
437
- eqs = assemble_drift (rs; combinatoric_ratelaws= combinatoric_ratelaws)
438
-
441
+ eqs = assemble_drift (rs; combinatoric_ratelaws= combinatoric_ratelaws)
439
442
noiseeqs = assemble_diffusion (rs,noise_scaling;
440
443
combinatoric_ratelaws= combinatoric_ratelaws)
441
-
442
- SDESystem (eqs,
443
- noiseeqs,
444
- get_iv (rs),
445
- states (rs),
446
- (noise_scaling=== nothing ) ?
447
- get_ps (rs) :
448
- union (get_ps (rs),toparam .(noise_scaling)),
449
- name= nameof (rs),systems= convert .(SDESystem,get_systems (rs)))
444
+ systems = convert .(SDESystem, get_systems (rs))
445
+ SDESystem (eqs, noiseeqs, get_iv (rs), get_states (rs),
446
+ (noise_scaling=== nothing ) ? get_ps (rs) : union (get_ps (rs), toparam .(noise_scaling)),
447
+ name= name,
448
+ systems= systems)
450
449
end
451
450
452
451
"""
@@ -462,10 +461,11 @@ Notes:
462
461
the ratelaw is `k*S*(S-1)`, i.e. the rate law is not normalized by the scaling
463
462
factor.
464
463
"""
465
- function Base. convert (:: Type{<:JumpSystem} ,rs:: ReactionSystem ; combinatoric_ratelaws= true )
466
- eqs = assemble_jumps (rs; combinatoric_ratelaws= combinatoric_ratelaws)
467
- JumpSystem (eqs,get_iv (rs),states (rs),get_ps (rs),name= nameof (rs),
468
- systems= convert .(JumpSystem,get_systems (rs)))
464
+ function Base. convert (:: Type{<:JumpSystem} ,rs:: ReactionSystem ;
465
+ name= nameof (rs), combinatoric_ratelaws= true , kwargs... )
466
+ eqs = assemble_jumps (rs; combinatoric_ratelaws= combinatoric_ratelaws)
467
+ systems = convert .(JumpSystem, get_systems (rs))
468
+ JumpSystem (eqs, get_iv (rs), get_states (rs), get_ps (rs), name= name, systems= systems)
469
469
end
470
470
471
471
@@ -474,35 +474,35 @@ end
474
474
475
475
# ODEProblem from AbstractReactionNetwork
476
476
function DiffEqBase. ODEProblem (rs:: ReactionSystem , u0, tspan, p= DiffEqBase. NullParameters (), args... ; kwargs... )
477
- return ODEProblem (convert (ODESystem,rs),u0,tspan,p, args... ; kwargs... )
477
+ return ODEProblem (convert (ODESystem,rs; kwargs ... ),u0,tspan,p, args... ; kwargs... )
478
478
end
479
479
480
480
# NonlinearProblem from AbstractReactionNetwork
481
481
function DiffEqBase. NonlinearProblem (rs:: ReactionSystem , u0, p= DiffEqBase. NullParameters (), args... ; kwargs... )
482
- return NonlinearProblem (convert (NonlinearSystem,rs), u0, p, args... ; kwargs... )
482
+ return NonlinearProblem (convert (NonlinearSystem,rs; kwargs ... ), u0, p, args... ; kwargs... )
483
483
end
484
484
485
485
486
486
# SDEProblem from AbstractReactionNetwork
487
487
function DiffEqBase. SDEProblem (rs:: ReactionSystem , u0, tspan, p= DiffEqBase. NullParameters (), args... ; noise_scaling= nothing , kwargs... )
488
- sde_sys = convert (SDESystem,rs, noise_scaling= noise_scaling)
489
- p_matrix = zeros (length (states (rs)), length (equations (rs)))
488
+ sde_sys = convert (SDESystem,rs; noise_scaling= noise_scaling, kwargs ... )
489
+ p_matrix = zeros (length (get_states (rs)), length (get_eqs (rs)))
490
490
return SDEProblem (sde_sys,u0,tspan,p,args... ; noise_rate_prototype= p_matrix,kwargs... )
491
491
end
492
492
493
493
# DiscreteProblem from AbstractReactionNetwork
494
494
function DiffEqBase. DiscreteProblem (rs:: ReactionSystem , u0, tspan:: Tuple , p= DiffEqBase. NullParameters (), args... ; kwargs... )
495
- return DiscreteProblem (convert (JumpSystem,rs), u0,tspan,p, args... ; kwargs... )
495
+ return DiscreteProblem (convert (JumpSystem,rs; kwargs ... ), u0,tspan,p, args... ; kwargs... )
496
496
end
497
497
498
498
# JumpProblem from AbstractReactionNetwork
499
499
function DiffEqJump. JumpProblem (rs:: ReactionSystem , prob, aggregator, args... ; kwargs... )
500
- return JumpProblem (convert (JumpSystem,rs), prob, aggregator, args... ; kwargs... )
500
+ return JumpProblem (convert (JumpSystem,rs; kwargs ... ), prob, aggregator, args... ; kwargs... )
501
501
end
502
502
503
503
# SteadyStateProblem from AbstractReactionNetwork
504
504
function DiffEqBase. SteadyStateProblem (rs:: ReactionSystem , u0, p= DiffEqBase. NullParameters (), args... ; kwargs... )
505
- return SteadyStateProblem (ODEFunction (convert (ODESystem,rs)),u0,p, args... ; kwargs... )
505
+ return SteadyStateProblem (ODEFunction (convert (ODESystem,rs; kwargs ... )),u0,p, args... ; kwargs... )
506
506
end
507
507
508
508
# determine which species a reaction depends on
0 commit comments