2c_DL_diffusivity_decomposition.py — Diffusivity Decomposition

Post-processing step that decomposes thermal diffusivity into propagation velocity and mean free path using the fitted L and R parameters (mirrors Notebook 5). Reads the model parameters from dl_workflow/model_parameters.hdf5 and precomputed vdos/velocity/diffusivity data, then:

  1. Computes the disorder linewidth Γ(ω) from the fitted model.

  2. Evaluates the PDC model for the disordered VDOS.

  3. Decomposes the Allen-Feldman diffusivity into propagation velocity vprop and mean free path ℓ as a function of frequency.

  4. Saves results and generates decomposition plots.

Run after 2b_DL_fit_params.py.

cd workflows
python 2c_DL_diffusivity_decomposition.py
  1import sys
  2import pathlib
  3sys.path.insert(0, str(pathlib.Path(__file__).parent))
  4
  5import h5py
  6import numpy as np
  7import matplotlib
  8import matplotlib.pyplot as plt
  9from ase.io import read
 10from scipy.interpolate import interp1d
 11
 12from tqdm import tqdm
 13
 14from smooth_disorder.structural import obtain_density, THzToCm, THz, Angstrom
 15from smooth_disorder.vis.interactive import *
 16
 17from smooth_disorder.disorder_linewidth import lorentzian_numpy, prepare_fitting_inputs
 18from smooth_disorder.disorder_linewidth import evaluate_linewidth_and_model_prediction
 19
 20from config import (
 21    CRYSTAL_POSCAR, DISORDERED_POSCAR, DISORDERED_DIFFUSIVITY,
 22    DL_WORK_DIR, EXTRAPOLATION_VALUE,
 23)
 24
 25WORK_DIR = DL_WORK_DIR
 26
 27CRYSTAL_VEL_SAVE     = f"{WORK_DIR}/crystal_vdos_group_vel"
 28DISORDERED_VDOS_SAVE = f"{WORK_DIR}/disordered_vdos"
 29SHIFTED_SAVE         = f"{WORK_DIR}/reduced_density_crystal_vdos_group_vel"
 30
 31MODEL_PARAMETERS_SAVE = f"{WORK_DIR}/model_parameters"
 32
 33
 34# read in the preprocessed data
 35(density_crystal,
 36density_disordered,
 37freq_disordered,
 38vdos_disordered,
 39interp_shifted_freq_crystal,
 40interp_shifted_vdos_crystal,
 41interp_shifted_speed_crystal) = prepare_fitting_inputs(
 42    CRYSTAL_POSCAR,
 43    DISORDERED_POSCAR,
 44    DISORDERED_VDOS_SAVE,
 45    SHIFTED_SAVE,
 46)
 47
 48# load the model parameters
 49with h5py.File(f"{MODEL_PARAMETERS_SAVE}.hdf5", "r") as f:
 50    model_params = np.asarray(f["final_model_params"])
 51    L_ref, R_ref = model_params[0]*1e1, model_params[1]*1e-6  # convert to standard units
 52
 53print(f"Grain boundary length: {L_ref} Angstrom")
 54print(f"Defect scattering parameter: {R_ref} THz cm nm^3")
 55
 56
 57# find the PDC VDOS
 58(
 59    vdos_PDC,
 60    disorder_linewidth,
 61    defect_linewidth,
 62    Casimir_model_linewidth
 63) = evaluate_linewidth_and_model_prediction(
 64        density_crystal,
 65        density_disordered,
 66        freq_disordered,
 67        vdos_disordered,
 68        interp_shifted_freq_crystal,
 69        interp_shifted_vdos_crystal,
 70        interp_shifted_speed_crystal,
 71        L=L_ref,
 72        R=R_ref,
 73    )
 74
 75
 76###########################
 77# DISORDER LINEWIDTH PLOT #
 78###########################
 79
 80
 81plt.figure(figsize=(16, 8))
 82
 83plt.plot(interp_shifted_freq_crystal, defect_linewidth, color=Colors[3], label="defect contribution")
 84plt.plot(interp_shifted_freq_crystal, Casimir_model_linewidth, color=Colors[0], label="grain boundary contribution")
 85plt.plot(interp_shifted_freq_crystal, disorder_linewidth, color=Colors[2], label="total disorder linewidth")
 86
 87plt.xlabel("Frequency [cm^-1]")
 88plt.ylabel("Disorder linewidth [cm^-1]")
 89
 90plt.title("Disorder linewidth and its contributions")
 91
 92plt.legend(loc="upper left")
 93
 94plt.savefig(f"{WORK_DIR}/disorder_linewidth.png", dpi=300)
 95
 96
 97
 98########################
 99# VDOS COMPARISON PLOT #
