Tools#
A number of utility functions, for example for dealing with autocorrelation functions, Fourier transforms, and smoothing.
- dynasor.tools.acfs.compute_acf(Z, delta_t=1.0, method='scipy')[source]#
Computes the autocorrelation function (ACF) for a one-dimensional signal \(Z\) in time as
\[ACF(\tau) = \frac{\left < Z(t) Z^*(t+\tau) \right >}{\left < Z(t) Z^*(t) \right >}\]Here, only the real part of the ACF is returned since if \(Z\) is complex the imaginary part should average out to zero for any stationary signal.
- dynasor.tools.acfs.fermi_dirac(t, t_0, t_width)[source]#
Evaluates a Fermi-Dirac-like function in time \(f(t)\), which can be applied to an ACF in time to artificially damp it, i.e., forcing it to go to zero for long times without affecting the short-time correlations too much.
\[f(t) = \frac{1}{\exp{[(t-t_0)/t_\mathrm{width}}] + 1}\]
- dynasor.tools.acfs.gaussian_decay(t, t_sigma)[source]#
Evaluates a gaussian distribution in time \(f(t)\), which can be applied to an ACF in time to artificially damp it, i.e., forcing it to go to zero for long times.
\[f(t) = \exp{\left [-\frac{1}{2} \left (\frac{t}{t_\mathrm{sigma}}\right )^2 \right ] }\]
- dynasor.tools.acfs.psd_from_acf(acf, dt=1, angular=True, even=True)[source]#
Computes the power spectral density from auto-correlation function
- Parameters:
acf – The acf as an array
dt – The timestep between samples
angular – Whether to return normal or angular freqs
even – Whether to mirror the acf and force psd to be purely real
- dynasor.tools.acfs.smoothing_function(data, window_size, window_type='hamming')[source]#
Smoothing function for 1D arrays. This functions employs pandas rolling window average
- dynasor.tools.damped_harmonic_oscillator.acf_position_dho(t, w0, gamma, A=1.0)[source]#
The damped damped harmonic oscillator (DHO) autocorrelation function for the position. The definition of this function can be found in the
dynasor documentation <dynasor.materialsmodeling.org/theory.html#damped-harmonic-oscillator-model>_
.
- dynasor.tools.damped_harmonic_oscillator.acf_velocity_dho(t, w0, gamma, A=1.0)[source]#
The damped damped harmonic oscillator (DHO) autocorrelation function for the velocity. The definition of this function can be found in the
dynasor documentation <dynasor.materialsmodeling.org/theory.html#damped-harmonic-oscillator-model>_
.
- dynasor.tools.damped_harmonic_oscillator.psd_position_dho(w, w0, gamma, A=1.0)[source]#
The power spectral density (PSD) function for the damped harmonic oscillator (DHO) (i.e., the Fourier transform of the autocorrelation function) for the position.
The definition of this function can be found in the
dynasor documentation <dynasor.materialsmodeling.org/theory.html#damped-harmonic-oscillator-model>_
.
- dynasor.tools.damped_harmonic_oscillator.psd_velocity_dho(w, w0, gamma, A=1.0)[source]#
The power spectral density (PSD) function for the damped harmonic oscillator (DHO) (i.e., the Fourier transform of the autocorrelation function) for the position.
The definition of this function can be found in the
dynasor documentation <dynasor.materialsmodeling.org/theory.html#damped-harmonic-oscillator-model>_
.
- dynasor.tools.structures.align_structure(atoms, atol=1e-05)[source]#
Rotates and realigns a structure such that * the first cell vector points along the x-directon * the second cell vector lies in the xy-plane
Note that this function modifies the
atoms
object in place.- Parameters:
atoms (
Atoms
) – Input structure to be rotated aligned with the x,y,z coordinte system.atol (
float
) – Absolute tolerance used for sanity checking the cell.
- dynasor.tools.structures.find_permutation(atoms, atoms_ref)[source]#
Returns the best permutation of atoms for mapping one configuration onto another.
- Parameters:
atoms – Configuration to be permuted.
atoms_ref – Configuration onto which to map.
Examples
After obtaining the permutation via
p = find_permutation(atoms1, atoms2)
the reordered structureatoms1[p]
will give the closest match toatoms2
.
- dynasor.tools.structures.get_P_matrix(c, S)[source]#
Returns the P matrix, i.e., the
3x3
integer matrix \(P\) that satisfies$$ P c = S $$
Here, \(c\) is the primitive cell metric and \(S\) is the supercell metric as row vectors. Note that the above condition is equivalent to:
$$ c^T P^T = S^T $$
- dynasor.tools.structures.get_displacements(atoms, atoms_ideal, check_mic=True, cell_tol=0.0001)[source]#
Returns the the smallest possible displacements between a displaced configuration relative to an ideal (reference) configuration.
- Parameters:
atoms (
Atoms
) – Structure with displaced atoms.ideal – Ideal configuration relative to which displacements are computed.
check_mic (
bool
) – Whether to check minimum image convention.cell_tol (
float
) – Cell tolerance; if cell missmatch more than tol value error is raised.
- Return type:
- dynasor.tools.structures.get_displacements_from_u(u, cell, check_mic=True)[source]#
wraps displacements using mic
- dynasor.tools.structures.get_offset_index(primitive, supercell, tol=0.01, wrap=True)[source]#
Returns the basis index and primitive cell offsets for a supercell.
This implementation uses a simple iteration procedure which should be fairly quick. If more stability is needed consider the following approach:
find the P-matrix:
P = ideal.cell @ prim.cell_inv.T
compensate for strain:
P *= len(ideal)/len(prim)/det(P)
generate the reference structure:
ref_atoms = make_supercell(round(P), prim)
find the assignment using
ref_atoms
via the Hungarian algorithm using the mic distances
- Parameters:
primitive (
Atoms
) – Primitive cell.supercell (
Atoms
) – Some ideal repetition of the primitive cell.tol (
float
) – Tolerance length parameter. Increase to allow for slgihtly rattled or strained cells.wrap (
bool
) – It might happen that the ideal cell boundary cuts through a unit cell whose lattice points lie inside the ideal cell. If there is a basis, an atom belonging to this unit cell might get wrapped while another is not. Then the wrapped atom now belongs to a lattice point outside the P matrix so to say. This would result in more lattice points than expected fromN_unit = len(ideal)/len(prim)
.
- Returns:
offsets – The lattice points as integers in
(N, 3)
-array.index – The basis indices as integers in
(N,)
-array.