Skip to content

Commit 37096a3

Browse files
committed
update
1 parent 829da0f commit 37096a3

File tree

4 files changed

+28
-9
lines changed

4 files changed

+28
-9
lines changed

HISTORY.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ rn = @reaction_network begin
2222
@parameters η
2323
k, 2X --> X2, [noise_scaling=η]
2424
end
25-
get_metadata(rn, :noise_scaling)
25+
getnoisescaling(rn)
2626
```
2727
- Changed fields of internal `Reaction` structure. `ReactionSystems`s saved using `serialize` on previous Catalyst versions cannot be loaded using this (or later) versions.
2828
- Simulation of spatial ODEs now supported. For full details, please see https://github.com/SciML/Catalyst.jl/pull/644 and upcoming documentation. Note that these methods are currently considered alpha, with the interface and approach changing even in non-breaking Catalyst releases.

docs/src/api/catalyst_api.md

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -178,9 +178,6 @@ substoichmat
178178
prodstoichmat
179179
netstoichmat
180180
reactionrates
181-
get_metadata_dict
182-
has_metadata
183-
get_metadata
184181
```
185182

186183
## [Functions to extend or modify a network](@id api_network_extension_and_modification)

src/Catalyst.jl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,6 @@ export mm, mmr, hill, hillr, hillar
8080
include("networkapi.jl")
8181
export species, nonspecies, reactionparams, reactions, speciesmap, paramsmap
8282
export numspecies, numreactions, numreactionparams, setdefaults!, symmap_to_varmap
83-
export get_metadata_dict, has_metadata, get_metadata
8483
export make_empty_network, addspecies!, addparam!, addreaction!, reactionparamsmap
8584
export dependants, dependents, substoichmat, prodstoichmat, netstoichmat
8685
export conservationlaws, conservedquantities, conservedequations, conservationlaw_constants

src/reactionsystem.jl

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ Notes:
9898
- The three-argument form assumes all reactant and product stoichiometric coefficients
9999
are one.
100100
"""
101-
struct Reaction{R, S, T}
101+
struct Reaction{S, T}
102102
"""The rate function (excluding mass action terms)."""
103103
rate::Any
104104
"""Reaction substrates."""
@@ -120,7 +120,7 @@ struct Reaction{R, S, T}
120120
Contain additional data, such whenever the reaction have a specific noise-scaling expression for
121121
the chemical Langevin equation.
122122
"""
123-
metadata::Vector{Pair{Symbol, R}}
123+
metadata::Vector{Pair{Symbol, Any}}
124124
end
125125

126126
"""
@@ -187,7 +187,7 @@ function Reaction(rate, subs, prods, substoich, prodstoich;
187187
end
188188

189189
# Check that all metadata entries are unique.
190-
if length(unique(entry[1] for entry in metadata)) < length(metadata)
190+
if any(metadata[i] in metadata[i+1:end] for i in eachindex(metadata))
191191
error("Repeated entries for the same metadata encountered in the following metadata set: $([entry[1] for entry in metadata]).")
192192
end
193193

@@ -853,6 +853,28 @@ end
853853

854854
######################## Other accessors ##############################
855855

856+
"""
857+
getnoisescaling(reaction::Reaction)
858+
859+
Returns the noise scaling associated with a specific reaction. If the `:noise_scaling` metadata has
860+
set, returns that. Else, returns `1.0`.
861+
862+
Arguments:
863+
- `reaction`: The reaction for which we wish to retrive all metadata.
864+
865+
Example:
866+
```julia
867+
reaction = @reaction k, 0 --> X, [noise_scaling=0.0]
868+
getnoisescaling(reaction)
869+
"""
870+
function getnoisescaling(reaction::Reaction)
871+
has_metadata(reaction, :noise_scaling) && (return get_metadata(reaction, :noise_scaling))
872+
return 1.0
873+
end
874+
875+
876+
# These are currently considered internal, but can be used by public accessor functions like getnoisescaling.
877+
856878
"""
857879
get_metadata_dict(reaction::Reaction)
858880
@@ -909,7 +931,8 @@ function get_metadata(reaction::Reaction, md_key::Symbol)
909931
if !has_metadata(reaction, md_key)
910932
error("The reaction does not have a metadata field $md_key. It does have the following metadata fields: $(keys(get_metadata_dict(reaction))).")
911933
end
912-
return get_metadata_dict(reaction)[findfirst(isequal(md_key, entry[1]) for entry in get_metadata_dict(reaction))][2]
934+
metadata = get_metadata_dict(reaction)
935+
return metadata[findfirst(isequal(md_key, entry[1]) for entry in get_metadata_dict(reaction))][2]
913936
end
914937

915938
######################## Conversion to ODEs/SDEs/jump, etc ##############################

0 commit comments

Comments
 (0)