Query data from MP

I was trying to query the data from MP using MPRester, but ran into a really weird problem. Below is the codes I used:

from pymatgen import MPRester, Composition

mpr = MPRester()
data = mpr.query(criteria = {‘elements’: [‘Ti’, ‘O’], ‘nelements’: 2},
properties=[“formation_energy_per_atom”, “energy”, “unit_cell_formula”,
‘nsites’, ‘spacegroup’])
len(data)

However, the length in data is 0, which is apparently wrong. But if I change ‘Ti’ to ‘Fe’, I can get the data. Any idea why it happens? What did I do wrong?

Hi jlc198,

Generally queries trying to match array subfields are order-specific, and element arrays are ordered alphabetically, so the following works:

mpr = MPRester()
data = mpr.query(criteria={"elements": ["O", "Ti"], "nelements": 2}, 
                 properties=['formation_energy_per_atom', 'energy', 
                             'unit_cell_formula', 'nsites', 'spacegroup'])
len(data)
>>> 84

If you’d like to do a match on all of the fields of elements while constraining nelements, you can use the $all operator to do this in an order-agnostic way, e. g.

mpr = MPRester()
data = mpr.query(criteria={"elements": {"$all": ["Ti", "O"]}, 
                           "nelements": 2}, 
                 properties=['formation_energy_per_atom', 'energy', 
                             'unit_cell_formula', 'nsites', 'spacegroup'])
len(data)
>>> 84

Is there a way to list all the properties that are available in MP?

Hi @Federico_Ottomano,

this is a very old thread that only applies to our legacy API which does not receive data updates or maintenance anymore. Please see our docs for help with our new API and python client mp-api.

As for a list of properties, here are a few options I can think of:

  • under the Calculated Properties filter in the materials explorer.
  • in the doc strings or MPDataDoc.available_fields of mp-api (see above docs)
  • in the API docs

HTH

Thread closed due to inactivity, please open a new thread to address related issues.