Materials Databases 标志

Materials Databases

社区
jkitchin
materials-databases

Expert assistant for accessing materials databases (AFLOW and Materials Project) - query crystal structures, materials properties, thermodynamic data, and computational results from comprehensive databases

概览

发布者jkitchin
代码仓库knowhow
技能名称materials-databases
星标数
45
复刻数
9
附带文件
6
许可协议MIT
链接
  • Markdown 格式的指令

    模型按需加载 SKILL.md 文件,因此只有在请求确实与该技能匹配时才会消耗 Token。

  • 兼容任何大语言模型

    AI 技能采用纯 Markdown,而非特定提供商的代码,因此可搭配 GPT、Claude、Gemini、Grok 或本地模型使用。

  • 6 个附带文件

    模型执行任务时可读取的脚本、模板和参考资料。这些文件为只读文件,绝不会被执行。

  • 开源

    由 jkitchin 发布于 GitHub。请在安装前查看技能的源文件。

安装

在 TypingMind 中安装 Materials Databases AI 技能,即可搭配任意大语言模型使用;也可以将其放入其他支持读取 SKILL.md 的智能体中。

1

安装到 TypingMind

TypingMind 可直接从 GitHub 文件夹安装技能:读取 SKILL.md,打包资源文件,并将结果保存在本地。

  1. 打开应用,前往“插件 → 技能”。
  2. 选择“从 GitHub 安装”。
  3. 粘贴下方的技能文件夹 URL 并确认。
    https://github.com/jkitchin/knowhow/tree/main/skills/research/materials-databases
  4. 请在每个需要使用该技能的聊天中启用它。
依次选择“插件 → 技能 → 添加技能 → 从 GitHub URL 导入”,然后粘贴文件夹 URL 并点击“继续”。
2

安装到其他智能体

任何支持 Agent Skills 格式的智能体都可以使用此技能,只需将文件夹复制到该智能体的技能目录中。

Claude Code — .claude/skills
git clone --depth 1 https://github.com/jkitchin/knowhow.git /tmp/knowhow
mkdir -p .claude/skills
cp -r /tmp/knowhow/skills/research/materials-databases .claude/skills/materials-databases
复制后,请重启 Claude Code,以加载新技能。

在 TypingMind 中使用此技能

在任意 TypingMind 聊天中启用 Materials Databases,后续即可交由模型处理。技能的名称和描述会放在系统提示词中,一旦请求匹配,模型就会自动加载完整指令,无需您手动调用,且在实际使用前不会消耗 Token。

一旦请求与技能匹配,模型就会自动加载 Materials Databases。

兼容任何 AI 模型

AI 技能是纯 Markdown 指令,而非特定提供商的代码,因此 Materials Databases 不局限于最初适配的模型。只需在 TypingMind 中安装一次,即可搭配 GPT-5、Claude、Gemini、Grok、DeepSeek、Mistral、Llama 或您自行运行的本地模型使用,全程使用您自己的 API 密钥。

  • 仅在需要时加载

    系统提示词中仅包含技能名称和描述。首次遇到匹配的请求时才会加载完整指令,因此技能未使用时,这些指令不会消耗 Token。

  • 在聊天中切换模型

    技能是指令而非代码,因此切换模型不会导致技能失效,新模型会读取同一个 SKILL.md。

技能指令

这是模型会加载的 SKILL.md 内容。请在安装前阅读,因为技能就是模型将遵循的指令。

Materials Databases Access Skill

You are an expert assistant for accessing and querying materials science databases, specifically AFLOW and Materials Project. Help users retrieve crystal structures, materials properties, and computational data efficiently.

Overview

This skill enables access to two major materials databases:

  1. AFLOW (Automatic Flow for Materials Discovery)

    • 3.5+ million calculated materials
    • Crystal structures, thermodynamic properties, elastic properties
    • No API key required for basic access
    • REST API with simple URL-based queries
  2. Materials Project (MP)

    • 150,000+ inorganic compounds
    • Electronic structure, phonons, elasticity, surfaces, batteries
    • Requires free API key
    • Python client library (mp-api) with rich functionality

