Example #1
0
 def _reset(self):
     
     NMA._reset(self)
     self._cutoff = None
     self._gamma = None
     self._kirchhoff = None
     self._is3d = False
Example #2
0
 def __init__(self, name='Unknown'):
     
     NMA.__init__(self, name)
     self._is3d = False
     self._cutoff = None
     self._kirchhoff = None
     self._gamma = None
Example #3
0
    def addEigenpair(self, eigenvector, eigenvalue=None):
        """Add *eigenvector* and *eigenvalue* pair to :class:`NMA` instance.
        If *eigenvalue* is not given, it will be set to 1.  Eigenvalue is also 
        set as the variance."""

        NMA.addEigenpair(self, eigenvector, eigenvalue)
        self._vars = self._eigvals.copy()
Example #4
0
 def setEigens(self, vectors, values=None):
     """Set eigenvectors and eigenvalues.
     
     :arg vectors: eigenvectors
     :type vectors: numpy.ndarray
     
     :arg values: Eigenvalues. When ``None`` is passed (default value), 
         all eigenvalues will be set to ``1``.
     :type values: numpy.ndarray
     
     For M modes and N atoms, *vectors* must have shape ``(3*N, M)``
     and values must have shape ``(M,)``.  Eigenvalues are also set as the 
     variances."""
     
     NMA.setEigens(self, vectors, values)
     self._vars = self._eigvals.copy()
Example #5
0
def extendModel(model, nodes, atoms):
    """Extend a coarse grained *model* built for *nodes* to *atoms*.  *model*
    may be :class:`~.ANM`, :class:`~.GNM`, :class:`~.PCA`, or :class:`~.NMA` 
    instance.  This will take part of the normal modes for each node (i.e. Cα 
    atoms) and extend it to all other atoms in the same residue.  For each atom
    in *nodes* argument *atoms* argument must contain a corresponding residue.  
    Note that modes in the extended model will not be normalized.  For a usage
    example see :ref:`extendmodel`."""
    
    if not isinstance(model, NMA):
        raise TypeError('model must be an NMA instance')
    if not isinstance(nodes, Atomic):
        raise TypeError('nodes must be an Atomic instance')
    if model.numAtoms() != nodes.numAtoms():
        raise ValueError('model and nodes must have same number of atoms')
    
    if isinstance(atoms, Atomic):
        is3d = model.is3d()            
        atom_indices = []
        indices = []
        hierview = atoms.getHierView()
        for i, node in enumerate(nodes):
            res = hierview[node.getChid(), node.getResnum(), node.getIcode()]
            if res is None:
                raise ValueError('hierview must contain a residue for all atoms')
            atom_indices.append(res.getIndices())
            if is3d:
                indices.append(range(i*3, (i+1)*3) * len(res))
            else:
                indices.append([i] * len(res))
        atom_indices = np.concatenate(atom_indices)
        indices = np.concatenate(indices)
        
        array = model.getArray()[indices,:]
        extended = NMA('Extended ' + str(model))
        extended.setEigens(array, model.getEigvals())
        if isinstance(atoms, AtomGroup):
            ag = atoms
        else: 
            ag = atoms.getAtomGroup()
        atommap = AtomMap(ag, atom_indices, np.arange(len(atom_indices)), 
                          np.array([]), str(atoms), atoms.getACSIndex())
        return extended, atommap
    else:
        raise TypeError('atoms must be an Atomic instance')
