Skip to content

Commit

Permalink
Merge branch 'fix_tests' into enable_SI_on_1.11
Browse files Browse the repository at this point in the history
  • Loading branch information
TorkelE committed Mar 9, 2025
2 parents d59ab30 + 5c1cfd9 commit b57a659
Show file tree
Hide file tree
Showing 20 changed files with 1,050 additions and 672 deletions.
1 change: 1 addition & 0 deletions HISTORY.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@
end
plot_network(brusselator)
```
- The letter Ø (used in Danish/Norwegian alphabet) is now conisdred the same as ∅ (empty set). It can no longer be used as a species/parameter.

## Catalyst 14.4.1
- Support for user-defined functions on the RHS when providing coupled equations
Expand Down
6 changes: 4 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,15 @@ BifurcationKit = "0f109fa4-8a5d-4b75-95aa-f515264e7665"
CairoMakie = "13f3f980-e62b-5c42-98c6-ff1f3baf88f0"
GraphMakie = "1ecd5474-83a3-4783-bb4f-06765db800d2"
HomotopyContinuation = "f213a82b-91d6-5c5d-acf7-10f1c761b327"
Makie = "ee78f7c6-11fb-53f2-987a-cfe4a2b5a57a"
NetworkLayout = "46757867-2c16-5918-afeb-47bfcb05e46a"
StructuralIdentifiability = "220ca800-aa68-49bb-acd8-6037fa93a544"


[extensions]
CatalystBifurcationKitExtension = "BifurcationKit"
CatalystCairoMakieExtension = "CairoMakie"
CatalystGraphMakieExtension = ["GraphMakie", "NetworkLayout"]
CatalystGraphMakieExtension = ["GraphMakie", "NetworkLayout", "Makie"]
CatalystHomotopyContinuationExtension = "HomotopyContinuation"
CatalystStructuralIdentifiabilityExtension = "StructuralIdentifiability"

Expand All @@ -57,8 +58,9 @@ Graphs = "1.4"
HomotopyContinuation = "2.9"
JumpProcesses = "9.13.2"
LaTeXStrings = "1.3.0"
Latexify = "0.16.5"
Latexify = "0.16.6"
MacroTools = "0.5.5"
Makie = "0.22.1"
ModelingToolkit = "< 9.60"
NetworkLayout = "0.4.7"
Parameters = "0.12"
Expand Down
2 changes: 1 addition & 1 deletion docs/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ HomotopyContinuation = "2.9"
IncompleteLU = "0.2"
JumpProcesses = "9.13.2"
Latexify = "0.16.5"
LinearSolve = "2.30"
LinearSolve = "2.30, 3"
ModelingToolkit = "< 9.60"
NetworkLayout = "0.4"
NonlinearSolve = "3.12, 4"
Expand Down
5 changes: 3 additions & 2 deletions docs/src/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,9 @@ ReactionSystem
```

## [Options for the `@reaction_network` DSL](@id api_dsl_options)
We have [previously described](@ref dsl_advanced_options) how options permits the user to supply non-reaction information to [`ReactionSystem`](@ref) created through the DSL. Here follows a list
We have [previously described](@ref dsl_advanced_options) how options allow one to supply additional information to a [`ReactionSystem`](@ref) created with the DSL. Here follows a list
of all options currently available.
- [`parameters`]:(@ref dsl_advanced_options_declaring_species_and_parameters) Allows the designation of a set of symbols as system parameter.
- [`parameters`](@ref dsl_advanced_options_declaring_species_and_parameters): Allows the designation of a set of symbols as system parameters.
- [`species`](@ref dsl_advanced_options_declaring_species_and_parameters): Allows the designation of a set of symbols as system species.
- [`variables`](@ref dsl_advanced_options_declaring_species_and_parameters): Allows the designation of a set of symbols as system non-species variables.
- [`ivs`](@ref dsl_advanced_options_ivs): Allows the designation of a set of symbols as system independent variables.
Expand All @@ -100,6 +100,7 @@ of all options currently available.
- [`continuous_events`](@ref constraint_equations_events): Allows the creation of continuous events.
- [`discrete_events`](@ref constraint_equations_events): Allows the creation of discrete events.
- [`combinatoric_ratelaws`](@ref faq_combinatoric_ratelaws): Takes a single option (`true` or `false`), which sets whether to use combinatorial rate laws.
- [`require_declaration`](@ref dsl_advanced_options_require_dec): Turns off all inference of parameters, species, variables, the default differential, and observables (requiring these to be explicitly declared using e.g. `@species`).

