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
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) 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 |
Returns:
| Type | Description |
|---|---|
ndarray
|
Complex generating function :math: |
Notes
Implements [Alkauskas 2014a, Eq. 8]:
.. math::
G(t) = e^{S(t) - S}\, e^{-\gamma|t|}
The Fourier transform of G(t) gives the optical spectral function A(ℏω).
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'
|