def showOverlapTable(rows, cols, **kwargs): """Show overlap table using :func:`~matplotlib.pyplot.pcolor`. *rows* and *cols* are sets of normal modes, and correspond to rows and columns of the displayed overlap matrix. Note that mode indices are incremented by 1. List of modes should contain a set of contiguous modes from the same model. Default arguments for :func:`~matplotlib.pyplot.pcolor`: * ``cmap=plt.cm.jet`` * ``norm=plt.normalize(0, 1)`` .. plot:: :context: :include-source: plt.figure(figsize=(5,4)) showOverlapTable( p38_pca[:6], p38_anm[:6] ) plt.title('p38 PCA vs ANM') .. plot:: :context: :nofigs: plt.close('all')""" import matplotlib.pyplot as plt overlap = abs(calcOverlap(rows, cols)) if isinstance(rows, NMA): rows = rows[:] if isinstance(cols, NMA): cols = cols[:] cmap = kwargs.pop('cmap', plt.cm.jet) norm = kwargs.pop('norm', plt.normalize(0, 1)) show = (plt.pcolor(overlap, cmap=cmap, norm=norm, **kwargs), plt.colorbar()) x_range = np.arange(1, len(cols)+1) plt.xticks(x_range-0.5, x_range) plt.xlabel(str(cols)) y_range = np.arange(1, len(rows)+1) plt.yticks(y_range-0.5, y_range) plt.ylabel(str(rows)) plt.axis([0, len(cols), 0, len(rows)]) return show
def showOverlapTable(rows, cols, *args, **kwargs): """Show overlap table using :func:`~matplotlib.pyplot.pcolor`. *rows* and *cols* are sets of normal modes, and correspond to rows and columns of the displayed matrix. Note that mode indices are increased by 1. List of modes should contain a set of contiguous modes from the same model. .. plot:: :context: :include-source: plt.figure(figsize=(5,4)) showOverlapTable( p38_pca[:6], p38_anm[:6] ) plt.title('p38 PCA vs ANM') .. plot:: :context: :nofigs: plt.close('all')""" import matplotlib.pyplot as plt if not isinstance(rows, (NMA, ModeSet)): raise TypeError('rows must be an NMA model or a ModeSet, not {0:s}' .format(type(rows))) if not isinstance(rows, (NMA, ModeSet)): raise TypeError('cols must be an NMA model or a ModeSet, not {0:s}' .format(type(cols))) overlap = abs(calcOverlap(rows, cols)) if isinstance(rows, NMA): rows = rows[:] if isinstance(cols, NMA): cols = cols[:] show = (plt.pcolor(overlap, cmap=plt.cm.jet, *args, **kwargs), plt.colorbar()) x_range = np.arange(1, len(cols)+1) plt.xticks(x_range-0.5, x_range) plt.xlabel(str(cols)) y_range = np.arange(1, len(rows)+1) plt.yticks(y_range-0.5, y_range) plt.ylabel(str(rows)) plt.axis([0, len(cols), 0, len(rows)]) return show
def showCumulOverlap(mode, modes, *args, **kwargs): """Show cumulative overlap using :func:`~matplotlib.pyplot.plot`. :type mode: :class:`~.Mode`, :class:`~.Vector` :arg modes: multiple modes :type modes: :class:`~.ModeSet`, :class:`~.ANM`, :class:`~.GNM`, :class:`~.PCA` .. plot:: :context: :include-source: plt.figure(figsize=(5,4)) showCumulOverlap( p38_pca[0], p38_anm ) # Let's also show the overlap showOverlap( p38_pca[0], p38_anm ) .. plot:: :context: :nofigs: plt.close('all')""" import matplotlib.pyplot as plt if not isinstance(mode, (Mode, Vector)): raise TypeError('mode must be NMA, ModeSet, Mode or Vector, not {0:s}' .format(type(mode))) if not isinstance(modes, (NMA, ModeSet)): raise TypeError('modes must be NMA, ModeSet, or Mode, not {0:s}' .format(type(modes))) cumov = (calcOverlap(mode, modes) ** 2).cumsum() ** 0.5 if isinstance(modes, NMA): arange = np.arange(0.5, len(modes)+0.5) else: arange = modes.getIndices() + 0.5 show = plt.plot(arange, cumov, *args, **kwargs) plt.title('Cumulative overlap with {0:s}'.format(str(mode))) plt.xlabel('{0:s} mode index'.format(modes)) plt.ylabel('Cumulative overlap') plt.axis((arange[0]-0.5, arange[-1]+0.5, 0, 1)) return show
def showOverlap(mode, modes, *args, **kwargs): """Show overlap :func:`~matplotlib.pyplot.bar`. :arg mode: a single mode/vector :type mode: :class:`~.Mode`, :class:`~.Vector` :arg modes: multiple modes :type modes: :class:`~.ModeSet`, :class:`~.ANM`, :class:`~.GNM`, :class:`~.PCA` .. plot:: :context: :include-source: plt.figure(figsize=(4,4)) showOverlap( p38_pca[0], p38_anm[:6] ) .. plot:: :context: :nofigs: plt.close('all')""" import matplotlib.pyplot as plt if not isinstance(mode, (Mode, Vector)): raise TypeError('mode must be Mode or Vector, not {0:s}' .format(type(mode))) if not isinstance(modes, (NMA, ModeSet)): raise TypeError('modes must be NMA or ModeSet, not {0:s}' .format(type(modes))) overlap = abs(calcOverlap(mode, modes)) if isinstance(modes, NMA): arange = np.arange(0.5, len(modes)+0.5) else: arange = modes.getIndices() + 0.5 show = plt.bar(arange, overlap, *args, **kwargs) plt.title('Overlap with {0:s}'.format(str(mode))) plt.xlabel('{0:s} mode index'.format(modes)) plt.ylabel('Overlap') return show
def showCrossProjection(ensemble, mode_x, mode_y, scale=None, scalar=None, *args, **kwargs): """Show a projection of conformational deviations onto modes from different models using :func:`~matplotlib.pyplot.plot`. This function differs from :func:`showProjection` by accepting modes from two different models. :arg ensemble: Ensemble for which deviations will be projected :type ensemble: :class:`~prody.ensemble.Ensemble` :arg mode_x: Projection onto this mode will be shown along x-axis. :type mode_x: :class:`Mode` :arg mode_y: Projection onto this mode will be shown along y-axis. :type mode_y: :class:`Mode` :arg scale: Scale width of the projection onto one of modes. ``x`` and ``y`` are accepted. :type scale: str :arg scalar: Scalar factor for ``x`` or ``y``. If ``scalar=None`` is passed, best scaling factor will be calculated and printed on the console. :type scalar: float The projected values are by default converted to RMSD. Pass ``rmsd=False`` to calculate raw projection values. :class:`Vector` instances are accepted as *ensemble* argument to allow for projecting a deformation vector onto normal modes. By default ``marker='o', ls='None'`` is passed to the plotting function to disable lines. .. plot:: :context: :include-source: plt.figure(figsize=(5.2,4)) showCrossProjection(p38_ensemble, p38_pca[0], p38_anm[2]) .. plot:: :context: :nofigs: plt.close('all') |example| See :ref:`pca-xray-plotting` for a more elaborate example.""" import matplotlib.pyplot as plt if not isinstance(ensemble, (Ensemble, Conformation, Vector)): raise TypeError('ensemble must be Ensemble, Conformation, or Vector, ' 'not {0:s}'.format(type(ensemble))) if not isinstance(mode_x, VectorBase): raise TypeError('mode_x must be a Mode instance, not {0:s}' .format(type(mode_x))) if not mode_x.is3d(): raise ValueError('mode_x must be 3-dimensional') if not isinstance(mode_y, VectorBase): raise TypeError('mode_y must be a Mode instance, not {0:s}' .format(type(mode_y))) if not mode_y.is3d(): raise ValueError('mode_y must be 3-dimensional') if scale is not None: assert isinstance(scale, str), 'scale must be a string' scale = scale.lower() assert scale in ('x', 'y'), 'scale must be x or y' if scalar is not None: assert isinstance(scalar, float), 'scalar must be a float' xcoords = calcProjection(ensemble, mode_x, kwargs.get('rmsd', True)) ycoords = calcProjection(ensemble, mode_y, kwargs.pop('rmsd', True)) if scale: if scalar is None: scalar = ((ycoords.max() - ycoords.min()) / (xcoords.max() - xcoords.min())) scalar = scalar * np.sign(calcOverlap(mode_x, mode_y)) if scale == 'x': LOGGER.info('Projection onto {0:s} is scaled by {1:.2f}' .format(mode_x, scalar)) else: scalar = 1 / scalar LOGGER.info('Projection onto {0:s} is scaled by {1:.2f}' .format(mode_y, scalar)) if scale == 'x': xcoords = xcoords * scalar else: ycoords = ycoords * scalar if 'ls' not in kwargs: kwargs['ls'] = 'None' if 'marker' not in kwargs: kwargs['marker'] = 'o' show = plt.plot(xcoords, ycoords, *args, **kwargs) plt.xlabel('{0:s} coordinate'.format(mode_x)) plt.ylabel('{0:s} coordinate'.format(mode_y)) return show