The problem about mpr.materials.summary.search

Hi,

I tried to use “mpr.materials.summary.search” to get the materials by defining several conditions, but always get problems.

Condition1: The materials contain “H”.
Condition 2: The materials that do not contain radioactive elements, non-metal elements.
Condition 3: The number of elements in each compound should be in the range of 2-5.

Below is the code:

elements = [“H”]
excluded_elements = [“Ac”, “Th”, “Pa”, “U”, “Np”, “Pu”, “Am”, “Cm”, “Bk”,
“Cf”, “Es”, “Fm”, “Md”, “No”, “Lr”, “As”, “Pm”, “Rf”,
“Db”, “Sg”, “Tc”, “Bh”, “Hs”, “Mt”, “Ds”, “Rg”, “Cn”,
“Nh”, “Fl”, “Mc”, “Lv”, “Ts”, “Og”, “Po”, “At”, “Rn”,
“S”, “F”, “Br”, “At”, “H”, “C”, “He”, “Ne”, “Ar”, “Kr”,
“Xe”, “Tc”, “Si”, “Fr”, “Ra”, “Se”, “P”, “B”, “At”, “Rn”,
“Cl”, “At”, “He”, “Ne”, “Ar”, “Kr”, “Xe”, “Tc”, “Tl”, “La”,
“Ce”, “Pr”, “Nd”, “Pm”, “Sm”, “Eu”, “Gd”, “Tb”, “Dy”, “Ho”,
“Er”, “Tm”, “Yb”, “Lu”, “As”, “Te”, “Si”, “N”, “I”, “O”]

#'nelements':1

# Specify the properties to retrieve

properties = [‘material_id’,‘nsites’, ‘elements’, ‘nelements’, ‘composition’, ‘composition_reduced’, ‘formula_pretty’,
‘chemsys’, ‘volume’, ‘density’, ‘density_atomic’, ‘symmetry’, ‘property_name’, ‘last_updated’, ‘origins’, ‘structure’, ‘task_ids’,
‘uncorrected_energy_per_atom’, ‘spacegroup_number’,’ spacegroup_symbol’,‘structure’,
‘energy_per_atom’, ‘formation_energy_per_atom’, ‘energy_above_hull’, ‘is_stable’, ‘equilibrium_reaction_energy_per_atom’,
‘decomposes_to’, ‘band_gap’, ‘cbm’, ‘vbm’, ‘efermi’, ‘is_gap_direct’, ‘is_metal’]

# Search for summaries matching the criteria and properties

summaries = m.materials.summary.search(elements=elements, exclude_elements=excluded_elements, num_elements=[2,6], fields=properties)

data = []
for summary in summaries:
data.append(summary)

The problem is

“MPRestError: REST query returned with error status code 422 on URL https://api.materialsproject.org/materials/summary/?nelements_min=2&nelements_max=6&elements=H&exclude_elements=Ac%2CTh%2CPa%2CU%2CNp%2CPu%2CAm%2CCm%2CBk%2CCf%2CEs%2CFm%2CMd%2CNo%2CLr%2CAs%2CPm%2CRf%2CDb%2CSg%2CTc%2CBh%2CHs%2CMt%2CDs%2CRg%2CCn%2CNh%2CFl%2CMc%2CLv%2CTs%2COg%2CPo%2CAt%2CRn%2CS%2CF%2CBr%2CAt%2CH%2CC%2CHe%2CNe%2CAr%2CKr%2CXe%2CTc%2CSi%2CFr%2CRa%2CSe%2CP%2CB%2CAt%2CRn%2CCl%2CAt%2CHe%2CNe%2CAr%2CKr%2CXe%2CTc%2CTl%2CLa%2CCe%2CPr%2CNd%2CPm%2CSm%2CEu%2CGd%2CTb%2CDy%2CHo%2CEr%2CTm%2CYb%2CLu%2CAs%2CTe%2CSi%2CN%2CI%2CO&_limit=1000&_fields=material_id%2Cnsites%2Celements%2Cnelements%2Ccomposition%2Ccomposition_reduced%2Cformula_pretty%2Cchemsys%2Cvolume%2Cdensity%2Cdensity_atomic%2Csymmetry%2Cproperty_name%2Clast_updated%2Corigins%2Cstructure%2Ctask_ids%2Cuncorrected_energy_per_atom%2Cspacegroup_number%2C+spacegroup_symbol%2Cstructure%2Cenergy_per_atom%2Cformation_energy_per_atom%2Cenergy_above_hull%2Cis_stable%2Cequilibrium_reaction_energy_per_atom%2Cdecomposes_to%2Cband_gap%2Ccbm%2Cvbm%2Cefermi%2Cis_gap_direct%2Cis_metal with message:
exclude_elements - String should have at most 15 characters”

Could you help to check it?
Thank you very much.

Xue

You’re providing too many elements to exclude. Use condition #1 to query the API and retrieve all results. Then filter the results locally on your machine.

Hi,

Thank you very much for your supporting.

I deleted the code about excluding many elements. The program is running now.