예제 #1
0
파일: kinetics.py 프로젝트: yulanl22/htmd
    def plotFluxPathways(self,
                         statetype='macro',
                         mode='net_flux',
                         fraction=1.0):
        """ Plot flux pathways between source and sink state.

        The flux is in units of transition events per lag time used to construct the Markov model.

        Parameters
        ----------
        statetype : {'macro','coarse','micro'}
            What type of states to plot
        mode : {'net_flux', 'gross_flux'}
            Type of fluxes to plot
        fraction : float
            Fraction of fluxes for which to report pathways. Doesn't change the plot, only the text output.
        """
        # Make mode a radio button with interactive plot
        from pyemma import msm
        from pyemma.plots import plot_flux
        from matplotlib import pylab as plt
        self._intergrityCheck()

        plt.figure()
        if statetype == 'micro':
            tpt = msm.tpt(self.model.msm, [self.sourcemicro], [self.sinkmicro])
            fig, pos = plot_flux(tpt, attribute_to_plot=mode)
        elif statetype == 'macro' or statetype == 'coarse':
            metastable_sets = []
            for i in range(self.model.macronum):
                metastable_sets.append(
                    np.where(self.model.macro_ofmicro == i)[0])
            tpt = msm.tpt(self.model.msm, metastable_sets[self.source],
                          metastable_sets[self.sink])
            #from IPython.core.debugger import Tracer
            #Tracer()()
            newsets, tpt = tpt.coarse_grain(metastable_sets)
            setmap = []
            # getting the mapping of new sets to old sets
            for set1 in newsets:
                for idx2, set2 in enumerate(metastable_sets):
                    if set(set1) == set(set2):
                        setmap.append(idx2)
                        continue
            setmap = np.array(setmap)
            fig, pos = plot_flux(tpt,
                                 attribute_to_plot=mode,
                                 state_labels=setmap)
        fig.show()

        paths, pathfluxes = tpt.pathways(fraction=fraction)
        cumflux = 0
        print("Path flux\t\t%path\t%of total\tpath")
        for i in range(len(paths)):
            cumflux += pathfluxes[i]
            print('{}\t{:3.1f}%\t{:3.1f}%\t\t{}'.format(
                pathfluxes[i], 100.0 * pathfluxes[i] / tpt.total_flux,
                100.0 * cumflux / tpt.total_flux, setmap[paths[i]]))
예제 #2
0
    def fluxPathways(self):
        import pyemma.plots as mplt
        import pyemma.msm as msm
        import matplotlib.pylab as plt
        self._intergrityCheck()

        plt.ion()
        tpt = msm.tpt(self.model.coarsemsm, [self.source], [self.sink])
        mplt.plot_flux(tpt[1], show_committor=False)
        plt.show()
예제 #3
0
파일: kinetics.py 프로젝트: jeiros/htmd
    def plotFluxPathways(self, statetype='macro', mode='net_flux', fraction=1.0):
        """ Plot flux pathways between source and sink state.

        Parameters
        ----------
        statetype : {'macro','coarse','micro'}
            What type of states to plot
        mode : {'net_flux', 'gross_flux'}
            Type of fluxes to plot
        fraction : float
            Fraction of fluxes for which to report pathways. Doesn't change the plot, only the text output.
        """
        # Make mode a radio button with interactive plot
        from pyemma import msm
        from pyemma.plots import plot_flux
        from matplotlib import pylab as plt
        self._intergrityCheck()

        plt.figure()
        if statetype == 'micro':
            tpt = msm.tpt(self.model.msm, [self.sourcemicro], [self.sinkmicro])
            fig, pos = plot_flux(tpt, attribute_to_plot=mode)
        elif statetype == 'macro' or statetype == 'coarse':
            metastable_sets = []
            for i in range(self.model.macronum):
                metastable_sets.append(np.where(self.model.macro_ofmicro == i)[0])
            tpt = msm.tpt(self.model.msm, metastable_sets[self.source], metastable_sets[self.sink])
            #from IPython.core.debugger import Tracer
            #Tracer()()
            newsets, tpt = tpt.coarse_grain(metastable_sets)
            setmap = []
            # getting the mapping of new sets to old sets
            for set1 in newsets:
                for idx2, set2 in enumerate(metastable_sets):
                    if set(set1) == set(set2):
                        setmap.append(idx2)
                        continue
            setmap = np.array(setmap)
            fig, pos = plot_flux(tpt, attribute_to_plot=mode, state_labels=setmap)
        fig.show()

        paths, pathfluxes = tpt.pathways(fraction=fraction)
        cumflux = 0
        print("Path flux\t\t%path\t%of total\tpath")
        for i in range(len(paths)):
            cumflux += pathfluxes[i]
            print('{}\t{:3.1f}%\t{:3.1f}%\t\t{}'.format(
                    pathfluxes[i], 100.0*pathfluxes[i]/tpt.total_flux,
                    100.0*cumflux/tpt.total_flux, setmap[paths[i]]))
