-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from ADicksonLab/min_dist
Efficient minimum distance calculations
- Loading branch information
Showing
3 changed files
with
26 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,4 +2,5 @@ | |
|
||
numpy | ||
scipy | ||
pint | ||
pint | ||
scikit-learn |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,6 +27,7 @@ | |
'numpy', | ||
'scipy', | ||
'pint', | ||
'scikit-learn' | ||
] | ||
|
||
# extras requirements list | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,28 @@ | ||
import numpy as np | ||
import scipy.spatial.distance as dist | ||
from sklearn.neighbors import KDTree | ||
|
||
def distance(): | ||
return None | ||
|
||
def minimum_distance(coordsA, coordsB): | ||
"""Calculate the minimum distance between members of coordsA and coordsB. | ||
Uses a fast binary search algorithm of order N*log(N). | ||
Parameters | ||
---------- | ||
coordsA : arraylike, shape (Natoms_A, 3) | ||
First set of coordinates. | ||
coordsB : arraylike, shape (Natoms_B, 3) | ||
Second set of coordinates. | ||
""" | ||
|
||
# make sure the number of dimensions is 3 | ||
assert (coordsA.shape[1] == 3) and (coordsB.shape[1] == 3), \ | ||
"Minimum distance expecting arrays of shape (N, 3)" | ||
|
||
tree = KDTree(coordsA) | ||
return(tree.query(coordsB, dualtree=False, k=1)[0].min()) |