<jupyter_start><jupyter_text>EXAMPLE: LLZO ELECTROCHEMICAL STABILITY COMPUTATION<jupyter_code>oxidations, reductions = \
            stability_window({'Li': 7.0, 'La': 3.0, 'Zr': 2.0, 'O': 12.0}, mpr, verbosity=False, 
                             icsd=True, remove_non_comp_ox = 0  )<jupyter_output><empty_output><jupyter_text>Visualization of LLZO results<jupyter_code># OXIDATION: 
#
# Reults here contains for each oxidation reaction 
# a tuple of the form (potential,error_on_potential, products, stoichio_coeff) 
#
# They are listed in increasing order so that the limit oxidation reaction is the first one

# if errore = True potentials with error larger than 0.5 eV are neglected

errore=True
error_cutoff=0.5

if (errore):

    results = [ (pot,err, [prod_['formula'] for prod_ in prod],coeff) 
             for pot, err, prod, coeff in 
               sorted(zip(oxidations['pot'],oxidations['error'],oxidations['products'],oxidations['coeffs']), 
                                          key=lambda pair: pair[0]) if  err< error_cutoff ]# np.abs(err/pot)<2.0 ]
else:
    results = [ (pot,err, [prod_['formula'] for prod_ in prod],coeff) 
             for pot, err, prod, coeff in 
               sorted(zip(oxidations['pot'],oxidations['error'],oxidations['products'],oxidations['coeffs']), 
                                          key=lambda pair: pair[0]) ]

print('POSSIBLE OXIDATION REACTIONS \n')
results[0:10]
# REDUCTIONS: 
#
# Reults here contains for each reduction reaction 
# a tuple of the form (potential,error_on_potential, products, stoichio_coeff) 
#
# They are listed in decreasing order so that the limit reduction reaction is the first one

# if errore = True potentials with error larger than 0.5 eV are neglected


error=True
error_cutoff=0.5

if (error):

    results = [ (pot,err, [prod_['formula'] for prod_ in prod],coeff) 
         for pot, err, prod, coeff in 
           sorted(zip(reductions['pot'],reductions['error'],reductions['products'],reductions['coeffs']), 
                                      reverse=True,key=lambda pair: pair[0]) if err < error_cutoff ] #np.abs(err/pot)< 1.0 ]
else:
    
    results = [ (pot,err, [prod_['formula'] for prod_ in prod],coeff) 
         for pot, err, prod, coeff in 
           sorted(zip(reductions['pot'],reductions['error'],reductions['products'],reductions['coeffs']), 
                                      reverse=True,key=lambda pair: pair[0]) ]
    
print('POSSIBLE REDUCTION REACTIONS \n')
results[0:10]
# OXIDATIONS
#
# We plot here as a function of the error cutoff the potential of the minimum oxidation potential found.
# For each error cutoff, potentials with error larger than error_cutoff are neglected
# Such analyisis can help to investigate the error on the final result
#

minimum=[]
minimum_error=[]
chosen= [0.5,0.75,1.0,1.25,1.5]
for error_ in chosen:
    error=True

    if (error):

        results = [ (pot,err, [prod_['formula'] for prod_ in prod],coeff) 
             for pot, err, prod, coeff in 
               sorted(zip(oxidations['pot'],oxidations['error'],oxidations['products'],oxidations['coeffs']), 
                                          reverse=False, key=lambda pair: pair[0]) if err < error_ ] #np.abs(err/pot)< 1.0 ]
    else:

        results = [ (pot,err, [prod_['formula'] for prod_ in prod],coeff) 
             for pot, err, prod, coeff in 
               sorted(zip(oxidations['pot'],oxidations['error'],oxidations['products'],oxidations['coeffs']), 
                                          reverse=False, key=lambda pair: pair[0]) ]
        
    minimum.append(results[0][0])
    minimum_error.append(results[0][1])
    
plt.ylabel('Potential - oxidation')
plt.xlabel('Error-cutoff')

plt.plot(chosen,minimum)
plt.errorbar(chosen,minimum,yerr=minimum_error)
# REDUCTIONS
#
# We plot here as a function of the error cutoff the potential of the minimum oxidation potential found.
# For each error cutoff, potentials with error larger than error_cutoff are neglected
# Such analyisis can help to investigate the error on the final result
#

