Materials Project Emmet

2024.5.17 · active · verified Fri Apr 17

Emmet is a builder framework developed by the Materials Project to manage and process scientific data, primarily related to materials science. It provides tools to extract, transform, and load data into a standardized database schema, facilitating advanced materials discovery and analysis. The library is actively maintained with frequent updates, with the current stable version being 2024.5.17, available as 'mp-emmet' on PyPI.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to fetch materials data, specifically a TaskDoc, from the Materials Project database. Emmet defines the underlying schema for these documents. The `MPRester` from `pymatgen` is the standard client for interacting with the Materials Project API, which serves Emmet-structured data. Ensure your `MP_API_KEY` environment variable is set for successful API calls.

import os
from pymatgen.ext.matproj import MPRester

# Set your Materials Project API key as an environment variable (MP_API_KEY)
# Get your API key from https://materialsproject.org/dashboard
api_key = os.environ.get("MP_API_KEY", "")

if not api_key:
    print("Warning: MP_API_KEY environment variable not set. API calls will likely fail.")
    print("Using a placeholder API key for demonstration purposes.")
    api_key = "YOUR_API_KEY_HERE_IF_NOT_SET_IN_ENV"

try:
    with MPRester(api_key=api_key) as mpr:
        # Fetch the TaskDoc for a specific Materials Project task_id
        # Example Task ID for LiCoO2 calculation
        task_id = "mp-149"
        task_doc = mpr.get_task_doc(task_id)

        print(f"\nSuccessfully fetched TaskDoc for ID: {task_id}")
        print(f"Pretty Formula: {task_doc.formula_pretty}")
        print(f"Energy per atom: {task_doc.energy_per_atom:.3f} eV/atom")

except Exception as e:
    print(f"\nAn error occurred during data retrieval: {e}")
    print("Please ensure your MP_API_KEY is correctly set and valid.")

view raw JSON →