diff --git a/docs/src/api.md b/docs/src/api.md index db182b0706..51a403c1a5 100644 --- a/docs/src/api.md +++ b/docs/src/api.md @@ -157,6 +157,7 @@ species nonspecies reactionparams reactions +nonreactions numspecies numparams numreactions diff --git a/src/Catalyst.jl b/src/Catalyst.jl index fccfc39c66..b347f0ab31 100644 --- a/src/Catalyst.jl +++ b/src/Catalyst.jl @@ -98,7 +98,7 @@ export get_noise_scaling, has_noise_scaling # The `ReactionSystem` structure and its functions. include("reactionsystem.jl") export ReactionSystem, isspatial -export species, nonspecies, reactionparams, reactions, speciesmap, paramsmap +export species, nonspecies, reactionparams, reactions, nonreactions, speciesmap, paramsmap export numspecies, numreactions, numreactionparams, setdefaults! export make_empty_network, reactionparamsmap export dependants, dependents, substoichmat, prodstoichmat, netstoichmat diff --git a/src/reactionsystem.jl b/src/reactionsystem.jl index 55d2ab87af..47a0af56b4 100644 --- a/src/reactionsystem.jl +++ b/src/reactionsystem.jl @@ -811,6 +811,18 @@ function numreactions(network) nr end +""" + nonreactions(network) + +Return the non-reaction equations within the network (i.e. algebraic and differnetial equations). + +Notes: +- Allocates a new array to store the non-species variables. +""" +function nonreactions(network) + equations(network)[(numreactions(network) + 1):end] +end + """ numreactionparams(network) diff --git a/test/reactionsystem_core/coupled_equation_crn_systems.jl b/test/reactionsystem_core/coupled_equation_crn_systems.jl index 942f8980ed..54ac3021b4 100644 --- a/test/reactionsystem_core/coupled_equation_crn_systems.jl +++ b/test/reactionsystem_core/coupled_equation_crn_systems.jl @@ -211,6 +211,55 @@ let end +### Accessor Tests ### + +# Checks basic accessor functions for a basic coupled CRN/equation model. +let + # Creates a reaction system. + t = default_t() + D = default_time_deriv() + @parameters p d v + @species X(t) + @variables V(t) W(t) + + eqs = [ + Reaction(p, [], [X]), + Reaction(d, [X], []), + Reaction(d, [X], nothing, [2], nothing), + D(V) ~ X - v*V, + W^2 ~ log(V) + X + ] + @named coupled_rs = ReactionSystem(eqs, t) + + # Check unknowns-related accessors. + @test Catalyst.has_species(coupled_rs) + @test issetequal(Catalyst.get_species(coupled_rs), [X]) + @test issetequal(species(coupled_rs), [X]) + @test issetequal(ModelingToolkit.get_unknowns(coupled_rs), [X, V, W]) + @test issetequal(unknowns(coupled_rs), [X, V, W]) + @test issetequal(nonspecies(coupled_rs), [V, W]) + @test numspecies(coupled_rs) == 1 + + # Check parameters-related accessors. + @test Catalyst.has_rxs(coupled_rs) + @test issetequal(Catalyst.get_rxs(coupled_rs), eqs[1:3]) + @test issetequal(reactions(coupled_rs), eqs[1:3]) + @test issetequal(equations(coupled_rs), eqs) + @test issetequal(nonreactions(coupled_rs), eqs[4:5]) + @test issetequal(reactionrates(coupled_rs), [p, d, d]) + @test numreactions(coupled_rs) == 3 + + # Check parameters-related accessors. + @test issetequal(parameters(coupled_rs), [p, d, v]) + @test issetequal(reactionparams(coupled_rs), [p, d, v]) + @test numparams(coupled_rs) == 3 + @test numreactionparams(coupled_rs) == 3 + + # Check other accessors. + @test !isspatial(coupled_rs) +end + + ### Species, Variables, and Parameter Handling ### # Checks that coupled systems contain the correct species, variables, and parameters.