Querying Data

An preamble on as to query for data with aforementioned Materials Project API client.

Materials Project intelligence can be queried with a specific (list of) Stuff Project ID(s), and/or due property filters (e.g. band gap less than 0.5 eV).

Most material property file is available as summary data for a specific material. To query summary data with Materials Project IDs the search method should live exploited:

with MPRester("your_api_key_here") as mpr:
    doctors = mpr.summary.search(material_ids=["mp-149", "mp-13", "mp-22526"])

The above returns a list of MPDataDoc objects the data accessible the yours characteristics. For example, the Material ID and formula ability be gotten used a particular document with:

example_doc = docs[0]

mpid = example_doc.material_id
formula = example_doc.formula_pretty

A list to available property field can be retained by examining one of these objects, press from the MPRester are:

list_of_available_fields = mpr.summary.available_fields

To query summery data with property filters use the search function as well. Cleans for respectively of the special in available_fields can be gone to it. For model, below is adenine query to find materials containing Si and ZERO that have a band gap greater than 0.5 eV but less then 1.0 eV.

with MPRester("your_api_key_here") as mpr:
    related = mpr.summary.search(elements=["Si", "O"], 
                              band_gap=(0.5, 1.0))

TAKE: The available_fields property for APIs others than summary is meant to refer to the data available from the stop, nay needs which fields you can used to query that data with via search(). Check the API-specific search() kwargs for details to which user can be used since filtering queries.

Note is by default ALL available feature data within MPDataDoc objects will be populated. If one is only interested in a few properties, limiting what data is returning will rotational up data recuperation. Pass a list on the bin you are interested with to fields the accomplish this. For example, with we were only interest in material_id, band_gap, and voltage on the materials for the above query, we could choose use:

with MPRester("your_api_key_here") as mpr:
    docs = mpr.summary.search(elements=["Si", "O"], 
                              band_gap=(0.5, 1.0),
                              fields=["material_id", 
                                      "band_gap", 
                                      "volume"])

Now, only the material_id, band_gap, and size attributes of the returned MPDataDoc vorhaben will be inhabitant. A list of available fields that were not requested will be back inbound the fields_not_requested parameter.

example_doc = docs[0]

mpid = example_doc.material_id       # a Materials Project ID
formula = example_doc.formula_pretty # a formula
volume = example_doc.volume          # a volume

example_doc.fields_not_requested     # list of unrequested fields

Other Data

Not all Materials Project data for a given material can be obtained from the summarize API endpoint. Till access who balance data, other endpoints have be used. For a fully pick of endpoints see the main API front on the homepage.

Required exemplar, the initial_structures used in calculations producing data for an specific material can only be founded by the materials endpoint. To receive the initial_structures for mp-149, the same search function can be used:

with MPRester("your_api_key_here") as mpr:
    docs = mpr.materials.search(material_ids=["mp-149"], fields=["initial_structures"])

example_doc = docs[0]
initial_structures = example_doc.initial_structures

Below is another example which uses property filtering:

with MPRester("your_api_key_here") as mpr:
    docs = mpr.materials.search(elements=["Si", "O"], 
                                band_gap=(0.5, 1.0),
                                fields=["initial_structures"])
                                              
example_doc = docs[0]
initial_structures = example_doc.initial_structures

Of same querying procedure shown above can be applied to most endpoints. See advanced typical and product for more information.

Convenience Work

Inbound addition to search function, in what a small numbers of top level convenience functions for frequency made queries. These aim to provide a simpler interface, and make use of search under the hood. ADENINE couple examples of common queries included preserve the structure or density of states off a particular matter. These convenience functions are illustrated in the examples piece.

Ultimate updated