[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M6AFKDKKDST88G616H6TZ41A":3,"skill-same:01M6AFKDKKDST88G616H6TZ41A":108},{"skillNo":4,"name":5,"nameZh":6,"description":7,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":16,"categories":17,"keywords":26,"publishedAt":43,"linkOnly":44,"markdownContent":45,"markdownBody":46,"frontMatter":47,"refName":48,"commitSha":49,"skillDirectory":50,"forksCount":51,"repositoryHtmlUrl":52,"repositoryHomepageUrl":53,"ownerHtmlUrl":54,"ownerBlogUrl":55,"ownerDescription":56,"updatedAt":57,"install":58,"resources":71},"01M6AFKDKKDST88G616H6TZ41A","pymatgen",null,"Materials science toolkit. Crystal structures (CIF, POSCAR), phase diagrams, band structure, DOS, Materials Project integration, format conversion, for computational materials science.","davila7\u002Fclaude-code-templates","davila7","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F6216945?v=4","01M6ADEWWFPS191NFM0Y1EX1JH","Daniel Avila","01M6ADJHGM78PHQRD3XZTFDVKK",33481,"MIT","https:\u002F\u002Fgithub.com\u002Fdavila7\u002Fclaude-code-templates\u002Fblob\u002Fmain\u002Fcli-tool\u002Fcomponents\u002Fskills\u002Fscientific\u002Fpymatgen\u002FSKILL.md",[18,23],{"categoryNo":19,"categoryName":20,"taxonomyType":21,"taxonomyTypeDesc":22},"01JBSEEDCAT000000000000010","后端与接口","SCENARIO","使用场景",{"categoryNo":24,"categoryName":25,"taxonomyType":21,"taxonomyTypeDesc":22},"01JBSEEDCAT000000000000023","Skill与智能体开发",[5,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42],"project","Materials Project","phase","materials","for","phase diagrams","crystal","Materials Science","computational","toolkit","structure","diagrams","conversion","format","science","integration","2026-11-10 10:12:30",false,"---\nname: pymatgen\ndescription: \"Materials science toolkit. Crystal structures (CIF, POSCAR), phase diagrams, band structure, DOS, Materials Project integration, format conversion, for computational materials science.\"\n---\n\n# Pymatgen - Python Materials Genomics\n\n## Overview\n\nPymatgen 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.\n\n## When to Use This Skill\n\nThis skill should be used when:\n- Working with crystal structures or molecular systems in materials science\n- Converting between structure file formats (CIF, POSCAR, XYZ, etc.)\n- Analyzing symmetry, space groups, or coordination environments\n- Computing phase diagrams or assessing thermodynamic stability\n- Analyzing electronic structure data (band gaps, DOS, band structures)\n- Generating surfaces, slabs, or studying interfaces\n- Accessing the Materials Project database programmatically\n- Setting up high-throughput computational workflows\n- Analyzing diffusion, magnetism, or mechanical properties\n- Working with VASP, Gaussian, Quantum ESPRESSO, or other computational codes\n\n## Quick Start Guide\n\n### Installation\n\n```bash\n# Core pymatgen\nuv pip install pymatgen\n\n# With Materials Project API access\nuv pip install pymatgen mp-api\n\n# Optional dependencies for extended functionality\nuv pip install pymatgen[analysis]  # Additional analysis tools\nuv pip install pymatgen[vis]       # Visualization tools\n```\n\n### Basic Structure Operations\n\n```python\nfrom pymatgen.core import Structure, Lattice\n\n# Read structure from file (automatic format detection)\nstruct = Structure.from_file(\"POSCAR\")\n\n# Create structure from scratch\nlattice = Lattice.cubic(3.84)\nstruct = Structure(lattice, [\"Si\", \"Si\"], [[0,0,0], [0.25,0.25,0.25]])\n\n# Write to different format\nstruct.to(filename=\"structure.cif\")\n\n# Basic properties\nprint(f\"Formula: {struct.composition.reduced_formula}\")\nprint(f\"Space group: {struct.get_space_group_info()}\")\nprint(f\"Density: {struct.density:.2f} g\u002Fcm³\")\n```\n\n### Materials Project Integration\n\n```bash\n# Set up API key\nexport MP_API_KEY=\"your_api_key_here\"\n```\n\n```python\nfrom mp_api.client import MPRester\n\nwith MPRester() as mpr:\n    # Get structure by material ID\n    struct = mpr.get_structure_by_material_id(\"mp-149\")\n\n    # Search for materials\n    materials = mpr.materials.summary.search(\n        formula=\"Fe2O3\",\n        energy_above_hull=(0, 0.05)\n    )\n```\n\n## Core Capabilities\n\n### 1. Structure Creation and Manipulation\n\nCreate structures using various methods and perform transformations.\n\n**From files:**\n```python\n# Automatic format detection\nstruct = Structure.from_file(\"structure.cif\")\nstruct = Structure.from_file(\"POSCAR\")\nmol = Molecule.from_file(\"molecule.xyz\")\n```\n\n**From scratch:**\n```python\nfrom pymatgen.core import Structure, Lattice\n\n# Using lattice parameters\nlattice = Lattice.from_parameters(a=3.84, b=3.84, c=3.84,\n                                  alpha=120, beta=90, gamma=60)\ncoords = [[0, 0, 0], [0.75, 0.5, 0.75]]\nstruct = Structure(lattice, [\"Si\", \"Si\"], coords)\n\n# From space group\nstruct = Structure.from_spacegroup(\n    \"Fm-3m\",\n    Lattice.cubic(3.5),\n    [\"Si\"],\n    [[0, 0, 0]]\n)\n```\n\n**Transformations:**\n```python\nfrom pymatgen.transformations.standard_transformations import (\n    SupercellTransformation,\n    SubstitutionTransformation,\n    PrimitiveCellTransformation\n)\n\n# Create supercell\ntrans = SupercellTransformation([[2,0,0],[0,2,0],[0,0,2]])\nsupercell = trans.apply_transformation(struct)\n\n# Substitute elements\ntrans = SubstitutionTransformation({\"Fe\": \"Mn\"})\nnew_struct = trans.apply_transformation(struct)\n\n# Get primitive cell\ntrans = PrimitiveCellTransformation()\nprimitive = trans.apply_transformation(struct)\n```\n\n**Reference:** See `references\u002Fcore_classes.md` for comprehensive documentation of Structure, Lattice, Molecule, and related classes.\n\n### 2. File Format Conversion\n\nConvert between 100+ file formats with automatic format detection.\n\n**Using convenience methods:**\n```python\n# Read any format\nstruct = Structure.from_file(\"input_file\")\n\n# Write to any format\nstruct.to(filename=\"output.cif\")\nstruct.to(filename=\"POSCAR\")\nstruct.to(filename=\"output.xyz\")\n```\n\n**Using the conversion script:**\n```bash\n# Single file conversion\npython scripts\u002Fstructure_converter.py POSCAR structure.cif\n\n# Batch conversion\npython scripts\u002Fstructure_converter.py *.cif --output-dir .\u002Fposcar_files --format poscar\n```\n\n**Reference:** See `references\u002Fio_formats.md` for detailed documentation of all supported formats and code integrations.\n\n### 3. Structure Analysis and Symmetry\n\nAnalyze structures for symmetry, coordination, and other properties.\n\n**Symmetry analysis:**\n```python\nfrom pymatgen.symmetry.analyzer import SpacegroupAnalyzer\n\nsga = SpacegroupAnalyzer(struct)\n\n# Get space group information\nprint(f\"Space group: {sga.get_space_group_symbol()}\")\nprint(f\"Number: {sga.get_space_group_number()}\")\nprint(f\"Crystal system: {sga.get_crystal_system()}\")\n\n# Get conventional\u002Fprimitive cells\nconventional = sga.get_conventional_standard_structure()\nprimitive = sga.get_primitive_standard_structure()\n```\n\n**Coordination environment:**\n```python\nfrom pymatgen.analysis.local_env import CrystalNN\n\ncnn = CrystalNN()\nneighbors = cnn.get_nn_info(struct, n=0)  # Neighbors of site 0\n\nprint(f\"Coordination number: {len(neighbors)}\")\nfor neighbor in neighbors:\n    site = struct[neighbor['site_index']]\n    print(f\"  {site.species_string} at {neighbor['weight']:.3f} Å\")\n```\n\n**Using the analysis script:**\n```bash\n# Comprehensive analysis\npython scripts\u002Fstructure_analyzer.py POSCAR --symmetry --neighbors\n\n# Export results\npython scripts\u002Fstructure_analyzer.py structure.cif --symmetry --export json\n```\n\n**Reference:** See `references\u002Fanalysis_modules.md` for detailed documentation of all analysis capabilities.\n\n### 4. Phase Diagrams and Thermodynamics\n\nConstruct phase diagrams and analyze thermodynamic stability.\n\n**Phase diagram construction:**\n```python\nfrom mp_api.client import MPRester\nfrom pymatgen.analysis.phase_diagram import PhaseDiagram, PDPlotter\n\n# Get entries from Materials Project\nwith MPRester() as mpr:\n    entries = mpr.get_entries_in_chemsys(\"Li-Fe-O\")\n\n# Build phase diagram\npd = PhaseDiagram(entries)\n\n# Check stability\nfrom pymatgen.core import Composition\ncomp = Composition(\"LiFeO2\")\n\n# Find entry for composition\nfor entry in entries:\n    if entry.composition.reduced_formula == comp.reduced_formula:\n        e_above_hull = pd.get_e_above_hull(entry)\n        print(f\"Energy above hull: {e_above_hull:.4f} eV\u002Fatom\")\n\n        if e_above_hull > 0.001:\n            # Get decomposition\n            decomp = pd.get_decomposition(comp)\n            print(\"Decomposes to:\", decomp)\n\n# Plot\nplotter = PDPlotter(pd)\nplotter.show()\n```\n\n**Using the phase diagram script:**\n```bash\n# Generate phase diagram\npython scripts\u002Fphase_diagram_generator.py Li-Fe-O --output li_fe_o.png\n\n# Analyze specific composition\npython scripts\u002Fphase_diagram_generator.py Li-Fe-O --analyze \"LiFeO2\" --show\n```\n\n**Reference:** See `references\u002Fanalysis_modules.md` (Phase Diagrams section) and `references\u002Ftransformations_workflows.md` (Workflow 2) for detailed examples.\n\n### 5. Electronic Structure Analysis\n\nAnalyze band structures, density of states, and electronic properties.\n\n**Band structure:**\n```python\nfrom pymatgen.io.vasp import Vasprun\nfrom pymatgen.electronic_structure.plotter import BSPlotter\n\n# Read from VASP calculation\nvasprun = Vasprun(\"vasprun.xml\")\nbs = vasprun.get_band_structure()\n\n# Analyze\nband_gap = bs.get_band_gap()\nprint(f\"Band gap: {band_gap['energy']:.3f} eV\")\nprint(f\"Direct: {band_gap['direct']}\")\nprint(f\"Is metal: {bs.is_metal()}\")\n\n# Plot\nplotter = BSPlotter(bs)\nplotter.save_plot(\"band_structure.png\")\n```\n\n**Density of states:**\n```python\nfrom pymatgen.electronic_structure.plotter import DosPlotter\n\ndos = vasprun.complete_dos\n\n# Get element-projected DOS\nelement_dos = dos.get_element_dos()\nfor element, element_dos_obj in element_dos.items():\n    print(f\"{element}: {element_dos_obj.get_gap():.3f} eV\")\n\n# Plot\nplotter = DosPlotter()\nplotter.add_dos(\"Total DOS\", dos)\nplotter.show()\n```\n\n**Reference:** See `references\u002Fanalysis_modules.md` (Electronic Structure section) and `references\u002Fio_formats.md` (VASP section).\n\n### 6. Surface and Interface Analysis\n\nGenerate slabs, analyze surfaces, and study interfaces.\n\n**Slab generation:**\n```python\nfrom pymatgen.core.surface import SlabGenerator\n\n# Generate slabs for specific Miller index\nslabgen = SlabGenerator(\n    struct,\n    miller_index=(1, 1, 1),\n    min_slab_size=10.0,      # Å\n    min_vacuum_size=10.0,    # Å\n    center_slab=True\n)\n\nslabs = slabgen.get_slabs()\n\n# Write slabs\nfor i, slab in enumerate(slabs):\n    slab.to(filename=f\"slab_{i}.cif\")\n```\n\n**Wulff shape construction:**\n```python\nfrom pymatgen.analysis.wulff import WulffShape\n\n# Define surface energies\nsurface_energies = {\n    (1, 0, 0): 1.0,\n    (1, 1, 0): 1.1,\n    (1, 1, 1): 0.9,\n}\n\nwulff = WulffShape(struct.lattice, surface_energies)\nprint(f\"Surface area: {wulff.surface_area:.2f} Ų\")\nprint(f\"Volume: {wulff.volume:.2f} ų\")\n\nwulff.show()\n```\n\n**Adsorption site finding:**\n```python\nfrom pymatgen.analysis.adsorption import AdsorbateSiteFinder\nfrom pymatgen.core import Molecule\n\nasf = AdsorbateSiteFinder(slab)\n\n# Find sites\nads_sites = asf.find_adsorption_sites()\nprint(f\"On-top sites: {len(ads_sites['ontop'])}\")\nprint(f\"Bridge sites: {len(ads_sites['bridge'])}\")\nprint(f\"Hollow sites: {len(ads_sites['hollow'])}\")\n\n# Add adsorbate\nadsorbate = Molecule(\"O\", [[0, 0, 0]])\nads_struct = asf.add_adsorbate(adsorbate, ads_sites[\"ontop\"][0])\n```\n\n**Reference:** See `references\u002Fanalysis_modules.md` (Surface and Interface section) and `references\u002Ftransformations_workflows.md` (Workflows 3 and 9).\n\n### 7. Materials Project Database Access\n\nProgrammatically access the Materials Project database.\n\n**Setup:**\n1. Get API key from https:\u002F\u002Fnext-gen.materialsproject.org\u002F\n2. Set environment variable: `export MP_API_KEY=\"your_key_here\"`\n\n**Search and retrieve:**\n```python\nfrom mp_api.client import MPRester\n\nwith MPRester() as mpr:\n    # Search by formula\n    materials = mpr.materials.summary.search(formula=\"Fe2O3\")\n\n    # Search by chemical system\n    materials = mpr.materials.summary.search(chemsys=\"Li-Fe-O\")\n\n    # Filter by properties\n    materials = mpr.materials.summary.search(\n        chemsys=\"Li-Fe-O\",\n        energy_above_hull=(0, 0.05),  # Stable\u002Fmetastable\n        band_gap=(1.0, 3.0)            # Semiconducting\n    )\n\n    # Get structure\n    struct = mpr.get_structure_by_material_id(\"mp-149\")\n\n    # Get band structure\n    bs = mpr.get_bandstructure_by_material_id(\"mp-149\")\n\n    # Get entries for phase diagram\n    entries = mpr.get_entries_in_chemsys(\"Li-Fe-O\")\n```\n\n**Reference:** See `references\u002Fmaterials_project_api.md` for comprehensive API documentation and examples.\n\n### 8. Computational Workflow Setup\n\nSet up calculations for various electronic structure codes.\n\n**VASP input generation:**\n```python\nfrom pymatgen.io.vasp.sets import MPRelaxSet, MPStaticSet, MPNonSCFSet\n\n# Relaxation\nrelax = MPRelaxSet(struct)\nrelax.write_input(\".\u002Frelax_calc\")\n\n# Static calculation\nstatic = MPStaticSet(struct)\nstatic.write_input(\".\u002Fstatic_calc\")\n\n# Band structure (non-self-consistent)\nnscf = MPNonSCFSet(struct, mode=\"line\")\nnscf.write_input(\".\u002Fbandstructure_calc\")\n\n# Custom parameters\ncustom = MPRelaxSet(struct, user_incar_settings={\"ENCUT\": 600})\ncustom.write_input(\".\u002Fcustom_calc\")\n```\n\n**Other codes:**\n```python\n# Gaussian\nfrom pymatgen.io.gaussian import GaussianInput\n\ngin = GaussianInput(\n    mol,\n    functional=\"B3LYP\",\n    basis_set=\"6-31G(d)\",\n    route_parameters={\"Opt\": None}\n)\ngin.write_file(\"input.gjf\")\n\n# Quantum ESPRESSO\nfrom pymatgen.io.pwscf import PWInput\n\npwin = PWInput(struct, control={\"calculation\": \"scf\"})\npwin.write_file(\"pw.in\")\n```\n\n**Reference:** See `references\u002Fio_formats.md` (Electronic Structure Code I\u002FO section) and `references\u002Ftransformations_workflows.md` for workflow examples.\n\n### 9. Advanced Analysis\n\n**Diffraction patterns:**\n```python\nfrom pymatgen.analysis.diffraction.xrd import XRDCalculator\n\nxrd = XRDCalculator()\npattern = xrd.get_pattern(struct)\n\n# Get peaks\nfor peak in pattern.hkls:\n    print(f\"2θ = {peak['2theta']:.2f}°, hkl = {peak['hkl']}\")\n\npattern.plot()\n```\n\n**Elastic properties:**\n```python\nfrom pymatgen.analysis.elasticity import ElasticTensor\n\n# From elastic tensor matrix\nelastic_tensor = ElasticTensor.from_voigt(matrix)\n\nprint(f\"Bulk modulus: {elastic_tensor.k_voigt:.1f} GPa\")\nprint(f\"Shear modulus: {elastic_tensor.g_voigt:.1f} GPa\")\nprint(f\"Young's modulus: {elastic_tensor.y_mod:.1f} GPa\")\n```\n\n**Magnetic ordering:**\n```python\nfrom pymatgen.transformations.advanced_transformations import MagOrderingTransformation\n\n# Enumerate magnetic orderings\ntrans = MagOrderingTransformation({\"Fe\": 5.0})\nmag_structs = trans.apply_transformation(struct, return_ranked_list=True)\n\n# Get lowest energy magnetic structure\nlowest_energy_struct = mag_structs[0]['structure']\n```\n\n**Reference:** See `references\u002Fanalysis_modules.md` for comprehensive analysis module documentation.\n\n## Bundled Resources\n\n### Scripts (`scripts\u002F`)\n\nExecutable Python scripts for common tasks:\n\n- **`structure_converter.py`**: Convert between structure file formats\n  - Supports batch conversion and automatic format detection\n  - Usage: `python scripts\u002Fstructure_converter.py POSCAR structure.cif`\n\n- **`structure_analyzer.py`**: Comprehensive structure analysis\n  - Symmetry, coordination, lattice parameters, distance matrix\n  - Usage: `python scripts\u002Fstructure_analyzer.py structure.cif --symmetry --neighbors`\n\n- **`phase_diagram_generator.py`**: Generate phase diagrams from Materials Project\n  - Stability analysis and thermodynamic properties\n  - Usage: `python scripts\u002Fphase_diagram_generator.py Li-Fe-O --analyze \"LiFeO2\"`\n\nAll scripts include detailed help: `python scripts\u002Fscript_name.py --help`\n\n### References (`references\u002F`)\n\nComprehensive documentation loaded into context as needed:\n\n- **`core_classes.md`**: Element, Structure, Lattice, Molecule, Composition classes\n- **`io_formats.md`**: File format support and code integration (VASP, Gaussian, etc.)\n- **`analysis_modules.md`**: Phase diagrams, surfaces, electronic structure, symmetry\n- **`materials_project_api.md`**: Complete Materials Project API guide\n- **`transformations_workflows.md`**: Transformations framework and common workflows\n\nLoad references when detailed information is needed about specific modules or workflows.\n\n## Common Workflows\n\n### High-Throughput Structure Generation\n\n```python\nfrom pymatgen.transformations.standard_transformations import SubstitutionTransformation\nfrom pymatgen.io.vasp.sets import MPRelaxSet\n\n# Generate doped structures\nbase_struct = Structure.from_file(\"POSCAR\")\ndopants = [\"Mn\", \"Co\", \"Ni\", \"Cu\"]\n\nfor dopant in dopants:\n    trans = SubstitutionTransformation({\"Fe\": dopant})\n    doped_struct = trans.apply_transformation(base_struct)\n\n    # Generate VASP inputs\n    vasp_input = MPRelaxSet(doped_struct)\n    vasp_input.write_input(f\".\u002Fcalcs\u002FFe_{dopant}\")\n```\n\n### Band Structure Calculation Workflow\n\n```python\n# 1. Relaxation\nrelax = MPRelaxSet(struct)\nrelax.write_input(\".\u002F1_relax\")\n\n# 2. Static (after relaxation)\nrelaxed = Structure.from_file(\"1_relax\u002FCONTCAR\")\nstatic = MPStaticSet(relaxed)\nstatic.write_input(\".\u002F2_static\")\n\n# 3. Band structure (non-self-consistent)\nnscf = MPNonSCFSet(relaxed, mode=\"line\")\nnscf.write_input(\".\u002F3_bandstructure\")\n\n# 4. Analysis\nfrom pymatgen.io.vasp import Vasprun\nvasprun = Vasprun(\"3_bandstructure\u002Fvasprun.xml\")\nbs = vasprun.get_band_structure()\nbs.get_band_gap()\n```\n\n### Surface Energy Calculation\n\n```python\n# 1. Get bulk energy\nbulk_vasprun = Vasprun(\"bulk\u002Fvasprun.xml\")\nbulk_E_per_atom = bulk_vasprun.final_energy \u002F len(bulk)\n\n# 2. Generate and calculate slabs\nslabgen = SlabGenerator(bulk, (1,1,1), 10, 15)\nslab = slabgen.get_slabs()[0]\n\nMPRelaxSet(slab).write_input(\".\u002Fslab_calc\")\n\n# 3. Calculate surface energy (after calculation)\nslab_vasprun = Vasprun(\"slab_calc\u002Fvasprun.xml\")\nE_surf = (slab_vasprun.final_energy - len(slab) * bulk_E_per_atom) \u002F (2 * slab.surface_area)\nE_surf *= 16.021766  # Convert eV\u002FŲ to J\u002Fm²\n```\n\n**More workflows:** See `references\u002Ftransformations_workflows.md` for 10 detailed workflow examples.\n\n## Best Practices\n\n### Structure Handling\n\n1. **Use automatic format detection**: `Structure.from_file()` handles most formats\n2. **Prefer immutable structures**: Use `IStructure` when structure shouldn't change\n3. **Check symmetry**: Use `SpacegroupAnalyzer` to reduce to primitive cell\n4. **Validate structures**: Check for overlapping atoms or unreasonable bond lengths\n\n### File I\u002FO\n\n1. **Use convenience methods**: `from_file()` and `to()` are preferred\n2. **Specify formats explicitly**: When automatic detection fails\n3. **Handle exceptions**: Wrap file I\u002FO in try-except blocks\n4. **Use serialization**: `as_dict()`\u002F`from_dict()` for version-safe storage\n\n### Materials Project API\n\n1. **Use context manager**: Always use `with MPRester() as mpr:`\n2. **Batch queries**: Request multiple items at once\n3. **Cache results**: Save frequently used data locally\n4. **Filter effectively**: Use property filters to reduce data transfer\n\n### Computational Workflows\n\n1. **Use input sets**: Prefer `MPRelaxSet`, `MPStaticSet` over manual INCAR\n2. **Check convergence**: Always verify calculations converged\n3. **Track transformations**: Use `TransformedStructure` for provenance\n4. **Organize calculations**: Use clear directory structures\n\n### Performance\n\n1. **Reduce symmetry**: Use primitive cells when possible\n2. **Limit neighbor searches**: Specify reasonable cutoff radii\n3. **Use appropriate methods**: Different analysis tools have different speed\u002Faccuracy tradeoffs\n4. **Parallelize when possible**: Many operations can be parallelized\n\n## Units and Conventions\n\nPymatgen uses atomic units throughout:\n- **Lengths**: Angstroms (Å)\n- **Energies**: Electronvolts (eV)\n- **Angles**: Degrees (°)\n- **Magnetic moments**: Bohr magnetons (μB)\n- **Time**: Femtoseconds (fs)\n\nConvert units using `pymatgen.core.units` when needed.\n\n## Integration with Other Tools\n\nPymatgen integrates seamlessly with:\n- **ASE** (Atomic Simulation Environment)\n- **Phonopy** (phonon calculations)\n- **BoltzTraP** (transport properties)\n- **Atomate\u002FFireworks** (workflow management)\n- **AiiDA** (provenance tracking)\n- **Zeo++** (pore analysis)\n- **OpenBabel** (molecule conversion)\n\n## Troubleshooting\n\n**Import errors**: Install missing dependencies\n```bash\nuv pip install pymatgen[analysis,vis]\n```\n\n**API key not found**: Set MP_API_KEY environment variable\n```bash\nexport MP_API_KEY=\"your_key_here\"\n```\n\n**Structure read failures**: Check file format and syntax\n```python\n# Try explicit format specification\nstruct = Structure.from_file(\"file.txt\", fmt=\"cif\")\n```\n\n**Symmetry analysis fails**: Structure may have numerical precision issues\n```python\n# Increase tolerance\nfrom pymatgen.symmetry.analyzer import SpacegroupAnalyzer\nsga = SpacegroupAnalyzer(struct, symprec=0.1)\n```\n\n## Additional Resources\n\n- **Documentation**: https:\u002F\u002Fpymatgen.org\u002F\n- **Materials Project**: https:\u002F\u002Fmaterialsproject.org\u002F\n- **GitHub**: https:\u002F\u002Fgithub.com\u002Fmaterialsproject\u002Fpymatgen\n- **Forum**: https:\u002F\u002Fmatsci.org\u002F\n- **Example notebooks**: https:\u002F\u002Fmatgenb.materialsvirtuallab.org\u002F\n\n## Version Notes\n\nThis skill is designed for pymatgen 2024.x and later. For the Materials Project API, use the `mp-api` package (separate from legacy `pymatgen.ext.matproj`).\n\nRequirements:\n- Python 3.10 or higher\n- pymatgen >= 2023.x\n- mp-api (for Materials Project access)\n","# Pymatgen - Python Materials Genomics\n\n## Overview\n\nPymatgen 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.\n\n## When to Use This Skill\n\nThis skill should be used when:\n- Working with crystal structures or molecular systems in materials science\n- Converting between structure file formats (CIF, POSCAR, XYZ, etc.)\n- Analyzing symmetry, space groups, or coordination environments\n- Computing phase diagrams or assessing thermodynamic stability\n- Analyzing electronic structure data (band gaps, DOS, band structures)\n- Generating surfaces, slabs, or studying interfaces\n- Accessing the Materials Project database programmatically\n- Setting up high-throughput computational workflows\n- Analyzing diffusion, magnetism, or mechanical properties\n- Working with VASP, Gaussian, Quantum ESPRESSO, or other computational codes\n\n## Quick Start Guide\n\n### Installation\n\n```bash\n# Core pymatgen\nuv pip install pymatgen\n\n# With Materials Project API access\nuv pip install pymatgen mp-api\n\n# Optional dependencies for extended functionality\nuv pip install pymatgen[analysis]  # Additional analysis tools\nuv pip install pymatgen[vis]       # Visualization tools\n```\n\n### Basic Structure Operations\n\n```python\nfrom pymatgen.core import Structure, Lattice\n\n# Read structure from file (automatic format detection)\nstruct = Structure.from_file(\"POSCAR\")\n\n# Create structure from scratch\nlattice = Lattice.cubic(3.84)\nstruct = Structure(lattice, [\"Si\", \"Si\"], [[0,0,0], [0.25,0.25,0.25]])\n\n# Write to different format\nstruct.to(filename=\"structure.cif\")\n\n# Basic properties\nprint(f\"Formula: {struct.composition.reduced_formula}\")\nprint(f\"Space group: {struct.get_space_group_info()}\")\nprint(f\"Density: {struct.density:.2f} g\u002Fcm³\")\n```\n\n### Materials Project Integration\n\n```bash\n# Set up API key\nexport MP_API_KEY=\"your_api_key_here\"\n```\n\n```python\nfrom mp_api.client import MPRester\n\nwith MPRester() as mpr:\n    # Get structure by material ID\n    struct = mpr.get_structure_by_material_id(\"mp-149\")\n\n    # Search for materials\n    materials = mpr.materials.summary.search(\n        formula=\"Fe2O3\",\n        energy_above_hull=(0, 0.05)\n    )\n```\n\n## Core Capabilities\n\n### 1. Structure Creation and Manipulation\n\nCreate structures using various methods and perform transformations.\n\n**From files:**\n```python\n# Automatic format detection\nstruct = Structure.from_file(\"structure.cif\")\nstruct = Structure.from_file(\"POSCAR\")\nmol = Molecule.from_file(\"molecule.xyz\")\n```\n\n**From scratch:**\n```python\nfrom pymatgen.core import Structure, Lattice\n\n# Using lattice parameters\nlattice = Lattice.from_parameters(a=3.84, b=3.84, c=3.84,\n                                  alpha=120, beta=90, gamma=60)\ncoords = [[0, 0, 0], [0.75, 0.5, 0.75]]\nstruct = Structure(lattice, [\"Si\", \"Si\"], coords)\n\n# From space group\nstruct = Structure.from_spacegroup(\n    \"Fm-3m\",\n    Lattice.cubic(3.5),\n    [\"Si\"],\n    [[0, 0, 0]]\n)\n```\n\n**Transformations:**\n```python\nfrom pymatgen.transformations.standard_transformations import (\n    SupercellTransformation,\n    SubstitutionTransformation,\n    PrimitiveCellTransformation\n)\n\n# Create supercell\ntrans = SupercellTransformation([[2,0,0],[0,2,0],[0,0,2]])\nsupercell = trans.apply_transformation(struct)\n\n# Substitute elements\ntrans = SubstitutionTransformation({\"Fe\": \"Mn\"})\nnew_struct = trans.apply_transformation(struct)\n\n# Get primitive cell\ntrans = PrimitiveCellTransformation()\nprimitive = trans.apply_transformation(struct)\n```\n\n**Reference:** See `references\u002Fcore_classes.md` for comprehensive documentation of Structure, Lattice, Molecule, and related classes.\n\n### 2. File Format Conversion\n\nConvert between 100+ file formats with automatic format detection.\n\n**Using convenience methods:**\n```python\n# Read any format\nstruct = Structure.from_file(\"input_file\")\n\n# Write to any format\nstruct.to(filename=\"output.cif\")\nstruct.to(filename=\"POSCAR\")\nstruct.to(filename=\"output.xyz\")\n```\n\n**Using the conversion script:**\n```bash\n# Single file conversion\npython scripts\u002Fstructure_converter.py POSCAR structure.cif\n\n# Batch conversion\npython scripts\u002Fstructure_converter.py *.cif --output-dir .\u002Fposcar_files --format poscar\n```\n\n**Reference:** See `references\u002Fio_formats.md` for detailed documentation of all supported formats and code integrations.\n\n### 3. Structure Analysis and Symmetry\n\nAnalyze structures for symmetry, coordination, and other properties.\n\n**Symmetry analysis:**\n```python\nfrom pymatgen.symmetry.analyzer import SpacegroupAnalyzer\n\nsga = SpacegroupAnalyzer(struct)\n\n# Get space group information\nprint(f\"Space group: {sga.get_space_group_symbol()}\")\nprint(f\"Number: {sga.get_space_group_number()}\")\nprint(f\"Crystal system: {sga.get_crystal_system()}\")\n\n# Get conventional\u002Fprimitive cells\nconventional = sga.get_conventional_standard_structure()\nprimitive = sga.get_primitive_standard_structure()\n```\n\n**Coordination environment:**\n```python\nfrom pymatgen.analysis.local_env import CrystalNN\n\ncnn = CrystalNN()\nneighbors = cnn.get_nn_info(struct, n=0)  # Neighbors of site 0\n\nprint(f\"Coordination number: {len(neighbors)}\")\nfor neighbor in neighbors:\n    site = struct[neighbor['site_index']]\n    print(f\"  {site.species_string} at {neighbor['weight']:.3f} Å\")\n```\n\n**Using the analysis script:**\n```bash\n# Comprehensive analysis\npython scripts\u002Fstructure_analyzer.py POSCAR --symmetry --neighbors\n\n# Export results\npython scripts\u002Fstructure_analyzer.py structure.cif --symmetry --export json\n```\n\n**Reference:** See `references\u002Fanalysis_modules.md` for detailed documentation of all analysis capabilities.\n\n### 4. Phase Diagrams and Thermodynamics\n\nConstruct phase diagrams and analyze thermodynamic stability.\n\n**Phase diagram construction:**\n```python\nfrom mp_api.client import MPRester\nfrom pymatgen.analysis.phase_diagram import PhaseDiagram, PDPlotter\n\n# Get entries from Materials Project\nwith MPRester() as mpr:\n    entries = mpr.get_entries_in_chemsys(\"Li-Fe-O\")\n\n# Build phase diagram\npd = PhaseDiagram(entries)\n\n# Check stability\nfrom pymatgen.core import Composition\ncomp = Composition(\"LiFeO2\")\n\n# Find entry for composition\nfor entry in entries:\n    if entry.composition.reduced_formula == comp.reduced_formula:\n        e_above_hull = pd.get_e_above_hull(entry)\n        print(f\"Energy above hull: {e_above_hull:.4f} eV\u002Fatom\")\n\n        if e_above_hull > 0.001:\n            # Get decomposition\n            decomp = pd.get_decomposition(comp)\n            print(\"Decomposes to:\", decomp)\n\n# Plot\nplotter = PDPlotter(pd)\nplotter.show()\n```\n\n**Using the phase diagram script:**\n```bash\n# Generate phase diagram\npython scripts\u002Fphase_diagram_generator.py Li-Fe-O --output li_fe_o.png\n\n# Analyze specific composition\npython scripts\u002Fphase_diagram_generator.py Li-Fe-O --analyze \"LiFeO2\" --show\n```\n\n**Reference:** See `references\u002Fanalysis_modules.md` (Phase Diagrams section) and `references\u002Ftransformations_workflows.md` (Workflow 2) for detailed examples.\n\n### 5. Electronic Structure Analysis\n\nAnalyze band structures, density of states, and electronic properties.\n\n**Band structure:**\n```python\nfrom pymatgen.io.vasp import Vasprun\nfrom pymatgen.electronic_structure.plotter import BSPlotter\n\n# Read from VASP calculation\nvasprun = Vasprun(\"vasprun.xml\")\nbs = vasprun.get_band_structure()\n\n# Analyze\nband_gap = bs.get_band_gap()\nprint(f\"Band gap: {band_gap['energy']:.3f} eV\")\nprint(f\"Direct: {band_gap['direct']}\")\nprint(f\"Is metal: {bs.is_metal()}\")\n\n# Plot\nplotter = BSPlotter(bs)\nplotter.save_plot(\"band_structure.png\")\n```\n\n**Density of states:**\n```python\nfrom pymatgen.electronic_structure.plotter import DosPlotter\n\ndos = vasprun.complete_dos\n\n# Get element-projected DOS\nelement_dos = dos.get_element_dos()\nfor element, element_dos_obj in element_dos.items():\n    print(f\"{element}: {element_dos_obj.get_gap():.3f} eV\")\n\n# Plot\nplotter = DosPlotter()\nplotter.add_dos(\"Total DOS\", dos)\nplotter.show()\n```\n\n**Reference:** See `references\u002Fanalysis_modules.md` (Electronic Structure section) and `references\u002Fio_formats.md` (VASP section).\n\n### 6. Surface and Interface Analysis\n\nGenerate slabs, analyze surfaces, and study interfaces.\n\n**Slab generation:**\n```python\nfrom pymatgen.core.surface import SlabGenerator\n\n# Generate slabs for specific Miller index\nslabgen = SlabGenerator(\n    struct,\n    miller_index=(1, 1, 1),\n    min_slab_size=10.0,      # Å\n    min_vacuum_size=10.0,    # Å\n    center_slab=True\n)\n\nslabs = slabgen.get_slabs()\n\n# Write slabs\nfor i, slab in enumerate(slabs):\n    slab.to(filename=f\"slab_{i}.cif\")\n```\n\n**Wulff shape construction:**\n```python\nfrom pymatgen.analysis.wulff import WulffShape\n\n# Define surface energies\nsurface_energies = {\n    (1, 0, 0): 1.0,\n    (1, 1, 0): 1.1,\n    (1, 1, 1): 0.9,\n}\n\nwulff = WulffShape(struct.lattice, surface_energies)\nprint(f\"Surface area: {wulff.surface_area:.2f} Ų\")\nprint(f\"Volume: {wulff.volume:.2f} ų\")\n\nwulff.show()\n```\n\n**Adsorption site finding:**\n```python\nfrom pymatgen.analysis.adsorption import AdsorbateSiteFinder\nfrom pymatgen.core import Molecule\n\nasf = AdsorbateSiteFinder(slab)\n\n# Find sites\nads_sites = asf.find_adsorption_sites()\nprint(f\"On-top sites: {len(ads_sites['ontop'])}\")\nprint(f\"Bridge sites: {len(ads_sites['bridge'])}\")\nprint(f\"Hollow sites: {len(ads_sites['hollow'])}\")\n\n# Add adsorbate\nadsorbate = Molecule(\"O\", [[0, 0, 0]])\nads_struct = asf.add_adsorbate(adsorbate, ads_sites[\"ontop\"][0])\n```\n\n**Reference:** See `references\u002Fanalysis_modules.md` (Surface and Interface section) and `references\u002Ftransformations_workflows.md` (Workflows 3 and 9).\n\n### 7. Materials Project Database Access\n\nProgrammatically access the Materials Project database.\n\n**Setup:**\n1. Get API key from https:\u002F\u002Fnext-gen.materialsproject.org\u002F\n2. Set environment variable: `export MP_API_KEY=\"your_key_here\"`\n\n**Search and retrieve:**\n```python\nfrom mp_api.client import MPRester\n\nwith MPRester() as mpr:\n    # Search by formula\n    materials = mpr.materials.summary.search(formula=\"Fe2O3\")\n\n    # Search by chemical system\n    materials = mpr.materials.summary.search(chemsys=\"Li-Fe-O\")\n\n    # Filter by properties\n    materials = mpr.materials.summary.search(\n        chemsys=\"Li-Fe-O\",\n        energy_above_hull=(0, 0.05),  # Stable\u002Fmetastable\n        band_gap=(1.0, 3.0)            # Semiconducting\n    )\n\n    # Get structure\n    struct = mpr.get_structure_by_material_id(\"mp-149\")\n\n    # Get band structure\n    bs = mpr.get_bandstructure_by_material_id(\"mp-149\")\n\n    # Get entries for phase diagram\n    entries = mpr.get_entries_in_chemsys(\"Li-Fe-O\")\n```\n\n**Reference:** See `references\u002Fmaterials_project_api.md` for comprehensive API documentation and examples.\n\n### 8. Computational Workflow Setup\n\nSet up calculations for various electronic structure codes.\n\n**VASP input generation:**\n```python\nfrom pymatgen.io.vasp.sets import MPRelaxSet, MPStaticSet, MPNonSCFSet\n\n# Relaxation\nrelax = MPRelaxSet(struct)\nrelax.write_input(\".\u002Frelax_calc\")\n\n# Static calculation\nstatic = MPStaticSet(struct)\nstatic.write_input(\".\u002Fstatic_calc\")\n\n# Band structure (non-self-consistent)\nnscf = MPNonSCFSet(struct, mode=\"line\")\nnscf.write_input(\".\u002Fbandstructure_calc\")\n\n# Custom parameters\ncustom = MPRelaxSet(struct, user_incar_settings={\"ENCUT\": 600})\ncustom.write_input(\".\u002Fcustom_calc\")\n```\n\n**Other codes:**\n```python\n# Gaussian\nfrom pymatgen.io.gaussian import GaussianInput\n\ngin = GaussianInput(\n    mol,\n    functional=\"B3LYP\",\n    basis_set=\"6-31G(d)\",\n    route_parameters={\"Opt\": None}\n)\ngin.write_file(\"input.gjf\")\n\n# Quantum ESPRESSO\nfrom pymatgen.io.pwscf import PWInput\n\npwin = PWInput(struct, control={\"calculation\": \"scf\"})\npwin.write_file(\"pw.in\")\n```\n\n**Reference:** See `references\u002Fio_formats.md` (Electronic Structure Code I\u002FO section) and `references\u002Ftransformations_workflows.md` for workflow examples.\n\n### 9. Advanced Analysis\n\n**Diffraction patterns:**\n```python\nfrom pymatgen.analysis.diffraction.xrd import XRDCalculator\n\nxrd = XRDCalculator()\npattern = xrd.get_pattern(struct)\n\n# Get peaks\nfor peak in pattern.hkls:\n    print(f\"2θ = {peak['2theta']:.2f}°, hkl = {peak['hkl']}\")\n\npattern.plot()\n```\n\n**Elastic properties:**\n```python\nfrom pymatgen.analysis.elasticity import ElasticTensor\n\n# From elastic tensor matrix\nelastic_tensor = ElasticTensor.from_voigt(matrix)\n\nprint(f\"Bulk modulus: {elastic_tensor.k_voigt:.1f} GPa\")\nprint(f\"Shear modulus: {elastic_tensor.g_voigt:.1f} GPa\")\nprint(f\"Young's modulus: {elastic_tensor.y_mod:.1f} GPa\")\n```\n\n**Magnetic ordering:**\n```python\nfrom pymatgen.transformations.advanced_transformations import MagOrderingTransformation\n\n# Enumerate magnetic orderings\ntrans = MagOrderingTransformation({\"Fe\": 5.0})\nmag_structs = trans.apply_transformation(struct, return_ranked_list=True)\n\n# Get lowest energy magnetic structure\nlowest_energy_struct = mag_structs[0]['structure']\n```\n\n**Reference:** See `references\u002Fanalysis_modules.md` for comprehensive analysis module documentation.\n\n## Bundled Resources\n\n### Scripts (`scripts\u002F`)\n\nExecutable Python scripts for common tasks:\n\n- **`structure_converter.py`**: Convert between structure file formats\n  - Supports batch conversion and automatic format detection\n  - Usage: `python scripts\u002Fstructure_converter.py POSCAR structure.cif`\n\n- **`structure_analyzer.py`**: Comprehensive structure analysis\n  - Symmetry, coordination, lattice parameters, distance matrix\n  - Usage: `python scripts\u002Fstructure_analyzer.py structure.cif --symmetry --neighbors`\n\n- **`phase_diagram_generator.py`**: Generate phase diagrams from Materials Project\n  - Stability analysis and thermodynamic properties\n  - Usage: `python scripts\u002Fphase_diagram_generator.py Li-Fe-O --analyze \"LiFeO2\"`\n\nAll scripts include detailed help: `python scripts\u002Fscript_name.py --help`\n\n### References (`references\u002F`)\n\nComprehensive documentation loaded into context as needed:\n\n- **`core_classes.md`**: Element, Structure, Lattice, Molecule, Composition classes\n- **`io_formats.md`**: File format support and code integration (VASP, Gaussian, etc.)\n- **`analysis_modules.md`**: Phase diagrams, surfaces, electronic structure, symmetry\n- **`materials_project_api.md`**: Complete Materials Project API guide\n- **`transformations_workflows.md`**: Transformations framework and common workflows\n\nLoad references when detailed information is needed about specific modules or workflows.\n\n## Common Workflows\n\n### High-Throughput Structure Generation\n\n```python\nfrom pymatgen.transformations.standard_transformations import SubstitutionTransformation\nfrom pymatgen.io.vasp.sets import MPRelaxSet\n\n# Generate doped structures\nbase_struct = Structure.from_file(\"POSCAR\")\ndopants = [\"Mn\", \"Co\", \"Ni\", \"Cu\"]\n\nfor dopant in dopants:\n    trans = SubstitutionTransformation({\"Fe\": dopant})\n    doped_struct = trans.apply_transformation(base_struct)\n\n    # Generate VASP inputs\n    vasp_input = MPRelaxSet(doped_struct)\n    vasp_input.write_input(f\".\u002Fcalcs\u002FFe_{dopant}\")\n```\n\n### Band Structure Calculation Workflow\n\n```python\n# 1. Relaxation\nrelax = MPRelaxSet(struct)\nrelax.write_input(\".\u002F1_relax\")\n\n# 2. Static (after relaxation)\nrelaxed = Structure.from_file(\"1_relax\u002FCONTCAR\")\nstatic = MPStaticSet(relaxed)\nstatic.write_input(\".\u002F2_static\")\n\n# 3. Band structure (non-self-consistent)\nnscf = MPNonSCFSet(relaxed, mode=\"line\")\nnscf.write_input(\".\u002F3_bandstructure\")\n\n# 4. Analysis\nfrom pymatgen.io.vasp import Vasprun\nvasprun = Vasprun(\"3_bandstructure\u002Fvasprun.xml\")\nbs = vasprun.get_band_structure()\nbs.get_band_gap()\n```\n\n### Surface Energy Calculation\n\n```python\n# 1. Get bulk energy\nbulk_vasprun = Vasprun(\"bulk\u002Fvasprun.xml\")\nbulk_E_per_atom = bulk_vasprun.final_energy \u002F len(bulk)\n\n# 2. Generate and calculate slabs\nslabgen = SlabGenerator(bulk, (1,1,1), 10, 15)\nslab = slabgen.get_slabs()[0]\n\nMPRelaxSet(slab).write_input(\".\u002Fslab_calc\")\n\n# 3. Calculate surface energy (after calculation)\nslab_vasprun = Vasprun(\"slab_calc\u002Fvasprun.xml\")\nE_surf = (slab_vasprun.final_energy - len(slab) * bulk_E_per_atom) \u002F (2 * slab.surface_area)\nE_surf *= 16.021766  # Convert eV\u002FŲ to J\u002Fm²\n```\n\n**More workflows:** See `references\u002Ftransformations_workflows.md` for 10 detailed workflow examples.\n\n## Best Practices\n\n### Structure Handling\n\n1. **Use automatic format detection**: `Structure.from_file()` handles most formats\n2. **Prefer immutable structures**: Use `IStructure` when structure shouldn't change\n3. **Check symmetry**: Use `SpacegroupAnalyzer` to reduce to primitive cell\n4. **Validate structures**: Check for overlapping atoms or unreasonable bond lengths\n\n### File I\u002FO\n\n1. **Use convenience methods**: `from_file()` and `to()` are preferred\n2. **Specify formats explicitly**: When automatic detection fails\n3. **Handle exceptions**: Wrap file I\u002FO in try-except blocks\n4. **Use serialization**: `as_dict()`\u002F`from_dict()` for version-safe storage\n\n### Materials Project API\n\n1. **Use context manager**: Always use `with MPRester() as mpr:`\n2. **Batch queries**: Request multiple items at once\n3. **Cache results**: Save frequently used data locally\n4. **Filter effectively**: Use property filters to reduce data transfer\n\n### Computational Workflows\n\n1. **Use input sets**: Prefer `MPRelaxSet`, `MPStaticSet` over manual INCAR\n2. **Check convergence**: Always verify calculations converged\n3. **Track transformations**: Use `TransformedStructure` for provenance\n4. **Organize calculations**: Use clear directory structures\n\n### Performance\n\n1. **Reduce symmetry**: Use primitive cells when possible\n2. **Limit neighbor searches**: Specify reasonable cutoff radii\n3. **Use appropriate methods**: Different analysis tools have different speed\u002Faccuracy tradeoffs\n4. **Parallelize when possible**: Many operations can be parallelized\n\n## Units and Conventions\n\nPymatgen uses atomic units throughout:\n- **Lengths**: Angstroms (Å)\n- **Energies**: Electronvolts (eV)\n- **Angles**: Degrees (°)\n- **Magnetic moments**: Bohr magnetons (μB)\n- **Time**: Femtoseconds (fs)\n\nConvert units using `pymatgen.core.units` when needed.\n\n## Integration with Other Tools\n\nPymatgen integrates seamlessly with:\n- **ASE** (Atomic Simulation Environment)\n- **Phonopy** (phonon calculations)\n- **BoltzTraP** (transport properties)\n- **Atomate\u002FFireworks** (workflow management)\n- **AiiDA** (provenance tracking)\n- **Zeo++** (pore analysis)\n- **OpenBabel** (molecule conversion)\n\n## Troubleshooting\n\n**Import errors**: Install missing dependencies\n```bash\nuv pip install pymatgen[analysis,vis]\n```\n\n**API key not found**: Set MP_API_KEY environment variable\n```bash\nexport MP_API_KEY=\"your_key_here\"\n```\n\n**Structure read failures**: Check file format and syntax\n```python\n# Try explicit format specification\nstruct = Structure.from_file(\"file.txt\", fmt=\"cif\")\n```\n\n**Symmetry analysis fails**: Structure may have numerical precision issues\n```python\n# Increase tolerance\nfrom pymatgen.symmetry.analyzer import SpacegroupAnalyzer\nsga = SpacegroupAnalyzer(struct, symprec=0.1)\n```\n\n## Additional Resources\n\n- **Documentation**: https:\u002F\u002Fpymatgen.org\u002F\n- **Materials Project**: https:\u002F\u002Fmaterialsproject.org\u002F\n- **GitHub**: https:\u002F\u002Fgithub.com\u002Fmaterialsproject\u002Fpymatgen\n- **Forum**: https:\u002F\u002Fmatsci.org\u002F\n- **Example notebooks**: https:\u002F\u002Fmatgenb.materialsvirtuallab.org\u002F\n\n## Version Notes\n\nThis skill is designed for pymatgen 2024.x and later. For the Materials Project API, use the `mp-api` package (separate from legacy `pymatgen.ext.matproj`).\n\nRequirements:\n- Python 3.10 or higher\n- pymatgen >= 2023.x\n- mp-api (for Materials Project access)\n",{"name":5,"description":7},"main","2b749c82b5d11fac39d9a6e021ce3f5b8a541bd1","cli-tool\u002Fcomponents\u002Fskills\u002Fscientific\u002Fpymatgen",3931,"https:\u002F\u002Fgithub.com\u002Fdavila7\u002Fclaude-code-templates","https:\u002F\u002Faitmpl.com","https:\u002F\u002Fgithub.com\u002Fdavila7","https:\u002F\u002Fdanielavila.me","Building AI dev tools with LLMs","2026-11-14 06:14:46",{"source":8,"skillName":5,"commands":59,"prompt":69,"zipAvailable":70},[60,63,66],{"tool":61,"command":62},"npx","npx skills add davila7\u002Fclaude-code-templates --skill pymatgen",{"tool":64,"command":65},"bunx","bunx skills add davila7\u002Fclaude-code-templates --skill pymatgen",{"tool":67,"command":68},"pnpm","pnpm dlx skills add davila7\u002Fclaude-code-templates --skill pymatgen","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002Fdavila7\u002Fclaude-code-templates\u002Fblob\u002Fmain\u002Fcli-tool\u002Fcomponents\u002Fskills\u002Fscientific\u002Fpymatgen\u002FSKILL.md",true,[72,78,82,86,90,94,100,104],{"path":73,"resourceType":74,"resourceTypeDesc":75,"sizeBytes":76,"sourceHtmlUrl":77},"references\u002Fanalysis_modules.md","REFERENCE","参考文档",12945,"https:\u002F\u002Fgithub.com\u002Fdavila7\u002Fclaude-code-templates\u002Fblob\u002Fmain\u002Fcli-tool\u002Fcomponents\u002Fskills\u002Fscientific\u002Fpymatgen\u002Freferences\u002Fanalysis_modules.md",{"path":79,"resourceType":74,"resourceTypeDesc":75,"sizeBytes":80,"sourceHtmlUrl":81},"references\u002Fcore_classes.md",9445,"https:\u002F\u002Fgithub.com\u002Fdavila7\u002Fclaude-code-templates\u002Fblob\u002Fmain\u002Fcli-tool\u002Fcomponents\u002Fskills\u002Fscientific\u002Fpymatgen\u002Freferences\u002Fcore_classes.md",{"path":83,"resourceType":74,"resourceTypeDesc":75,"sizeBytes":84,"sourceHtmlUrl":85},"references\u002Fio_formats.md",10518,"https:\u002F\u002Fgithub.com\u002Fdavila7\u002Fclaude-code-templates\u002Fblob\u002Fmain\u002Fcli-tool\u002Fcomponents\u002Fskills\u002Fscientific\u002Fpymatgen\u002Freferences\u002Fio_formats.md",{"path":87,"resourceType":74,"resourceTypeDesc":75,"sizeBytes":88,"sourceHtmlUrl":89},"references\u002Fmaterials_project_api.md",12770,"https:\u002F\u002Fgithub.com\u002Fdavila7\u002Fclaude-code-templates\u002Fblob\u002Fmain\u002Fcli-tool\u002Fcomponents\u002Fskills\u002Fscientific\u002Fpymatgen\u002Freferences\u002Fmaterials_project_api.md",{"path":91,"resourceType":74,"resourceTypeDesc":75,"sizeBytes":92,"sourceHtmlUrl":93},"references\u002Ftransformations_workflows.md",16805,"https:\u002F\u002Fgithub.com\u002Fdavila7\u002Fclaude-code-templates\u002Fblob\u002Fmain\u002Fcli-tool\u002Fcomponents\u002Fskills\u002Fscientific\u002Fpymatgen\u002Freferences\u002Ftransformations_workflows.md",{"path":95,"resourceType":96,"resourceTypeDesc":97,"sizeBytes":98,"sourceHtmlUrl":99},"scripts\u002Fphase_diagram_generator.py","SCRIPT","脚本",7353,"https:\u002F\u002Fgithub.com\u002Fdavila7\u002Fclaude-code-templates\u002Fblob\u002Fmain\u002Fcli-tool\u002Fcomponents\u002Fskills\u002Fscientific\u002Fpymatgen\u002Fscripts\u002Fphase_diagram_generator.py",{"path":101,"resourceType":96,"resourceTypeDesc":97,"sizeBytes":102,"sourceHtmlUrl":103},"scripts\u002Fstructure_analyzer.py",8452,"https:\u002F\u002Fgithub.com\u002Fdavila7\u002Fclaude-code-templates\u002Fblob\u002Fmain\u002Fcli-tool\u002Fcomponents\u002Fskills\u002Fscientific\u002Fpymatgen\u002Fscripts\u002Fstructure_analyzer.py",{"path":105,"resourceType":96,"resourceTypeDesc":97,"sizeBytes":106,"sourceHtmlUrl":107},"scripts\u002Fstructure_converter.py",5179,"https:\u002F\u002Fgithub.com\u002Fdavila7\u002Fclaude-code-templates\u002Fblob\u002Fmain\u002Fcli-tool\u002Fcomponents\u002Fskills\u002Fscientific\u002Fpymatgen\u002Fscripts\u002Fstructure_converter.py",[109,136,162,193,228,251],{"skillNo":110,"name":111,"nameZh":6,"description":112,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":113,"categories":114,"keywords":116,"publishedAt":43},"01M70NHBTQ8BV0A2SCAZXEPHCX","wealthville-pool-scoring","Score DeFi liquidity pools before providing liquidity. Returns a 0-100 pool score and an Enter\u002FHold\u002FExit\u002FReduce\u002FAvoid verdict with calibrated confidence for ~68,800 Solana pools and 575 EVM pools, plus a public miss-inclusive track record. Use when asked whether a pool is worth LPing into, which pools look best right now, or how accurate the scores have actually been.","https:\u002F\u002Fgithub.com\u002Fdavila7\u002Fclaude-code-templates\u002Fblob\u002Fmain\u002Fcli-tool\u002Fcomponents\u002Fskills\u002Fweb-data\u002Fwealthville-pool-scoring\u002FSKILL.md",[115],{"categoryNo":24,"categoryName":25,"taxonomyType":21,"taxonomyTypeDesc":22},[117,118,119,120,121,31,122,123,124,125,126,127,128,129,130,131,132,133,134,135],"scoring","pool","wealthville pool scoring","liquidity","which","exit","now","use","when","reduce","with","record","track","verdict","evm","solana","how","public","look",{"skillNo":137,"name":138,"nameZh":6,"description":139,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":140,"categories":141,"keywords":143,"publishedAt":43},"01M70MB6VR8ERJ4EM8D5KHBMEV","technical-debt-auditor","Scans a codebase and produces a quantified technical debt report with a prioritized remediation plan. Analyzes dead code, TODO\u002FFIXME\u002FHACK markers, dependency staleness, complexity hotspots, code duplication signals, test coverage gaps, unused exports, and outdated patterns. Use this skill when the user asks to audit their codebase for tech debt, wants a health check of their code quality, says things like \"where should I focus refactoring\", \"find code smells\", \"audit my codebase\", \"what technical debt do we have\", \"prioritize cleanup work\", or asks about code quality metrics. Also trigger when the user mentions \"code rot\", \"legacy cleanup\", \"refactoring priorities\", or wants to understand the overall health of a project before a major effort. Trigger even if the user doesn't say \"technical debt\" explicitly — any request to systematically assess code quality and identify improvement priorities belongs here.","https:\u002F\u002Fgithub.com\u002Fdavila7\u002Fclaude-code-templates\u002Fblob\u002Fmain\u002Fcli-tool\u002Fcomponents\u002Fskills\u002Fdevelopment\u002Ftechnical-debt-auditor\u002FSKILL.md",[142],{"categoryNo":24,"categoryName":25,"taxonomyType":21,"taxonomyTypeDesc":22},[144,145,146,147,148,149,150,151,27,152,153,125,154,155,156,157,158,159,160,161],"technical debt","debt","technical","technical debt auditor","auditor","coverage","complexity","markers","cleanup","unused","code","todo","work","plan","focus","signals","audit","dependency",{"skillNo":163,"name":164,"nameZh":6,"description":165,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":166,"categories":167,"keywords":175,"publishedAt":43},"01M70KPYH9QNHCNME5GJQGE22K","readonly-sql-guard","Make an agent's database access provably read-only. Use when an agent runs caller-supplied SQL against a production\u002FERP\u002Fanalytics database (a \"query\" MCP tool, text-to-SQL, an admin console), or when reviewing DB-access code for write\u002FDDL\u002Fside-effect\u002Ftransaction-escape risks. Checks what a statement CALLS, not just its shape.","https:\u002F\u002Fgithub.com\u002Fdavila7\u002Fclaude-code-templates\u002Fblob\u002Fmain\u002Fcli-tool\u002Fcomponents\u002Fskills\u002Fdatabase\u002Freadonly-sql-guard\u002FSKILL.md",[168,169,170],{"categoryNo":19,"categoryName":20,"taxonomyType":21,"taxonomyTypeDesc":22},{"categoryNo":24,"categoryName":25,"taxonomyType":21,"taxonomyTypeDesc":22},{"categoryNo":171,"categoryName":172,"taxonomyType":173,"taxonomyTypeDesc":174},"01JBSEEDCAT000000000000033","数据分析师","PROFESSION","适用职业",[176,177,178,179,180,181,182,31,183,184,185,186,187,188,189,124,190,191,125,192],"readonly","guard","sql guard","sql","readonly sql guard","erp","effect","read-only","db","just","tool","calls","only","MCP","access","database","query",{"skillNo":194,"name":195,"nameZh":6,"description":196,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":197,"licenseFileUrl":198,"sourceHtmlUrl":199,"categories":200,"keywords":204,"publishedAt":43},"01M6AFY6F7CC2BBZP1QD6VTNVC","web-artifacts-builder","Suite of tools for creating elaborate, multi-component claude.ai HTML artifacts using modern frontend web technologies (React, Tailwind CSS, shadcn\u002Fui). Use for complex artifacts requiring state management, routing, or shadcn\u002Fui components - not for simple single-file HTML\u002FJSX artifacts.","Apache-2.0","https:\u002F\u002Fgithub.com\u002Fdavila7\u002Fclaude-code-templates\u002Fblob\u002Fmain\u002Fcli-tool\u002Fcomponents\u002Fskills\u002Futilities\u002Fweb-artifacts-builder\u002FLICENSE.txt","https:\u002F\u002Fgithub.com\u002Fdavila7\u002Fclaude-code-templates\u002Fblob\u002Fmain\u002Fcli-tool\u002Fcomponents\u002Fskills\u002Futilities\u002Fweb-artifacts-builder\u002FSKILL.md",[201],{"categoryNo":202,"categoryName":203,"taxonomyType":21,"taxonomyTypeDesc":22},"01JBSEEDCAT000000000000009","前端开发",[205,206,207,208,209,210,211,212,213,214,215,216,217,218,219,220,221,222,223,224,225,226,31,227],"artifacts builder","web","web artifacts builder","artifacts","builder","state","routing","state management","component","css","frontend","ui","Tools","file","components","shadcn","react","Tailwind","suite","jsx","html","single-file","ui components",{"skillNo":229,"name":230,"nameZh":6,"description":231,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":197,"licenseFileUrl":232,"sourceHtmlUrl":233,"categories":234,"keywords":239,"publishedAt":43},"01M6AFWF33SFV9Z3SF4PEEE4BF","webapp-testing","Toolkit for interacting with and testing local web applications using Playwright. Supports verifying frontend functionality, debugging UI behavior, capturing browser screenshots, and viewing browser logs.","https:\u002F\u002Fgithub.com\u002Fdavila7\u002Fclaude-code-templates\u002Fblob\u002Fmain\u002Fcli-tool\u002Fcomponents\u002Fskills\u002Fsecurity\u002Fwebapp-testing\u002FLICENSE.txt","https:\u002F\u002Fgithub.com\u002Fdavila7\u002Fclaude-code-templates\u002Fblob\u002Fmain\u002Fcli-tool\u002Fcomponents\u002Fskills\u002Fsecurity\u002Fwebapp-testing\u002FSKILL.md",[235,238],{"categoryNo":236,"categoryName":237,"taxonomyType":21,"taxonomyTypeDesc":22},"01JBSEEDCAT000000000000008","测试与质量",{"categoryNo":202,"categoryName":203,"taxonomyType":21,"taxonomyTypeDesc":22},[240,241,242,243,244,206,245,215,216,246,36,247,248,31,249,127,250],"webapp testing","testing","webapp","browser","playwright","applications","debugging","logs","screenshots","local","behavior",{"skillNo":252,"name":253,"nameZh":6,"description":254,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":197,"licenseFileUrl":255,"sourceHtmlUrl":256,"categories":257,"keywords":265,"publishedAt":43},"01M6AF67Q67JJJ5V51JR2P52KA","discernment-nudge","After you give a substantive answer or draft that the user may act on — advice or recommendations, drafted artifacts such as goals, plans, pitches, proposals, or emails, estimates or projections, analysis or interpretation of data, factual claims they may rely on, or a multi-step argument — invoke this skill BEFORE finalizing your reply and then, if it applies, append 2-3 short follow-up questions, each tied to something specific in what you just produced, that help the user check key facts, probe the reasoning or assumptions, and notice missing context. Do this at most once per conversation. Skip it when the user asked a trivial how-to or simple lookup, wants a purely educational explanation, asked you only to format, convert, or assemble a file from content they provided, is writing code they will run, is doing creative writing or casual chat, or already asked you to double-check, cite, or review — the skill file explains these boundaries and the exact output format.","https:\u002F\u002Fgithub.com\u002Fdavila7\u002Fclaude-code-templates\u002Fblob\u002Fmain\u002Fcli-tool\u002Fcomponents\u002Fskills\u002Fproductivity\u002Fdiscernment-nudge\u002FLICENSE.txt","https:\u002F\u002Fgithub.com\u002Fdavila7\u002Fclaude-code-templates\u002Fblob\u002Fmain\u002Fcli-tool\u002Fcomponents\u002Fskills\u002Fproductivity\u002Fdiscernment-nudge\u002FSKILL.md",[258,261,262],{"categoryNo":259,"categoryName":260,"taxonomyType":21,"taxonomyTypeDesc":22},"01JBSEEDCAT000000000000018","写作与文案",{"categoryNo":24,"categoryName":25,"taxonomyType":21,"taxonomyTypeDesc":22},{"categoryNo":263,"categoryName":264,"taxonomyType":173,"taxonomyTypeDesc":174},"01JBSEEDCAT000000000000036","内容创作者",[266,267,268,269,270,271,272,273,208,274,218,154,275,276,277,278,279,188,280,125,281,282,283,284,285,133,286],"discernment nudge","nudge","interpretation","help","run","reasoning","data","writing","lookup","content","review","conversation","short","up","invoke","you","analysis","claims","argument","assemble","recommendations"]