Installation Requirements

Materials Project (mp-api)

bash
# Install the Materials Project API client
pip install mp-api

# Alternative: with conda
conda install -c conda-forge mp-api

AFLOW

AFLOW uses REST API - no Python package installation required. However, for convenience:

bash
# Optional: Install requests for API calls
pip install requests

# Optional: Install aflow Python package (community-maintained)
pip install aflow

Additional Recommended Packages

bash
# For structure manipulation and visualization
pip install pymatgen ase

# For data analysis
pip install pandas numpy matplotlib

API Key Setup

Materials Project API Key

  1. Get an API key:

  2. Set up authentication:

    Option A: Environment variable (recommended)

    bash
    export MP_API_KEY="your_api_key_here"

    Option B: Configuration file

    bash
    # Create ~/.config/.mpapi.json or ~/.pmgrc.yaml
    echo '{"MAPI_KEY": "your_api_key_here"}' > ~/.config/.mpapi.json

    Option C: Pass directly in code

    python
    from mp_api.client import MPRester
    
    with MPRester("your_api_key_here") as mpr:
        # Your code here
        pass

AFLOW

No API key required - AFLOW API is publicly accessible.

Core Functionality

Materials Project - Common Queries

Search by formula:

python
from mp_api.client import MPRester

with MPRester(api_key="YOUR_API_KEY") as mpr:
    # Search for all Silicon entries
    docs = mpr.materials.summary.search(formula="Si")

    # Get specific properties
    docs = mpr.materials.summary.search(
        formula="Fe2O3",
        fields=["material_id", "formula_pretty", "band_gap", "energy_per_atom"]
    )

Search by material ID:

python
with MPRester() as mpr:  # Uses env var or config file
    structure = mpr.get_structure_by_material_id("mp-149")
    doc = mpr.materials.summary.get_data_by_id("mp-149")

Search by criteria:

python
with MPRester() as mpr:
    # Find materials with band gap between 1-3 eV
    docs = mpr.materials.summary.search(
        band_gap=(1, 3),
        elements=["O", "Ti"],
        num_elements=2
    )

    # Find stable materials
    docs = mpr.materials.summary.search(
        energy_above_hull=(0, 0.01),  # Nearly stable
        fields=["material_id", "formula_pretty", "energy_above_hull"]
    )

Available data types:

  • materials.summary - General materials properties
  • materials.thermo - Thermodynamic data
  • materials.electronic_structure - Band structures, DOS
  • materials.phonon - Phonon band structures
  • materials.elasticity - Elastic tensors
  • materials.surface_properties - Surface energies
  • molecules - Molecular structures and properties

AFLOW - REST API Queries

Basic URL structure:

http://aflowlib.duke.edu/AFLOWDATA/ICSD_WEB/<system>/<file>?<directives>

Common queries using REST:

python
import requests

# Get all keywords for a material
url = "http://aflowlib.duke.edu/AFLOWDATA/ICSD_WEB/FCC/Ag1/?keywords"
response = requests.get(url)
data = response.text

# Get specific property (e.g., enthalpy)
url = "http://aflowlib.duke.edu/AFLOWDATA/ICSD_WEB/FCC/Ag1/?enthalpy_formation_atom"
response = requests.get(url)

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

Using aflow Python package (optional):

python
import aflow

# Search for materials
results = aflow.search(filter='species(Au),Egap(5*)')

for result in results:
    print(result.enthalpy_formation_atom)
    print(result.Egap)
    structure = result.atoms  # Get ASE Atoms object

Common AFLOW directives:

  • ?keywords - List all available properties
  • ?enthalpy_formation_atom - Formation enthalpy per atom
  • ?Egap - Band gap
  • ?volume_cell - Unit cell volume
  • ?geometry - Crystal structure (POSCAR format)
  • ?files - List all available files

