MSE 598-DM Spring 2021

Thermodynamics and crystal structure

Stable crystals are ones that minimize the free energy F. For example, table salt NaCl is stable partly because G(NaCl) < G(Na) + G(Cl), where Na and Cl represent pure elemental solids. However, it’s not enough to just be stable versus the elemental solids; it must also be stable versus decomposition into, for example, 1/2 Na2Cl + NaCl2. Formally, we want to minimize the total free energy of a collection of compounds.

For now, we will assume that energy is the same as free energy (this is equivalent to zero temperature, zero pressure, which is not as bad as it might sound). Materials project contains the computed energy (via density functional theory) of many compounds.

Install pymatgen

!pip install pymatgen

You may need to hit “restart runtime” since pymatgen has a lot of weird dependencies.

Get an API key

Go to materialsproject.org and make an account.

Click on API and request an API key.

Getting started

from pymatgen import MPRester
import pandas as pd
import numpy as np
import seaborn as sns
import matplotlib.pyplot as plt
API_KEY = "XXXXXXXXX"

Instead of XXXXXXXXX, insert the key you got from materials project. Don’t share the key with anyone.

Testing the query object

with MPRester(API_KEY) as mpr:
    print(mpr.supported_properties)

You should get a list of possible properties that you can request. The with statement is called a context manager. It ensures your connection is closed correctly when the block ends.

Querying the database.

Here’s a simple function that queries materials project, returning

def make_query(query):
    with MPRester(API_KEY) as mpr:
      return mpr.get_entries(query,
        ['material_id',
        'pretty_formula',
        'icsd_id',
        'icsd_ids', 
        'e_above_hull',                            
        'spacegroup', 
        'energy_per_atom',
        'energy', 
        'composition'])

Downloading computed values

Try looking at the results.

make_query("C")

Getting results for a chemical system Ti-O

results = make_query("Ti-O")

Making a convex hull diagram

Use the PhaseDiagram object to construct the convex hull. Note that you’ll need not just the Ti-O system, but also the

phase = pymatgen.analysis.phase_diagram.PhaseDiagram(results)
plotter = pymatgen.analysis.phase_diagram.PDPlotter(phase)
plotter.get_plot()

Doing dict-type queries

This can allow you to grab the energy above the hull from the database, since it is already pre-computed.

  with MPRester(API_KEY) as mpr:
     query_results=mpr.query("Ti-O",
      ['material_id',
      'pretty_formula',
      'icsd_id',
      'icsd_ids', 
      'e_above_hull',                            
      'spacegroup', 
      'energy_per_atom',
      'energy', 
      'composition'])
df = pd.DataFrame(query_results)

Questions