Esempio n. 1
0
def trialMakePolyList(v): # [i think this is experimental code by Huaicai, never called, perhaps never tested. -- bruce 051117]
    pMat = []
    for i in range(size(v)):
        pMat += [polyMat[i] * v[i]]
    
    segs = []
    for corner, edges, planes in polyTab:
      pts = size(planes)
      for i in range(pts):
          segs += [pMat[corner], pMat[planes[i]]]
          segs += [pMat[planes[i]], pMat[planes[(i+1)%pts]]]
    
    return segs
Esempio n. 2
0
def trialMakePolyList(
    v
):  # [i think this is experimental code by Huaicai, never called, perhaps never tested. -- bruce 051117]
    pMat = []
    for i in range(size(v)):
        pMat += [polyMat[i] * v[i]]

    segs = []
    for corner, edges, planes in polyTab:
        pts = size(planes)
        for i in range(pts):
            segs += [pMat[corner], pMat[planes[i]]]
            segs += [pMat[planes[i]], pMat[planes[(i + 1) % pts]]]

    return segs
Esempio n. 3
0
def povStrVec(va):  # review: refile in povheader or so? [bruce 071215 comment]
    # used in other modules too
    rstr = '<'
    for ii in range(size(va)):
        rstr += str(va[ii]) + ', '

    return rstr
Esempio n. 4
0
def povStrVec(va): # review: refile in povheader or so? [bruce 071215 comment]
    # used in other modules too
    rstr = '<'
    for ii in range(size(va)):
        rstr += str(va[ii]) + ', '
    
    return rstr
Esempio n. 5
0
    def __alignMatrixDimension(self, cm, thisSeq, castSeq, axis=0):
        """
        Correct one dimension of contactMatrix by inserting and deleting
        columns, so that it can be later compared to contact matrices based
        on slightly different sequences.
        
        @param cm: contact matrix, 2D matrix of residue contacts
                   recceptor x ligand sequence
        @type  cm: array
        @param thisSeq: AA sequence of this dimension of the contactMatrix
        @type  thisSeq: string
        @param castSeq: AA sequence of this dimension in the other contact
        @type  castSeq: string
        @param axis: which dimension to adapt (0=receptor, 1=ligand)
        @type  axis: 1|0
        
        @return: contact matrix with residue contacts compatible to refSeq.
        @rtype: 2D array
        """
        # compare the two sequences
        seqdiff = SequenceMatcher(None, thisSeq, castSeq)
        seqDiff = seqdiff.get_opcodes()
        ## print seqDiff

        # decide which dimension to work on
        if not axis:
            cm = N.transpose( cm )

        seqCount = 0   # keep track of sequence length changes
        i=0

        for list in seqDiff:

            # remove the column corresponding to the deletion in the
            # docked sequence
            if str( seqDiff[i][0] ) == 'delete':

                # separate matrix into before and after deletion
                matrixSeg1 = cm[ :, : seqDiff[i][1] + seqCount ]
                matrixSeg2 = cm[ :, seqDiff[i][2] + seqCount : ]
                # concatenate part
                cm = N.concatenate( ( matrixSeg1, matrixSeg2 ), 1)
                seqCount = seqCount + seqDiff[i][1] - seqDiff[i][2]

            # inserts zeros in the column where there is a insertion in the
            # docked sequence
            if str( seqDiff[i][0] ) == 'insert':

                # create a matrix to be inserted
                insertZeros= seqDiff[i][4] - seqDiff[i][3]
                insertColumns = N.array( [ [0] * insertZeros ] * N.size(cm,0) )
                # separate matrix into before and after insertion
                matrixSeg1 = cm[ :, : seqDiff[i][1] + seqCount ]
                matrixSeg2 = cm[ :, seqDiff[i][2] + seqCount : ]
                # concatenate parts with the zero matrix
                cm = N.concatenate( (matrixSeg1,insertColumns,matrixSeg2), 1)
                seqCount = seqCount + seqDiff[i][4] - seqDiff[i][3]

            i=i+1

        if not axis:
            return N.transpose( cm )
        return cm
