From 85d4a2940898e31627b94fa1a20e5cabc5f5b531 Mon Sep 17 00:00:00 2001 From: Dylan Date: Mon, 18 Nov 2024 17:44:30 +0000 Subject: [PATCH] Minor docstring fixes --- dfttoolkit/output.py | 4 ++-- dfttoolkit/utils/math_utils.py | 4 ++-- dfttoolkit/utils/vibrations_utils.py | 32 ++++++++++++---------------- dfttoolkit/vibrations.py | 26 +++++++++++----------- tests/test_output.py | 4 ++-- 5 files changed, 32 insertions(+), 38 deletions(-) diff --git a/dfttoolkit/output.py b/dfttoolkit/output.py index 84797a1..1b49606 100644 --- a/dfttoolkit/output.py +++ b/dfttoolkit/output.py @@ -967,9 +967,9 @@ def get_n_initial_ks_states(self, include_spin_polarised=True) -> int: Parameters ---------- - include_spin_polarised : bool, optional + include_spin_polarised : bool, default=True Whether to include the spin-down states in the count if the calculation is - spin polarised (the default is True). + spin polarised. Returns ------- diff --git a/dfttoolkit/utils/math_utils.py b/dfttoolkit/utils/math_utils.py index 23cad79..c8af90b 100644 --- a/dfttoolkit/utils/math_utils.py +++ b/dfttoolkit/utils/math_utils.py @@ -240,10 +240,10 @@ def get_autocorrelation_function_manual_lag( ---------- signal : 1D npt.NDArray Siganl for which the autocorrelation function should be calculated. - max_lag : Union[None, int], optional + max_lag : Union[None, int] Autocorrelation will be calculated for a range of 0 to max_lag, where max_lag is the largest lag for the calculation of the - autocorrelation function. The default is None. + autocorrelation function Returns ------- diff --git a/dfttoolkit/utils/vibrations_utils.py b/dfttoolkit/utils/vibrations_utils.py index d390138..4df3f58 100644 --- a/dfttoolkit/utils/vibrations_utils.py +++ b/dfttoolkit/utils/vibrations_utils.py @@ -56,6 +56,7 @@ def get_cross_correlation_function( return cross_correlation +# TODO Fix docstrings and types def get_cross_spectrum( signal_0: npt.NDArray, signal_1: npt.NDArray, @@ -83,16 +84,16 @@ def get_cross_spectrum( Second siganl for which the correlation function should be calculated. time_step : float DESCRIPTION. - bootstrapping_blocks : int, optional - DESCRIPTION. The default is 1. - bootstrapping_overlap : int, optional - DESCRIPTION. The default is 0. - zero_padding : int, optional + bootstrapping_blocks : int, default=1 + DESCRIPTION + bootstrapping_overlap : int, default=0 + DESCRIPTION + zero_padding : int, default=0 Pad the cross correlation function with zeros to increase the frequency resolution of the FFT. This also avoids the effect of varying spectral leakage. However, it artificially broadens the resulting cross spectrum and introduces wiggles. - cutoff_at_last_maximum : bool, optional + cutoff_at_last_maximum : bool, default=False Cut off the cross correlation function at the last maximum to hide spectral leakage. @@ -114,7 +115,8 @@ def get_cross_spectrum( signal_length = len(signal_0) block_size = int( np.floor( - signal_length * (1 + bootstrapping_overlap) + signal_length + * (1 + bootstrapping_overlap) / (bootstrapping_blocks + bootstrapping_overlap) ) ) @@ -123,8 +125,7 @@ def get_cross_spectrum( cross_spectrum = [] for block in range(bootstrapping_blocks): - block_start = int(np.ceil(block * block_size / - (1 + bootstrapping_overlap))) + block_start = int(np.ceil(block * block_size / (1 + bootstrapping_overlap))) if block_start < 0: block_start = 0 @@ -204,8 +205,7 @@ def get_cross_spectrum_mem( """ # Calculate the autocorrelation of the time series autocorr = np.correlate(signal_0, signal_1, mode="full") / len(signal_0) - autocorr = autocorr[len(autocorr) // - 2: len(autocorr) // 2 + model_order + 1] + autocorr = autocorr[len(autocorr) // 2 : len(autocorr) // 2 + model_order + 1] # Create a Toeplitz matrix from the autocorrelation function # R = toeplitz(autocorr[:-1]) @@ -309,8 +309,7 @@ def get_line_widths( res = [np.nan, np.nan, np.nan] if use_lorentzian: - res = lorentzian_fit(frequencies, power_spectrum, - filter_maximum=filter_maximum) + res = lorentzian_fit(frequencies, power_spectrum, filter_maximum=filter_maximum) if np.isnan(res[0]): res = get_peak_parameters(frequencies, power_spectrum) @@ -396,8 +395,7 @@ def _get_normal_mode_decomposition_numba( # Loop over atoms and components for i in range(number_of_cell_atoms): for m in range(velocity_components): - projection_sum += velocities[n, - i, m] * eigenvectors[k, i, m] + projection_sum += velocities[n, i, m] * eigenvectors[k, i, m] # Store the result in the projected velocities array velocities_projected[n, k] = projection_sum @@ -408,9 +406,7 @@ def _get_normal_mode_decomposition_numpy( ) -> None: # Use einsum to perform the double summation over cell atoms and time steps - velocities_projected += np.einsum( - 'tij,kij->tk', velocities, eigenvectors.conj() - ) + velocities_projected += np.einsum("tij,kij->tk", velocities, eigenvectors.conj()) # number_of_cell_atoms = velocities.shape[1] # number_of_frequencies = eigenvectors.shape[0] diff --git a/dfttoolkit/vibrations.py b/dfttoolkit/vibrations.py index 0e97387..2fb9b77 100644 --- a/dfttoolkit/vibrations.py +++ b/dfttoolkit/vibrations.py @@ -74,9 +74,9 @@ def get_displacements(self, displacement: float = 0.0025) -> list: Parameters ---------- - displacement : float, optional + displacement : float, default=0.0025 Displacement for finte difference calculation of vibrations in - Angstrom. The default is 0.0025 Angstrom. + Angstrom. Returns ------- @@ -133,9 +133,8 @@ def get_hessian( Parameters ---------- - set_constrained_atoms_zero : bool, optional + set_constrained_atoms_zero : bool, default=False Set elements in Hessian that code for constrained atoms to zero. - The default is False. Returns ------- @@ -185,8 +184,8 @@ def get_symmetrized_hessian(self, hessian=None): Parameters ---------- - hessian : TYPE, optional - DESCRIPTION. The default is None. + hessian : TYPE, default=None + DESCRIPTION Returns ------- @@ -227,13 +226,12 @@ def get_eigenvalues_and_eigenvectors( ---------- hessian : npt.NDArray[np.float64], optional Hessian. The default is None. - only_real : bool, optional + only_real : bool, default=True Returns only real valued eigenfrequencies + eigenmodes (ATTENTION: if you want to also include instable modes, you have to - symmetrize the hessian as provided below). The default is True. - symmetrize_hessian : bool, optional + symmetrize the hessian as provided below). + symmetrize_hessian : bool, default=True Symmetrise the hessian only for this function (no global change). - The default is True. Returns ------- @@ -500,10 +498,10 @@ def get_cross_correlation_function( DESCRIPTION. time_step : float DESCRIPTION. - bootstrapping_blocks : int, optional - DESCRIPTION. The default is 1. - bootstrapping_overlap : int, optional - DESCRIOTION. The default is 0. + bootstrapping_blocks : int, default=1 + DESCRIPTION + bootstrapping_overlap : int, default=0 + DESCRIPTION Returns ------- diff --git a/tests/test_output.py b/tests/test_output.py index 3f20df5..cd73927 100644 --- a/tests/test_output.py +++ b/tests/test_output.py @@ -50,10 +50,10 @@ def test_get_geometry(self): if self._aims_fixture_no in [1, 2, 3, 5, 7, 9]: assert len(geom) == 3 - assert geom.get_is_periodic() == False + assert geom.get_is_periodic() is False else: assert len(geom) == 2 - assert geom.get_is_periodic() == True + assert geom.get_is_periodic() is True # TODO # def test_get_parameters(self):