@@ -364,9 +364,10 @@ function make_reaction_system(ex::Expr; name = :(gensym(:ReactionSystem)))
364
364
default_reaction_metadata = :([])
365
365
compound_expr, compound_species = read_compound_options (options)
366
366
check_default_noise_scaling! (default_reaction_metadata, options)
367
+ default_reaction_metadata = expr_equal_vector_to_pairs (default_reaction_metadata)
367
368
368
369
# Parses reactions, species, and parameters.
369
- reactions = get_reactions (reaction_lines; default_reaction_metadata )
370
+ reactions = get_reactions (reaction_lines)
370
371
species_declared = [extract_syms (options, :species ); compound_species]
371
372
parameters_declared = extract_syms (options, :parameters )
372
373
variables = extract_syms (options, :variables )
@@ -424,9 +425,12 @@ function make_reaction_system(ex::Expr; name = :(gensym(:ReactionSystem)))
424
425
$ observed_vars
425
426
$ comps
426
427
427
- Catalyst. make_ReactionSystem_internal ($ rxexprs, $ tiv, setdiff (union ($ spssym, $ varssym, $ compssym), $ obs_syms),
428
- $ pssym; name = $ name, spatial_ivs = $ sivs,
429
- observed = $ observed_eqs)
428
+ Catalyst. remake_ReactionSystem_internal (
429
+ Catalyst. make_ReactionSystem_internal (
430
+ $ rxexprs, $ tiv, setdiff (union ($ spssym, $ varssym, $ compssym), $ obs_syms),
431
+ $ pssym; name = $ name, spatial_ivs = $ sivs, observed = $ observed_eqs);
432
+ default_reaction_metadata = $ default_reaction_metadata
433
+ )
430
434
end
431
435
end
432
436
@@ -593,8 +597,7 @@ function get_reaction(line)
593
597
end
594
598
595
599
# Generates a vector containing a number of reaction structures, each containing the information about one reaction.
596
- function get_reactions (exprs:: Vector{Expr} , reactions = Vector {ReactionStruct} (undef, 0 );
597
- default_reaction_metadata = :([]))
600
+ function get_reactions (exprs:: Vector{Expr} , reactions = Vector {ReactionStruct} (undef, 0 ))
598
601
for line in exprs
599
602
# Reads core reaction information.
600
603
arrow, rate, reaction, metadata = read_reaction_line (line)
@@ -604,16 +607,12 @@ function get_reactions(exprs::Vector{Expr}, reactions = Vector{ReactionStruct}(u
604
607
if typeof (rate) != Expr || rate. head != :tuple
605
608
error (" Error: Must provide a tuple of reaction rates when declaring a bi-directional reaction." )
606
609
end
607
- push_reactions! (reactions, reaction. args[2 ], reaction. args[3 ], rate. args[1 ], metadata. args[1 ], arrow;
608
- default_reaction_metadata)
609
- push_reactions! (reactions, reaction. args[3 ], reaction. args[2 ], rate. args[2 ], metadata. args[2 ], arrow;
610
- default_reaction_metadata)
610
+ push_reactions! (reactions, reaction. args[2 ], reaction. args[3 ], rate. args[1 ], metadata. args[1 ], arrow)
611
+ push_reactions! (reactions, reaction. args[3 ], reaction. args[2 ], rate. args[2 ], metadata. args[2 ], arrow)
611
612
elseif in (arrow, fwd_arrows)
612
- push_reactions! (reactions, reaction. args[2 ], reaction. args[3 ], rate, metadata, arrow;
613
- default_reaction_metadata)
613
+ push_reactions! (reactions, reaction. args[2 ], reaction. args[3 ], rate, metadata, arrow)
614
614
elseif in (arrow, bwd_arrows)
615
- push_reactions! (reactions, reaction. args[3 ], reaction. args[2 ], rate, metadata, arrow;
616
- default_reaction_metadata)
615
+ push_reactions! (reactions, reaction. args[3 ], reaction. args[2 ], rate, metadata, arrow)
617
616
else
618
617
throw (" Malformed reaction, invalid arrow type used in: $(MacroTools. striplines (line)) " )
619
618
end
646
645
# Used to create multiple reactions from, for instance, `k, (X,Y) --> 0`.
647
646
# Handles metadata, e.g. `1.0, Z --> 0, [noise_scaling=η]`.
648
647
function push_reactions! (reactions:: Vector{ReactionStruct} , sub_line:: ExprValues , prod_line:: ExprValues ,
649
- rate:: ExprValues , metadata:: ExprValues , arrow:: Symbol ; default_reaction_metadata :: Expr )
648
+ rate:: ExprValues , metadata:: ExprValues , arrow:: Symbol )
650
649
# The rates, substrates, products, and metadata may be in a tupple form (e.g. `k, (X,Y) --> 0`).
651
650
# This finds the length of these tuples (or 1 if not in tuple forms). Errors if lengs inconsistent.
652
651
lengs = (tup_leng (sub_line), tup_leng (prod_line), tup_leng (rate), tup_leng (metadata))
@@ -658,7 +657,6 @@ function push_reactions!(reactions::Vector{ReactionStruct}, sub_line::ExprValues
658
657
for i in 1 : maximum (lengs)
659
658
# If the `only_use_rate` metadata was not provided, this has to be infered from the arrow used.
660
659
metadata_i = get_tup_arg (metadata, i)
661
- merge_metadata! (metadata_i, default_reaction_metadata)
662
660
if all ([arg. args[1 ] != :only_use_rate for arg in metadata_i. args])
663
661
push! (metadata_i. args, :(only_use_rate = $ (in (arrow, pure_rate_arrows))))
664
662
end
@@ -673,16 +671,6 @@ function push_reactions!(reactions::Vector{ReactionStruct}, sub_line::ExprValues
673
671
end
674
672
end
675
673
676
- # Merge the metadata encoded by a reaction with the default metadata (for all reactions) given by the system.
677
- # If a metadata value is present in both vectors, uses the non-default value.
678
- function merge_metadata! (metadata, default_reaction_metadata)
679
- for entry in default_reaction_metadata. args
680
- if ! in (entry. args[1 ], arg. args[1 ] for arg in metadata. args)
681
- push! (metadata. args, entry)
682
- end
683
- end
684
- end
685
-
686
674
function processmult (op, mult, stoich)
687
675
if (mult isa Number) && (stoich isa Number)
688
676
op (mult, stoich)
0 commit comments