Esempio n. 6
0
    def calc_sse_dist_matrix(self, ptnode_list):
        """
        Build the matrix of SSE distance, i.e. min dist between residues
        in the SSEs.

        NOTE: the self-distance (i.e. matrix elements [i,i]) are set to
        infinity rather than 0, so we can efficiently use argmin
        in get_sse_min_distance() to find SSE (not same one) with min
        distance - we are wanting to find minimum distances
        in ptgraph2, not maximum distances.

        Parameters:
          ptnode_list - iterable over PTNode objects represneting SSEs


        Return value:
           None. (sets data members)
           

        Uses data members (WRITE):

          sse_dist_matrix - square symmetric
                            Numeric.array matrix of dimensions
                            len(ptnode_list) x len(ptnode_list) where each
                            elementis distance between the two SSEs
                            represented by the ptnodes,
                            as defined by calc_sse_dist() (min residue distance)

          sse_index_map - dict of { ptnode : array_index } mapping a PTNode
                          object to index in sse_dist_matrix

          reverse_sse_index_map - list of PTNode objects mapping
                                 index back to PTNode
                                 (i.e. reverse of index_map)

          sse_residue_map - dict of {(ptnode1, ptnode2) : (residue1, residue2)}
                             which for every pair of sses gives the residue
                             in each which are closest (used in the distance
                             matrix). Note both (ptnode1,ptnode2) and
                             (ptnode2,ptnode1) are stored, with residues
                             swapped appropriately.
                              
        
        """
        self.sse_dist_matrix = Numeric.zeros(
            (len(ptnode_list), len(ptnode_list)), Numeric.Float)

        # set the self-distances to infinity (see comments above and in
        # get_sse_min_distance()
        # TODO: maybe if we used NaN instead of inf, this would allow
        # both min/max and argmin/argmax rather than just min/argmin
        # (as we actualy use) to be useful. I tried it with Python 2.5.1
        # on Linux and it worked (ie NaN is neither max nor min) but
        # not really sure how reliable that behaviour is... so sticking
        # with inf for now since we only need min/argmin anyway.
        for i in range(0, Numeric.size(self.sse_dist_matrix, 0)):
            self.sse_dist_matrix[i, i] = float("inf")

        self.reverse_sse_index_map = len(ptnode_list) * [-1]  #will in 0..len-1
        index_maplist = list(enumerate(ptnode_list))
        for i in range(len(index_maplist)):
            row, sse_one = index_maplist[i]
            self.sse_index_map[sse_one] = row
            self.reverse_sse_index_map[row] = sse_one
            for j in range(i + 1, len(index_maplist)):
                col, sse_two = index_maplist[j]
                (dist, res_one, res_two) = self.calc_sse_dist(sse_one, sse_two)
                self.sse_dist_matrix[row, col] = dist
                self.sse_dist_matrix[col, row] = dist
                self.sse_residue_map[sse_one, sse_two] = (res_one, res_two)
                self.sse_residue_map[sse_two, sse_one] = (res_two, res_one)
Esempio n. 7
0
    def calc_sse_dist_matrix(self, ptnode_list):
        """
        Build the matrix of SSE distance, i.e. min dist between residues
        in the SSEs.

        NOTE: the self-distance (i.e. matrix elements [i,i]) are set to
        infinity rather than 0, so we can efficiently use argmin
        in get_sse_min_distance() to find SSE (not same one) with min
        distance - we are wanting to find minimum distances
        in ptgraph2, not maximum distances.

        Parameters:
          ptnode_list - iterable over PTNode objects represneting SSEs


        Return value:
           None. (sets data members)
           

        Uses data members (WRITE):

          sse_dist_matrix - square symmetric
                            Numeric.array matrix of dimensions
                            len(ptnode_list) x len(ptnode_list) where each
                            elementis distance between the two SSEs
                            represented by the ptnodes,
                            as defined by calc_sse_dist() (min residue distance)

          sse_index_map - dict of { ptnode : array_index } mapping a PTNode
                          object to index in sse_dist_matrix

          reverse_sse_index_map - list of PTNode objects mapping
                                 index back to PTNode
                                 (i.e. reverse of index_map)

          sse_residue_map - dict of {(ptnode1, ptnode2) : (residue1, residue2)}
                             which for every pair of sses gives the residue
                             in each which are closest (used in the distance
                             matrix). Note both (ptnode1,ptnode2) and
                             (ptnode2,ptnode1) are stored, with residues
                             swapped appropriately.
                              
        
        """
        self.sse_dist_matrix =Numeric.zeros((len(ptnode_list),len(ptnode_list)),
                                            Numeric.Float)

        # set the self-distances to infinity (see comments above and in
        # get_sse_min_distance()
        # TODO: maybe if we used NaN instead of inf, this would allow
        # both min/max and argmin/argmax rather than just min/argmin
        # (as we actualy use) to be useful. I tried it with Python 2.5.1
        # on Linux and it worked (ie NaN is neither max nor min) but
        # not really sure how reliable that behaviour is... so sticking
        # with inf for now since we only need min/argmin anyway.
        for i in range(0, Numeric.size(self.sse_dist_matrix,0)):
            self.sse_dist_matrix[i,i] = float("inf")

        self.reverse_sse_index_map = len(ptnode_list) * [ -1 ] #will in 0..len-1
        index_maplist = list(enumerate(ptnode_list))
        for i in range(len(index_maplist)):
            row, sse_one = index_maplist[i]
            self.sse_index_map[sse_one] = row
            self.reverse_sse_index_map[row] = sse_one
            for j in range(i+1, len(index_maplist)):
                col, sse_two = index_maplist[j]
                (dist, res_one, res_two) = self.calc_sse_dist(sse_one, sse_two)
                self.sse_dist_matrix[row, col] = dist
                self.sse_dist_matrix[col, row] = dist
                self.sse_residue_map[sse_one, sse_two] = (res_one, res_two)
                self.sse_residue_map[sse_two, sse_one] = (res_two, res_one)