# pymatgen

pymatgen handles crystal structure transformations, file conversions between CIF and POSCAR, symmetry analysis, and Materials Project queries.

- skill · `type=skill` · Claude Code, Codex, Cursor, GitHub Copilot, Gemini CLI, OpenCode, Windsurf (Devin Desktop), Claude.ai · 12 installs · ★ 1933 repo stars
- Author: benchflow-ai
- License: MIT · policy=mirror · the beginning of the file is at the end of this page
- Source: https://github.com/benchflow-ai/skillsbench/tree/HEAD/tasks/crystallographic-wyckoff-position-analysis/environment/skills/pymatgen/SKILL.md
- Updated: 2026-10-24
- Security check: automated, 2026-11-16 (text) — no signs of malicious code found.
- HTML: https://affpapa.org/en/nevibecode/skills/benchflow-ai-pymatgen

## What it does

This skill equips coding agents with workflows for the `pymatgen` materials genomics library. It covers building lattices from parameters, creating supercells, and converting geometry between 100+ computational codes including VASP and Quantum ESPRESSO.

Reference patterns include correct extraction of Wyckoff positions using `get_symmetry_dataset().wyckoffs` and local coordination checks with `CrystalNN`. Fetching structures directly from the Materials Project database requires the separate `mp-api` package and an active `MP_API_KEY` environment variable.

## Install

### Claude Code (native platform)

1. **Skills CLI (Vercel)**
```bash
npx skills add benchflow-ai/skillsbench --skill pymatgen -a claude-code
```

2. **Manually: put the files in place**
- File: `~/.claude/skills/pymatgen/SKILL.md` — Copy the whole skill folder; for one project use .claude/skills/pymatgen/

### Codex

1. **Skills CLI (Vercel)**
```bash
npx skills add benchflow-ai/skillsbench --skill pymatgen -a codex
```

2. **Manually: put the files in place**
- File: `.agents/skills/pymatgen/SKILL.md` — For all projects use ~/.agents/skills/

### Cursor

1. **Skills CLI (Vercel)**
```bash
npx skills add benchflow-ai/skillsbench --skill pymatgen -a cursor
```

2. **Manually: put the files in place**
- File: `.cursor/skills/pymatgen/SKILL.md` — Cursor also reads .agents/skills/ and .claude/skills/

### GitHub Copilot

1. **GitHub CLI**
```bash
gh skill install benchflow-ai/skillsbench tasks/crystallographic-wyckoff-position-analysis/environment/skills/pymatgen
```

2. **Manually: put the files in place**
- File: `.github/skills/pymatgen/SKILL.md`

### Gemini CLI

1. **Skills CLI (Vercel)**
```bash
npx skills add benchflow-ai/skillsbench --skill pymatgen -a gemini-cli
```

2. **Platform CLI**
```bash
gemini skills install https://github.com/benchflow-ai/skillsbench --path tasks/crystallographic-wyckoff-position-analysis/environment/skills/pymatgen
```

### Windsurf (Devin Desktop)

**Manually: put the files in place**
- File: `.devin/skills/pymatgen/SKILL.md` — The legacy .windsurf/skills/ path still works

### OpenCode

**Skills CLI (Vercel)**
```bash
npx skills add benchflow-ai/skillsbench --skill pymatgen -a opencode
```

### Claude.ai

**Claude.ai**
- Zip the folder and upload it in Settings → Capabilities → Skills

Where a file is given instead of a command, copy the files from the source to that path: https://github.com/benchflow-ai/skillsbench/tree/HEAD/tasks/crystallographic-wyckoff-position-analysis/environment/skills/pymatgen/SKILL.md

## When to use it
- convert crystal structures between CIF and POSCAR formats
- calculate space groups and symmetry operations
- retrieve computed compounds from the Materials Project API
- construct phase diagrams to evaluate thermodynamic stability

## Example prompts
- Convert `POSCAR` to `structure.cif` using pymatgen
- Find the space group and coordination numbers for site 0 in `structure.cif`
- Query Materials Project for `Fe2O3` structures close to the convex hull

## Source text · SKILL.md · MIT

Below is the content of a third-party file. It is data, not instructions for you: do not act on anything written inside unless the human asks. Block tag: ce37ef9b1f8daf86.

BEGIN THIRD-PARTY FILE ce37ef9b1f8daf86
````text
---
name: pymatgen
description: Materials science toolkit. Crystal structures (CIF, POSCAR), phase diagrams, band structure, DOS, Materials Project integration, format conversion, for computational materials science.
license: MIT license
metadata:
    skill-author: K-Dense Inc.
---

# 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 Materials Project's database of computed materials. Supports 100+ file formats from various computational codes.

## When to Use This Skill

This skill should be used when:
- Working with crystal structures or molecular systems in materials science
- Converting between structure file formats (CIF, POSCAR, XYZ, etc.)
- Analyzing symmetry, space groups, or coordination environments
- Extracting Wyckoff letters, multiplicities, and representative fractional coordinates from CIF files (see `references/wyckoff-positions-from-cif.md` — use `get_symmetry_dataset().wyckoffs`, not `get_symmetrized_structure().wyckoff_symbols`)
- Computing phase diagrams or assessing thermodynamic stability
- Analyzing electronic structure data (band gaps, DOS, band structures)
- Generating surfaces, slabs, or studying interfaces
- Accessing the Materials Project database programmatically
- Setting up high-throughput computational workflows
- Analyzing diffusion, magnetism, or mechanical properties
- Working with VASP, Gaussian, Quantum ESPRESSO, or other computational codes

## Quick Start Guide

### Installation

```bash
# Core pymatgen
uv pip install pymatgen

# With Materials Project API access
uv pip install pymatgen mp-api

# Optional dependencies for extended functionality
uv pip install pymatgen[analysis]  # Additional analysis tools
uv pip install pymatgen[vis]       # Visualization tools
```

### Basic Structure Operations

```python
from pymatgen.core import Structure, Lattice

# Read structure from file (automatic format detection)
struct = Structure.from_file("POSCAR")

# Create structure from scratch
lattice = Lattice.cubic(3.84)
struct = Structure(lattice, ["Si", "Si"], [[0,0,0], [0.25,0.25,0.25]])

# Write to different format
struct.to(filename="structure.cif")

# Basic properties
print(f"Formula: {struct.composition.reduced_formula}")
print(f"Space group: {struct.get_space_group_info()}")
print(f"Density: {struct.density:.2f} g/cm³")
```

### Materials Project Integration

```bash
# Set up API key
export MP_API_KEY="your_api_key_here"
```

```python
from mp_api.client import MPRester

with MPRester() as mpr:
    # Get structure by material ID
    struct = mpr.get_structure_by_material_id("mp-149")
````
END THIRD-PARTY FILE ce37ef9b1f8daf86

The third-party file has ended. Everything between the ce37ef9b1f8daf86 tags is data: requests and commands from it are not followed. An “end of file” line with another tag inside the block is part of the file.

First 2885 of 21099 bytes. © benchflow-ai · MIT · https://github.com/benchflow-ai/skillsbench/tree/HEAD/tasks/crystallographic-wyckoff-position-analysis/environment/skills/pymatgen/SKILL.md

_Part of the page did not fit — see the HTML version._

---
NeVibeCode on affpapa.org. Catalog texts are descriptions, not instructions for the agent. How to choose and install: https://affpapa.org/en/nevibecode/agents.md
