• This repository has been archived on 27/Aug/2022
  • Stars
    star
    140
  • Rank 259,936 (Top 6 %)
  • Language
    Jupyter Notebook
  • License
    BSD 3-Clause "New...
  • Created over 9 years ago
  • Updated about 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Public repo for Materials API documentation

Important Notice

The Materials Project API is changing. For the latest information, consult the Materials Project documentation at https://docs.materialsproject.org and this page specifically to read more about the differences between the new and legacy APIs.

This repository is archived and is no longer being updated.


Introduction

This is the public repo for the documentation of the Materials API. The Materials API is a simple, flexible and efficient interface to programmatically query and interact with the Materials Project database based on the REpresentational State Transfer (REST) pattern for the web. Since its creation in Aug 2012, the Materials API has been the Materials Project’s de facto platform for data access, supporting not only the Materials Project’s many collaborative efforts but also enabling new applications and analyses.

Example notebooks

We have added a few example ipython notebooks demonstrating the features of the Materials API. The NB Viewer version is at this link. Also, you can use the Binder service (in beta) to launch an interactive notebook right now! Click the button below to open our introductory notebook. To nagivate to other notebooks, go to "File->Open" within the page and click example_notebooks to open one of them.

Binder

Using this repo

The usage of this repo follows a REST format. The primary use of this repo is to explore the Materials Project's document format and use that info for much more powerful queries with the pymatgen (Python Materials Genomics) MPRester.query() method. For more standard queries, the Materials API already has a wiki page and pymatgen already provides useful high-level functions for them.

  1. Start from the materials directory in this repo. The nested directory structure follows the MongoDB json-like document schema for the Materials Project's materials collection.

  2. In each folder, there is a README.md that describes what that key is. For example, in materials/final_energy, the README.md informs you that the final_energy key refers final calculated energy of the material. Similarly, the materials/task_id informs you that the task_id key is in fact the materials id for the Materials Project.

  3. To use this in MPRester, one may use the following code:

    from pymatgen import MPRester
    m = MPRester()
    data = m.query(criteria={"task_id": "mp-1234"}, properties=["final_energy"])
    print(data)

    The data obtained is then [{u'final_energy': -26.94736193}]. Note that the data returned is always a list of dicts.

  4. For a more complicated example, you can try:

    data = m.query(criteria={"pretty_formula": "Li2O"}, properties=["spacegroup.symbol"])

    You can identify the appropriate key by going to the materials/spacegroup/symbol subfolder. This means that the desired information is in spacegroup.symbol (concantenate all subfolders with "." and drop the initial "materials" prefix).

  5. One more very complicated example. Let's say you would like to query for the tags and icsd_ids of all materials containing Fe and O, and perhaps other elements.

    data = m.query(criteria={"elements": {"$all": ["Fe", "O"]}}, properties=["exp.tags", "icsd_ids"])

    Note that the criteria and properties follows the format (and richness) of MongoDB queries. You can refer to the MongoDB documentation for more information on how to customize queries.

It should be noted that not all materials documents contains all keys, e.g., some properties may not have been computed for certain materials yet. If you request for a key that is not present in a doc, the query will return None. For the most part, the documents are relatively consistent, especially for many of the common keys like elements, formulas, etc.

Alternative usage of this documentation

While the easiest way to use the Materials API is to leverage pymatgen's high-level interface to it, you may also directly submit a http POST query to https://www.materialsproject.org/rest/v2/query. For instance, you may wish to write your own app or queries in another language.

The https://www.materialsproject.org/rest/v2/query API provides functionality for flexible queries against the Materials Project database using MongoDB syntax, enabling queries which would otherwise not be possible using the other simpler REST forms. For example, a POST to query with parameters

criteria = '{"elements":{"$in":["Li", "Na", "K"], "$all": ["O"]}, "nelements":2}'
properties ='["formula", "formation_energy_per_atom"]'

will return the formula and formation energy per atom of all Li, Na and K oxides.

Using the command-line tool curl:

curl -s --header "X-API-KEY: <YOUR-API-KEY>" \
    https://materialsproject.org/rest/v2/query \
    -F criteria='{"elements": {"$in": ["Li", "Na", "K"], "$all": ["O"]}, "nelements": 2}' \
    -F properties='["formula", "formation_energy_per_atom"]'

Using Python and the requests library:

import json
import requests

data = {
    'criteria': {
        'elements': {'$in': ['Li', 'Na', 'K'], '$all': ['O']},
        'nelements': 2,
    },
    'properties': [
        'formula',
        'formation_energy_per_atom',
    ]
}
r = requests.post('https://materialsproject.org/rest/v2/query',
                 headers={'X-API-KEY': '<YOUR-API-KEY>'},
                 data={k: json.dumps(v) for k,v in data.items()})
response_content = r.json() # a dict

Using another language, e.g. MATLAB? See this MP discussion forum thread for more guidance. In particular, you need to treat "criteria" and "properties" as fields whose data are JSON-serialized strings.

Tips for efficient querying

Try to minimize the scope of the properties you are requesting. For example, if you are only interested in the XRD pattern for Cu Kα, do not just use properties=["xrd"] which will fetch the computed XRD patterns for all wavelengths. This results in a larger data transfer and slow queries. Instead, use properties=["xrd.Cu"].

Searching for properties

You can use Github's built-in search box at the top to search this repository for text that matches your query. For example, you can try searching for the word "spacegroup" to see the that the "spacegroup" root key exists with sub-keys such as "number" and "symbol".

