def alter_occupancy(fhandle, occupancy):
    """Sets the occupancy column in all ATOM/HETATM records to a given value.
    """
    records = 'ATOM', 'HETATM'
    occupancy = '{0:>6.2f}'.format(occupancy)
    for line in fhandle:
        if line.startswith(records):
            yield line[:54] + occupancy + line[60:]
        else:
            yield line
