Skip to content

Commit b3dce88

Browse files
committed
format
1 parent 7487e0d commit b3dce88

File tree

2 files changed

+28
-15
lines changed

2 files changed

+28
-15
lines changed

src/network_analysis.jl

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,8 @@ end
199199
Returns a symbolic matrix by default, but will return a numerical matrix if parameter values are specified via pmap.
200200
"""
201201
function laplacianmat(rn::ReactionSystem, pmap = Dict(); sparse = false)
202-
D = incidencemat(rn; sparse); K = fluxmat(rn, pmap; sparse)
202+
D = incidencemat(rn; sparse)
203+
K = fluxmat(rn, pmap; sparse)
203204
D*K
204205
end
205206

@@ -213,7 +214,9 @@ function fluxmat(rn::ReactionSystem, pmap::Dict = Dict(); sparse=false)
213214
rates = reactionrates(rn)
214215

215216
!isempty(pmap) && (rates = substitutevals(rn, pmap, parameters(rn), rates))
216-
rcmap = reactioncomplexmap(rn); nc = length(rcmap); nr = length(rates)
217+
rcmap = reactioncomplexmap(rn)
218+
nc = length(rcmap)
219+
nr = length(rates)
217220
mtype = eltype(rates) <: Symbolics.BasicSymbolic ? Num : eltype(rates)
218221
if sparse
219222
return fluxmat(SparseMatrixCSC{mtype, Int}, rcmap, rates)
@@ -239,7 +242,8 @@ function fluxmat(::Type{SparseMatrixCSC{T, Int}}, rcmap, rates) where T
239242
end
240243

241244
function fluxmat(::Type{Matrix{T}}, rcmap, rates) where T
242-
nr = length(rates); nc = length(rcmap)
245+
nr = length(rates)
246+
nc = length(rcmap)
243247
K = zeros(T, nr, nc)
244248
for (i, (complex, rxs)) in enumerate(rcmap)
245249
for (rx, dir) in rxs
@@ -260,7 +264,7 @@ function fluxmat(rn::ReactionSystem, pmap::Tuple; sparse = false)
260264
end
261265

262266
# Helper to substitute values into a (vector of) symbolic expressions. The syms are the symbols to substitute and the symexprs are the expressions to substitute into.
263-
function substitutevals(rn::ReactionSystem, map::Dict, syms, symexprs)
267+
function substitutevals(rn::ReactionSystem, map::Dict, syms, symexprs)
264268
length(map) != length(syms) && error("Incorrect number of parameter-value pairs were specified.")
265269
map = symmap_to_varmap(rn, map)
266270
map = Dict(ModelingToolkit.value(k) => v for (k, v) in map)
@@ -272,11 +276,13 @@ end
272276
273277
Return the vector whose entries correspond to the "mass action products" of each complex. For example, given the complex A + B, the corresponding entry of the vector would be ``A*B``, and for the complex 2X + Y, the corresponding entry would be ``X^2*Y``. The ODE system of a chemical reaction network can be factorized as ``\frac{dx}{dt} = Y A_k Φ(x)``, where ``Y`` is the [`complexstoichmat`](@ref) and ``A_k`` is the negative of the [`laplacianmat`](@ref). This utility returns ``Φ(x)``.
274278
Returns a symbolic vector by default, but will return a numerical vector if species concentrations are specified as a tuple, vector, or dictionary via scmap.
275-
If the `combinatoric_ratelaws` option is set, will include prefactors for that (see [introduction to Catalyst's rate laws](@ref introduction_to_catalyst_ratelaws).
279+
If the `combinatoric_ratelaws` option is set, will include prefactors for that (see [introduction to Catalyst's rate laws](@ref introduction_to_catalyst_ratelaws). Will default to the default for the system.
276280
"""
277-
function massactionvector(rn::ReactionSystem, scmap::Dict = Dict(); combinatoric_ratelaws = true)
278-
r = numreactions(rn); rxs = reactions(rn)
279-
sm = speciesmap(rn); specs = species(rn)
281+
function massactionvector(rn::ReactionSystem, scmap::Dict = Dict(); combinatoric_ratelaws = rn.combinatoric_ratelaws)
282+
r = numreactions(rn)
283+
rxs = reactions(rn)
284+
sm = speciesmap(rn)
285+
specs = species(rn)
280286

