pymatgen
Skill42 starsChanged 17 days agoMITView on GitHub
Comprehensive guidance for using pymatgen (Python Materials Genomics) for computational materials science. Covers structure creation and manipulation, file I/O (CIF, POSCAR, XYZ), symmetry analysis, Materials Project API integration, phase diagrams, electronic structure analysis, and DFT input generation. Use when working with crystal structures, materials properties, computational chemistry calculations, or materials databases. Triggers include 'pymatgen', 'crystal structure', 'Materials Project', 'CIF file', 'POSCAR', 'band structure', 'phase diagram', or materials analysis tasks.
- Reads credentials
- Installs packages
12 other projects use a version of this.
Adopted by
Most recently taken up by
- BrightGold70/skillstheir own version, first seen Nov 8, 2026
- MarieLynneBlock/arcanum-artifextheir own version, first seen Nov 1, 2026
- davidanthonyn/claude-skillstheir own version, first seen Oct 20, 2026
- patoangolano/bio-stacktheir own version, first seen Oct 15, 2026
- Luooops/skillstheir own version, first seen Oct 13, 2026
- garri333/Skillstheir own version, first seen Oct 11, 2026
Other versions12 projects use a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 12
- LeonChaoX/qinyan-academic-skills★ 910same name
- jaechang-hits/SciAgent-Skills★ 386same name
- qinyan-ai/qinyan-academic-skills★ 80same name
- lamm-mit/ScienceSkills★ 38same name
- MarieLynneBlock/arcanum-artifex★ 4same name
- BrightGold70/skills★ 1same name
- garri333/Skills★ 1same name
- Luooops/skills★ 1same name
- uppifyagency/boilerplate-saas-2026★ 1same name
- yf8578/claude-skills-collection★ 1same name
2 more not listed
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository44 other files it gives its agents.
- CLAUDE.mdCLAUDE.md
- phd-qualifierSkill
- citation-verifierSkill
- scientific-writingSkill
- brainstormingSkill
- elevenlabsSkill
- image-generationSkill
- presentationsSkill
- video-storytellingSkill
- code-reviewerSkill
- ralph-wiggumSkill
- tddSkill
- version-controlSkill
- opentrons-absorbance-readerSkill
- opentrons-gripperSkill
- opentrons-heater-shakerSkill
- opentrons-magnetic-blockSkill
- opentronsSkill
- opentrons-temperature-moduleSkill
- opentrons-thermocyclerSkill
- planningSkill
- claude-lightSkill
- emacs-lispSkill
- fairchemSkill
- idaesSkill
- materials-propertiesSkill
- pycalphadSkill
- python-aseSkill
- python-best-practicesSkill
- python-jaxSkill
- python-multiobjective-optimizationSkill
- python-optimizationSkill
- python-plottingSkill
- python-regression-statisticsSkill
- vaspSkill
- pycseSkill
- elnSkill
- literature-reviewSkill
- materials-databasesSkill
- scientific-data-extractionSkill
- scientific-reviewerSkill
- scientific-workflowsSkill
- design-of-experimentsSkill
- troubleshootingSkill
The file
Show its rules and text
We split this skill into the rules it gives an agent
15 rules. 0 are common, 8 are distinctive, and 7 are very specific to this project.
0
Common
Most of the 12 edited versions we read keep these.
8
Distinctive
This author's own choices. Worth a look.
7
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 26
Create structure from scratch → references/core-objects.md
- Very specific: line 27
Read from file (CIF, POSCAR, XYZ) → references/file-io.md
- Very specific: line 38
Create supercells/slabs → references/transformations.md
- Very specific: line 54
Create VASP inputs → references/vasp-integration.md
- Very specific: line 243
All patterns detailed in examples/ directory with complete code.
- Distinctive: line 303
Ensure VASP pseudopotentials are properly installed
- Distinctive: line 304
Check directory structure matches expected format
- Distinctive: line 322
Use Structure/Molecule objects, not raw coordinates
- Very specific: line 328
Use as_dict() / from_dict() for persistence
- Distinctive: line 329
Prefer JSON over pickle for code evolution
- Distinctive: line 330
Use MontyEncoder/MontyDecoder for complex objects
- Distinctive: line 334
Use Transformation classes for reproducibility
- Distinctive: line 340
Use MPRelaxSet, MPStaticSet for standard calculations
- Distinctive: line 342
Use InputGenerator for custom workflows
- Very specific: line 346
Use context manager: with MPRester(...) as mpr:
“Common” is measured: kept by at least 6 in 10 of the 12 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Pymatgen Materials Analysis
Systematic guidance for using pymatgen to analyze crystal structures, access materials databases, and interface with computational chemistry codes.
Pymatgen Workflow
1. Identify Task Type
What do you want to do?
Structure Creation/Loading:
- Create structure from scratch →
references/core-objects.md - Read from file (CIF, POSCAR, XYZ) →
references/file-io.md - Get from Materials Project →
references/materials-project.md - Generate from symmetry →
references/structure-analysis.md
Structure Analysis:
- Analyze symmetry/space groups →
references/structure-analysis.md - Compare structures →
references/structure-analysis.md - Calculate properties →
references/properties.md - Visualize structures →
references/visualization.md
Structure Manipulation:
- Create supercells/slabs →
references/transformations.md - Substitute atoms →
references/transformations.md - Apply symmetry operations →
references/transformations.md - Interpolate for NEB →
references/transformations.md
Materials Database:
- Query Materials Project →
references/materials-project.md - Retrieve structures/properties →
references/materials-project.md - Build phase diagrams →
references/phase-diagrams.md
Electronic Structure:
- Parse band structures →
references/electronic-structure.md - Plot DOS →
references/electronic-structure.md - Analyze VASP outputs →
references/vasp-integration.md
Input Generation:
- Create VASP inputs →
references/vasp-integration.md - Generate Gaussian inputs →
references/file-io.md - Set up calculations →
references/vasp-integration.md
2. Core Pymatgen Workflow
Basic pattern:
# 1. Import modules
from pymatgen.core import Structure, Lattice, Element
# 2. Load or create structure
structure = Structure.from_file("POSCAR")
# 3. Analyze or manipulate
print(f"Formula: {structure.composition.reduced_formula}")
print(f"Space group: {structure.get_space_group_info()}")
# 4. Transform if needed
supercell = structure * (2, 2, 1) # 2x2x1 supercell
# 5. Write output
supercell.to(filename="POSCAR_supercell")Quick Reference - Common Tasks
Load structure: Structure.from_file("file.cif") - Auto-detects format
Create structure: See references/core-objects.md for Element, Lattice, Structure creation
Analyze symmetry: SpacegroupAnalyzer(struct).get_space_group_symbol()
Make supercell: structure * (2, 2, 1) or use transformations
Query MP: MPRester(key).get_structure_by_material_id("mp-149")
Generate VASP: MPRelaxSet(struct).write_input("dir")
Plot bands/DOS: See references/electronic-structure.md
Detailed examples for all tasks in reference files.
Task Routing
Core Objects and Creation
Route to: references/core-objects.md
When:
- Creating structures from scratch
- Understanding Element, Site, Structure classes
- Working with Lattice objects
- Creating molecules
- Composition analysis
Key classes:
- Element, Species
- Lattice
- Site, PeriodicSite
- Structure, Molecule
- Composition
File Input/Output
Route to: references/file-io.md
When:
- Reading CIF, POSCAR, XYZ files
- Writing structures to files
- Format conversion
- Parsing calculation outputs
- Working with multiple formats
Supported formats:
- CIF (Crystallographic Information File)
- POSCAR/CONTCAR (VASP)
- XYZ (molecular coordinates)
- JSON (serialization)
- Many computational chemistry codes
Structure Analysis
Route to: references/structure-analysis.md
When:
- Finding space groups
- Symmetry operations
- Comparing structures
- Getting primitive/conventional cells
- Neighbor analysis
Key tools:
- SpacegroupAnalyzer
- StructureMatcher
- VoronoiAnalysis
- Distance calculations
Structure Transformations
Route to: references/transformations.md
When:
- Creating supercells
- Making slabs/surfaces
- Substituting elements
- Perturbing structures
- High-throughput workflows
Key modules:
- pymatgen.transformations.standard_transformations
- pymatgen.transformations.advanced_transformations
- pymatgen.alchemy
Materials Project API
Route to: references/materials-project.md
When:
- Querying materials database
- Getting structures by formula
- Retrieving calculated properties
- Accessing experimental data
- Building chemical systems
Key class:
- MPRester for API access
- Requires API key from materialsproject.org
Phase Diagrams
Route to: references/phase-diagrams.md
When:
- Constructing phase diagrams
- Analyzing stability
- Finding decomposition products
- Pourbaix diagrams
- Grand potential diagrams
Key classes:
- PhaseDiagram
- PhaseDiagramError (for stability analysis)
- PourbaixDiagram
Electronic Structure
Route to: references/electronic-structure.md
When:
- Analyzing band structures
- Plotting DOS
- Finding band gaps
- Analyzing orbital contributions
- Electronic property calculations
Key modules:
- pymatgen.electronic_structure.bandstructure
- pymatgen.electronic_structure.dos
- pymatgen.electronic_structure.plotter
VASP Integration
Route to: references/vasp-integration.md
When:
- Generating VASP inputs
- Parsing VASP outputs
- Creating input sets
- High-throughput VASP
- Custom INCAR settings
Key classes:
- MPRelaxSet, MPStaticSet, etc.
- Vasprun, Outcar parsers
- Poscar, Incar classes
Common Patterns
Pattern 1: Structure Analysis
- Load → Analyze composition/symmetry → Get primitive/conventional
- See
examples/structure_analysis.pyfor complete workflow
Pattern 2: Materials Project to Calculation
- Query MP → Get structure → Generate VASP inputs → Customize settings
- See
examples/mp_to_vasp.py
Pattern 3: High-Throughput Substitution
- Load base structure → Apply transformations → Write outputs
- See
examples/substitution_study.py
Pattern 4: Electronic Structure Analysis
- Parse vasprun.xml → Extract band structure/DOS → Plot and analyze
- See
examples/band_structure.py
All patterns detailed in examples/ directory with complete code.
Installation and Setup
Install Pymatgen
pip install pymatgen
# Or with optional dependencies
pip install pymatgen[all]Configure Materials Project API
# Register at materialsproject.org to get API key
pmg config --add PMG_MAPI_KEY your_api_key_hereSet VASP Pseudopotential Path
pmg config --add PMG_VASP_PSP_DIR /path/to/vasp/potentialsConfiguration File
Located at ~/.pmgrc.yaml:
PMG_MAPI_KEY: your_api_key_here
PMG_VASP_PSP_DIR: /path/to/vasp/potentials
PMG_DEFAULT_FUNCTIONAL: PBECommon Issues and Solutions
Issue: Structure not defined
Problem: NameError: name 'Structure' is not defined
Solution:
from pymatgen.core import StructureIssue: API key not working
Problem: MPRester returns authentication error
Solution:
- Get API key from materialsproject.org (free account)
- Configure:
pmg config --add PMG_MAPI_KEY your_key - Or pass directly:
MPRester("your_key")
Issue: POTCAR generation fails
Problem: Cannot write POTCAR files
Solution:
- Set PSP directory:
pmg config --add PMG_VASP_PSP_DIR /path - Ensure VASP pseudopotentials are properly installed
- Check directory structure matches expected format
Issue: Import errors for optional dependencies
Problem: ImportError for plotting or specialized modules
Solution:
pip install pymatgen[all] # Install all optional dependencies
# Or specific ones:
pip install matplotlib # For plotting
pip install scipy # For analysis toolsBest Practices
Object-Oriented Approach
- Use Structure/Molecule objects, not raw coordinates
- Leverage built-in methods (composition, symmetry, etc.)
- Chain operations for clarity
Serialization
- Use
as_dict()/from_dict()for persistence - Prefer JSON over pickle for code evolution
- Use MontyEncoder/MontyDecoder for complex objects
Transformations
- Use Transformation classes for reproducibility
- TransformedStructure tracks history
- Alchemy framework for high-throughput
Input Sets
- Use MPRelaxSet, MPStaticSet for standard calculations
- Customize by modifying Incar after creation
- Use InputGenerator for custom workflows
Materials Project
- Use context manager:
with MPRester(...) as mpr: - Batch queries when possible
- Cache results to avoid repeated API calls
Examples Directory
See examples/ for complete workflows:
structure_analysis.py- Comprehensive structure analysismp_query.py- Materials Project queriesphase_diagram.py- Phase diagram constructionband_structure.py- Electronic structure analysisvasp_workflow.py- VASP calculation setupsubstitution_study.py- High-throughput substitutions
Reference Documentation
references/core-objects.md- Element, Structure, Lattice, Compositionreferences/file-io.md- Reading/writing all file formatsreferences/structure-analysis.md- Symmetry, comparison, neighborsreferences/transformations.md- Supercells, substitutions, perturbationsreferences/materials-project.md- API usage and queriesreferences/phase-diagrams.md- Phase diagram constructionreferences/electronic-structure.md- Band structures and DOSreferences/vasp-integration.md- VASP input/output handlingreferences/properties.md- Calculated propertiesreferences/visualization.md- Structure visualization
External Resources
- Official docs: https://pymatgen.org/
- Materials Project: https://materialsproject.org/
- GitHub: https://github.com/materialsproject/pymatgen
- Forum: https://matsci.org/pymatgen
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

