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
+63Lines changed: 63 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -701,3 +701,66 @@ 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 reaction networks. E.g. consider the growth of a cell, where the rate of change in the cell's volume depends on some growth factor. Here, the cell's volume would be described by a normal ODE. 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$) is linear in 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 parameter using the `@parameters` 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
+
If the differential does not appear isolated on the lhs, its subject variable must also be explicitly declared (as it is not inferred for these cases).
746
+
747
+
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:
748
+
```@example eqs1
749
+
rn = @reaction_network begin
750
+
@equations begin
751
+
D(V) ~ G
752
+
D(N) ~ -G
753
+
end
754
+
(p,d), 0 <--> G
755
+
end
756
+
nothing #hide
757
+
```
758
+
759
+
When only a single equation is added, the `begin ... end` statement can be omitted. E.g., the first model can be declared equivalently using:
# Goes through all differentials, checking that they are correctly formatted and their symbol is not used elsewhere.
869
+
for dexpr in diffexpr.args
870
+
(dexpr.head != :(=)) &&error("Differential declaration must have form like D = Differential(t), instead \"$(dexpr)\" was given.")
871
+
(dexpr.args[1] isa Symbol) ||error("Differential left-hand side must be a single symbol, instead \"$(dexpr.args[1])\" was given.")
872
+
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.")
873
+
in(dexpr.args[1], forbidden_symbols_error) &&error("A forbidden symbol ($(dexpr.args[1])) was used as a differential name.")
874
+
end
875
+
876
+
# If the default differential D has been used, but not pre-declared using the @differenitals
877
+
# options, add this declaration to the list of declared differentials.
878
+
if add_default_diff &&!any(diff_dec.args[1] ==:Dfor diff_dec in diffexpr.args)
879
+
push!(diffexpr.args, :(D =Differential($(tiv))))
880
+
end
881
+
882
+
return diffexpr
883
+
end
884
+
885
+
# Read the events (continious or discrete) provided as options to the DSL. Returns an expression which evalutes to these.
0 commit comments