예제 #4
0
B = [4]
tpt = msm.tpt(M, A, B)

# get tpt gross flux
F = tpt.gross_flux
print('**Flux matrix**:')
print(F)
print('**forward committor**:')
print(tpt.committor)
print('**backward committor**:')
print(tpt.backward_committor)
# we position states along the y-axis according to the commitor
tptpos = np.array([tpt.committor, [0, 0, 0.5, -0.5, 0]]).transpose()
print('\n**Gross flux illustration**: ')
pl = mplt.plot_flux(tpt,
                    pos=tptpos,
                    arrow_label_format="%10.4f",
                    attribute_to_plot='gross_flux')
"""Note that in the gross flux above we had fluxes between states 1 and 3.
 These fluxes just represent that some reactive trajectories leave 1, go to 3, 
 go then back to 1 and then go on to the target state 4 directly or via state 2.
  This detour via state 3 is usually of no interest, and their contribution is 
  already contained in the main paths 0->1 and 1->{2,4}. Therefore we remove all n
  onproductive recrossings by taking the difference flux between pairs of states that 
  have fluxes in both directions. This gives us the net flux."""

# get tpt net flux
Fp = tpt.net_flux
# or: tpt.flux (it's the same!)
print('**Net-Flux matrix**:')
print(Fp)
# visualize
예제 #5
0
    def plotFluxPathways(
        self, statetype="macro", mode="net_flux", fraction=1.0, plot=True, save=None
    ):
        """Plot flux pathways between source and sink state.

        The flux is in units of transition events per lag time used to construct the Markov model.

        Parameters
        ----------
        statetype : {'macro','coarse','micro'}
            What type of states to plot
        mode : {'net_flux', 'gross_flux'}
            Type of fluxes to plot
        fraction : float
            Fraction of fluxes for which to report pathways. Doesn't change the plot, only the text output.
        plot : bool
            If set it False the plot will not show up in a figure
        save : str
            If a path is passed to save, the plot will be saved to the specified file
        """
        # Make mode a radio button with interactive plot
        from pyemma import msm
        from pyemma.plots import plot_flux
        from matplotlib import pylab as plt

        self._intergrityCheck()

        plt.figure()
        if statetype == "micro":
            tpt = msm.tpt(self.model.msm, [self.sourcemicro], [self.sinkmicro])
            fig, pos = plot_flux(tpt, attribute_to_plot=mode)
        elif statetype == "macro" or statetype == "coarse":
            metastable_sets = []
            for i in range(self.model.macronum):
                metastable_sets.append(np.where(self.model.macro_ofmicro == i)[0])
            tpt = msm.tpt(
                self.model.msm, metastable_sets[self.source], metastable_sets[self.sink]
            )
            newsets, tpt = tpt.coarse_grain(metastable_sets)
            setmap = []
            # getting the mapping of new sets to old sets
            for set1 in newsets:
                for idx2, set2 in enumerate(metastable_sets):
                    if set(set1) == set(set2):
                        setmap.append(idx2)
                        continue
            setmap = np.array(setmap)
            fig, pos = plot_flux(tpt, attribute_to_plot=mode, state_labels=setmap)

        if save is not None:
            fig.savefig(save, dpi=300, bbox_inches="tight", pad_inches=0.2)
        if plot:
            fig.show()

        paths, pathfluxes = tpt.pathways(fraction=fraction)
        cumflux = 0
        print("Path flux\t\t%path\t%of total\tpath")
        for i in range(len(paths)):
            cumflux += pathfluxes[i]
            print(
                "{}\t{:3.1f}%\t{:3.1f}%\t\t{}".format(
                    pathfluxes[i],
                    100.0 * pathfluxes[i] / tpt.total_flux,
                    100.0 * cumflux / tpt.total_flux,
                    setmap[paths[i]],
                )
            )
예제 #6
0
파일: tpt.py 프로젝트: cescgina/msm_pele
def plotTPT(TPT_object, state_labels='auto', outfile=None):
    """ Plot the flux network from a Reactive Flux object"""
    flux_figure = mplt.plot_flux(TPT_object, state_labels=state_labels)
    if not outfile is None:
        flux_figure.savefig(outfile)
    return flux_figure