import tqdm


def find_stable_phases(all_compounds, criteria):
    """
    find all compounds with e_above_hull within given range of zero
    args:
        all_compounds - returned from load_compounds (list of dicts)
        criteria - criteria for a stable phase in meV
    output:
        list of dicts of stable phases
    """
    print('Finding Stable Phases....')    
        
    stable_phase = []
    
    #find all compounds with e_above_hull within 0.05 of 0
    for compound in tqdm.tqdm(all_compounds): 
        if abs(compound['e_above_hull']) < criteria/1000:
            stable_phase.append(compound)
    return stable_phase