def replace_chain_identifiers(fhandle, chain_ids):
    """Replaces one chain identifier by another in the PDB file.
    """
    chain_from, chain_to = chain_ids
    records = 'ATOM', 'HETATM', 'TER', 'ANISOU'
    for line in fhandle:
        if line.startswith(records):
            if line[21] == chain_from:
                yield line[:21] + chain_to + line[22:]
                continue
        yield line
