Error for get_pourbaix_entries with new mp_api


I am trying to get elemental proubaix data with get_pourbaix_entries() function with the new MPRester from mp_api.client, but I got the following errors. It used to work with old pymatgen MPRester. How should I fix this?

Thank you.

Did you install the mpcontribs-client? It looks like MPRester.contribs is set to None which means there should be a warning or error message when you import MPRester. Do you see any message during importing MPRester?

I just installed mpcontrbs-client with “pip install mpcontribs-client”, but I still get the same error.
When I import MPRester, I got following messages.

Thanks for reporting this! The URL to the CFFI documentation suggests that this is an issue affecting specific operating systems. I’ll look into it and will try to release a new version of mpcontribs-client that hopefully circumvents the problem. In the meantime, you might have to use an OS that isn’t as restrictive with write+execute memory.

@johan28 mpcontribs-client==4.5.0 should not have the cffi error anymore. Please give it a try. Thanks!

Hi tschaume,

The problem was solved before after the update of mpcontribs-client, but I recently got similar error again.

Hi johan28,

this is due to a change in the operation IDs for the MPContribs API that went out today. Please upgrade to the latest mp-api==0.30.5 and mpcontribs-client==5.0.4.


I am facing the same issue again when using new API. I used mp-api==0.30.5 and mpcontribs-client==5.0.4. But facing the error given below.

AttributeError                            Traceback (most recent call last)
<ipython-input-25-8e0003795b0e> in <module>
      1 # Get all pourbaix entries corresponding to the Cu-O-H chemical system.
----> 2 entries = mpr.get_pourbaix_entries(["Nb", "C", "O"])

/usr/local/lib/python3.8/dist-packages/mp_api/client/ in get_pourbaix_entries(self, chemsys, solid_compat, use_gibbs)
    630         # download the ion reference data from MPContribs
--> 631         ion_data = self.get_ion_reference_data_for_chemsys(chemsys)
    633         # build the PhaseDiagram for get_ion_entries

/usr/local/lib/python3.8/dist-packages/mp_api/client/ in get_ion_reference_data_for_chemsys(self, chemsys)
    749         """
--> 751         ion_data = self.get_ion_reference_data()
    753         return [d for d in ion_data if d["data"]["MajElements"] in chemsys]

/usr/local/lib/python3.8/dist-packages/mp_api/client/ in get_ion_reference_data(self)
    710                 compounds and aqueous species, Wiley, New York (1978)'}}
    711         """
--> 712         return self.contribs.query_contributions(
    713             query={"project": "ion_ref_data"}, fields=["identifier", "formula", "data"], paginate=True
    714         ).get("data")

~/.local/lib/python3.8/site-packages/mpcontribs/client/ in query_contributions(self, query, fields, sort, paginate, timeout)
   1558         project_names = list(project_names)
-> 1560         if not skip_dupe_check and len(collect_ids) != len(contributions):
   1561             unique_identifiers = self.get_unique_identifiers_flags(projects=project_names)
   1562             existing = defaultdict(dict, self.get_all_ids(

~/.local/lib/python3.8/site-packages/mpcontribs/client/ in get_all_ids(self, query, include, timeout, data_id_fields, fmt, op)
   1460             if is_public and not resp["is_approved"]:
   1461                 return {"error": f"project `{query['project']}` is not approved yet!"}
-> 1462 
   1463             resp = self.projects.updateProjectByName(
   1464                 pk=query["project"], project={"is_public": is_public}

~/.local/lib/python3.8/site-packages/mpcontribs/client/ in get_totals(self, query, timeout, resource, op)
   1347             serializable, error = self._is_serializable_dict(data["data"])
   1348             if not serializable:
-> 1349                 return {"error": error}
   1351         query = query or {}

~/.local/lib/python3.8/site-packages/mpcontribs/client/ in _run_futures(futures, total, timeout, desc, disable)
    499                 for column in columns[key]:
--> 500                     param_name = f"{column}__{op}"
    501                     param_spec = deepcopy(param.param_spec)
    502                     param_spec["name"] = param_name

/usr/local/lib/python3.8/dist-packages/tqdm/ in __init__(self, *args, **kwargs)
    243             self.displayed = True
    244         self.disp = self.display
--> 245         self.colour = colour
    247         # Print initial bar state

/usr/local/lib/python3.8/dist-packages/tqdm/ in colour(self, bar_color)
    202     def colour(self, bar_color):
    203         if hasattr(self, 'container'):
--> 204             self.container.children[-2].style.bar_color = bar_color
    206     def __init__(self, *args, **kwargs):

AttributeError: 'FloatProgress' object has no attribute 'style'

@nihal I unfortunately can’t reproduce your error with mp_api==0.33.3, pymatgen==2023.7.17, and mpcontribs-client==5.4.2. Try upgrading to these versions.

@tschaume Thanks for the response. I am using following code with the updated versions but still getting the same error.
!pip install pymatgen==2023.7.17
!pip install mp-api==0.33.3
!pip install mpcontribs-client==5.4.2

#NOTE - make sure to paste your new API key below.
MP_API_KEY = “----------------”

from mp_api.client import MPRester
from pymatgen.analysis.pourbaix_diagram import PourbaixDiagram, PourbaixPlotter
%matplotlib inline

Initialize the MP Rester

mpr = MPRester(MP_API_KEY)
entries = mpr.get_pourbaix_entries ([“Cu”])

@nihal the error message tells me that your code is actually not using the latest version of mpcontribs-client. Make sure to use the right python environment and restart your jupyter notebook after upgrading.

@tschaume Thanks. it worked for me.

Hi tschaume @tschaume , I used the latest mp-api==0.30.5 and mpcontribs-client==5.0.4 but got a KeyError below

@Ruihan_Li please try to upgrade to the latest versions of pymatgen, mp-api, and mpcontribs-client.

Hi tschaume, @tschaume
Thank you for the suggestions! I am able to get the Pourbaix diagram but could not get the heatmap for my materials. I got a ValueError indicating a composition mismatch (snapshot 2) but I was able to find it in the entries (snapshot 3). Is it related to the stoichiometry? The material features FeMn7O10Cl3. The entry ID provided in the snapshot is also correct.

Thread closed due to inactivity, please open a new thread to address related issues.