dfttk.phonon

harmonic_phonon_yphon

HarmonicPhononYphon class for computing thermodynamic properties using phonon DOS data from VASP and YPHON.

class dfttk.phonon.harmonic_phonon_yphon.HarmonicPhononYphon[source]

Bases: object

Class for computing thermodynamic properties within the harmonic approximation using phonon density of states (DOS) data from VASP and YPHON.

phonon_dos[source]

Raw phonon DOS data loaded from YPHON output.

Type:

pd.DataFrame

scaled_phonon_dos[source]

Phonon DOS data scaled to the specified number of atoms.

Type:

pd.DataFrame

number_of_atoms[source]

Number of atoms used for scaling the DOS and thermodynamic properties.

Type:

int

volumes_per_atom[source]

Unique volumes per atom corresponding to the phonon DOS data.

Type:

np.ndarray

volumes[source]

Total volumes (per supercell) after scaling by number_of_atoms.

Type:

np.ndarray

helmholtz_energies[source]

Vibrational Helmholtz free energy (eV/atom); shape (temperatures, volumes).

Type:

np.ndarray

entropies[source]

Vibrational entropies (eV/K/atom); shape (temperatures, volumes).

Type:

np.ndarray

heat_capacities[source]

Vibrational heat capacity at constant volume (eV/K/atom); shape (temperatures, volumes).

Type:

np.ndarray

helmholtz_energies_fit[source]

Fitted Helmholtz energy (eV/atom); shape (temperatures, volumes_fit).

Type:

np.ndarray

entropies_fit[source]

Fitted entropies (eV/K/atom); shape (temperatures, volumes_fit).

Type:

np.ndarray

heat_capacities_fit[source]

Fitted heat capacity (eV/K/atom); shape (temperatures, volumes_fit).

Type:

np.ndarray

helmholtz_energies_poly_coeffs[source]

Polynomial coefficients for Helmholtz energy fit.

Type:

np.ndarray

entropies_poly_coeffs[source]

Polynomial coefficients for entropies fit.

Type:

np.ndarray

heat_capacities_poly_coeffs[source]

Polynomial coefficients for heat capacity fit.

Type:

np.ndarray

load_dos(path)[source]

Load phonon DOS data from vdos and volph files in the specified directory.

Parameters:

path (str) – Directory containing vdos_ and volph_ files.

Returns:

Combined phonon DOS data.

Return type:

None

Raises:
  • FileNotFoundError – If no vdos or volph files are found in the directory.

  • ValueError – If the number of vdos files does not match the number of volph files, or if the indexes of vdos and volph files do not match.

scale_dos(number_of_atoms, plot=False)[source]

Scale the area under the phonon DOS to 3N, where N is the number of atoms.

Parameters:
  • number_of_atoms (int) – Number of atoms to scale the DOS to.

  • plot (bool) – If True, return a plotly Figure of the original and scaled DOS.

Returns:

Plotly Figure if plot is True, otherwise None.

Return type:

None

Raises:

RuntimeError – If phonon DOS data is not loaded (call load_dos() before scale_dos()).

plot_dos()[source]

Plot the scaled phonon density of states (DOS) for multiple volumes.

Returns:

Plotly Figure object showing the scaled phonon DOS for each volume.

Return type:

Figure

Raises:

RuntimeError – If scaled phonon DOS data or volumes_per_atom is not set.

calculate_harmonic(temperatures, selected_volumes=None)[source]

Calculate vibrational thermodynamic properties (Helmholtz energy, internal energy, entropies, heat capacity) at the specified temperatures using the scaled phonon DOS and the harmonic approximation.

Parameters:
  • temperatures (ndarray) – 1D array of temperatures in Kelvin.

  • selected_volumes (ndarray) – 1D array of volumes to calculate properties for.

Raises:

RuntimeError – If scaled phonon DOS data or volumes_per_atom is not set (call scale_dos() before calculate_harmonic()).

