pymatgen-materials
Materials science computation with pymatgen. Use when: (1) crystal structure creation and manipulation, (2) phase diagram construction, (3) electronic structure analysis, (4) symmetry and space group operations, (5) VASP input/output parsing. NOT for: molecular chemistry (use rdkit-chemistry), protein structure (use biopython-bio), or general numerical computation (use scipy-analysis).
Best use case
pymatgen-materials is best used when you need a repeatable AI agent workflow instead of a one-off prompt.
Materials science computation with pymatgen. Use when: (1) crystal structure creation and manipulation, (2) phase diagram construction, (3) electronic structure analysis, (4) symmetry and space group operations, (5) VASP input/output parsing. NOT for: molecular chemistry (use rdkit-chemistry), protein structure (use biopython-bio), or general numerical computation (use scipy-analysis).
Teams using pymatgen-materials should expect a more consistent output, faster repeated execution, less prompt rewriting.
When to use this skill
- You want a reusable workflow that can be run more than once with consistent structure.
When not to use this skill
- You only need a quick one-off answer and do not need a reusable workflow.
- You cannot install or maintain the underlying files, dependencies, or repository context.
Installation
Claude Code / Cursor / Codex
Manual Installation
- Download SKILL.md from GitHub
- Place it in
.claude/skills/pymatgen-materials/SKILL.mdinside your project - Restart your AI agent — it will auto-discover the skill
How pymatgen-materials Compares
| Feature / Agent | pymatgen-materials | Standard Approach |
|---|---|---|
| Platform Support | Not specified | Limited / Varies |
| Context Awareness | High | Baseline |
| Installation Complexity | Unknown | N/A |
Frequently Asked Questions
What does this skill do?
Materials science computation with pymatgen. Use when: (1) crystal structure creation and manipulation, (2) phase diagram construction, (3) electronic structure analysis, (4) symmetry and space group operations, (5) VASP input/output parsing. NOT for: molecular chemistry (use rdkit-chemistry), protein structure (use biopython-bio), or general numerical computation (use scipy-analysis).
Where can I find the source code?
You can find the source code on GitHub using the link provided at the top of the page.
SKILL.md Source
# Pymatgen Materials Science
Materials science analysis using pymatgen for crystal structures, phase diagrams,
electronic structure, and computational materials workflows.
## When to Use
- Crystal structure creation, manipulation, and visualization
- Phase diagram construction and thermodynamic stability analysis
- Electronic structure (band structure, DOS) parsing and plotting
- Symmetry analysis and space group determination
- Reading/writing VASP, CIF, POSCAR, and other structure formats
## When NOT to Use
- Molecular chemistry or drug design (use rdkit-chemistry)
- Protein or biomolecular structure (use biopython-bio)
- General plotting without materials context (use matplotlib-viz)
- Machine learning on materials data (use dedicated ML frameworks)
## Crystal Structure Creation
```python
from pymatgen.core import Structure, Lattice, Molecule
# Create from spacegroup and Wyckoff positions
structure = Structure.from_spacegroup(
"Fm-3m", Lattice.cubic(5.43), ["Si"], [[0, 0, 0]]
)
# Create from file
structure = Structure.from_file("POSCAR")
structure = Structure.from_file("structure.cif")
# Create manually with lattice parameters
lattice = Lattice.from_parameters(a=3.84, b=3.84, c=3.84, alpha=90, beta=90, gamma=90)
structure = Structure(lattice, ["Cu", "Cu", "Cu", "Cu"],
[[0, 0, 0], [0.5, 0.5, 0], [0.5, 0, 0.5], [0, 0.5, 0.5]])
# Hexagonal lattice
lattice = Lattice.hexagonal(a=2.46, c=6.71)
```
## Structure Properties and Manipulation
```python
# Basic properties
print(structure.lattice) # lattice vectors
print(structure.lattice.abc) # a, b, c lengths
print(structure.lattice.angles) # alpha, beta, gamma
print(structure.volume) # unit cell volume
print(structure.density) # density in g/cm^3
print(structure.composition) # chemical formula
print(len(structure)) # number of sites
# Space group and symmetry
from pymatgen.symmetry.analyzer import SpacegroupAnalyzer
sga = SpacegroupAnalyzer(structure)
print(sga.get_space_group_symbol()) # e.g., "Fm-3m"
print(sga.get_space_group_number()) # e.g., 225
print(sga.get_point_group_symbol()) # e.g., "m-3m"
conventional = sga.get_conventional_standard_structure()
primitive = sga.get_primitive_standard_structure()
# Supercell and perturbation
supercell = structure.copy()
supercell.make_supercell([2, 2, 2])
structure.perturb(0.01) # random perturbation
# Write to file
structure.to(filename="POSCAR")
structure.to(filename="output.cif")
structure.to(fmt="poscar") # return as string
```
## Phase Diagrams
```python
from pymatgen.analysis.phase_diagram import PhaseDiagram, PDPlotter, PDEntry
from pymatgen.core import Composition
# Build entries from computed energies
entries = [
PDEntry(Composition("Li"), -1.9),
PDEntry(Composition("Fe"), -8.3),
PDEntry(Composition("O"), -4.95),
PDEntry(Composition("LiFePO4"), -43.2),
PDEntry(Composition("FePO4"), -38.5),
PDEntry(Composition("Li3PO4"), -25.6),
]
# Construct phase diagram
pd = PhaseDiagram(entries)
# Stability analysis
for entry in entries:
ehull = pd.get_e_above_hull(entry)
print(f"{entry.composition.reduced_formula}: E_above_hull = {ehull:.3f} eV/atom")
# Decomposition products
decomp, ehull = pd.get_decomp_and_e_above_hull(entries[3])
for comp, amount in decomp.items():
print(f" {comp.reduced_formula}: {amount:.3f}")
# Plot
plotter = PDPlotter(pd)
plotter.get_plot().savefig("phase_diagram.pdf")
```
## Electronic Structure
```python
from pymatgen.io.vasp import Vasprun, BSVasprun
from pymatgen.electronic_structure.plotter import BSPlotter, DosPlotter
# Parse VASP output
vasprun = Vasprun("vasprun.xml", parse_dos=True, parse_eigen=True)
print(f"Final energy: {vasprun.final_energy} eV")
print(f"Converged: {vasprun.converged}")
# Band structure
bs_vasprun = BSVasprun("vasprun.xml")
bs = bs_vasprun.get_band_structure(line_mode=True)
print(f"Band gap: {bs.get_band_gap()['energy']:.3f} eV")
print(f"Direct: {bs.get_band_gap()['direct']}")
bs_plotter = BSPlotter(bs)
bs_plotter.get_plot().savefig("band_structure.pdf")
# Density of states
dos = vasprun.complete_dos
dos_plotter = DosPlotter()
dos_plotter.add_dos("Total", dos)
dos_plotter.add_dos_dict(dos.get_element_dos())
dos_plotter.get_plot().savefig("dos.pdf")
```
## VASP I/O
```python
from pymatgen.io.vasp import Poscar, Incar, Kpoints, Outcar
# Read VASP files
poscar = Poscar.from_file("POSCAR")
structure = poscar.structure
incar = Incar.from_file("INCAR")
print(incar["ENCUT"])
kpoints = Kpoints.from_file("KPOINTS")
outcar = Outcar("OUTCAR")
print(f"Total magnetization: {outcar.total_mag}")
print(f"Final energy: {outcar.final_energy}")
# Create VASP input set
from pymatgen.io.vasp.sets import MPRelaxSet
relax_set = MPRelaxSet(structure)
relax_set.write_input("vasp_input/")
```
## Best Practices
1. Always check symmetry with `SpacegroupAnalyzer` after structure creation.
2. Use `get_primitive_standard_structure()` to reduce computational cost.
3. Validate structures with `structure.is_valid()` before running calculations.
4. Use Materials Project API (`MPRester`) to fetch known structures and energies.
5. When comparing energies, normalize per atom (`energy / len(structure)`).
6. Save structures in CIF format for archival and POSCAR for VASP input.
7. Use `structure.get_neighbors()` for local environment analysis.
8. Check convergence flags in `Vasprun` before trusting computed properties.Related Skills
materials-screening
Orchestrates a materials screening workflow from database search through property filtering to stability assessment and ranking. Use when identifying candidate materials for batteries, catalysts, semiconductors, or other applications. NOT for molecular chemistry or biological compound analysis.
materials-science
Analyzes material properties including crystal structures, phase diagrams, mechanical/thermal/electronic properties, and supports materials discovery through computational approaches; trigger when users discuss alloys, ceramics, polymers, nanomaterials, or materials characterization.
materials-project
Query the Materials Project API v3 for crystal structures, band gaps, formation energies, and thermodynamic stability of 150k+ inorganic materials. Use when: (1) searching materials by chemical formula, (2) looking up material properties by MP ID, (3) filtering materials by band gap, energy, or density, (4) finding stable phases for a composition. NOT for: organic molecules (use pubchem-compound), proteins (use uniprot-protein), drug compounds (use chembl-drug).
xurl
A CLI tool for making authenticated requests to the X (Twitter) API. Use this skill when you need to post tweets, reply, quote, search, read posts, manage followers, send DMs, upload media, or interact with any X API v2 endpoint.
xlsx
Use this skill any time a spreadsheet file is the primary input or output. This means any task where the user wants to: open, read, edit, or fix an existing .xlsx, .xlsm, .csv, or .tsv file (e.g., adding columns, computing formulas, formatting, charting, cleaning messy data); create a new spreadsheet from scratch or from other data sources; or convert between tabular file formats. Trigger especially when the user references a spreadsheet file by name or path — even casually (like "the xlsx in my downloads") — and wants something done to it or produced from it. Also trigger for cleaning or restructuring messy tabular data files (malformed rows, misplaced headers, junk data) into proper spreadsheets. The deliverable must be a spreadsheet file. Do NOT trigger when the primary deliverable is a Word document, HTML report, standalone Python script, database pipeline, or Google Sheets API integration, even if tabular data is involved.
writing
No description provided.
world-bank-data
World Bank Open Data API for development indicators. Use when: user asks about GDP, population, poverty, health, or education statistics by country. NOT for: real-time financial data or stock prices.
wikipedia-search
Search and fetch structured content from Wikipedia using the MediaWiki API for reliable, encyclopedic information
wikidata-knowledge
Query Wikidata for structured knowledge using SPARQL and entity search. Use when: (1) finding structured facts about entities (people, places, organizations), (2) querying relationships between entities, (3) cross-referencing external identifiers (Wikipedia, VIAF, GND, ORCID), (4) building knowledge graphs from linked data. NOT for: full-text article content (use Wikipedia API), scientific literature (use semantic-scholar), geospatial data (use OpenStreetMap).
weather
Get current weather and forecasts via wttr.in or Open-Meteo. Use when: user asks about weather, temperature, or forecasts for any location. NOT for: historical weather data, severe weather alerts, or detailed meteorological analysis. No API key needed.
wacli
Send WhatsApp messages to other people or search/sync WhatsApp history via the wacli CLI (not for normal user chats).
voice-call
Start voice calls via the OpenClaw voice-call plugin.