7
7
8
8
Wrapper for the species-reaction graph containing edges for rate-dependence on species. Intended to allow plotting of multiple edges.
9
9
"""
10
- struct SRGraphWrap{T} <: AbstractGraph{T}
10
+ struct SRGraphWrap{T} <: Graphs. AbstractGraph{T}
11
11
g:: SimpleDiGraph{T}
12
- rateedges:: Vector{SimpleEdge}
12
+ rateedges:: Vector{Graphs.SimpleEdge{T}}
13
+ edgeorder:: Vector{Int64}
13
14
end
14
15
15
16
# Create the SimpleDiGraph corresponding to the species and reactions
16
17
function SRGraphWrap (rn:: ReactionSystem )
17
- srg = speciesreactiongraph (rn)
18
- rateedges = Vector {SimpleEdge} ()
18
+ srg = species_reaction_graph (rn)
19
+ rateedges = Vector {Graphs. SimpleEdge{Int} } ()
19
20
sm = speciesmap (rn); specs = species (rn)
20
21
21
22
deps = Set ()
@@ -25,11 +26,13 @@ function SRGraphWrap(rn::ReactionSystem)
25
26
if ! isempty (deps)
26
27
for spec in deps
27
28
specidx = sm[spec]
28
- push! (rateedges, SimpleEdge (specidx, i + length (specs)))
29
+ push! (rateedges, Graphs . SimpleEdge (specidx, i + length (specs)))
29
30
end
30
31
end
31
32
end
32
- SRGraphWrap (srg, rateedges)
33
+ edgelist = vcat (collect (Graphs. edges (srg)), rateedges)
34
+ edgeorder = sortperm (edgelist)
35
+ SRGraphWrap (srg, rateedges, edgeorder)
33
36
end
34
37
35
38
Base. eltype (g:: SRGraphWrap ) = eltype (g. g)
@@ -44,8 +47,7 @@ Graphs.vertices(g::SRGraphWrap) = vertices(g.g)
44
47
Graphs. is_directed (g:: SRGraphWrap ) = is_directed (g. g)
45
48
46
49
function Graphs. edges (g:: SRGraphWrap )
47
- edgelist = vcat (collect (Graphs. edges (g. g)), g. rateedges)
48
- edgelist = sort! (edgelist)
50
+ edgelist = vcat (collect (Graphs. edges (g. g)), g. rateedges)[g. edgeorder]
49
51
end
50
52
51
53
function gen_distances (g:: SRGraphWrap ; inc = 0.2 )
60
62
"""
61
63
PetriNet(rn::ReactionSystem)
62
64
63
- See the documentation for [`SRGraph `](@ref).
65
+ See the documentation for [`plot_network `](@ref).
64
66
"""
65
- function PetriNet (rn:: ReactionSystem )
66
- SRGraph (rn)
67
+ function Catalyst . plot_petrinet (rn:: ReactionSystem )
68
+ plot_network (rn)
67
69
end
68
70
69
71
"""
70
- SRGraph (rn::ReactionSystem; interactive=false)
72
+ plot_network (rn::ReactionSystem; interactive=false)
71
73
72
74
Converts a [`ReactionSystem`](@ref) into a GraphMakie plot of the species reaction graph.
73
75
Reactions correspond to small green circles, and species to blue circles.
@@ -81,10 +83,9 @@ Notes:
81
83
rate expression. For example, in the reaction `k*A, B --> C`, there would be a
82
84
red arrow from `A` to the reaction node. In `k*A, A+B --> C`, there would be
83
85
red and black arrows from `A` to the reaction node.
84
- - The `interactive` flag sets the ability to interactively drag nodes and edges in the generated plot.
85
- Only allowed if `GLMakie` is the loaded Makie backend.
86
86
"""
87
- function plot_speciesreaction_graph (rn:: ReactionSystem ; interactive = false )
87
+ # TODO : update docs for interacting with plots. The `interactive` flag sets the ability to interactively drag nodes and edges in the generated plot. Only allowed if `GLMakie` is the loaded Makie backend.
88
+ function Catalyst. plot_network (rn:: ReactionSystem )
88
89
srg = SRGraphWrap (rn)
89
90
ns = length (species (rn))
90
91
nodecolors = vcat ([:skyblue3 for i in 1 : ns],
@@ -103,38 +104,30 @@ function plot_speciesreaction_graph(rn::ReactionSystem; interactive = false)
103
104
end
104
105
edgecolors = [:black for i in 1 : ne (srg)]
105
106
106
- elist = Graphs . edges (srg)
107
- for i in 2 : length (elist )
108
- if elist [i] == elist[i - 1 ]
107
+ num_e = ne (srg. g )
108
+ for i in 1 : length (srg . edgeorder )
109
+ if srg . edgeorder [i] > num_e
109
110
edgecolors[i] = :red
110
111
insert! (edgelabels, i, " " )
111
112
end
112
113
end
113
114
114
- f, ax, p = graphplot (srg;
115
+ graphplot (srg;
115
116
edge_color = edgecolors,
116
- elabels = edgelabels,
117
+ elabels = edgelabels,
117
118
elabels_rotation = 0 ,
118
- ilabels = ilabels,
119
+ ilabels = ilabels,
119
120
node_color = nodecolors,
120
121
node_size = nodesizes,
121
122
arrow_shift = :end ,
122
123
arrow_size = 20 ,
123
124
curve_distance_usage = true ,
124
125
curve_distance = gen_distances (srg)
125
126
)
126
-
127
- interactive && begin
128
- deregister_interaction! (ax, :rectanglezoom )
129
- register_interaction! (ax, :ndrag , NodeDrag (p))
130
- register_interaction! (ax, :edrag , EdgeDrag (p))
131
- end
132
- display (f)
133
- f
134
127
end
135
128
136
129
"""
137
- ComplexGraph (rn::ReactionSystem; interactive=false)
130
+ plot_complexes (rn::ReactionSystem; interactive=false)
138
131
139
132
Creates a GraphMakie plot of the [`ReactionComplex`](@ref)s in `rn`. Reactions
140
133
correspond to arrows and reaction complexes to blue circles.
144
137
parameter or a `Number`. i.e. `k, A --> B`.
145
138
- Red arrows from complexes to complexes indicate reactions whose rate
146
139
depends on species. i.e. `k*C, A --> B` for `C` a species.
147
- - The `interactive` flag sets the ability to interactively drag nodes and edges in the generated plot.
148
- Only allowed if `GLMakie` is the loaded Makie backend.
149
140
"""
150
- function plot_complex_graph (rn:: ReactionSystem ; interactive = false )
141
+ function Catalyst . plot_complexes (rn:: ReactionSystem )
151
142
img = incidencematgraph (rn)
152
143
specs = species (rn); rxs = reactions (rn)
153
144
edgecolors = [:black for i in 1 : ne (img)]
@@ -161,7 +152,7 @@ function plot_complex_graph(rn::ReactionSystem; interactive = false)
161
152
(! isempty (deps)) && (edgecolors[i] = :red )
162
153
end
163
154
164
- f, ax, p = graphplot (img;
155
+ graphplot (img;
165
156
edge_color = edgecolors,
166
157
elabels = edgelabels,
167
158
ilabels = complexlabels (rn),
@@ -170,14 +161,6 @@ function plot_complex_graph(rn::ReactionSystem; interactive = false)
170
161
arrow_shift = :end ,
171
162
curve_distance = 0.2
172
163
)
173
-
174
- interactive && begin
175
- deregister_interaction! (ax, :rectanglezoom )
176
- register_interaction! (ax, :ndrag , NodeDrag (p))
177
- register_interaction! (ax, :edrag , EdgeDrag (p))
178
- end
179
- display (f)
180
- f
181
164
end
182
165
183
166
function complexelem_tostr (e:: Catalyst.ReactionComplexElement , specstrs)
@@ -199,9 +182,9 @@ function complexlabels(rn::ReactionSystem)
199
182
if isempty (complex)
200
183
push! (labels, " ∅" )
201
184
elseif length (complex) == 1
202
- push! (labels, complexelemtostr (complex[1 ], specstrs))
185
+ push! (labels, complexelem_tostr (complex[1 ], specstrs))
203
186
else
204
- elems = map (c -> complexelemtostr (c, specstrs), complex)
187
+ elems = map (c -> complexelem_tostr (c, specstrs), complex)
205
188
str = reduce ((e1, e2) -> * (e1, " + " , e2), @view elems[2 : end ]; init = elems[1 ])
206
189
push! (labels, str)
207
190
end
0 commit comments