Phonopy

3.5.0 · active · verified Wed Apr 15

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

Install

Imports

Quickstart

This quickstart demonstrates how to initialize a `Phonopy` object with a unit cell and supercell matrix, and generate the necessary atomic displacements for subsequent DFT force calculations. The example uses a Silicon diamond structure, a common test case in phonon calculations. After generating displacements, the `supercells_with_displacements` can be used to create input files for an external DFT code. Once the forces are computed, they would be fed back into Phonopy for full phonon property analysis.

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.

view raw JSON →