Skip to content

Commit

Permalink
Merge pull request #7 from ADicksonLab/min_dist
Browse files Browse the repository at this point in the history
Efficient minimum distance calculations
  • Loading branch information
alexrd authored Feb 9, 2023
2 parents 613ce67 + 8211ac4 commit c927918
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
3 changes: 2 additions & 1 deletion requirements.in
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@

numpy
scipy
pint
pint
scikit-learn
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
'numpy',
'scipy',
'pint',
'scikit-learn'
]

# extras requirements list
Expand Down
23 changes: 23 additions & 0 deletions src/geomm/distance.py
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())

0 comments on commit c927918

Please sign in to comment.