## [ModelingToolkit and Catalyst accessor functions](@id api_accessor_functions)
A [`ReactionSystem`](@ref) is an instance of a
Expand Down
40 changes: 39 additions & 1 deletion docs/src/model_creation/dsl_advanced.md
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,6 @@ ModelingToolkit.getdescription(two_state_system.kA)
```

### [Designating constant-valued/fixed species parameters](@id dsl_advanced_options_constant_species)

Catalyst enables the designation of parameters as `constantspecies`. These parameters can be used as species in reactions, however, their values are not changed by the reaction and remain constant throughout the simulation (unless changed by e.g. the [occurrence of an event](@ref constraint_equations_events). Practically, this is done by setting the parameter's `isconstantspecies` metadata to `true`. Here, we create a simple reaction where the species `X` is converted to `Xᴾ` at rate `k`. By designating `X` as a constant species parameter, we ensure that its quantity is unchanged by the occurrence of the reaction.
```@example dsl_advanced_constant_species
using Catalyst # hide
Expand Down Expand Up @@ -575,6 +574,45 @@ nothing # hide
!!! note
When using interpolation, expressions like `2$spec` won't work; the multiplication symbol must be explicitly included like `2*$spec`.

## [Creating individual reaction using the `@reaction` macro](@id dsl_advanced_options_reaction_macro)
Catalyst exports a macro `@reaction`, which can be used to generate a singular [`Reaction`](@ref) object of the same type which is stored within the [`ReactionSystem`](@ref) structure (which in turn can be generated by `@reaction_network`). Generally, `@reaction` follows [identical rules to those of `@reaction_network`](@ref dsl_description_reactions) for writing and interpreting reactions (however, bi-directional reactions are not permitted). E.g. here we create a simple dimerisation reaction:
```@example dsl_advanced_reaction_macro
using Catalyst # hide
rx_dimerisation = @reaction kD, 2X --> X2
```
Here, `@reaction` is followed by a single line consisting of three parts:
- A rate (at which the reaction occurs).
- Any number of substrates (which are consumed by the reaction).
- Any number of products (which are produced by the reaction).

In the next example, we first create a simple [SIR model](@ref basic_CRN_library_sir). Then, we specify the same model by instead creating its individual reaction components using the `@reaction` macro. Finally, we confirm that these are identical to those stored in the initial model (using the [`reactions`](@ref) function).
```@example dsl_advanced_reaction_macro
sir_model = @reaction_network begin
α, S + I --> 2I
β, I --> R
end
infection_rx = @reaction α, S + I --> 2I
recovery_rx = @reaction β, I --> R
sir_rxs = [infection_rx, recovery_rx]
issetequal(reactions(sir_model), sir_rxs)
```
One of the primary uses of the `@reaction` macro is to provide some of the convenience of the DSL to [*programmatic modelling](@ref programmatic_CRN_construction). E.g. here we can combine our reactions to create a `ReactionSystem` directly, and also confirm that this is identical to the model created through the DSL:
```@example dsl_advanced_reaction_macro
sir_programmatic = complete(ReactionSystem(sir_rxs, default_t(); name = :sir))
sir_programmatic == sir_model
```

