Skip to content

[Bug]: ridiculous limits on MP-API queries #1103

@computron

Description

@computron

Code snippet

"""Minimal repro: exclude_elements query string >60 chars triggers 422."""
from mp_api.client import MPRester

# 23 radioactive elements -> comma-joined string is 72 chars, exceeds API's 60-char cap
RADIOACTIVE = [
    "Tc", "Pm", "Po", "At", "Rn", "Fr", "Ra",
    "Ac", "Th", "Pa", "U", "Np", "Pu", "Am", "Cm",
    "Bk", "Cf", "Es", "Fm", "Md", "No", "Lr",
]

with MPRester() as mpr:
    docs = mpr.materials.summary.search(
        num_elements=(2, 2),
        exclude_elements=RADIOACTIVE,
        fields=["material_id"],
        num_chunks=1,
        chunk_size=1,
    )

# Yields: MPRestError 422 — "exclude_elements - String should have at most 60 characters"

What happened?

I want to query for some structures but exclude radioactive elements.

The extremely conservative MP-API settings doesn't let me exclude so many elements.

So how are people supposed to do this query?

Version

current

Which OS?

  • MacOS
  • Windows
  • Linux

Log output

(atomate2_env) ajain:~/Documents/code_venvs/atomate2_env/Part_2-MongoDB_High_Throughput$ python script2.py 
Traceback (most recent call last):
  File "/Users/ajain/Documents/code_venvs/atomate2_env/Part_2-MongoDB_High_Throughput/script2.py", line 12, in <module>
    docs = mpr.materials.summary.search(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/ajain/Documents/code_venvs/atomate2_env/lib/python3.11/site-packages/mp_api/client/routes/materials/summary.py", line 393, in search
    return super()._search(  # type: ignore[return-value]
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/ajain/Documents/code_venvs/atomate2_env/lib/python3.11/site-packages/mp_api/client/core/client.py", line 1456, in _search
    return self._get_all_documents(
           ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/ajain/Documents/code_venvs/atomate2_env/lib/python3.11/site-packages/mp_api/client/core/client.py", line 1520, in _get_all_documents
    results = self._query_resource(
              ^^^^^^^^^^^^^^^^^^^^^
  File "/Users/ajain/Documents/code_venvs/atomate2_env/lib/python3.11/site-packages/mp_api/client/core/client.py", line 795, in _query_resource
    data = self._submit_requests(
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/ajain/Documents/code_venvs/atomate2_env/lib/python3.11/site-packages/mp_api/client/core/client.py", line 978, in _submit_requests
    data, total_num_docs = self._submit_request_and_process(
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/ajain/Documents/code_venvs/atomate2_env/lib/python3.11/site-packages/mp_api/client/core/client.py", line 1237, in _submit_request_and_process
    raise MPRestError(
mp_api.client.core.exceptions.MPRestError: REST query returned with error status code 422 on URL https://api.materialsproject.org/materials/summary/?nelements_min=2&nelements_max=2&exclude_elements=Tc%2CPm%2CPo%2CAt%2CRn%2CFr%2CRa%2CAc%2CTh%2CPa%2CU%2CNp%2CPu%2CAm%2CCm%2CBk%2CCf%2CEs%2CFm%2CMd%2CNo%2CLr&_limit=1&_fields=material_id with message:
exclude_elements - String should have at most 60 characters

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions