Issue querying pourbaix entries using the mp-api rester

Howdy,

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.

Here are some example combos:

My questions:

  • Is something awry?
  • Should I be weary of the pourbaix results on the old website/ is this error with good cause?

Thank you very much for the help!

Hi @bwander,

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!

Best,

Matt

Hello @mkhorton,

Thank you for the reply!

Kind Regards,

Brook

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.

Best,

Matt

Hello @mkhorton ,

Thanks for looking into this!

Kind Regards,

Brook

Thanks for reporting @bwander and for investigating @mkhorton . I agree with your proposed fix.

ion_ref_comps = [Ion.from_formula(d["formula"]).composition for d in ion_data]

should be

ion_ref_comps = [Composition(d["Reference Solid"]) for d in ion_data]

1 Like

Thanks for chiming in @rkingsbury, appreciate the second pair of eyes!

Ok, this should be fixed with mp-api version 0.20.6 which should be up in a few minutes or so.

I wish I had my slackmoji friend party-blob to properly respond. Thanks so much!

1 Like