API key problem

I am attempting to run robocrys (robocrys · PyPI).

 robocrys --api-key "<API_KEY>" mp-856

I see the following error:

pymatgen.ext.matproj.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”: “2024-03-19T16:58:03.712455”}’

I suspect that the problem is that robocrys is doing the wrong thing, but any suggestions as to how to check if the API key is valid?

Hi @Ian_Foster, you can check what your API key is here (scroll down to “API Key” while logged in):
https://next-gen.materialsproject.org/api#api-key.

You might also need to update your pymatgen and robocrys packages, since pymatgen 2022.0.8 is quite out of date.

@Ian_Foster it looks like you’re using a legacy API key with robocrys. I just tried an API key for our new / next-gen API (the one @Aaron_Kaplan was eluding to) and the latest version of robocrys. It still results in the following error but that might be a different issue - see

ValueError: Unexpected atomic number Z=119

@tschaume: Both robocrys and matminer are lagging in package support, see matminer issue #920.

@Ian_Foster: you can still get this working as follows. Install matminer from git as:
pip install git+https://github.com/hackingmaterials/matminer.git
And then run get_robocrys_from_mp using the following script with your desired MP ID and API key:

from __future__ import annotations
from robocrys.cli import robocrystallographer
from mp_api.client import MPRester

def get_robocrys_from_mp(mpid : str | int, api_key : str | None = None):

    if isinstance(mpid, int):
        mpid = f"mp-{mpid}"

    with MPRester(api_key=api_key) as mpr:
        structure = mpr.materials.summary.search(material_ids=[mpid])[0].structure
    
    return robocrystallographer(structure = structure)

Sorry about the arcane solution - I’ll need to get a fix into robocrys (it still uses the legacy API and is lagging in support for that) and then both matminer and robocrys need new releases

1 Like