Skip to content

Commit 68fcd94

Browse files
committed
format
1 parent 4c19284 commit 68fcd94

File tree

14 files changed

+155
-126
lines changed

14 files changed

+155
-126
lines changed

docs/make.jl

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,10 @@ makedocs(sitename = "Catalyst.jl",
4040
collapselevel = 1,
4141
assets = ["assets/favicon.ico"],
4242
canonical = "https://docs.sciml.ai/Catalyst/stable/"),
43-
modules = [Catalyst, ModelingToolkit,
44-
isdefined(Base, :get_extension) ? Base.get_extension(Catalyst, :CatalystGraphMakieExtension) :
45-
Catalyst.CatalystGraphMakieExtension],
43+
modules = [Catalyst, ModelingToolkit,
44+
isdefined(Base, :get_extension) ?
45+
Base.get_extension(Catalyst, :CatalystGraphMakieExtension) :
46+
Catalyst.CatalystGraphMakieExtension],
4647
doctest = false,
4748
clean = true,
4849
pages = pages,

docs/pages.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,8 @@ pages = Any[
7575
],
7676
"FAQs" => "faqs.md",
7777
"API" => Any[
78-
"api/core_api.md",
79-
"api/network_analysis_api.md"
80-
],
78+
"api/core_api.md",
79+
"api/network_analysis_api.md"
80+
],
8181
"Developer Documentation" => "devdocs/dev_guide.md"
8282
]

