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/introduction_to_catalyst/catalyst_for_new_julia_users.md
+2-2Lines changed: 2 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -77,7 +77,7 @@ Catalyst models are created through the `@reaction_network` *macro*. For more in
77
77
78
78
The `@reaction_network` command is followed by the `begin` keyword, which is followed by one line for each *reaction* of the model. Each reaction consists of a *reaction rate*, followed by the reaction itself. The reaction contains a set of *substrates* and a set of *products* (what is consumed and produced by the reaction, respectively). These are separated by a `-->` arrow. Finally, the model ends with the `end` keyword.
79
79
80
-
Here, we create a simple *birth-death* model, where a single species ($X$) is created at rate $b$, and degraded at rate $d$. The model is stored in the variable `rn`.
80
+
Here, we create a simple [*birth-death* model](@ref basic_CRN_library_bd), where a single species ($X$) is created at rate $b$, and degraded at rate $d$. The model is stored in the variable `rn`.
81
81
```@example ex2
82
82
rn = @reaction_network begin
83
83
b, 0 --> X
@@ -136,7 +136,7 @@ Pkg.add("JumpProcesses")
136
136
using JumpProcesses
137
137
```
138
138
139
-
This time, we will declare a so-called [SIR model for an infectious disease](https://en.wikipedia.org/wiki/Compartmental_models_in_epidemiology#The_SIR_model). Note that even if this model does not describe a set of chemical reactions, it can be modelled using the same framework. The model consists of 3 species:
139
+
This time, we will declare a so-called [SIR model for an infectious disease](@ref basic_CRN_library_sir). Note that even if this model does not describe a set of chemical reactions, it can be modelled using the same framework. The model consists of 3 species:
140
140
* $S$, the amount of *susceptible* individuals.
141
141
* $I$, the amount of *infected* individuals.
142
142
* $R$, the amount of *recovered* (or *removed*) individuals.
While Catalyst has primarily been designed around the modelling of biological systems, reaction network models are also common across chemistry. This section describes two types of functionality, that while of general interest, should be especially useful in the modelling of chemical systems.
3
+
While Catalyst has primarily been designed around the modelling of biological systems, reaction network models are also common in chemistry. This section describes two types of functionality, that while of general interest, should be especially useful in the modelling of chemical systems.
4
4
- The `@compound` option, which enables the user to designate that a specific species is composed of certain subspecies.
5
5
- The `balance_reaction` function, which enables the user to balance a reaction so the same number of components occur on both sides.
6
6
7
+
7
8
## Modelling with compound species
8
9
9
10
### Creating compound species programmatically
@@ -17,7 +18,7 @@ Next, we create the `CO2` compound species:
17
18
```@example chem1
18
19
@compound CO2 ~ C + 2O
19
20
```
20
-
Here, the compound is the first argument to the macro, followed by its component (with the left-hand and right-hand sides separated by a `~` sign). While non-compound species (such as `C` and `O`) have their independent variable (in this case `t`) designated, independent variables are generally not designated for compounds (these are instead directly inferred from their components). Components with non-unit stoichiometries have this value written before the component (generally, the rules for designating the components of a compound are identical to those of designating the substrates or products of a reaction). The created compound, `CO2`, is also a species, and can be used wherever e.g. `C` can be used:
21
+
Here, the compound is the first argument to the macro, followed by its component (with the left-hand and right-hand sides separated by a `~` sign). While non-compound species (such as `C` and `O`) have their independent variable (in this case `t`) designated, independent variables are generally not designated for compounds (these are instead directly inferred from their components). Components with non-unitary stoichiometries have this value written before the component (generally, the rules for designating the components of a compound are identical to those of designating the substrates or products of a reaction). The created compound, `CO2`, is also a species, and can be used wherever e.g. `C` can be used:
21
22
```@example chem1
22
23
isspecies(CO2)
23
24
```
@@ -32,7 +33,7 @@ Alternatively, we can retrieve the components and their stoichiometric coefficie
32
33
```@example chem1
33
34
component_coefficients(CO2)
34
35
```
35
-
Finally, it is possible to check whether a species is a compound or not using the `iscompound` function:
36
+
Finally, it is possible to check whether a species is a compound using the `iscompound` function:
36
37
```@example chem1
37
38
iscompound(CO2)
38
39
```
@@ -68,7 +69,7 @@ end
68
69
```
69
70
When creating compound species using the DSL, it is important to note that *every component must be known to the system as a species, either by being declared using the `@species` or `@compound` options, or by appearing in a reaction*. E.g. the following is not valid
70
71
```julia
71
-
rn =@reaction_networkbegin``
72
+
rn =@reaction_networkbegin
72
73
@compoundsbegin
73
74
C2O ~ C +2O
74
75
H2O ~2H + O
@@ -77,7 +78,7 @@ rn = @reaction_network begin``
77
78
(k1,k2), H2O+ CO2 <--> H2CO3
78
79
end
79
80
```
80
-
as the components `C`, `H`, and `O` are not declared as a species anywhere. Please also note that only `@compounds` can be used as an option in the DSL, not `@compound`.
81
+
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`.
81
82
82
83
### Designating metadata and default values for compounds
83
84
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 `,`:
@@ -92,10 +93,10 @@ If both default values and meta data are provided, the metadata is provided afte
92
93
```@example chem1
93
94
@compound (CO2 = 2.0, [unit="mol"]) ~ C + 2O
94
95
```
95
-
In all of these cases, the side to the left of the `~` must be enclosed within `()`.
96
+
In all of these cases, the left-hand side must be enclosed within `()`.
96
97
97
98
### Compounds with multiple independent variables
98
-
While we generally do not need to specify independent variables for compound, if the components (together) have more than one independent variable, this have to be done:
99
+
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*:
99
100
```@example chem1
100
101
t = default_t()
101
102
@variables s
@@ -113,7 +114,7 @@ Here, the reaction rate (`k`) is not involved in the reaction balancing. We use
113
114
```@example chem1
114
115
balance_reaction(rx)
115
116
```
116
-
which correctly finds the (rather trivial) solution `C + 2O --> CO2`. Here we note that `balance_reaction` actually returns a vector. The reason is thatthe reaction balancing problem may have several solutions. Typically, there is only a single solution (in which case this is the vector's only element). No, or an infinite number of, solutions is also possible depending on the given reaction.
117
+
which correctly finds the (rather trivial) solution `C + 2O --> CO2`. Here we note that `balance_reaction` actually returns a vector. The reason is that, in some cases, the reaction balancing problem does not have a single obvious solution. Typically, a single solution is the obvious candidate (in which case this is the vector's only element). However, when this is not the case, the vector instead contain several reactions (from which a balanced reaction cab be generated).
117
118
118
119
Let us consider a more elaborate example, the reaction between ammonia (NH₃) and oxygen (O₂) to form nitrogen monoxide (NO) and water (H₂O). Let us first create the components and the unbalanced reaction:
Copy file name to clipboardExpand all lines: docs/src/model_creation/dsl_advanced.md
+16-16Lines changed: 16 additions & 16 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -9,7 +9,7 @@ using Catalyst
9
9
```
10
10
11
11
## [Explicit specification of network species and parameters](@id dsl_advanced_options_declaring_species_and_parameters)
12
-
[Previously](@ref ref), we mentioned that the DSL automatically determines which symbols correspond to species and which to parameters. This is done by designating everything that appears as either a substrate or a product as a species, and all remaining quantities as parameters (i.e. those only appearing within rates or [stoichiometric constants](@refref)). Sometimes, one might want to manually override this default behaviour for a given symbol. I.e. consider the following model, where the conversion of a protein `P` from its inactive form (`Pᵢ`) to its active form (`Pₐ`) is catalysed by an enzyme (`E`). Using the most natural description:
12
+
Previously, we mentioned that the DSL automatically determines which symbols correspond to species and which to parameters. This is done by designating everything that appears as either a substrate or a product as a species, and all remaining quantities as parameters (i.e. those only appearing within rates or [stoichiometric constants](@refdsl_description_stoichiometries_parameters)). Sometimes, one might want to manually override this default behaviour for a given symbol. I.e. consider the following model, where the conversion of a protein `P` from its inactive form (`Pᵢ`) to its active form (`Pₐ`) is catalysed by an enzyme (`E`). Using the most natural description:
13
13
```@example dsl_advanced_explicit_definitions
14
14
catalysis_sys = @reaction_network begin
15
15
k*E, Pᵢ --> Pₐ
@@ -74,7 +74,7 @@ end
74
74
parameters(dimerisation)
75
75
```
76
76
!!! danger
77
-
Generally, Catalyst and the SciML ecosystem *do not* guarantee that parameter and species order are preserved throughout various operations on a model. Writing programs that depend on these orders is *strongly discouraged*. There are, however, some legacy packages which still depend on order (one example is provided [here](@refref)). In these situations, this might be useful. However, in these cases, it is recommended that the user is extra wary, and also checks the order manually.
77
+
Generally, Catalyst and the SciML ecosystem *do not* guarantee that parameter and species order are preserved throughout various operations on a model. Writing programs that depend on these orders is *strongly discouraged*. There are, however, some legacy packages which still depend on order (one example can be found [here](@refoptimization_parameter_fitting_basics)). In these situations, this might be useful. However, in these cases, it is recommended that the user is extra wary, and also checks the order manually.
78
78
79
79
!!! note
80
80
The syntax of the `@species` and `@parameters` options is identical to that used by the `@species` and `@parameters` macros [used in programmatic modelling in Catalyst](@ref programmatic_CRN_construction) (for e.g. designating metadata or initial conditions). Hence, if one has learnt how to specify species/parameters using either approach, that knowledge can be transferred to the other one.
@@ -125,7 +125,7 @@ rn = @reaction_network begin
125
125
end
126
126
127
127
tspan = (0.0, 10.0)
128
-
p = [:p => 1.0, :D => 0.2]
128
+
p = [:p => 1.0, :d => 0.2]
129
129
oprob = ODEProblem(rn, u0, tspan, p)
130
130
sol = solve(oprob)
131
131
plot(sol)
@@ -171,18 +171,18 @@ two_state_system = @reaction_network begin
171
171
(ka,kD), Xi <--> Xa
172
172
end
173
173
```
174
-
A metadata can be given to only a subset of a system's species/parameters, and a quantity can be given several metadata entries. To give several metadata, separate each by a `,`. Here we only provide a description for `kA`, for which we also provide a [bounds metadata](@refhttps://docs.sciml.ai/ModelingToolkit/dev/basics/Variable_metadata/#Bounds),
174
+
A metadata can be given to only a subset of a system's species/parameters, and a quantity can be given several metadata entries. To give several metadata, separate each by a `,`. Here we only provide a description for `kA`, for which we also provide a [`bounds` metadata](@refhttps://docs.sciml.ai/ModelingToolkit/dev/basics/Variable_metadata/#Bounds),
175
175
```@example dsl_advanced_metadata
176
176
two_state_system = @reaction_network begin
177
-
@parameters kA [description="X's activation rate", bound=(0.01,10.0)]
177
+
@parameters kA [description="X's activation rate", bounds=(0.01,10.0)]
178
178
(ka,kD), Xi <--> Xa
179
179
end
180
180
```
181
181
182
182
It is possible to add both default values and metadata to a parameter/species. In this case, first provide the default value, and next the metadata. I.e. to in the above example set $kA$'s default value to $1.0$ we use
@@ -191,10 +191,10 @@ When designating metadata for species/parameters in `begin ... end` blocks the s
191
191
```@example dsl_advanced_metadata
192
192
two_state_system = @reaction_network begin
193
193
@parameters begin
194
-
kA, [description="X's activation rate", bound=(0.01,10.0)]
195
-
kD = 1.0, [description="X's deactivation rate"]
194
+
kA, [description="X's activation rate", bounds=(0.01,10.0)]
195
+
kD = 1.0, [description="X's deactivation rate"]
196
196
end
197
-
(ka,kD), Xi <--> Xa
197
+
(kA,kD), Xi <--> Xa
198
198
end
199
199
```
200
200
@@ -229,7 +229,7 @@ end
229
229
A common use-case for constant species is when modelling systems where some species are present in such surplus that their amounts the reactions' effect on it is negligible. A system which is commonly modelled this way is the [Brusselator](https://en.wikipedia.org/wiki/Brusselator).
Sometimes it is desired to designate that a parameter should have a specific [type](@ref ref). When supplying this parameter's value to e.g. an `ODEProblem`, that parameter will then be restricted to that specific type. Designating a type is done by appending the parameter with `::` followed by its type. E.g. in the following example we specify that the parameter `n` (the number of `X` molecules in the `Xn` polymer) must be an integer (`Int64`)
232
+
Sometimes it is desired to designate that a parameter should have a specific [type](https://docs.julialang.org/en/v1/manual/types/). When supplying this parameter's value to e.g. an `ODEProblem`, that parameter will then be restricted to that specific type. Designating a type is done by appending the parameter with `::` followed by its type. E.g. in the following example we specify that the parameter `n` (the number of `X` molecules in the `Xn` polymer) must be an integer (`Int64`)
233
233
```@example dsl_advanced_parameter_types
234
234
using Catalyst # hide
235
235
polymerisation_network = @reaction_network begin
@@ -238,7 +238,7 @@ polymerisation_network = @reaction_network begin
238
238
end
239
239
nothing # hide
240
240
```
241
-
Generally, when simulating models with mixed parameter types, it is recommended to [declare parameter values as tuples, rather than vectors](@refref), e.g.:
241
+
Generally, when simulating models with mixed parameter types, it is recommended to [declare parameter values as tuples, rather than vectors](@refsimulation_intro_ODEs_input_forms), e.g.:
242
242
```@example dsl_advanced_parameter_types
243
243
ps = (:kB => 0.2, :kD => 1.0, :n => 2)
244
244
nothing # hide
@@ -254,7 +254,7 @@ nothing # hide
254
254
```
255
255
256
256
### [Vector-valued species or parameters](@id dsl_advanced_options_vector_variables)
257
-
Sometimes, one wishes to declare a large number of similar parameters or species. This can be done by *creating them as vectors*. E.g. below we create a [two-state system](@refref). However, instead of declaring `X1` and `X2` (and `k1` and `k2`) as separate entities, we declare them as vectors:
257
+
Sometimes, one wishes to declare a large number of similar parameters or species. This can be done by *creating them as vectors*. E.g. below we create a [two-state system](@refbasic_CRN_library_two_states). However, instead of declaring `X1` and `X2` (and `k1` and `k2`) as separate entities, we declare them as vectors:
258
258
```@example dsl_advanced_vector_variables
259
259
using Catalyst # hide
260
260
two_state_model = @reaction_network begin
@@ -316,7 +316,7 @@ end
316
316
rn1 == rn2
317
317
```
318
318
319
-
Setting model names is primarily useful for [hierarchical modelling](@refref), where network names are appended to the display names of subnetworks' species and parameters.
319
+
Setting model names is primarily useful for [hierarchical modelling](@refcompositional_modeling), where network names are appended to the display names of subnetworks' species and parameters.
Sometimes one might want to use observable variables. These are variables with values that can be computed directly from a system's state (rather than having their values implicitly given by reactions or equations). Observables can be designated using the `@observables` option. Here, the `@observables` option is followed by a `begin ... end` block with one line for each observable. Each line first gives the observable, followed by a `~` (*not* a `=`!), followed by an expression describing how to compute it.
@@ -350,11 +350,11 @@ sol[:Xtot]
350
350
to get a vector with `Xtot`'s value throughout the simulation. We can also use
351
351
```@example dsl_advanced_observables
352
352
using Plots
353
-
plot(sol; idxs = [:Xtot, :Ytot])
353
+
plot(sol; idxs = :Xtot)
354
354
```
355
355
to plot the observables (rather than the species).
356
356
357
-
Observables can be defined using complicated expressions containing species, parameters, and [variables](@ref ref) (but not other observables). In the following example (which uses a [parametric stoichiometry](@refref)) `X` polymerises to form a complex `Xn` containing `n` copies of `X`. Here, we create an observable describing the total number of `X` molecules in the system:
357
+
Observables can be defined using complicated expressions containing species, parameters, and [variables](@ref ref) (but not other observables). In the following example (which uses a [parametric stoichiometry](@refdsl_description_stoichiometries_parameters)) `X` polymerises to form a complex `Xn` containing `n` copies of `X`. Here, we create an observable describing the total number of `X` molecules in the system:
358
358
```@example dsl_advanced_observables
359
359
rn = @reaction_network begin
360
360
@observables Xtot ~ X + n*Xn
@@ -378,7 +378,7 @@ Observables are by default considered [variables](@ref ref) (not species). To de
0 commit comments