@@ -223,8 +223,12 @@ function assemble_diffusion(rs, noise_scaling; combinatoric_ratelaws=true)
223
223
eqs
224
224
end
225
225
226
- function var2op (var)
227
- Operation (var,Vector {Expression} ())
226
+ var2op (var:: Sym ) = var
227
+ var2op (var:: Sym{FnType{Tuple{<:Any}, T}} ) where {T} = Sym {FnType{Tuple{}, T}} (nameof (var))()
228
+ var2op (var:: Num ) = var2op (value (var))
229
+
230
+ function var2op (var:: Term )
231
+ Sym {FnType{Tuple{}, symtype(var)}} (nameof (var. op))()
228
232
end
229
233
230
234
# Calculate the Jump rate law (like ODE, but uses X instead of X(t).
@@ -258,12 +262,12 @@ function jumpratelaw(rx; rxvars=get_variables(rx.rate), combinatoric_ratelaw=tru
258
262
@unpack rate, substrates, substoich, only_use_rate = rx
259
263
rl = rate
260
264
for op in rxvars
261
- rl = substitute (rl, op => var2op (op. op ))
265
+ rl = substitute (rl, op => var2op (op))
262
266
end
263
267
if ! only_use_rate
264
268
coef = one (eltype (substoich))
265
269
for (i,stoich) in enumerate (substoich)
266
- s = var2op (substrates[i]. op )
270
+ s = var2op (substrates[i])
267
271
rl *= s
268
272
isone (stoich) && continue
269
273
for i in one (stoich): (stoich- one (stoich))
312
316
zeroorder = (length (substoich) == 0 )
313
317
reactant_stoch = Vector {Pair{Term,eltype(substoich)}} (undef, length (substoich))
314
318
@inbounds for i = 1 : length (reactant_stoch)
315
- reactant_stoch[i] = var2op (substrates[i]. op ) => substoich[i]
319
+ reactant_stoch[i] = var2op (substrates[i]) => substoich[i]
316
320
end
317
321
# push!(rstoich, reactant_stoch)
318
322
coef = (zeroorder || (! combinatoric_ratelaw)) ? one (eltype (substoich)) : prod (stoich -> factorial (stoich), substoich)
@@ -457,7 +461,7 @@ law, i.e. for `2S -> 0` at rate `k` the ratelaw would be `k*S^2/2!`. If
457
461
ignored.
458
462
"""
459
463
function Base. convert (:: Type{<:NonlinearSystem} ,rs:: ReactionSystem ; combinatoric_ratelaws= true )
460
- states_swaps = map (states -> Operation (states,[ var2op (rs . iv)]), rs. states)
464
+ states_swaps = value .( rs. states)
461
465
eqs = map (eq -> 0 ~ make_sub! (eq,states_swaps),getproperty .(assemble_drift (rs; combinatoric_ratelaws= combinatoric_ratelaws),:rhs ))
462
466
NonlinearSystem (eqs,rs. states,rs. ps,name= rs. name,
463
467
systems= convert .(NonlinearSystem,rs. systems))
0 commit comments