defectpl.utils¶
Displacement and configuration coordinates¶
calc_delR
¶
Compute the unweighted Cartesian displacement norm ΔR.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dR
|
ndarray
|
Atomic displacement matrix, shape |
required |
Returns:
| Type | Description |
|---|---|
float
|
:math: |
Examples:
Source code in defectpl/utils.py
calc_delQ
¶
Compute the mass-weighted configuration coordinate difference ΔQ.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
masses
|
ndarray
|
Atomic masses in AMU, shape |
required |
dR
|
ndarray
|
Atomic displacement matrix in Å, shape |
required |
Returns:
| Type | Description |
|---|---|
float
|
:math: |
Notes
The closure relation :math:\Delta Q^2 = \sum_k q_k^2 holds when the
phonon eigenvectors span the full displacement space.
Examples:
>>> import numpy as np
>>> masses = np.array([12.011, 15.999])
>>> dR = np.array([[0.1, 0.0, 0.0], [0.0, 0.2, 0.0]])
>>> calc_delQ(masses, dR) # sqrt(12.011*0.01 + 15.999*0.04)
0.8289...
Source code in defectpl/utils.py
calc_delta_Q
¶
Calculate the mass-weighted configuration coordinate displacement delta Q between two structures.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
struct1
|
Structure
|
Initial reference equilibrium configuration. |
required |
struct2
|
Structure
|
Final reference equilibrium configuration. |
required |
Returns:
| Type | Description |
|---|---|
float
|
Mass-weighted structural displacement delta Q in amu^(½) * Å. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If structures have unequal numbers of atoms. |
Source code in defectpl/utils.py
calc_qks
¶
Project atomic displacements onto phonon normal modes to find mode coordinates q_k.
This function uses a loop-based approach to calculate the dimensioned configuration coordinates from real-space displacement vectors.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
masses
|
ndarray
|
1D array of atomic masses for each atom in the system. Shape: (N_atoms,). Unit: AMU. |
required |
dR
|
ndarray
|
2D array of atomic displacement vectors between two configurations. Shape: (N_atoms, 3). Unit: Angstrom (Å). |
required |
eigenvectors
|
ndarray
|
3D array representing the normal mode eigenvectors matrix. Shape: (N_modes, N_atoms, 3). Dimensionless (normalized). |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
1D array of projected configuration coordinates for each mode k. Shape: (N_modes,). Unit: SI units (kg^{½} * m). |
See Also
calc_qks_vectorized : Faster, loopless alternative for this calculation.
Source code in defectpl/utils.py
calc_qks_force_mode
¶
Project atomic force differences onto phonon normal modes using energies in eV.
This function calculates the dimensioned configuration coordinates using a loop-based approach, derived from the excited state forces acting on the ground state geometry. Acoustic or zero-frequency modes are protected to prevent division-by-zero errors.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
masses
|
ndarray
|
1D array of atomic masses for each atom in the system. Shape: (N_atoms,). Unit: AMU. |
required |
forces
|
ndarray
|
2D array containing the difference in force vectors between the excited and ground states. Shape: (N_atoms, 3). Unit: eV/Angstrom (eV/Å). |
required |
eigenvectors
|
ndarray
|
3D array representing the normal mode eigenvectors matrix. Shape: (N_modes, N_atoms, 3). Dimensionless (normalized). |
required |
frequencies_eV
|
ndarray
|
1D array of Gamma-point phonon mode energies. Shape: (N_modes,). Unit: Electron-volts (eV). |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
1D array of projected configuration coordinates for each mode k. Shape: (N_modes,). Unit: SI units (kg^{½} * m). |
See Also
calc_qks_force_vectorized : Faster, loopless alternative for this calculation.
Source code in defectpl/utils.py
Huang–Rhys factors and spectral function¶
calc_Sks
¶
Compute partial Huang–Rhys factors for each Gamma-point phonon mode.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
qks
|
ndarray
|
Mode-projected configuration coordinates in SI units (kg^(½)·m),
shape |
required |
frequencies
|
ndarray
|
Phonon mode energies in eV, shape |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
Partial Huang–Rhys factors :math: |
Notes
The partial HR factor is [Alkauskas 2014a, Eq. 4]:
.. math::
S_k = \frac{\omega_k q_k^2}{2\hbar}
where :math:q_k is in SI units (kg^(½)·m) and :math:\omega_k
is converted from eV via :math:\omega_k = E_k / \hbar.
The total HR factor is :math:S = \sum_k S_k.
Source code in defectpl/utils.py
calc_S_omega
¶
Compute the continuous electron–phonon spectral density function S(ω).
Each discrete mode contribution :math:S_k \delta(\omega - \omega_k) is
replaced by a normalized Gaussian of width sigma, giving:
.. math::
S(\omega) = \sum_k S_k \, g(\omega - \omega_k, \sigma)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
frequencies
|
ndarray
|
Phonon mode energies in eV, shape |
required |
Sks
|
ndarray
|
Partial Huang–Rhys factors, shape |
required |
omega_range
|
list of float
|
Energy grid specification |
required |
sigma
|
float
|
Gaussian broadening width in eV. The default 6 meV is suitable for defect calculations; increase for broad sidebands. |
6e-3
|
Returns:
| Type | Description |
|---|---|
ndarray
|
Spectral density :math: |
See Also
calc_St : Transforms S(ω) to the time domain via inverse FFT.
Source code in defectpl/utils.py
gaussian_broadening
¶
Evaluate a normalized Gaussian centred at omega_k with width sigma.
Used by :func:calc_S_omega to replace each discrete delta-function
mode contribution with a Gaussian of unit area.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
omega
|
float or ndarray
|
Evaluation energy in eV (can be a grid). |
required |
omega_k
|
float or ndarray
|
Centre energy in eV (phonon mode frequency or broadcast array). |
required |
sigma
|
float
|
Standard deviation (broadening width) in eV. |
required |
Returns:
| Type | Description |
|---|---|
float or ndarray
|
Gaussian value(s) at omega in eV^{-1}. |
Source code in defectpl/utils.py
Phonon IPR¶
calc_IPR
¶
Calculate the site-projected Inverse Participation Ratio (IPR) for phonon modes.
For each normal mode i the per-atom weight is:
p_{i,a} = sum_{xyz} e_{i,a,xyz}^2
and the IPR is defined as:
IPR_i = sum_a p_{i,a}^2 / (sum_a p_{i,a})^2
Range: 1/N (fully delocalized over N atoms) to 1 (fully localized on one atom).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
eigenvectors
|
ndarray
|
Phonon normal mode eigenvectors, shape (nmodes, natoms, 3). Works for both normalized (phonopy) and un-normalized eigenvectors. |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
IPR value for each normal mode, shape (nmodes,). |
Source code in defectpl/utils.py
calc_IPR_alkauskas
¶
Calculate the phonon IPR following Alkauskas et al. (New J. Phys. 16, 073026, 2014), eq. 12.
For each normal mode k the per-atom weight is:
p_{k,α} = Σ_i e_{k,α,i}²
and the Alkauskas IPR is:
IPR_k = (Σ_α p_{k,α})² / Σ_α p_{k,α}²
For phonopy-normalized eigenvectors (Σ_α p_{k,α} = 1) this reduces to 1 / Σ_α p_{k,α}².
Range: 1 (fully localized on one atom) to N (fully delocalized over N atoms).
This is the reciprocal of the traditional IPR returned by :func:calc_IPR, and equals the
paper's equation 12 for normalized eigenvectors. The localization ratio β_k = N × IPR_k⁻¹
(traditional) = N / IPR_k (Alkauskas) — both conventions give the same β_k via
natoms * calc_IPR(evecs) or natoms / calc_IPR_alkauskas(evecs).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
eigenvectors
|
ndarray
|
Phonon normal mode eigenvectors, shape (nmodes, natoms, 3). Works for both normalized (phonopy) and un-normalized eigenvectors. |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
Alkauskas IPR value for each normal mode, shape (nmodes,). |
Source code in defectpl/utils.py
Temperature-dependent PL and absorption¶
calc_phonon_occupation
¶
Compute the Bose-Einstein phonon occupation number for each mode.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
frequencies
|
ndarray
|
Phonon frequencies in eV, shape |
required |
temperature
|
float
|
Temperature in Kelvin. Pass 0 to get an all-zero array (T = 0 limit). |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
Occupation numbers :math: |
Notes
Implements Jin et al. (2021), Eq. 9 / Alkauskas et al. (2014), Eq. 9:
.. math::
\bar{n}_k(T) = \frac{1}{e^{\hbar\omega_k / k_B T} - 1}
At T = 0 all occupation numbers are zero (no thermally excited phonons).
Source code in defectpl/utils.py
calc_C_omega
¶
Build the thermal electron–phonon spectral density C(ℏω, T) on a uniform grid.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
frequencies
|
ndarray
|
Phonon frequencies in eV, shape |
required |
Sks
|
ndarray
|
Partial Huang–Rhys factors, shape |
required |
nks
|
ndarray
|
Bose-Einstein occupation numbers :math: |
required |
omega_range
|
list[ω_min, ω_max, n_points]
|
Energy grid parameters in eV. |
required |
sigma
|
float or (float, float)
|
Gaussian broadening in eV. Scalar → uniform; 2-tuple → linearly interpolated from lowest to highest frequency mode. Default 6 meV. |
0.006
|
Returns:
| Type | Description |
|---|---|
ndarray
|
:math: |
Notes
Implements Jin et al. (2021), Eq. 12:
.. math::
C(\hbar\omega, T) = \sum_k \bar{n}_k(T)\, S_k\,
\delta(\hbar\omega - \hbar\omega_k)
with δ-functions replaced by Gaussians (with optional frequency-dependent width σ(ω_k)). At T = 0 the function returns a zero array without allocating the FFT buffers.
Source code in defectpl/utils.py
calc_Ct
¶
Transform C(ℏω, T) to the time domain, returning the real cosine component.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
C_omega
|
ndarray
|
Thermal spectral density :math: |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
Real-valued :math: |
Notes
Implements Jin et al. (2021), using the relation:
.. math::
C(t, T) = \operatorname{Re}\!\left[
\int_0^\infty C(\hbar\omega, T)\, e^{-i\omega t}\, d(\hbar\omega)
\right]
which is the real part of the inverse Fourier transform of C(ω, T),
identical in structure to :func:calc_St but restricted to its real part.
Source code in defectpl/utils.py
calc_C_total
¶
Compute the zero-time thermal correction C(0, T) = Σ_k n̄_k S_k.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
nks
|
ndarray
|
Bose-Einstein occupation numbers, shape |
required |
Sks
|
ndarray
|
Partial Huang–Rhys factors, shape |
required |
Returns:
| Type | Description |
|---|---|
float
|
:math: |
Notes
This is the thermal analogue of the total Huang–Rhys factor S = Σ_k S_k. At T = 0 it evaluates to zero, keeping the generating function unchanged.
Source code in defectpl/utils.py
calc_Absorption_Intensity
¶
Compute the absorption spectral function and absorption intensity from G(t, T).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
Gts
|
ndarray
|
Complex PL generating function G(t, T) from :func: |
required |
EZPL
|
float
|
Zero-phonon line energy in eV. |
required |
resolution
|
float
|
Spectral grid density in points per eV. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
A_abs |
ndarray
|
Absorption spectral function :math: |
intensity_abs |
ndarray
|
Absorption intensity :math: |
Notes
The absorption generating function is the complex conjugate of the PL generating function (Jin et al. 2021; derivation from Eq. 8):
.. math::
G_{abs}(t, T) = G^*(t, T)
because replacing :math:S(t) = \sum_k S_k e^{i\omega_k t} with
:math:S^*(t) = \sum_k S_k e^{-i\omega_k t} while leaving the real
thermal correction :math:C(t,T) unchanged yields exactly
:math:\overline{G(t,T)}.
The sideband appears on the high-energy side of the ZPL (energy axis
:math:E_{ZPL} + E), opposite to PL emission. The prefactor is
:math:\omega (linear) rather than :math:\omega^3.
Source code in defectpl/utils.py
calc_effective_phonon_frequency
¶
Compute the effective phonon frequency for the 1D configurational coordinate model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
frequencies
|
ndarray
|
Phonon frequencies in eV, shape |
required |
delta_Q_k
|
ndarray
|
Mode-projected configurational displacements q_k in amu\ :sup: |
required |
Returns:
| Type | Description |
|---|---|
float
|
Effective phonon frequency :math: |
Notes
Implements Jin et al. (2021), Eq. 16:
.. math::
\Omega = \frac{\sum_k \omega_k^2\, \Delta Q_k^2}{\sum_k \Delta Q_k^2}
This weighted average collapses the full phonon spectrum onto a single
representative mode for use in the 1D harmonic oscillator lineshape model
(:class:~defectpl.defectpl.VibrationalSpectra1D).
Source code in defectpl/utils.py
Generating function and spectrum¶
calc_St
¶
Transform the electron–phonon spectral density S(ω) to the time domain S(t).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
S_omega
|
ndarray
|
Spectral density on a uniform energy grid, shape |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
Complex-valued time-domain array :math: |
Notes
Implements [Alkauskas 2014a, Eq. 9]:
.. math::
S(t) = \int_0^\infty S(\hbar\omega)\, e^{-i\omega t}\, d(\hbar\omega)
via an inverse FFT with phase centering.
See Also
calc_Gts : Constructs G(t) from S(t).
Source code in defectpl/utils.py
calc_Gts
¶
Compute the generating function G(t, T) from the time-domain spectral function.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
Sts
|
ndarray
|
Time-domain spectral function S(t), shape |
required |
total_HR
|
float
|
Total Huang–Rhys factor :math: |
required |
gamma
|
float
|
ZPL broadening parameter in meV; applied as a Lorentzian decay
:math: |
required |
resolution
|
float
|
Spectral grid density in points per eV ( |
required |
Cts
|
ndarray
|
Real-valued time-domain thermal correction C(t, T) from :func: |
None
|
C_total
|
float
|
Zero-time thermal correction C(0, T) = Σ n̄_k S_k from :func: |
0.0
|
Returns:
| Type | Description |
|---|---|
ndarray
|
Complex generating function :math: |
Notes
Implements Jin et al. (2021), Eq. 8 / Eq. 10:
.. math::
G(t, T) = e^{S(t) - S + 2C(t,T) - 2C(0,T)}\, e^{-\gamma|t|}
At T = 0 (Cts = None or all-zero) the thermal correction vanishes and
the expression reduces to the Alkauskas (2014) formula :math:G(t) = e^{S(t)-S}.
Source code in defectpl/utils.py
calc_Spectrum_Intensity
¶
Compute the optical spectral function A(ℏω) and PL intensity L(ℏω) from G(t).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
Gts
|
ndarray
|
Complex generating function G(t), shape |
required |
EZPL
|
float
|
Zero-phonon line energy in eV. Used to shift the spectral axis so that the ZPL appears at the correct absolute photon energy. |
required |
resolution
|
float
|
Spectral grid density in points per eV ( |
required |
Returns:
| Name | Type | Description |
|---|---|---|
A |
ndarray
|
Optical spectral function :math: |
intensity |
ndarray
|
Normalized PL intensity :math: |
Notes
Implements [Alkauskas 2014a, Eq. 7]:
.. math::
A(E_{\text{ZPL}} - \hbar\omega) =
\frac{1}{2\pi} \int_{-\infty}^{\infty} G(t)\, e^{i\omega t}\, dt
The :math:\omega^3 prefactor originates from the photon density of states.
Source code in defectpl/utils.py
1D overlap integrals¶
calculate_hermite
¶
Compute the physicist's Hermite polynomial H_n(x) using recurrence relation stability.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n
|
int
|
The order index of the target Hermite polynomial. |
required |
x
|
float
|
The specific coordinate position coordinate value to evaluate. |
required |
Returns:
| Type | Description |
|---|---|
float
|
The evaluated numerical result of the physicist's Hermite polynomial. |
Source code in defectpl/utils.py
calculate_overlap_element
¶
Calculate the 1D analytical transition overlap integral between two harmonic oscillator states.
This implements analytical Franck-Condon factor calculations supporting models where ground and excited configurations can possess different vibrational frequencies.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
m
|
int
|
Vibrational quantum number index mapping the excited state. |
required |
n
|
int
|
Vibrational quantum number index mapping the ground state. |
required |
rho
|
float
|
Dimensionless offset displacement parameter between harmonic minima. |
required |
cosfi
|
float
|
Mixing angle cosine property resolving frequency transformation shifts scaling. |
required |
sinfi
|
float
|
Mixing angle sine property resolving frequency transformation shifts scaling. |
required |
Returns:
| Type | Description |
|---|---|
float
|
The computed structural overlap integral element value between states (m, n). |
Source code in defectpl/utils.py
Configuration Coordinate Diagram fitting¶
get_omega_from_pes
¶
Fit a harmonic parabola E(Q) = ½·M·ω²·Q² to PES data points.
A second-order polynomial is fit to (Q, E) data. The effective angular frequency ω is extracted from the curvature coefficient and returned in eV (as an effective phonon energy ℏω).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
q_values
|
ndarray
|
Configuration coordinate values Q in amu^(½)·Å. |
required |
energies
|
ndarray
|
Total energies (or energy differences) in eV, zero-referenced to the minimum. |
required |
ax
|
Axes
|
If provided, the fitted parabola is plotted on this axes object. |
None
|
eval_grid
|
ndarray
|
Q grid for plotting the fit curve. Required when ax is given. |
None
|
Returns:
| Type | Description |
|---|---|
float
|
Effective phonon energy ℏω in eV derived from the parabola curvature. |
Notes
The fit uses :func:numpy.polyfit (degree 2). The curvature coefficient
a₂ (eV/amu·Å²) is related to the angular frequency by:
.. math::
\hbar\omega = \sqrt{2 a_2 / M_{\text{ref}}}
where an effective reference mass of 1 amu is assumed (since Q is already mass-weighted). The units are handled via the AMU2KG, ANG2M, and EV2J conversion factors.
Source code in defectpl/utils.py
extract_important_properties
¶
Write a structured summary of scalar PL properties to a text file.
Extracts S, DW factor, ΔQ, ΔR, and configuration metadata from a
:class:~defectpl.defectpl.Photoluminescence instance. Force-mode
runs omit ΔQ/ΔR since they are not directly computed in that mode.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pl_engine
|
Photoluminescence
|
A fully computed Photoluminescence instance. |
required |
filename
|
str
|
Output file path. Default |
'important_properties.txt'
|
Source code in defectpl/utils.py
1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 | |