Skip to content

Commit

Permalink
Added MDAnalysis.lib module
Browse files Browse the repository at this point in the history
lib._distances now has zero error checking wrapper around C math
routines

core.distances is now pure python module which calls lib._distances
  • Loading branch information
richardjgowers committed May 15, 2015
1 parent 9b1f0e9 commit bb7f382
Show file tree
Hide file tree
Showing 11 changed files with 4,516 additions and 10,903 deletions.
585 changes: 585 additions & 0 deletions package/MDAnalysis/core/distances.py

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package/MDAnalysis/core/parallel/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,4 @@
"""

import distances
from . import distances
22 changes: 22 additions & 0 deletions package/MDAnalysis/lib/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# -*- Mode: python; tab-width: 4; indent-tabs-mode:nil; coding:utf-8 -*-
# vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4 fileencoding=utf-8
#
# MDAnalysis --- http://www.MDAnalysis.org
# Copyright (c) 2006-2015 Naveen Michaud-Agrawal, Elizabeth J. Denning, Oliver Beckstein
# and contributors (see AUTHORS for the full list)
#
# Released under the GNU Public Licence, v2 or any higher version
#
# Please cite your use of MDAnalysis in published work:
#
# N. Michaud-Agrawal, E. J. Denning, T. B. Woolf, and O. Beckstein.
# MDAnalysis: A Toolkit for the Analysis of Molecular Dynamics Simulations.
# J. Comput. Chem. 32 (2011), 2319--2327, doi:10.1002/jcc.21787
#


"""
:mod:`MDAnalysis.lib` --- Low level access to math routines
================================================================
"""

Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.. automodule:: MDAnalysis.lib._distances
:members:
15 changes: 15 additions & 0 deletions package/doc/sphinx/source/documentation_pages/lib_modules.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
.. _lib:

************************
MDAnalysis math library
************************

Low level access to MDAnalysis' math functions. These have little to
no error checking done on inputs so should be used with caution.
Versions of these routines with error checking are available in
:module:`~MDAnalysis.core.distances`

.. toctree::
:maxdepth: 1

lib/_distances
1 change: 1 addition & 0 deletions package/doc/sphinx/source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ Contents
./documentation_pages/core_modules
./documentation_pages/KDTree_modules
./documentation_pages/visualization_modules
./documentation_pages/lib_modules



Expand Down
29 changes: 15 additions & 14 deletions package/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ def detect_openmp():
include_dirs=include_dirs + ['src/dcd/include'],
define_macros=define_macros,
extra_compile_args=extra_compile_args),
Extension('core.distances', ['src/numtools/distances.%s' % ("pyx" if use_cython else "c")],
Extension('lib._distances', ['src/numtools/distances.%s' % ("pyx" if use_cython else "c")],
include_dirs=include_dirs + ['src/numtools'],
libraries=['m'],
define_macros=define_macros,
Expand Down Expand Up @@ -268,19 +268,20 @@ def detect_openmp():
provides=['MDAnalysis'],
license='GPL 2',
packages=['MDAnalysis',
'MDAnalysis.core',
'MDAnalysis.core.parallel',
'MDAnalysis.topology',
'MDAnalysis.topology.tpr',
'MDAnalysis.selections',
'MDAnalysis.coordinates',
'MDAnalysis.coordinates.xdrfile',
'MDAnalysis.coordinates.pdb',
'MDAnalysis.KDTree',
'MDAnalysis.analysis',
'MDAnalysis.analysis.hbonds',
'MDAnalysis.tests',
'MDAnalysis.visualization'],
'MDAnalysis.analysis',
'MDAnalysis.analysis.hbonds',
'MDAnalysis.coordinates',
'MDAnalysis.coordinates.xdrfile',
'MDAnalysis.coordinates.pdb',
'MDAnalysis.core',
'MDAnalysis.core.parallel',
'MDAnalysis.KDTree',
'MDAnalysis.lib',
'MDAnalysis.selections',
'MDAnalysis.topology',
'MDAnalysis.topology.tpr',
'MDAnalysis.tests',
'MDAnalysis.visualization'],
package_dir={'MDAnalysis': 'MDAnalysis'},
ext_package='MDAnalysis',
ext_modules=extensions,
Expand Down
97 changes: 63 additions & 34 deletions package/src/numtools/calc_distances.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ static void minimum_image(double *x, float *box, float *inverse_box)
}
}
}

static void minimum_image_triclinic(double *dx, coordinate* box, float* box_half)
{
// Minimum image convention for triclinic systems, modelled after domain.cpp in LAMMPS
Expand Down Expand Up @@ -73,7 +74,9 @@ static void minimum_image_triclinic(double *dx, coordinate* box, float* box_half
}
}
}
static void calc_distance_array(coordinate* ref, int numref, coordinate* conf, int numconf, float* box, double* distances)

static void _calc_distance_array_ortho(coordinate* ref, int numref, coordinate* conf,
int numconf, float* box, double* distances)
{
int i, j;
double dx[3];
Expand All @@ -97,7 +100,8 @@ static void calc_distance_array(coordinate* ref, int numref, coordinate* conf, i
}
}

static void calc_distance_array_noPBC(coordinate* ref, int numref, coordinate* conf, int numconf, double* distances)
static void _calc_distance_array(coordinate* ref, int numref, coordinate* conf,
int numconf, double* distances)
{
int i, j;
double dx[3];
Expand All @@ -114,8 +118,8 @@ static void calc_distance_array_noPBC(coordinate* ref, int numref, coordinate* c
}
}


static void calc_self_distance_array(coordinate* ref, int numref, float* box, double* distances, int distnum)
static void _calc_self_distance_array_ortho(coordinate* ref, int numref, float* box,
double* distances, int distnum)
{
int i, j, distpos;
double dx[3];
Expand All @@ -142,7 +146,8 @@ static void calc_self_distance_array(coordinate* ref, int numref, float* box, do
}


static void calc_self_distance_array_noPBC(coordinate* ref, int numref, double* distances, int distnum)
static void _calc_self_distance_array(coordinate* ref, int numref, double* distances,
int distnum)
{
int i, j, distpos;
double dx[3];
Expand All @@ -161,7 +166,7 @@ static void calc_self_distance_array_noPBC(coordinate* ref, int numref, double*
}
}

static void coord_transform(coordinate* coords, int numCoords, coordinate* box)
static void _coord_transform(coordinate* coords, int numCoords, coordinate* box)
{
int i, j, k;
float new[3];
Expand All @@ -182,7 +187,8 @@ static void coord_transform(coordinate* coords, int numCoords, coordinate* box)
coords[i][2] = new[2];
}
}
static void ortho_pbc(coordinate* coords, int numcoords, float* box, float* box_inverse){

static void _ortho_pbc(coordinate* coords, int numcoords, float* box, float* box_inverse){
int i, s[3];
// Moves all coordinates to within the box boundaries for a orthogonal box
for (i=0; i < numcoords; i++){
Expand All @@ -194,7 +200,8 @@ static void ortho_pbc(coordinate* coords, int numcoords, float* box, float* box_
coords[i][2] -= s[2] * box[2];
}
}
static void triclinic_pbc(coordinate* coords, int numcoords, coordinate* box, float* box_inverse){

static void _triclinic_pbc(coordinate* coords, int numcoords, coordinate* box, float* box_inverse){
int i, s;
// Moves all coordinates to within the box boundaries for a triclinic box
// Assumes box having zero values for box[0][1], box[0][2] and box [1][2]
Expand All @@ -213,7 +220,10 @@ static void triclinic_pbc(coordinate* coords, int numcoords, coordinate* box, fl
coords[i][0] -= s * box[0][0];
}
}
static void calc_distance_array_triclinic(coordinate* ref, int numref, coordinate* conf, int numconf, coordinate* box, double* distances)

static void _calc_distance_array_triclinic(coordinate* ref, int numref,
coordinate* conf, int numconf,
coordinate* box, double* distances)
{
int i, j;
double dx[3];
Expand All @@ -228,8 +238,8 @@ static void calc_distance_array_triclinic(coordinate* ref, int numref, coordinat
box_inverse[1] = 1.0 / box[1][1];
box_inverse[2] = 1.0 / box[2][2];
// Move coords to inside box
triclinic_pbc(ref, numref, box, box_inverse);
triclinic_pbc(conf, numconf, box, box_inverse);
_triclinic_pbc(ref, numref, box, box_inverse);
_triclinic_pbc(conf, numconf, box, box_inverse);

for (i=0; i < numref; i++){
for (j=0; j < numconf; j++){
Expand All @@ -242,7 +252,10 @@ static void calc_distance_array_triclinic(coordinate* ref, int numref, coordinat
}
}
}
static void calc_self_distance_array_triclinic(coordinate* ref, int numref, coordinate* box, double *distances, int distnum)

static void _calc_self_distance_array_triclinic(coordinate* ref, int numref,
coordinate* box, double *distances,
int distnum)
{
int i, j, distpos;
double dx[3];
Expand All @@ -257,7 +270,7 @@ static void calc_self_distance_array_triclinic(coordinate* ref, int numref, coor
box_inverse[1] = 1.0 / box[1][1];
box_inverse[2] = 1.0 / box[2][2];

triclinic_pbc(ref, numref, box, box_inverse);
_triclinic_pbc(ref, numref, box, box_inverse);

distpos = 0;
for (i=0; i < numref; i++){
Expand All @@ -273,7 +286,8 @@ static void calc_self_distance_array_triclinic(coordinate* ref, int numref, coor
}
}

static void calc_bond_distance(coordinate* atom1, coordinate* atom2, int numatom, float* box, double* distances)
static void _calc_bond_distance_ortho(coordinate* atom1, coordinate* atom2,
int numatom, float* box, double* distances)
{
int i;
double dx[3];
Expand All @@ -294,7 +308,9 @@ static void calc_bond_distance(coordinate* atom1, coordinate* atom2, int numatom
*(distances+i) = sqrt(rsq);
}
}
static void calc_bond_distance_triclinic(coordinate* atom1, coordinate* atom2, int numatom, coordinate* box, double* distances)
static void _calc_bond_distance_triclinic(coordinate* atom1, coordinate* atom2,
int numatom, coordinate* box,
double* distances)
{
int i;
double dx[3];
Expand All @@ -309,8 +325,8 @@ static void calc_bond_distance_triclinic(coordinate* atom1, coordinate* atom2, i
box_inverse[1] = 1.0/box[1][1];
box_inverse[2] = 1.0/box[2][2];

triclinic_pbc(atom1, numatom, box, box_inverse);
triclinic_pbc(atom2, numatom, box, box_inverse);
_triclinic_pbc(atom1, numatom, box, box_inverse);
_triclinic_pbc(atom2, numatom, box, box_inverse);

for (i=0; i<numatom; i++) {
dx[0] = atom1[i][0] - atom2[i][0];
Expand All @@ -322,7 +338,9 @@ static void calc_bond_distance_triclinic(coordinate* atom1, coordinate* atom2, i
*(distances+i) = sqrt(rsq);
}
}
static void calc_bond_distance_noPBC(coordinate* atom1, coordinate* atom2, int numatom, double* distances)

static void _calc_bond_distance(coordinate* atom1, coordinate* atom2,
int numatom, double* distances)
{
int i;
double dx[3];
Expand All @@ -337,7 +355,8 @@ static void calc_bond_distance_noPBC(coordinate* atom1, coordinate* atom2, int n
}
}

static void calc_angle(coordinate* atom1, coordinate* atom2, coordinate* atom3, int numatom, double* angles)
static void _calc_angle(coordinate* atom1, coordinate* atom2,
coordinate* atom3, int numatom, double* angles)
{
int i;
double rji[3], rjk[3];
Expand All @@ -364,7 +383,9 @@ static void calc_angle(coordinate* atom1, coordinate* atom2, coordinate* atom3,
}
}

static void calc_angle_ortho(coordinate* atom1, coordinate* atom2, coordinate* atom3, int numatom, float* box, double* angles)
static void _calc_angle_ortho(coordinate* atom1, coordinate* atom2,
coordinate* atom3, int numatom,
float* box, double* angles)
{
// Angle is calculated between two vectors
// pbc option ensures that vectors are constructed between atoms in the same image as eachother
Expand Down Expand Up @@ -401,7 +422,10 @@ static void calc_angle_ortho(coordinate* atom1, coordinate* atom2, coordinate* a
*(angles+i) = atan2(y,x);
}
}
static void calc_angle_triclinic(coordinate* atom1, coordinate* atom2, coordinate* atom3, int numatom, coordinate* box, double* angles)

static void _calc_angle_triclinic(coordinate* atom1, coordinate* atom2,
coordinate* atom3, int numatom,
coordinate* box, double* angles)
{
// Triclinic version of min image aware angle calculate, see above
int i;
Expand All @@ -417,9 +441,9 @@ static void calc_angle_triclinic(coordinate* atom1, coordinate* atom2, coordinat
box_inverse[1] = 1.0/box[1][1];
box_inverse[2] = 1.0/box[2][2];

triclinic_pbc(atom1, numatom, box, box_inverse);
triclinic_pbc(atom2, numatom, box, box_inverse);
triclinic_pbc(atom3, numatom, box, box_inverse);
_triclinic_pbc(atom1, numatom, box, box_inverse);
_triclinic_pbc(atom2, numatom, box, box_inverse);
_triclinic_pbc(atom3, numatom, box, box_inverse);

for (i=0; i<numatom; i++) {
rji[0] = atom1[i][0] - atom2[i][0];
Expand All @@ -444,8 +468,9 @@ static void calc_angle_triclinic(coordinate* atom1, coordinate* atom2, coordinat
}
}

static void calc_torsion(coordinate* atom1, coordinate* atom2, coordinate* atom3, coordinate* atom4,
int numatom, double* angles)
static void _calc_torsion(coordinate* atom1, coordinate* atom2,
coordinate* atom3, coordinate* atom4,
int numatom, double* angles)
{
int i;
double va[3], vb[3], vc[3];
Expand Down Expand Up @@ -490,8 +515,10 @@ static void calc_torsion(coordinate* atom1, coordinate* atom2, coordinate* atom3
*(angles + i) = atan2(y,x); //atan2 is better conditioned than acos
}
}
static void calc_torsion_ortho(coordinate* atom1, coordinate* atom2, coordinate* atom3, coordinate* atom4,
int numatom, float* box, double* angles)

static void _calc_torsion_ortho(coordinate* atom1, coordinate* atom2,
coordinate* atom3, coordinate* atom4,
int numatom, float* box, double* angles)
{
int i;
double va[3], vb[3], vc[3];
Expand Down Expand Up @@ -544,8 +571,10 @@ static void calc_torsion_ortho(coordinate* atom1, coordinate* atom2, coordinate*
*(angles + i) = atan2(y,x); //atan2 is better conditioned than acos
}
}
static void calc_torsion_triclinic(coordinate* atom1, coordinate* atom2, coordinate* atom3, coordinate* atom4,
int numatom, coordinate* box, double* angles)

static void _calc_torsion_triclinic(coordinate* atom1, coordinate* atom2,
coordinate* atom3, coordinate* atom4,
int numatom, coordinate* box, double* angles)
{
int i;
double va[3], vb[3], vc[3];
Expand All @@ -562,10 +591,10 @@ static void calc_torsion_triclinic(coordinate* atom1, coordinate* atom2, coordin
box_inverse[1] = 1.0/box[1][1];
box_inverse[2] = 1.0/box[2][2];

triclinic_pbc(atom1, numatom, box, box_inverse);
triclinic_pbc(atom2, numatom, box, box_inverse);
triclinic_pbc(atom3, numatom, box, box_inverse);
triclinic_pbc(atom4, numatom, box, box_inverse);
_triclinic_pbc(atom1, numatom, box, box_inverse);
_triclinic_pbc(atom2, numatom, box, box_inverse);
_triclinic_pbc(atom3, numatom, box, box_inverse);
_triclinic_pbc(atom4, numatom, box, box_inverse);

for (i=0; i<numatom; i++) {
// connecting vectors between all 4 atoms: 1 -va-> 2 -vb-> 3 -vc-> 4
Expand Down
Loading

0 comments on commit bb7f382

Please sign in to comment.