281287
if !all(r -> ismassaction(r, rn), rxs)
282288
error("The supplied ReactionSystem has reactions that are not ismassaction. The mass action vector is only defined for pure mass action networks.")
@@ -298,12 +304,12 @@ function massactionvector(rn::ReactionSystem, scmap::Dict = Dict(); combinatoric
298304
Φ
299305
end
300306

301-
function massactionvector(rn::ReactionSystem, scmap::Tuple; combinatoric_ratelaws = true)
307+
function massactionvector(rn::ReactionSystem, scmap::Tuple; combinatoric_ratelaws = rn.combinatoric_ratelaws)
302308
sdict = Dict(scmap)
303309
massactionvector(rn, sdict; combinatoric_ratelaws)
304310
end
305311

306-
function massactionvector(rn::ReactionSystem, scmap::Vector; combinatoric_ratelaws = true)
312+
function massactionvector(rn::ReactionSystem, scmap::Vector; combinatoric_ratelaws = rn.combinatoric_ratelaws)
307313
sdict = Dict(scmap)
308314
massactionvector(rn, sdict; combinatoric_ratelaws)
309315
end

test/network_analysis/network_properties.jl

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,8 @@ let
381381

382382
K = fluxmat(MAPK)
383383
# Construct matrix from incidence matrix
384-
mat = zeros(Num, 30, 26); D = incidencemat(MAPK)
384+
mat = zeros(Num, 30, 26)
385+
D = incidencemat(MAPK)
385386
rates = reactionrates(MAPK)
386387
for (i, col) in enumerate(eachcol(D))
387388
sub = findfirst(==(-1), col)
@@ -403,7 +404,8 @@ let
403404
A_k = Catalyst.laplacianmat(MAPK; sparse = true)
404405
@test Catalyst.issparse(A_k)
405406

406-
S = netstoichmat(MAPK); Y = complexstoichmat(MAPK)
407+
S = netstoichmat(MAPK)
408+
Y = complexstoichmat(MAPK)
407409
@test isequal(S*K, Y*A_k)
408410

409411
eqs = Catalyst.assemble_oderhs(MAPK, specs)
@@ -440,7 +442,8 @@ let
440442
(k2, k3), 2Y + 2Z <--> 3X
441443
end
442444

443-
Φ = Catalyst.massactionvector(rn); specs = species(rn)
445+
Φ = Catalyst.massactionvector(rn)
446+
specs = species(rn)
444447
crvec = [rn.X^2/2 * rn.Y * rn.Z^3/6,
445448
1.,
446449
rn.Y^2/2 * rn.Z^2/2,
@@ -455,7 +458,10 @@ let
455458

456459
# Test that the ODEs generated are the same.
457460
eqs = Catalyst.assemble_oderhs(rn, specs)
458-
S = netstoichmat(rn); Y = complexstoichmat(rn); K = fluxmat(rn); A_k = laplacianmat(rn)
461+
S = netstoichmat(rn)
462+
Y = complexstoichmat(rn)
463+
K = fluxmat(rn)
464+
A_k = laplacianmat(rn)
459465
@test all(iszero, simplify(eqs - S*K*Φ))
460466
@test all(iszero, simplify(eqs - Y*A_k*Φ))
461467

@@ -467,7 +473,8 @@ let
467473
k = rand(rng, numparams(rn))
468474
ratevec = collect(zip(parameters(rn), k))
469475
ratemap = Dict(ratevec)
470-
K = fluxmat(rn, ratemap); A_k = laplacianmat(rn, ratemap)
476+
K = fluxmat(rn, ratemap)
477+
A_k = laplacianmat(rn, ratemap)
471478

472479
numeqs = similar(eqs)
473480
for i in 1:length(eqs)

0 commit comments

Comments
 (0)