Skip to content

Commit 99237cf

Browse files
committed
misc improvements
1 parent f9cab9e commit 99237cf

File tree

3 files changed

+119
-106
lines changed

3 files changed

+119
-106
lines changed

docs/src/catalyst_functionality/chemistry_related_functionality.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22

33
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.
44
- 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.
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 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:
99
```@example chem1
1010
@variables t
1111
@species C(t) O(t)
@@ -14,11 +14,11 @@ Next, we create the `CO2` compound:
1414
```@example chem1
1515
@compound CO2(t) = C + 2O
1616
```
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 time dependant 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:
1818
```@example chem1
1919
isspecies(CO2)
2020
```
21-
However, in its metadata is 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:
2222
```@example chem1
2323
components(CO2)
2424
```
@@ -41,7 +41,7 @@ Compound components that are also compounds are allowed, e.g. we can create a ca
4141
@compound H2CO3(t) = CO2 + H2O
4242
```
4343

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:
4545
```@example chem1
4646
@species H(t)
4747
@compounds begin
@@ -50,18 +50,18 @@ When multiple compounds are created, they can be created simultaneously using th
5050
end
5151
```
5252

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.
5454

5555
## 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:
5757
```@example chem1
5858
rx = @reaction k, C + O --> $CO2
5959
```
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
6161
```@example chem1
6262
balance_reaction(rx)
6363
```
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.
6565

6666
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:
6767
```@example chem2
@@ -76,7 +76,7 @@ using Catalyst # hide
7676
end
7777
unbalanced_reaction = @reaction k, $NH3 + $O2 --> $NO + $H2O
7878
```
79-
We can now created a balanced version (where the amount of H, N, and O is the same on both sides):
79+
We can now create a balanced version (where the amount of H, N, and O is the same on both sides):
8080
```@example chem2
8181
balanced_reaction = balance_reaction(unbalanced_reaction)[1]
8282
```

src/chemistry_functionality.jl

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Symbolics.option_to_metadata_type(::Val{:coefficients}) = CompoundCoefficients
1212
"""
1313
@compound
1414
15-
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.
1616
1717
Example:
1818
```julia
@@ -22,7 +22,7 @@ Example:
2222
```
2323
2424
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.
2626
"""
2727
macro compound(expr)
2828
make_compound(MacroTools.striplines(expr))
@@ -62,7 +62,7 @@ end
6262
"""
6363
@compounds
6464
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.
6666
6767
Example:
6868
```julia
@@ -77,7 +77,7 @@ end
7777
```
7878
7979
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.
8181
"""
8282
macro compounds(expr)
8383
make_compounds(MacroTools.striplines(expr))
@@ -132,6 +132,7 @@ function component_coefficients(s)
132132
return [c => co for (c, co) in zip(components(s), coefficients(s))]
133133
end
134134

135+
135136
### Reaction Balancing Functionality ###
136137

137138
# Reaction balancing error.

0 commit comments

Comments
 (0)