100########################
101
102
103
104def obtain_crystal_vdos():
105
106    with h5py.File(f"{CRYSTAL_VEL_SAVE}.hdf5", "r") as f:
107        freq_crystal = np.asarray(f["frequencies_bin"])  # [cm⁻¹]
108        vdos_crystal = np.asarray(f["vdos_return"])      # [THz⁻¹ nm⁻³]
109
110    return freq_crystal, vdos_crystal
111
112freq_crystal, vdos_crystal = obtain_crystal_vdos()
113
114
115
116plt.figure(figsize=(16, 8))
117
118plt.plot(freq_disordered, vdos_disordered, color=Colors[0], label='disordered system')
119plt.plot(freq_disordered, vdos_PDC, color=Colors[1], label='PDC model of the VDOS of disordered system')
120
121
122plt.xlabel("Frequency [cm^-1]")
123plt.ylabel("VDOS [THz^-1 nm^-3]")
124
125plt.title("VDOS of disordered system vs PDC VDOS model")
126
127plt.legend(loc="upper left")
128
129plt.savefig(f"{WORK_DIR}/disordered_vs_pdc_vdos.png", dpi=300)
130
131
132#############################
133# PROPAGATION VELOCITY PLOT #
134#############################
135
136
137with h5py.File(DISORDERED_DIFFUSIVITY, "r") as f:
138    print(f.keys())
139    diffusivity_plot = np.asarray(f["diffusivity"])  # in m^2/s
140    frequencies_plot_diff = np.asarray(f["frequencies_plot"])  # in cm^-1
141
142
143lifetime = 1/disorder_linewidth * THzToCm * 1e-12  # in seconds
144lifetime_function = interp1d(interp_shifted_freq_crystal, lifetime, bounds_error=False, fill_value=EXTRAPOLATION_VALUE)
145lifetime_interpolated = lifetime_function(frequencies_plot_diff)
146
147plt.figure(figsize=(16, 8))
148
149plt.plot(interp_shifted_freq_crystal, interp_shifted_speed_crystal * 1e-3, color=Colors[3], label='reference crystal')
150plt.plot(frequencies_plot_diff, np.sqrt(diffusivity_plot/lifetime_interpolated) * 1e-3, color=Colors[0], label='disordered system')
151
152
153plt.xlabel("Frequency [cm^-1]")
154plt.ylabel("Propagation velocity [km/s]")
155
156plt.title("Propagation velocity in reference crystal and disordered system")
157
158plt.legend(loc="upper right")
159
160plt.savefig(f"{WORK_DIR}/propagation_velocity.png", dpi=300)
161
162
163plt.figure(figsize=(16, 8))
164
165plt.plot(frequencies_plot_diff, np.sqrt(diffusivity_plot*lifetime_interpolated) * 1e10)
166
167plt.xlabel("Frequency [cm^-1]")
168plt.ylabel("Mean free path [A]")
169
170plt.title("Mean free path in the disordered system")
171
172plt.savefig(f"{WORK_DIR}/mean_free_path.png", dpi=300)