@@ -62,7 +62,9 @@ class AugmentedPKDTree(object):
6262
6363 """
6464
65- def __init__ (self , box : Optional [npt .ArrayLike ] = None , leafsize : int = 10 ) -> None :
65+ def __init__ (
66+ self , box : Optional [npt .ArrayLike ] = None , leafsize : int = 10
67+ ) -> None :
6668 """
6769
6870 Parameters
@@ -96,7 +98,9 @@ def pbc(self):
9698 """
9799 return self .box is not None
98100
99- def set_coords (self , coords : npt .ArrayLike , cutoff : Optional [float ] = None ) -> None :
101+ def set_coords (
102+ self , coords : npt .ArrayLike , cutoff : Optional [float ] = None
103+ ) -> None :
100104 """Constructs KDTree from the coordinates
101105
102106 Wrapping of coordinates to the primary unit cell is enforced
@@ -143,15 +147,18 @@ def set_coords(self, coords: npt.ArrayLike, cutoff: Optional[float] = None) -> N
143147 # Bring the coordinates in the central cell
144148 self .coords = apply_PBC (coords , self .box )
145149 # generate duplicate images
146- self .aug , self .mapping = augment_coordinates (self .coords , self .box , cutoff )
150+ self .aug , self .mapping = augment_coordinates (
151+ self .coords , self .box , cutoff
152+ )
147153 # Images + coords
148154 self .all_coords = np .concatenate ([self .coords , self .aug ])
149155 self .ckdt = cKDTree (self .all_coords , leafsize = self .leafsize )
150156 else :
151157 # if cutoff distance is provided for non PBC calculations
152158 if cutoff is not None :
153159 raise RuntimeError (
154- "Donot provide cutoff distance for" " non PBC aware calculations"
160+ "Donot provide cutoff distance for"
161+ " non PBC aware calculations"
155162 )
156163 self .coords = coords
157164 self .ckdt = cKDTree (self .coords , self .leafsize )
@@ -182,9 +189,13 @@ def search(self, centers: npt.ArrayLike, radius: float) -> npt.NDArray:
182189 # Sanity check
183190 if self .pbc :
184191 if self .cutoff is None :
185- raise ValueError ("Cutoff needs to be provided when working with PBC." )
192+ raise ValueError (
193+ "Cutoff needs to be provided when working with PBC."
194+ )
186195 if self .cutoff < radius :
187- raise RuntimeError ("Set cutoff greater or equal to the radius." )
196+ raise RuntimeError (
197+ "Set cutoff greater or equal to the radius."
198+ )
188199 # Bring all query points to the central cell
189200 wrapped_centers = apply_PBC (centers , self .box )
190201 indices = list (self .ckdt .query_ball_point (wrapped_centers , radius ))
@@ -232,15 +243,23 @@ def search_pairs(self, radius: float) -> npt.NDArray:
232243
233244 if self .pbc :
234245 if self .cutoff is None :
235- raise ValueError ("Cutoff needs to be provided when working with PBC." )
246+ raise ValueError (
247+ "Cutoff needs to be provided when working with PBC."
248+ )
236249 if self .cutoff < radius :
237- raise RuntimeError ("Set cutoff greater or equal to the radius." )
250+ raise RuntimeError (
251+ "Set cutoff greater or equal to the radius."
252+ )
238253
239254 pairs = np .array (list (self .ckdt .query_pairs (radius )), dtype = np .intp )
240255 if self .pbc :
241256 if len (pairs ) > 1 :
242- pairs [:, 0 ] = undo_augment (pairs [:, 0 ], self .mapping , len (self .coords ))
243- pairs [:, 1 ] = undo_augment (pairs [:, 1 ], self .mapping , len (self .coords ))
257+ pairs [:, 0 ] = undo_augment (
258+ pairs [:, 0 ], self .mapping , len (self .coords )
259+ )
260+ pairs [:, 1 ] = undo_augment (
261+ pairs [:, 1 ], self .mapping , len (self .coords )
262+ )
244263 if pairs .size > 0 :
245264 # First sort the pairs then pick the unique pairs
246265 pairs = np .sort (pairs , axis = 1 )
@@ -288,9 +307,13 @@ class initialization
288307 # Sanity check
289308 if self .pbc :
290309 if self .cutoff is None :
291- raise ValueError ("Cutoff needs to be provided when working with PBC." )
310+ raise ValueError (
311+ "Cutoff needs to be provided when working with PBC."
312+ )
292313 if self .cutoff < radius :
293- raise RuntimeError ("Set cutoff greater or equal to the radius." )
314+ raise RuntimeError (
315+ "Set cutoff greater or equal to the radius."
316+ )
294317 # Bring all query points to the central cell
295318 wrapped_centers = apply_PBC (centers , self .box )
296319 other_tree = cKDTree (wrapped_centers , leafsize = self .leafsize )
@@ -300,7 +323,9 @@ class initialization
300323 dtype = np .intp ,
301324 )
302325 if pairs .size > 0 :
303- pairs [:, 1 ] = undo_augment (pairs [:, 1 ], self .mapping , len (self .coords ))
326+ pairs [:, 1 ] = undo_augment (
327+ pairs [:, 1 ], self .mapping , len (self .coords )
328+ )
304329 else :
305330 other_tree = cKDTree (centers , leafsize = self .leafsize )
306331 pairs = other_tree .query_ball_tree (self .ckdt , radius )
@@ -315,13 +340,17 @@ class initialization
315340
316341class PeriodicKDTree (object ):
317342
318- def __init__ (self , box : Optional [npt .ArrayLike ] = None , leafsize : int = 10 ) -> None :
343+ def __init__ (
344+ self , box : Optional [npt .ArrayLike ] = None , leafsize : int = 10
345+ ) -> None :
319346 self .leafsize = leafsize
320347 self .dim = 3
321348 self .box = box
322349 self ._built = False
323- self .cutoff = None
324- self .mapping = None
350+
351+ self .cutoff : Optional [float ] = None
352+ self .mapping : Optional [npt .NDArray ] = None
353+ self ._tree : Optional [Union [AugmentedPKDTree , cKDTree ]] = None
325354
326355 _use_augmented = False
327356 if box is not None :
@@ -353,7 +382,9 @@ def pbc(self):
353382 """
354383 return self .box is not None
355384
356- def set_coords (self , coords : npt .ArrayLike , cutoff : Optional [float ] = None ) -> None :
385+ def set_coords (
386+ self , coords : npt .ArrayLike , cutoff : Optional [float ] = None
387+ ) -> None :
357388 """Constructs KDTree from the coordinates
358389
359390 Parameters
@@ -416,12 +447,18 @@ def search(self, centers: npt.ArrayLike, radius: float) -> npt.NDArray:
416447
417448 if self .pbc :
418449 if self .cutoff is None :
419- raise ValueError ("Cutoff needs to be provided when working with PBC." )
450+ raise ValueError (
451+ "Cutoff needs to be provided when working with PBC."
452+ )
420453 if self .cutoff < radius :
421- raise RuntimeError ("Set cutoff greater or equal to the radius." )
454+ raise RuntimeError (
455+ "Set cutoff greater or equal to the radius."
456+ )
422457 wrapped_centers = apply_PBC (centers , self .box )
423458 assert isinstance (self ._tree , cKDTree )
424- indices = list (self ._tree .query_ball_point (wrapped_centers , radius ))
459+ indices = list (
460+ self ._tree .query_ball_point (wrapped_centers , radius )
461+ )
425462 else :
426463 assert isinstance (self ._tree , cKDTree )
427464 indices = list (self ._tree .query_ball_point (centers , radius ))
@@ -442,9 +479,6 @@ def get_indices(self) -> npt.NDArray:
442479 indices : NDArray
443480 neighbors for the last query points and search radius
444481 """
445- if self ._use_augmented :
446- assert self ._tree is not None
447- return self ._tree .get_indices ()
448482 return self ._indices
449483
450484 def search_pairs (self , radius : float ) -> npt .NDArray :
@@ -469,9 +503,13 @@ def search_pairs(self, radius: float) -> npt.NDArray:
469503
470504 if self .pbc :
471505 if self .cutoff is None :
472- raise ValueError ("Cutoff needs to be provided when working with PBC." )
506+ raise ValueError (
507+ "Cutoff needs to be provided when working with PBC."
508+ )
473509 if self .cutoff < radius :
474- raise RuntimeError ("Set cutoff greater or equal to the radius." )
510+ raise RuntimeError (
511+ "Set cutoff greater or equal to the radius."
512+ )
475513
476514 assert isinstance (self ._tree , cKDTree )
477515 pairs = np .array (list (self ._tree .query_pairs (radius )), dtype = np .intp )
@@ -514,9 +552,13 @@ def search_tree(self, centers: npt.ArrayLike, radius: float) -> np.ndarray:
514552
515553 if self .pbc :
516554 if self .cutoff is None :
517- raise ValueError ("Cutoff needs to be provided when working with PBC." )
555+ raise ValueError (
556+ "Cutoff needs to be provided when working with PBC."
557+ )
518558 if self .cutoff < radius :
519- raise RuntimeError ("Set cutoff greater or equal to the radius." )
559+ raise RuntimeError (
560+ "Set cutoff greater or equal to the radius."
561+ )
520562 wrapped_centers = apply_PBC (centers , self .box )
521563 box_array = np .asarray (self .box , dtype = np .float32 )
522564 other_tree = cKDTree (
0 commit comments