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
## How can I turn off automatic inferring of species and parameters when using the DSL?
286
+
## [How does the Catalyst DSL (`@reaction_network`) infer what different symbols represent?](@id faq_dsl_sym_inference)
287
+
When declaring a model using the Catalyst DSL, e.g.
288
+
```@example faq_dsl_inference
289
+
using Catalyst
290
+
rn = @reaction_network begin
291
+
(p,d), 0 <--> X
292
+
end
293
+
```
294
+
Catalyst can automatically infer that `X` is a species and `p` and `d` are parameters. In total, Catalyst can infer the following quantities:
295
+
- Species (from reaction reactants).
296
+
- Parameters (from reaction rates and stoichiometries).
297
+
- (non-species) Variables (from the `@equations` option).
298
+
- Differential functions (from the `@equations` option).
299
+
- Observables (from the [`@observables` option](@ref dsl_advanced_options_observables)).
300
+
- Compound species (from the [`@compounds` option](@ref chemistry_functionality_compounds_DSL)).
301
+
302
+
Inference of species, variables, and parameters follows the following steps:
303
+
1. Every symbol [explicitly declared](@ref dsl_advanced_options_declaring_species_and_parameters) using the `@species`, `@variables`, and `@parameters` options are assigned to the corresponding category.
304
+
2. Every symbol not declared in (1) that occurs as a reaction reactant is inferred as a species.
305
+
3. Every symbol not declared in (1) or (2) that occurs in an expression provided after `@equations` is inferred as a variable.
306
+
4. Every symbol not declared in (1), (2), or (3) that occurs either as a reaction rate or stoichiometric coefficient is inferred to be a parameter.
307
+
308
+
Here, in
309
+
```@example faq_dsl_inference
310
+
using Catalyst
311
+
rn = @reaction_network begin
312
+
@parameters p1
313
+
@equations V ~ X + p1
314
+
X + V + p1 + p2, 0 --> X
315
+
end
316
+
```
317
+
`p` is first set as a parameter (as it is explicitly declared as such). Next, `X` is inferred as a species. Next, `V` is inferred as a variable. Finally, `p2` is inferred as a parameter.
318
+
319
+
Next, if any expression `D(...)` (where `...` can be anything) is encountered within the `@equations` option, `D` is inferred to be the differential with respect to the default independent variable (typically `t`). Note that using `D` in this way, while also using it in another form (e.g. in a reaction rate) will produce an error.
320
+
321
+
Any symbol used as the left-hand side within the `@observables` option is inferred to be an observable. These are by default assumed to be *variables*. It is possible to simultaneously explicitly declare an observable using the `@species` or `@variables` options (in the former case, the observable will be treated as a species instead). Using observables within most other expressions (e.g. as a reactant) will produce an error.
322
+
323
+
Any symbol declared as a compound using the `@compound` option is automatically inferred to be a system species.
324
+
325
+
Symbols occurring within other expressions will not be inferred as anything. These must either occur in one of the forms described above (which enables Catalyst to infer what they are) or be explicitly declared. E.g. having a parameter which only occurs in an event:
326
+
```julia
327
+
using Catalyst
328
+
rn_error =@reaction_networkbegin
329
+
@discrete_events1.0=> [X ~ X + Xadd]
330
+
d, X -->0
331
+
end
332
+
```
333
+
is not permitted. E.g. here `Xadd` must be explicitly declared as a parameter using `@parameters`:
334
+
```@example faq_dsl_inference
335
+
using Catalyst
336
+
rn = @reaction_network begin
337
+
@parameters Xadd
338
+
@discrete_events 1.0 => [X ~ X + Xadd]
339
+
d, X --> 0
340
+
end
341
+
```
342
+
343
+
It is possible to turn off all inference (requiring all symbols to be declared using `@parameters`, `@species`, and `@variables`) through the [`@require_declaration` option](@ref faq_require_declaration).
344
+
345
+
## [How can I turn off automatic inferring of species and parameters when using the DSL?](@id faq_require_declaration)
287
346
This option can be set using the `@require_declaration` option inside `@reaction_network`. In this case all the species, parameters, and variables in the system must be pre-declared using one of the `@species`, `@parameters`, or `@variables` macros. For more information about what is inferred automatically and not, please see the section on [`@require_declaration`](@ref dsl_advanced_options_require_dec).
Copy file name to clipboardExpand all lines: docs/src/model_creation/chemistry_related_functionality.md
+4-4Lines changed: 4 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -7,7 +7,7 @@ While Catalyst has primarily been designed around the modelling of biological sy
7
7
8
8
## [Modelling with compound species](@id chemistry_functionality_compounds)
9
9
10
-
### Creating compound species programmatically
10
+
### [Creating compound species programmatically](@id chemistry_functionality_compounds_programmatic)
11
11
We will first show how to create compound species through [programmatic model construction](@ref programmatic_CRN_construction), and then demonstrate using the DSL. To create a compound species, use the `@compound` macro, first designating the compound, followed by its components (and their stoichiometries). In this example, we will create a CO₂ molecule, consisting of one C atom and two O atoms. First, we create species corresponding to the components:
12
12
```@example chem1
13
13
using Catalyst
@@ -55,7 +55,7 @@ When multiple compounds are created, they can be created simultaneously using th
55
55
end
56
56
```
57
57
58
-
### Creating compound species within the DSL
58
+
### [Creating compound species within the DSL](@id chemistry_functionality_compounds_DSL)
59
59
It is also possible to declare species as compound species within the `@reaction_network` DSL, using the `@compounds` options:
60
60
```@example chem1
61
61
rn = @reaction_network begin
@@ -81,7 +81,7 @@ end
81
81
```
82
82
as the components `C`, `H`, and `O` are not declared as species anywhere. Please also note that only `@compounds` can be used as an option in the DSL, not `@compound`.
83
83
84
-
### Designating metadata and default values for compounds
84
+
### [Designating metadata and default values for compounds](@id chemistry_functionality_compounds_metadata)
85
85
Just like for normal species, it is possible to designate metadata and default values for compounds. Metadata is provided after the compound name, but separated from it by a `,`:
86
86
```@example chem1
87
87
@compound (CO2, [unit="mol"]) ~ C + 2O
@@ -99,7 +99,7 @@ nothing # hide
99
99
```
100
100
In all of these cases, the left-hand side must be enclosed within `()`.
101
101
102
-
### Compounds with multiple independent variables
102
+
### [Compounds with multiple independent variables](@id chemistry_functionality_compounds_mult_ivs)
103
103
While we generally do not need to specify independent variables for compound, if the components (together) have more than one independent variable, this *must be done*:
0 commit comments