import copy


def rename(object, complex):
    """
    Takes a PDB object and a complex.
    Returns a copy of the PDB object so that no chain in the object has the same id as a chain in the complex.
    Renaming is done checking non-used chain names in the complex, starting form ASCII character A.
    """

    # ASCII A-Za-z encoded on decimal 65 to 122
    object_copy = copy.deepcopy(object)
    for chain in object_copy.get_chains():
        N = 65
        while chain.get_id() in [a.get_id() for a in complex.get_chains()]:
            try:
                chain.id = chr(N)
            except ValueError:
                pass
            N += 1
    return object_copy