@@ -92,7 +92,7 @@ function coordinate(name, ex::Expr, p, scale_noise)
92
92
g = make_func (g_expr, reactants, parameters)
93
93
p_matrix = zeros (length (reactants), length (reactions))
94
94
95
- (jump_rate_expr, jump_affect_expr, jumps) = get_jumps (reactions, reactants,parameters)
95
+ (jump_rate_expr, jump_affect_expr, jumps, regular_jumps ) = get_jumps (reactions, reactants, parameters)
96
96
97
97
f_rhs = [element. args[2 ] for element in f_expr]
98
98
# symjac = Expr(:quote, calculate_jac(f_rhs, syms))
@@ -105,7 +105,7 @@ function coordinate(name, ex::Expr, p, scale_noise)
105
105
f_funcs = [element. args[2 ] for element in f_expr]
106
106
g_funcs = [element. args[2 ] for element in g_expr]
107
107
108
- typeex,constructorex = maketype (name, f, f_funcs, f_symfuncs, g, g_funcs, jumps, Meta. quot (jump_rate_expr), Meta. quot (jump_affect_expr), p_matrix, syms; params= params, reactions= reactions)
108
+ typeex,constructorex = maketype (name, f, f_funcs, f_symfuncs, g, g_funcs, jumps, regular_jumps, Meta. quot (jump_rate_expr), Meta. quot (jump_affect_expr), p_matrix, syms; params= params, reactions= reactions)
109
109
110
110
push! (exprs,typeex)
111
111
push! (exprs,constructorex)
@@ -313,12 +313,15 @@ function get_jumps(reactions::Vector{ReactionStruct}, reactants::OrderedDict{Sym
313
313
rates = Vector {Any} (length (reactions))
314
314
affects = Vector {Vector{Expr}} (length (reactions))
315
315
jumps = Expr (:tuple )
316
+ reg_rates = Expr (:block )
317
+ reg_c = Expr (:block )
316
318
idx = 0
317
319
for reaction in deepcopy (reactions)
318
320
rates[idx += 1 ] = recursive_clean! (reaction. rate_SSA)
319
321
affects[idx] = Vector {Expr} (0 )
320
- foreach (prod -> push! (affects[idx],:(@inbounds integrator. u[$ (reactants[prod. reactant])] += $ (prod. stoichiometry))), reaction. products)
321
- foreach (sub -> push! (affects[idx],:(@inbounds integrator. u[$ (reactants[sub. reactant])] -= $ (sub. stoichiometry))), reaction. substrates)
322
+ reactant_set = union (getfield .(reaction. products, :reactant ),getfield .(reaction. substrates, :reactant ))
323
+ foreach (r -> push! (affects[idx],:(@inbounds integrator. u[$ (reactants[r])] += $ (get_stoch_diff (reaction,r)))), reactant_set)
324
+ syntax_rate = recursive_replace! (deepcopy (rates[idx]), (reactants,:internal_var___u ), (parameters, :internal_var___p ))
322
325
# if reaction.is_pure_mass_action
323
326
# ma_sub_stoch = :(reactant_stoich = [[]])
324
327
# ma_stoch_change = :(reactant_stoich = [[]])
@@ -327,11 +330,14 @@ function get_jumps(reactions::Vector{ReactionStruct}, reactants::OrderedDict{Sym
327
330
# push!(jumps.args,:(MassActionJump($(reaction.rate_org),$(ma_sub_stoch),$(ma_stoch_change))))
328
331
# else
329
332
recursive_contains (:t ,rates[idx]) ? push! (jumps. args,Expr (:call ,:VariableRateJump )) : push! (jumps. args,Expr (:call ,:ConstantRateJump ))
330
- push! (jumps. args[idx]. args, :((internal_var___u,internal_var___p,t) -> $ ( recursive_replace! ( deepcopy (rates[idx]), (reactants, :internal_var___u ), (parameters, :internal_var___p ))) ))
333
+ push! (jumps. args[idx]. args, :((internal_var___u,internal_var___p,t) -> $ syntax_rate ))
331
334
push! (jumps. args[idx]. args, :(integrator -> $ (expr_arr_to_block (deepcopy (affects[idx])))))
332
335
# end
336
+ push! (reg_rates. args,:(internal_var___out[$ idx]= $ syntax_rate))
337
+ foreach (r -> push! (reg_c. args,:(internal_var___dc[$ (reactants[r]),$ idx]= $ (get_stoch_diff (reaction,r)))), reactant_set)
333
338
end
334
- return (Tuple (rates),Tuple (affects),jumps)
339
+ reg_jumps = :(RegularJump ((internal_var___out,internal_var___u,internal_var___p,t)-> $ reg_rates,(internal_var___dc,internal_var___u,internal_var___p,t,internal_var___mark)-> $ reg_c,zeros ($ (length (reactants)),$ (length (reactions)));constant_c= true ))
340
+ return (Tuple (rates),Tuple (affects),jumps,reg_jumps)
335
341
end
336
342
337
343
# Recursively traverses an expression and removes things like X^1, 1*X. Will not actually have any affect on the expression when used as a function, but will make it much easier to look at it for debugging, as well as if it is transformed to LaTeX code.
0 commit comments