docs: def nearest_neighbors(coordinates_a, coordinates_b, periodic, r=None, n=None):
      '''Nearest neighbor search between two arrays of coordinates. Notice that
      you can control the result by selecting neighbors either by radius *r* or
      by number *n*. The algorithm uses a periodic variant of KDTree to reach a
      Nlog(N) time complexity.
  
      :param np.ndarray coordinates_a: Either an array of coordinates of shape (N,3)
                                       or a single point of shape (3,)
      :param np.ndarray coordinates_b: Same as coordinates_a
      :param np.ndarray periodic: Either a matrix of box vectors (3, 3) or an
                                  array of box lengths of shape (3,). Only
                                  orthogonal boxes are supported.
      :param float r: Radius of neighbor search
      :param int n: Number of nearest neighbors to return
  
      '''
  
      if r is None and n is None:
          raise ValueError('You should pass either the parameter n or r')
      coordinates_a = _check_coordinates(coordinates_a)
      coordinates_b = _check_coordinates(coordinates_b)
      periodic = _check_periodic(periodic)
  
      kdtree = PeriodicCKDTree(periodic, coordinates_b)
  
      if r is not None:
          neigh = kdtree.query_ball_point(coordinates_a, r)
          if isnested(neigh):
              return (neigh, [coordinates_b.take(nb, axis=0) for nb in neigh])
          else:
              return (neigh, coordinates_b.take(neigh, axis=0)) if len(neigh) != 0 else ([], [])
  
      if n is not None:
          neigh = kdtree.query(coordinates_b, n)
          return neigh if len(neigh) != 0 else ([], [])