markovmodel / msmtools

Tools for estimating and analyzing Markov state models
GNU Lesser General Public License v3.0
40 stars 27 forks source link

tpt pathway decomposition fails when requesting all pathways #7

Closed marscher closed 9 years ago

marscher commented 9 years ago

From @franknoe on April 14, 2015 23:53

In the BPTI notebook, when requesting all pathways by:

cgflux.pathways()

or

cgflux.pathways(fraction=1.0)

this exception happens:

/Users/noe/anaconda/lib/python2.7/site-packages/pyEMMA-1.2-py2.7-macosx-10.5-x86_64.egg/pyemma/msm/flux/sparse/pathways.pyc in pathway(F, A, B)
    146                           "obtained from a reversible transition meatrix."))
    147     else:
--> 148         wL = pathway(F, A, [b1, ])
    149     if np.any(B == b2):
    150         wR = [b2, ]

/Users/noe/anaconda/lib/python2.7/site-packages/pyEMMA-1.2-py2.7-macosx-10.5-x86_64.egg/pyemma/msm/flux/sparse/pathways.pyc in pathway(F, A, B)
    138 
    139     """
--> 140     b1, b2, F = find_bottleneck(F, A, B)
    141     if np.any(A == b1):
    142         wL = [b1, ]

/Users/noe/anaconda/lib/python2.7/site-packages/pyEMMA-1.2-py2.7-macosx-10.5-x86_64.egg/pyemma/msm/flux/sparse/pathways.pyc in find_bottleneck(F, A, B)
     43 
     44     """Check if edge with largest conductivity connects A and B"""
---> 45     b = np.array(row[-1], col[-1])
     46     if has_path(b, A, B):
     47         return b

IndexError: index -1 is out of bounds for axis 0 with size 0

Copied from original issue: markovmodel/PyEMMA#251

marscher commented 9 years ago

find_bottleneck does not handle the case of an empty flux matrix

marscher commented 9 years ago

From @trendelkampschroer on July 1, 2015 15:10

@franknoe: Could you point me to the location for the BPTI notebook and the resources required to run it. Starting from there I will try to find out what went wrong.

@marscher: Thanks for pointing out this problem in find_bottleneck. I will have a look at it too.

marscher commented 9 years ago

From @franknoe on July 1, 2015 15:12

I think you can just use the tpt ipython notebook because BPTI is not needed for that. If you ask the pathway decomposition to give the fraction 1.0 (all) of the pathways, then there is an exception.

Am 01/07/15 um 17:10 schrieb Benjamin Trendelkamp-Schroer:

@franknoe https://github.com/franknoe: Could you point me to the location for the BPTI notebook and the resources required to run it. Starting from there I will try to find out what went wrong.

@marscher https://github.com/marscher: Thanks for pointing out this problem in find_bottleneck. I will have a look at it too.

— Reply to this email directly or view it on GitHub https://github.com/markovmodel/PyEMMA/issues/251#issuecomment-117711158.


Prof. Dr. Frank Noe Head of Computational Molecular Biology group Freie Universitaet Berlin

Phone: (+49) (0)30 838 75354 Web: research.franknoe.de

Mail: Arnimallee 6, 14195 Berlin, Germany

marscher commented 9 years ago

From @trendelkampschroer on July 1, 2015 15:14

Okay will do that.

marscher commented 9 years ago

From @trendelkampschroer on July 9, 2015 15:23

This has been fixed by e37c082a2ea5251edd9c639889d9abffb7ef5fed

gph82 commented 7 years ago

Hi I'm still getting this issue (i think it's this one, that's why I'm not opening a new one). Needed file attached is test.npy.zip

import pyemma
import msmtools
import numpy as np
print("pyemma.__version__",pyemma.__version__)
print("msmtools.__version__", msmtools.__version__)
# pyemma.__version__ 2.0.2-69-g907c6d9
# msmtools.__version__ -1.2+3.ge6a7a93-py3.4-linux-x86_64.egg
P, A_idx, B_idx = np.load('test.npy')
iMSM_test = pyemma.msm.MSM(P)
iMSM_test.pcca(6)
print("Idxs of metastable sets:", A_idx, B_idx)
# Idxs of metastable sets: 5 4
tpt_test = pyemma.msm.tpt(iMSM_test, 
                          iMSM_test.metastable_sets[A_idx], 
                          iMSM_test.metastable_sets[B_idx]
                          )
_, tpt_coarse_reactive_flux_test = tpt_test.coarse_grain(iMSM_test.metastable_sets)
# No problem here
tpt_coarse_reactive_flux_test.pathways(fraction=.99)
# Problem here
tpt_coarse_reactive_flux_test.pathways()
---------------------------------------------------------------------------
IndexError                                Traceback (most recent call last)
<ipython-input-3-76033c5b7238> in <module>()
      5 _, tpt_coarse_reactive_flux_test = tpt_test.coarse_grain(iMSM_test.metastable_sets)
      6 tpt_coarse_reactive_flux_test.pathways(fraction=.99)
----> 7 tpt_coarse_reactive_flux_test.pathways()

/home/mi/gph82/miniconda3/lib/python3.4/site-packages/msmtools-1.2+3.ge6a7a93-py3.4-linux-x86_64.egg/msmtools/flux/reactive_flux.py in pathways(self, fraction, maxiter)
    200         """
    201         return tptapi.pathways(self.net_flux, self.A, self.B,
--> 202                                fraction=fraction, maxiter=maxiter)
    203 
    204     def _pathways_to_flux(self, paths, pathfluxes, n=None):

