Skip to content

Commit 11c1313

Browse files
committed
tolerance and nullspace
1 parent 63a92c7 commit 11c1313

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

src/network_analysis.jl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -738,13 +738,13 @@ function conservationlaw_errorcheck(rs, pre_varmap)
738738
end
739739

740740
"""
741-
isdetailedbalanced(rs::ReactionSystem, parametermap)
741+
isdetailedbalanced(rs::ReactionSystem, parametermap; reltol=1e-9, abstol)
742742
743743
Constructively compute whether a kinetic system (a reaction network with a set of rate constants) will admit detailed-balanced equilibrium
744744
solutions, using the Wegscheider conditions, [Feinberg, 1989](https://www.sciencedirect.com/science/article/pii/0009250989851243). A detailed-balanced solution is one for which the rate of every forward reaction exactly equals its reverse reaction. Accepts a dictionary, vector, or tuple of variable-to-value mappings, e.g. [k1 => 1.0, k2 => 2.0,...].
745745
"""
746746

747-
function isdetailedbalanced(rs::ReactionSystem, parametermap::Dict)
747+
function isdetailedbalanced(rs::ReactionSystem, parametermap::Dict; abstol=0, reltol=1e-9)
748748
if length(parametermap) != numparams(rs)
749749
error("Incorrect number of parameters specified.")
750750
elseif !isreversible(rs)
@@ -773,30 +773,30 @@ function isdetailedbalanced(rs::ReactionSystem, parametermap::Dict)
773773
ic = Graphs.cycle_basis(g)[1]
774774
fwd = prod([K[ic[r], ic[r + 1]] for r in 1:(length(ic) - 1)]) * K[ic[end], ic[1]]
775775
rev = prod([K[ic[r + 1], ic[r]] for r in 1:(length(ic) - 1)]) * K[ic[1], ic[end]]
776-
fwd rev ? continue : return false
776+
isapprox(fwd, rev; atol = abstol, rtol = reltol) ? continue : return false
777777
end
778778

779779
# Spanning Forest Conditions: for non-deficiency 0 networks, we get an additional δ equations. Choose an orientation for each reaction pair in the spanning forest (we will take the one given by default from kruskal_mst).
780780

781781
if deficiency(rs) > 0
782782
rxn_idxs = [edgeindex(D, Graphs.src(e), Graphs.dst(e)) for e in spanning_forest]
783783
S_F = netstoichmat(rs)[:, rxn_idxs]
784-
sols = nullspace(S_F)
784+
sols = positive_nullspace(S_F)
785785

786786
for i in 1:size(sols, 2)
787787
α = sols[:, i]
788788
fwd = prod([K[Graphs.src(e), Graphs.dst(e)]^α[i]
789789
for (e, i) in zip(spanning_forest, 1:length(α))])
790790
rev = prod([K[Graphs.dst(e), Graphs.src(e)]^α[i]
791791
for (e, i) in zip(spanning_forest, 1:length(α))])
792-
fwd rev ? continue : return false
792+
isapprox(fwd, rev; atol = abstol, rtol = reltol) ? continue : return false
793793
end
794794
end
795795

796796
true
797797
end
798798

799-
# Helper to find the index of the reaction with a given reactnat and product complex.
799+
# Helper to find the index of the reaction with a given reactant and product complex.
800800
function edgeindex(imat, src::T, dst::T) where T <: Int
801801
for i in 1:size(imat, 2)
802802
(imat[src, i] == -1) && (imat[dst, i] == 1) && return i

0 commit comments

Comments
 (0)