def GenerateContactMap(TimeStep,protocol):
    """Read a frame and compute the contactMap between two groups of atom given a ContactMapProtocol
    NOTE: if protocol.byres=True, then we report the number of atomic contacts for a given
          residue pair in contact
    Numbering of atoms and residues is the one given by the PSF file"""
    rowNS = AtomNeighborSearch(protocol.rowGroup) #KDE-tree object for rowGroup
    colNS = AtomNeighborSearch(protocol.colGroup) #KDE-tree object for colGroup
    rowClose = rowNS.search_list(protocol.colGroup,protocol.cutOff) #atoms of rowGroup in contact with colGroup
    if not rowClose: #no contacts
        shape=(TimeStep.numatoms,TimeStep.numatoms) #all atoms in the system
        if protocol.byres: shape=(protocol.numberOfResidues,protocol.numberOfResidues)
        csr=csr_matrix( ([],([],[])), shape, dtype='int32')  #empty map
        cma=CMA.csr_ContactMap(csr)
        cma.setDistanceCutOff(protocol.cutOff)
        return cma
    colClose = colNS.search_list(rowClose,protocol.cutOff) #atoms of colGroup in contact with rowClose/rowGroup
    dd=distance_array(rowClose.coordinates(),colClose.coordinates(),TimeStep.dimensions[0:3])
    (rowIndices,colIndices) = numpy.where(dd<protocol.cutOff)
    rowIndices=rowClose.indices()[rowIndices]
    colIndices=colClose.indices()[colIndices]  
    if protocol.byres:
        #switch from atomic indices to residue numbers
        rowIndices=protocol.atom2res[rowIndices]
        colIndices=protocol.atom2res[colIndices]
        shape=(protocol.numberOfResidues,protocol.numberOfResidues)
    else:
        #Take into account if the first atomic index was zero
        rowIndices += protocol.shift
        colIndices += protocol.shift
        shape=(TimeStep.numatoms,TimeStep.numatoms) #all atoms in the system
    #create sparse matrix for the contact map. 
    data=numpy.ones( len(rowIndices) ) #just signaling a contact map
    csr=csr_matrix( (data, (rowIndices,colIndices)), shape, dtype='int32')
    if protocol.byres: csr.data[:]=1 #overwrite number of atomic contacts per residue pair with 1 only
    #trace()
    if protocol.filter: csr=protocol.filter(csr) #Filtering
    cma=CMA.csr_ContactMap(csr)
    cma.setDistanceCutOff(protocol.cutOff)
    return cma
Example #2
0
def between(group, A, B, distance):
    """Return sub group of *group* that is within *distance* of both *A* and *B*.

    *group*, *A*, and *B* must be
    :class:`~MDAnalysis.core.AtomGroup.AtomGroup` instances.  Works best
    if *group* is bigger than either *A* or *B*. This function is not
    aware of periodic boundary conditions.

    Can be used to find bridging waters or molecules in an interface.

    Similar to "*group* and (AROUND *A* *distance* and AROUND *B* *distance*)".

    .. SeeAlso:: Makes use of :mod:`MDAnalysis.KDTree.NeighborSearch`.

    .. versionadded: 0.7.5
    """
    from MDAnalysis.KDTree.NeighborSearch import AtomNeighborSearch
    from MDAnalysis.core.AtomGroup import AtomGroup

    ns_group = AtomNeighborSearch(group)
    resA = set(ns_group.search_list(A, distance))
    resB = set(ns_group.search_list(B, distance))
    return AtomGroup(resB.intersection(resA))
Example #3
0
def between(group, A, B, distance):
    """Return sub group of *group* that is within *distance* of both *A* and *B*.

    *group*, *A*, and *B* must be
    :class:`~MDAnalysis.core.AtomGroup.AtomGroup` instances.  Works best
    if *group* is bigger than either *A* or *B*. This function is not
    aware of periodic boundary conditions.

    Can be used to find bridging waters or molecules in an interface.

    Similar to "*group* and (AROUND *A* *distance* and AROUND *B* *distance*)".

    .. SeeAlso:: Makes use of :mod:`MDAnalysis.KDTree.NeighborSearch`.

    .. versionadded: 0.7.5
    """
    from MDAnalysis.KDTree.NeighborSearch import AtomNeighborSearch
    from MDAnalysis.core.AtomGroup import AtomGroup

    ns_group = AtomNeighborSearch(group)
    resA = set(ns_group.search_list(A, distance))
    resB = set(ns_group.search_list(B, distance))
    return AtomGroup(resB.intersection(resA))
Example #4
0
def number_of_neighbouring_residues(residue_to_find, center, radius):
    x = AtomNeighborSearch(residue_to_find)
    neighboring = AtomNeighborSearch.search_list(x, center, radius, level='R')
    number = len(neighboring)
    return number