Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
TorkelE committed May 22, 2024
1 parent a649acc commit 0e08508
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 25 deletions.
1 change: 1 addition & 0 deletions HISTORY.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## Catalyst unreleased (master branch)

## Catalyst 14.0
- Rename `reactionparams`, `numreactionparams`, and `reactionparamsmap` to `reactionsystemparams`, `numreactionsystemparams`, and `reactionsystemparamsmap`, respectively.
- To be more consistent with ModelingToolkit's immutability requirement for systems, we have removed API functions that mutate `ReactionSystem`s such as `addparam!`, `addreaction!`, `addspecies`, `@add_reactions`, and `merge!`. Please use `ModelingToolkit.extend` and `ModelingToolkit.compose` to generate new merged and/or composed `ReactionSystem`s from multiple component systems.
- Added CatalystStructuralIdentifiabilityExtension, which permits StructuralIdentifiability.jl function to be applied directly to Catalyst systems. E.g. use
```julia
Expand Down
8 changes: 4 additions & 4 deletions docs/src/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ can call:
the system and any sub-systems that are also `ReactionSystems`.
* `ModelingToolkit.parameters(rn)` returns all parameters across the
system, *all sub-systems*, and all constraint systems.
* [`reactionparams(rn)`](@ref) is a vector of all the parameters within the
* [`reactionsystemparams(rn)`](@ref) is a vector of all the parameters within the
system and any sub-systems that are also `ReactionSystem`s. These include all
parameters that appear within some `Reaction`.
* `ModelingToolkit.equations(rn)` returns all [`Reaction`](@ref)s and all
Expand All @@ -155,16 +155,16 @@ accessor functions.
```@docs
species
nonspecies
reactionparams
reactionsystemparams
reactions
nonreactions
numspecies
numparams
numreactions
numreactionparams
numreactionsystemparams
speciesmap
paramsmap
reactionparamsmap
reactionsystemparamsmap
isspecies
Catalyst.isconstant
Catalyst.isbc
Expand Down
6 changes: 3 additions & 3 deletions src/Catalyst.jl
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,9 @@ export get_noise_scaling, has_noise_scaling
# The `ReactionSystem` structure and its functions.
include("reactionsystem.jl")
export ReactionSystem, isspatial
export species, nonspecies, reactionparams, reactions, nonreactions, speciesmap, paramsmap
export numspecies, numreactions, numreactionparams, setdefaults!
export make_empty_network, reactionparamsmap
export species, nonspecies, reactionsystemparams, reactions, nonreactions, speciesmap, paramsmap
export numspecies, numreactions, numreactionsystemparams, setdefaults!
export make_empty_network, reactionsystemparamsmap
export dependants, dependents, substoichmat, prodstoichmat, netstoichmat
export reactionrates
export isequivalent
Expand Down
22 changes: 11 additions & 11 deletions src/reactionsystem.jl
Original file line number Diff line number Diff line change
Expand Up @@ -723,7 +723,7 @@ function get_indep_sts(rs::ReactionSystem, remove_conserved = false)
end

"""
reactionparams(network)
reactionsystemparams(network)
Given a [`ReactionSystem`](@ref), return a vector of all parameters defined
within the system and any subsystems that are of type `ReactionSystem`. To get
Expand All @@ -733,11 +733,11 @@ subsystems, use `parameters(network)`.
Notes:
- Allocates and has to calculate these dynamically by comparison for each reaction.
"""
function reactionparams(network)
function reactionsystemparams(network)
ps = get_ps(network)
systems = filter_nonrxsys(network)
isempty(systems) && return ps
unique([ps; reduce(vcat, map(sys -> species(sys, reactionparams(sys)), systems))])
unique([ps; reduce(vcat, map(sys -> species(sys, reactionsystemparams(sys)), systems))])
end

