pKaTool/dist_geom.py
def find_matrix_match(self):
        """Find a match in the energies in pkamatrix"""
        #
        # Complete distances
        #
        distmat=self.distance_matrix.copy()
        for group in distmat.keys():
            distmat[group][group]=0.0
        #
        # Number of groups in distance matrix
        #
        groups=distmat.keys()
        num_groups=len(groups)
        #
        # Make it into a Numeric matrix with energies
        #
        import math
        EM=numpy.zeros([num_groups,num_groups])
        for x in range(num_groups):
            for y in range(num_groups):
                if distmat[groups[x]][groups[y]]>0.0:
                    EM[x][y]=(243.4*math.log(10))/distmat[groups[x]][groups[y]]
                else:
                    EM[x][y]=0.0
                 #distance=243.3*math.log(10)/(eps*E)
        self.PDB_text.insert(END,'REF: %30s %7.2f\n' %(groups,0.0))

        EMT = EM.transpose() # not really necessary as EM is symmetric
        print 'Energy matrix',EM
        print 'Transposed energy matrix',EMT
        #
        # Now get all the groups in the protein
        #
        tmp_titgrps=self.pkamatrix.keys()
        tmp_titgrps.sort()
        titgrps=[]
        for grp in tmp_titgrps:
            if not 'TYR' in grp:
                titgrps.append(grp)
        print titgrps
        permutations=self.construct_permutations(num_groups,titgrps)
        #
        # Calculate the differences between the matrices
        #
        diffs=[]
        for perm in permutations.keys():
 #           print perm
            this_perm=eval(perm)
            this_matrix=numpy.zeros([len(this_perm),len(this_perm)])
            count1=0
            for res1 in this_perm:
                count2=0
                for res2 in this_perm:
                    if res1==res2:
                        this_matrix[count1][count2]=0.0
                    else:
                        # takes the average of the two interaction energies
                        this_matrix[count1][count2]=((self.pkamatrix[res1][res2][0]-self.pkamatrix[res1][res2][1]-self.pkamatrix[res1][res2][2]+self.pkamatrix[res1][res2][3])
                                                     +(self.pkamatrix[res2][res1][0]-self.pkamatrix[res2][res1][1]-self.pkamatrix[res2][res1][2]+self.pkamatrix[res2][res1][3]))/2

# this_matrix[count1][count2]=self.pkamatrix[res1][res2][0]-self.pkamatrix[res1][res2][1]-self.pkamatrix[res1][res2][2]+self.pkamatrix[res1][res2][3]
# this_matrix[count1][count2]=min((self.pkamatrix[res1][res2][0]-self.pkamatrix[res1][res2][1]-self.pkamatrix[res1][res2][2]+self.pkamatrix[res1][res2][3]),(self.pkamatrix[res2][res1][0]-self.pkamatrix[res2][res1][1]-self.pkamatrix[res2][res1][2]+self.pkamatrix[res2][res1][3]))



                    count2=count2+1
                count1=count1+1
            #
            # Get the difference
            #
            diff=EM-this_matrix
            sum=0.0
            for x in diff:
                for y in x:
                    sum=sum+abs(y)
            #
            # Calculate Frobenius inner product
            #
            product = numpy.dot(EMT,this_matrix)


#            normThis_matrix = math.sqrt(numpy.trace(numpy.dot(this_matrix.transpose(),this_matrix)))
                                      
            Frobenius  = math.sqrt(numpy.trace(numpy.dot(diff.transpose(),diff)))
            #Frobenius = numpy.trace(product)

            diffs.append([Frobenius,sum,perm])
        #
        # Sort and report
        #
        diffs.sort()
        #diffs.reverse()

        for fro,sum,sol in diffs:#[:10]:
            self.PDB_text.insert(END,'%30s %7.2f %7.2f\n' %(sol,sum,fro))
        self.PDB_text.insert(END,'Number of permutations: %d' %(len(permutations.keys())))
        return
