Dear MP team.
It’s been a while 
I am trying to query all the entries in MP that contain a list of elements. Here is the code snippet I’ve used:
elements = ['Li', 'La', 'Zr', 'Ta', 'O', 'W', 'F', 'Fe', 'Ga', 'Al', 'Nb']
mpr.get_entries_in_chemsys(elements)
But I got this error:
MPRestError: REST query returned with error status code 414. Content: b'URI too long\n'
I tried reducing the number of elements in that list and error disappeared. So it seems I was querying more information than the MPRest can handle? Is there a workaround to resolve this error?
Thank you!
Jianli
Hi @Jianli_Cheng,
Well you found the workaround yourself
→ use a smaller list
That said though, your elements list generates 2047 combinations. The max number of elements in MP right now is nine, so for your list of 11 elements you’re generating a bunch of junk combinations for len > nine (only 12, but point stands) and for chemical systems that don’t exist.
So overall suggestion would be, pick your target chemical systems (the large/parent chemical systems you want to enumerate [ostensibly, to build phase diagrams?]), do a bit of exploratory querying to see if those chemical systems exist, then prepare your queries accordingly → i.e., don’t mix disjoint chemical systems into one query.
Just to add on to what @tsmathis said (messages crossed in the pipes), if all you want is the entries which contain any combination of just those elements (so Al2O3 would be fine, but AlP would not), then this is what you might want to try:
from mp_api.client import MPRester
subset_elements = {'Li', 'La', 'Zr', 'Ta', 'O', 'W', 'F', 'Fe', 'Ga', 'Al', 'Nb'}
with MPRester() as mpr:
mat_docs = mpr.materials.search(fields=["composition","material_id"])
subset_mat_docs = [
doc
for doc in mat_docs
if {ele.value for ele in doc.composition.elements}.difference(subset_elements) == set()
]
entries = mpr.get_entries(chemsys_formula_mpids = [doc.material_id for doc in subset_mat_docs])
^ great example of doing a bit exploratory querying prior to sending off a big request
Thank you so much for your reply @tsmathis @Aaron_Kaplan .
I got this error when running the code snippet @Aaron_Kaplan shared:
AttributeError: 'Materials' object has no attribute 'search'
I am using mp-api==0.46.0
You might want to do a clean install of mp-api - the code snippet was working for me with mp-api==0.46.0