You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/src/model_creation/dsl_advanced.md
+39-28Lines changed: 39 additions & 28 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -500,34 +500,6 @@ Catalyst.getdescription(rx)
500
500
501
501
A list of all available reaction metadata can be found [in the api](@ref api_rx_metadata).
502
502
503
-
## [Declaring individual reaction using the `@reaction` macro](@id dsl_advanced_options_reaction_macro)
504
-
Catalyst exports a macro `@reaction` which can be used to generate a singular [`Reaction`](@ref) object of the same type which is stored within the [`ReactionSystem`](@ref) structure (which in turn can be generated by `@reaction_network `). In the following example, we create a simple [SIR model](@ref basic_CRN_library_sir). Next, we instead create its individual reaction components using the `@reaction` macro. Finally, we confirm that these are identical to those stored in the initial model (using the [`reactions`](@ref) function).
Here, the `@reaction` macro is followed by a single line consisting of three parts:
517
-
- A rate (at which the reaction occurs).
518
-
- Any number of substrates (which are consumed by the reaction).
519
-
- Any number of products (which are produced by the reaction).
520
-
The rules of writing and interpreting this line are [identical to those for `@reaction_network`](@ref dsl_description_reactions) (however, bi-directional reactions are not permitted).
521
-
522
-
Generally, the `@reaction` macro provides a more concise notation to the [`Reaction`](@ref) constructor. One of its primary uses is for [creating models programmatically](@ref programmatic_CRN_construction). When doing so, it can often be useful to use [*interpolation*](@ref dsl_advanced_options_symbolics_and_DSL_interpolation) of symbolic variables declared previously:
523
-
```@example dsl_advanced_reaction_macro
524
-
t = default_t()
525
-
@parameters k b
526
-
@species A(t)
527
-
ex = k*A^2 + t
528
-
rx = @reaction b*$ex*$A, $A --> C
529
-
```
530
-
531
503
## [Working with symbolic variables and the DSL](@id dsl_advanced_options_symbolics_and_DSL)
532
504
We have previously described how Catalyst represents its models symbolically (enabling e.g. symbolic differentiation of expressions stored in models). While Catalyst utilises this for many internal operation, these symbolic representations can also be accessed and harnessed by the user. Primarily, doing so is much easier during programmatic (as opposed to DSL-based) modelling. Indeed, the section on [programmatic modelling](@ref programmatic_CRN_construction) goes into more details about symbolic representation in models, and how these can be used. It is, however, also ways to utilise these methods during DSL-based modelling. Below we briefly describe two methods for doing so.
533
505
@@ -602,6 +574,45 @@ nothing # hide
602
574
!!! note
603
575
When using interpolation, expressions like `2$spec` won't work; the multiplication symbol must be explicitly included like `2*$spec`.
604
576
577
+
## [Creating individual reaction using the `@reaction` macro](@id dsl_advanced_options_reaction_macro)
578
+
Catalyst exports a macro `@reaction`, which can be used to generate a singular [`Reaction`](@ref) object of the same type which is stored within the [`ReactionSystem`](@ref) structure (which in turn can be generated by `@reaction_network`). Generally, `@reaction` follows [identical rules to those of `@reaction_network`](@ref(@ref dsl_description_reactions)) for writing and interpreting reactions (however, bi-directional reactions are not permitted). E.g. here we create a simple dimerisation reaction:
579
+
```@example dsl_advanced_reaction_macro
580
+
using Catalyst # hide
581
+
rx_dimerisation = @reaction kD, 2X --> X2
582
+
```
583
+
Here, `@reaction` is followed by a single line consisting of three parts:
584
+
- A rate (at which the reaction occurs).
585
+
- Any number of substrates (which are consumed by the reaction).
586
+
- Any number of products (which are produced by the reaction).
587
+
588
+
In the next example, we first create a simple [SIR model](@ref basic_CRN_library_sir). Next, we instead create its individual reaction components using the `@reaction` macro. Finally, we confirm that these are identical to those stored in the initial model (using the [`reactions`](@ref) function).
589
+
```@example dsl_advanced_reaction_macro
590
+
sir_model = @reaction_network begin
591
+
α, S + I --> 2I
592
+
β, I --> R
593
+
end
594
+
infection_rx = @reaction α, S + I --> 2I
595
+
recovery_rx = @reaction β, I --> R
596
+
sir_rxs = [infection_rx, recovery_rx]
597
+
issetequal(reactions(sir_model), sir_rxs)
598
+
```
599
+
One of the primary uses of the `@reaction` macro is to provide some of the convenience of the DSL to [*programmatic modelling](@ref programmatic_CRN_construction). E.g. here we can combine our reactions to create a `ReactionSystem` directly, and also confirm that this is identical to the model created through the DSL:
600
+
```@example dsl_advanced_reaction_macro
601
+
sir_programmatic = complete(ReactionSystem(sir_rxs, default_t(); name = :sir))
602
+
sir_programmatic == sir_model
603
+
```
604
+
605
+
During programmatic modelling, it can be good to keep in mind that already declared symbolic variables can be [*interpolated*](@ref dsl_advanced_options_symbolics_and_DSL_interpolation). E.g. here we create two production reactions both depending on the same Michaelis-Menten function:
606
+
```@example dsl_advanced_reaction_macro
607
+
t = default_t()
608
+
@species X(t)
609
+
@parameters v K
610
+
mm_term = Catalyst.mm(X, v, K)
611
+
rx1 = @reaction $mm_term, 0 --> P1
612
+
rx2 = @reaction $mm_term, 0 --> P2
613
+
nothing # hide
614
+
```
615
+
605
616
## [Disabling mass action for reactions](@id dsl_advanced_options_disable_ma)
606
617
607
618
As [described previously](@ref math_models_in_catalyst_rre_odes), Catalyst uses *mass action kinetics* to generate ODEs from reactions. Here, each reaction generates a term for each of its reactants, which consists of the reaction's rate, substrates, and the reactant's stoichiometry. E.g. the following reaction:
error("@default_noise_scaling should only have a single expression as its input, this appears not to be the case: \"$(options[:default_noise_scaling])\"")
error("@default_noise_scaling should only have a single expression as its input, this appears not to be the case: \"$(options[:default_noise_scaling])\"")
0 commit comments