AFLUX search syntax:

species(element1,element2)  # Chemical system
Egap(min*,max*)            # Band gap range (eV)
enthalpy_formation_atom(min*,max*)  # Formation enthalpy range
catalog(ICSD)              # Database catalog

Workflow Guidance

When to Use Materials Project

  1. You need electronic structure data (band structures, DOS, Fermi surfaces)
  2. Battery materials research (voltage, capacity calculations)
  3. Surface properties and adsorption energies
  4. Detailed phonon calculations
  5. Integration with pymatgen workflows
  6. Phase stability analysis (phase diagrams, energy above hull)

When to Use AFLOW

  1. Large-scale materials screening (millions of entries)
  2. Elastic properties and mechanical data
  3. No API key setup possible/desired
  4. ICSD-based structures (experimental references)
  5. Quick property lookups (simple REST calls)

Combining Both Databases

python
# Example: Cross-reference findings
from mp_api.client import MPRester
import requests

# Find in Materials Project
with MPRester() as mpr:
    mp_docs = mpr.materials.summary.search(
        formula="TiO2",
        fields=["material_id", "band_gap", "energy_per_atom"]
    )

# Cross-check with AFLOW
aflow_url = "http://aflowlib.duke.edu/search/API/?species(Ti,O),nspecies(2)"
aflow_data = requests.get(aflow_url).json()

Best Practices

  1. Use specific queries - Request only needed fields to reduce data transfer

    python
    docs = mpr.materials.summary.search(
        formula="Li",
        fields=["material_id", "formula_pretty", "band_gap"]  # Specify fields
    )
  2. Paginate large results - Use chunk_size for large queries

    python
    docs = mpr.materials.summary.search(
        elements=["O"],
        num_chunks=10,  # Fetch in chunks
        chunk_size=1000
    )
  3. Cache results locally - Save API results to avoid repeated queries

    python
    import pickle
    
    # Save results
    with open("mp_results.pkl", "wb") as f:
        pickle.dump(docs, f)
  4. Handle structures properly - Convert between formats as needed

    python
    from pymatgen.io.ase import AseAtomsAdaptor
    
    # MP Structure → ASE Atoms
    atoms = AseAtomsAdaptor.get_atoms(structure)
    
    # ASE Atoms → MP Structure
    structure = AseAtomsAdaptor.get_structure(atoms)
  5. Check API status - Materials Project has rate limits (typically generous)

Error Handling

python
from mp_api.client import MPRester
from mp_api.client.core import MPRestError

try:
    with MPRester() as mpr:
        docs = mpr.materials.summary.search(formula="InvalidFormula")
except MPRestError as e:
    print(f"API Error: {e}")
except Exception as e:
    print(f"Unexpected error: {e}")

Common Tasks

Task 1: Find Band Gap of a Material

python
# Materials Project
with MPRester() as mpr:
    docs = mpr.materials.summary.search(
        formula="GaN",
        fields=["material_id", "band_gap", "is_gap_direct"]
    )
    for doc in docs:
        print(f"{doc.material_id}: {doc.band_gap} eV (direct: {doc.is_gap_direct})")

# AFLOW
import requests
url = "http://aflowlib.duke.edu/search/API/?species(Ga,N),Egap"
response = requests.get(url)

Task 2: Get Crystal Structure

python
# Materials Project - returns pymatgen Structure
with MPRester() as mpr:
    structure = mpr.get_structure_by_material_id("mp-149")
    structure.to(filename="POSCAR")

# AFLOW - returns POSCAR format text
url = "http://aflowlib.duke.edu/AFLOWDATA/ICSD_WEB/FCC/Ag1/?geometry"
poscar = requests.get(url).text

Task 3: Screen for Stable Materials

