pymatgen
它能做什么
这个工具可以帮助你分析和整理材料数据。它能检查信息、转换格式,并帮助你了解结构和化合物的性质。
适用场景
- ✓当你拥有材料数据,并想确保其准确无误时。
- ✓当你需要把数据从一种格式转换为另一种格式时。
- ✓当你想了解某种材料的结构和性质时。
技能链接
https://github.com/K-Dense-AI/scientific-agent-skills/blob/main/skills/pymatgen/SKILL.md复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。
使用方法
最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。
可直接粘贴的消息
适用于 Claude Code、Codex 或 Cursor:在项目文件夹中运行,即可安装该技能。
下载 SKILL.md,放进智能体的技能文件夹。
可以这样问 AI
“分析这个材料结构文件,告诉我它的性质。”
每周 5 个新技能,1 分钟读完。
工作原理
该工具利用一套规则和函数来读取、校验和处理材料信息。它会记录每一步操作,以保证结果的准确性。
技术内容(原始 SKILL.md)
作者在 GitHub 上的英文原文。
pymatgen
Use pymatgen for explicit, provenance-preserving work with compositions, molecules, periodic structures, computed entries, symmetry, phase diagrams, electronic structures, and electronic-structure-code files. Treat every parse, conversion, symmetry assignment, transformation, and database result as method- and parameter-dependent.
The MIT frontmatter license covers this skill. pymatgen and
pymatgen-core are MIT; mp-api declares BSD-3-Clause-LBNL. Materials Project
data is generally CC BY 4.0, while contributed data remains owned by its
contributors. Check the exact artifact and data terms before redistribution.
Verified snapshot (2026-09-30)
pymatgen==2026.9.24is the latest stable wrapper release (uploaded 2026-09-23). Package metadata requires Python 3.11+ and directly requirespymatgen-core>=2026.9.23.pymatgen-core==2026.9.23is the latest stable core release (2026-09-23). It now contains core objects, symmetry/lattice operations, and the I/O layer, all under the existingpymatgen.*namespace.mp-api==0.46.5is the latest stable Materials Project client (2026-08-18), requires Python 3.11+, and depends onpymatgen>2024.2.20.- The current API site is built from 2026.9.23 core documentation. Pinning both
distributions prevents
pymatgen==2026.9.24from silently resolving to a different future core. - Pymatgen uses date-based versions. PyPI renders the date with dots; do not infer semantic-version compatibility from the numbers.
The local CLI suite and synthetic examples were executed on this snapshot. File-dependent VASP/Q-Chem parses and authenticated API examples below are illustrative: their signatures and current SDK source were checked, but no licensed calculation or authenticated service retrieval was performed.
Create a project lock for reproducibility:
uv init --python 3.11
uv add "pymatgen==2026.9.24" "pymatgen-core==2026.9.23" "mp-api==0.46.5"
uv lock
uv sync --frozen
For a disposable reviewed environment:
uv venv --python 3.11 .venv-pymatgen
uv pip install --python .venv-pymatgen/bin/python \
"pymatgen==2026.9.24" "pymatgen-core==2026.9.23" "mp-api==0.46.5"
Direct pins do not freeze all transitive wheels. Preserve uv.lock, platform,
Python version, package versions, and artifact hashes.
Required workflow
- State whether the object is a non-periodic
Moleculeor periodicStructure; record lattice and periodic boundary conditions. - State units. Pymatgen commonly uses Å, degrees, eV, eV/atom, amu, and g/cm³, but each API's documented contract is authoritative.
- State coordinate mode.
Structurecoordinates are fractional unlesscoords_are_cartesian=True;Moleculecoordinates are Cartesian. - Inspect every parser warning. For CIF, preserve occupancy, site-merging, stoichiometry, and correction warnings; do not silently accept fixes.
- Report disorder/partial occupancies and oxidation-state decoration. Never guess oxidation states implicitly.
- Run validation before symmetry, neighbor, transformation, conversion, or thermodynamic analysis.
- Sweep symmetry tolerances and report
symprecin Å andangle_tolerancein degrees with every assignment. - Treat transformations as new artifacts. Preserve the input, parameters, software versions, warnings, and parent/child checksums.
- Before conversion, identify representation loss. Write only to a new path and round-trip-check scientifically relevant properties.
- Build phase diagrams only from compatible total energies and correction schemes. A computed hull is conditional on the supplied entry set.
- Keep all database access off by default. Disclose endpoint, filters, fields, result limit, cache behavior, output, license, and citation before an explicit execution step.
- Preserve an artifact manifest. Never use pickle or load an untrusted general object graph; use schema-validated JSON and explicit constructors.
Core objects
Use the public convenience imports:
from pymatgen.core import Composition, Element, Lattice, Molecule, Structure
composition = Composition("LiFePO4", strict=True)
iron = Element("Fe")
lattice = Lattice.cubic(5.64) # Å
structure = Structure(
lattice,
["Na", "Cl"],
[[0, 0, 0], [0.5, 0.5, 0.5]],
coords_are_cartesian=False,
validate_proximity=True,
)
molecule = Molecule(
["O", "H", "H"],
…
常见问题
这里的“结构”和“化合物”是什么意思?
“结构”指材料中原子的排列方式,也就是原子在空间中如何组织。“化合物”是由化学元素组合而成、构成这些材料的物质。
为什么要记录每一步?
记录每一步(即溯源信息)能让你清楚地知道结果是如何得出的,从而让他人可以放心地验证或复现你的工作。
这个工具能用于非晶材料吗?
可以。该工具既能处理周期性结构(如晶体),也能处理非周期性的分子。
详情
作者的原始描述
Analyzes, validates, converts, and transforms materials structures and computed materials data with pymatgen. Use for local phase diagrams, symmetry sensitivity, electronic-structure I/O, and bounded Materials Project queries.
热度
- GitHub 星标
- 51k
- 排名
- #3542
- 许可证
- MIT
- 更新时间
- 2026/10/15
评论
- …