Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
101 commits
Select commit Hold shift + click to select a range
c04301a
First commit for gridded method
ayushsuhane Jun 26, 2018
c3e227a
removed the parallel handler to remove hard dependency on omp.h, can …
ayushsuhane Jun 26, 2018
007d47d
added the license header
ayushsuhane Jun 30, 2018
fc61e5e
Added MDAnalysis header file to c_gridsearch.pyx
seb-buch Jul 1, 2018
4b273a9
Corrected C (de)allocation in c_gridsearch.pyx. Should fix memory leak
seb-buch Jul 1, 2018
02b5819
Added Tests for grid search. Added grid in MDAnalysis.lib.__init__
seb-buch Jul 1, 2018
0f35031
Removed pointer to nsgrid structure to avoid need to free it
seb-buch Jul 4, 2018
bdad5e3
Removed abort() from c_gridsearch.pyx
seb-buch Jul 4, 2018
f65e32b
grid allocation moved to FastNS method
seb-buch Jul 7, 2018
ff33b2f
NSResults object added to store results from NS. Started documentation
seb-buch Jul 8, 2018
579fa00
Corrected Memory Leak
seb-buch Jul 8, 2018
0239d14
Added MDAnalysis/lib/c_search.pyx for Grid NS search
ayushsuhane Jun 26, 2018
5e9fe31
removed the parallel handler to remove hard dependency on omp.h, can …
ayushsuhane Jun 26, 2018
97d07fe
Added MDAnalysis header file to c_gridsearch.pyx
seb-buch Jul 1, 2018
a26f437
Corrected C (de)allocation in c_gridsearch.pyx. Should fix memory leak
seb-buch Jul 1, 2018
2855400
Removed pointer to nsgrid structure to avoid need to free it
seb-buch Jul 1, 2018
4d4a415
Removed abort() from c_gridsearch.pyx and grid allocation moved to Fa…
seb-buch Jul 4, 2018
c6339c5
NSResults object added to store results from NS. Started documentation
seb-buch Jul 8, 2018
7f4a176
Memory allocation changed to PyMem to enhance speed in c_gridsearch.pyx
seb-buch Jul 8, 2018
8650509
Unneeded code removed from c_gridsearch.pyx
seb-buch Jul 16, 2018
1a0e150
Module MDAnalysis/lib/c_gridsearch.pyx renamed to nsgrid.pyx
seb-buch Jul 18, 2018
a1e03dd
Tests written for FastNS
seb-buch Jul 18, 2018
8a75a5f
Removed all references to c_gridsearch.pyx/grid module that reappeare…
seb-buch Jul 18, 2018
7b0c56c
remove unused code
kain88-de Jul 21, 2018
3765868
make init_callable twice
kain88-de Jul 21, 2018
f230008
use OK and ERROR as return codes
kain88-de Jul 21, 2018
a738fa9
remove dead code
kain88-de Jul 21, 2018
89f0b89
remove possible memory leak
kain88-de Jul 21, 2018
08de29b
added the capped function, modified the nsgrid to use box, coordinate…
ayushsuhane Jul 27, 2018
9d52ac9
recovering accidently removed augment in setupd during rebase
ayushsuhane Jul 27, 2018
8b8ea74
corrected name in documentation
ayushsuhane Jul 28, 2018
e71b671
minor corrections to remove pylint error
ayushsuhane Jul 28, 2018
a5d1355
Used vectors in place of lists and dict, cleaned code and modified fu…
ayushsuhane Jul 31, 2018
46f9030
removed dict from buffers for speedup and modified tests
ayushsuhane Jul 31, 2018
2c83681
mend
ayushsuhane Jul 31, 2018
b05e243
reverted tests, removed sorting from get_indices, get_distances, modi…
ayushsuhane Aug 1, 2018
4f1e729
minor changes for failing tests
ayushsuhane Aug 1, 2018
7fd1f80
added hack to handle NoPBC, tests to follow
ayushsuhane Aug 1, 2018
57e9d55
conform tests a/c to modifications in API
ayushsuhane Aug 1, 2018
a7264ec
removed python functions, added no pbc handle using python min, max
ayushsuhane Aug 2, 2018
929fbf5
docs unchecked
ayushsuhane Aug 3, 2018
c817b39
returning list for get_indices, checked Docs
ayushsuhane Aug 4, 2018
66d94e5
removed parallel libraries
ayushsuhane Aug 4, 2018
e28c70a
solved contiguous issue, fixed tests, and added checks in API
ayushsuhane Aug 6, 2018
76c81cf
Added self_capped for nsgrid, moved no pbc box handling outside nsgri…
ayushsuhane Aug 6, 2018
e90dfd2
TST: Windows tests now xfail where needed (#2027)
tylerjereddy Aug 6, 2018
2a0b01f
updated CHANGELOG
ayushsuhane Aug 7, 2018
0cde1de
added sebastien to authors
ayushsuhane Aug 7, 2018
b7751d1
merged develop
ayushsuhane Aug 7, 2018
e2c2b56
Merge pull request #2008 from ayushsuhane/cappedgrid
richardjgowers Aug 7, 2018
0f18f48
updated selection.rst to match groups.py docstring
Aug 7, 2018
070fa52
First commit for gridded method
ayushsuhane Jun 26, 2018
e4f94a0
removed the parallel handler to remove hard dependency on omp.h, can …
ayushsuhane Jun 26, 2018
c01327a
added the license header
ayushsuhane Jun 30, 2018
c9b5868
Added MDAnalysis header file to c_gridsearch.pyx
seb-buch Jul 1, 2018
4ed99dc
Corrected C (de)allocation in c_gridsearch.pyx. Should fix memory leak
seb-buch Jul 1, 2018
ca16fea
Added Tests for grid search. Added grid in MDAnalysis.lib.__init__
seb-buch Jul 1, 2018
5fd9009
Removed pointer to nsgrid structure to avoid need to free it
seb-buch Jul 4, 2018
169122a
Removed abort() from c_gridsearch.pyx
seb-buch Jul 4, 2018
064a290
grid allocation moved to FastNS method
seb-buch Jul 7, 2018
9222b5c
NSResults object added to store results from NS. Started documentation
seb-buch Jul 8, 2018
0e8a0c1
Corrected Memory Leak
seb-buch Jul 8, 2018
0ac6fa0
Added MDAnalysis/lib/c_search.pyx for Grid NS search
ayushsuhane Jun 26, 2018
67f1350
removed the parallel handler to remove hard dependency on omp.h, can …
ayushsuhane Jun 26, 2018
13322b8
Added MDAnalysis header file to c_gridsearch.pyx
seb-buch Jul 1, 2018
2dd9df0
Corrected C (de)allocation in c_gridsearch.pyx. Should fix memory leak
seb-buch Jul 1, 2018
fcfd4df
Removed pointer to nsgrid structure to avoid need to free it
seb-buch Jul 1, 2018
1dd614c
Removed abort() from c_gridsearch.pyx and grid allocation moved to Fa…
seb-buch Jul 4, 2018
2a8ddf7
NSResults object added to store results from NS. Started documentation
seb-buch Jul 8, 2018
9136e38
Memory allocation changed to PyMem to enhance speed in c_gridsearch.pyx
seb-buch Jul 8, 2018
9fa49c9
Unneeded code removed from c_gridsearch.pyx
seb-buch Jul 16, 2018
af26835
Module MDAnalysis/lib/c_gridsearch.pyx renamed to nsgrid.pyx
seb-buch Jul 18, 2018
fe97bc9
Tests written for FastNS
seb-buch Jul 18, 2018
63f3df0
Removed all references to c_gridsearch.pyx/grid module that reappeare…
seb-buch Jul 18, 2018
12a525b
remove unused code
kain88-de Jul 21, 2018
077fd04
make init_callable twice
kain88-de Jul 21, 2018
c91527c
use OK and ERROR as return codes
kain88-de Jul 21, 2018
1f56c50
remove dead code
kain88-de Jul 21, 2018
9cb7007
remove possible memory leak
kain88-de Jul 21, 2018
e0afbc0
added the capped function, modified the nsgrid to use box, coordinate…
ayushsuhane Jul 27, 2018
e03549e
recovering accidently removed augment in setupd during rebase
ayushsuhane Jul 27, 2018
186b952
corrected name in documentation
ayushsuhane Jul 28, 2018
dfe2073
minor corrections to remove pylint error
ayushsuhane Jul 28, 2018
8ae1dca
Used vectors in place of lists and dict, cleaned code and modified fu…
ayushsuhane Jul 31, 2018
27c8364
removed dict from buffers for speedup and modified tests
ayushsuhane Jul 31, 2018
8af2c3b
mend
ayushsuhane Jul 31, 2018
31589b5
reverted tests, removed sorting from get_indices, get_distances, modi…
ayushsuhane Aug 1, 2018
feb920b
minor changes for failing tests
ayushsuhane Aug 1, 2018
ca3df79
added hack to handle NoPBC, tests to follow
ayushsuhane Aug 1, 2018
a5eca15
conform tests a/c to modifications in API
ayushsuhane Aug 1, 2018
920f725
removed python functions, added no pbc handle using python min, max
ayushsuhane Aug 2, 2018
af9b99e
docs unchecked
ayushsuhane Aug 3, 2018
c374ebd
returning list for get_indices, checked Docs
ayushsuhane Aug 4, 2018
b7b73b0
removed parallel libraries
ayushsuhane Aug 4, 2018
711d79d
solved contiguous issue, fixed tests, and added checks in API
ayushsuhane Aug 6, 2018
cd8d427
Added self_capped for nsgrid, moved no pbc box handling outside nsgri…
ayushsuhane Aug 6, 2018
505fc60
TST: Windows tests now xfail where needed (#2027)
tylerjereddy Aug 6, 2018
0347de1
updated CHANGELOG
ayushsuhane Aug 7, 2018
4115571
added sebastien to authors
ayushsuhane Aug 7, 2018
818e595
Added coverage of cython extensions when setup.py is called with the …
seb-buch Aug 8, 2018
fcff850
Merge remote-tracking branch 'origin/develop' into issue-443-cythonco…
seb-buch Aug 8, 2018
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
7 changes: 0 additions & 7 deletions .appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,6 @@ max_jobs: 100
cache:
- '%LOCALAPPDATA%\pip\Cache'

matrix:
# FIXME: allow all Windows builds
# to fail for now; remove this
# when we have full Windows compatibility
allow_failures:
- PYTHON_ARCH: 64

image:
- Visual Studio 2015

Expand Down
2 changes: 2 additions & 0 deletions package/.coveragerc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[run]
plugins = Cython.Coverage
8 changes: 7 additions & 1 deletion package/CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,18 @@ The rules for this file:

------------------------------------------------------------------------------
??/??/18 tylerjereddy, richardjgowers, palnabarun, orbeckst, kain88-de, zemanj,
VOD555, davidercruz, jbarnoud, ayushsuhane, hfmull, micaela-matta
VOD555, davidercruz, jbarnoud, ayushsuhane, hfmull, micaela-matta,
sebastien.buchoux

* 0.18.1

Enhancements

* Added a wrapper of lib.nsgrid in lib.distances.self_capped_distance
and lib.distances.capped_distanceto automatically chose the fastest
method for distance based calculations. (PR #2008)
* Added Grid search functionality in lib.nsgrid for faster distance based
calculations. (PR #2008)
* Modified around selections to work with KDTree and periodic boundary
conditions. Should reduce memory usage (#974 PR #2022)
* Modified topology.guessers.guess_bonds to automatically select the
Expand Down
3 changes: 2 additions & 1 deletion package/MDAnalysis/lib/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
from __future__ import absolute_import

__all__ = ['log', 'transformations', 'util', 'mdamath', 'distances',
'NeighborSearch', 'formats', 'pkdtree']
'NeighborSearch', 'formats', 'pkdtree', 'nsgrid']

from . import log
from . import transformations
Expand All @@ -39,3 +39,4 @@
from . import NeighborSearch
from . import formats
from . import pkdtree
from . import nsgrid
146 changes: 140 additions & 6 deletions package/MDAnalysis/lib/distances.py
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,8 @@ def capped_distance(reference, configuration, max_cutoff, min_cutoff=None,
Currently only supports brute force and Periodic KDtree

.. SeeAlso:: :func:'MDAnalysis.lib.distances.distance_array'
.. SeeAlso:: :func:'MDAnalysis.lib.pkdtree.PeriodicKDTree'
.. SeeAlso:: :func:'MDAnalysis.lib.pkdtree.PeriodicKDTree.search'
.. SeeAlso:: :class:'MDAnalysis.lib.nsgrid.FastNS.search'
"""
if box is not None:
if box.shape[0] != 6:
Expand Down Expand Up @@ -517,10 +518,12 @@ def _determine_method(reference, configuration, max_cutoff, min_cutoff=None,
Currently implemented methods are present in the ``methods`` dictionary
bruteforce : returns ``_bruteforce_capped``
PKDtree : return ``_pkdtree_capped`
NSGrid : return ``_nsgrid_capped`

"""
methods = {'bruteforce': _bruteforce_capped,
'pkdtree': _pkdtree_capped}
'pkdtree': _pkdtree_capped,
'nsgrid': _nsgrid_capped}

if method is not None:
return methods[method]
Expand Down Expand Up @@ -568,7 +571,6 @@ def _bruteforce_capped(reference, configuration, max_cutoff,
"""
pairs, distance = [], []


reference = np.asarray(reference, dtype=np.float32)
configuration = np.asarray(configuration, dtype=np.float32)

Expand Down Expand Up @@ -644,6 +646,77 @@ def _pkdtree_capped(reference, configuration, max_cutoff,
return pairs, distances


def _nsgrid_capped(reference, configuration, max_cutoff, min_cutoff=None,
box=None):
"""Search all the pairs in *reference* and *configuration* within
a specified distance using Grid Search


Parameters
-----------
reference : array
reference coordinates array with shape ``reference.shape = (3,)``
or ``reference.shape = (len(reference), 3)``.
configuration : array
Configuration coordinate array with shape ``reference.shape = (3,)``
or ``reference.shape = (len(reference), 3)``
max_cutoff : float
Maximum cutoff distance between the reference and configuration
min_cutoff : (optional) float
Minimum cutoff distance between reference and configuration [None]
box : array
The dimensions, if provided, must be provided in the same
The unitcell dimesions for this system format as returned
by :attr:`MDAnalysis.coordinates.base.Timestep.dimensions`:
``[lx,ly, lz, alpha, beta, gamma]``. Minimum image convention
is applied if the box is provided

"""
from .nsgrid import FastNS
if reference.shape == (3, ):
reference = reference[None, :]
if configuration.shape == (3, ):
configuration = configuration[None, :]

if box is None:
# create a pseudobox
# define the max range
# and supply the pseudobox
# along with only one set of coordinates
pseudobox = np.zeros(6, dtype=np.float32)
all_coords = np.concatenate([reference, configuration])
lmax = all_coords.max(axis=0)
lmin = all_coords.min(axis=0)
# Using maximum dimension as the box size
boxsize = (lmax-lmin).max()
# to avoid failures of very close particles
# but with larger cutoff
if boxsize < 2*max_cutoff:
# just enough box size so that NSGrid doesnot fails
sizefactor = 2.2*max_cutoff/boxsize
else:
sizefactor = 1.2
pseudobox[:3] = sizefactor*boxsize
pseudobox[3:] = 90.
shiftref, shiftconf = reference.copy(), configuration.copy()
# Extra padding near the origin
shiftref -= lmin - 0.1*boxsize
shiftconf -= lmin - 0.1*boxsize
gridsearch = FastNS(max_cutoff, shiftconf, box=pseudobox, pbc=False)
results = gridsearch.search(shiftref)
else:
gridsearch = FastNS(max_cutoff, configuration, box=box)
results = gridsearch.search(reference)

pairs = results.get_pairs()
pair_distance = results.get_pair_distances()

if min_cutoff is not None:
idx = pair_distance > min_cutoff
pairs, pair_distance = pairs[idx], pair_distance[idx]
return pairs, pair_distance


def self_capped_distance(reference, max_cutoff, min_cutoff=None,
box=None, method=None):
"""Finds all the pairs and respective distances within a specified cutoff
Expand Down Expand Up @@ -695,10 +768,11 @@ def self_capped_distance(reference, max_cutoff, min_cutoff=None,

Note
-----
Currently only supports brute force and Periodic KDtree
Currently only supports brute force, Periodic KDtree and Grid Search

.. SeeAlso:: :func:'MDAnalysis.lib.distances.self_distance_array'
.. SeeAlso:: :func:'MDAnalysis.lib.pkdtree.PeriodicKDTree'
.. SeeAlso:: :func:'MDAnalysis.lib.pkdtree.PeriodicKDTree.search'
.. SeeAlso:: :func:'MDAnalysis.lib.nsgrid.FastNS.self_search'
"""
if box is not None:
if box.shape[0] != 6:
Expand Down Expand Up @@ -750,10 +824,12 @@ def _determine_method_self(reference, max_cutoff, min_cutoff=None,
Currently implemented methods are present in the ``methods`` dictionary
bruteforce : returns ``_bruteforce_capped_self``
PKDtree : return ``_pkdtree_capped_self``
NSGrid : return ``_nsgrid_capped_self``

"""
methods = {'bruteforce': _bruteforce_capped_self,
'pkdtree': _pkdtree_capped_self}
'pkdtree': _pkdtree_capped_self,
'nsgrid': _nsgrid_capped_self}

if method is not None:
return methods[method]
Expand Down Expand Up @@ -858,6 +934,64 @@ def _pkdtree_capped_self(reference, max_cutoff, min_cutoff=None,
return np.asarray(pairs), np.asarray(distance)


def _nsgrid_capped_self(reference, max_cutoff, min_cutoff=None,
box=None):
"""Finds all the pairs among the *reference* coordinates within
a fixed distance using gridsearch

Returns
-------
pairs : array
Arrray of ``[i, j]`` pairs such that atom-index ``i``
and ``j`` from reference array are within a fixed distance
distance: array
Distance between ``reference[i]`` and ``reference[j]``
atom coordinate

"""
from .nsgrid import FastNS

reference = np.asarray(reference, dtype=np.float32)
if reference.shape == (3, ) or len(reference) == 1:
return [], []

if box is None:
# create a pseudobox
# define the max range
# and supply the pseudobox
# along with only one set of coordinates
pseudobox = np.zeros(6, dtype=np.float32)
lmax = reference.max(axis=0)
lmin = reference.min(axis=0)
# Using maximum dimension as the box size
boxsize = (lmax-lmin).max()
# to avoid failures of very close particles
# but with larger cutoff
if boxsize < 2*max_cutoff:
# just enough box size so that NSGrid doesnot fails
sizefactor = 2.2*max_cutoff/boxsize
else:
sizefactor = 1.2
pseudobox[:3] = sizefactor*boxsize
pseudobox[3:] = 90.
shiftref = reference.copy()
# Extra padding near the origin
shiftref -= lmin - 0.1*boxsize
gridsearch = FastNS(max_cutoff, shiftref, box=pseudobox, pbc=False)
results = gridsearch.self_search()
else:
gridsearch = FastNS(max_cutoff, reference, box=box)
results = gridsearch.self_search()

pairs = results.get_pairs()[::2, :]
pair_distance = results.get_pair_distances()[::2]

if min_cutoff is not None:
idx = pair_distance > min_cutoff
pairs, pair_distance = pairs[idx], pair_distance[idx]
return pairs, pair_distance


def transform_RtoS(inputcoords, box, backend="serial"):
"""Transform an array of coordinates from real space to S space (aka lambda space)

Expand Down
Loading