amep.cluster.identify#
- amep.cluster.identify(coords: ndarray, box_boundary: ndarray, sizes: ndarray | None = None, pbc: bool = True, rmax: float = 1.122) tuple[list, ndarray] #
Identify clusters from particle coordinates, and respective sizes.
Return an array of particle pairs and the corresponding distances between the particles and identifies which particles belong to the same cluster.
- Parameters:
coords (np.ndarray) – Particle coordinates as array of shape (N,3).
box_boundary (np.ndarray of shape (3,2)) – Boundary of the simulation box in the form of np.array([[xmin, xmax], [ymin, ymax], [zmin, zmax]]).
sizes (numpy.ndarray|None, optional) – Array of size (N,) containing the size of each particle (assuming that the particles are spherical). If None, rmax is used for finding pairs. If given, rmax scales the contact distances. The default is None.
pbc (bool, optional) – If True, periodic boundary conditions will be considered when calculating the pairwise distances. The default is True.
rmax (float, optional) – Maximum distance. If the distance between two particles is smaller than rmax, they are considered as belonging to the same cluster. The default is 1.122.
- Returns:
sorted_clusters (list) – List of lists, where each list contains the indices of the particles that belong to the same cluster. The list is sorted by the number of particles in each cluster.
idx (numpy.ndarray) – Array of shape (N,) containing the cluster ID for each particle. N is the total number of particles.
Examples
>>> import amep >>> import numpy as np >>> coords = np.array([[1,0,0], [4,0,0], [-2,0,0], [4.5,0,0]]) >>> box = np.array([[-5,5],[-5,5],[-0.5,0.5]]) >>> clusters, idx = amep.cluster.identify( ... coords, box, pbc=True, rmax=3 ... ) >>> print(clusters) [[0, 1, 2, 3]] >>> print(idx) [0. 0. 0. 0.] >>> clusters, idx = amep.cluster.identify( ... coords, box, pbc=True, rmax=2 ... ) >>> print(clusters) [[1, 3]] >>> print(idx) [1. 0. 2. 0.] >>>