Skip to content

Commit

Permalink
Check for finite query coordinates
Browse files Browse the repository at this point in the history
  • Loading branch information
padix-key committed Jan 7, 2025
1 parent 226f2b4 commit a86b18b
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/biotite/structure/celllist.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -631,8 +631,14 @@ cdef class CellList:

cdef ptr[:,:,:] cells = self._cells
cdef int[:,:,:] cell_length = self._cell_length
cdef uint8[:] finite_mask = (
np.isfinite(np.asarray(coord)).all(axis=-1).astype(np.uint8, copy=False)
)

for pos_i in range(coord.shape[0]):
if not finite_mask[pos_i]:
# For non-finite coordinates, there are no adjacent atoms
continue
array_i = 0
cell_r = cell_radius[pos_i]
x = coord[pos_i, 0]
Expand Down Expand Up @@ -757,8 +763,8 @@ def _check_coord(coord):
raise ValueError("Coordinates must not be empty")
if coord.shape[1] != 3:
raise ValueError("Coordinates must have form (x,y,z)")
if np.isnan(coord).any():
raise ValueError("Coordinates contain NaN values")
if not np.isfinite(coord).all():
raise ValueError("Coordinates contain non-finite values")


def _empty_result(as_mask):
Expand Down

0 comments on commit a86b18b

Please sign in to comment.