CJBartel / perovskite-stability

MIT License
35 stars 15 forks source link

Three ambiguous oxidation states #1

Open sthartman opened 5 years ago

sthartman commented 5 years ago

I'm getting a key error for 'Pb' when I attempt to use PredictAABBXX6 for CsPbSnBiO6, since none of the cases defined in chosen_ox_states are true and so the three 'ambiguous' elements are not added to the oxidation dict.

Specifically, what happens is it generates three combos which add to the correct charge value. unspec_els: ['Pb', 'Sn', 'Bi'] good_combos: [(2, 4, 5), (4, 2, 5), (4, 4, 3)] chis: [2.33, 1.96, 2.02]

The minimum chi is less than 0.9 * the max, so we go to spread_combos spread_combos:[(2, 4, 5), (4, 2, 5)] Unfortunately, neither of these satisfy the conditional if combo[mindex] == np.max(combo) and there is no else statement to handle this situation, so the function exits without adding anything to ox_dict

I think in this scenario the most plausible combo is certainly (2,4,5) but I haven't put too much thought into the logic needed to guarantee this choice.

sthartman commented 5 years ago

As a work-around, I'm defining an objective function which compares the elements pairwise and penalizes combos if the more electronegative element of the pair has a higher oxidation state. if np.min(chis) <= 0.9np.max(chis): if len(spread_combos) > 1: ambig = True for combo in spread_combos: if combo[mindex] == np.max(combo): if combo[maxdex] == np.min(combo): ambig = False for idx in range(len(unspec_els)): el = unspec_els[idx] ox_dict[el] = combo[idx] if ambig == True: obj_funs = [] for combo in spread_combos: obj_fun = 0.0 for i in range(len(combo)): for j in range(len(combo)): obj_fun = obj_fun + (chis[i] - chis[j]) (combo[i] - combo[j]) obj_funs.append(obj_fun) best_combo = spread_combos[obj_funs.index(np.min(obj_funs))] for idx in range(len(unspec_els)): el = unspec_els[idx] ox_dict[el] = best_combo[idx]

CJBartel commented 5 years ago

Ah nice, thanks for spotting this (and sorry I'm just getting to this). I like your approach. I'll think about how best to incorporate it.

CJBartel commented 5 years ago

You might also consider checking out https://github.com/CJBartel/compmatscipy/blob/master/compmatscipy/PerovskiteStability.py (see updated README on this repo).