matcalc._phonon module
Calculator for phonon properties.
- class PhononCalc(calculator: Calculator | str, *, atom_disp: float = 0.015, min_length: float | None = 20.0, supercell_matrix: ArrayLike | None = None, t_step: float = 10, t_max: float = 1000, t_min: float = 0, fmax: float = 0.0001, max_steps: int = 5000, optimizer: str = 'FIRE', relax_structure: bool = True, relax_calc_kwargs: dict | None = None, imaginary_freq_tol: float = -0.01, on_imaginary_modes: Literal['error', 'warn'] = 'warn', fix_imaginary_attempts: int = 0, rattle_method: Literal['random', 'mc', 'phonon'] = 'random', rattle_stdev: float = 0.01, rattle_temperature: float | None = None, seed: int | None = 42, symprec: float = 1e-05, write_force_constants: bool | str | Path = False, write_band_structure: bool | str | Path = False, write_total_dos: bool | str | Path = False, write_phonon: bool | str | Path = True)[source]
Bases:
PropCalcA class for phonon and thermal property calculations using phonopy.
The PhononCalc class extends the PropCalc class to provide functionalities for calculating phonon properties and thermal properties of a given structure using the phonopy library. It includes options for structural relaxation before phonon property determination, as well as methods to export calculated properties to various output files for further analysis or visualization.
- t_step, t_max, t_min
Thermal property temperature grid (K).
- seed[source]
Seed for the rattle random number generator (default 42 is reproducible; None for nondeterministic).
- Parameters:
calculator – ASE calculator or universal model name string.
atom_disp – Displacement for phonopy finite differences.
min_length – Minimum supercell size along each lattice direction (Å).
supercell_matrix – Integer supercell matrix; if None, derived from
min_length.t_step – Temperature step for thermal properties (K).
t_max – Maximum temperature (K).
t_min – Minimum temperature (K).
fmax – Relaxation force tolerance (eV/Å). Default 1e-4 (previously 1e-5): 1e-5 is at the float32 force noise floor of foundation potentials (relaxations end at max|F| ~ 5e-6 to 1e-5 eV/Å) and costs 1.5-2.4x more steps for no measurable change in the thermal properties. Pass
fmax=1e-5to restore the old behavior.max_steps – Maximum relaxation steps before phonopy.
optimizer – Optimizer for pre-phonon relaxation.
relax_structure – Whether to relax before building phonopy.
relax_calc_kwargs – Optional kwargs for
RelaxCalc.imaginary_freq_tol – Threshold (THz) for classifying imaginary modes.
on_imaginary_modes –
"warn"or"error"when imaginary modes exist.fix_imaginary_attempts – Rattle/relax/phonon retries; 0 disables.
rattle_method – Rattle used by the retries.
"random"draws Gaussian displacements;"mc"uses MC rattle, which rejects moves that bring atoms closer than 0.8 times the shortest interatomic distance."phonon"superimposes the Gamma-point normal modes of the input cell with amplitudes proportional to 1/|omega|.rattle_stdev – Standard deviation (Å) of the rattle displacements per Cartesian component. For
"mc", the displacements are approximately this size (smaller when moves are rejected). For"phonon", the RMS of the displacements per Cartesian component (unused whenrattle_temperatureis set).rattle_temperature – If set, the phonon rattle uses classical thermal amplitudes at this temperature (K) instead of
rattle_stdev. Only used withrattle_method="phonon".seed – Seed for the rattle random number generator (default 42 is reproducible; None for nondeterministic).
symprec – symmetry precision used for spglib symmetry finding.
write_force_constants – Path to write FCs, True for default name, or False.
write_band_structure – Path, True for default YAML, or False.
write_total_dos – Path, True for default DOS file, or False.
write_phonon – Path, True for default
phonon.yaml, or False.
- _check_imaginary_modes(frequencies: ndarray) None[source]
Warn or raise if imaginary modes are present, based on on_imaginary_modes setting.
- Parameters:
frequencies – Frequencies array from the mesh run.
- _rattle_structure(structure_in: Structure, rng: np.random.RandomState, phonon: phonopy.Phonopy, stdev: float = 0.01) Structure[source]
Rattle the atoms to bump out of stationary point (stdev=0.01 Å).
- Parameters:
structure_in – Pymatgen structure.
rng – Random number generator for the displacements.
phonon – Phonopy object of
structure_in, used by the phonon rattle.stdev – standard deviation in angstrom for the rattle.
- Returns:
Pymatgen structure with rattled atomic positions.
- _relax_structure(structure_in: Structure) dict[source]
Relax a structure.
- Parameters:
structure_in – Pymatgen structure.
- Returns:
Full result dict from RelaxCalc.
- Warns:
UserWarning – If the relaxation did not reach
fmaxwithinmax_steps. Unlike the other calculators, PhononCalc does not raise here, so that existing workflows keep running; the force constants are then computed around a non-equilibrium structure.
- _resolve_imaginary_modes(structure_in: Structure, phonon: phonopy.Phonopy, frequencies: np.ndarray, disp_supercells: list) tuple[dict, phonopy.Phonopy, np.ndarray, list[Structure]][source]
Attempt to resolve imaginary modes by rattling and re-relaxing.
- Parameters:
structure_in – Current primitive-cell structure.
phonon – Phonopy object from the most recent build.
frequencies – Frequencies from the most recent mesh run.
disp_supercells – Displaced supercells from the most recent build.
- Returns:
Updated (RelaxCalc dictionary, phonon, frequencies, disp_supercells).
- _run_phonopy(structure: Structure) tuple[phonopy.Phonopy, np.ndarray, list[Structure]][source]
Build a Phonopy object, run force calculations, and return (phonon, frequencies, disp_supercells).
- Parameters:
structure – Pymatgen structure.
- Returns:
Tuple of (phonon, frequencies, disp_supercells).
- calc(structure: Structure | Atoms | dict[str, Any]) dict[source]
Compute phonons and thermal properties with phonopy.
- Parameters:
structure – Pymatgen structure, ASE atoms, or dict with structure keys.
- Returns:
Dict with
phonon(phonopy.Phonopy),thermal_properties(phonopy thermal dict:temperaturesin K,free_energyin kJ/mol,entropyin J/(K*mol),heat_capacityin J/(K*mol)),frequenciesin THz,disp_supercells, plus any relaxation fields merged in._unitsmaps each numeric output to its unit string.
- _mc_rattle(atoms: Atoms, rattle_std: float, d_min: float, rng: np.random.RandomState, width: float = 0.1, n_iter: int = 10, max_attempts: int = 5000, max_disp: float = 2.0) np.ndarray[source]
Monte Carlo rattle displacements.
- Adapted from hiphive, described in:
F. Eriksson, E. Fransson, P. Erhart, Adv. Theory Simul. 2, 1800184 (2019). doi: 10.1002/adts.201800184
Each Gaussian trial move of an atom is accepted with probability
(erf((d - d_min) / width) + 1) / 2, wheredis the shortest distance from the atom to its neighbors within2 * d_min. The neighbor list is built once from the initial positions.- Parameters:
atoms – ASE atoms to rattle (not modified).
rattle_std – Standard deviation of each trial move (Å).
d_min – Center of the acceptance error function (Å).
rng – Random number generator.
width – Width of the acceptance error function (Å).
n_iter – Number of Monte Carlo sweeps over all atoms.
max_attempts – Maximum trial moves per atom and sweep.
max_disp – Trial moves that displace an atom by more than this (Å) are rejected.
- Returns:
Displacements (N, 3) in Å.
- _phonon_rattle(phonon: Phonopy, stdev: float, rng: RandomState, temperature: float | None = None) ndarray[source]
Phonon rattle displacements of the phonopy primitive cell (the input cell).
Adapted from hiphive, which follows D. West, S. K. Estreicher, Phys. Rev. Lett. 96, 115504 (2006). The normal modes of the Gamma-point dynamical matrix get Gaussian amplitudes proportional to 1/|omega|. Imaginary modes are treated as real and the three acoustic modes are left out. The displacements are scaled to an RMS of
stdev, or, iftemperatureis set, have the classical thermal amplitudes sqrt(kB T / m) / omega.- Parameters:
phonon – Phonopy object with force constants.
stdev – RMS of the displacements per Cartesian component (Å).
rng – Random number generator.
temperature – Temperature (K) for thermal amplitudes instead of
stdev.
- Returns:
Displacements (N, 3) in Å.