Return type:

None

fit_harmonic(volumes_fit, order=2)[source]

Fit the Helmholtz energy, entropy, and heat capacity as a function of volume using polynomial regression for each temperature.

Parameters:
  • volumes_fit (ndarray) – 1D array of volumes to evaluate the fitted properties.

  • order (int) – Polynomial order for fitting. Defaults to 2.

Raises:

RuntimeError – If required thermodynamic properties are not set (call calculate_harmonic() before fit_harmonic()).

Return type:

None

plot_harmonic(property)[source]

Plot a thermodynamic property (Helmholtz energy, entropy, or heat capacity) as a function of temperature for each volume.

Parameters:

property (str) – Name of the property to plot. Must be one of ‘helmholtz_energy’, ‘entropy’, or ‘heat_capacity’.

Returns:

Plotly Figure object with the property vs. temperature curves.

Return type:

Figure

Raises:
  • RuntimeError – If required thermodynamic properties are not set (call calculate_harmonic() before fit_harmonic()).

  • ValueError – If property is not one of ‘helmholtz_energy’, ‘entropy’, or ‘heat_capacity’.

plot_fit_harmonic(property, selected_temperatures=None)[source]

Plot fitted thermodynamic properties (Helmholtz energy, entropy, or heat capacity) as a function of volume for selected temperatures.

Parameters:
  • property (str) – Name of the property to plot. Must be one of ‘helmholtz_energy’, ‘entropy’, or ‘heat_capacity’.

  • selected_temperatures (ndarray) – Array of temperatures (in K) to plot. If None, five temperatures are selected evenly from the range.

Returns:

Plotly Figure object with the fitted property vs. volume curves.

Return type:

Figure

Raises:
  • RuntimeError – If fitted thermodynamic properties are not set (call fit_harmonic() before plot_fit_harmonic()).

  • ValueError – If property is not one of ‘helmholtz_energy’, ‘entropy’, or ‘heat_capacity’.

static pad_arrays(arrays, pad_value=0, pad_type='constant')[source]

Pad a list of 1D arrays to the same length for stacking.

Parameters:
  • arrays (list of np.ndarray) – List of 1D arrays to pad.

  • pad_value (float, optional) – Value to use for constant padding. Default is 0.

  • pad_type (str, optional) – Padding strategy: - “constant”: pad with pad_value (default) - “increasing”: pad with increasing values based on the last increment

Returns:

2D array with each input array padded to the maximum length.

Return type:

np.ndarray

yphon_phonon_data

YphonPhononData class for storing and processing phonon data from VASP and YPHON calculations.

class dfttk.phonon.yphon_phonon_data.YphonPhononData(path)[source]

Bases: object

Class for storing and processing phonon data from VASP and YPHON calculations.

This class manages VASP input/output, loads and processes YPHON phonon DOS results, and provides methods for calculating and plotting thermodynamic properties using the harmonic approximation.

path[source]

Path to the directory containing phonon calculation results.

Type:

str

incars[source]

List of INCAR dictionaries for each phonon calculation.

Type:

list[dict]

kpoints[source]

KPOINTS object for the calculations.

Type:

Kpoints

potcar[source]

POTCAR object for the calculations.

Type:

Potcar

phonon_structures[source]

List of Pymatgen Structure objects for each phonon calculation.

Type:

list[Structure]

number_of_atoms[source]

Number of atoms used for scaling the phonon DOS.

Type:

int

volumes[source]

Array of volumes for each structure, shape (n_volumes,).

Type:

np.ndarray

temperatures[source]

Array of temperatures used for thermodynamic calculations, shape (n_temperatures,).

Type:

np.ndarray

helmholtz_energies[source]

Helmholtz free energy (eV/atom), shape (n_temperatures, n_volumes).

Type:

np.ndarray

internal_energies[source]

Internal energy (eV/atom), shape (n_temperatures, n_volumes).

