Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified docs/source/_static/info_plot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion examples/sample_entropy.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []
Expand Down
2 changes: 1 addition & 1 deletion examples/video_to_trajectory.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
2 changes: 2 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/dynsight/_internal/analysis/entropy.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
7 changes: 5 additions & 2 deletions src/dynsight/_internal/descriptors/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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
Expand Down
20 changes: 12 additions & 8 deletions src/dynsight/_internal/lens/lens.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/dynsight/_internal/trajectory/cluster_insight.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion tests/analysis/test_sample_entropy.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)


Expand Down
6 changes: 3 additions & 3 deletions tests/trajectory/test_trj.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down