Find a match in the energies in pkamatrix
Find a match in the energies in pkamatrix
Find a match in the energies in pkamatrix
def find_matrix_match(self):
         Complete distances
        distmat=self.distance_matrix.copy()
        for group in distmat.keys():
            distmat[group][group]=0.0
         Number of groups in distance matrix
        groups=distmat.keys()
        num_groups=len(groups)
         Make it into a Numeric matrix with energies
        import math
        EM=numpy.zeros([num_groups,num_groups])
        for x in range(num_groups):
            for y in range(num_groups):
                if distmat[groups[x]][groups[y]]>0.0:
                    EM[x][y]=(243.4*math.log(10))/distmat[groups[x]][groups[y]]
                else:
                    EM[x][y]=0.0
                 distance=243.3*math.log(10)/(eps*E)
        self.PDB_text.insert(END,'REF: %30s %7.2f\n' %(groups,0.0))
        EMT = EM.transpose()  not really necessary as EM is symmetric
        print 'Energy matrix',EM
        print 'Transposed energy matrix',EMT
         Now get all the groups in the protein
        tmp_titgrps=self.pkamatrix.keys()
        tmp_titgrps.sort()
        titgrps=[]
        for grp in tmp_titgrps:
            if not 'TYR' in grp:
                titgrps.append(grp)
        print titgrps
        permutations=self.construct_permutations(num_groups,titgrps)
         Calculate the differences between the matrices
        diffs=[]
        for perm in permutations.keys():
            print perm
            this_perm=eval(perm)
            this_matrix=numpy.zeros([len(this_perm),len(this_perm)])
            count1=0
            for res1 in this_perm:
                count2=0
                for res2 in this_perm:
                    if res1==res2:
                        this_matrix[count1][count2]=0.0
                    else:
                         takes the average of the two interaction energies
                        this_matrix[count1][count2]=((self.pkamatrix[res1][res2][0]-self.pkamatrix[res1][res2][1]-self.pkamatrix[res1][res2][2]+self.pkamatrix[res1][res2][3])
                                                     +(self.pkamatrix[res2][res1][0]-self.pkamatrix[res2][res1][1]-self.pkamatrix[res2][res1][2]+self.pkamatrix[res2][res1][3]))/2
 this_matrix[count1][count2]=self.pkamatrix[res1][res2][0]-self.pkamatrix[res1][res2][1]-self.pkamatrix[res1][res2][2]+self.pkamatrix[res1][res2][3]
 this_matrix[count1][count2]=min((self.pkamatrix[res1][res2][0]-self.pkamatrix[res1][res2][1]-self.pkamatrix[res1][res2][2]+self.pkamatrix[res1][res2][3]),(self.pkamatrix[res2][res1][0]-self.pkamatrix[res2][res1][1]-self.pkamatrix[res2][res1][2]+self.pkamatrix[res2][res1][3]))
                    count2=count2+1
                count1=count1+1
             Get the difference
            diff=EM-this_matrix
            sum=0.0
            for x in diff:
                for y in x:
                    sum=sum+abs(y)
             Calculate Frobenius inner product
            product = numpy.dot(EMT,this_matrix)
            normThis_matrix = math.sqrt(numpy.trace(numpy.dot(this_matrix.transpose(),this_matrix)))
            Frobenius  = math.sqrt(numpy.trace(numpy.dot(diff.transpose(),diff)))
            Frobenius = numpy.trace(product)
            diffs.append([Frobenius,sum,perm])
         Sort and report
        diffs.sort()
        diffs.reverse()
        for fro,sum,sol in diffs:[:10]:
            self.PDB_text.insert(END,'%30s %7.2f %7.2f\n' %(sol,sum,fro))
        self.PDB_text.insert(END,'Number of permutations: %d' %(len(permutations.keys())))
        return
