pKaTool/dist_geom.py
def construct_permutations(self,permutation_size,choices):
        """Construct all permutations of a combination of <permutation_size> items of <choices>"""
        print 'Construct all permutations of a combination of %d items of %d' %(permutation_size,len(choices))
        permutations={}
        x=[]
        count=[]
        for level in range(permutation_size):
            x.append(choices)
            count.append(0)
        done=None
        while not done:
            this_perm=[]
            #
            # Construct this permutation
            #
            for pos in range(len(count)):
                c_value=count[pos]
                if not x[pos][c_value] in this_perm:
                    this_perm.append(x[pos][c_value])
            #
            # Is this a valid permutation?
            #
            if len(this_perm)==permutation_size:
                this_perm=str(this_perm)
                if not permutations.has_key(this_perm):
                    permutations[this_perm]=None
            #
            # Increment count
            #
            count[0]=count[0]+1
            for pos in range(len(count)):
                if count[pos]==len(x[pos]):
                    if pos+1==len(count):
                        done=1
                        break
                    count[pos+1]=count[pos+1]+1
                    count[pos]=0
        return permutations
Construct all permutations of a combination of <permutation_size> items of <choices>
Construct all permutations of a combination of  items of 
Construct all permutations of a combination of items of
def construct_permutations(self,permutation_size,choices):
        print 'Construct all permutations of a combination of %d items of %d' %(permutation_size,len(choices))
        permutations={}
        x=[]
        count=[]
        for level in range(permutation_size):
            x.append(choices)
            count.append(0)
        done=None
        while not done:
            this_perm=[]
             Construct this permutation
            for pos in range(len(count)):
                c_value=count[pos]
                if not x[pos][c_value] in this_perm:
                    this_perm.append(x[pos][c_value])
             Is this a valid permutation?
            if len(this_perm)==permutation_size:
                this_perm=str(this_perm)
                if not permutations.has_key(this_perm):
                    permutations[this_perm]=None
             Increment count
            count[0]=count[0]+1
            for pos in range(len(count)):
                if count[pos]==len(x[pos]):
                    if pos+1==len(count):
                        done=1
                        break
                    count[pos+1]=count[pos+1]+1
                    count[pos]=0
        return permutations
def construct_permutations ( self , permutation_size , choices ) : print 'Construct all permutations of a combination of %d items of %d' % ( permutation_size , len ( choices ) ) permutations = { } x = [ ] count = [ ] for level in range ( permutation_size ) : x . append ( choices ) count . append ( 0 ) done = None while not done : this_perm = [ ] for pos in range ( len ( count ) ) : c_value = count [ pos ] if not x [ pos ] [ c_value ] in this_perm : this_perm . append ( x [ pos ] [ c_value ] ) if len ( this_perm ) == permutation_size : this_perm = str ( this_perm ) if not permutations . has_key ( this_perm ) : permutations [ this_perm ] = None count [ 0 ] = count [ 0 ] + 1 for pos in range ( len ( count ) ) : if count [ pos ] == len ( x [ pos ] ) : if pos + 1 == len ( count ) : done = 1 break count [ pos + 1 ] = count [ pos + 1 ] + 1 count [ pos ] = 0 return permutations
Construct all permutations of a combination of <permutation_size> items of <choices>
Construct all permutations of a combination of <permutation_size > items of <choices >
"""Construct all permutations of a combination of <permutation_size> items of <choices>""" # # Construct this permutation # # # Is this a valid permutation? # # # Increment count #
self
permutation_size
choices