Skip to content

Commit 2d6d4c3

Browse files
committed
- JumpSystem is now properly created for Variable and Constant RateJumps.
- Version of oderatelawy, jumpratelaw function (possibly unnecessary). - Added var2op utility function (possibly unnecessary).
1 parent efd7749 commit 2d6d4c3

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

src/systems/reaction/reactionsystem.jl

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,43 @@ function assemble_diffusion(rs)
122122
end
123123

124124
function assemble_jumps(rs)
125+
eqs = Vector{Union{ConstantRateJump, MassActionJump, VariableRateJump}}()
125126

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}())
126162
end
127163

128164
function Base.convert(::Type{<:ODESystem},rs::ReactionSystem)

0 commit comments

Comments
 (0)