New issues with materialsvirtuallab notebook and cohesive energy

Hi

For my research I am often looking for cohesive energies of compound, which I need to interrogate the API for. In the past I simply launch a notebook using:

https://hub.gke2.mybinder.org/user/materialsvirtuallab-matgenb-yauaypxc/lab/workspaces/auto-B/tree/notebooks/2013-01-01-Getting%20crystal%20structures%20from%20online%20sources.ipynb

I then just modify something for my own purpose and it has always worked fine:

from pymatgen.ext.matproj import MPRester
mpr = MPRester(“insert my ID”)
mpr.get_cohesive_energy(‘mp-6124’, per_atom=True)

Now for some reason as of yesterday I get this issue for cohesive energy

Does anyone know why all of sudden this isn’t working?:


TypeError Traceback (most recent call last)
in
1 # Querying by formula only.
2
----> 3 mpr.get_cohesive_energy(‘mp-6124’, per_atom=True)

/srv/conda/envs/notebook/lib/python3.7/site-packages/pymatgen/ext/matproj.py in get_cohesive_energy(self, material_id, per_atom)
1310 Cohesive energy (eV).
1311 “”"
→ 1312 entry = self.get_entry_by_material_id(material_id)
1313 ebulk = entry.energy / entry.composition.get_integer_formula_and_factor()[1]
1314 comp_dict = entry.composition.reduced_composition.as_dict()

/srv/conda/envs/notebook/lib/python3.7/site-packages/pymatgen/ext/matproj.py in get_entry_by_material_id(self, material_id, compatible_only, inc_structure, property_data, conventional_unit_cell)
747 inc_structure=inc_structure,
748 property_data=property_data,
→ 749 conventional_unit_cell=conventional_unit_cell,
750 )
751 return data[0]

/srv/conda/envs/notebook/lib/python3.7/site-packages/pymatgen/ext/matproj.py in get_entries(self, chemsys_formula_id_criteria, compatible_only, inc_structure, property_data, conventional_unit_cell, sort_by_e_above_hull)
563 with warnings.catch_warnings():
564 warnings.filterwarnings(“ignore”, message=“Failed to guess oxidation states.*”)
→ 565 entries = MaterialsProject2020Compatibility().process_entries(entries, clean=True)
566 if sort_by_e_above_hull:
567 entries = sorted(entries, key=lambda entry: entry.data[“e_above_hull”])

/srv/conda/envs/notebook/lib/python3.7/site-packages/pymatgen/entries/compatibility.py in process_entries(self, entries, clean, verbose)
557 processed_entry_list = []
558
→ 559 for entry in PBar(entries, disable=(not verbose)):
560 ignore_entry = False
561 # if clean is True, remove all previous adjustments from the entry

/srv/conda/envs/notebook/lib/python3.7/site-packages/pymatgen/util/sequence.py in init(self, total, **kwargs)
36 self.total = total
37 self.done = 0
—> 38 self.report()
39
40 def update(self, amount):

/srv/conda/envs/notebook/lib/python3.7/site-packages/pymatgen/util/sequence.py in report(self)
52 Print progress.
53 “”"
—> 54 print("{} of {} done {:.1%}".format(self.done, self.total, self.done / self.total))
55
56

TypeError: unsupported operand type(s) for /: ‘int’ and ‘list’

I was able to recreate the bug, but only using a notebook running in the matgenb binder hub. I was able to fix the problem by installing the tqdm package, which is used for progress bars:

pip install tqdm

You can run this in terminal, or in Jupyter by using an exclamation point, i.e. !pip install tqdm

Let me know if this works for you?

I have the same issue.
tqdm is already installed.
I have got pymatgen using “pip install pymatgen --no-binary pymatgen --upgrade” in a conda environment on latest Ubuntu.
The error appears after executing “mpr.get_pourbaix_entries([“Cu”])”
Let me know what kind of information shold I share to give you better description of the issue.

Hi all, this solution worked for a while but coming back to it now I am getting a new issue, I add in my MPR, install tqdm, but cannot get it to work.

MPRestError Traceback (most recent call last)
/srv/conda/envs/notebook/lib/python3.7/site-packages/pymatgen/ext/matproj.py in _make_request(self, sub_url, payload, method, mp_decode)
253
→ 254 raise MPRestError(“REST query returned with error status code {}”.format(response.status_code))
255

MPRestError: REST query returned with error status code 403

During handling of the above exception, another exception occurred:

MPRestError Traceback (most recent call last)
/tmp/ipykernel_132/2749567356.py in
----> 1 mpr.get_cohesive_energy(‘mp-721988’, per_atom=True)

/srv/conda/envs/notebook/lib/python3.7/site-packages/pymatgen/ext/matproj.py in get_cohesive_energy(self, material_id, per_atom)
1310 Cohesive energy (eV).
1311 “”"
→ 1312 entry = self.get_entry_by_material_id(material_id)
1313 ebulk = entry.energy / entry.composition.get_integer_formula_and_factor()[1]
1314 comp_dict = entry.composition.reduced_composition.as_dict()

/srv/conda/envs/notebook/lib/python3.7/site-packages/pymatgen/ext/matproj.py in get_entry_by_material_id(self, material_id, compatible_only, inc_structure, property_data, conventional_unit_cell)
747 inc_structure=inc_structure,
748 property_data=property_data,
→ 749 conventional_unit_cell=conventional_unit_cell,
750 )
751 return data[0]

/srv/conda/envs/notebook/lib/python3.7/site-packages/pymatgen/ext/matproj.py in get_entries(self, chemsys_formula_id_criteria, compatible_only, inc_structure, property_data, conventional_unit_cell, sort_by_e_above_hull)
522 else:
523 criteria = chemsys_formula_id_criteria
→ 524 data = self.query(criteria, props)
525
526 entries = []

/srv/conda/envs/notebook/lib/python3.7/site-packages/pymatgen/ext/matproj.py in query(self, criteria, properties, chunk_size, max_tries_per_chunk, mp_decode)
991 count_payload = payload.copy()
992 count_payload[“options”] = json.dumps({“count_only”: True})
→ 993 num_results = self._make_request("/query", payload=count_payload, method=“POST”)
994 if num_results <= chunk_size:
995 return self._make_request("/query", payload=payload, method=“POST”, mp_decode=mp_decode)

/srv/conda/envs/notebook/lib/python3.7/site-packages/pymatgen/ext/matproj.py in _make_request(self, sub_url, payload, method, mp_decode)
256 except Exception as ex:
257 msg = “{}. Content: {}”.format(str(ex), response.content) if hasattr(response, “content”) else str(ex)
→ 258 raise MPRestError(msg)
259
260 def get_database_version(self):

MPRestError: REST query returned with error status code 403. Content: b’{“valid_response”: false, “error”: “API_KEY is not a valid key.”, “version”: {“db”: “2020_09_08”, “pymatgen”: “2022.0.8”, “rest”: “2.0”}, “created_at”: “2022-05-27T11:15:53.023977”}’