/home/mi/gph82/miniconda3/lib/python3.4/site-packages/msmtools-1.2+3.ge6a7a93-py3.4-linux-x86_64.egg/msmtools/flux/api.py in pathways(F, A, B, fraction, maxiter)
    536         return sparse.pathways.pathways(F, A, B, fraction=fraction, maxiter=maxiter)
    537     elif isdense(F):
--> 538         return sparse.pathways.pathways(csr_matrix(F), A, B, fraction=fraction, maxiter=maxiter)
    539     else:
    540         raise _type_not_supported

/home/mi/gph82/miniconda3/lib/python3.4/site-packages/msmtools-1.2+3.ge6a7a93-py3.4-linux-x86_64.egg/msmtools/flux/sparse/pathways.py in pathways(F, A, B, fraction, maxiter, tol)
    288         """Find dominant pathway of flux-network"""
    289         try:
--> 290             path = pathway(F, A, B)
    291         except PathwayError:
    292             break

/home/mi/gph82/miniconda3/lib/python3.4/site-packages/msmtools-1.2+3.ge6a7a93-py3.4-linux-x86_64.egg/msmtools/flux/sparse/pathways.py in pathway(F, A, B)
    179                           "obtained from a reversible transition meatrix."))
    180     else:
--> 181         wR = pathway(F, [b2, ], B)
    182     return wL + wR
    183 

/home/mi/gph82/miniconda3/lib/python3.4/site-packages/msmtools-1.2+3.ge6a7a93-py3.4-linux-x86_64.egg/msmtools/flux/sparse/pathways.py in pathway(F, A, B)
    179                           "obtained from a reversible transition meatrix."))
    180     else:
--> 181         wR = pathway(F, [b2, ], B)
    182     return wL + wR
    183 

/home/mi/gph82/miniconda3/lib/python3.4/site-packages/msmtools-1.2+3.ge6a7a93-py3.4-linux-x86_64.egg/msmtools/flux/sparse/pathways.py in pathway(F, A, B)
    171                             "obtained from a reversible transition meatrix."))
    172     else:
--> 173         wL = pathway(F, A, [b1, ])
    174     if np.any(B == b2):
    175         wR = [b2, ]

/home/mi/gph82/miniconda3/lib/python3.4/site-packages/msmtools-1.2+3.ge6a7a93-py3.4-linux-x86_64.egg/msmtools/flux/sparse/pathways.py in pathway(F, A, B)
    171                             "obtained from a reversible transition meatrix."))
    172     else:
--> 173         wL = pathway(F, A, [b1, ])
    174     if np.any(B == b2):
    175         wR = [b2, ]

/home/mi/gph82/miniconda3/lib/python3.4/site-packages/msmtools-1.2+3.ge6a7a93-py3.4-linux-x86_64.egg/msmtools/flux/sparse/pathways.py in pathway(F, A, B)
    171                             "obtained from a reversible transition meatrix."))
    172     else:
--> 173         wL = pathway(F, A, [b1, ])
    174     if np.any(B == b2):
    175         wR = [b2, ]

/home/mi/gph82/miniconda3/lib/python3.4/site-packages/msmtools-1.2+3.ge6a7a93-py3.4-linux-x86_64.egg/msmtools/flux/sparse/pathways.py in pathway(F, A, B)
    171                             "obtained from a reversible transition meatrix."))
    172     else:
--> 173         wL = pathway(F, A, [b1, ])
    174     if np.any(B == b2):
    175         wR = [b2, ]

/home/mi/gph82/miniconda3/lib/python3.4/site-packages/msmtools-1.2+3.ge6a7a93-py3.4-linux-x86_64.egg/msmtools/flux/sparse/pathways.py in pathway(F, A, B)
    163 
    164     """
--> 165     b1, b2, F = find_bottleneck(F, A, B)
    166     if np.any(A == b1):
    167         wL = [b1, ]

/home/mi/gph82/miniconda3/lib/python3.4/site-packages/msmtools-1.2+3.ge6a7a93-py3.4-linux-x86_64.egg/msmtools/flux/sparse/pathways.py in find_bottleneck(F, A, B)
     68 
     69     """Check if edge with largest conductivity connects A and B"""
---> 70     b = np.array(row[-1], col[-1])
     71     if has_path(b, A, B):
     72         return b

IndexError: index -1 is out of bounds for axis 0 with size 0