minimum=[]
minimum_error=[]
chosen= [0.25,0.5,0.75,1.0,1.25,1.5,2.0,3.0,4.0]
for error_ in chosen:
    error=True

    if (error):

        results = [ (pot,err, [prod_['formula'] for prod_ in prod],coeff) 
             for pot, err, prod, coeff in 
               sorted(zip(reductions['pot'],reductions['error'],reductions['products'],reductions['coeffs']), 
                                          reverse=True,key=lambda pair: pair[0]) if err < error_ ] #np.abs(err/pot)< 1.0 ]
    else:

        results = [ (pot,err, [prod_['formula'] for prod_ in prod],coeff) 
             for pot, err, prod, coeff in 
               sorted(zip(reductions['pot'],reductions['error'],reductions['products'],reductions['coeffs']), 
                                          reverse=True,key=lambda pair: pair[0]) ]
        
    minimum.append(results[0][0])
    minimum_error.append(results[0][1])
    
plt.ylabel('Potential - reduction')
plt.xlabel('Error-cutoff')

plt.plot(chosen,minimum)
plt.errorbar(chosen,minimum,yerr=minimum_error)<jupyter_output><empty_output><jupyter_text>INSPECT SELECTED INSTABILITY REACTIONS<jupyter_code>reagent=download_and_filter_formula([{'Li': 7.0, 'La': 3.0, 'Zr': 2.0, 'O': 12.0}],mpr, verbosity=True, icsd=False)

products_red=download_and_filter_formula([ {'Li': 2.0, 'O': 1.0},{'La': 1.0},
                                  {'Li': 6, 'O': 7, 'Zr': 2},{'Li': 1}],mpr,verbosity=True, icsd=False)

products_ox=download_and_filter_formula([ {'Li': 2.0, 'O': 2.0},{'La': 2.0, 'O': 3.0},
                                 {'Li': 6, 'O': 7, 'Zr': 2},{'Li': 1}],mpr,verbosity=True, icsd=False)

print(compute_potential(reagent, products_ox, verbosity=True))
print(compute_potential(reagent, products_red, verbosity = True))<jupyter_output>download_and_filter_formula
{'Li': 7.0, 'La': 3.0, 'Zr': 2.0, 'O': 12.0}
Elapsed time for downloading:  1.4825401306152344
filter_compounds_formula
{'Li': 7.0, 'La': 3.0, 'Zr': 2.0, 'O': 12.0}
96 0
0 -7.139211504375001 -7.139211504375001 96
0
End filter compounds formula---- 

 End download and filter formula---- 

download_and_filter_formula
{'Li': 2.0, 'O': 1.0}
Elapsed time for downloading:  1.486400842666626
filter_compounds_formula
{'Li': 2.0, 'O': 1.0}
102 5
0 -4.590261840392157 -4.590261840392157 102
1 -4.669131471666667 -4.669131471666667 12
2 -4.602423630686275 -4.602423630686275 102
3 -4.593584400392157 -4.593584400392157 102
4 -4.754507463333334 -4.754507463333334 3
5 -4.578540282156863 -4.578540282156863 102
3
End filter compounds formula---- 

{'La': 1.0}
Elapsed time for downloading:  0.6051418781280518
filter_compounds_formula
{'La': 1.0}
4 1
0 -4.80448641 -4.80448641 1
1 -4.9265915325 -4.9265915325 4
2 -4.92327123 -4.92327123 1
1
End filter compounds formula---- 

{'Li'[...]
{'fraction_non_alphanumeric': 0.1404994888272236, 'fraction_numerical': 0.07536147217759603, 'mean_word_length': 3.229771463866584, 'pattern_counts': {'":': 0, '<': 20, '<?xml version=': 0, '>': 12, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 25, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '395718', 'license': 'MIT', 'n_tokens_mistral': 2696, 'n_tokens_neox': 2316, 'n_words': 575, 'path': 'Example.ipynb', 'repo_name': 'zrl-aiida-toolbox/Phase-stability-analyzer', 'size': '6847'}