{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Introduction\n", "\n", "Pymatgen supports reading of most common file formats, including the Crystallographic Information File and various input and output files of computational codes like VASP. However, it is often easier and quicker to directly query for structures from online sources. Though private databases such as the Inorganic Crystal Structure Database are not open, there are open sources such as the Materials Project and the Crystallographic Open Database (COD) where one can obtain crystal structures." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# Uncomment the subsequent lines in this cell to install dependencies for Google Colab.\n", "# !pip install pymatgen==2022.7.19\n", "from __future__ import annotations" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Materials Project\n", "\n", "Pymatgen contains a high-level interface to the Materials Project, which can be used to query for structures very easily." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "from pymatgen.ext.matproj import MPRester\n", "\n", "# Note that you will need to add your Materials API key in your .pmgrc.yaml file as \"PMG_MAPI_KEY\".\n", "# Alternatively, you will need to supply the API key as an arg to MPRester.\n", "mpr = MPRester()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "[Structure Summary\n", "Lattice\n", " abc : 3.2910717923597561 3.2910718996250861 3.2910720568557887\n", " angles : 60.129710432884849 60.129709521376753 60.129703130390972\n", " volume : 25.279668381289056\n", " A : 2.91738857 0.097894369999999994 1.5200046599999999\n", " B : 0.96463405999999996 2.7550356100000002 1.5200046599999999\n", " C : 0.13320635 0.097894430000000004 3.28691771\n", "PeriodicSite: O (0.0000, 0.0000, 0.0000) [0.0000, 0.0000, 0.0000]\n", "PeriodicSite: Li (3.0121, 2.2136, 4.7463) [0.7502, 0.7502, 0.7502]\n", "PeriodicSite: Li (1.0031, 0.7372, 1.5806) [0.2498, 0.2498, 0.2498], Structure Summary\n", "Lattice\n", " abc : 5.1517948200000001 3.1404278300000001 5.9334081599999999\n", " angles : 90.0 90.0 90.0\n", " volume : 95.995660249910003\n", " A : 5.1517948200000001 0.0 0.0\n", " B : 0.0 3.1404278300000001 0.0\n", " C : 0.0 0.0 5.9334081599999999\n", "PeriodicSite: Li (0.0631, 0.7851, 0.9438) [0.0122, 0.2500, 0.1591]\n", "PeriodicSite: Li (0.7268, 0.7851, 3.4367) [0.1411, 0.2500, 0.5792]\n", "PeriodicSite: Li (1.8490, 2.3553, 0.4700) [0.3589, 0.7500, 0.0792]\n", "PeriodicSite: Li (2.5128, 2.3553, 3.9105) [0.4878, 0.7500, 0.6591]\n", "PeriodicSite: Li (2.6390, 0.7851, 2.0229) [0.5122, 0.2500, 0.3409]\n", "PeriodicSite: Li (3.3027, 0.7851, 5.4634) [0.6411, 0.2500, 0.9208]\n", "PeriodicSite: Li (4.4249, 2.3553, 2.4967) [0.8589, 0.7500, 0.4208]\n", "PeriodicSite: Li (5.0887, 2.3553, 4.9896) [0.9878, 0.7500, 0.8409]\n", "PeriodicSite: O (1.2677, 2.3553, 2.3664) [0.2461, 0.7500, 0.3988]\n", "PeriodicSite: O (1.3082, 0.7851, 5.3331) [0.2539, 0.2500, 0.8988]\n", "PeriodicSite: O (3.8436, 2.3553, 0.6003) [0.7461, 0.7500, 0.1012]\n", "PeriodicSite: O (3.8841, 0.7851, 3.5670) [0.7539, 0.2500, 0.6012]]\n" ] } ], "source": [ "# Querying by formula only.\n", "structures = mpr.get_structures(\"Li2O\")\n", "print(structures)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Li2 O4\n", "Li2 O1\n", "Li8 O4\n", "Li4 O4\n", "Li1 O3\n", "Li16 O16\n" ] } ], "source": [ "# Querying by chemical system only.\n", "structures = mpr.get_structures(\"Li-O\")\n", "for s in structures:\n", " print(s.formula)\n", "# A number of Li-O structures are returned with different Li:O ratios." ] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.11.5" } }, "nbformat": 4, "nbformat_minor": 2 }