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
+31-3Lines changed: 31 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,7 +5,9 @@ While Catalyst has primarily been designed around the modelling of biological sy
5
5
- The `balance_reaction` function enabling the user to balance a reaction so the same number of components occur on both sides.
6
6
7
7
## Modelling with compound species
8
-
Defining compound species is currently only supported for [programmatic construction](@ref programmatic_CRN_construction) of reactions and reaction network models. To create a compound species, use the `@compound` macro, first designating the compound, followed by its components (and stoichiometries). In this example, we will create a CO₂ compound species, consisting of one C species and two O species. First, we create species corresponding to the components:
8
+
9
+
#### Creating compound species programmatically
10
+
We will first show how to create compound species through [programmatic 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 stoichiometries). In this example, we will create a CO₂ compound species, consisting of one C species and two O species. First, we create species corresponding to the components:
9
11
```@example chem1
10
12
@variables t
11
13
@species C(t) O(t)
@@ -50,10 +52,34 @@ When multiple compounds are created, they can be created simultaneously using th
50
52
end
51
53
```
52
54
53
-
One use of defining a species as a compound is that they can be used to balance reactions to that the number of compounds are the same on both sides.
55
+
#### Creating compound species programmatically
56
+
It is also possible to declare species as compound species within the `@reaction_network` DSL, using the `@compounds` options:
57
+
```@example chem1
58
+
rn = @reaction_network begin
59
+
@species C(t) H(t) O(t)
60
+
@compounds begin
61
+
C2O(t) = C + 2O
62
+
H2O(t) = 2H + O
63
+
H2CO3(t) = CO2 + H2O
64
+
end
65
+
(k1,k2), H2O+ CO2 <--> H2CO3
66
+
end
67
+
```
68
+
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
+
```julia
70
+
rn =@reaction_networkbegin
71
+
@compoundsbegin
72
+
C2O(t) = C +2O
73
+
H2O(t) =2H + O
74
+
H2CO3(t) = CO2 + H2O
75
+
end
76
+
(k1,k2), H2O+ CO2 <--> H2CO3
77
+
end
78
+
```
79
+
as the components `C`, `H`, and `O` are not explicitly declared as a species anywhere. Please also note that only `@compounds` can be used as an option in the DSL, not `@compound`.
54
80
55
81
## Balancing chemical reactions
56
-
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:
82
+
One use of defining a species as a compound is that they can be used to balance reactions to that the number of compounds 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:
57
83
```@example chem1
58
84
rx = @reaction k, C + O --> $CO2
59
85
```
@@ -81,5 +107,7 @@ We can now create a balanced version (where the amount of H, N, and O is the sam
Reactions declared as a part of a `ReactionSystem` (e.g. using the DSL) can be retrieved for balancing using the `reaction` function. Please note that balancing these will not mutate the `ReactionSystem`, but a new reaction system will need to be created using the balanced reactions.
111
+
84
112
!!! note
85
113
Reaction balancing is currently not supported for reactions involving compounds of compounds.
0 commit comments