Skip to content

Commit 2a81fca

Browse files
committed
up
1 parent 26634d3 commit 2a81fca

File tree

6 files changed

+367
-138
lines changed

6 files changed

+367
-138
lines changed

src/spatial_reaction_systems/lattice_reaction_systems.jl

Lines changed: 34 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
### Lattice Reaction Network Structure ###
22
# Describes a spatial reaction network over a graph.
3-
struct LatticeReactionSystem{S,T} # <: MT.AbstractTimeDependentSystem # Adding this part messes up show, disabling me from creating LRSs
3+
# Adding the "<: MT.AbstractTimeDependentSystem" part messes up show, disabling me from creating LRSs.
4+
struct LatticeReactionSystem{S,T} # <: MT.AbstractTimeDependentSystem
45
# Input values.
56
"""The reaction system within each compartment."""
67
rs::ReactionSystem{S}
@@ -20,27 +21,49 @@ struct LatticeReactionSystem{S,T} # <: MT.AbstractTimeDependentSystem # Adding t
2021
init_digraph::Bool
2122
"""Species that may move spatially."""
2223
spat_species::Vector{BasicSymbolic{Real}}
23-
"""All parameters related to the lattice reaction system (both with spatial and non-spatial effects)."""
24+
"""
25+
All parameters related to the lattice reaction system
26+
(both with spatial and non-spatial effects).
27+
"""
2428
parameters::Vector{BasicSymbolic{Real}}
25-
"""Parameters which values are tied to vertexes (adjacencies), e.g. (possibly) have a unique value at each vertex of the system."""
29+
"""
30+
Parameters which values are tied to vertexes (adjacencies),
31+
e.g. (possibly) have a unique value at each vertex of the system.
32+
"""
2633
vertex_parameters::Vector{BasicSymbolic{Real}}
27-
"""Parameters which values are tied to edges (adjacencies), e.g. (possibly) have a unique value at each edge of the system."""
34+
"""
35+
Parameters which values are tied to edges (adjacencies),
36+
e.g. (possibly) have a unique value at each edge of the system.
37+
"""
2838
edge_parameters::Vector{BasicSymbolic{Real}}
2939

30-
function LatticeReactionSystem(rs::ReactionSystem{S},
31-
spatial_reactions::Vector{T},
40+
function LatticeReactionSystem(rs::ReactionSystem{S}, spatial_reactions::Vector{T},
3241
lattice::DiGraph; init_digraph = true) where {S, T}
33-
(T <: AbstractSpatialReaction) || error("The second argument must be a vector of AbstractSpatialReaction subtypes.") # There probably some better way to ascertain that T has that type. Not sure how.
42+
# There probably some better way to ascertain that T has that type. Not sure how.
43+
if !(T <: AbstractSpatialReaction)
44+
error("The second argument must be a vector of AbstractSpatialReaction subtypes.")
45+
end
3446

35-
spat_species = (isempty(spatial_reactions) ? Vector{BasicSymbolic{Real}}[] : unique(reduce(vcat, [spatial_species(sr) for sr in spatial_reactions])))
47+
if isempty(spatial_reactions)
48+
spat_species = Vector{BasicSymbolic{Real}}[]
49+
else
50+
spat_species = unique(reduce(vcat, [spatial_species(sr) for sr in spatial_reactions]))
51+
end
52+
num_species = length(unique([species(rs); spat_species]))
3653
rs_edge_parameters = filter(isedgeparameter, parameters(rs))
37-
srs_edge_parameters = (isempty(spatial_reactions) ? Vector{BasicSymbolic{Real}}[] : setdiff(reduce(vcat, [parameters(sr) for sr in spatial_reactions]), parameters(rs)))
54+
if isempty(spatial_reactions)
55+
srs_edge_parameters = Vector{BasicSymbolic{Real}}[]
56+
else
57+
srs_edge_parameters = setdiff(reduce(vcat, [parameters(sr) for sr in spatial_reactions]), parameters(rs))
58+
end
3859
edge_parameters = unique([rs_edge_parameters; srs_edge_parameters])
3960
vertex_parameters = filter(!isedgeparameter, parameters(rs))
40-
ps = [parameters(rs); setdiff([edge_parameters; vertex_parameters], parameters(rs))] # Ensures that the order begins similarly to in the non-spatial ReactionSystem.
61+
# Ensures the parameter order begins similarly to in the non-spatial ReactionSystem.
62+
ps = [parameters(rs); setdiff([edge_parameters; vertex_parameters], parameters(rs))]
4163

4264
foreach(sr -> check_spatial_reaction_validity(rs, sr; edge_parameters=edge_parameters), spatial_reactions)
43-
return new{S,T}(rs, spatial_reactions, lattice, nv(lattice), ne(lattice), length(unique([species(rs); spat_species])), init_digraph, spat_species, ps, vertex_parameters, edge_parameters)
65+
return new{S,T}(rs, spatial_reactions, lattice, nv(lattice), ne(lattice), num_species,
66+
init_digraph, spat_species, ps, vertex_parameters, edge_parameters)
4467
end
4568
end
4669
function LatticeReactionSystem(rs, srs, lat::SimpleGraph)

0 commit comments

Comments
 (0)