Protool/contact_order.py
def res_separation(self,ID1,ID2,ss=False):
        """Get the number of residues between the two IDs"""
        #print 'Finding shortest route between',ID1,ID2
        res1=self.resid(ID1)
        res2=self.resid(ID2)
        #
        # Keep a dictionary of results
        #
        if not hasattr(self,'sep_results'):
            self.sep_results={}
            for r in self.residues.keys():
                self.sep_results[r]={}
        if self.sep_results[res1].has_key(res2):
            return self.sep_results[res1][res2]
        #
        # Use Dijkstra's algorithm to find the shortest path between the two
        #
        G={}
        for residue in self.residues.keys():
            G[residue]={}
            neighbours=self.get_neighbours(residue,ss=ss)
            G[residue]['NB']={}
            for r2 in neighbours:
                G[residue]['NB'][r2]=1 # 1 is the distance between neighbours
            G[residue]['dist']=9999999
            G[residue]['visited']=False
        #
        # We have the graph, now search it
        #
        current=res1
        G[res1]['dist']=0.0
        done=False
        while not done:
            for nb in G[current]['NB']:
                if not G[nb]['visited']:
                    thisdist=G[current]['dist']+G[current]['NB'][nb]
                    if thisdist<G[nb]['dist'] and thisdist<G[res2]['dist']:
                        G[nb]['dist']=thisdist
            G[current]['visited']=True
            #
            # Find new current node
            #
            mindist=99999999999999
            bestnode=None
            for node in G.keys():
                if not G[node]['visited']:
                    if G[node]['dist']<mindist:
                        mindist=G[node]['dist']
                        bestnode=node
            current=bestnode
            if current is None or G[current]['dist']>G[res2]['dist']:
                done=True
        #
        # Shortest distance
        #
        self.sep_results[res1][res2]=G[res2]['dist']
        self.sep_results[res2][res1]=G[res2]['dist']
        #print 'Shortest distance between %7s and %7s is %5.1f' %(res1,res2,G[res2]['dist'])
        return G[res2]['dist']
Get the number of residues between the two IDs
Get the number of residues between the two IDs
Get the number of residues between the two IDs
def res_separation(self,ID1,ID2,ss=False):
        res1=self.resid(ID1)
        res2=self.resid(ID2)
         Keep a dictionary of results
        if not hasattr(self,'sep_results'):
            self.sep_results={}
            for r in self.residues.keys():
                self.sep_results[r]={}
        if self.sep_results[res1].has_key(res2):
            return self.sep_results[res1][res2]
         Use Dijkstra's algorithm to find the shortest path between the two
        G={}
        for residue in self.residues.keys():
            G[residue]={}
            neighbours=self.get_neighbours(residue,ss=ss)
            G[residue]['NB']={}
            for r2 in neighbours:
                G[residue]['NB'][r2]=1  1 is the distance between neighbours
            G[residue]['dist']=9999999
            G[residue]['visited']=False
         We have the graph, now search it
        current=res1
        G[res1]['dist']=0.0
        done=False
        while not done:
            for nb in G[current]['NB']:
                if not G[nb]['visited']:
                    thisdist=G[current]['dist']+G[current]['NB'][nb]
                    if thisdist<G[nb]['dist'] and thisdist<G[res2]['dist']:
                        G[nb]['dist']=thisdist
            G[current]['visited']=True
             Find new current node
            mindist=99999999999999
            bestnode=None
            for node in G.keys():
                if not G[node]['visited']:
                    if G[node]['dist']<mindist:
                        mindist=G[node]['dist']
                        bestnode=node
            current=bestnode
            if current is None or G[current]['dist']>G[res2]['dist']:
                done=True
         Shortest distance
        self.sep_results[res1][res2]=G[res2]['dist']
        self.sep_results[res2][res1]=G[res2]['dist']
        print 'Shortest distance between %7s and %7s is %5.1f' %(res1,res2,G[res2]['dist'])
        return G[res2]['dist']
def res_separation ( self , ID1 , ID2 , ss = False ) : res1 = self . resid ( ID1 ) res2 = self . resid ( ID2 ) if not hasattr ( self , 'sep_results' ) : self . sep_results = { } for r in self . residues . keys ( ) : self . sep_results [ r ] = { } if self . sep_results [ res1 ] . has_key ( res2 ) : return self . sep_results [ res1 ] [ res2 ] G = { } for residue in self . residues . keys ( ) : G [ residue ] = { } neighbours = self . get_neighbours ( residue , ss = ss ) G [ residue ] [ 'NB' ] = { } for r2 in neighbours : G [ residue ] [ 'NB' ] [ r2 ] = 1 G [ residue ] [ 'dist' ] = 9999999 G [ residue ] [ 'visited' ] = False current = res1 G [ res1 ] [ 'dist' ] = 0.0 done = False while not done : for nb in G [ current ] [ 'NB' ] : if not G [ nb ] [ 'visited' ] : thisdist = G [ current ] [ 'dist' ] + G [ current ] [ 'NB' ] [ nb ] if thisdist < G [ nb ] [ 'dist' ] and thisdist < G [ res2 ] [ 'dist' ] : G [ nb ] [ 'dist' ] = thisdist G [ current ] [ 'visited' ] = True mindist = 99999999999999 bestnode = None for node in G . keys ( ) : if not G [ node ] [ 'visited' ] : if G [ node ] [ 'dist' ] < mindist : mindist = G [ node ] [ 'dist' ] bestnode = node current = bestnode if current is None or G [ current ] [ 'dist' ] > G [ res2 ] [ 'dist' ] : done = True self . sep_results [ res1 ] [ res2 ] = G [ res2 ] [ 'dist' ] self . sep_results [ res2 ] [ res1 ] = G [ res2 ] [ 'dist' ] return G [ res2 ] [ 'dist' ]
Get the number of residues between the two IDs
Get the number of residues between the two IDs
"""Get the number of residues between the two IDs""" #print 'Finding shortest route between',ID1,ID2 # # Keep a dictionary of results # # # Use Dijkstra's algorithm to find the shortest path between the two # # 1 is the distance between neighbours # # We have the graph, now search it # # # Find new current node # # # Shortest distance # #print 'Shortest distance between %7s and %7s is %5.1f' %(res1,res2,G[res2]['dist'])
self
ID1
ID2
ss