def split_by_ems(self, same_react = False, warn = False):
"""Split reactions according to the elementary modes they take part in.
Return a list of reactions grouped by elementary mode, and the list of reactions
not taking part in any elementary mode.
:param same_react: if True, do not split reactions with the same reactant.
:type same_react: boolean
:param warn: if True, give a warning if not all reactions take part in at least
one elementary mode.
:type warn: boolean
:rtype: (list of lists reactions, list of reactions).
"""
subnet = {}
tinvs = self.t_invariants
if tinvs.rows == 0:
return [self.reactions], []
# case of reactions not taking part in any em
if warn:
if any(sum(tinvs[:, c]) == 0 for c in range(tinvs.cols)):
warnings.warn("Network not covered by elementary modes.")
a = sp.SparseMatrix(sp.zeros(self.n_reactions))
for t in range(tinvs.rows):
inds = [r for r in range(self.n_reactions) if tinvs[t, r] != 0]
for i in inds:
for j in inds:
a[i, j] = 1
if same_react:
for c in self.complexes:
inds = [r for r in range(self.n_reactions) if self.reactions[r].reactant == c]
for i in inds:
for j in inds:
a[i, j] = 1
ncc, cc = connected_components(csr_matrix(np.array(a.tolist()).astype(np.int)))
rcc = [[self.reactions[r] for r in range(self.n_reactions) if cc[r] == l] for l in range(ncc)]
return [rc for rc in rcc if len(rc) > 1], [rc[0] for rc in rcc if len(rc) == 1]
### Print ###
评论列表
文章目录