Skip to content

Commit

Permalink
distopia 0.4.0 compatibility changes (#4734)
Browse files Browse the repository at this point in the history
* start of docs

* improve distopia stup

* add backend conditionals

* fix wrong backend

* shims

* working except for dihedrals

* move to 0.3.0

* bump ci

* bump ci

* Update package/MDAnalysis/lib/distances.py

Co-authored-by: Oliver Beckstein <[email protected]>

* fix versioning

* add version checking

* remove erroneous triclinic note

* remove unnesecary import

* add explanatory notes

* change tests in line with discussion

* changelog

* Apply suggestions from code review

Co-authored-by: Oliver Beckstein <[email protected]>

* add more tests

* improve docs

* improve docs again

* hmmm

* add type for calc_bond_distance_ortho()

* just stuff answers back in if we used a buffer

* add cram for distance array also

* fix changelogs

* black

* imporve mock test

* fix typo

* add debug printing

* add explanatory comment on use of serial backend comparison

* add testing

* black

* fix typo

* fix test

* fix dih

* black

* fix dihedrals

* fix reference values

* change function names for 0.4.0

* black

* fix typo

* fix wrong versions

---------

Co-authored-by: Oliver Beckstein <[email protected]>
  • Loading branch information
hmacdope and orbeckst authored Feb 10, 2025
1 parent 084b8cc commit b79c77d
Show file tree
Hide file tree
Showing 5 changed files with 377 additions and 119 deletions.
2 changes: 1 addition & 1 deletion .github/actions/setup-deps/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ inputs:
dask:
default: 'dask'
distopia:
default: 'distopia>=0.2.0,<0.3.0'
default: 'distopia>=0.4.0'
h5py:
default: 'h5py>=2.10'
hole2:
Expand Down
6 changes: 4 additions & 2 deletions package/CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ The rules for this file:

-------------------------------------------------------------------------------
??/??/?? IAlibay, ChiahsinChu, RMeli, tanishy7777, talagayev, tylerjereddy,
marinegor
marinegor, hmacdope

* 2.9.0

Expand All @@ -27,12 +27,14 @@ Fixes
the function to prevent shared state. (Issue #4655)

Enhancements
* Improve distopia backend support in line with new functionality available
in distopia >= 0.3.1 (PR #4734)
* Addition of 'water' token for water selection (Issue #4839)
* Enables parallelization for analysis.density.DensityAnalysis (Issue #4677, PR #4729)
* Enables parallelization for analysis.contacts.Contacts (Issue #4660)
* Enable parallelization for analysis.nucleicacids.NucPairDist (Issue #4670)
* Add check and warning for empty (all zero) coordinates in RDKit converter (PR #4824)
* Added `precision` for XYZWriter (Issue #4775, PR #4771)
* Added `precision` for XYZWriter (Issue #4775, PR #4771)


Changes
Expand Down
149 changes: 128 additions & 21 deletions package/MDAnalysis/lib/_distopia.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,48 +28,51 @@
as a selectable backend.
"""
import warnings
from packaging.version import Version

MIN_DISTOPIA_VERSION = Version("0.4.0")

# check for distopia
try:
import distopia
except ImportError:
HAS_DISTOPIA = False
distopia_version = Version("0.0.0")
else:
HAS_DISTOPIA = True

# check for compatibility: currently needs to be >=0.2.0,<0.3.0 (issue
# #4740) No distopia.__version__ available so we have to do some probing.
needed_funcs = ["calc_bonds_no_box_float", "calc_bonds_ortho_float"]
has_distopia_020 = all([hasattr(distopia, func) for func in needed_funcs])
if not has_distopia_020:
# check for compatibility: currently needs to be >=0.4.0,
# some versions of `distopia` don't have a version attribute
try:
distopia_version = Version(distopia.__version__)
except AttributeError:
distopia_version = Version("0.0.0")
if distopia_version < MIN_DISTOPIA_VERSION:
warnings.warn(
"Install 'distopia>=0.2.0,<0.3.0' to be used with this "
"release of MDAnalysis. Your installed version of "
"distopia >=0.3.0 will NOT be used.",
f"distopia version {distopia_version} is too old; "
f"need at least {MIN_DISTOPIA_VERSION}, Your installed version of "
"distopia will NOT be used.",
category=RuntimeWarning,
)
del distopia
HAS_DISTOPIA = False


from .c_distances import (
calc_bond_distance_triclinic as _calc_bond_distance_triclinic_serial,
)
import numpy as np


def calc_bond_distance_ortho(
coords1, coords2: np.ndarray, box: np.ndarray, results: np.ndarray
coords1: np.ndarray,
coords2: np.ndarray,
box: np.ndarray,
results: np.ndarray,
) -> None:
distopia.calc_bonds_ortho_float(coords1, coords2, box[:3], results=results)
# upcast is currently required, change for 3.0, see #3927
distopia.distances_ortho(coords1, coords2, box[:3], results=results)


def calc_bond_distance(
coords1: np.ndarray, coords2: np.ndarray, results: np.ndarray
) -> None:
distopia.calc_bonds_no_box_float(coords1, coords2, results=results)
# upcast is currently required, change for 3.0, see #3927
distopia.distances_no_box(coords1, coords2, results=results)


def calc_bond_distance_triclinic(
Expand All @@ -78,8 +81,112 @@ def calc_bond_distance_triclinic(
box: np.ndarray,
results: np.ndarray,
) -> None:
# redirect to serial backend
warnings.warn(
"distopia does not support triclinic boxes, using serial backend instead."
distopia.distances_triclinic(coords1, coords2, box, results=results)


def calc_angle(
coords1: np.ndarray,
coords2: np.ndarray,
coords3: np.ndarray,
results: np.ndarray,
) -> None:
distopia.angles_no_box(coords1, coords2, coords3, results=results)


def calc_angle_ortho(
coords1: np.ndarray,
coords2: np.ndarray,
coords3: np.ndarray,
box: np.ndarray,
results: np.ndarray,
) -> None:
distopia.angles_ortho(coords1, coords2, coords3, box[:3], results=results)


def calc_angle_triclinic(
coords1: np.ndarray,
coords2: np.ndarray,
coords3: np.ndarray,
box: np.ndarray,
results: np.ndarray,
) -> None:

distopia.angles_triclinic(coords1, coords2, coords3, box, results=results)


def calc_dihedral(
coords1: np.ndarray,
coords2: np.ndarray,
coords3: np.ndarray,
coords4: np.ndarray,
results: np.ndarray,
) -> None:
distopia.dihedrals_no_box(
coords1, coords2, coords3, coords4, results=results
)


def calc_dihedral_ortho(
coords1: np.ndarray,
coords2: np.ndarray,
coords3: np.ndarray,
coords4: np.ndarray,
box: np.ndarray,
results: np.ndarray,
) -> None:
distopia.dihedrals_ortho(
coords1, coords2, coords3, coords4, box[:3], results=results
)
_calc_bond_distance_triclinic_serial(coords1, coords2, box, results)


def calc_dihedral_triclinic(
coords1: np.ndarray,
coords2: np.ndarray,
coords3: np.ndarray,
coords4: np.ndarray,
box: np.ndarray,
results: np.ndarray,
) -> None:
distopia.dihedrals_triclinic(
coords1, coords2, coords3, coords4, box, results=results
)


def calc_distance_array(
coords1: np.ndarray, coords2: np.ndarray, results: np.ndarray
) -> None:
distopia.distance_array_no_box(coords1, coords2, results=results)


def calc_distance_array_ortho(
coords1: np.ndarray,
coords2: np.ndarray,
box: np.ndarray,
results: np.ndarray,
) -> None:
distopia.distance_array_ortho(coords1, coords2, box[:3], results=results)


def calc_distance_array_triclinic(
coords1: np.ndarray,
coords2: np.ndarray,
box: np.ndarray,
results: np.ndarray,
) -> None:
distopia.distance_array_triclinic(coords1, coords2, box, results=results)


def calc_self_distance_array(coords: np.ndarray, results: np.ndarray) -> None:
distopia.self_distance_array_no_box(coords, results=results)


def calc_self_distance_array_ortho(
coords: np.ndarray, box: np.ndarray, results: np.ndarray
) -> None:
distopia.self_distance_array_ortho(coords, box[:3], results=results)


def calc_self_distance_array_triclinic(
coords: np.ndarray, box: np.ndarray, results: np.ndarray
) -> None:
distopia.self_distance_array_triclinic(coords, box, results=results)
Loading

0 comments on commit b79c77d

Please sign in to comment.