pymatgen

Materials science toolkit. Crystal structures (CIF, POSCAR), phase diagrams, band structure, DOS, Materials Project integration, format conversion, for computational materials science.

Install

Hot:5

Download and extract to your skills directory

Copy command and send to AI Agent for auto-install:

Download and install this skill https://openskills.cc/api/download?slug=k-dense-ai-skills-pymatgen&locale=en&source=copy

Pymatgen - The Python flagship tool for materials science data analysis

Skills overview

Pymatgen (Python Materials Genomics) is a powerful Python library for materials science. It provides core support for the Materials Project and can analyze, transform, and visualize a wide range of materials data, including crystal structures, molecules, electronic structures, and phase diagrams. It supports 100+ types of computational software file formats.

Use cases

  • First-principles calculation post-processing: When you need to process computation outputs from software such as VASP, Quantum ESPRESSO, and Gaussian, pymatgen can quickly extract key physical properties like band structures, density of states, and elastic constants, and generate publication-ready plots for papers.
  • Materials data mining and screening: By using the Materials Project API to access a computed database of over 150,000 materials, you can batch-filter materials based on criteria such as band gap, formation energy, and stability, accelerating the discovery of new materials.
  • Building high-throughput computation workflows: When you need to perform large-scale materials calculations (e.g., doped-system screening, surface energy calculations), pymatgen provides automation tools such as structure conversion, symmetry analysis, and input file generation—greatly improving efficiency.
  • Core features

  • Intelligent structure conversion and manipulation: Automatically identifies and converts crystal structure file formats such as CIF, POSCAR, XYZ, and 100+ others. It supports tasks like supercell construction, element substitution, symmetry analysis, and primitive-cell reduction. With a single line of code, you can perform complex structure transformations.
  • Electronic structure and thermodynamic analysis: Includes tools for visualizing band structures and density of states. It can compute key parameters such as band gaps and Fermi levels. It also supports building phase diagrams and evaluating thermodynamic stability—helping you determine whether a material will decompose and what decomposition products it will form, along with the corresponding energies.
  • Materials Project database integration: Offers a unified API to access materials databases. It supports multidimensional search by chemical formula, element system, property ranges, and more, letting you directly retrieve data such as structures, band structures, and phase diagrams without repeating calculations.
  • FAQ

    What is pymatgen? Who is it for?

    Pymatgen is an open-source Python library for materials science, mainly used to process and analyze materials data such as crystal structures, electronic structures, and phase diagrams. It is especially suitable for graduate students, postdocs, and researchers working in computational materials science, condensed matter physics, and materials informatics. If you frequently handle VASP results, need to query the Materials Project database, or want to perform high-throughput materials screening, pymatgen will significantly improve your workflow efficiency.

    How do I install and configure pymatgen?

    You can install the core library with pip install pymatgen or uv pip install pymatgen. If you want to access the Materials Project database, you also need to install the mp-api package and configure an API key (register at https://next-gen.materialsproject.org/ ). After setting the environment variable export MP_API_KEY="your_key", you can use MPRester in your code to query the database. For advanced analysis features (such as band plotting), it is recommended to install the pymatgen[vis] extension package.

    What file formats does pymatgen support? How do I convert files?

    Pymatgen supports 100+ file formats from computational software, including:

  • Structure files: CIF, POSCAR/CONTCAR, XYZ, CSSR, pdb, etc.

  • Computation outputs: VASP OUTCAR, vasprun.xml, CHGCAR; Gaussian log files; Quantum ESPRESSO outputs, etc.

  • Data formats: JSON and yaml for data storage
  • Conversion is straightforward:

    # Automatically detect and read formats
    struct = Structure.from_file("input.cif")
    # Save to another format
    struct.to("POSCAR")  # Convert to VASP format

    It also provides command-line scripts for batch conversion:
    python scripts/structure_converter.py *.cif --output-dir ./poscar_files --format poscar