pKaTool/dist_geom.py
def do_triangle_smoothing(self):
        """Make sure that the distances are consistent"""
        anychange=1
        count=1
        while anychange:
            anychange=None
            for A in self.D_matrix.keys():
                for B in self.D_matrix.keys():
                    if B==A:
                        continue
                    for C in self.D_matrix.keys():
                        if C==B or C==A:
                            continue
                        #
                        # Flag for changes
                        #
                        changed=None
                        #
                        # Get the distances
                        #
                        AB=self.D_matrix[A][B]
                        AC=self.D_matrix[A][C]
                        BC=self.D_matrix[B][C]
                        #
                        # AC cannot be bigger than AB+BC
                        #
                        if AC>AB+BC:
                            AC=AB+BC
                        #
                        # AC dist must at least be AB-CB
                        #
                        if AC<AB-BC:
                            AC=AB-BC
                        #
                        # Put vals back into the matrix
                        #
                        if changed:
                            self.D_matrix[A][B]=AB
                            self.D_matrix[B][A]=AB
                            self.D_matrix[A][C]=AC
                            self.D_matrix[C][A]=AC
                            self.D_matrix[B][C]=BC
                            self.D_matrix[C][B]=BC
                            anychange=1
            print 'Triangle smoothing round %3d done' %count
            count=count+1
        print 'Triangle smoothing converged'
        print self.D_matrix
        print
        return self.D_matrix
Make sure that the distances are consistent
Make sure that the distances are consistent
Make sure that the distances are consistent
def do_triangle_smoothing(self):
        anychange=1
        count=1
        while anychange:
            anychange=None
            for A in self.D_matrix.keys():
                for B in self.D_matrix.keys():
                    if B==A:
                        continue
                    for C in self.D_matrix.keys():
                        if C==B or C==A:
                            continue
                         Flag for changes
                        changed=None
                         Get the distances
                        AB=self.D_matrix[A][B]
                        AC=self.D_matrix[A][C]
                        BC=self.D_matrix[B][C]
                         AC cannot be bigger than AB+BC
                        if AC>AB+BC:
                            AC=AB+BC
                         AC dist must at least be AB-CB
                        if AC<AB-BC:
                            AC=AB-BC
                         Put vals back into the matrix
                        if changed:
                            self.D_matrix[A][B]=AB
                            self.D_matrix[B][A]=AB
                            self.D_matrix[A][C]=AC
                            self.D_matrix[C][A]=AC
                            self.D_matrix[B][C]=BC
                            self.D_matrix[C][B]=BC
                            anychange=1
            print 'Triangle smoothing round %3d done' %count
            count=count+1
        print 'Triangle smoothing converged'
        print self.D_matrix
        print
        return self.D_matrix
def do_triangle_smoothing ( self ) : anychange = 1 count = 1 while anychange : anychange = None for A in self . D_matrix . keys ( ) : for B in self . D_matrix . keys ( ) : if B == A : continue for C in self . D_matrix . keys ( ) : if C == B or C == A : continue changed = None AB = self . D_matrix [ A ] [ B ] AC = self . D_matrix [ A ] [ C ] BC = self . D_matrix [ B ] [ C ] if AC > AB + BC : AC = AB + BC if AC < AB - BC : AC = AB - BC if changed : self . D_matrix [ A ] [ B ] = AB self . D_matrix [ B ] [ A ] = AB self . D_matrix [ A ] [ C ] = AC self . D_matrix [ C ] [ A ] = AC self . D_matrix [ B ] [ C ] = BC self . D_matrix [ C ] [ B ] = BC anychange = 1 print 'Triangle smoothing round %3d done' % count count = count + 1 print 'Triangle smoothing converged' print self . D_matrix print return self . D_matrix
Make sure that the distances are consistent
Make sure that the distances are consistent
"""Make sure that the distances are consistent""" # # Flag for changes # # # Get the distances # # # AC cannot be bigger than AB+BC # # # AC dist must at least be AB-CB # # # Put vals back into the matrix #
self