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/dsl_description.md
+62Lines changed: 62 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -701,3 +701,65 @@ rn = @reaction_network begin
701
701
end
702
702
nothing # hide
703
703
```
704
+
705
+
## Incorporating (differential) equations into reaction network models
706
+
Some models cannot be purely described as a reaction network. E.g. consider the growth of a cell, where the rate of change in cell's volume depends on some growth factor. Here, the cell's volume would be described by a normal equation. Such equations can be incorporated into a model using the `@equations` option. Here, we create a model where a growth factor ($G$) is produced and degraded at a linear rates, and the rate of change in cell volume ($V$) os linear to the amount of growth factor:
707
+
```@example eqs1
708
+
using Catalyst #hide
709
+
rn = @reaction_network begin
710
+
@equations begin
711
+
D(V) ~ G
712
+
end
713
+
(p,d), 0 <--> G
714
+
end
715
+
```
716
+
Here, `D(V)` indicates the (time) derivative with respect to `D`. The differential equation left and right hand sides are separated by a `~`. The left-hand side should contain differential only, the right hand side can contain any algebraic expression.
717
+
718
+
We can check the differential equation corresponding to this reaction network using latexify:
719
+
```@example eqs1
720
+
using Latexify
721
+
latexify(rn; form=:ode)
722
+
```
723
+
We can also simulate it using the normal syntax
724
+
```@example eqs1
725
+
using DifferentialEquations, Plots # hide
726
+
u0 = [:G => 0.0, :V => 0.1]
727
+
ps = [:p => 1.0, :d => 0.5]
728
+
oprob = ODEProblem(rn, u0, (0.0, 1.0), ps)
729
+
sol = solve(oprob)
730
+
plot(sol)
731
+
```
732
+
Here, growth is indefinite. To improve the model, [a callback](@ref advanced_simulations_callbacks) can be used to half the volume (cell division) once some threshold is reached.
733
+
734
+
When creating differential equations this way, the subject of the differential is automatically inferred to be a variable, however, any component on the right-hand side must be declare somewhere in the macro. E.g. to add a scaling parameter ($k$), we must declare that $k$ is a parmaeter using the `@paraemters` option:
735
+
```@example eqs1
736
+
rn = @reaction_network begin
737
+
@parameters k
738
+
@equations begin
739
+
D(V) ~ k*G
740
+
end
741
+
(p,d), 0 <--> G
742
+
end
743
+
nothing #hide
744
+
```
745
+
746
+
It is possible to add several equations to the model. In this case, each have a separate line. E.g. to keep track of a supply of nutrition ($N$) in the growth media, we can use:
747
+
```@example eqs1
748
+
rn = @reaction_network begin
749
+
@equations begin
750
+
D(V) ~ G
751
+
D(N) ~ -G
752
+
end
753
+
(p,d), 0 <--> G
754
+
end
755
+
nothing #hide
756
+
```
757
+
758
+
When only a single equation is added, the `begin ... end` statement can be omitted. E.g., the first model can be declared equivalently using:
Given a [`ReactionSystem`](@ref), return a vector of all `Equations` in the system that are differential equations (contains a derivative with respect to any variable).
103
+
Notes:
104
+
- If `ModelingToolkit.get_systems(network)` is not empty, will allocate.
# Goes through all differentials, checking that they are correctly formatted and their symbol is not used elsewhere.
840
+
for dexpr in diffexpr.args
841
+
(dexpr.head != :(=)) &&error("Differential declaration must have form like D = Differential(t), instead \"$(dexpr)\" was given.")
842
+
(dexpr.args[1] isa Symbol) ||error("Differential left-hand side must be a single symbol, instead \"$(dexpr.args[1])\" was given.")
843
+
in(dexpr.args[1], used_syms) &&error("Differential name ($(dexpr.args[1])) is also a species, variable, or parameter. This is ambigious and not allowed.")
844
+
in(dexpr.args[1], forbidden_symbols_error) &&error("A forbidden symbol ($(dexpr.args[1])) was used as a differential name.")
845
+
end
846
+
847
+
return diffexpr
848
+
end
849
+
850
+
# Read the events (continious or discrete) provided as options to the DSL. Returns an expression which evalutes to these.
0 commit comments