Skip to content

Commit

Permalink
Merge pull request #63 from matteobecchi/mega_upgrade
Browse files Browse the repository at this point in the history
Removing all version limitations. Dynsight should now work on Python >= 3.10. Thank you @matteobecchi
  • Loading branch information
andrewtarzia authored Feb 14, 2025
2 parents fc6f952 + 4a18026 commit 21cd885
Show file tree
Hide file tree
Showing 19 changed files with 76 additions and 102 deletions.
22 changes: 21 additions & 1 deletion .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,24 @@ on:
jobs:
ruff:
runs-on: ubuntu-22.04
strategy:
matrix:
python-version: ['3.10', '3.13' ]
name: ruff on ${{ matrix.python-version }}
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: "3.10"
python-version: ${{ matrix.python-version }}
cache: "pip"
- run: pip install -e '.[dev]'
- run: ruff check .
mypy:
runs-on: ubuntu-22.04
strategy:
matrix:
python-version: ['3.10', '3.13' ]
name: mypy on ${{ matrix.python-version }}
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
Expand All @@ -28,6 +36,10 @@ jobs:
- run: mypy .
ruff-format:
runs-on: ubuntu-22.04
strategy:
matrix:
python-version: ['3.10', '3.13' ]
name: ruff-format on ${{ matrix.python-version }}
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
Expand All @@ -38,6 +50,10 @@ jobs:
- run: ruff format --check .
pytest:
runs-on: ubuntu-22.04
strategy:
matrix:
python-version: ['3.10', '3.13' ]
name: pytest on ${{ matrix.python-version }}
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
Expand All @@ -48,6 +64,10 @@ jobs:
- run: pytest --cov=src --cov-report term-missing
doctest:
runs-on: ubuntu-22.04
strategy:
matrix:
python-version: ['3.10', '3.13' ]
name: doctest on ${{ matrix.python-version }}
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
Expand Down
6 changes: 3 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ maintainers = [
]

