Skip to content

Commit aa12d24

Browse files
committed
revert to return , add docstrings
1 parent a6d924a commit aa12d24

File tree

1 file changed

+33
-23
lines changed

1 file changed

+33
-23
lines changed

src/network_analysis.jl

Lines changed: 33 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -197,10 +197,12 @@ end
197197
198198
Return the negative of the graph Laplacian of the reaction network. 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 graph Laplacian, and ``Φ`` is the [`massactionvector`](@ref). ``A_k`` is an n-by-n matrix, where n is the number of complexes, where ``A_{ij} = k_{ij}`` if a reaction exists between the two complexes and 0 otherwise.
199199
Returns a symbolic matrix by default, but will return a numerical matrix if parameter values are specified via pmap.
200+
201+
**Warning**: Unlike other Catalyst functions, the `laplacianmat` function will return a `Matrix{Num}` in the symbolic case. This is to allow easier computation of the matrix decomposition of the ODEs.
200202
"""
201-
function laplacianmat(rn::ReactionSystem, pmap::Dict = Dict())
202-
D = incidencemat(rn)
203-
K = fluxmat(rn, pmap)
203+
function laplacianmat(rn::ReactionSystem, pmap::Dict = Dict(); sparse = false)
204+
D = incidencemat(rn; sparse)
205+
K = fluxmat(rn, pmap; sparse)
204206
D * K
205207
end
206208

@@ -212,8 +214,10 @@ Base.one(::Type{Union{R, Symbolics.BasicSymbolic{Real}}}) where R <: Real = one(
212214
213215
Return an r×c matrix ``K`` such that, if complex ``j`` is the substrate complex of reaction ``i``, then ``K_{ij} = k``, the rate constant for this reaction. Mostly a helper function for the network Laplacian, [`laplacianmat`](@ref). Has the useful property that ``\frac{dx}{dt} = S*K*Φ(x)``, where S is the [`netstoichmat`](@ref) or net stoichiometry matrix and ``Φ(x)`` is the [`massactionvector`](@ref).
214216
Returns a symbolic matrix by default, but will return a numerical matrix if rate constants are specified as a `Tuple`, `Vector`, or `Dict` of symbol-value pairs via `pmap`.
217+
218+
**Warning**: Unlike other Catalyst functions, the `fluxmat` function will return a `Matrix{Num}` in the symbolic case. This is to allow easier computation of the matrix decomposition of the ODEs.
215219
"""
216-
function fluxmat(rn::ReactionSystem, pmap::Dict = Dict())
220+
function fluxmat(rn::ReactionSystem, pmap::Dict = Dict(); sparse=false)
217221
rates = if isempty(pmap)
218222
reactionrates(rn)
219223
else
@@ -224,24 +228,28 @@ function fluxmat(rn::ReactionSystem, pmap::Dict = Dict())
224228
nc = length(rcmap)
225229
nr = length(rates)
226230
mtype = eltype(rates) <: Symbolics.BasicSymbolic ? Num : eltype(rates)
227-
Matrix{Any}(fluxmat(Matrix{mtype}, rcmap, rates))
228-
end
229-
230-
# function fluxmat(::Type{SparseMatrixCSC{T, Int}}, rcmap, rates) where T
231-
# Is = Int[]
232-
# Js = Int[]
233-
# Vs = T[]
234-
# for (i, (complex, rxs)) in enumerate(rcmap)
235-
# for (rx, dir) in rxs
236-
# dir == -1 && begin
237-
# push!(Is, rx)
238-
# push!(Js, i)
239-
# push!(Vs, rates[rx])
240-
# end
241-
# end
242-
# end
243-
# Z = sparse(Is, Js, Vs, length(rates), length(rcmap))
244-
# end
231+
if sparse
232+
return fluxmat(SparseMatrixCSC{mtype, Int}, rcmap, rates)
233+
else
234+
return fluxmat(Matrix{mtype}, rcmap, rates)
235+
end
236+
end
237+
238+
function fluxmat(::Type{SparseMatrixCSC{T, Int}}, rcmap, rates) where T
239+
Is = Int[]
240+
Js = Int[]
241+
Vs = T[]
242+
for (i, (complex, rxs)) in enumerate(rcmap)
243+
for (rx, dir) in rxs
244+
dir == -1 && begin
245+
push!(Is, rx)
246+
push!(Js, i)
247+
push!(Vs, rates[rx])
248+
end
249+
end
250+
end
251+
Z = sparse(Is, Js, Vs, length(rates), length(rcmap))
252+
end
245253

246254
function fluxmat(::Type{Matrix{T}}, rcmap, rates) where T
247255
nr = length(rates)
@@ -279,6 +287,8 @@ end
279287
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)``.
280288
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.
281289
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.
290+
291+
**Warning**: Unlike other Catalyst functions, the `massactionvector` function will return a `Matrix{Num}` in the symbolic case. This is to allow easier computation of the matrix decomposition of the ODEs.
282292
"""
283293
function massactionvector(rn::ReactionSystem, scmap::Dict = Dict(); combinatoric_ratelaws = Catalyst.get_combinatoric_ratelaws(rn))
284294
r = numreactions(rn)
@@ -306,7 +316,7 @@ function massactionvector(rn::ReactionSystem, scmap::Dict = Dict(); combinatoric
306316
push!(Φ, maprod)
307317
end
308318

309-
Vector{Any}(Φ)
319+
Φ
310320
end
311321

312322
function massactionvector(rn::ReactionSystem, scmap::Tuple; combinatoric_ratelaws = Catalyst.get_combinatoric_ratelaws(rn))

0 commit comments

Comments
 (0)