diff --git a/docs/source/_static/info_plot.png b/docs/source/_static/info_plot.png index 96c9d0af..d21b3840 100644 Binary files a/docs/source/_static/info_plot.png and b/docs/source/_static/info_plot.png differ diff --git a/examples/sample_entropy.py b/examples/sample_entropy.py index d4101217..0efa9746 100644 --- a/examples/sample_entropy.py +++ b/examples/sample_entropy.py @@ -141,7 +141,7 @@ def main() -> None: fractions = [] for _, delta_t in enumerate(delta_t_list): reshaped_data = dynsight.onion.helpers.reshape_from_nt(data, delta_t) - state_list, labels = dynsight.onion.onion_uni(reshaped_data) + _, labels = dynsight.onion.onion_uni(reshaped_data) tmp_list = [] tmp_frac = [] diff --git a/examples/video_to_trajectory.py b/examples/video_to_trajectory.py index 97d0dfaf..7903191e 100644 --- a/examples/video_to_trajectory.py +++ b/examples/video_to_trajectory.py @@ -30,7 +30,7 @@ def plot_results( n_detections = [len(result) for result in instance.prediction_results] - fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(10, 4)) + _, (ax1, ax2) = plt.subplots(1, 2, figsize=(10, 4)) ax1.plot(n_detections, marker="o") ax1.set_title("N° Detections in Time") diff --git a/pyproject.toml b/pyproject.toml index 763cb51f..f5d2ee5d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -91,8 +91,10 @@ convention = "google" "ANN001", "PLR0912", "PLR0915", + "RUF059", ] "docs/source/conf.py" = ["D100", "INP001"] +"docs/source/_static/recipes/*" = ["RUF059"] [tool.mypy] show_error_codes = true diff --git a/src/dynsight/_internal/analysis/entropy.py b/src/dynsight/_internal/analysis/entropy.py index 878a63d9..30790072 100644 --- a/src/dynsight/_internal/analysis/entropy.py +++ b/src/dynsight/_internal/analysis/entropy.py @@ -216,7 +216,7 @@ def compute_shannon_multi( if data.size == 0: msg = "data is empty" raise ValueError(msg) - n_points, n_dims = data.shape + _, n_dims = data.shape if n_dims != len(data_ranges) or n_dims != len(n_bins): msg = "Mismatch between data dimensions, data_ranges, and n_bins" raise ValueError(msg) diff --git a/src/dynsight/_internal/descriptors/misc.py b/src/dynsight/_internal/descriptors/misc.py index b897b38b..aab8ddf8 100644 --- a/src/dynsight/_internal/descriptors/misc.py +++ b/src/dynsight/_internal/descriptors/misc.py @@ -97,7 +97,7 @@ def orientational_order_param( def _compute_aver_align( neigh_list_t: list[AtomGroup], - frame_vel: NDArray[np.float64], + frame_vel: NDArray[np.float64], # shape (n_atoms, n_dim) ) -> NDArray[np.float64]: """Computes the average alignment for all the atoms in a frame.""" phi_t = np.zeros(len(frame_vel)) @@ -114,7 +114,10 @@ def _compute_aver_align( continue # no self-counting, no neighbors with v = 0.0 alignments = np.array( - [1 - cosine(atom_i, frame_vel[j]) for j in valid_neighbors] + [ + 1 - cosine(np.array(atom_i), frame_vel[j]) + for j in valid_neighbors + ] ) phi_t[i] = np.mean(alignments) return phi_t diff --git a/src/dynsight/_internal/lens/lens.py b/src/dynsight/_internal/lens/lens.py index 7aba2acf..987066b6 100644 --- a/src/dynsight/_internal/lens/lens.py +++ b/src/dynsight/_internal/lens/lens.py @@ -108,13 +108,17 @@ def neighbour_change_in_time( Returns: tuple: - lens_array: The calculated LENS parameter. - It's a numpy.array of shape (n_particles, n_frames - 1) + It's a np.array of shape (n_particles, n_frames - delay + 1) - number_of_neighs: The count of neighbors per frame. - It's a numpy.array of shape (n_particles, n_frames) + It's a np.array of shape (n_particles, n_frames) - lens_numerators: The numerators used for calculating LENS. - It's a numpy.array of shape (n_particles, n_frames - 1) + It's a np.array of shape (n_particles, n_frames - delay + 1) - lens_denominators: The denominators used for calculating LENS. - It's a numpy.array of shape (n_particles, n_frames - 1) + It's a np.array of shape (n_particles, n_frames - delay + 1) + + Note: + The first frame of the output array is identically zero. This is due + to compatibility with older code. Example: @@ -151,10 +155,10 @@ def neighbour_change_in_time( n_atoms = np.asarray(neigh_list_per_frame, dtype=object).shape[1] n_frames = np.asarray(neigh_list_per_frame, dtype=object).shape[0] - lens_array = np.zeros((n_atoms, n_frames)) # The LENS values - number_of_neighs = np.zeros((n_atoms, n_frames), dtype=int) # The NN - lens_numerators = np.zeros((n_atoms, n_frames)) # LENS numerator - lens_denominators = np.zeros((n_atoms, n_frames)) # LENS denominator + lens_array = np.zeros((n_atoms, n_frames - delay + 1)) + number_of_neighs = np.zeros((n_atoms, n_frames), dtype=int) + lens_numerators = np.zeros((n_atoms, n_frames - delay + 1)) + lens_denominators = np.zeros((n_atoms, n_frames - delay + 1)) # each nnlist contains also the atom that generates them, # so 0 nn is a 1 element list diff --git a/src/dynsight/_internal/trajectory/cluster_insight.py b/src/dynsight/_internal/trajectory/cluster_insight.py index 94594af8..99c7f6cc 100644 --- a/src/dynsight/_internal/trajectory/cluster_insight.py +++ b/src/dynsight/_internal/trajectory/cluster_insight.py @@ -446,7 +446,7 @@ def dump_colored_trj(self, trj: Trj, file_path: Path) -> None: if self.labels.shape != (n_atoms, n_frames): msg = ( f"Shape mismatch: Trj should have {self.labels.shape[0]} " - f"atoms, {self.labels.shape[0]} frames, but has {n_atoms} " + f"atoms, {self.labels.shape[1]} frames, but has {n_atoms} " f"atoms, {n_frames} frames." ) logger.log(msg) diff --git a/tests/analysis/test_sample_entropy.py b/tests/analysis/test_sample_entropy.py index 65d82c44..efd68a07 100644 --- a/tests/analysis/test_sample_entropy.py +++ b/tests/analysis/test_sample_entropy.py @@ -40,7 +40,7 @@ def test_too_short( def test_too_small_rfact(random_data: NDArray[np.float64]) -> None: """Test that a too small r_factor raises a RuntimeError.""" - with pytest.raises(RuntimeError, match="No matching sequences found."): + with pytest.raises(RuntimeError, match=r"No matching sequences found."): dynsight.analysis.sample_entropy(random_data, r_factor=0.0) diff --git a/tests/trajectory/test_trj.py b/tests/trajectory/test_trj.py index 6522bb2d..5480cbdb 100644 --- a/tests/trajectory/test_trj.py +++ b/tests/trajectory/test_trj.py @@ -161,19 +161,19 @@ def test_onion_analysis(universe: MDAnalysis.Universe) -> None: def test_insight_load_errors(file_paths: dict[str, Path]) -> None: """Test insight load errors.""" with pytest.raises( - ValueError, match="'dataset_file' key not found in JSON file." + ValueError, match=r"'dataset_file' key not found in JSON file." ): _ = Insight.load_from_json(file_paths["files_dir"] / "empty.json") with pytest.raises( - ValueError, match="'labels_file' key not found in JSON file." + ValueError, match=r"'labels_file' key not found in JSON file." ): _ = ClusterInsight.load_from_json( file_paths["files_dir"] / "ins_1_test.json" ) with pytest.raises( - ValueError, match="'reshaped_data_file' key not found in JSON file." + ValueError, match=r"'reshaped_data_file' key not found in JSON file." ): _ = OnionInsight.load_from_json( file_paths["files_dir"] / "cl_ins_test.json"