During programmatic modelling, it can be good to keep in mind that already declared symbolic variables can be [*interpolated*](@ref dsl_advanced_options_symbolics_and_DSL_interpolation). E.g. here we create two production reactions both depending on the same Michaelis-Menten function:
```@example dsl_advanced_reaction_macro
t = default_t()
@species X(t)
@parameters v K
mm_term = Catalyst.mm(X, v, K)
rx1 = @reaction $mm_term, 0 --> P1
rx2 = @reaction $mm_term, 0 --> P2
nothing # hide
```

## [Disabling mass action for reactions](@id dsl_advanced_options_disable_ma)

As [described previously](@ref math_models_in_catalyst_rre_odes), Catalyst uses *mass action kinetics* to generate ODEs from reactions. Here, each reaction generates a term for each of its reactants, which consists of the reaction's rate, substrates, and the reactant's stoichiometry. E.g. the following reaction:
Expand Down
14 changes: 7 additions & 7 deletions docs/src/model_creation/model_visualisation.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,34 +88,34 @@ In this section we demonstrate some of the ways that plot objects can be manipul
f, ax, p = plot_complexes(brusselator, show_rate_labels = true)
```

It seems like a bit of the top node is cut off. Let's hide the tick marks and grid and increase the top and bottom margins by increasing `yautolimitmargin`.
It seems like a bit of the top node is cut off. Let's increase the top and bottom margins by increasing `yautolimitmargin`.
```@example visualisation_graphs
hidedecorations!(ax)
ax.yautolimitmargin = (0.1, 0.1) # defaults to (0.05, 0.05)
ax.yautolimitmargin = (0.3, 0.3) # defaults to (0.15, 0.15)
ax.aspect = DataAspect()
f
```

There are many keyword arguments that can be passed to `plot_network` or `plot_complexes` to change the look of the graph (which get passed to the `graphplot` Makie recipe). Let's change the color of the nodes and make the inner labels a bit smaller. As before, we hide the tick marks and grid. Let's also give the plot a title.
There are many keyword arguments that can be passed to `plot_network` or `plot_complexes` to change the look of the graph (which get passed to the `graphplot` Makie recipe). Let's change the color of the nodes and make the inner labels a bit smaller. Let's also give the plot a title.
```@example visualisation_graphs
f, ax, p = plot_complexes(brusselator, show_rate_labels = true, node_color = :yellow, ilabels_fontsize = 10)
hidedecorations!(ax)
ax.yautolimitmargin = (0.1, 0.1) # defaults to (0.05, 0.05)
ax.aspect = DataAspect()
ax.title = "Brusselator"
f
```

Most of the kwargs that modify the nodes or edges will also accept a vector with the same length as the number of nodes or edges, respectively. See [here](https://graph.makie.org/stable/#The-graphplot-Recipe) for a full list of keyword arguments to `graph_plot`. Note that `plot_complexes` and `plot_network` default to `layout = Stress()` rather than `layout = Spring()`, since `Stress()` is better at generating plots with fewer edge crossings. More layout options and customizations (such as pinning nodes to certain positions) can be found in the [`NetworkLayout` documentation](https://juliagraphs.org/NetworkLayout.jl/stable/).

Once a graph is already created we can also change the keyword arguments by modifying the fields of the `Plot` object `p`.
```@example visualisation_graphs
p.node_color = :orange
f
```

Custom node positions can also be given, if the automatic layout is unsatisfactory.
```@example visualisation_graphs
fixedlayout = [(0,0), (1,0), (0,1), (1,1), (2,0)]
p.layout = fixedlayout
autolimits!(ax)
f
```

Makie graph plots can be made to be interactive, allowing one to drag nodes and edges. To do this, we retrieve the axis from the GraphMakie plot, and then register the interactions. **Note that this can only be done if `GLMakie` is the installed Makie backend. See the [GraphMakie docs](https://graph.makie.org/stable/#Predefined-Interactions) for more information about the types of interactions one can register.** Below is a non-interactive code example that shows how to do this:
Expand Down
4 changes: 2 additions & 2 deletions docs/src/spatial_modelling/lattice_reaction_systems.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ lat_getu(sol, :X1, lrs)
and plot the simulation using
```@example spatial_intro_basics
import CairoMakie
lattice_animation(sol, :X1, lrs, "lattice_simulation_2d.mp4")
lattice_animation(sol, :X1, lrs, "lattice_simulation.mp4")
```
![](./lattice_simulation_2d.mp4)
![](./lattice_simulation.mp4)
More information on how to retrieve values from spatial simulations can be found [here](@ref lattice_simulation_structure_interaction_simulation_species), and for plotting them, [here](@ref lattice_simulation_plotting). Finally, a list of functions for querying `LatticeReactionSystems` for various properties can be found [here](@ref api_lattice_simulations).

## [Spatial reactions](@id spatial_lattice_modelling_intro_spatial_reactions)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
### 1d Lattice Simulation Plots/Animations ###

# Internal dispatch for the plotting of a lattice simulation on a 1d lattice (Cartesian or masked).
# Internal dispatch for the plotting of a lattice simulation on a 1d lattice (Cartesian or masked).
function lattice_plot(
sol, sp, lrs::LatticeReactionSystem{Q, R, <:Catalyst.GridLattice{1, S}, T};
t = sol.t[end], markersize = 20, kwargs...) where {Q, R, S, T}
Expand All @@ -12,7 +12,7 @@ function lattice_plot(
markersize = markersize, kwargs...)
end

# Internal dispatch for the animation of a lattice simulation on a 1d lattice (Cartesian or masked).
# Internal dispatch for the animation of a lattice simulation on a 1d lattice (Cartesian or masked).
function lattice_animation(
sol, sp, lrs::LatticeReactionSystem{Q, R, <:Catalyst.GridLattice{1, S}, T},
filename::String;
Expand Down Expand Up @@ -40,7 +40,7 @@ function lattice_animation(
return nothing
end

# Internal dispatch for the kymographs of a lattice simulation on a 1d lattice (Cartesian or masked).
# Internal dispatch for the kymographs of a lattice simulation on a 1d lattice (Cartesian or masked).
function lattice_kymograph(
sol, sp, lrs::LatticeReactionSystem{Q, R, <:Catalyst.GridLattice{1, S}, T};
colormap = :BuGn_7,
Expand All @@ -64,7 +64,7 @@ end

### 2d Lattice Simulation Plots/Animations ###

# Internal dispatch for the plotting of a lattice simulation on a 2d lattice (Cartesian or masked).
# Internal dispatch for the plotting of a lattice simulation on a 2d lattice (Cartesian or masked).
function lattice_plot(sol, sp,
lrs::LatticeReactionSystem{Q, R, <:Catalyst.GridLattice{2, S}, T}; t = sol.t[end],
colormap = :BuGn_7, plot_min = nothing, plot_max = nothing,
Expand All @@ -80,14 +80,14 @@ function lattice_plot(sol, sp,
return heatmap(x_vals,
y_vals,
vals;
axis = (xlabel = "Time", ylabel = "Compartment",
axis = (xlabel = "Compartment", ylabel = "Compartment",
xgridvisible = false, ygridvisible = false),
colormap,
colorrange = (plot_min, plot_max),
kwargs...)
end

# Internal dispatch for the animation of a lattice simulation on a 2d lattice (Cartesian or masked).
# Internal dispatch for the animation of a lattice simulation on a 2d lattice (Cartesian or masked).
function lattice_animation(
sol, sp, lrs::LatticeReactionSystem{Q, R, <:Catalyst.GridLattice{2, S}, T},
filename::String;
Expand All @@ -101,7 +101,7 @@ function lattice_animation(

# Creates the base figure (which is modified in the animation).
fig, ax, hm = heatmap(x_vals, y_vals, vals[1];
axis = (xgridvisible = false, ygridvisible = false),
axis = (xgridvisible = false, ygridvisible = false, xlabel = "Compartment", ylabel = "Compartment"),
colormap, colorrange = (plot_min, plot_max),
kwargs...)
ttitle && (ax.title = "Time: $(round(t[1]; sigdigits = 3))")
Expand All @@ -116,14 +116,14 @@ end

### 3d Lattice Simulation Plots/Animations (Errors Only) ###

# Internal dispatch for the plotting of a lattice simulation on a 3d lattice (Cartesian or masked).
# Internal dispatch for the plotting of a lattice simulation on a 3d lattice (Cartesian or masked).
function lattice_plot(
sol, sp, lrs::LatticeReactionSystem{Q, R, <:Catalyst.GridLattice{3, S}, T};
kwargs...) where {Q, R, S, T}
throw(ArgumentError("The `lattice_plot` function does not support 3d Cartesian/masked lattices."))
end

# Internal dispatch for the animation of a lattice simulation on a 3d lattice (Cartesian or masked).
# Internal dispatch for the animation of a lattice simulation on a 3d lattice (Cartesian or masked).
function lattice_animation(
sol, sp, lrs::LatticeReactionSystem{Q, R, <:Catalyst.GridLattice{3, S}, T},
filename::String; kwargs...) where {Q, R, S, T}
Expand Down
2 changes: 1 addition & 1 deletion ext/CatalystGraphMakieExtension.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module CatalystGraphMakieExtension

# Fetch packages.
using Catalyst, GraphMakie, Graphs, Symbolics, SparseArrays, NetworkLayout
using Catalyst, GraphMakie, Graphs, Symbolics, SparseArrays, NetworkLayout, Makie
using Symbolics: get_variables!
import Catalyst: species_reaction_graph, incidencematgraph, lattice_plot, lattice_animation

Expand Down
9 changes: 8 additions & 1 deletion ext/CatalystGraphMakieExtension/rn_graph_plot.jl
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,9 @@ function Catalyst.plot_network(rn::ReactionSystem; kwargs...)

f.axis.xautolimitmargin = (0.15, 0.15)
f.axis.yautolimitmargin = (0.15, 0.15)
hidedecorations!(f.axis)
hidespines!(f.axis)
f.axis.aspect = DataAspect()

f
end
Expand Down Expand Up @@ -260,9 +263,13 @@ function Catalyst.plot_complexes(rn::ReactionSystem; show_rate_labels = false, k
curve_distance = gen_distances(cg),
kwargs...
)

f.axis.xautolimitmargin = (0.15, 0.15)
f.axis.yautolimitmargin = (0.15, 0.15)

hidedecorations!(f.axis)
hidespines!(f.axis)
f.axis.aspect = DataAspect()

f
end

Expand Down
7 changes: 1 addition & 6 deletions src/Catalyst.jl
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,9 @@ const ExprValues = Union{Expr, Symbol, Float64, Int, Bool}
const CONSERVED_CONSTANT_SYMBOL =

# Declares symbols which may neither be used as parameters nor unknowns.
const forbidden_symbols_skip = Set([:ℯ, :pi, , :t, :∅])
const forbidden_symbols_skip = Set([:ℯ, :pi, , :t, :∅, ])
const forbidden_symbols_error = union(Set([:im, :nothing, CONSERVED_CONSTANT_SYMBOL]),
forbidden_symbols_skip)
const forbidden_variables_error = let
fvars = copy(forbidden_symbols_error)
delete!(fvars, :t)
fvars
end

### Package Main ###

Expand Down
2 changes: 1 addition & 1 deletion src/chemistry_functionality.jl
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ function make_compound(expr)
# Cannot extract directly using e.g. "getfield.(composition, :reactant)" because then
# we get something like :([:C, :O]), rather than :([C, O]).
composition = Catalyst.recursive_find_reactants!(expr.args[3], 1,
Vector{ReactantStruct}(undef, 0))
Vector{DSLReactant}(undef, 0))
components = :([]) # Becomes something like :([C, O]).
coefficients = :([]) # Becomes something like :([1, 2]).
for comp in composition
Expand Down
Loading

0 comments on commit b57a659

Please sign in to comment.