예제 #1
0
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)
예제 #2
0
파일: editing.py 프로젝트: npabon/ProDy
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)
예제 #3
0
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)
예제 #4
0
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)
예제 #5
0
파일: editing.py 프로젝트: npabon/ProDy
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)
예제 #6
0
파일: editing.py 프로젝트: npabon/ProDy
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)