python
# Find thermodynamically stable oxides with specific properties
with MPRester() as mpr:
    docs = mpr.materials.summary.search(
        elements=["O"],
        energy_above_hull=(0, 0.05),  # Stable or nearly stable
        band_gap=(1.0, 4.0),  # Semiconducting
        num_elements=(2, 3),  # Binary or ternary
        fields=["material_id", "formula_pretty", "band_gap", "energy_above_hull"]
    )

References

  • See references/materials-project.md for detailed MP API documentation
  • See references/aflow.md for AFLOW REST API and AFLUX syntax
  • See examples/ for complete working scripts

Key Points

  • Materials Project requires API key (free); AFLOW does not
  • MP has better Python integration; AFLOW uses REST API
  • MP: 150k materials, rich electronic/phonon data; AFLOW: 3.5M materials, elastic properties
  • Always specify fields in MP queries for efficiency
  • Use pymatgen for structure manipulation and analysis
  • Both databases are continuously updated with new calculations

附带文件

技能加载后,模型会按需读取这些文件。它们仅作为可读文件提供,绝不会被执行。

常见问题

Materials Databases AI 技能有什么作用?

Expert assistant for accessing materials databases (AFLOW and Materials Project) - query crystal structures, materials properties, thermodynamic data, and computational results from comprehensive databases

为什么在 TypingMind 中使用 Materials Databases?

因为您只需安装一次,就能搭配任何模型使用。Materials Databases 采用纯 Markdown 格式,而非特定提供商专用的代码,因此同一技能可用于 GPT-5、Claude、Gemini、Grok 或本地模型。您甚至可以在聊天中途切换模型,而不会影响技能的正常使用。TypingMind 使用您自己的 API 密钥,因此您直接向提供商付费,而不是按席位订阅;您的技能和聊天记录也都保留在您自己的存储空间中。

如何在 TypingMind 中安装 Materials Databases?

在 TypingMind 中打开“插件 → 技能 → 从 GitHub 安装”,然后粘贴 https://github.com/jkitchin/knowhow/tree/main/skills/research/materials-databases。TypingMind 会读取其中的 SKILL.md,打包相关文件,并将其安装为技能,供您在各个聊天中按需启用。

哪些 AI 模型可以使用 Materials Databases?

您在 TypingMind 中连接的任何模型都可以。AI 技能采用纯 Markdown 指令,而非特定提供商专用的代码,因此 GPT、Claude、Gemini、Grok 和本地模型都能在请求匹配时加载此技能。

Materials Databases 可以搭配多少个 AI 模型使用?

数量不限。只要模型支持技能,您就可以将它与 Materials Databases 搭配使用。GPT、Claude、Gemini、Grok、DeepSeek、Mistral、Llama 等模型都可以通过您自己的 API 密钥接入 TypingMind。

Materials Databases AI 技能免费吗?

是的。jkitchin 已在 GitHub 上根据 MIT 许可证发布了该技能。您只需向自己的 AI 提供商支付所用 Token 的费用。

什么是 AI 技能?

AI 技能是一组可复用的指令,用于教会 AI 模型完成某项特定任务。它遵循开放的 Agent Skills 格式:包含名称和描述的 SKILL.md 文件,以及模型可能需要的脚本、模板或参考文件。模型仅在您的请求与技能匹配时才会读取这些指令,因此已安装的技能在使用前不会产生任何费用。

AI 技能与插件或 MCP 服务器有何不同?

插件或 MCP 服务器为模型提供可调用的新工具,也就是在某处运行并返回结果的代码。AI 技能则为模型提供知识和流程:如何处理任务、遵循哪些步骤,以及怎样的输出才算优质。技能采用纯 Markdown 格式,因此不需要服务器、API 密钥或运行时环境,并且适用于任何模型。

查看全部

立即创建您自己的 AI 工作区

订阅我们的电子简报,获取新功能和后续赠奖活动的通知 👇