ext/CatalystCairoMakieExtension/cairo_makie_extension_spatial_modelling.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,8 @@ function lattice_animation(
101101

102102
# Creates the base figure (which is modified in the animation).
103103
fig, ax, hm = heatmap(x_vals, y_vals, vals[1];
104-
axis = (xgridvisible = false, ygridvisible = false, xlabel = "Compartment", ylabel = "Compartment"),
104+
axis = (xgridvisible = false, ygridvisible = false,
105+
xlabel = "Compartment", ylabel = "Compartment"),
105106
colormap, colorrange = (plot_min, plot_max),
106107
kwargs...)
107108
ttitle && (ax.title = "Time: $(round(t[1]; sigdigits = 3))")

ext/CatalystGraphMakieExtension/rn_graph_plot.jl

Lines changed: 69 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -12,29 +12,29 @@ Wrapper intended to allow plotting of multiple edges. This is needed in the foll
1212
`gen_distances` sets the distances between the edges that allows multiple to be visible on the plot at the same time.
1313
"""
1414
struct MultiGraphWrap{T} <: Graphs.AbstractGraph{T}
15-
g::SimpleDiGraph{T}
16-
multiedges::Vector{Graphs.SimpleEdge{T}}
17-
"""Sets the drawing order of the edges. Needed because multiedges need to be consecutive to be drawn properly."""
18-
edgeorder::Vector{Int64}
15+
g::SimpleDiGraph{T}
16+
multiedges::Vector{Graphs.SimpleEdge{T}}
17+
"""Sets the drawing order of the edges. Needed because multiedges need to be consecutive to be drawn properly."""
18+
edgeorder::Vector{Int64}
1919
end
2020

2121
# Create the SimpleDiGraph corresponding to the species and reactions, the species-reaction graph
22-
function SRGraphWrap(rn::ReactionSystem)
22+
function SRGraphWrap(rn::ReactionSystem)
2323
srg = species_reaction_graph(rn)
2424
multiedges = Vector{Graphs.SimpleEdge{Int}}()
2525
sm = speciesmap(rn)
2626
specs = species(rn)
2727

2828
deps = Set()
29-
for (i, rx) in enumerate(reactions(rn))
29+
for (i, rx) in enumerate(reactions(rn))
3030
empty!(deps)
3131
get_variables!(deps, rx.rate, specs)
3232
if !isempty(deps)
33-
for spec in deps
33+
for spec in deps
3434
specidx = sm[spec]
35-
has_edge(srg, specidx, i + length(specs)) ?
36-
push!(multiedges, Graphs.SimpleEdge(specidx, i + length(specs))) :
37-
add_edge!(srg, Graphs.SimpleEdge(specidx, i + length(specs)))
35+
has_edge(srg, specidx, i + length(specs)) ?
36+
push!(multiedges, Graphs.SimpleEdge(specidx, i + length(specs))) :
37+
add_edge!(srg, Graphs.SimpleEdge(specidx, i + length(specs)))
3838
end
3939
end
4040
end
@@ -44,16 +44,17 @@ function SRGraphWrap(rn::ReactionSystem)
4444
end
4545

4646
# Automatically set edge drawing order if not supplied
47-
function MultiGraphWrap(g::SimpleDiGraph{T}, multiedges::Vector{Graphs.SimpleEdge{T}}) where T
47+
function MultiGraphWrap(
48+
g::SimpleDiGraph{T}, multiedges::Vector{Graphs.SimpleEdge{T}}) where {T}
4849
edgelist = vcat(collect(Graphs.edges(g)), multiedges)
4950
edgeorder = sortperm(edgelist)
5051
MultiGraphWrap(g, multiedges, edgeorder)
5152
end
5253

5354
# Return the multigraph and reaction order corresponding to the complex graph. The reaction order is the order of reactions(rn) that would match the edge order given by g.edgeorder.
54-
function ComplexGraphWrap(rn::ReactionSystem)
55+
function ComplexGraphWrap(rn::ReactionSystem)
5556
img = incidencematgraph(rn)
56-
D = incidencemat(rn; sparse=true)
57+
D = incidencemat(rn; sparse = true)
5758
specs = species(rn)
5859
rxs = reactions(rn)
5960

@@ -78,7 +79,7 @@ function ComplexGraphWrap(rn::ReactionSystem)
7879
edgelist = edgelist[rxorder]
7980
multiedges = Vector{Graphs.SimpleEdge{Int}}()
8081
for i in 2:length(edgelist)
81-
isequal(edgelist[i], edgelist[i-1]) && push!(multiedges, edgelist[i])
82+
isequal(edgelist[i], edgelist[i - 1]) && push!(multiedges, edgelist[i])
8283
end
8384
MultiGraphWrap(img, multiedges), rxorder
8485
end
@@ -87,16 +88,16 @@ Base.eltype(g::MultiGraphWrap) = eltype(g.g)
8788
Graphs.edgetype(g::MultiGraphWrap) = edgetype(g.g)
8889
Graphs.has_edge(g::MultiGraphWrap, s, d) = has_edge(g.g, s, d)
8990
Graphs.has_vertex(g::MultiGraphWrap, i) = has_vertex(g.g, i)
90-
Graphs.inneighbors(g::MultiGraphWrap{T}, i) where T = inneighbors(g.g, i)
91-
Graphs.outneighbors(g::MultiGraphWrap{T}, i) where T = outneighbors(g.g, i)
91+
Graphs.inneighbors(g::MultiGraphWrap{T}, i) where {T} = inneighbors(g.g, i)
92+
Graphs.outneighbors(g::MultiGraphWrap{T}, i) where {T} = outneighbors(g.g, i)
9293
Graphs.ne(g::MultiGraphWrap) = length(g.multiedges) + length(Graphs.edges(g.g))
9394
Graphs.nv(g::MultiGraphWrap) = nv(g.g)
9495
Graphs.vertices(g::MultiGraphWrap) = vertices(g.g)
9596
Graphs.is_directed(::Type{<:MultiGraphWrap}) = true
9697
Graphs.is_directed(g::MultiGraphWrap) = is_directed(g.g)
9798
Graphs.is_connected(g::MultiGraphWrap) = is_connected(g.g)
9899

99-
function Graphs.adjacency_matrix(g::MultiGraphWrap)
100+
function Graphs.adjacency_matrix(g::MultiGraphWrap)
100101
adj = Graphs.adjacency_matrix(g.g)
101102
for e in g.multiedges
102103
adj[src(e), dst(e)] = 1
@@ -108,32 +109,32 @@ function Graphs.edges(g::MultiGraphWrap)
108109
edgelist = vcat(collect(Graphs.edges(g.g)), g.multiedges)[g.edgeorder]
109110
end
110111

111-
function gen_distances(g::MultiGraphWrap; inc = 0.2)
112+
function gen_distances(g::MultiGraphWrap; inc = 0.2)
112113
edgelist = edges(g)
113114
distances = zeros(length(edgelist))
114115
edgedict = Dict(edgelist[1] => [1])
115116
for (i, e) in enumerate(@view edgelist[2:end])
116-
if edgelist[i] != edgelist[i+1]
117-
edgedict[e] = [i+1]
117+
if edgelist[i] != edgelist[i + 1]
118+
edgedict[e] = [i + 1]
118119
else
119-
push!(edgedict[e], i+1)
120+
push!(edgedict[e], i + 1)
120121
end
121122
end
122123

123124
for (edge, inds) in edgedict
124125
if haskey(edgedict, Edge(dst(edge), src(edge)))
125-
distances[inds[1]] != 0. && continue
126+
distances[inds[1]] != 0.0 && continue
126127
inds_ = edgedict[Edge(dst(edge), src(edge))]
127128

128129
len = length(inds) + length(inds_)
129-
sp = -inc/2*(len-1)
130-
ep = sp + inc*(len-1)
130+
sp = -inc / 2 * (len - 1)
131+
ep = sp + inc * (len - 1)
131132
dists = collect(sp:inc:ep)
132133
distances[inds] = dists[1:length(inds)]
133-
distances[inds_] = -dists[length(inds)+1:end]
134+
distances[inds_] = -dists[(length(inds) + 1):end]
134135
else
135-
sp = -inc/2*(length(inds)-1)
136-
ep = sp + inc*(length(inds)-1)
136+
sp = -inc / 2 * (length(inds) - 1)
137+
ep = sp + inc * (length(inds) - 1)
137138
distances[inds] = collect(sp:inc:ep)
138139
end
139140
end
@@ -158,30 +159,30 @@ Notes:
158159
red and black arrows from `A` to the reaction node.
159160
160161
For a list of accepted keyword arguments to the graph plot, please see the [GraphMakie documentation](https://graph.makie.org/stable/#The-graphplot-Recipe).
161-
"""
162+
"""
162163
function Catalyst.plot_network(rn::ReactionSystem; kwargs...)
163164
srg = SRGraphWrap(rn)
164165
ns = length(species(rn))
165-
nodecolors = vcat([:skyblue3 for i in 1:ns],
166-
[:green for i in ns+1:nv(srg)])
167-
ilabels = vcat(map(s -> String(tosymbol(s, escape=false)), species(rn)),
168-
["R$i" for i in 1:nv(srg)-ns])
166+
nodecolors = vcat([:skyblue3 for i in 1:ns],
167+
[:green for i in (ns + 1):nv(srg)])
168+
ilabels = vcat(map(s -> String(tosymbol(s, escape = false)), species(rn)),
169+
["R$i" for i in 1:(nv(srg) - ns)])
169170

170171
ssm = substoichmat(rn)
171172
psm = prodstoichmat(rn)
172173
# Get stoichiometry of reaction
173174
edgelabels = map(Graphs.edges(srg.g)) do e
174-
string(src(e) > ns ?
175-
psm[dst(e), src(e)-ns] :
176-
ssm[src(e), dst(e)-ns])
177-
end
175+
string(src(e) > ns ?
176+
psm[dst(e), src(e) - ns] :
177+
ssm[src(e), dst(e) - ns])
178+
end
178179
edgecolors = [:black for i in 1:ne(srg)]
179180

180181
num_e = ne(srg.g)
181182
# Handle the rate edges
182183
for i in 1:length(srg.edgeorder)
183184
# If there are stoichiometry and rate edges from the same species to reaction
184-
if srg.edgeorder[i] > num_e
185+
if srg.edgeorder[i] > num_e
185186
edgecolors[i] = :red
186187
insert!(edgelabels, i, "")
187188
elseif edgelabels[i] == "0"
@@ -190,29 +191,29 @@ function Catalyst.plot_network(rn::ReactionSystem; kwargs...)
190191
end
191192
end
192193

193-
layout = if !haskey(kwargs, :layout)
194+
layout = if !haskey(kwargs, :layout)
194195
Stress()
195196
end
196-
f = graphplot(srg;
197-
layout,
198-
edge_color = edgecolors,
199-
elabels = edgelabels,
200-
elabels_rotation = 0,
201-
ilabels = ilabels,
202-
node_color = nodecolors,
203-
arrow_shift = :end,
204-
arrow_size = 20,
205-
curve_distance_usage = true,
206-
curve_distance = gen_distances(srg),
207-
kwargs...
208-
)
197+
f = graphplot(srg;
198+
layout,
199+
edge_color = edgecolors,
200+
elabels = edgelabels,
201+
elabels_rotation = 0,
202+
ilabels = ilabels,
203+
node_color = nodecolors,
204+
arrow_shift = :end,
205+
arrow_size = 20,
206+
curve_distance_usage = true,
207+
curve_distance = gen_distances(srg),
208+
kwargs...
209+
)
209210

210211
f.axis.xautolimitmargin = (0.15, 0.15)
211212
f.axis.yautolimitmargin = (0.15, 0.15)
212213
hidedecorations!(f.axis)
213214
hidespines!(f.axis)
214215
f.axis.aspect = DataAspect()
215-
216+
216217
f
217218
end
218219

@@ -248,21 +249,21 @@ function Catalyst.plot_complexes(rn::ReactionSystem; show_rate_labels = false, k
248249
# Get complex graph and reaction order for edgecolors and edgelabels. rxorder gives the order of reactions(rn) that would match the edge order in edges(cg).
249250
cg, rxorder = ComplexGraphWrap(rn)
250251

251-
layout = if !haskey(kwargs, :layout)
252+
layout = if !haskey(kwargs, :layout)
252253
Stress()
253254
end
254255
f = graphplot(cg;
255-
layout,
256-
edge_color = edgecolors[rxorder],
257-
elabels = show_rate_labels ? edgelabels[rxorder] : [],
258-
ilabels = complexlabels(rn),
259-
node_color = :skyblue3,
260-
elabels_rotation = 0,
261-
arrow_shift = :end,
262-
curve_distance_usage = true,
263-
curve_distance = gen_distances(cg),
264-
kwargs...
265-
)
256+
layout,
257+
edge_color = edgecolors[rxorder],
258+
elabels = show_rate_labels ? edgelabels[rxorder] : [],
259+
ilabels = complexlabels(rn),
260+
node_color = :skyblue3,
261+
elabels_rotation = 0,
262+
arrow_shift = :end,
263+
curve_distance_usage = true,
264+
curve_distance = gen_distances(cg),
265+
kwargs...
266+
)
266267

267268
f.axis.xautolimitmargin = (0.15, 0.15)
268269
f.axis.yautolimitmargin = (0.15, 0.15)
@@ -273,9 +274,9 @@ function Catalyst.plot_complexes(rn::ReactionSystem; show_rate_labels = false, k
273274
f
274275
end
275276

276-
function complexelem_tostr(e::Catalyst.ReactionComplexElement, specstrs)
277+
function complexelem_tostr(e::Catalyst.ReactionComplexElement, specstrs)
277278
if e.speciesstoich == 1
278-
return "$(specstrs[e.speciesid])"
279+
return "$(specstrs[e.speciesid])"
279280
else
280281
return "$(e.speciesstoich)$(specstrs[e.speciesid])"
281282
end
@@ -285,11 +286,11 @@ end
285286
function complexlabels(rn::ReactionSystem)
286287
labels = String[]
287288

288-
specstrs = map(s -> String(tosymbol(s, escape=false)), species(rn))
289+
specstrs = map(s -> String(tosymbol(s, escape = false)), species(rn))
289290
complexes, B = reactioncomplexes(rn)
290291

291292
for complex in complexes
292-
if isempty(complex)
293+
if isempty(complex)
293294
push!(labels, "")
294295
elseif length(complex) == 1
295296
push!(labels, complexelem_tostr(complex[1], specstrs))

ext/CatalystHomotopyContinuationExtension/homotopy_continuation_extension.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,8 @@ function common_denominator(expr)
139139
den ^= pow
140140
return num / den
141141
end
142-
return maketerm(BasicSymbolic, operation(expr), map(common_denominator, arguments(expr)), metadata(expr))
142+
return maketerm(BasicSymbolic, operation(expr),
143+
map(common_denominator, arguments(expr)), metadata(expr))
143144
end
144145

145146
# If the input is a fraction, removes the denominator.

src/Catalyst.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,8 @@ export @reaction_network, @network_component, @reaction, @species
110110
# Network analysis functionality.
111111
include("network_analysis.jl")
112112
export reactioncomplexmap, reactioncomplexes, incidencemat
113-
export complexstoichmat, laplacianmat, fluxmat, massactionvector, complexoutgoingmat, adjacencymat
113+
export complexstoichmat, laplacianmat, fluxmat, massactionvector, complexoutgoingmat,
114+
adjacencymat
114115
export incidencematgraph, linkageclasses, stronglinkageclasses,
115116
terminallinkageclasses, deficiency, subnetworks
116117
export linkagedeficiencies, isreversible, isweaklyreversible

src/chemistry_functionality.jl

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,10 +103,12 @@ function make_compound(expr)
103103

104104
# If no ivs were given, inserts an expression which evaluates to the union of the ivs
105105
# for the species the compound depends on.
106-
ivs_get_expr = :(unique(reduce( vcat, (sorted_arguments(ModelingToolkit.unwrap(comp))
106+
ivs_get_expr = :(unique(reduce(
107+
vcat, (sorted_arguments(ModelingToolkit.unwrap(comp))
107108
for comp in $components))))
108109
if isempty(ivs)
109-
species_expr = Catalyst.insert_independent_variable(species_expr, :($ivs_get_expr...))
110+
species_expr = Catalyst.insert_independent_variable(
111+
species_expr, :($ivs_get_expr...))
110112
end
111113

112114
# Creates the found expressions that will create the compound species.

0 commit comments

Comments
 (0)