def read_atat_fit_out(filename, filter_names=None, i_energy=1):
    """
    read fit.out of atat
    filter_names - do not read name numbers greater than filter_name
    i_energy - 1 for fit.out, 2 for predstr.out
    return - concentration list, energy list
    """
    X, E, nam = [], [], []
    count = 0
    with open(filename, 'r') as f:
        for line in f:
            vals = line.split()
            try:
                name = int(vals[-1])
            except:
                name = 0
            if filter_names and name > filter_names:
                continue
            e = round(float(vals[i_energy]), 4)
            x = float(vals[0])
            X.append(x)
            E.append(e)
            nam.append(name)
            count += 1
    return X, E
