Skip to content

Commit 60ee753

Browse files
committed
fix docstrings and docs
1 parent 21a77ad commit 60ee753

File tree

3 files changed

+49
-37
lines changed

3 files changed

+49
-37
lines changed

docs/src/network_analysis/crnt.md renamed to docs/src/network_analysis/crn_theory.md

Lines changed: 32 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,27 @@
1+
> Note, currently API functions for network analysis and conservation law analysis
2+
> do not work with constant species (currently only generated by SBMLToolkit).
3+
14
# [Chemical Reaction Network Theory](@id network_analysis_structural_aspects)
25

36
The systems of ODEs or stochastic chemical kinetics models that arise from chemical
4-
reaction networks can often have their steady-state properties known in advance,
7+
reaction networks can often have their steady-state properties (number of steady states, etc.) known in advance,
58
simply by analyzing the graph structure of the network. The subfield of chemistry
69
and math studying this relationship is called [Chemical Reaction Network Theory](https://en.wikipedia.org/wiki/Chemical_reaction_network_theory).
710

8-
In this tutorial we introduce several of the Catalyst API functions for network
11+
In this tutorial we give a broad overview of chemical reaction network theory, building on the discussion of the structure of
12+
the reaction network ODEs in the previous section. We also introduce several of the Catalyst API functions for network
913
analysis. A complete summary of the exported functions is given in the API
1014
section
11-
[`Network-Analysis-and-Representations`](https://docs.sciml.ai/Catalyst/stable/api/catalyst_api/#Network-Analysis-and-Representations).
15+
[Network Analysis and Representations](@ref api_network_analysis).
1216

1317
Broadly, results from chemical reaction network theory relate a purely
1418
graph-structural property (e.g. deficiency) to dynamical properties of the reaction system
15-
(e.g. complex balance).
16-
17-
We'll now illustrate some of the types of network properties that Catalyst can determine,
18-
using the [reaction complex representation](@ref network_analysis_reaction_complexes) in these calculations.
19+
(e.g. complex balance). The relevant graph here is the one corresponding to the [reaction complex representation](@ref network_analysis_reaction_complexes)
20+
of the network, where the nodes represent the reaction complexes and the edges represent reactions.
21+
Let us illustrate some of the types of network properties that
22+
Catalyst can determine.
1923

20-
Throughout this seciton, we will consider the [reaction complex representation](@ref network_analysis_reaction_complexes) of the following reaction network.
24+
To begin, consider the following reaction network:
2125
```@example s1
2226
using Catalyst
2327
rn = @reaction_network begin
@@ -34,7 +38,7 @@ with graph
3438
plot_complexes(rn)
3539
```
3640

37-
### [Linkage classes and sub-networks of the reaction network](@id network_analysis_structural_aspects_linkage)
41+
## [Linkage classes and sub-networks of the reaction network](@id network_analysis_structural_aspects_linkage)
3842
The preceding reaction complex graph shows that `rn` is composed of two
3943
disconnected sub-graphs, one containing the complexes ``A+B``, ``C``, ``D+E``, and
4044
``F``, the other containing the complexes ``2A``, ``B + G``, and ``H``. These sets,
@@ -69,10 +73,7 @@ and,
6973
plot_complexes(subnets[2])
7074
```
7175

72-
![subnetwork_2](../assets/complex_subnets2.svg)
73-
74-
75-
# [Deficiency of the network](@id network_analysis_structural_aspects_deficiency)
76+
## [Deficiency of the network](@id network_analysis_structural_aspects_deficiency)
7677
A famous theorem in Chemical Reaction Network Theory, the Deficiency Zero
7778
Theorem [^1], allows us to use knowledge of the net stoichiometry matrix and the
7879
linkage classes of a *mass action* [RRE ODE system](@ref network_analysis_matrix_vector_representation) to draw conclusions about the
@@ -127,7 +128,7 @@ Quoting Feinberg [^1]
127128
> linkage classes will allow.
128129
129130

130-
### [Reversibility of the network](@id network_analysis_structural_aspects_reversibility)
131+
## [Reversibility of the network](@id network_analysis_structural_aspects_reversibility)
131132
A reaction network is *reversible* if the "arrows" of the reactions are
132133
symmetric so that every reaction is accompanied by its reverse reaction.
133134
Catalyst's API provides the [`isreversible`](@ref) function to determine whether
@@ -148,7 +149,7 @@ isreversible(rn)
148149
```
149150
Consider another example,
150151
```@example s1
151-
rn = @reaction_network begin
152+
rn2 = @reaction_network begin
152153
(k1,k2),A <--> B
153154
k3, A + C --> D
154155
k4, D --> B+E
@@ -174,7 +175,7 @@ isweaklyreversible(rn, subnets)
174175
Every reversible network is also weakly reversible, but not every weakly
175176
reversible network is reversible.
176177

177-
### [Deficiency Zero Theorem](@id network_analysis_structural_aspects_deficiency_zero_theorem)
178+
## [Deficiency Zero Theorem](@id network_analysis_structural_aspects_deficiency_zero_theorem)
178179
Knowing the deficiency and weak reversibility of a mass action chemical reaction
179180
network ODE model allows us to make inferences about the corresponding
180181
steady state behavior. Before illustrating how this works for one example, we
@@ -248,16 +249,16 @@ asymptotically stable.
248249

249250
As a final example, consider the following network from [^1]
250251
```@example s1
251-
rn = @reaction_network begin
252+
def0_rn = @reaction_network begin
252253
(k1,k2),A <--> 2B
253254
(k3,k4), A + C <--> D
254255
k5, B+E --> C + D
255256
end
256-
reactioncomplexes(rn)
257-
subnets = subnetworks(rn)
258-
isma = all(rx -> ismassaction(rx,rn), reactions(rn))
259-
def = deficiency(rn)
260-
iswr = isweaklyreversible(rn, subnets)
257+
reactioncomplexes(def0_rn)
258+
subnets = subnetworks(def0_rn)
259+
isma = all(rx -> ismassaction(rx,def0_rn), reactions(def0_rn))
260+
def = deficiency(def0_rn)
261+
iswr = isweaklyreversible(def0_rn, subnets)
261262
isma,def,iswr
262263
```
263264
which we see is mass action and has deficiency zero, but is not weakly
@@ -268,26 +269,29 @@ RRE ODEs cannot have a positive equilibrium solution.
268269
satisfiesdeficiencyzero
269270
```
270271

271-
### Deficiency One Theorem
272+
## Deficiency One Theorem
272273
Very analogous to the deficiency zero theorem is the deficiency one theorem. The deficiency one theorem applies to a network with the following properties:
273274
1. The deficiency of each *linkage class* of the network is at most 1,
274275
2. The sum of the linkage class deficiencies is the total deficiency of the network, and
275-
3. Each linkage class has at most one terminal linkage class.
276+
3. Each linkage class has at most one terminal linkage class, which is a linkage class that is 1) strongly connected, and 2) has no outgoing reactions.
277+
278+
For the set of reactions $A \to B, B \to A, B \to C$, $\{A, B, C\}$ is a linkage class, and $\{A, B\}$ is a strong linkage class (since A is reachable from B and vice versa). However, $\{A, B\}$ is not a terminal linkage class, because the reaction $B \to C$ goes to a complex outside the linkage class.
276279