def find_matrix_match ( self ) : distmat = self . distance_matrix . copy ( ) for group in distmat . keys ( ) : distmat [ group ] [ group ] = 0.0 groups = distmat . keys ( ) num_groups = len ( groups ) import math EM = numpy . zeros ( [ num_groups , num_groups ] ) for x in range ( num_groups ) : for y in range ( num_groups ) : if distmat [ groups [ x ] ] [ groups [ y ] ] > 0.0 : EM [ x ] [ y ] = ( 243.4 * math . log ( 10 ) ) / distmat [ groups [ x ] ] [ groups [ y ] ] else : EM [ x ] [ y ] = 0.0 self . PDB_text . insert ( END , 'REF: %30s %7.2f\n' % ( groups , 0.0 ) ) EMT = EM . transpose ( ) print 'Energy matrix' , EM print 'Transposed energy matrix' , EMT tmp_titgrps = self . pkamatrix . keys ( ) tmp_titgrps . sort ( ) titgrps = [ ] for grp in tmp_titgrps : if not 'TYR' in grp : titgrps . append ( grp ) print titgrps permutations = self . construct_permutations ( num_groups , titgrps ) diffs = [ ] for perm in permutations . keys ( ) : this_perm = eval ( perm ) this_matrix = numpy . zeros ( [ len ( this_perm ) , len ( this_perm ) ] ) count1 = 0 for res1 in this_perm : count2 = 0 for res2 in this_perm : if res1 == res2 : this_matrix [ count1 ] [ count2 ] = 0.0 else : this_matrix [ count1 ] [ count2 ] = ( ( self . pkamatrix [ res1 ] [ res2 ] [ 0 ] - self . pkamatrix [ res1 ] [ res2 ] [ 1 ] - self . pkamatrix [ res1 ] [ res2 ] [ 2 ] + self . pkamatrix [ res1 ] [ res2 ] [ 3 ] ) + ( self . pkamatrix [ res2 ] [ res1 ] [ 0 ] - self . pkamatrix [ res2 ] [ res1 ] [ 1 ] - self . pkamatrix [ res2 ] [ res1 ] [ 2 ] + self . pkamatrix [ res2 ] [ res1 ] [ 3 ] ) ) / 2 count2 = count2 + 1 count1 = count1 + 1 diff = EM - this_matrix sum = 0.0 for x in diff : for y in x : sum = sum + abs ( y ) product = numpy . dot ( EMT , this_matrix ) Frobenius = math . sqrt ( numpy . trace ( numpy . dot ( diff . transpose ( ) , diff ) ) ) diffs . append ( [ Frobenius , sum , perm ] ) diffs . sort ( ) for fro , sum , sol in diffs : self . PDB_text . insert ( END , '%30s %7.2f %7.2f\n' % ( sol , sum , fro ) ) self . PDB_text . insert ( END , 'Number of permutations: %d' % ( len ( permutations . keys ( ) ) ) ) return
Find a match in the energies in pkamatrix
Find a match in the energies in pkamatrix
"""Find a match in the energies in pkamatrix""" # # Complete distances # # # Number of groups in distance matrix # # # Make it into a Numeric matrix with energies # #distance=243.3*math.log(10)/(eps*E) # not really necessary as EM is symmetric # # Now get all the groups in the protein # # # Calculate the differences between the matrices # #           print perm # takes the average of the two interaction energies # this_matrix[count1][count2]=self.pkamatrix[res1][res2][0]-self.pkamatrix[res1][res2][1]-self.pkamatrix[res1][res2][2]+self.pkamatrix[res1][res2][3] # this_matrix[count1][count2]=min((self.pkamatrix[res1][res2][0]-self.pkamatrix[res1][res2][1]-self.pkamatrix[res1][res2][2]+self.pkamatrix[res1][res2][3]),(self.pkamatrix[res2][res1][0]-self.pkamatrix[res2][res1][1]-self.pkamatrix[res2][res1][2]+self.pkamatrix[res2][res1][3])) # # Get the difference # # # Calculate Frobenius inner product # #            normThis_matrix = math.sqrt(numpy.trace(numpy.dot(this_matrix.transpose(),this_matrix))) #Frobenius = numpy.trace(product) # # Sort and report # #diffs.reverse() #[:10]:
self