pymatgen
Materials science toolkit. Crystal structures (CIF, POSCAR), phase diagrams, band structure, DOS, Materials Project integration, format conversion, for computational materials science.
Install
mkdir -p .claude/skills/pymatgen && curl -L -o skill.zip "https://mcp.directory/api/skills/download/2574" && unzip -o skill.zip -d .claude/skills/pymatgen && rm skill.zipInstalls to .claude/skills/pymatgen
About this skill
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
- 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
# 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
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
# Set up API key
export MP_API_KEY="your_api_key_here"
from mp_api.client import MPRester
with MPRester() as mpr:
# Get structure by material ID
struct = mpr.get_structure_by_material_id("mp-149")
# Search for materials
materials = mpr.materials.summary.search(
formula="Fe2O3",
energy_above_hull=(0, 0.05)
)
Core Capabilities
1. Structure Creation and Manipulation
Create structures using various methods and perform transformations.
From files:
# Automatic format detection
struct = Structure.from_file("structure.cif")
struct = Structure.from_file("POSCAR")
mol = Molecule.from_file("molecule.xyz")
From scratch:
from pymatgen.core import Structure, Lattice
# Using lattice parameters
lattice = Lattice.from_parameters(a=3.84, b=3.84, c=3.84,
alpha=120, beta=90, gamma=60)
coords = [[0, 0, 0], [0.75, 0.5, 0.75]]
struct = Structure(lattice, ["Si", "Si"], coords)
# From space group
struct = Structure.from_spacegroup(
"Fm-3m",
Lattice.cubic(3.5),
["Si"],
[[0, 0, 0]]
)
Transformations:
from pymatgen.transformations.standard_transformations import (
SupercellTransformation,
SubstitutionTransformation,
PrimitiveCellTransformation
)
# Create supercell
trans = SupercellTransformation([[2,0,0],[0,2,0],[0,0,2]])
supercell = trans.apply_transformation(struct)
# Substitute elements
trans = SubstitutionTransformation({"Fe": "Mn"})
new_struct = trans.apply_transformation(struct)
# Get primitive cell
trans = PrimitiveCellTransformation()
primitive = trans.apply_transformation(struct)
Reference: See references/core_classes.md for comprehensive documentation of Structure, Lattice, Molecule, and related classes.
2. File Format Conversion
Convert between 100+ file formats with automatic format detection.
Using convenience methods:
# Read any format
struct = Structure.from_file("input_file")
# Write to any format
struct.to(filename="output.cif")
struct.to(filename="POSCAR")
struct.to(filename="output.xyz")
Using the conversion script:
# Single file conversion
python scripts/structure_converter.py POSCAR structure.cif
# Batch conversion
python scripts/structure_converter.py *.cif --output-dir ./poscar_files --format poscar
Reference: See references/io_formats.md for detailed documentation of all supported formats and code integrations.
3. Structure Analysis and Symmetry
Analyze structures for symmetry, coordination, and other properties.
Symmetry analysis:
from pymatgen.symmetry.analyzer import SpacegroupAnalyzer
sga = SpacegroupAnalyzer(struct)
# Get space group information
print(f"Space group: {sga.get_space_group_symbol()}")
print(f"Number: {sga.get_space_group_number()}")
print(f"Crystal system: {sga.get_crystal_system()}")
# Get conventional/primitive cells
conventional = sga.get_conventional_standard_structure()
primitive = sga.get_primitive_standard_structure()
Coordination environment:
from pymatgen.analysis.local_env import CrystalNN
cnn = CrystalNN()
neighbors = cnn.get_nn_info(struct, n=0) # Neighbors of site 0
print(f"Coordination number: {len(neighbors)}")
for neighbor in neighbors:
site = struct[neighbor['site_index']]
print(f" {site.species_string} at {neighbor['weight']:.3f} Å")
Using the analysis script:
# Comprehensive analysis
python scripts/structure_analyzer.py POSCAR --symmetry --neighbors
# Export results
python scripts/structure_analyzer.py structure.cif --symmetry --export json
Reference: See references/analysis_modules.md for detailed documentation of all analysis capabilities.
4. Phase Diagrams and Thermodynamics
Construct phase diagrams and analyze thermodynamic stability.
Phase diagram construction:
from mp_api.client import MPRester
from pymatgen.analysis.phase_diagram import PhaseDiagram, PDPlotter
# Get entries from Materials Project
with MPRester() as mpr:
entries = mpr.get_entries_in_chemsys("Li-Fe-O")
# Build phase diagram
pd = PhaseDiagram(entries)
# Check stability
from pymatgen.core import Composition
comp = Composition("LiFeO2")
# Find entry for composition
for entry in entries:
if entry.composition.reduced_formula == comp.reduced_formula:
e_above_hull = pd.get_e_above_hull(entry)
print(f"Energy above hull: {e_above_hull:.4f} eV/atom")
if e_above_hull > 0.001:
# Get decomposition
decomp = pd.get_decomposition(comp)
print("Decomposes to:", decomp)
# Plot
plotter = PDPlotter(pd)
plotter.show()
Using the phase diagram script:
# Generate phase diagram
python scripts/phase_diagram_generator.py Li-Fe-O --output li_fe_o.png
# Analyze specific composition
python scripts/phase_diagram_generator.py Li-Fe-O --analyze "LiFeO2" --show
Reference: See references/analysis_modules.md (Phase Diagrams section) and references/transformations_workflows.md (Workflow 2) for detailed examples.
5. Electronic Structure Analysis
Analyze band structures, density of states, and electronic properties.
Band structure:
from pymatgen.io.vasp import Vasprun
from pymatgen.electronic_structure.plotter import BSPlotter
# Read from VASP calculation
vasprun = Vasprun("vasprun.xml")
bs = vasprun.get_band_structure()
# Analyze
band_gap = bs.get_band_gap()
print(f"Band gap: {band_gap['energy']:.3f} eV")
print(f"Direct: {band_gap['direct']}")
print(f"Is metal: {bs.is_metal()}")
# Plot
plotter = BSPlotter(bs)
plotter.save_plot("band_structure.png")
Density of states:
from pymatgen.electronic_structure.plotter import DosPlotter
dos = vasprun.complete_dos
# Get element-projected DOS
element_dos = dos.get_element_dos()
for element, element_dos_obj in element_dos.items():
print(f"{element}: {element_dos_obj.get_gap():.3f} eV")
# Plot
plotter = DosPlotter()
plotter.add_dos("Total DOS", dos)
plotter.show()
Reference: See references/analysis_modules.md (Electronic Structure section) and references/io_formats.md (VASP section).
6. Surface and Interface Analysis
Generate slabs, analyze surfaces, and study interfaces.
Slab generation:
from pymatgen.core.surface import SlabGenerator
# Generate slabs for specific Miller index
slabgen = SlabGenerator(
struct,
miller_index=(1, 1, 1),
min_slab_size=10.0, # Å
min_vacuum_size=10.0, # Å
center_slab=True
)
slabs = slabgen.get_slabs()
# Write slabs
for i, slab in enumerate(slabs):
slab.to(filename=f"slab_{i}.cif")
Wulff shape construction:
from pymatgen.analysis.wulff import WulffShape
# Define surface energies
surface_energies = {
(1, 0, 0): 1.0,
(1, 1, 0): 1.1,
(1, 1, 1): 0.9,
}
wulff = WulffShape(struct.lattice, surface_energies)
print(f"Surface area: {wulff.surface_area:.2f} Ų")
print(f"Volume: {wulff.volume:.2f} ų")
wulff.show()
Adsorption site finding:
from pymatgen.analysis.adsorption import AdsorbateSiteFinder
from pymatgen.core import Molecule
asf = AdsorbateSiteFinder(slab)
# Find sites
ads_sites = asf.find_adsorption_sites()
print(f"On-top sites: {len(ads_sites['ontop'])}")
print(f"Bridge sites: {len(ads_sites['bridge'])}")
print(f"Hollow sites: {len(ads_sites['hollow'])}")
# Add adsorbate
adsorbate = Molecule("O", [[0, 0, 0]])
ads_struct = asf.add_adsorbate(adsorbate, ads_sites["ontop"][0])
Reference: See references/analysis_modules.md (Surface and Interface section) and references/transformations_workflows.md (Workflows 3 and 9).
7. Materials Project Database Access
Programmatically access the Materials Project database.
Setup:
- Get API key from https://next-g
Content truncated.
More by benchflow-ai
View all skills by benchflow-ai →You might also like
flutter-development
aj-geddes
Build beautiful cross-platform mobile apps with Flutter and Dart. Covers widgets, state management with Provider/BLoC, navigation, API integration, and material design.
drawio-diagrams-enhanced
jgtolentino
Create professional draw.io (diagrams.net) diagrams in XML format (.drawio files) with integrated PMP/PMBOK methodologies, extensive visual asset libraries, and industry-standard professional templates. Use this skill when users ask to create flowcharts, swimlane diagrams, cross-functional flowcharts, org charts, network diagrams, UML diagrams, BPMN, project management diagrams (WBS, Gantt, PERT, RACI), risk matrices, stakeholder maps, or any other visual diagram in draw.io format. This skill includes access to custom shape libraries for icons, clipart, and professional symbols.
ui-ux-pro-max
nextlevelbuilder
"UI/UX design intelligence. 50 styles, 21 palettes, 50 font pairings, 20 charts, 8 stacks (React, Next.js, Vue, Svelte, SwiftUI, React Native, Flutter, Tailwind). Actions: plan, build, create, design, implement, review, fix, improve, optimize, enhance, refactor, check UI/UX code. Projects: website, landing page, dashboard, admin panel, e-commerce, SaaS, portfolio, blog, mobile app, .html, .tsx, .vue, .svelte. Elements: button, modal, navbar, sidebar, card, table, form, chart. Styles: glassmorphism, claymorphism, minimalism, brutalism, neumorphism, bento grid, dark mode, responsive, skeuomorphism, flat design. Topics: color palette, accessibility, animation, layout, typography, font pairing, spacing, hover, shadow, gradient."
godot
bfollington
This skill should be used when working on Godot Engine projects. It provides specialized knowledge of Godot's file formats (.gd, .tscn, .tres), architecture patterns (component-based, signal-driven, resource-based), common pitfalls, validation tools, code templates, and CLI workflows. The `godot` command is available for running the game, validating scripts, importing resources, and exporting builds. Use this skill for tasks involving Godot game development, debugging scene/resource files, implementing game systems, or creating new Godot components.
nano-banana-pro
garg-aayush
Generate and edit images using Google's Nano Banana Pro (Gemini 3 Pro Image) API. Use when the user asks to generate, create, edit, modify, change, alter, or update images. Also use when user references an existing image file and asks to modify it in any way (e.g., "modify this image", "change the background", "replace X with Y"). Supports both text-to-image generation and image-to-image editing with configurable resolution (1K default, 2K, or 4K for high resolution). DO NOT read the image file first - use this skill directly with the --input-image parameter.
fastapi-templates
wshobson
Create production-ready FastAPI projects with async patterns, dependency injection, and comprehensive error handling. Use when building new FastAPI applications or setting up backend API projects.
Related MCP Servers
Browse all serversSerena is a free AI code generator toolkit providing robust code editing and retrieval, turning LLMs into powerful artif
Connect Blender to Claude AI for seamless 3D modeling. Use AI 3D model generator tools for faster, intuitive, interactiv
Unlock powerful text to speech and AI voice generator tools with ElevenLabs. Create, clone, and customize speech easily.
FinLab AI — quantitative trading toolkit with extensive data access, backtesting platform, and algorithmic trading tools
Foundry Toolkit: Deploy, test, and analyze smart contracts on EVM networks and local Anvil with powerful blockchain dev
Frida enables dynamic instrumentation and debugging for mobile and desktop apps, offering advanced process management an
Stay ahead of the MCP ecosystem
Get weekly updates on new skills and servers.