75
75
# ################ query-based macros:
76
76
77
77
"""
78
- @min_reaction_network
78
+ @min_reaction_network
79
79
80
80
Generates a subtype of an `AbstractReactionNetwork` that only encodes a chemical
81
81
reaction network. Use [`addodes!`](@ref), [`addsdes!`](@ref) or
@@ -160,10 +160,10 @@ function min_coordinate(name, ex::Expr, p, scale_noise)
160
160
161
161
# Build the type
162
162
exprs = Vector {Expr} (undef,0 )
163
- typeex,constructorex = maketype (DiffEqBase. AbstractReactionNetwork, name, nothing , nothing ,
164
- nothing , nothing , nothing , nothing , nothing , nothing ,
165
- nothing , nothing , syms, scale_noise; params= params,
166
- reactions= reactions, symjac= nothing , syms_to_ints= reactants,
163
+ typeex,constructorex = maketype (DiffEqBase. AbstractReactionNetwork, name, nothing , nothing ,
164
+ nothing , nothing , nothing , nothing , nothing , nothing ,
165
+ nothing , nothing , syms, scale_noise; params= params,
166
+ reactions= reactions, symjac= nothing , syms_to_ints= reactants,
167
167
params_to_ints= parameters)
168
168
push! (exprs,typeex)
169
169
push! (exprs,constructorex)
@@ -213,7 +213,7 @@ function get_minnetwork(ex::Expr, p)
213
213
end
214
214
215
215
# Generates a vector containing a number of reaction structures, each containing the infromation about one reaction.
216
- function get_reactions (ex:: Expr , reactions = Vector {ReactionStruct} (undef,0 ))
216
+ function get_reactions (ex:: Expr , reactions = Vector {ReactionStruct} (undef,0 ))
217
217
for line in ex. args
218
218
(line. head != :tuple ) && (continue )
219
219
(rate,r_line) = line. args
@@ -253,8 +253,8 @@ struct ReactionStruct
253
253
dependants:: Vector{Symbol}
254
254
is_pure_mass_action:: Bool
255
255
256
- function ReactionStruct (s:: Vector{ReactantStruct} , p:: Vector{ReactantStruct} ,
257
- ro:: ExprValues , rde:: ExprValues , rssa:: ExprValues ,
256
+ function ReactionStruct (s:: Vector{ReactantStruct} , p:: Vector{ReactantStruct} ,
257
+ ro:: ExprValues , rde:: ExprValues , rssa:: ExprValues ,
258
258
dep:: Vector{Symbol} , isma:: Bool )
259
259
new (s,p,ro,rde,rssa,dep,isma)
260
260
end
@@ -331,6 +331,13 @@ function add_reactants!(ex::ExprValues, mult::Int, reactants::Vector{ReactantStr
331
331
return reactants
332
332
end
333
333
334
+ # For each reaction, sets its dependencies and whenever it is a pure mass action reaction.
335
+ function update_reaction_info (reactions:: Vector{ReactionStruct} ,syms:: Vector{Symbol} )
336
+ for i = 1 : length (reactions)
337
+ reactions[i] = ReactionStruct (reactions[i],syms)
338
+ end
339
+ end
340
+
334
341
# From the vector with all reactions, generates a dictionary with all reactants. Each reactant will point to a number so that X --> means X will be replaced with u[1] in the equations.
335
342
function get_reactants (reactions:: Vector{ReactionStruct} )
336
343
reactants = OrderedDict {Symbol,Int} ()
@@ -356,13 +363,6 @@ function get_parameters(p)
356
363
return parameters
357
364
end
358
365
359
- # For each reaction, sets its dependencies and whenever it is a pure mass action reaction.
360
- function update_reaction_info (reactions:: Vector{ReactionStruct} ,syms:: Vector{Symbol} )
361
- for i = 1 : length (reactions)
362
- reactions[i] = ReactionStruct (reactions[i],syms)
363
- end
364
- end
365
-
366
366
# Produces an array of expressions. Each entry corresponds to a line in the function f, which constitutes the deterministic part of the system. The Expressions can be used for debugging, making LaTex code, or creating the real f function for simulating the network.
367
367
function get_f (reactions:: Vector{ReactionStruct} , reactants:: OrderedDict{Symbol,Int} )
368
368
f = Vector {Expr} (undef,length (reactants))
@@ -376,11 +376,11 @@ function get_f(reactions::Vector{ReactionStruct}, reactants::OrderedDict{Symbol,
376
376
end
377
377
end
378
378
379
- for line in f
379
+ for line in f
380
380
if length (line. args[2 ]. args) == 1
381
381
@assert line. args[2 ]. args[1 ] == :+
382
382
line. args[2 ] = 0
383
- else
383
+ else
384
384
line. args[2 ] = clean_subtractions (line. args[2 ])
385
385
end
386
386
end
@@ -575,14 +575,23 @@ end
575
575
576
576
# Parses an expression, and returns a set with all symbols in the expression, which is also a part of the provided vector with symbols (syms).
577
577
function recursive_content (ex,syms:: Vector{Symbol} ,content:: Vector{Symbol} )
578
- if typeof (ex) != Expr
578
+ if ex isa Symbol
579
579
in (ex,syms) && push! (content,ex)
580
- else
580
+ elseif ex isa Expr
581
581
foreach (arg -> recursive_content (arg,syms,content), ex. args)
582
582
end
583
583
return content
584
584
end
585
585
586
+ function recursive_content (ex,symsmap:: OrderedDict{Symbol,Int} ,content:: Vector{Symbol} )
587
+ if ex isa Symbol
588
+ haskey (symsmap,ex) && push! (content,ex)
589
+ elseif ex isa Expr
590
+ foreach (arg -> recursive_content (arg,symsmap,content), ex. args)
591
+ end
592
+ return content
593
+ end
594
+
586
595
# Makes the various jacobian elements required.
587
596
function get_jacs (f_rhs:: Vector{ExprValues} , syms:: Vector{Symbol} , reactants:: OrderedDict{Symbol,Int} , parameters:: OrderedDict{Symbol,Int} )
588
597
symjac = calculate_symjac (deepcopy (f_rhs), syms)
0 commit comments