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/catalyst_functionality/chemistry_related_functionality.md
+16-7Lines changed: 16 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -6,7 +6,7 @@ While Catalyst has primarily been designed around the modelling of biological sy
6
6
7
7
## Modelling with compound species
8
8
9
-
####Creating compound species programmatically
9
+
### Creating compound species programmatically
10
10
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:
11
11
```@example chem1
12
12
using Catalyst
@@ -17,7 +17,7 @@ Next, we create the `CO2` compound species:
17
17
```@example chem1
18
18
@compound CO2 ~ C + 2O
19
19
```
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 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:
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
21
```@example chem1
22
22
isspecies(CO2)
23
23
```
@@ -53,7 +53,7 @@ When multiple compounds are created, they can be created simultaneously using th
53
53
end
54
54
```
55
55
56
-
####Creating compound species within the DSL
56
+
### Creating compound species within the DSL
57
57
It is also possible to declare species as compound species within the `@reaction_network` DSL, using the `@compounds` options:
58
58
```@example chem1
59
59
rn = @reaction_network begin
@@ -63,12 +63,12 @@ rn = @reaction_network begin
63
63
H2O ~ 2H + O
64
64
H2CO3 ~ CO2 + H2O
65
65
end
66
-
(k1,k2), H2O+ CO2 <--> H2CO3
66
+
(k1,k2), H2O+ CO2 <--> H2CO3
67
67
end
68
68
```
69
-
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`option, or by appearing in a reaction*. E.g. the following is not valid
69
+
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
70
```julia
71
-
rn =@reaction_networkbegin
71
+
rn =@reaction_networkbegin``
72
72
@compoundsbegin
73
73
C2O ~ C +2O
74
74
H2O ~2H + O
@@ -79,7 +79,7 @@ end
79
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
81
82
-
####Designating metadata and default values for compounds
82
+
### Designating metadata and default values for compounds
83
83
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 `,`:
84
84
```@example chem1
85
85
@compound (CO2, [unit="mol"]) ~ C + 2O
@@ -94,6 +94,15 @@ If both default values and meta data are provided, the metadata is provided afte
94
94
```
95
95
In all of these cases, the side to the left of the `~` must be enclosed within `()`.
96
96
97
+
### 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
+
```@example chem1
100
+
@variables t s
101
+
@species N(s) O(t)
102
+
@compound NO2(t,s) ~ N + 2O
103
+
```
104
+
Here, `NO2` depend both on a spatial independent variable (`s`) and a time one (`t`). This is required since, while multiple independent variables can be inferred, their internal order cannot (and must hence be provided by the user).
105
+
97
106
## Balancing chemical reactions
98
107
One use of defining a species as a compound is that they can be used to balance reactions so that the number of components are the same on both sides. Catalyst provides the `balance_reaction` function, which takes a reaction, and returns a balanced version. E.g. let us consider a reaction when carbon dioxide is formed from carbon and oxide `C + O --> CO2`. Here, `balance_reaction` enables us to find coefficients creating a balanced reaction (in this case, where the number of carbon and oxygen atoms are the same on both sides). To demonstrate, we first created the unbalanced reactions:
0 commit comments