Phonopy
Phonopy is an open-source Python package designed for calculating phonon properties at harmonic and quasi-harmonic levels. It integrates with various first-principles density functional theory (DFT) codes, such as VASP, Quantum ESPRESSO, and ABINIT, to compute interatomic forces. Using the finite displacement method and crystal symmetry, Phonopy can derive phonon band structures, densities of states (DOS), thermal properties (free energy, heat capacity, entropy), group velocities, and more. The library is actively maintained and regularly updated, with version 3.5.0 being the current release.
Warnings
- breaking As of Version 3.2.0 (March 2026), several parameters in the `Phonopy.__init__()` method were removed: `frequency_scale_factor`, `dynamical_matrix_decimals`, `force_constants_decimals`, `store_dense_svecs`, and `set_factor_by_calculator`. Code using these parameters will break.
- deprecated The `FREQUENCY_CONVERSION_FACTOR` tag (and `--factor` option) is deprecated since Version 2.44.0 (October 2025). Using the `factor` parameter in `Phonopy.__init__()` will now emit a warning. Similarly, `phonopy.interface.calculator.get_default_physical_units` and physical units in `phonopy.units` are deprecated (v2.38.2, April 2025).
- breaking From Version 2.30.0 (November 2024), the `symfc` package became a *necessary* dependency for Phonopy. Additionally, `symfc` is now the *default* force constants calculator for the `phonopy-load` command.
- gotcha Incorrect `PATH` and `PYTHONPATH` environment variables can lead to issues with `phonopy` execution or import, especially with multiple installations or `conda` environments. This is a common source of 'command not found' or 'module not found' errors.
- gotcha The error 'Remapping of atoms by TrimmedCell failed' often occurs when `phonopy` struggles to determine the primitive cell. This is particularly common when defining primitive axes manually or with certain complex structures.
- gotcha Imaginary (negative) phonon frequencies in results, especially when using the DFPT method, can indicate insufficient k-point sampling in the underlying DFT calculation. High accuracy in forces is critical for stable phonon dispersions.
Install
-
pip install phonopy -
conda install -c conda-forge phonopy
Imports
- Phonopy
from phonopy import Phonopy
- PhonopyAtoms
from phonopy.structure.atoms import PhonopyAtoms
Quickstart
import numpy as np
from phonopy import Phonopy
from phonopy.structure.atoms import PhonopyAtoms
# Define a simple unit cell (e.g., Silicon diamond structure)
a = 5.404 # Lattice constant in Angstrom
unitcell = PhonopyAtoms(
symbols=['Si'] * 8,
cell=np.diag([a, a, a]),
scaled_positions=[
[0, 0, 0], [0, 0.5, 0.5], [0.5, 0, 0.5], [0.5, 0.5, 0],
[0.25, 0.25, 0.25], [0.25, 0.75, 0.75], [0.75, 0.25, 0.75], [0.75, 0.75, 0.25]
]
)
# Define the supercell matrix (e.g., 2x2x2 supercell)
supercell_matrix = [[2, 0, 0], [0, 2, 0], [0, 0, 2]]
# Initialize Phonopy object
# The primitive matrix is often set based on the crystal structure, e.g., for FCC/diamond-like cells
# For Si, the primitive cell is usually R-centered hexagonal or face-centered orthorhombic.
# A common choice for diamond is: [[0, 0.5, 0.5], [0.5, 0, 0.5], [0.5, 0.5, 0]]
primitive_matrix = [[0, 0.5, 0.5], [0.5, 0, 0.5], [0.5, 0.5, 0]]
phonon = Phonopy(
unitcell,
supercell_matrix=supercell_matrix,
primitive_matrix=primitive_matrix
)
# Generate displacements for force calculations
# distance defines the displacement magnitude (default 0.01 Angstrom for VASP-like calculators)
phonon.generate_displacements(distance=0.03)
# Get the supercells with displacements. These would typically be used to generate input files for DFT calculations.
supercells_with_displacements = phonon.supercells_with_displacements
print(f"Number of displaced supercells: {len(supercells_with_displacements)}")
print("First displaced supercell (symbols and scaled positions):")
print(supercells_with_displacements[0].symbols)
print(supercells_with_displacements[0].scaled_positions)
# In a real workflow, you would then run DFT calculations on these supercells to get forces,
# and then use phonon.set_forces() and further methods to compute phonon properties.