PythonからMaterials Project APIを使う
説明
Materials Project (MP)は、材料科学研究者向けのオープンソースデータベースである。多様な無機物質に関する計算科学的データを提供し、PythonベースのAPIを通じて便利に利用できる。以下の説明は公式ドキュメントを参照したもので、本稿に含まれない詳細は公式ドキュメントを参照すること。
会員登録とAPIキーの発行
MP APIを使うにはMPホームページで会員登録が必要である。GitHub、Gmail、またはその他のメールで登録できる。ホームページ右上のAPIタブで自身のAPIキーを確認できる。

インストール
pipを使うか、GitHubからダウンロードしてインストールできる。
# using pip
pip install mp_api
# from github
git clone https://github.com/materialsproject/api
cd api
pip install -e .
使い方
PythonでMPResterクライアントを呼び出して必要な機能を使える。with構文の使用が推奨されている。
from mp_api.client import MPRester
# Option 1: Pass your API key directly as an argument.
with MPRester("your_api_key_here") as mpr:
# do stuff with mpr...
# Option 2: Use the `MP_API_KEY` environment variable:
# export MP_API_KEY="your_api_key_here"
# Note: You can also configure your API key through pymatgen
with MPRester() as mpr:
# do stuff with mpr ...
