Alterlab pymatgen

From NVlabs/Skill2Env · View interactive version

Alterlab pymatgen is an AI agent skill from the GitHub repository NVlabs/Skill2Env. Analyzes and manipulates materials with the pymatgen toolkit — crystal structures and molecules, phase diagrams and thermodynamic stability, electronic structure (band structures, DOS), surfaces and interfaces, and Materials Project database access. Use when working with crystal structures in materi

How to use this skill

Skill file

Pymatgen - Python Materials Genomics

Overview

Pymatgen is a comprehensive Python library for materials analysis that powers the

Materials Project. Create, analyze, and manipulate crystal structures and molecules;

compute phase diagrams and thermodynamic properties; analyze electronic structure (band

structures, DOS); generate surfaces and interfaces; and access the Materials Project

database. Supports 100+ file formats from various computational codes.

When to Use This Skill

Use when:

Quick Start

uv pip install pymatgen           # core
uv pip install pymatgen mp-api    # + Materials Project API access
uv pip install pymatgen[analysis] # extended analysis tools
uv pip install pymatgen[vis]      # visualization tools
from pymatgen.core import Structure, Lattice

struct = Structure.from_file("POSCAR")        # auto format detection
struct.to(filename="structure.cif")           # write any format
print(struct.composition.reduced_formula)
print(struct.get_space_group_info())
print(f"{struct.density:.2f} g/cm³")
export MP_API_KEY="your_api_key_here"   # for Materials Project access

Core Capabilities (routing)

Each capability has a copy-paste code block in references/core_examples.md and deeper

module docs in the references listed below.

  1. Structure creation & manipulation — from files, from scratch (lattice params or

space group), transformations (supercell, substitution, primitive). → core_classes.md

  1. File-format conversion — from_file()/to() plus scripts/structure_converter.py

for single/batch. → io_formats.md

  1. Structure analysis & symmetry — SpacegroupAnalyzer, CrystalNN, plus

scripts/structure_analyzer.py. → analysis_modules.md

  1. Phase diagrams & thermodynamics — PhaseDiagram, energy-above-hull, decomposition,

plus scripts/phase_diagram_generator.py. → analysis_modules.md, transformations_workflows.md

  1. Electronic structure — band structures and DOS from Vasprun, band gaps,

metallicity. → analysis_modules.md, io_formats.md

  1. Surfaces & interfaces — SlabGenerator, WulffShape, AdsorbateSiteFinder.

→ analysis_modules.md, transformations_workflows.md

  1. Materials Project access — MPRester search and retrieval with property filters.

→ materials_project_api.md

  1. Computational workflow setup — VASP input sets (MPRelaxSet, MPStaticSet,

MPNonSCFSet), Gaussian, Quantum ESPRESSO. → io_formats.md, transformations_workflows.md

  1. Advanced analysis — XRD patterns, elastic tensors, magnetic ordering.

→ analysis_modules.md

Multi-step worked examples (high-throughput generation, band-structure pipeline, surface

energy): references/common_workflows_code.md.

Bundled Resources

Scripts (`scripts/`)

detection). Usage: python scripts/structure_converter.py POSCAR structure.cif

matrix. Usage: python scripts/structure_analyzer.py structure.cif --symmetry --neighbors

analysis. Usage: python scripts/phase_diagram_generator.py Li-Fe-O --analyze "LiFeO2"

All scripts include detailed help, e.g. python scripts/structure_converter.py --help

References (`references/`)

Best Practices

Structures: use auto format detection; prefer IStructure when immutable; reduce to

primitive cell with SpacegroupAnalyzer; validate for overlapping atoms / bad bond

lengths. File I/O: prefer from_file()/to(); specify format when detection fails;

use as_dict()/from_dict() for version-safe storage. MP API: always use the context

manager; batch queries; cache results; filter by property. Workflows: prefer input

sets over manual INCAR; verify convergence; track transformations for provenance.

Performance: use primitive cells; bound neighbor-search cutoffs; parallelize where

possible.

Units and Conventions

Lengths in Å, energies in eV, angles in degrees, magnetic moments in μB, time in fs.

Convert with pymatgen.core.units.

Integration

Integrates with ASE, Phonopy, BoltzTraP, Atomate/Fireworks, AiiDA, Zeo++, and OpenBabel.

Troubleshooting

Additional Resources

Docs: https://pymatgen.org/ · Materials Project: https://materialsproject.org/ ·

GitHub: https://github.com/materialsproject/pymatgen · Forum: https://matsci.org/ ·

Example notebooks: https://matgenb.materialsvirtuallab.org/

Version Notes

Designed for pymatgen 2024.x and later. For the Materials Project API, use the mp-api

package (separate from legacy pymatgen.ext.matproj). Requirements: Python ≥ 3.10,

pymatgen ≥ 2023.x, mp-api (for Materials Project access).

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.