dependencies = [
"numpy < 1.24.0", # Needed right now, to remove in the future
"dscribe >1.2.0, <=1.2.2",
"numpy",
"dscribe",
"tropea-clustering",
"MDAnalysis",
]
# Set by cpctools.
requires-python = "<3.11,>=3.8"
requires-python = ">=3.8"
dynamic = ["version"]
readme = "README.rst"
description = "Simplifies analysis of Molecular Dynamics simulations."
Expand Down
4 changes: 2 additions & 2 deletions src/dynsight/_internal/analysis/entropy.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def compute_data_entropy(
.. testcode:: shannon1-test
:hide:
assert data_entropy == 0.9993954419344714
assert np.isclose(data_entropy, 0.9993954419344714)
"""
counts, _ = np.histogram(
data,
Expand Down Expand Up @@ -108,7 +108,7 @@ def compute_entropy_gain(
.. testcode:: shannon2-test
:hide:
assert entropy_gain == 0.0010065005804883983
assert np.isclose(entropy_gain, 0.0010065005804883983)
"""
if data.shape[0] != labels.shape[0]:
msg = (
Expand Down
11 changes: 6 additions & 5 deletions src/dynsight/_internal/analysis/spatial_average.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,19 @@

if TYPE_CHECKING:
import MDAnalysis
from numpy.typing import NDArray

import ctypes
from multiprocessing import Array, Pool

import numpy as np
from MDAnalysis.analysis.distances import distance_array

array: np.ndarray[float, Any]
array: NDArray[np.float64]


def initworker(
shared_array: np.ndarray[float, Any],
shared_array: NDArray[np.float64],
shape: int,
dtype: tuple[float, Any],
) -> None:
Expand All @@ -27,7 +28,7 @@ def initworker(

def processframe(
args: tuple[MDAnalysis.Universe, MDAnalysis.AtomGroup, float, int, bool],
) -> tuple[int, np.ndarray[float, Any]]:
) -> tuple[int, NDArray[np.float64]]:
universe, selection, cutoff, frame, is_vector = args
universe.trajectory[frame]
distances = distance_array(
Expand Down Expand Up @@ -59,12 +60,12 @@ def processframe(

def spatialaverage(
universe: MDAnalysis.Universe,
descriptor_array: np.ndarray[float, Any],
descriptor_array: NDArray[np.float64],
selection: str,
cutoff: float,
traj_cut: int = 0,
num_processes: int = 4,
) -> np.ndarray[float, Any]:
) -> NDArray[np.float64]:
"""Compute spatially averaged descriptor values over neighboring particles.
This function takes a molecular dynamics (MD) simulation stored in an
Expand Down
13 changes: 8 additions & 5 deletions src/dynsight/_internal/analysis/time_correlations.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,18 @@

from __future__ import annotations

from typing import Any
from typing import TYPE_CHECKING

if TYPE_CHECKING:
from numpy.typing import NDArray

import numpy as np


def self_time_correlation(
data: np.ndarray[float, Any],
data: NDArray[np.float64],
max_delay: int | None = None,
) -> tuple[np.ndarray[float, Any], np.ndarray[float, Any]]:
) -> tuple[NDArray[np.float64], NDArray[np.float64]]:
"""Computes the mean self time correlation function for time-series.
Takes as input an array of shape (n_particles, n_frames), where the
Expand Down Expand Up @@ -92,9 +95,9 @@ def self_time_correlation(


def cross_time_correlation(
data: np.ndarray[float, Any],
data: NDArray[np.float64],
max_delay: int | None = None,
) -> tuple[np.ndarray[float, Any], np.ndarray[float, Any]]:
) -> tuple[NDArray[np.float64], NDArray[np.float64]]:
"""Computes the mean cross time correlation function for time-series.
Takes as input an array of shape (n_particles, n_frames), where the
Expand Down
13 changes: 7 additions & 6 deletions src/dynsight/_internal/lens/lens.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
from __future__ import annotations

from typing import TYPE_CHECKING, Any
from typing import TYPE_CHECKING

if TYPE_CHECKING:
from MDAnalysis import AtomGroup, Universe
from numpy.typing import NDArray

import numpy as np
from MDAnalysis.lib.NeighborSearch import AtomNeighborSearch
Expand Down Expand Up @@ -79,10 +80,10 @@ def list_neighbours_along_trajectory(
def neighbour_change_in_time(
neigh_list_per_frame: list[list[AtomGroup]],
) -> tuple[
np.ndarray[float, Any],
np.ndarray[int, Any],
np.ndarray[float, Any],
np.ndarray[float, Any],
NDArray[np.float64],
NDArray[np.int64],
NDArray[np.float64],
NDArray[np.float64],
]:
"""Return, listed per atom, the LENS values at each frame.
Expand Down Expand Up @@ -143,7 +144,7 @@ def neighbour_change_in_time(
# this is the number of common NN between frames
lensarray = np.zeros((nat, nframes))
# this is the number of NN at that frame
numberofneighs = np.zeros((nat, nframes))
numberofneighs = np.zeros((nat, nframes), dtype=int)
# this is the numerator of LENS
lensnumerators = np.zeros((nat, nframes))
# this is the denominator of lens
Expand Down
7 changes: 4 additions & 3 deletions src/dynsight/_internal/soapify/saponify.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

if TYPE_CHECKING:
import MDAnalysis
from numpy.typing import NDArray

import numpy as np
from ase import Atoms
Expand All @@ -21,7 +22,7 @@ def saponify_trajectory(
soap_respectpbc: bool = True,
n_core: int = 1,
**soapkwargs: Any,
) -> np.ndarray[float, Any]:
) -> NDArray[np.float64]:
"""Calculate the SOAP fingerprints for each atom in a MDA universe.
* Author: Simone Martino
Expand Down Expand Up @@ -108,10 +109,10 @@ def saponify_trajectory(


def fill_soap_vector_from_dscribe(
soapfromdscribe: np.ndarray[float, Any],
soapfromdscribe: NDArray[np.float64],
lmax: int = 8,
nmax: int = 8,
) -> np.ndarray[float, Any]:
) -> NDArray[np.float64]:
"""Return the SOAP power spectrum from dscribe results.
* Author: Matteo Becchi
Expand Down
23 changes: 13 additions & 10 deletions src/dynsight/_internal/timesoap/timesoap.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,17 @@

from __future__ import annotations

from typing import Any
from typing import TYPE_CHECKING

if TYPE_CHECKING:
from numpy.typing import NDArray

import numpy as np


def normalize_soap(
soaptrajectory: np.ndarray[float, Any],
) -> np.ndarray[float, Any]:
soaptrajectory: NDArray[np.float64],
) -> NDArray[np.float64]:
"""Returns the SOAP spectra normalized to unitary length.
Parameters:
Expand Down Expand Up @@ -58,9 +61,9 @@ def normalize_soap(


def soap_distance(
v_1: np.ndarray[float, Any],
v_2: np.ndarray[float, Any],
) -> np.ndarray[float, Any]:
v_1: NDArray[np.float64],
v_2: NDArray[np.float64],
) -> NDArray[np.float64]:
r"""Computes the Kernel SOAP distance between two SOAP spectra.
The SOAP distance is calculated with:
Expand All @@ -86,7 +89,7 @@ def soap_distance(
SOAP spectra.
Returns:
np.ndarray[float, Any] : the SOAP distances between the input spectra.
NDArray[np.float64] : the SOAP distances between the input spectra.
Example:
Expand Down Expand Up @@ -127,9 +130,9 @@ def soap_distance(


def timesoap(
soaptrajectory: np.ndarray[float, Any],
soaptrajectory: NDArray[np.float64],
delay: int = 1,
) -> np.ndarray[float, Any]:
) -> NDArray[np.float64]:
"""Performs the 'timeSOAP' analysis on the given SOAP trajectory.
timeSOAP was developed by Cristina Caurso. See for reference the paper
Expand All @@ -144,7 +147,7 @@ def timesoap(
Default is 1.
Returns:
np.ndarray[float, Any]
NDArray[np.float64]
Values of timesoap of each particle at each frame.
Has shape (n_particles, n_frames - 1).
Expand Down
6 changes: 5 additions & 1 deletion tests/analysis/test_shannon.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,13 @@ def test_output_files(original_wd: Path) -> None: # noqa: ARG001
os.chdir(temp_dir)

# Test the use of the function computing entropy

# This is necessary because of type checking:
data_min = float(np.min(random_data))
data_max = float(np.max(random_data))
data_entropy = dynsight.analysis.compute_data_entropy(
random_data,
data_range=(np.min(random_data), np.max(random_data)),
data_range=(data_min, data_max),
n_bins=20,
)

Expand Down
Binary file added tests/onion/output_multi/2D_trajectory.npy
Binary file not shown.
4 changes: 0 additions & 4 deletions tests/onion/output_multi/final_states.txt

This file was deleted.

2 changes: 0 additions & 2 deletions tests/onion/output_multi/fraction_0.txt

This file was deleted.

Binary file modified tests/onion/output_multi/labels.npy
Binary file not shown.
2 changes: 0 additions & 2 deletions tests/onion/output_multi/number_of_states.txt

This file was deleted.

12 changes: 0 additions & 12 deletions tests/onion/output_uni/final_states.txt

This file was deleted.

2 changes: 0 additions & 2 deletions tests/onion/output_uni/fraction_0.txt

This file was deleted.

2 changes: 0 additions & 2 deletions tests/onion/output_uni/number_of_states.txt

This file was deleted.

Loading

0 comments on commit 21cd885

Please sign in to comment.