def sliceVector(vector, atoms, selstr): """Return a slice of *vector* matching *atoms* specified by *selstr*. Note that returned :class:`Vector` instance is not normalized. :arg vector: vector instance to be sliced :type vector: :class:`VectorBase` :arg atoms: atoms for which *vector* describes a deformation, motion, etc. :type atoms: :class:`~prody.atomic.Atomic` :arg selstr: selection string :type selstr: str :returns: (:class:`Vector`, :class:`~prody.atomic.Selection`)""" if not isinstance(vector, VectorBase): raise TypeError("vector must be a VectorBase instance, not {0:s}".format(type(vector))) if not isinstance(atoms, Atomic): raise TypeError("atoms must be an Atomic instance, not {0:s}".format(type(atoms))) if atoms.numAtoms() != vector.numAtoms(): raise ValueError("number of atoms in *vector* and *atoms* must be " "equal") if isinstance(atoms, AtomGroup): sel = atoms.select(selstr) which = sel.getIndices() else: which = SELECT.getIndices(atoms, selstr) sel = Selection(atoms.getAtomGroup(), atoms.getIndices()[which], selstr, atoms.getACSIndex()) vec = Vector( vector.getArrayNx3()[which, :].flatten(), '{0:s} slice "{1:s}"'.format(str(vector), selstr), vector.is3d() ) return (vec, sel)
def sliceVector(vector, atoms, select): """Return part of the *vector* for *atoms* matching *select*. Note that returned :class:`.Vector` instance is not normalized. :arg vector: vector instance to be sliced :type vector: :class:`.VectorBase` :arg atoms: atoms for which *vector* describes a deformation, motion, etc. :type atoms: :class:`.Atomic` :arg select: an atom selection or a selection string :type select: :class:`.Selection`, str :returns: (:class:`.Vector`, :class:`.Selection`)""" if not isinstance(vector, VectorBase): raise TypeError('vector must be a VectorBase instance, not {0:s}' .format(type(vector))) if not isinstance(atoms, Atomic): raise TypeError('atoms must be an Atomic instance, not {0:s}' .format(type(atoms))) if atoms.numAtoms() != vector.numAtoms(): raise ValueError('number of atoms in model and atoms must be equal') if isinstance(select, str): selstr = select if isinstance(atoms, AtomGroup): sel = atoms.select(selstr) which = sel._getIndices() else: which = SELECT.getIndices(atoms, selstr) sel = Selection(atoms.getAtomGroup(), atoms.getIndices()[which], selstr, atoms.getACSIndex()) elif isinstance(select, AtomSubset): sel = select if isinstance(atoms, AtomGroup): if sel.getAtomGroup() != atoms: raise ValueError('select and atoms do not match') which = sel._getIndices() else: if atoms.getAtomGroup() != sel.getAtomGroup(): raise ValueError('select and atoms do not match') elif not sel in atoms: raise ValueError('select is not a subset of atoms') idxset = set(atoms._getIndices()) which = np.array([idx in idxset for idx in sel._getIndices()]) which = which.nonzero()[0] selstr = sel.getSelstr() else: raise TypeError('select must be a string or a Selection instance') vec = Vector(vector.getArrayNx3()[ which, :].flatten(), '{0:s} slice {1:s}'.format(str(vector), repr(selstr)), vector.is3d()) return (vec, sel)
def sliceVector(vector, atoms, select): """Return part of the *vector* for *atoms* matching *select*. Note that returned :class:`.Vector` instance is not normalized. :arg vector: vector instance to be sliced :type vector: :class:`.VectorBase` :arg atoms: atoms for which *vector* describes a deformation, motion, etc. :type atoms: :class:`.Atomic` :arg select: an atom selection or a selection string :type select: :class:`.Selection`, str :returns: (:class:`.Vector`, :class:`.Selection`)""" if not isinstance(vector, VectorBase): raise TypeError('vector must be a VectorBase instance, not {0}' .format(type(vector))) if not isinstance(atoms, Atomic): raise TypeError('atoms must be an Atomic instance, not {0}' .format(type(atoms))) if atoms.numAtoms() != vector.numAtoms(): raise ValueError('number of atoms in model and atoms must be equal') if isinstance(select, str): selstr = select if isinstance(atoms, AtomGroup): sel = atoms.select(selstr) which = sel._getIndices() else: which = SELECT.getIndices(atoms, selstr) sel = Selection(atoms.getAtomGroup(), atoms.getIndices()[which], selstr, atoms.getACSIndex()) elif isinstance(select, AtomSubset): sel = select if isinstance(atoms, AtomGroup): if sel.getAtomGroup() != atoms: raise ValueError('select and atoms do not match') which = sel._getIndices() else: if atoms.getAtomGroup() != sel.getAtomGroup(): raise ValueError('select and atoms do not match') elif not sel in atoms: raise ValueError('select is not a subset of atoms') idxset = set(atoms._getIndices()) which = np.array([idx in idxset for idx in sel._getIndices()]) which = which.nonzero()[0] selstr = sel.getSelstr() else: raise TypeError('select must be a string or a Selection instance') vec = Vector(vector.getArrayNx3()[ which, :].flatten(), '{0} slice {1}'.format(str(vector), repr(selstr)), vector.is3d()) return (vec, sel)
def sliceModel(model, atoms, selstr): """Return a slice of *model* matching *atoms* specified by *selstr*. Note that sliced normal modes (eigenvectors) are not normalized. :arg mode: NMA model instance to be sliced :type mode: :class:`NMA` :arg atoms: atoms for which the *model* was built :type atoms: :class:`~prody.atomic.Atomic` :arg selstr: selection string :type selstr: str :returns: (:class:`NMA`, :class:`~prody.atomic.Selection`)""" if not isinstance(model, NMA): raise TypeError("mode must be a NMA instance, not {0:s}".format(type(model))) if not isinstance(atoms, Atomic): raise TypeError("atoms must be an Atomic instance, not {0:s}".format(type(atoms))) if atoms.numAtoms() != model.numAtoms(): raise ValueError("number of atoms in *model* and *atoms* must be " "equal") array = model._getArray() if isinstance(atoms, AtomGroup): sel = atoms.select(selstr) which = sel.getIndices() else: which = SELECT.getIndices(atoms, selstr) sel = Selection(atoms.getAtomGroup(), atoms.getIndices()[which], selstr, atoms.getACSIndex()) nma = type(model)('{0:s} slice "{1:s}"'.format(model.getTitle(), selstr)) if model.is3d(): which = [which.reshape((len(which), 1)) * 3] which.append(which[0] + 1) which.append(which[0] + 2) which = np.concatenate(which, 1).flatten() nma.setEigens(array[which, :], model.getEigenvalues()) return (nma, sel)
def sliceMode(mode, atoms, selstr): """Return a slice of *mode* matching *atoms* specified by *selstr*. This works slightly difference from :func:`sliceVector`. Mode array (eigenvector) is multiplied by square-root of the variance along the mode. If mode is from an elastic network model, variance is defined as the inverse of the eigenvalue. Note that returned :class:`Vector` instance is not normalized. :arg mode: mode instance to be sliced :type mode: :class:`Mode` :arg atoms: atoms for which *mode* describes a deformation, motion, etc. :type atoms: :class:`~prody.atomic.Atomic` :arg selstr: selection string :type selstr: str :returns: (:class:`Vector`, :class:`~prody.atomic.Selection`)""" if not isinstance(mode, Mode): raise TypeError("mode must be a Mode instance, not {0:s}".format(type(mode))) if not isinstance(atoms, Atomic): raise TypeError("atoms must be an Atomic instance, not {0:s}".format(type(atoms))) if atoms.numAtoms() != mode.numAtoms(): raise ValueError("number of atoms in *mode* and *atoms* must be equal") if isinstance(atoms, AtomGroup): sel = atoms.select(selstr) which = sel.getIndices() else: which = SELECT.getIndices(atoms, selstr) sel = Selection(atoms.getAtomGroup(), atoms.getIndices()[which], selstr, atoms.getACSIndex()) vec = Vector( mode.getArrayNx3()[which, :].flatten() * mode.getVariance() ** 0.5, '{0:s} slice "{1:s}"'.format(str(mode), selstr), mode.is3d(), ) return (vec, sel)
def sliceModel(model, atoms, select): """Return a part of the *model* for *atoms* matching *select*. Note that normal modes (eigenvectors) are not normalized. :arg mode: NMA model instance to be sliced :type mode: :class:`.NMA` :arg atoms: atoms for which the *model* was built :type atoms: :class:`.Atomic` :arg select: an atom selection or a selection string :type select: :class:`.Selection`, str :returns: (:class:`.NMA`, :class:`.Selection`)""" if not isinstance(model, NMA): raise TypeError('mode must be a NMA instance, not {0:s}' .format(type(model))) if not isinstance(atoms, Atomic): raise TypeError('atoms must be an Atomic instance, not {0:s}' .format(type(atoms))) if atoms.numAtoms() != model.numAtoms(): raise ValueError('number of atoms in model and atoms must be equal') array = model._getArray() if isinstance(select, str): selstr = select if isinstance(atoms, AtomGroup): sel = atoms.select(selstr) which = sel.getIndices() else: which = SELECT.getIndices(atoms, selstr) sel = Selection(atoms.getAtomGroup(), atoms.getIndices()[which], selstr, atoms.getACSIndex()) elif isinstance(select, AtomSubset): sel = select if isinstance(atoms, AtomGroup): if sel.getAtomGroup() != atoms: raise ValueError('select and atoms do not match') which = sel._getIndices() else: if atoms.getAtomGroup() != sel.getAtomGroup(): raise ValueError('select and atoms do not match') elif not sel in atoms: raise ValueError('select is not a subset of atoms') idxset = set(atoms._getIndices()) which = np.array([idx in idxset for idx in sel._getIndices()]) which = which.nonzero()[0] selstr = sel.getSelstr() else: raise TypeError('select must be a string or a Selection instance') nma = type(model)('{0:s} slice {1:s}' .format(model.getTitle(), repr(selstr))) if model.is3d(): which = [which.reshape((len(which),1))*3] which.append(which[0]+1) which.append(which[0]+2) which = np.concatenate(which, 1).flatten() nma.setEigens( array[which, :], model.getEigvals() ) return (nma, sel)
def sliceMode(mode, atoms, select): """Return part of the *mode* for *atoms* matching *select*. This works slightly different from :func:`.sliceVector`. Mode array (eigenvector) is multiplied by square-root of the variance along the mode. If mode is from an elastic network model, variance is defined as the inverse of the eigenvalue. Note that returned :class:`~.Vector` instance is not normalized. :arg mode: mode instance to be sliced :type mode: :class:`.Mode` :arg atoms: atoms for which *mode* describes a deformation, motion, etc. :type atoms: :class:`.Atomic` :arg select: an atom selection or a selection string :type select: :class:`.Selection`, str :returns: (:class:`~.Vector`, :class:`~.Selection`)""" if not isinstance(mode, Mode): raise TypeError('mode must be a Mode instance, not {0:s}' .format(type(mode))) if not isinstance(atoms, Atomic): raise TypeError('atoms must be an Atomic instance, not {0:s}' .format(type(atoms))) if atoms.numAtoms() != mode.numAtoms(): raise ValueError('number of atoms in model and atoms must be equal') if isinstance(select, str): selstr = select if isinstance(atoms, AtomGroup): sel = atoms.select(selstr) which = sel._getIndices() else: which = SELECT.getIndices(atoms, selstr) sel = Selection(atoms.getAtomGroup(), atoms.getIndices()[which], selstr, atoms.getACSIndex()) elif isinstance(select, AtomSubset): sel = select if isinstance(atoms, AtomGroup): if sel.getAtomGroup() != atoms: raise ValueError('select and atoms do not match') which = sel._getIndices() else: if atoms.getAtomGroup() != sel.getAtomGroup(): raise ValueError('select and atoms do not match') elif not sel in atoms: raise ValueError('select is not a subset of atoms') idxset = set(atoms._getIndices()) which = np.array([idx in idxset for idx in sel._getIndices()]) which = which.nonzero()[0] selstr = sel.getSelstr() else: raise TypeError('select must be a string or a Selection instance') vec = Vector(mode.getArrayNx3()[ which,:].flatten() * mode.getVariance()**0.5, '{0:s} slice {1:s}'.format(str(mode), repr(selstr)), mode.is3d()) return (vec, sel)
def sliceModel(model, atoms, select): """Return a part of the *model* for *atoms* matching *select*. Note that normal modes (eigenvectors) are not normalized. :arg mode: NMA model instance to be sliced :type mode: :class:`.NMA` :arg atoms: atoms for which the *model* was built :type atoms: :class:`.Atomic` :arg select: an atom selection or a selection string :type select: :class:`.Selection`, str :returns: (:class:`.NMA`, :class:`.Selection`)""" if not isinstance(model, NMA): raise TypeError('mode must be a NMA instance, not {0}' .format(type(model))) if not isinstance(atoms, Atomic): raise TypeError('atoms must be an Atomic instance, not {0}' .format(type(atoms))) if atoms.numAtoms() != model.numAtoms(): raise ValueError('number of atoms in model and atoms must be equal') array = model._getArray() if isinstance(select, str): selstr = select if isinstance(atoms, AtomGroup): sel = atoms.select(selstr) which = sel.getIndices() else: which = SELECT.getIndices(atoms, selstr) sel = Selection(atoms.getAtomGroup(), atoms.getIndices()[which], selstr, atoms.getACSIndex()) elif isinstance(select, AtomSubset): sel = select if isinstance(atoms, AtomGroup): if sel.getAtomGroup() != atoms: raise ValueError('select and atoms do not match') which = sel._getIndices() else: if atoms.getAtomGroup() != sel.getAtomGroup(): raise ValueError('select and atoms do not match') elif not sel in atoms: raise ValueError('select is not a subset of atoms') idxset = set(atoms._getIndices()) which = np.array([idx in idxset for idx in sel._getIndices()]) which = which.nonzero()[0] selstr = sel.getSelstr() else: raise TypeError('select must be a string or a Selection instance') nma = type(model)('{0} slice {1}' .format(model.getTitle(), repr(selstr))) if model.is3d(): which = [which.reshape((len(which), 1))*3] which.append(which[0]+1) which.append(which[0]+2) which = np.concatenate(which, 1).flatten() nma.setEigens(array[which, :], model.getEigvals()) return (nma, sel)
def sliceMode(mode, atoms, select): """Return part of the *mode* for *atoms* matching *select*. This works slightly different from :func:`.sliceVector`. Mode array (eigenvector) is multiplied by square-root of the variance along the mode. If mode is from an elastic network model, variance is defined as the inverse of the eigenvalue. Note that returned :class:`.Vector` instance is not normalized. :arg mode: mode instance to be sliced :type mode: :class:`.Mode` :arg atoms: atoms for which *mode* describes a deformation, motion, etc. :type atoms: :class:`.Atomic` :arg select: an atom selection or a selection string :type select: :class:`.Selection`, str :returns: (:class:`.Vector`, :class:`.Selection`)""" if not isinstance(mode, Mode): raise TypeError('mode must be a Mode instance, not {0}' .format(type(mode))) if not isinstance(atoms, Atomic): raise TypeError('atoms must be an Atomic instance, not {0}' .format(type(atoms))) if atoms.numAtoms() != mode.numAtoms(): raise ValueError('number of atoms in model and atoms must be equal') if isinstance(select, str): selstr = select if isinstance(atoms, AtomGroup): sel = atoms.select(selstr) which = sel._getIndices() else: which = SELECT.getIndices(atoms, selstr) sel = Selection(atoms.getAtomGroup(), atoms.getIndices()[which], selstr, atoms.getACSIndex()) elif isinstance(select, AtomSubset): sel = select if isinstance(atoms, AtomGroup): if sel.getAtomGroup() != atoms: raise ValueError('select and atoms do not match') which = sel._getIndices() else: if atoms.getAtomGroup() != sel.getAtomGroup(): raise ValueError('select and atoms do not match') elif not sel in atoms: raise ValueError('select is not a subset of atoms') idxset = set(atoms._getIndices()) which = np.array([idx in idxset for idx in sel._getIndices()]) which = which.nonzero()[0] selstr = sel.getSelstr() else: raise TypeError('select must be a string or a Selection instance') vec = Vector(mode.getArrayNx3()[which, :].flatten() * mode.getVariance()**0.5, '{0} slice {1}'.format(str(mode), repr(selstr)), mode.is3d()) return (vec, sel)