def IterativeSuperImposition( src1, src2,
                              initial_alignment, format = "plain",
                              cutoff = 4.0, max_iterations = 10 ):

    alignment = ConvertSequence2StructuralAlignment( src1, src2, initial_alignment, format)

    if len(alignment) == 0:
        raise "alignment is empty"

    rms = 10000

    iteration = 0

    ## get list of CA coordinates for structure1
    ca1 = GetPdbCoordinates( src1, renumber = 1, only_coordinates = 1)

    ## get list of CA coordinates for structure2 and rotate them
    ca2 = GetPdbCoordinates( src2, renumber = 1, only_coordinates = 1)

    last_alignment = None
    
    while alignment != last_alignment:
        
        # print "# aligning in iteration %i with %i pairs" % (iteration, len(alignment))
        
        rmsd, translation, rotation = GetSuperImposition( alignment )
    
##         print "# iteration=%i, atoms=%i, rmsd=%f, rotation=%s, translation=%s" % (iteration,
##                                                                                   len(alignment),
##                                                                                   rmsd,
##                                                                                   str(rotation),
##                                                                                   str(translation))

        ca1_rotated = RotateCoordinates( ca1, translation, rotation)
        
        last_alignment = alignment
        
        map_a2b = GetAlignmentBetweenCorrespondingAtoms( ca1_rotated, ca2, cutoff)

        if not map_a2b:
            raise ValueError, "no corresponding atoms within %f Angstroms found in iteration %i" % (cutoff, iteration)
            
        alignment = []
    
        for row in range( map_a2b.getRowFrom(), map_a2b.getRowTo()):
            col = map_a2b.mapRowToCol(row)
            if col:
                alignment.append( ca1[row-1] + ca2[col-1] + (1,))

        iteration += 1

        if iteration >= max_iterations:
            break

    return rmsd, len(alignment), translation, rotation, iteration


################################################################################
superimposes two structures.
dataset/ETHPy150Open CGATOxford/cgat/legacy/PdbTools.py/IterativeSuperImposition