pymatgen (Python Materials Genomics)

repository·main·Indexed 24 days ago

https://github.com/materialsproject/pymatgen

A robust, open-source Python library for materials analysis that defines core object representations for structures and molecules. It provides extensive I/O support for electronic structure codes (VASP, ABINIT, CIF, Gaussian, XYZ), analysis tools for phase and Pourbaix diagrams, and electronic structure analysis for density of states and band structures. It serves as the core analysis code powering the Materials Project and offers a lightweight version, pymatgen-core, for fundamental data objects.

Tokens
56.7K
Snippets
14
Records
414
Agent score
84%

What's inside pymatgen

  1. Overview of pymatgen features

    main

    Pymatgen (Python Materials Genomics) is a robust, open-source Python library for materials analysis. Key capabilities include:

    • Core Representations: Highly flexible classes for Element, Site, Molecule, and Structure objects.
    • I/O Support: Extensive support for formats like VASP, ABINIT, CIF, Gaussian, XYZ, and more.
    • Analysis Tools: Generation of phase diagrams, Pourbaix diagrams, diffusion analyses, and reactions.
    • Electronic Structure: Analysis of density of states (DOS) and band structures.
    • Data Integration: Integration with the Materials Project REST API, Crystallography Open Database, and other external sources.
  2. Analyze Density of States (DOS) with Dos and FermiDos

    main

    The pymatgen.electronic_structure.dos module provides tools for handling Density of States data.

    • Dos: Use this class to perform operations on DOS data, such as get_interpolated_gap() to find the band gap, get_interpolated_value() for specific energy points, or get_smeared_densities() for smeared DOS calculations.
    • FermiDos: Specifically handles DOS relative to the Fermi level. Key methods include get_fermi() to retrieve the Fermi energy, get_doping() to calculate doping levels, and get_fermi_interextrapolated() for interpolation.
    • LobsterCompleteDos: Provides specialized DOS analysis for LOBSTER outputs, including orbital-resolved DOS via get_element_spd_dos(), get_site_orbital_dos(), and get_site_t2g_eg_resolved_dos().
  3. Manage Abinit input objects via pymatgen.io.abinit

    main

    The pymatgen.io.abinit.abiobjects module provides several classes to represent Abinit input parameters as Python objects. Most of these objects support as_dict() and from_dict() for serialization, and to_abivars() to convert them into Abinit variable format.

    Key abstraction classes include:

    • Electrons: Manages electron-related settings like nspden (number of spin degenerate electrons) and nspinor (number of spinors).
    • KSampling: Handles k-point sampling, including monkhorst_automatic() for Monkhorst-Pack grids and explicit_path() for band structure paths.
    • PPModel: Manages Pseudopotential models, supporting modes like farid, godby, hybersten, linden, and noppmodel via PPModelModes.
    • RelaxationMethod: Defines how atoms and cells are relaxed, with options like atoms_and_cell() or atoms_only().
  4. Analyze piezoelectric sensitivity with ForceConstantMatrix and BornEffectiveCharge

    main

    The pymatgen.analysis.piezo_sensitivity module provides tools to evaluate how sensitive piezoelectric properties are to atomic displacements or strain.

    Key classes:

    • BornEffectiveCharge: Used to calculate Born Effective Charges (BEC).
    • ForceConstantMatrix: Used to manage and manipulate force constant matrices (FCM), including methods for symmetrization (get_symmetrized_FCM) and stability checks (get_stable_FCM).
    • InternalStrainTensor: Used for analyzing internal strain effects.
    • get_piezo(): A functional entry point to calculate piezoelectricity.
  5. Analyze phonon properties with pymatgen.io.phonopy

    main

    The pymatgen.io.phonopy module provides several utilities for analyzing phonon data, typically derived from Phonopy outputs. Key capabilities include:

    • Density of States (DOS): Use get_ph_dos() or get_complete_ph_dos() to obtain phonon DOS.
    • Band Structure: Use get_phonon_band_structure_from_fc() or get_phonon_band_structure_symm_line_from_fc() to calculate band structures from force constants.
    • Displaced Structures: Use get_displaced_structures() to retrieve structures used in phonon calculations.
    • Grüneisen Parameters: Use get_gruneisenparameter() to calculate thermal expansion related properties.
    • Structure Conversion: Convert between Phonopy and pymatgen structures using get_phonopy_structure() or get_pmg_structure().
  6. Use specialized VASP input sets for specific workflows

    main

    Pymatgen provides several specialized VaspInputSet subclasses to automate complex VASP workflows. These sets pre-configure incar and kpoints for specific physics tasks.

    Common specialized sets include:

    • MPRelaxSet: For standard Materials Project relaxation workflows.
    • MPStaticSet: For static (non-relaxing) calculations.
    • MPSOCSet: For calculations including Spin-Orbit Coupling.
    • MPHSEBSSet: For HSE hybrid functional band structure calculations.
    • MITNEBSet: For Nudged Elastic Band (NEB) calculations.
    • LobsterSet: For LOBSTER (Local Orbital Basis Suite Toward Electronic Structure Reconstruction) analysis.
    • MVLGWSet: For GW calculations.
    • MPNonSCFSet: For non-self-consistent field calculations.

    Most of these sets support from_prev_calc() to inherit parameters from a previous VASP run and override_from_prev_calc() to modify them.

  7. Manage LAMMPS input files and runs

    main

    The pymatgen.io.lammps.inputs module allows for programmatic construction and manipulation of LAMMPS input scripts.

    • LammpsInputFile: A class to build and edit LAMMPS input files. You can add commands (add_commands()), add simulation stages (add_stage()), and manage the script structure (e.g., remove_stage(), rename_stage()). It can be loaded from a file or string and written back to a file.
    • LammpsRun: Manages the execution context of a LAMMPS run, including writing inputs via write_inputs().
    • LammpsTemplateGen: A utility for generating input sets based on templates.
  8. Inspect Abinit pseudopotentials with AbinitPseudo and PawAbinitPseudo

    main

    Pymatgen provides several classes to handle and inspect Abinit pseudopotentials, distinguishing between standard and PAW (Projector Augmented Wave) types:

    Standard Pseudopotentials (AbinitPseudo)

    Used for general pseudopotential information. Key attributes include:

    • Z: Atomic number.
    • Z_val: Atomic number value.
    • l_max: Maximum angular momentum.
    • l_local: Local angular momentum.
    • summary(): Returns a summary of the pseudopotential.

    PAW Pseudopotentials (PawAbinitPseudo)

    Specifically for PAW-style pseudopotentials. Key attributes include:

    • paw_radius: The PAW radius.
    • supports_soc: Boolean indicating if Spin-Orbit Coupling is supported.

    PAW XML Setup (PawXmlSetup)

    For detailed inspection of PAW XML files, providing methods to:

    • plot_densities(): Plot core/valence densities.
    • plot_projectors(): Plot projector functions.
    • plot_waves(): Plot partial waves.
    • pseudo_core_density(): Access the pseudo-core density.
  9. Use pymatgen.alchemy for structure transformations and filtering

    main

    The pymatgen.alchemy package provides tools for generating new crystal structures through transformations (e.g., substituting elements) and filtering the resulting structures based on specific criteria.

    Key components include:

    • Filters: Classes like ChargeBalanceFilter, ContainsSpecieFilter, and SpecieProximityFilter used to validate or discard generated structures.
    • TransformedStructure: A container that tracks a sequence of transformations and filters applied to an initial structure.
    • Transmuters: High-level objects like StandardTransmuter that automate the process of applying transformations to a set of input structures and writing the results (e.g., to VASP input files).
  10. Use standard structure transformations in pymatgen

    main

    The pymatgen.transformations.standard_transformations module contains high-level transformations for common crystallographic and chemical tasks. Key transformations include:

    • Cell Transformations: ConventionalCellTransformation (to get the conventional cell), PrimitiveCellTransformation (to get the primitive cell), and ChargedCellTransformation (to adjust the cell for charge).
    • Chemical/Oxidation State Transformations: OxidationStateDecorationTransformation and AutoOxiStateDecorationTransformation to add oxidation states to sites, and OxidationStateRemovalTransformation to remove them.
    • Structure Modification: DeformStructureTransformation to perturb atomic positions, PerturbStructureTransformation for small displacements, and RemoveSpeciesTransformation or PartialRemoveSpecieTransformation to remove elements.
    • Ordering/Disorder: OrderDisorderedStructureTransformation to convert a disordered structure (with occupancies) into a specific ordered configuration. It supports several algorithms:
      • ALGO_BEST_FIRST
      • ALGO_COMPLETE
      • ALGO_FAST
    • Occupancy Management: DiscretizeOccupanciesTransformation to convert fractional occupancies into discrete site occupancies.
  11. Manage CP2K input sections with Section and SectionList

    main

    The pymatgen.io.cp2k.inputs module provides classes to programmatically construct CP2K input files.

    • Section: Represents a single block in a CP2K input file. You can manipulate its content using methods like set(), setitem(), update(), insert(), and unset(). It also supports inc() for incrementing values and silence() to suppress certain outputs.
    • SectionList: A collection of Section objects that can be managed using append(), extend(), and get().