From f4005db383f3f4c446433fb32156236f29f251ba Mon Sep 17 00:00:00 2001 From: Hugo MacDermott-Opeskin Date: Sat, 11 Nov 2023 23:15:48 +1000 Subject: [PATCH] Expose C distance backend in libmdanalysis.pxd (#4342) * expose C distance backend in libmdanalysis.pxd * changelog * add to modules list --- package/CHANGELOG | 2 ++ package/MDAnalysis/lib/c_distances.pxd | 29 +++++++++++++++++++ package/MDAnalysis/lib/c_distances.pyx | 26 ----------------- .../MDAnalysis/lib/libmdanalysis/__init__.pxd | 1 + .../documentation_pages/lib_modules.rst | 3 ++ 5 files changed, 35 insertions(+), 26 deletions(-) create mode 100644 package/MDAnalysis/lib/c_distances.pxd diff --git a/package/CHANGELOG b/package/CHANGELOG index 1cc96ddea05..eddb1fb8eac 100644 --- a/package/CHANGELOG +++ b/package/CHANGELOG @@ -30,6 +30,8 @@ Fixes * Fix atom charge reading in PDBQT parser (Issue #4282, PR #4283) Enhancements + * Refactor c_distances backend to have a cython .pxd header and expose in + libmdanalysis (Issue #4315, PR #4324) * Add faster nucleic acid Major and Minor pair distance calculators using AnalysisBase for updated nucleicacids module (Issue #3720, PR #3735) * Adds external sidebar links (Issue #4296) diff --git a/package/MDAnalysis/lib/c_distances.pxd b/package/MDAnalysis/lib/c_distances.pxd new file mode 100644 index 00000000000..cb5aa7915ad --- /dev/null +++ b/package/MDAnalysis/lib/c_distances.pxd @@ -0,0 +1,29 @@ +from libc.stdint cimport uint64_t, UINT64_MAX + + +cdef extern from "string.h": + void* memcpy(void* dst, void* src, int len) + +cdef extern from "calc_distances.h": + ctypedef float coordinate[3] + cdef bint USED_OPENMP + void _calc_distance_array(coordinate* ref, uint64_t numref, coordinate* conf, uint64_t numconf, double* distances) + void _calc_distance_array_ortho(coordinate* ref, uint64_t numref, coordinate* conf, uint64_t numconf, float* box, double* distances) + void _calc_distance_array_triclinic(coordinate* ref, uint64_t numref, coordinate* conf, uint64_t numconf, float* box, double* distances) + void _calc_self_distance_array(coordinate* ref, uint64_t numref, double* distances) + void _calc_self_distance_array_ortho(coordinate* ref, uint64_t numref, float* box, double* distances) + void _calc_self_distance_array_triclinic(coordinate* ref, uint64_t numref, float* box, double* distances) + void _coord_transform(coordinate* coords, uint64_t numCoords, double* box) + void _calc_bond_distance(coordinate* atom1, coordinate* atom2, uint64_t numatom, double* distances) + void _calc_bond_distance_ortho(coordinate* atom1, coordinate* atom2, uint64_t numatom, float* box, double* distances) + void _calc_bond_distance_triclinic(coordinate* atom1, coordinate* atom2, uint64_t numatom, float* box, double* distances) + void _calc_angle(coordinate* atom1, coordinate* atom2, coordinate* atom3, uint64_t numatom, double* angles) + void _calc_angle_ortho(coordinate* atom1, coordinate* atom2, coordinate* atom3, uint64_t numatom, float* box, double* angles) + void _calc_angle_triclinic(coordinate* atom1, coordinate* atom2, coordinate* atom3, uint64_t numatom, float* box, double* angles) + void _calc_dihedral(coordinate* atom1, coordinate* atom2, coordinate* atom3, coordinate* atom4, uint64_t numatom, double* angles) + void _calc_dihedral_ortho(coordinate* atom1, coordinate* atom2, coordinate* atom3, coordinate* atom4, uint64_t numatom, float* box, double* angles) + void _calc_dihedral_triclinic(coordinate* atom1, coordinate* atom2, coordinate* atom3, coordinate* atom4, uint64_t numatom, float* box, double* angles) + void _ortho_pbc(coordinate* coords, uint64_t numcoords, float* box) + void _triclinic_pbc(coordinate* coords, uint64_t numcoords, float* box) + void minimum_image(double* x, float* box, float* inverse_box) + void minimum_image_triclinic(float* x, float* box, float* inverse_box) \ No newline at end of file diff --git a/package/MDAnalysis/lib/c_distances.pyx b/package/MDAnalysis/lib/c_distances.pyx index 0bff9e2c531..c4e33ae263a 100644 --- a/package/MDAnalysis/lib/c_distances.pyx +++ b/package/MDAnalysis/lib/c_distances.pyx @@ -41,32 +41,6 @@ from libc.float cimport FLT_MAX, DBL_MAX # make UINT64_MAX visible at the python layer _UINT64_MAX = UINT64_MAX -cdef extern from "string.h": - void* memcpy(void* dst, void* src, int len) - -cdef extern from "calc_distances.h": - ctypedef float coordinate[3] - cdef bint USED_OPENMP - void _calc_distance_array(coordinate* ref, uint64_t numref, coordinate* conf, uint64_t numconf, double* distances) - void _calc_distance_array_ortho(coordinate* ref, uint64_t numref, coordinate* conf, uint64_t numconf, float* box, double* distances) - void _calc_distance_array_triclinic(coordinate* ref, uint64_t numref, coordinate* conf, uint64_t numconf, float* box, double* distances) - void _calc_self_distance_array(coordinate* ref, uint64_t numref, double* distances) - void _calc_self_distance_array_ortho(coordinate* ref, uint64_t numref, float* box, double* distances) - void _calc_self_distance_array_triclinic(coordinate* ref, uint64_t numref, float* box, double* distances) - void _coord_transform(coordinate* coords, uint64_t numCoords, double* box) - void _calc_bond_distance(coordinate* atom1, coordinate* atom2, uint64_t numatom, double* distances) - void _calc_bond_distance_ortho(coordinate* atom1, coordinate* atom2, uint64_t numatom, float* box, double* distances) - void _calc_bond_distance_triclinic(coordinate* atom1, coordinate* atom2, uint64_t numatom, float* box, double* distances) - void _calc_angle(coordinate* atom1, coordinate* atom2, coordinate* atom3, uint64_t numatom, double* angles) - void _calc_angle_ortho(coordinate* atom1, coordinate* atom2, coordinate* atom3, uint64_t numatom, float* box, double* angles) - void _calc_angle_triclinic(coordinate* atom1, coordinate* atom2, coordinate* atom3, uint64_t numatom, float* box, double* angles) - void _calc_dihedral(coordinate* atom1, coordinate* atom2, coordinate* atom3, coordinate* atom4, uint64_t numatom, double* angles) - void _calc_dihedral_ortho(coordinate* atom1, coordinate* atom2, coordinate* atom3, coordinate* atom4, uint64_t numatom, float* box, double* angles) - void _calc_dihedral_triclinic(coordinate* atom1, coordinate* atom2, coordinate* atom3, coordinate* atom4, uint64_t numatom, float* box, double* angles) - void _ortho_pbc(coordinate* coords, uint64_t numcoords, float* box) - void _triclinic_pbc(coordinate* coords, uint64_t numcoords, float* box) - void minimum_image(double* x, float* box, float* inverse_box) - void minimum_image_triclinic(float* x, float* box, float* inverse_box) OPENMP_ENABLED = True if USED_OPENMP else False diff --git a/package/MDAnalysis/lib/libmdanalysis/__init__.pxd b/package/MDAnalysis/lib/libmdanalysis/__init__.pxd index 8f24ccac51e..f9a47e519f2 100644 --- a/package/MDAnalysis/lib/libmdanalysis/__init__.pxd +++ b/package/MDAnalysis/lib/libmdanalysis/__init__.pxd @@ -4,3 +4,4 @@ from ..coordinates cimport timestep from .formats cimport libmdaxdr from .formats cimport libdcd +from . cimport c_distances diff --git a/package/doc/sphinx/source/documentation_pages/lib_modules.rst b/package/doc/sphinx/source/documentation_pages/lib_modules.rst index 1b55a968f43..4bc76c8fa10 100644 --- a/package/doc/sphinx/source/documentation_pages/lib_modules.rst +++ b/package/doc/sphinx/source/documentation_pages/lib_modules.rst @@ -103,5 +103,8 @@ For example, imagine we are writing a Cython extension module in Currently modules that are exposed as public Cython headers are: - :mod:`MDAnalysis.coordinates.timestep` +- :mod:`MDAnalysis.lib.formats.libmdaxdr` +- :mod:`MDAnalysis.lib.formats.libdcd` +- :mod:`MDAnalysis.lib.c_distances` For more details consult the source :mod:`MDAnalysis.lib.libmdanalysis.__init__.pxd` \ No newline at end of file