Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

distopia 0.3.0 compatibility changes #4734

Open
wants to merge 35 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
2ee12e5
start of docs
hmacdope Oct 15, 2024
9bf0cf7
improve distopia stup
hmacdope Oct 15, 2024
f8d1295
add backend conditionals
hmacdope Oct 15, 2024
badc778
fix wrong backend
hmacdope Oct 15, 2024
e97317b
shims
hmacdope Oct 15, 2024
e0ce653
working except for dihedrals
hmacdope Oct 15, 2024
63162df
move to 0.3.0
hmacdope Oct 16, 2024
0ec2057
bump ci
hmacdope Oct 16, 2024
2392101
bump ci
hmacdope Oct 17, 2024
2cb04d2
Update package/MDAnalysis/lib/distances.py
hmacdope Oct 21, 2024
e4b8a10
Merge remote-tracking branch 'upstream/develop' into distopia_0.3.0_c…
hmacdope Oct 21, 2024
517c676
fix versioning
hmacdope Oct 21, 2024
36de301
add version checking
hmacdope Oct 21, 2024
b49b028
remove erroneous triclinic note
hmacdope Oct 21, 2024
d895d99
remove unnesecary import
hmacdope Oct 21, 2024
5733a74
add explanatory notes
hmacdope Oct 21, 2024
36c010a
change tests in line with discussion
hmacdope Oct 21, 2024
763b493
changelog
hmacdope Oct 21, 2024
10356f7
Apply suggestions from code review
hmacdope Oct 23, 2024
3b0024a
add more tests
hmacdope Oct 23, 2024
9c149ec
improve docs
hmacdope Oct 23, 2024
8cae6f8
improve docs again
hmacdope Oct 23, 2024
50efeb9
hmmm
hmacdope Oct 24, 2024
2c070b7
Merge branch 'develop' into distopia_0.3.0_compat
orbeckst Dec 10, 2024
d4b9e9d
add type for calc_bond_distance_ortho()
orbeckst Dec 10, 2024
2621552
just stuff answers back in if we used a buffer
hmacdope Dec 31, 2024
154d389
Merge branch 'distopia_0.3.0_compat' of github.com:hmacdope/mdanalysi…
hmacdope Dec 31, 2024
c75dce2
add cram for distance array also
hmacdope Dec 31, 2024
02a3d93
fix changelogs
hmacdope Dec 31, 2024
07f1438
Merge remote-tracking branch 'upstream/develop' into distopia_0.3.0_c…
hmacdope Jan 2, 2025
9101d81
black
hmacdope Jan 2, 2025
447beac
imporve mock test
hmacdope Jan 2, 2025
0a60016
fix typo
hmacdope Jan 2, 2025
730cee9
add debug printing
hmacdope Jan 2, 2025
a865a46
Merge branch 'develop' into distopia_0.3.0_compat
orbeckst Jan 6, 2025
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
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.3.1'
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
tylerjereddy, 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
114 changes: 91 additions & 23 deletions package/MDAnalysis/lib/_distopia.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,48 +28,53 @@
as a selectable backend.
"""
import warnings
from packaging.version import Version

MIN_DISTOPIA_VERSION = Version("0.3.1")

# 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.3.1,
# some versions of `distopia` don't have a version attribute
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are these versions known? I.e. if we know that this only affects a certain set of releases and they are all <0.3.1, then can we skip the warning altogther and just assume that this only happens in old versions we don't care about?

(intent: I'm trying to completly bypass the follow-up "there are no tests for line 50" with a blunt solution)

try:
distopia_version = Version(distopia.__version__)
except AttributeError:
warnings.warn("distopia version cannot be determined, assuming 0.0.0")
distopia_version = Version("0.0.0")

Check warning on line 50 in package/MDAnalysis/lib/_distopia.py

View check run for this annotation

Codecov / codecov/patch

package/MDAnalysis/lib/_distopia.py#L48-L50

Added lines #L48 - L50 were not covered by tests
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.",
category=RuntimeWarning,
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 (
hmacdope marked this conversation as resolved.
Show resolved Hide resolved
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.calc_bonds_ortho(
hmacdope marked this conversation as resolved.
Show resolved Hide resolved
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.calc_bonds_no_box(
coords1, coords2, results=results
)


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


def calc_angle(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Has @RMeli lint lib? If so, could you run black on this file @hmacdope ?

coords1: np.ndarray, coords2: np.ndarray, coords3: np.ndarray, results: np.ndarray
) -> None:
distopia.calc_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.calc_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.calc_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.calc_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.calc_dihedrals_ortho(coords1, coords2, coords3, coords4, box[:3], results=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.calc_dihedrals_triclinic(coords1, coords2, coords3, coords4, box, results=results)

def calc_distance_array(
coords1: np.ndarray, coords2: np.ndarray, results: np.ndarray
) -> None:
distopia.calc_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.calc_distance_array_ortho(coords1, coords2, box[:3], results=results)

def calc_distance_array_triclinic(
hmacdope marked this conversation as resolved.
Show resolved Hide resolved
coords1: np.ndarray, coords2: np.ndarray, box: np.ndarray, results: np.ndarray
) -> None:
distopia.calc_distance_array_triclinic(coords1, coords2, box, results=results)
hmacdope marked this conversation as resolved.
Show resolved Hide resolved

def calc_self_distance_array(
hmacdope marked this conversation as resolved.
Show resolved Hide resolved
coords: np.ndarray, results: np.ndarray
) -> None:
distopia.calc_self_distance_array_no_box(coords, results=results)
hmacdope marked this conversation as resolved.
Show resolved Hide resolved

def calc_self_distance_array_ortho(
hmacdope marked this conversation as resolved.
Show resolved Hide resolved
coords: np.ndarray, box: np.ndarray, results: np.ndarray
) -> None:
distopia.calc_self_distance_array_ortho(coords, box[:3], results=results)

def calc_self_distance_array_triclinic(
hmacdope marked this conversation as resolved.
Show resolved Hide resolved
coords: np.ndarray, box: np.ndarray, results: np.ndarray
) -> None:
distopia.calc_self_distance_array_triclinic(coords, box, results=results)

Loading
Loading