Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Api update #997

Merged
merged 5 commits into from
Jul 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 56 additions & 12 deletions docs/src/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,22 @@ Reaction
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
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.
- [`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.
- [`compounds`](@ref chemistry_functionality_compounds): Allows the designation of compound species.
- [`observables`](@ref dsl_advanced_options_observables): Allows the designation of compound observables.
- [`default_noise_scaling`](@ref simulation_intro_SDEs_noise_saling): Enables the setting of a default noise scaling expression.
- [`differentials`](@ref constraint_equations_coupling_constraints): Allows the designation of differentials.
- [`equations`](@ref constraint_equations_coupling_constraints): Allows the creation of algebraic and/or differential equations.
- [`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.

## [ModelingToolkit and Catalyst accessor functions](@id api_accessor_functions)
A [`ReactionSystem`](@ref) is an instance of a
`ModelingToolkit.AbstractTimeDependentSystem`, and has a number of fields that
Expand Down Expand Up @@ -156,18 +172,36 @@ accessor functions.

```@docs
species
Catalyst.get_species
nonspecies
reactions
Catalyst.get_rxs
nonreactions
numspecies
numparams
numreactions
speciesmap
paramsmap
isspecies
isautonomous
```

## Coupled reaction/equation system properties
The following system property accessor functions are primarily relevant to reaction system [coupled
to differential and/or algebraic equations](@ref constraint_equations).
```@docs
ModelingToolkit.has_alg_equations
ModelingToolkit.alg_equations
ModelingToolkit.has_diff_equations
ModelingToolkit.diff_equations
```

## Basic species properties
The following functions permits the querying of species properties.
```@docs
isspecies
Catalyst.isconstant
Catalyst.isbc
Catalyst.isvalidreactant
```

## Basic reaction properties
TorkelE marked this conversation as resolved.
Show resolved Hide resolved
Expand All @@ -181,6 +215,17 @@ netstoichmat
reactionrates
```

## [Reaction metadata](@id api_rx_metadata)
The following functions permits the retrieval of [reaction metadata](@ref dsl_advanced_options_reaction_metadata).
```@docs
Catalyst.hasnoisescaling
Catalyst.getnoisescaling
Catalyst.hasdescription
Catalyst.getdescription
Catalyst.hasmisc
Catalyst.getmisc
```

## [Functions to extend or modify a network](@id api_network_extension_and_modification)
`ReactionSystem`s can be programmatically extended using [`ModelingToolkit.extend`](@ref) and
[`ModelingToolkit.compose`](@ref).
Expand Down Expand Up @@ -307,23 +352,22 @@ LatticeReactionSystem
The following functions can be used to querying the properties of `LatticeReactionSystem`s:
```@docs
reactionsystem
spatial_reactions
lattice
num_verts
num_edges
num_species
spatial_species
vertex_parameters
edge_parameters
edge_iterator
is_transport_system
Catalyst.spatial_reactions
Catalyst.lattice
Catalyst.num_verts
Catalyst.num_edges
Catalyst.num_species
Catalyst.spatial_species
Catalyst.vertex_parameters
Catalyst.edge_parameters
Catalyst.edge_iterator
Catalyst.is_transport_system
has_cartesian_lattice
has_masked_lattice
has_grid_lattice
has_graph_lattice
grid_size
grid_dims
get_lattice_graph
```
In addition, most accessor functions for normal `ReactionSystem`s (such as `species` and `parameters`) works when applied to `LatticeReactionSystem`s as well.

Expand Down
12 changes: 11 additions & 1 deletion docs/src/faqs.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ like
plot(sol; idxs = [A, B])
```

## How to disable rescaling of reaction rates in rate laws?
## [How to disable rescaling of reaction rates in rate laws?](@id faq_combinatoric_ratelaws)
As explained in the [Reaction rate laws used in simulations](@ref introduction_to_catalyst_ratelaws) section, for
a reaction such as `k, 2X --> 0`, the generated rate law will rescale the rate
constant, giving `k*X^2/2` instead of `k*X^2` for ODEs and `k*X*(X-1)/2` instead
Expand All @@ -71,6 +71,16 @@ osys = convert(ODESystem, rn; combinatoric_ratelaws=false)
Disabling these rescalings should work for all conversions of `ReactionSystem`s
to other `ModelingToolkit.AbstractSystem`s.

When creating a [`ReactionSystem`](@ref) using the DSL, combinatoric rate laws can be disabled (for
the created system, and all systems derived from it) using the `@combinatoric_ratelaws` option (providing `false` as its only input):
```@example faq1
rn = @reaction_network begin
@combinatoric_ratelaws false
k, 2X --> 0
end
nothing # hide
```

## How to use non-integer stoichiometric coefficients?
```@example faq2
using Catalyst
Expand Down
2 changes: 1 addition & 1 deletion docs/src/model_creation/chemistry_related_functionality.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ While Catalyst has primarily been designed around the modelling of biological sy
- The `balance_reaction` function, which enables the user to balance a reaction so the same number of components occur on both sides.


## Modelling with compound species
## [Modelling with compound species](@id chemistry_functionality_compounds)

### Creating compound species programmatically
We will first show how to create compound species through [programmatic model construction](@ref programmatic_CRN_construction), and then demonstrate using the DSL. To create a compound species, use the `@compound` macro, first designating the compound, followed by its components (and their stoichiometries). In this example, we will create a CO₂ molecule, consisting of one C atom and two O atoms. First, we create species corresponding to the components:
Expand Down
2 changes: 2 additions & 0 deletions docs/src/model_creation/dsl_advanced.md
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,8 @@ rx = @reaction p, 0 --> X, [description="A production reaction"]
Catalyst.getdescription(rx)
```

A list of all available reaction metadata can be found [in the api](@ref api_rx_metadata).

## [Working with symbolic variables and the DSL](@id dsl_advanced_options_symbolics_and_DSL)
We have previously described how Catalyst represents its models symbolically (enabling e.g. symbolic differentiation of expressions stored in models). While Catalyst utilises this for many internal operation, these symbolic representations can also be accessed and harnessed by the user. Primarily, doing so is much easier during programmatic (as opposed to DSL-based) modelling. Indeed, the section on [programmatic modelling](@ref programmatic_CRN_construction) goes into more details about symbolic representation in models, and how these can be used. It is, however, also ways to utilise these methods during DSL-based modelling. Below we briefly describe two methods for doing so.

Expand Down
5 changes: 5 additions & 0 deletions src/spatial_reaction_systems/spatial_reactions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ struct EdgeParameter end
Symbolics.option_to_metadata_type(::Val{:edgeparameter}) = EdgeParameter

# Implements the isedgeparameter check function.
"""
isedgeparameter(p)

Returns `true` if the parameter `p` is an edge parameter (else `false`).
"""
isedgeparameter(x::Num, args...) = isedgeparameter(Symbolics.unwrap(x), args...)
function isedgeparameter(x, default = false)
p = Symbolics.getparent(x, nothing)
Expand Down
Loading