277280
If these conditions are met, then the network will have at most one steady state in each stoichiometric compatibility class for any choice of rate constants and parameters.
278281
Unlike the deficiency zero theorem, networks obeying the deficiency one theorem are not guaranteed to have stable solutions.
282+
279283
```@docs; canonical=false
280284
satisfiesdeficiencyone
281285
```
282286

283-
### [Complex and Detailed Balance](@id network_analysis_complex_and_detailed_balance)
287+
## [Complex and Detailed Balance](@id network_analysis_complex_and_detailed_balance)
284288
A reaction network's steady state is **complex-balanced** if the total production of each *complex* is zero at the steady state. A reaction network's steady state is **detailed balanced** if every reaction is balanced by its reverse reaction at the steady-state (this corresponds to the usual notion of chemical equilibrium; note that this requires every reaction be reversible).
285289

286290
Note that detailed balance at a given steady state implies complex balance for that steady state, i.e. detailed balance is a stronger property than complex balance.
287291

288292
Remarkably, having just one positive steady state that is complex (detailed) balance implies that complex (detailed) balance obtains at *every* positive steady state, so we say that a network is complex (detailed) balanced if any one of its steady states are complex (detailed) balanced. Additionally, there will be exactly one steady state in every positive stoichiometric compatibility class, and this steady state is asymptotically stable. (For proofs of these results, please consult Martin Feinberg's *Foundations of Chemical Reaction Network Theory*[^1]). So knowing that a network is complex balanced is really quite powerful.
289293

290-
Let's check that the reaction network defined above is complex balanced by providing a set of rates:
294+
Let's check whether the reaction network defined above is complex balanced by providing a set of rates:
291295
```@example s1
292296
rates = Dict([:k1 => 2.4, :k2 => 4., :k3 => 10., :k4 => 5.5, :k5 => 0.4])
293297
iscomplexbalanced(rn, rates)
@@ -296,7 +300,7 @@ iscomplexbalanced(rn, rates)
296300
We can do a similar check for detailed balance. Let us make the reaction network
297301
```@example s1
298302
rn1 = @reaction_network begin
299-
(k1,k2),A <--> 2B
303+
(k1,k2), A <--> 2B
300304
(k3,k4), A + C <--> D
301305
(k5,k6), B + E --> C + D
302306
end
@@ -310,7 +314,7 @@ iscomplexbalanced
310314
isdetailedbalanced
311315
```
312316

313-
### [Concentration Robustness](@id network_analysis_concentration_robustness)
317+
## [Concentration Robustness](@id network_analysis_concentration_robustness)
314318
Certain reaction networks have species that do not change their concentration,
315319
regardless of the system is perturbed to a different stoichiometric compatibility
316320
class. This is a very useful property to have in biological contexts, where it might

docs/src/network_analysis/odes.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
# [Decomposing the Reaction Network ODEs](@id network_analysis_odes)
22

33
In this tutorial we will discuss the specific mathematical
4-
structure of the ODEs that arise from the mass-action dynamics
4+
structure of the [ODEs that arise from the mass-action dynamics](@ref math_models_in_catalyst_rre_odes)
55
of chemical reaction networks, and decompose them as a product
66
of matrices that describe the network. A complete summary of
7-
the exported functions is given in the API section [`Network-Analysis-and-Representations`](https://docs.sciml.ai/Catalyst/stable/api/catalyst_api/#Network-Analysis-and-Representations). See Feinberg's *Foundations of Chemical Reaction
7+
the exported functions is given in the API section [Network Analysis and Representations](@ref api_network_analysis). Please consult Feinberg's *Foundations of Chemical Reaction
88
Network Theory*[^1] for more discussion about the concepts on this page.
99

1010
Note, currently API functions for network analysis and conservation law analysis
@@ -240,14 +240,16 @@ K = fluxmat(rn)
240240

241241
Since we have that $\mathbf{v} = K\Phi$, we can rewrite the above decompositions as follows:
242242
```math
243+
\begin{align}
243244
\frac{d\mathbf{x}}{dt} &= N \mathbf{v}(\mathbf{x}(t),t) \\
244245
&= N K \Phi(\mathbf{x}(t),t) \\
245246
&= Z B K \Phi(\mathbf{x}(t),t).
247+
\end{align}
246248
```
247249

248250
The final matrix to discuss is the product of $A_k = BK$, which is a $C$-by-$C$ matrix that turns out to be exactly the negative of the [graph Laplacian](https://en.wikipedia.org/wiki/Laplacian_matrix) of the weighted graph whose nodes are reaction complexes and whose edges represent reactions, weighted by the rate constants. The API function for $A_k$ is the `laplacianmat`:
249251
```@example s1
250-
A_k = incidencemat(rn)
252+
A_k = laplacianmat(rn)
251253
```
252254
We can check that
253255
```@example s1
@@ -256,10 +258,12 @@ A_k == B * K
256258

257259
In sum, we have that
258260
```math
261+
\begin{align}
259262
\frac{d\mathbf{x}}{dt} &= N \mathbf{v}(\mathbf{x}(t),t) \\
260263
&= N K \Phi(\mathbf{x}(t),t) \\
261264
&= Z B K \Phi(\mathbf{x}(t),t).
262265
&= Z A_k \Phi(\mathbf{x}(t),t).
266+
\end{align}
263267
```
264268

265269
All three of the objects introduced in this section (the flux matrix, mass-action vector, Laplacian matrix) will return symbolic outputs by default, but can be made to return numerical outputs if values are specified.

src/network_analysis.jl

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,8 @@ end
198198
Return the negative of the graph Laplacian of the reaction network. The ODE system of a chemical reaction network can be factorized as ``\frac{dx}{dt} = Y A_k Φ(x)``, where ``Y`` is the [`complexstoichmat`](@ref) and ``A_k`` is the negative of the graph Laplacian, and ``Φ`` is the [`massactionvector`](@ref). ``A_k`` is an n-by-n matrix, where n is the number of complexes, where ``A_{ij} = k_{ij}`` if a reaction exists between the two complexes and 0 otherwise.
199199
Returns a symbolic matrix by default, but will return a numerical matrix if parameter values are specified via pmap.
200200
201+
Returns a symbolic matrix by default, but will return a numerical matrix if parameter values are specified via pmap.
202+
201203
**Warning**: Unlike other Catalyst functions, the `laplacianmat` function will return a `Matrix{Num}` in the symbolic case. This is to allow easier computation of the matrix decomposition of the ODEs, and to ensure that multiplying the sparse form of the matrix will work.
202204
"""
203205
function laplacianmat(rn::ReactionSystem, pmap::Dict = Dict(); sparse = false)
@@ -209,10 +211,10 @@ end
209211
@doc raw"""
210212
fluxmat(rn::ReactionSystem, pmap = Dict(); sparse=false)
211213
212-
Return an r×c matrix ``K`` such that, if complex ``j`` is the substrate complex of reaction ``i``, then ``K_{ij} = k``, the rate constant for this reaction. Mostly a helper function for the network Laplacian, [`laplacianmat`](@ref). Has the useful property that ``\frac{dx}{dt} = S*K*Φ(x)``, where S is the [`netstoichmat`](@ref) or net stoichiometry matrix and ``Φ(x)`` is the [`massactionvector`](@ref).
214+
Return an r×c matrix ``K`` such that, if complex ``j`` is the substrate complex of reaction ``i``, then ``K_{ij} = k``, the rate constant for this reaction. Mostly a helper function for the network Laplacian, [`laplacianmat`](@ref). Has the useful property that ``\frac{dx}{dt} = S*K*Φ(x)``, where S is the [`netstoichmat`](@ref) or net stoichiometry matrix and ``Φ(x)`` is the [`massactionvector`](@ref).
213215
Returns a symbolic matrix by default, but will return a numerical matrix if rate constants are specified as a `Tuple`, `Vector`, or `Dict` of symbol-value pairs via `pmap`.
214216
215-
**Warning**: Unlike other Catalyst functions, the `fluxmat` function will return a `Matrix{Num}` in the symbolic case. This is to allow easier computation of the matrix decomposition of the ODEs, and to ensure that multiplying the sparse form of the matrix will work.
217+
**Warning**: Unlike other Catalyst functions, the `fluxmat` function will return a `Matrix{Num}` in the symbolic case. This is to allow easier computation of the matrix decomposition of the ODEs, and to ensure that multiplying the sparse form of the matrix will work.
216218
"""
217219
function fluxmat(rn::ReactionSystem, pmap::Dict = Dict(); sparse=false)
218220
deps = Set()
@@ -286,11 +288,13 @@ end
286288
"""
287289
massactionvector(rn::ReactionSystem, scmap = Dict(); combinatoric_ratelaws = true)
288290
289-
Return the vector whose entries correspond to the "mass action products" of each complex. For example, given the complex A + B, the corresponding entry of the vector would be ``A*B``, and for the complex 2X + Y, the corresponding entry would be ``X^2*Y``. The ODE system of a chemical reaction network can be factorized as ``\frac{dx}{dt} = Y A_k Φ(x)``, where ``Y`` is the [`complexstoichmat`](@ref) and ``A_k`` is the negative of the [`laplacianmat`](@ref). This utility returns ``Φ(x)``.
290-
Returns a symbolic vector by default, but will return a numerical vector if species concentrations are specified as a tuple, vector, or dictionary via scmap.
291-
If the `combinatoric_ratelaws` option is set, will include prefactors for that (see [introduction to Catalyst's rate laws](@ref introduction_to_catalyst_ratelaws). Will default to the default for the system.
291+
Return the vector whose entries correspond to the "mass action products" of each complex. For example, given the complex A + B, the corresponding entry of the vector would be ``A*B``, and for the complex 2X + Y, the corresponding entry would be ``X^2*Y``. The ODE system of a chemical reaction network can be factorized as ``\frac{dx}{dt} = Y A_k Φ(x)``, where ``Y`` is the [`complexstoichmat`](@ref) and ``A_k`` is the negative of the [`laplacianmat`](@ref). This utility returns ``Φ(x)``.
292+
293+
Returns a symbolic vector by default, but will return a numerical vector if species concentrations are specified as a tuple, vector, or dictionary via scmap.
294+
295+
If the `combinatoric_ratelaws` option is set, will include prefactors for that (see [introduction to Catalyst's rate laws](@ref introduction_to_catalyst_ratelaws). Will default to the default for the system.
292296
293-
**Warning**: Unlike other Catalyst functions, the `massactionvector` function will return a `Vector{Num}` in the symbolic case. This is to allow easier computation of the matrix decomposition of the ODEs.
297+
**Warning**: Unlike other Catalyst functions, the `massactionvector` function will return a `Vector{Num}` in the symbolic case. This is to allow easier computation of the matrix decomposition of the ODEs.
294298
"""
295299
function massactionvector(rn::ReactionSystem, scmap::Dict = Dict(); combinatoric_ratelaws = Catalyst.get_combinatoric_ratelaws(rn))
296300
r = numreactions(rn)

0 commit comments

Comments
 (0)