Skip to content

Commit caab946

Browse files
committed
cache incidence mat
1 parent 4e598cc commit caab946

File tree

1 file changed

+11
-39
lines changed

1 file changed

+11
-39
lines changed

src/network_analysis.jl

Lines changed: 11 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -277,8 +277,7 @@ incidencematgraph(sir)
277277
function incidencematgraph(rn::ReactionSystem)
278278
nps = get_networkproperties(rn)
279279
if Graphs.nv(nps.incidencegraph) == 0
280-
isempty(nps.incidencemat) &&
281-
error("Please call reactioncomplexes(rn) first to construct the incidence matrix.")
280+
isempty(nps.incidencemat) && reactioncomplexes(rn)
282281
nps.incidencegraph = incidencematgraph(nps.incidencemat)
283282
end
284283
nps.incidencegraph
@@ -329,17 +328,12 @@ Given the incidence graph of a reaction network, return a vector of the
329328
connected components of the graph (i.e. sub-groups of reaction complexes that
330329
are connected in the incidence graph).
331330
332-
Notes:
333-
- Requires the `incidencemat` to already be cached in `rn` by a previous call to
334-
`reactioncomplexes`.
335-
336331
For example,
337332
```julia
338333
sir = @reaction_network SIR begin
339334
β, S + I --> 2I
340335
ν, I --> R
341336
end
342-
complexes,incidencemat = reactioncomplexes(sir)
343337
linkageclasses(sir)
344338
```
345339
gives
@@ -371,17 +365,12 @@ Here the deficiency, ``\delta``, of a network with ``n`` reaction complexes,
371365
\delta = n - \ell - s
372366
```
373367
374-
Notes:
375-
- Requires the `incidencemat` to already be cached in `rn` by a previous call to
376-
`reactioncomplexes`.
377-
378368
For example,
379369
```julia
380370
sir = @reaction_network SIR begin
381371
β, S + I --> 2I
382372
ν, I --> R
383373
end
384-
rcs,incidencemat = reactioncomplexes(sir)
385374
δ = deficiency(sir)
386375
```
387376
"""
@@ -419,17 +408,12 @@ end
419408
420409
Find subnetworks corresponding to each linkage class of the reaction network.
421410
422-
Notes:
423-
- Requires the `incidencemat` to already be cached in `rn` by a previous call to
424-
`reactioncomplexes`.
425-
426411
For example,
427412
```julia
428413
sir = @reaction_network SIR begin
429414
β, S + I --> 2I
430415
ν, I --> R
431416
end
432-
complexes,incidencemat = reactioncomplexes(sir)
433417
subnetworks(sir)
434418
```
435419
"""
@@ -456,17 +440,12 @@ end
456440
457441
Calculates the deficiency of each sub-reaction network within `network`.
458442
459-
Notes:
460-
- Requires the `incidencemat` to already be cached in `rn` by a previous call to
461-
`reactioncomplexes`.
462-
463443
For example,
464444
```julia
465445
sir = @reaction_network SIR begin
466446
β, S + I --> 2I
467447
ν, I --> R
468448
end
469-
rcs,incidencemat = reactioncomplexes(sir)
470449
linkage_deficiencies = linkagedeficiencies(sir)
471450
```
472451
"""
@@ -487,17 +466,12 @@ end
487466
488467
Given a reaction network, returns if the network is reversible or not.
489468
490-
Notes:
491-
- Requires the `incidencemat` to already be cached in `rn` by a previous call to
492-
`reactioncomplexes`.
493-
494469
For example,
495470
```julia
496471
sir = @reaction_network SIR begin
497472
β, S + I --> 2I
498473
ν, I --> R
499474
end
500-
rcs,incidencemat = reactioncomplexes(sir)
501475
isreversible(sir)
502476
```
503477
"""
@@ -511,30 +485,28 @@ end
511485
512486
Determine if the reaction network with the given subnetworks is weakly reversible or not.
513487
514-
Notes:
515-
- Requires the `incidencemat` to already be cached in `rn` by a previous call to
516-
`reactioncomplexes`.
517-
518488
For example,
519489
```julia
520490
sir = @reaction_network SIR begin
521491
β, S + I --> 2I
522492
ν, I --> R
523493
end
524-
rcs,incidencemat = reactioncomplexes(sir)
525494
subnets = subnetworks(rn)
526495
isweaklyreversible(rn, subnets)
527496
```
528497
"""
529498
function isweaklyreversible(rn::ReactionSystem, subnets)
530-
im = get_networkproperties(rn).incidencemat
531-
isempty(im) &&
532-
error("Error, please call reactioncomplexes(rn::ReactionSystem) to ensure the incidence matrix has been cached.")
533-
sparseig = issparse(im)
499+
nps = get_networkproperties(rn)
500+
isempty(nps.incidencemat) && reactioncomplexes(rn)
501+
imat = nps.incidencemat
502+
sparseig = issparse(imat)
503+
534504
for subnet in subnets
535-
nps = get_networkproperties(subnet)
536-
isempty(nps.incidencemat) && reactioncomplexes(subnet; sparse = sparseig)
505+
subnps = get_networkproperties(subnet)
506+
isempty(subnps.incidencemat) && reactioncomplexes(subnet; sparse = sparseig)
537507
end
508+
509+
# A network is weakly reversible if all of its subnetworks are strongly connected
538510
all(Graphs.is_strongly_connected incidencematgraph, subnets)
539511
end
540512

@@ -902,6 +874,6 @@ function satisfiesdeficiencyone(rn::ReactionSystem)
902874
complexes, D = reactioncomplexes(rn)
903875
lcs = linkageclasses(rn); tslcs = terminallinkageclasses(rn)
904876

905-
δ_l .<= 1 && sum(δ_l) = δ && length(lcs) == length(tslcs)
877+
δ_l .<= 1 && (sum(δ_l) == δ) && length(lcs) == length(tslcs)
906878
end
907879

0 commit comments

Comments
 (0)