Skip to content

Commit

Permalink
Kdtree fix (#130)
Browse files Browse the repository at this point in the history
add warning if cutoff/cell ratio too large for KDTree pairfinder. resolves issue #126
  • Loading branch information
shinkle-lanl authored Feb 20, 2025
1 parent 3652beb commit 3192c15
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ Bug Fixes:
- Fixed error when LAMMPS interface is in kokkos mode and the kokkos device was set to CPU.
- MLIAPInterface objects
- Fixed bug with RDF computer automatic initialization.
- KDTreeNeighbors finds at most one pair for each set of points. If pair cutoff is more than half
the length of one of the cell sides, it will fail to identify all of the pairs. Added error if
this occurs.

0.0.3
=======
Expand Down
8 changes: 5 additions & 3 deletions hippynn/layers/pairs/dispatch.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,10 +148,12 @@ def neighbor_list_kdtree(cutoff, coords, cell):
if torch.count_nonzero(cell_prod - torch.diag(torch.diag(cell_prod))):
raise ValueError("KD Tree search only works for orthorhombic cells.")

# Verify that the cutoff is less than the side lengths of the cell
# Verify that the cutoff is less half the shortest cell side length. Otherwise, it is possible to
# have multiple images of the same point be within the cutoff distance of another point. The
# current algorithm is unable to handle this.
cell_side_lengths = torch.sqrt(torch.diag(cell_prod))
if (cutoff >= cell_side_lengths).any():
raise ValueError(f"Cutoff value ({cutoff}) must be less than the cell slide lengths ({cell_side_lengths}).")
if (cutoff >= cell_side_lengths/2).any():
raise ValueError(f"Cutoff value ({cutoff}) must be less than half the shortest cell side length ({cell_side_lengths.min()}).")

if torch.count_nonzero(cell - torch.diag(torch.diag(cell))):
# Transform via isometry to a basis where cell is a diagonal matrix if it currently is not
Expand Down

0 comments on commit 3192c15

Please sign in to comment.