The Problem:
I have noticed that for certain combinations of elements, I am unable to query the pourbaix entries using the new mp-api rester. I get the following error:
/tmp/ipykernel_781/2026962356.py in get_pourbaix_info(mpid)
29 if len(comp) != 0:
30 # Query the pourbaix entries
---> 31 pbx_entries = mpr.get_pourbaix_entries(comp)
32 for entry in pbx_entries:
33 if entry.entry_id == mpid:
/opt/conda/lib/python3.8/site-packages/mp_api/client.py in get_pourbaix_entries(self, chemsys, solid_compat, use_gibbs)
528 ion_ref_pd = PhaseDiagram(ion_ref_entries)
529
--> 530 ion_entries = self.get_ion_entries(ion_ref_pd, ion_ref_data=ion_data)
531 pbx_entries = [PourbaixEntry(e, f"ion-{n}") for n, e in enumerate(ion_entries)]
532
/opt/conda/lib/python3.8/site-packages/mp_api/client.py in get_ion_entries(self, pd, ion_ref_data)
696 ]
697 if not refs:
--> 698 raise ValueError("Reference solid not contained in entry list")
699 stable_ref = sorted(refs, key=lambda x: x.energy_per_atom)[0]
700 rf = stable_ref.composition.get_reduced_composition_and_factor()[1]
ValueError: Reference solid not contained in entry list
When I search these combos on the old website, it constructs the diagram just fine. On the new website, the following message is displayed:
No pourbaix diagram generated. Search by elements to generate a pourbaix diagram.
Yes, something is definitely awry. I’ve been trying to track down this same bug for certain Pourbaix diagrams on the website. @rkingsbury who wrote a lot of the new Pourbaix API methods may also be able to shed some light.
A minimal example is simply for the C chemical system. Here, the ion reference data (MPRester.get_ion_reference_data_for_chemsys) returns a list of 17 entries, each of which have the reference solid (RefSolid) of Na2CO3.
Since the Na2CO3 phase is not in the ion_ref_pd (which is just the C-H-O chemical system and contains C, O2, H2O, CO2, H2), this line leads to refs=[] and the error that you see.
A similar issue is present for, say, Cl because of the presence of the NaCl and Na2CO3 reference solids. However, most elements are not affected, e.g. Ag because its reference is just Ag2O which is going to be present in the ion_ref_pd.
So, in short, definitely a bug, but I’m not sure what the correct fix is just yet!
No worries. I had a bit more time to look into this.
In the legacy MPRester, this line ensures that Na is also requested when constructing the list of ion reference entries and the ion reference phase diagram.
Therefore, I think the underlying bug in the new API ultimately comes from these lines. The correct fix would be to use d["RefSolid"] here instead of d["formula"]. @rkingsbury can you confirm this is an appropriate fix?
@bwander to your original question, I believe Pourbaix diagrams generated with the new API are correct as long as you don’t encounter this ValueError, i.e. if it works at all then it’s correct. We should be able to get this fixed soon.