SuperAPI AI 工具集

materials-databases

数据与分析

查看项目

更新于 10-27 12:35

技能介绍

用途

该技能面向材料科学研究场景,作为专家助手帮助用户高效访问和查询两个主流材料数据库:AFLOW(Automatic Flow for Materials Discovery)与 Materials Project。用户可借此检索晶体结构、材料性质、热力学数据与计算数据。

主要能力

AFLOW

  • 收录 350 万以上计算材料。
  • 提供晶体结构、热力学性质与弹性性质。
  • 基础访问无需 API Key,采用基于 URL 的简单 REST API 查询。
  • 支持 AFLUX 检索语言,如按化学体系、带隙范围、形成焓范围与数据库目录筛选。
  • 常用指令包括 ?keywords、?enthalpy_formation_atom、?Egap、?volume_cell、?geometry(POSCAR 格式)、?files。

Materials Project

  • 收录 15 万以上无机化合物。
  • 覆盖电子结构、声子、弹性、表面与电池材料数据。
  • 需要免费 API Key,使用 Python 客户端库 mp-api,功能丰富。
  • 支持按化学式、材料 ID(如 mp-149)或条件(带隙范围、元素组合、元素数量、energy_above_hull 等)检索。
  • 可用数据模块包括 materials.summary、materials.thermo、materials.electronic_structure、materials.phonon、materials.elasticity、materials.surface_properties 与 molecules。

使用方式

安装

Materials Project:

pip install mp-api

或使用 conda:

conda install -c conda-forge mp-api

AFLOW 无需安装 Python 包即可使用 REST API;可选安装:

pip install requests
pip install aflow

推荐附加包:

pip install pymatgen ase
pip install pandas numpy matplotlib

API Key 配置

Materials Project API Key 获取步骤:访问 https://materialsproject.org/api ,点击“Generate API Key”(需通过 ORCID 或邮箱登录),复制长字符串 API Key。配置方式有三种:

  1. 环境变量(推荐):
export MP_API_KEY="your_api_key_here"
  1. 配置文件:在 ~/.config/.mpapi.json 或 ~/.pmgrc.yaml 中写入:
echo '{"MAPI_KEY": "your_api_key_here"}' > ~/.config/.mpapi.json
  1. 代码中直接传入:
from mp_api.client import MPRester

with MPRester("your_api_key_here") as mpr:
    # Your code here
    pass

AFLOW 无需 API Key,API 公开可访问。

常见查询示例

Materials Project 按化学式检索:

from mp_api.client import MPRester

with MPRester(api_key="YOUR_API_KEY") as mpr:
    docs = mpr.materials.summary.search(formula="Si")
    docs = mpr.materials.summary.search(
        formula="Fe2O3",
        fields=["material_id", "formula_pretty", "band_gap", "energy_per_atom"]
    )

按材料 ID 检索:

with MPRester() as mpr:
    structure = mpr.get_structure_by_material_id("mp-149")
    doc = mpr.materials.summary.get_data_by_id("mp-149")

按条件检索:

with MPRester() as mpr:
    docs = mpr.materials.summary.search(
        band_gap=(1, 3),
        elements=["O", "Ti"],
        num_elements=2
    )
    docs = mpr.materials.summary.search(
        energy_above_hull=(0, 0.01),
        fields=["material_id", "formula_pretty", "energy_above_hull"]
    )

AFLOW REST 查询:

import requests

url = "http://aflowlib.duke.edu/AFLOWDATA/ICSD_WEB/FCC/Ag1/?keywords"
response = requests.get(url)
data = response.text

url = "http://aflowlib.duke.edu/AFLOWDATA/ICSD_WEB/FCC/Ag1/?enthalpy_formation_atom"
response = requests.get(url)

url = "http://aflowlib.duke.edu/search/API/?species(Au),Egap(5*),catalog(ICSD)"
response = requests.get(url)

使用 aflow Python 包(可选):

import aflow

results = aflow.search(filter='species(Au),Egap(5*)')

for result in results:
    print(result.enthalpy_formation_atom)
    print(result.Egap)
    structure = result.atoms

适用场景

  • 需要电子结构数据(能带结构、态密度、费米面)时,优先使用 Materials Project。
  • 电池材料研究(电压、容量计算)时,优先使用 Materials Project。
  • 表面性质与吸附能、详细声子计算、与 pymatgen 工作流集成、相稳定性分析(相图、energy above hull)时,优先使用 Materials Project。
  • 大规模材料筛选(数百万条目)、弹性性质与力学数据、无法或不希望设置 API Key、基于 ICSD 的实验参考结构、快速属性查询(简单 REST 调用)时,优先使用 AFLOW。
  • 可结合两个数据库进行交叉核验,例如先在 Materials Project 检索 TiO2,再通过 AFLOW 检索接口对照。

限制与注意事项

  • Materials Project 需要免费 API Key;AFLOW 无需 API Key。
  • Materials Project 的 Python 集成更好;AFLOW 使用 REST API。
  • 资料称 Materials Project 的速率限制通常较宽松,但建议关注 API 状态。
  • 查询时应尽量指定所需字段以减少数据传输,大结果集应分块获取(如 num_chunks、chunk_size),并可在本地缓存结果。
  • 结构转换可使用 pymatgen.io.ase.AseAtomsAdaptor 在 MP Structure 与 ASE Atoms 之间互转。
  • 错误处理可捕获 MPRestError 及其他异常。
  • 两个数据库均持续更新新的计算结果。
  • 详细 API 文档可参考 references/materials-project.md 与 references/aflow.md,完整可运行脚本见 examples/。