Skip to content

Commit 8f29ced

Browse files
committed
update doc with DSL compounds option.
1 parent b0c027d commit 8f29ced

File tree

1 file changed

+31
-3
lines changed

1 file changed

+31
-3
lines changed

docs/src/catalyst_functionality/chemistry_related_functionality.md

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ While Catalyst has primarily been designed around the modelling of biological sy
55
- The `balance_reaction` function enabling the user to balance a reaction so the same number of components occur on both sides.
66

77
## 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:
911
```@example chem1
1012
@variables t
1113
@species C(t) O(t)
@@ -50,10 +52,34 @@ When multiple compounds are created, they can be created simultaneously using th
5052
end
5153
```
5254

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_network begin
71+
@compounds begin
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`.
5480

5581
## 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:
5783
```@example chem1
5884
rx = @reaction k, C + O --> $CO2
5985
```
@@ -81,5 +107,7 @@ We can now create a balanced version (where the amount of H, N, and O is the sam
81107
balanced_reaction = balance_reaction(unbalanced_reaction)[1]
82108
```
83109

110+
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+
84112
!!! note
85113
Reaction balancing is currently not supported for reactions involving compounds of compounds.

0 commit comments

Comments
 (0)