Source code for schrodinger.trajectory.prody.modeset
# -*- coding: utf-8 -*-
#
# ProDy: A Python Package for Protein Dynamics Analysis
#
# Copyright (C) 2010-2014 University of Pittsburgh
#
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the "Software"),
# to deal in the Software without restriction, including without limitation
# the rights to use, copy, modify, merge, publish, distribute, sublicense,
# and/or sell copies of the Software, and to permit persons to whom the
# Software is furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
# DEALINGS IN THE SOFTWARE.
#
"""This module defines a pointer class for handling subsets of normal modes."""
from numpy import array
__all__ = ['ModeSet']
[docs]class ModeSet(object):
    """A class for providing access to subset of mode data.  Instances
    are obtained by slicing an NMA model (:class: `.ANM`, :class: `.GNM`, or
    :class: `.PCA`).  ModeSet's contain a reference to the model and a list
    of mode indices.  Methods common to NMA models are also defined for
    mode sets."""
    __slots__ = ['_model', '_indices']
[docs]    def __init__(self, model, indices):
        self._model = model
        self._indices = array(indices, int) 
[docs]    def __len__(self):
        return len(self._indices) 
    def __iter__(self):
        for i in self._indices:
            yield self._model[i]
    def __repr__(self):
        return '<ModeSet: {0} modes from {1}>'.format(len(self),
                                                      str(self._model))
    def __str__(self):
        return '{0} modes from {1}'.format(len(self._indices), str(self._model))
[docs]    def is3d(self):
        """Return **True** is model is 3-dimensional."""
        return self._model._is3d 
[docs]    def numAtoms(self):
        """Return number of atoms."""
        return self._model._n_atoms 
[docs]    def numModes(self):
        """Return number of modes in the instance (not necessarily maximum
        number of possible modes)."""
        return len(self._indices) 
[docs]    def numDOF(self):
        """Return number of degrees of freedom."""
        return self._model._dof 
[docs]    def getTitle(self):
        """Return title of the mode set."""
        return str(self) 
[docs]    def getModel(self):
        """Return the model that the modes belongs to."""
        return self._model 
[docs]    def getIndices(self):
        """Return indices of modes in the mode set."""
        return self._indices 
[docs]    def getEigvals(self):
        """Return eigenvalues.  For :class: `.PCA` and :class: `.EDA` models
        built using coordinate data in Å, unit of eigenvalues is `|A2|`.  For
        :class: `.ANM` and :class: `.GNM`, on the other hand, eigenvalues are
        in arbitrary or relative units but they correlate with stiffness of
        the motion along associated eigenvector."""
        return self._model._eigvals[self._indices] 
[docs]    def getVariances(self):
        """Return variances.  For :class: `.PCA` and :class: `.EDA` models
        built using coordinate data in Å, unit of variance is `|A2|`.  For
        :class: `.ANM` and :class: `.GNM`, on the other hand, variance is the
        inverse of the eigenvalue, so it has arbitrary or relative units."""
        return self._model._vars[self._indices] 
[docs]    def getArray(self):
        """Return a copy of eigenvectors array."""
        return self._model._array[:, self._indices] 
    getEigvecs = getArray
    def _getArray(self):
        """Return eigenvectors array."""
        return self._model._array[:, self._indices]