Skip to content

Commit c59a839

Browse files
committed
added networkanalysis
1 parent 4dc7fba commit c59a839

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed

src/network_analysis.jl

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -718,3 +718,54 @@ function conservationlaw_errorcheck(rs, pre_varmap)
718718
isempty(conservedequations(Catalyst.flatten(rs))) ||
719719
error("The system has conservation laws but initial conditions were not provided for some species.")
720720
end
721+
722+
"""
723+
iscomplexbalanced(rs::ReactionSystem, parametermap)
724+
725+
Constructively compute whether a network will have complex-balanced equilibrium
726+
solutions, following the method in van der Schaft et al., [2015](https://link.springer.com/article/10.1007/s10910-015-0498-2#Sec3). Accepts a dictionary, vector, or tuple ofvariable-to-value mappings, e.g. [k1 => 1.0, k2 => 2.0,...].
727+
"""
728+
729+
function iscomplexbalanced(rs::ReactionSystem, parametermap::Dict)
730+
if length(parametermap) != numparams(rs)
731+
error("Incorrect number of parameters specified.")
732+
end
733+
734+
pmap = symmap_to_varmap(rs, parametermap)
735+
pmap = Dict(ModelingToolkit.value(k) => v for (k,v) in pmap)
736+
737+
sm = speciesmap(rs)
738+
cm = reactioncomplexmap(rs)
739+
complexes, D = reactioncomplexes(rs)
740+
rxns = reactions(rs)
741+
nc = length(complexes); nr = numreactions(rs); nm = numspecies(rs)
742+
743+
if !all(r->ismassaction(r, rs), rxns)
744+
error("The supplied ReactionSystem has reactions that are not ismassaction. Testing for being complex balanced is currently only supported for pure mass action networks.")
745+
end
746+
747+
rates = [substitute(rate, pmap) for rate in reactionrates(rs)]
748+
749+
# Construct kinetic matrix, K
750+
K = zeros(nr, nc)
751+
for c in 1:nc
752+
complex = complexes[c]
753+
for (r, dir) in cm[complex]
754+
rxn = rxns[r]
755+
if dir == -1
756+
K[r, c] = rates[r]
757+
end
758+
end
759+
end
760+
761+
L = -D*K
762+
S = netstoichmat(rs)
763+
764+
# Compute ρ using the matrix-tree theorem
765+
g = incidencematgraph(rs)
766+
R = ratematrix(rs, rates)
767+
ρ = matrixtree(g, R)
768+
769+
# Determine if 1) ρ is positive and 2) D^T Ln ρ lies in the image of S^T
770+
if all(>(0), ρ)
771+
img = D'*log.(ρ)

0 commit comments

Comments
 (0)