Skip to content

Commit

Permalink
Expose C distance backend in libmdanalysis.pxd (#4342)
Browse files Browse the repository at this point in the history
* expose C distance backend in libmdanalysis.pxd

* changelog

* add to modules list
  • Loading branch information
hmacdope authored Nov 11, 2023
1 parent cfe2516 commit f4005db
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 26 deletions.
2 changes: 2 additions & 0 deletions package/CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
29 changes: 29 additions & 0 deletions package/MDAnalysis/lib/c_distances.pxd
Original file line number Diff line number Diff line change
@@ -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)
26 changes: 0 additions & 26 deletions package/MDAnalysis/lib/c_distances.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions package/MDAnalysis/lib/libmdanalysis/__init__.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
from ..coordinates cimport timestep
from .formats cimport libmdaxdr
from .formats cimport libdcd
from . cimport c_distances
3 changes: 3 additions & 0 deletions package/doc/sphinx/source/documentation_pages/lib_modules.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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`

0 comments on commit f4005db

Please sign in to comment.