amep.order.next_neighbors#
- amep.order.next_neighbors(coords: ndarray | None, box_boundary: ndarray | None, vor: Voronoi | None = None, ids: ndarray | None = None, width: float | None = 0.5, pbc: bool = True) ndarray#
Determines the next neighbors based on a given or calculated Voronoi diagram. Returns the number of next neighbors for each particle in coords and the next-neighbor distances as well as the indices of the next neighbors.
- Parameters:
coords (np.ndarray of shape (N,3) or None) – Array of coordinates/points to search for neighbors.
box_boundary (np.ndarray of shape (3,2) or None) – Boundary of the simulation box in the form of np.array([[xmin, xmax], [ymin, ymax], [zmin, zmax]]). If None, one has to specify the Voronoi diagram with the keyword vor (and ids for pbc=True).
width (float, optional) – Relative width (to the box) of the periodic images and mirrors used. For very low densities, this value might have to be set to a larger value than the default. For higher densities, this value can easily be set to smaller values (e.g., 0.1-0.3´). Please check the Voronoi plot to ensure the correct calculation. Range: [0,1]. The default is 0.5.
vor (scipy.spatialcor.Voronoi or None, optional) – If a Voronoi object vor (and indices ids for periodic boundary conditions pbc=True) is given, the Voronoi tessellation is not re-calculated. The default is None.
ids (np.ndarray or None, optional) – IDs of the points for which the number of next neighbors should be returned. If a Voronoi diagram is given via the vor keyword and pbc=True, ids is required to return only the coordinates inside the box. If the Voronoi tessellation and the ids are supplied, the Voronoi tessellation is not re-calculated. The default is None.
pbc (boolean, optional) – If True, periodic boundary conditions are used. The default is True.
- Returns:
nnn (np.ndarray of shape (N,)) – Number of next neighbors of other_coords in coords (same length as other_coords).
distances (np.ndarray of shape (N,)) – Array of lists containing the next-neighbor distances for each particle in coords (ids) to its next neighbors.
neighbors (np.ndarray of shape (N,)) – Array of lists containing the next-neighbor indices for each particle in coords (ids) to its next neighbors.
vor (scipy.spatial.voronoi) – The Scipy Voronoi object used for the calculations.
ids (np.ndarray of shape (N,)) – Particle indices for which the results are returned/which are returned from the Voronoi tesselation (see amep.order.voronoi).
Examples
Without periodic boundary conditions:
>>> import amep >>> import numpy as np >>> coords = np.array([[0,0,0],[1,0,0],[0,1,0],[-1,0,0],[0,-2,0]]) >>> box_boundary = np.array([[-4,4],[-4,4],[-0.5,0.5]]) >>> nnn, distances, neighbors, vor, ids = amep.order.next_neighbors( ... coords, box_boundary, pbc=False ... ) >>> print(nnn) # number of next neighbors [4 3 3 3 3] >>> print(distances) # next neighbor distances [list([1.0, 1.0, 1.0, 2.0]) list([1.4142135623730951, 1.0, 2.23606797749979]) list([1.4142135623730951, 1.4142135623730951, 1.0]) list([1.4142135623730951, 1.0, 2.23606797749979]) list([2.23606797749979, 2.23606797749979, 2.0])] >>> print(neighbors) # neighbor ids [list([3, 1, 2, 4]) list([2, 0, 4]) list([3, 1, 0]) list([2, 0, 4]) list([3, 1, 0])] >>> fig, axs = amep.plot.new(figsize=(3,3)) >>> amep.plot.voronoi(axs, vor, show_vertices=False) >>> axs.set_xlabel(r'$x$') >>> axs.set_ylabel(r'$y$') >>> axs.set_title('pbc = False') >>> axs.set_xlim(box_boundary[0]) >>> axs.set_ylim(box_boundary[1]) >>> fig.savefig('./figures/order/order-next_neighbors-pbc-False.png') >>>
With periodic boundary conditions:
>>> nnn, distances, neighbors, vor, ids = amep.order.next_neighbors( ... coords, box_boundary, pbc=True ... ) >>> print(nnn) # number of next neighbors [4 5 4 5 6] >>> print(distances) # next neighbor distances [list([1.0, 1.0, 2.0, 1.0]) list([2.23606797749979, 6.0, 1.0, 1.4142135623730951, 6.082762530298219]) list([1.4142135623730951, 1.4142135623730951, 1.0, 5.0]) list([2.23606797749979, 6.0, 1.0, 1.4142135623730951, 6.082762530298219]) list([5.0, 2.23606797749979, 7.280109889280518, 2.23606797749979, 7.280109889280518, 2.0])] >>> print(neighbors) # neighbor ids [list([3, 1, 4, 2]) list([4, 3, 0, 2, 2]) list([3, 1, 0, 2]) list([4, 0, 0, 2, 2]) list([1, 3, 0, 1, 3, 0])] >>> fig, axs = amep.plot.new(figsize=(3,3)) >>> amep.plot.voronoi(axs, vor, show_vertices=False) >>> amep.plot.box(axs, box_boundary=box_boundary, ls='--', c='r') >>> axs.set_xlabel(r'$x$') >>> axs.set_ylabel(r'$y$') >>> axs.set_title('pbc = True') >>> fig.savefig('./figures/order/order-next_neighbors-pbc-True.png')