Mp-api unavailable for charge density query in Jun 2024

I used some simple Colab scripts in the following link to acquire the charge density of mp-1326:

It did work several weeks ago. However, now it outputs the following error:

/usr/local/lib/python3.10/dist-packages/emmet/core/vasp/calc_types/ in task_type(inputs)
65 calc_type = []
—> 66 incar = inputs.get(“incar”, {})
67 kpts = inputs.get(“kpoints”) or {} # kpoints can be None, then want a dict

AttributeError: ‘NoneType’ object has no attribute ‘get’

I am afraid it may not be a user-side problem, as I have tried multiple versions of pymatgen and mp-api (including the latest, of course) both on Google Colab and my own server. One can recur this issue through the Colab link, which did output the chgcar data last month.

Thanks for reaching out. Try switching to the MPRester in the latest version of the mp-api client instead of pymatgen’s. Also, please use the MP_API_KEY environment variable before sending out a publicly accessible link to a notebook in order to avoid leaking your API key. Thanks. HTH

Hi, thanks for your response. As shown in the Colab page, the latest version of mp-api is installed at the beginning and I’ve switched to from mp_api.client import MPRester instead of using pymatgen. But the problem is exactly the same:

[... skipping hidden 1 frame]

/usr/local/lib/python3.10/dist-packages/emmet/core/vasp/calc_types/ in task_type(inputs)
     65     calc_type = []
---> 66     incar = inputs.get("incar", {})
     67     kpts = inputs.get("kpoints") or {}  # kpoints can be None, then want a dict

AttributeError: 'NoneType' object has no attribute 'get'

Thanks for the follow-up. I can reproduce it. @munrojm is looking into it and will get back to you.

@munrojm Hi Munrojm, just an update that now it says self.calcs_reversed is None.

Retrieving MaterialsDoc documents: 100%
 1/1 [00:00<00:00, 23.05it/s]
TypeError                                 Traceback (most recent call last)
<ipython-input-2-9b0b22d2852a> in <cell line: 12>()
     11 # Fetch the CHGCAR data using Materials Project API
     12 with MPRester(api_key) as mpr:
---> 13     chgcar = mpr.get_charge_density_from_material_id(material_id)
     15 # Get the smooth charge density data

13 frames
    [... skipping hidden 1 frame]

/usr/local/lib/python3.10/dist-packages/emmet/core/ in model_post_init(self, _TaskDoc__context)
    451         # To determine task and run type, we search for input sets in this order
    452         # of precedence: calcs_reversed, inputs, orig_inputs
--> 453         for inp_set in [self.calcs_reversed[0].input, self.input, self.orig_inputs]:
    454             if inp_set is not None:
    455                 break

TypeError: 'NoneType' object is not subscriptable

Follow-up: It is because emmet-core 0.84.1 has a bug. The solution is:

pip install mp-api
pip install emmet-core==0.83.0
#pip install numpy==1.26.4 # numpy 2.0 does not work either