Skip to content

Commit 63a92c7

Browse files
committed
Merge remote-tracking branch 'vyudu/detailedbalance' into detailedbalance
2 parents a2a9e4d + ef5f0cc commit 63a92c7

File tree

1 file changed

+101
-0
lines changed

1 file changed

+101
-0
lines changed

test/network_analysis/network_properties.jl

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -499,6 +499,107 @@ let
499499
@test isempty(cyclemat)
500500
end
501501

502+
### Complex and detailed balance tests
503+
504+
# The following network is conditionally complex balanced - it only
505+
506+
# Reversible, forest-like deficiency zero network - should be detailed balance for any choice of rate constants.
507+
let
508+
rn = @reaction_network begin
509+
(k1, k2), A <--> B + C
510+
(k3, k4), A <--> D
511+
(k5, k6), A + D <--> E
512+
(k7, k8), A + D <--> G
513+
(k9, k10), G <--> 2F
514+
(k11, k12), A + E <--> H
515+
end
516+
517+
k1 = rand(rng, numparams(rn))
518+
rates1 = Dict(zip(parameters(rn), k1))
519+
k2 = rand(StableRNG(232), numparams(rn))
520+
rates2 = Dict(zip(parameters(rn), k2))
521+
522+
rcs, D = reactioncomplexes(rn)
523+
@test Catalyst.isforestlike(rn) == true
524+
@test Catalyst.isdetailedbalanced(rn, rates1) == true
525+
@test Catalyst.isdetailedbalanced(rn, rates2) == true
526+
end
527+
528+
# Simple connected reversible network
529+
let
530+
rn = @reaction_network begin
531+
(k1, k2), A <--> B
532+
(k3, k4), B <--> C
533+
(k5, k6), C <--> A
534+
end
535+
536+
rcs, D = reactioncomplexes(rn)
537+
rates1 = [:k1=>1.0, :k2=>1.0, :k3=>1.0, :k4=>1.0, :k5=>1.0, :k6=>1.0]
538+
@test Catalyst.isdetailedbalanced(rn, rates1) == true
539+
rates2 = [:k1=>2.0, :k2=>1.0, :k3=>1.0, :k4=>1.0, :k5=>1.0, :k6=>1.0]
540+
@test Catalyst.isdetailedbalanced(rn, rates2) == false
541+
end
542+
543+
# Independent cycle tests: the following reaction entwork has 3 out-of-forest reactions.
544+
let
545+
rn = @reaction_network begin
546+
(k1, k2), A <--> B + C
547+
(k3, k4), A <--> D
548+
(k5, k6), B + C <--> D
549+
(k7, k8), A + D <--> E
550+
(k9, k10), G <--> 2F
551+
(k11, k12), A + D <--> G
552+
(k13, k14), G <--> E
553+
(k15, k16), 2F <--> E
554+
(k17, k18), A + E <--> H
555+
end
556+
557+
rcs, D = reactioncomplexes(rn)
558+
k = rand(rng, numparams(rn))
559+
p = parameters(rn)
560+
rates = Dict(zip(parameters(rn), k))
561+
@test Catalyst.isdetailedbalanced(rn, rates) == false
562+
563+
# Adjust rate constants to obey the independent cycle conditions.
564+
rates[p[6]] = rates[p[1]]*rates[p[4]]*rates[p[5]] / (rates[p[2]]*rates[p[3]])
565+
rates[p[14]] = rates[p[13]]*rates[p[11]]*rates[p[8]] / (rates[p[12]]*rates[p[7]])
566+
rates[p[16]] = rates[p[8]]*rates[p[15]]*rates[p[9]]*rates[p[11]] / (rates[p[7]]*rates[p[12]]*rates[p[10]])
567+
@test Catalyst.isdetailedbalanced(rn, rates) == true
568+
end
569+
570+
# Deficiency two network: the following reaction network must satisfy both the independent cycle conditions and the spanning forest conditions
571+
let
572+
rn = @reaction_network begin
573+
(k1, k2), 3A <--> A + 2B
574+
(k3, k4), A + 2B <--> 3B
575+
(k5, k6), 3B <--> 2A + B
576+
(k7, k8), 2A + B <--> 3A
577+
(k9, k10), 3A <--> 3B
578+
end
579+
580+
rcs, D = reactioncomplexes(rn)
581+
@test Catalyst.edgeindex(D, 1, 2) == 1
582+
@test Catalyst.edgeindex(D, 4, 3) == 6
583+
k = rand(rng, numparams(rn))
584+
p = parameters(rn)
585+
rates = Dict(zip(parameters(rn), k))
586+
@test Catalyst.isdetailedbalanced(rn, rates) == false
587+
588+
# Adjust rate constants to fulfill independent cycle conditions.
589+
rates[p[8]] = rates[p[7]]*rates[p[5]]*rates[p[9]] / (rates[p[6]]*rates[p[10]])
590+
rates[p[3]] = rates[p[2]]*rates[p[4]]*rates[p[9]] / (rates[p[1]]*rates[p[10]])
591+
@test Catalyst.isdetailedbalanced(rn, rates) == false
592+
# Should still fail - doesn't satisfy spanning forest conditions.
593+
594+
# Adjust rate constants to fulfill spanning forest conditions.
595+
cons = rates[p[6]] / rates[p[5]]
596+
rates[p[1]] = rates[p[2]] * cons
597+
rates[p[9]] = rates[p[10]] * cons^(3/2)
598+
rates[p[8]] = rates[p[7]]*rates[p[5]]*rates[p[9]] / (rates[p[6]]*rates[p[10]])
599+
rates[p[3]] = rates[p[2]]*rates[p[4]]*rates[p[9]] / (rates[p[1]]*rates[p[10]])
600+
@test Catalyst.isdetailedbalanced(rn, rates) == true
601+
end
602+
502603
### Other Network Properties Tests ###
503604

504605
# Tests outgoing complexes matrices (1).

0 commit comments

Comments
 (0)