"""
Expand Down Expand Up @@ -765,13 +765,13 @@ function paramsmap(network)
end

"""
reactionparamsmap(network)
reactionsystemparamsmap(network)
Given a [`ReactionSystem`](@ref), return a Dictionary mapping from parameters that
appear within `Reaction`s to their index within [`reactionparams(network)`](@ref).
appear within `Reaction`s to their index within [`reactionsystemparams(network)`](@ref).
"""
function reactionparamsmap(network)
Dict(p => i for (i, p) in enumerate(reactionparams(network)))
function reactionsystemparamsmap(network)
Dict(p => i for (i, p) in enumerate(reactionsystemparams(network)))
end

# used in the next function (`reactions(network)`).
Expand Down Expand Up @@ -824,18 +824,18 @@ function nonreactions(network)
end

"""
numreactionparams(network)
numreactionsystemparams(network)
Return the total number of parameters within the given [`ReactionSystem`](@ref)
and subsystems that are `ReactionSystem`s.
Notes
- If there are no subsystems this will be fast.
- As this calls [`reactionparams`](@ref), it can be slow and will allocate if
- As this calls [`reactionsystemparams`](@ref), it can be slow and will allocate if
there are any subsystems.
"""
function numreactionparams(network)
length(reactionparams(network))
function numreactionsystemparams(network)
length(reactionsystemparams(network))
end

"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ let
# Test API functions for composed model.
@test issetequal(species(rs), [A, B, C])
@test issetequal(unknowns(rs), [A, B, C, ns.D])
@test issetequal(reactionparams(rs), [r₊, r₋])
@test issetequal(reactionsystemparams(rs), [r₊, r₋])
@test issetequal(parameters(rs), [r₊, r₋, ns.β])
@test issetequal(reactions(rs), union(rxs1, rxs2))
@test issetequal(filter(eq -> eq isa Reaction, equations(rs)), union(rxs1, rxs2))
Expand Down Expand Up @@ -340,7 +340,7 @@ let
@test issetequal(unknowns(rs1), [A1, rs2.A2a, ns2.A2b, rs2.rs3.A3a, rs2.ns3.A3b])
@test issetequal(species(rs1), [A1, rs2.A2a, rs2.rs3.A3a])
@test issetequal(parameters(rs1), [p1, rs2.p2a, rs2.p2b, rs2.rs3.p3a, rs2.ns3.p3b])
@test issetequal(reactionparams(rs1), [p1, rs2.p2a, rs2.p2b, rs2.rs3.p3a])
@test issetequal(reactionsystemparams(rs1), [p1, rs2.p2a, rs2.p2b, rs2.rs3.p3a])
@test issetequal(rxs, reactions(rs1))
@test issetequal(eqs, equations(rs1))
@test Catalyst.combinatoric_ratelaws(rs1)
Expand Down
2 changes: 1 addition & 1 deletion test/dsl/dsl_advanced_model_construction.jl
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ let
@test ModelingToolkit.nameof(rn) == name
@test numreactions(rn) == 0
@test numspecies(rn) == 0
@test numreactionparams(rn) == 0
@test numreactionsystemparams(rn) == 0
end

rn = @reaction_network name begin
Expand Down
4 changes: 2 additions & 2 deletions test/miscellaneous_tests/api.jl
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,14 @@ let
@test pmat == prodstoichmat(rnmat) == Matrix(prodstoichmat(rnmat, sparse = true))
end

# Tests `reactionparamsmap`, `reactionrates`, and `symmap_to_varmap` getters.
# Tests `reactionsystemparamsmap`, `reactionrates`, and `symmap_to_varmap` getters.
let
rn = @reaction_network begin
(p,d), 0 <--> X
(kB,kD), 2X <--> X
end
@unpack p, d, kB, kD = rn
isequal(reactionparamsmap(rn), Dict([p => 1, d => 2, kB => 3, kD => 4]))
isequal(reactionsystemparamsmap(rn), Dict([p => 1, d => 2, kB => 3, kD => 4]))
issetequal(reactionrates(rn), [p, d, kB, kD])
isequal(symmap_to_varmap(rn, [:p => 1.0, :kB => 3.0]), [p => 1.0, kB => 3.0])
end
Expand Down
4 changes: 2 additions & 2 deletions test/reactionsystem_core/coupled_equation_crn_systems.jl
Original file line number Diff line number Diff line change
Expand Up @@ -251,9 +251,9 @@ let

# Check parameters-related accessors.
@test issetequal(parameters(coupled_rs), [p, d, v])
@test issetequal(reactionparams(coupled_rs), [p, d, v])
@test issetequal(reactionsystemparams(coupled_rs), [p, d, v])
@test numparams(coupled_rs) == 3
@test numreactionparams(coupled_rs) == 3
@test numreactionsystemparams(coupled_rs) == 3

# Check other accessors.
@test !isspatial(coupled_rs)
Expand Down

0 comments on commit 0e08508

Please sign in to comment.