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
+10-10Lines changed: 10 additions & 10 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,10 +2,10 @@
2
2
3
3
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.
4
4
- The `@compound` option, allowing the user to designate that a specific species is composed of certain subspecies.
5
-
- The `balance_reaction` function enabling the user to balance a reactions so the same number of compounds occur on both sides.
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 1 C species and 2 O species. First we create species corresponding to the components:
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:
9
9
```@example chem1
10
10
@variables t
11
11
@species C(t) O(t)
@@ -14,11 +14,11 @@ Next, we create the `CO2` compound:
14
14
```@example chem1
15
15
@compound CO2(t) = C + 2O
16
16
```
17
-
Here, the compound is the first argument to the macro, followed by its component. The `(t)` indicates that `CO2` is a time-dependant variable. Components with non-unitary stoichiometry have this value written before the component (generally, the rules for designating the components of a compounds are identical to hose of designating the substrates or products of a reaction). The created compound, `CO2`, is a species in every sense, and can be used wherever e.g. `C`could be used:
17
+
Here, the compound is the first argument to the macro, followed by its component. The `(t)` indicates that `CO2` is a timedependant species. 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 a species in every sense, and can be used wherever e.g. `C`can be used:
18
18
```@example chem1
19
19
isspecies(CO2)
20
20
```
21
-
However, in its metadatais stored the information of its components, which can be retrieved using the `components` (returning a vector of its component species) and `coefficients` (returning a vector with each component's stoichiometry) functions:
21
+
In its metadata, however, is stored information of its components, which can be retrieved using the `components` (returning a vector of its component species) and `coefficients` (returning a vector with each component's stoichiometry) functions:
22
22
```@example chem1
23
23
components(CO2)
24
24
```
@@ -41,7 +41,7 @@ Compound components that are also compounds are allowed, e.g. we can create a ca
41
41
@compound H2CO3(t) = CO2 + H2O
42
42
```
43
43
44
-
When multiple compounds are created, they can be created simultaneously using the `@compounds` macro, e.g. the previous code-block could have been executed using:
44
+
When multiple compounds are created, they can be created simultaneously using the `@compounds` macro, e.g. the previous code-block can be re-written as:
45
45
```@example chem1
46
46
@species H(t)
47
47
@compounds begin
@@ -50,18 +50,18 @@ When multiple compounds are created, they can be created simultaneously using th
50
50
end
51
51
```
52
52
53
-
One use 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 side.
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.
54
54
55
55
## 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`enable us to find coefficients creating a balanced reaction (in this case, where the number of carbon and oxygen atoms are teh same on both sides). To demonstrate, we first created the unbalanced 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:
57
57
```@example chem1
58
58
rx = @reaction k, C + O --> $CO2
59
59
```
60
-
Here, we set a reaction rate `k` (which is not involved in the reaction balancing). We also use interpolation of`CO2`, ensuring that the `CO2` used in the reaction is the same one we previously defined as a compound of `C` and `O`. Next, we call the `balance_reaction` function
60
+
Here, the reaction rate (`k`) is not involved in the reaction balancing. We use interpolation for`CO2`, ensuring that the `CO2` used in the reaction is the same one we previously defined as a compound of `C` and `O`. Next, we call the `balance_reaction` function
61
61
```@example chem1
62
62
balance_reaction(rx)
63
63
```
64
-
which correctly finds the (rather trivial) solution `C + 2O --> CO2`. Here we note that `balance_reaction` actually returns a vector. The reason is that the reaction balancing problem may have several solutions. Typically, there is only a single solution (in which case this is the vector's only element).
64
+
which correctly finds the (rather trivial) solution `C + 2O --> CO2`. Here we note that `balance_reaction` actually returns a vector. The reason is that the 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.
65
65
66
66
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:
Macro that creates a compound species, which is composed of smaller constituent species.
15
+
Macro that creates a compound species, which is composed of smaller component species.
16
16
17
17
Example:
18
18
```julia
@@ -22,7 +22,7 @@ Example:
22
22
```
23
23
24
24
Notes:
25
-
- The constituent species must be defined before using the `@compound` macro.
25
+
- The component species must be defined before using the `@compound` macro.
26
26
"""
27
27
macrocompound(expr)
28
28
make_compound(MacroTools.striplines(expr))
@@ -62,7 +62,7 @@ end
62
62
"""
63
63
@compounds
64
64
65
-
Macro that creates several compound species, which each is composed of smaller constituent species. Uses the same syntax as `@compound`, but with one compound species one each line.
65
+
Macro that creates several compound species, which each is composed of smaller component species. Uses the same syntax as `@compound`, but with one compound species one each line.
66
66
67
67
Example:
68
68
```julia
@@ -77,7 +77,7 @@ end
77
77
```
78
78
79
79
Notes:
80
-
- The constituent species must be defined before using the `@compound` macro.
80
+
- The component species must be defined before using the `@compound` macro.
81
81
"""
82
82
macrocompounds(expr)
83
83
make_compounds(MacroTools.striplines(expr))
@@ -132,6 +132,7 @@ function component_coefficients(s)
132
132
return [c => co for (c, co) inzip(components(s), coefficients(s))]
0 commit comments