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
+15-14Lines changed: 15 additions & 14 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -272,23 +272,24 @@ sol = solve(oprob)
272
272
plot(sol)
273
273
```
274
274
275
-
### [Turning off species, parameter, and variable inferring](@id dsl_advanced_options_require_dec)
276
-
In some cases it may be desirable for Catalyst to not infer species and parameters from the DSL, as in the case of reaction networks with very many variables, or as a sanity check that variable names are written correctly. To turn off inferring, simply add the `@require_declaration`macro to one of the lines of the `@reaction_network`declaration. Having this macro means that every single variable, species, or parameter will have to be explicitly declared using the `@variable`, `@species`, or `@parameter`macro. In the case that the DSL parser encounters an undeclared symbolic, it will error with an `UndeclaredSymbolicError` and print the reaction or equation that the undeclared symbolic was found in.
275
+
### [Turning off species, parameter, and variable inference](@id dsl_advanced_options_require_dec)
276
+
In some cases it may be desirable for Catalyst to not infer species and parameters from the DSL, as in the case of reaction networks with very many variables, or as a sanity check that variable names are written correctly. To turn off inference, simply use the `@require_declaration`option when using the `@reaction_network`DSL. This will require every single variable, species, or parameter used within the DSL to be explicitly declared using the `@variable`, `@species`, or `@parameter`options. In the case that the DSL parser encounters an undeclared symbolic, it will error with an `UndeclaredSymbolicError` and print the reaction or equation that the undeclared symbolic was found in.
277
277
278
-
```@example dsl_advanced_no_infer
278
+
```julia
279
279
using Catalyst
280
-
# The following case will throw an UndeclaredSymbolicError.
281
-
try @macroexpand @reaction_network begin
280
+
rn =@reaction_networkbegin
282
281
@require_declaration
283
282
(k1, k2), A <--> B
284
283
end
285
-
catch e
286
-
println(e.msg)
287
-
end
288
284
```
289
-
In order to avoid an error in this case all the relevant species and parameters will have to be declared.
285
+
Running the code above will yield the following error:
290
286
```
287
+
LoadError: UndeclaredSymbolicError: Unrecognized variables A detected in reaction expression: "((k1, k2), A <--> B)". Since the flag @require_declaration is declared, all species must be explicitly declared with the @species macro.
288
+
```
289
+
In order to avoid the error in this case all the relevant species and parameters will have to be declared.
290
+
```@example dsl_advanced_require_dec
291
291
# The following case will not error.
292
+
using Catalyst
292
293
t = default_t()
293
294
rn = @reaction_network begin
294
295
@require_declaration
@@ -299,11 +300,11 @@ end
299
300
```
300
301
301
302
The following cases in which the DSL would normally infer variables will all throw errors if `@require_declaration` is set and the variables are not explicitly declared.
302
-
-Inferring a species in a reaction, as in the example above
303
-
-Inferring a parameter in a reaction rate expression, as in the reaction line `k*n, A --> B`
304
-
-Inferring a parameter in the stoichiometry of a species, as in the reaction line `k, n*A --> B`
305
-
-Inferring a differential variable on the LHS of a coupled differential equation, as in `A` in `@equations D(A) ~ A^2`
306
-
-Inferring an [observable](@ref dsl_advanced_options_observables) that is declared using `@observables`
303
+
-Occurrence of an undeclared species in a reaction, as in the example above.
304
+
-Occurrence of an undeclared parameter in a reaction rate expression, as in the reaction line `k*n, A --> B`.
305
+
-Occurrence of an undeclared parameter in the stoichiometry of a species, as in the reaction line `k, n*A --> B`.
306
+
-Occurrence of an undeclared differential variable on the LHS of a coupled differential equation, as in `A` in `@equations D(A) ~ A^2`.
307
+
-Occurrence of an undeclared [observable](@ref dsl_advanced_options_observables) in an `@observables` expression, such as `@observables X1 ~ A + B`.
@@ -159,7 +159,7 @@ Macro that creates several compound species, which each is composed of smaller c
159
159
Example:
160
160
```julia
161
161
t = default_t()
162
-
@species C(t) H(t) O(t)
162
+
@species C(t) H(t) O(t)
163
163
@compounds
164
164
CH4(t) = C + 4H
165
165
O2(t) = 2O
@@ -168,11 +168,11 @@ t = default_t()
168
168
end
169
169
```
170
170
171
-
Notes:
171
+
Notes:
172
172
- The component species must be defined before using the `@compound` macro.
173
173
"""
174
174
macrocompounds(expr)
175
-
make_compounds(MacroTools.striplines(expr))
175
+
make_compounds(striplines(expr))
176
176
end
177
177
178
178
# Function managing the @compound macro.
@@ -183,7 +183,7 @@ function make_compounds(expr)
183
183
# For each compound in `expr`, creates the set of 7 compound creation lines (using `make_compound`).
184
184
# Next, loops through all 7*[Number of compounds] lines and add them to compound_declarations.
185
185
compound_calls = [Catalyst.make_compound(line) for line in expr.args]
186
-
for compound_call in compound_calls, line inMacroTools.striplines(compound_call).args
186
+
for compound_call in compound_calls, line instriplines(compound_call).args
187
187
push!(compound_declarations.args, line)
188
188
end
189
189
@@ -249,7 +249,7 @@ brxs = balance_reaction(rx) # No solution.
249
249
250
250
Notes:
251
251
- Balancing reactions that contain compounds of compounds is currently not supported.
252
-
- A reaction may not always yield a single solution; it could have an infinite number of solutions or none at all. When there are multiple solutions, a vector of all possible `Reaction` objects is returned. However, substrates and products may be interchanged as we currently do not solve for a linear combination that maintains the set of substrates and products.
252
+
- A reaction may not always yield a single solution; it could have an infinite number of solutions or none at all. When there are multiple solutions, a vector of all possible `Reaction` objects is returned. However, substrates and products may be interchanged as we currently do not solve for a linear combination that maintains the set of substrates and products.
253
253
- If the reaction cannot be balanced, an empty `Reaction` vector is returned.
254
254
"""
255
255
functionbalance_reaction(reaction::Reaction)
@@ -369,16 +369,16 @@ From a system, creates a new system where each reaction is a balanced version of
369
369
reaction of the original system. For more information, consider the `balance_reaction` function
370
370
(which is internally applied to each system reaction).
371
371
372
-
Arguments
372
+
Arguments
373
373
- `rs`: The reaction system that should be balanced.
374
374
375
375
Notes:
376
376
- If any reaction in the system cannot be balanced, throws an error.
377
-
- If any reaction in the system have an infinite number of potential reactions, throws an error.
377
+
- If any reaction in the system have an infinite number of potential reactions, throws an error.
378
378
Here, it would be possible to generate a valid reaction, however, no such routine is currently
379
379
implemented in `balance_system`.
380
380
- `balance_system` will not modify reactions of subsystems to the input system. It is recommended
381
-
not to apply `balance_system` to non-flattened systems.
381
+
not to apply `balance_system` to non-flattened systems.
382
382
"""
383
383
functionbalance_system(rs::ReactionSystem)
384
384
@set! rs.eqs = CatalystEqType[get_balanced_reaction(eq) for eq inget_eqs(rs)]
@@ -391,7 +391,7 @@ end
391
391
functionget_balanced_reaction(rx::Reaction)
392
392
brxs =balance_reaction(rx)
393
393
394
-
# In case there are no, or multiple, solutions to the balancing problem.
394
+
# In case there are no, or multiple, solutions to the balancing problem.
395
395
ifisempty(brxs)
396
396
error("Could not balance reaction `$rx`, unable to create a balanced `ReactionSystem`.")
0 commit comments