@@ -122,7 +122,43 @@ function assemble_diffusion(rs)
122
122
end
123
123
124
124
function assemble_jumps (rs)
125
+ eqs = Vector {Union{ConstantRateJump, MassActionJump, VariableRateJump}} ()
125
126
127
+ for rx in rs. eqs
128
+ rl = jumpratelaw (rx)
129
+ affect = Vector {Equation} ()
130
+ for (spec,stoich) in rx. netstoich
131
+ push! (affect,var2op (spec) ~ var2op (spec) + stoich)
132
+ end
133
+ if any (isequal .(var2op (rs. iv),get_variables (rx. rate)))
134
+ push! (eqs,VariableRateJump (rl,affect))
135
+ elseif any ([isequal (state,r_op) for state in rs. states, r_op in getfield .(get_variables (rx. rate),:op )])
136
+ push! (eqs,ConstantRateJump (rl,affect))
137
+ else
138
+ push! (eqs,ConstantRateJump (rl,affect))
139
+ end
140
+ end
141
+ eqs
142
+ end
143
+
144
+ # Calculate the Jump rate law (like ODE, but uses X instead of X(t).
145
+ # The former geenrates a "MethodError: objects of type Int64 are not callable" when trying to solve the problem.
146
+ function jumpratelaw (rx)
147
+ @unpack rate, substrates, substoich, only_use_rate = rx
148
+ rl = rate
149
+ if ! only_use_rate
150
+ coef = one (eltype (substoich))
151
+ for (i,stoich) in enumerate (substoich)
152
+ coef *= factorial (stoich)
153
+ rl *= isone (stoich) ? var2op (substrates[i]. op) : var2op (substrates[i]. op)^ stoich
154
+ end
155
+ (! isone (coef)) && (rl /= coef)
156
+ end
157
+ rl
158
+ end
159
+
160
+ function var2op (var)
161
+ Operation (var,Vector {Expression} ())
126
162
end
127
163
128
164
function Base. convert (:: Type{<:ODESystem} ,rs:: ReactionSystem )
0 commit comments