Type:

np.ndarray

entropies[source]

Entropy (eV/K/atom), shape (n_temperatures, n_volumes).

Type:

np.ndarray

heat_capacities[source]

Heat capacity (eV/K/atom), shape (n_temperatures, n_volumes).

Type:

np.ndarray

volumes_fit[source]

Volumes used for polynomial fits, shape (n_volumes_fit,).

Type:

np.ndarray

helmholtz_energies_fit[source]

Fitted Helmholtz free energies (n_temperatures, n_volumes_fit).

Type:

np.ndarray

entropies_fit[source]

Fitted entropies (n_temperatures, n_volumes_fit).

Type:

np.ndarray

heat_capacities_fit[source]

Fitted heat capacity data (n_temperatures, n_volumes_fit).

Type:

np.ndarray

helmholtz_energies_poly_coeffs[source]

Polynomial coefficients for Helmholtz energy fits.

Type:

np.ndarray

entropies_poly_coeffs[source]

Polynomial coefficients for entropy fits.

Type:

np.ndarray

heat_capacities_poly_coeffs[source]

Polynomial coefficients for heat capacity fits.

Type:

np.ndarray

_harmonic_phonon[source]

Cached instance for calculations and plotting.

Type:

HarmonicPhononYphon

_helmholtz_energies_fit_to_db[source]

Fitted Helmholtz energy data for database export.

Type:

dict

_entropies_fit_to_db[source]

Fitted entropy data for database export.

Type:

dict

_heat_capacities_fit_to_db[source]

Fitted heat capacity data for database export.

Type:

dict

process_phonon_dos()[source]

Run YPHON post-processing on the phonon calculation directory.

get_vasp_input(selected_phonon_volumes=None)[source]

Load VASP files (INCAR, KPOINTS, POTCAR, CONTCAR) for each phonon folder.

Parameters:

selected_phonon_volumes (ndarray) – If provided, only load structures with these phonon volumes.

Return type:

None

get_harmonic_data(number_of_atoms, volumes_fit, temperatures, order=2, selected_volumes=None)[source]

Load, scale, and process YPHON phonon DOS data to compute thermodynamic properties.

Parameters:
  • number_of_atoms (int) – Number of atoms to scale the phonon DOS to.

  • volumes_fit (ndarray) – 1D array of volumes to evaluate the fitted properties.

  • temperatures (ndarray) – Array of temperatures (K) for property calculation.

  • order (int) – Polynomial order for fitting thermodynamic properties. Defaults to 2.

  • selected_volumes (ndarray) – If provided, only calculate properties using these volumes. The volumes are volumes per atom multiplied by the number of atoms.

Return type:

None

plot_scaled_dos(number_of_atoms, plot=True)[source]

Plot the scaled phonon DOS for the specified number of atoms.

Parameters:
  • number_of_atoms (int) – Number of atoms to scale the DOS to.

  • plot (bool) – If True, display the plot.

Returns:

The Plotly figure object for the scaled DOS.

Return type:

Figure

Raises:

RuntimeError – If get_harmonic_data() has not been called.

plot_multiple_dos()[source]

Plot the scaled phonon DOS for multiple volumes.

Returns:

The Plotly figure object for the multiple DOS plot.

Return type:

Figure

Raises:

RuntimeError – If get_harmonic_data() has not been called.

plot_harmonic(property, selected_temperatures=None)[source]

Plot harmonic thermodynamic properties and their polynomial fits.

Parameters:
  • property (str) – Property to plot (‘helmholtz_energy’, ‘entropy’, or ‘heat_capacity’).

  • selected_temperatures (ndarray) – Temperatures to plot for the fit.

Returns:

(property vs. temperature, property fit vs. volume)

Return type:

tuple[Figure, Figure]

Raises:
  • RuntimeError – If get_harmonic_data() has not been called.

  • ValueError – If property is not a valid option.