Example #6
0
def extrapolateModel(enm, nodes, atoms):
    """Extrapolate *enm* built for *nodes* to *atoms*.
    
    This function is designed for extrapolating an NMA model built at coarse 
    grained level to all atom level.  For each atom in *nodes* argument *atoms* 
    argument must contain a corresponding residue.  Note that modes in the 
    extrapolated model will not be normalized.  For a usage example see 
    :ref:`extrapolate`."""

    if not isinstance(enm, NMA):
        raise TypeError("enm must be an NMA instance")
    if not isinstance(nodes, Atomic):
        raise TypeError("nodes must be an Atomic instance")
    if enm.numAtoms() != nodes.numAtoms():
        raise ValueError("enm and nodes must have same number of atoms")

    if isinstance(atoms, Atomic):
        is3d = enm.is3d()
        atom_indices = []
        indices = []
        hierview = atoms.getHierView()
        for i, node in enumerate(nodes):
            res = hierview[node.getChid(), node.getResnum(), node.getIcode()]
            if res is None:
                raise ValueError("hierview must contain a residue for all atoms")
            atom_indices.append(res.getIndices())
            if is3d:
                indices.append(range(i * 3, (i + 1) * 3) * len(res))
            else:
                indices.append([i] * len(res))
        atom_indices = np.concatenate(atom_indices)
        indices = np.concatenate(indices)

        array = enm.getArray()[indices, :]
        extra = NMA("Extrapolated " + str(enm))
        extra.setEigens(array, enm.getEigenvalues())
        if isinstance(atoms, AtomGroup):
            ag = atoms
        else:
            ag = atoms.getAtomGroup()
        atommap = AtomMap(ag, atom_indices, np.arange(len(atom_indices)), np.array([]), str(atoms), atoms.getACSIndex())
        return extra, atommap
    else:
        raise TypeError("atoms must be an Atomic instance")
Example #7
0
def parseModes(normalmodes, eigenvalues=None, nm_delimiter=None, 
               nm_skiprows=0, nm_usecols=None, ev_delimiter=None, 
               ev_skiprows=0, ev_usecols=None, ev_usevalues=None):
    """Return :class:`~.NMA` instance with normal modes parsed from 
    *normalmodes*.
    
    In normal mode file *normalmodes*, columns must correspond to modes 
    (eigenvectors).  Optionally, *eigenvalues* can be parsed from a separate 
    file. If eigenvalues are not provided, they will all be set to 1.
    
    :arg normalmodes: File or filename that contains normal modes. 
        If the filename extension is :file:`.gz` or :file:`.bz2`, the file is 
        first decompressed.
    :type normalmodes: str or file
    
    :arg eigenvalues: Optional, file or filename that contains eigenvalues. 
        If the filename extension is :file:`.gz` or :file:`.bz2`, 
        the file is first decompressed.
    :type eigenvalues: str or file

    :arg nm_delimiter: The string used to separate values in *normalmodes*. 
        By default, this is any whitespace.
    :type nm_delimiter: str

    :arg nm_skiprows: Skip the first *skiprows* lines in *normalmodes*. 
        Default is ``0``.
    :type nm_skiprows: 0

    :arg nm_usecols: Which columns to read from *normalmodes*, with 0 being the 
        first. For example, ``usecols = (1,4,5)`` will extract the 2nd, 5th and 
        6th columns. The default, ``None``, results in all columns being read.
    :type nm_usecols: list

    :arg ev_delimiter: The string used to separate values in *eigenvalues*. 
        By default, this is any whitespace.
    :type ev_delimiter: str

    :arg ev_skiprows: Skip the first *skiprows* lines in *eigenvalues*. 
        Default is ``0``.
    :type ev_skiprows: 0

    :arg ev_usecols: Which columns to read from *eigenvalues*, with 0 being the 
        first. For example, ``usecols = (1,4,5)`` will extract the 2nd, 5th and 
        6th columns. The default, ``None``, results in all columns being read.
    :type ev_usecols: list

    :arg ev_usevalues: Which columns to use after the eigenvalue column is
        parsed from *eigenvalues*, with 0 being the first. 
        This can be used if *eigenvalues* contains more values than the
        number of modes in *normalmodes*.
    :type ev_usevalues: list
    
    See :func:`parseArray` for details of parsing arrays from files."""
    
    modes = parseArray(normalmodes, delimiter=nm_delimiter, 
                       skiprows=nm_skiprows, usecols=nm_usecols)
    if eigenvalues is not None:
        values = parseArray(eigenvalues, delimiter=ev_delimiter, 
                            skiprows=ev_skiprows, usecols=ev_usecols)
        values = values.flatten()
        if ev_usevalues is not None:
            values = values[ev_usevalues]
    nma = NMA(os.path.splitext(os.path.split(normalmodes)[1])[0])
    nma.setEigens(modes, values)
    return nma
Example #8
0
 def __init__(self, name='Unknown'):
     NMA.__init__(self, name)