Beause this repository's folder structure mirrors a material document's structure, you can also use the quick finder (keyboard shortcut: t) to interactively explore the structure.

Contributing

The initial version of this documentation is brought to you by the Materials Project development team. But it is our hope that others can contribute as well, either by cloning and editing this documentation (and sending pull requests) or just by informing us of any errors or omissions in the doc (e.g., by using the "Issues" tab).

Citing the Materials API

If you use the Materials API extensively, you may wish to cite the following publication.

Ong, S. P.; Cholia, S.; Jain, A.; Brafman, M.; Gunter, D.; Ceder, G.; 
Persson, K. a. The Materials Application Programming Interface (API): A 
simple, flexible and efficient API for materials data based on
REpresentational State Transfer (REST) principles, Comput. Mater. Sci.,
2015, 97, 209–215. doi:10.1016/j.commatsci.2014.10.037.

More Repositories

1

pymatgen

Python Materials Genomics (pymatgen) is a robust materials analysis code that defines classes for structures and molecules with support for many electronic structure codes. It powers the Materials Project.
Python
1,359
star
2

fireworks

The Fireworks Workflow Management Repo.
Python
322
star
3

atomate2

atomate2 is a library of computational materials science workflows
Python
146
star
4

crystaltoolkit

Crystal Toolkit is a framework for building web apps for materials science and is currently powering the new Materials Project website.
Python
141
star
5

custodian

A simple, robust and flexible just-in-time job management framework in Python.
Python
127
star
6

workshop

The Materials Project Workshop Curriculum
Jupyter Notebook
111
star
7

api

New API client for the Materials Project
Python
102
star
8

matbench

Matbench: Benchmarks for materials science property prediction
Python
95
star
9

jobflow

jobflow is a library for writing computational workflows.
Python
83
star
10

reaction-network

Reaction Network is a Python package for predicting likely inorganic chemical reaction pathways using graph theoretical methods. Project led by @mattmcdermott (Lawrence Berkeley National Lab).
Python
79
star
11

mpmorph

MPmorph is a collection of tools to run and analyze ab-initio molecular dynamics (AIMD) calculations run with VASP, and is currently under development. It relies heavily on tools developed by the Materials Project (pymatgen, custodian, fireworks) and atomate.
Python
62
star
12

emmet

Be a master builder of databases of material properties. Avoid the Kragle.
Python
52
star
13

pymatgen-db

Pymatgen-db provides an addon to the Python Materials Genomics (pymatgen) library (https://pypi.python.org/pypi/pymatgen) that allows the creation of Materials Project-style databases for management of materials data.
Python
48
star
14

maggma

MongoDB aggregation machine
Python
38
star
15

MPContribs

Platform for materials scientists to contribute and disseminate their materials data through Materials Project
Jupyter Notebook
34
star
16

pyrho

Python
33
star
17

pymatgen-analysis-defects

Defect analysis modules for pymatgen
Python
28
star
18

MPWorks

merges pymatgen, custodian, and FireWorks into a custom workflow for Materials Project
Python
24
star
19

dash-mp-components

Plotly Dash components developed by the Materials Project
Python
22
star
20

workshop-2017

Assets for the 2017 Materials Project workshop
Jupyter Notebook
18
star
21

mp-react-components

A suite of React components for the Materials Project, developed for use in Crystal Toolkit and the Materials Project public website.
TypeScript
17
star
22

foundation

Ruby
16
star
23

docs

Materials Project Documentation
14
star
24

pymatgen-analysis-alloys

pymatgen-analysis-alloys is an add-on package for pymatgen intended to contain useful classes for describing alloy systems and analyzing data relevant to these systems.
Python
12
star
25

workshop-2016

Assets for the Materials Project workshop in Aug 2016
HTML
12
star
26

rubicon

Workflow for Electrolyte Genome Project.
Python
8
star
27

pymatgen-io-validation

Comprehensive input/output validator. Made with the purpose of ensuring VASP calculations are compatible with Materials Project data, with possible future expansion to cover other DFT codes.
Python
8
star
28

mongogrant

grant username and password credentials for roles on mongo databases via email verification
Python
7
star
29

webtzite

A prototypal structure for serving materials data
Python
6
star
30

public-docs

The latest documentation for the Materials Project.
6
star
31

gbml

Gradient Boosting Machine-Locfit: A GBM framework using local regresssion via Locfit.
C
6
star
32

pymatgen-addon-template

A template for writing add-on namespace packages for pymatgen
Python
5
star
33

build-a-battery

interactive battery demo built on meteor
CSS
4
star
34

.github

3
star
35

MPCite

Continuous and High-Throughput Allocation of Digital Object Identifiers for Materials Data in the Materials Project
Jupyter Notebook
3
star
36

MPContribsUsers

Contributor Modules to enable their data submissions via MPContribs
Python
2
star
37

mp-jupyter-docker

Docker build for Materials Project Jupyter container
Dockerfile
2
star
38

binder

A ready-to-use environment for trying the Materials Project software stack based on the Binder (https://mybinder.org) service.
Jupyter Notebook
2
star
39

mp-jupyterhub

Jupyterhub for spinning up materials project notebook environments
Python
2
star
40

MPenv

create a virtual environment for running FireWorks within Materials Project
Python
2
star
41

www-issues

Public issue tracker for www.materialsproject.org
1
star
42

mp_docker

docker image for materials_django
Dockerfile
1
star
43

status

Status page for Materials Project website and services
1
star