amep.cluster.masses#

amep.cluster.masses(clusters: list, mass: ndarray) ndarray#

Calculates the masses of the given clusters.

Parameters:#

clusterslist

List of lists, where each list contains the indices of the particles that belong to the same cluster. If None, the geometric center of the given coords is calculated. If not None, the geometric center of each cluster in clusters is calculated, where coords must be the coordinates of the particles in clusters. The default is None.

massnp.ndarray of shape (N,)

Mass of all N particles in the system, ordered by particle index.

returns:

Masses of the clusters.

rtype:

np.ndarray

Examples

>>> import amep
>>> import numpy as np
>>> coords = np.array([[1,0,0], [4,0,0], [0.5,0,0], [4.5,0,0]])
>>> box = np.array([[-5,5],[-5,5],[-0.5,0.5]])
>>> mass = np.array([20, 1, 2, 5])
>>> clusters, idx = amep.cluster.identify(
...     coords, box, pbc=True, rmax=0.5
... )
>>> masses = amep.cluster.masses(clusters, mass)
>>> print(masses)
[22  6]
>>> traj = amep.load.traj("../examples/data/lammps.h5amep")
>>> frame = traj[-1]
>>> clusters, idx = amep.cluster.identify(
...     frame.coords(), frame.box, pbc=True
... )
>>> masses = amep.cluster.masses(clusters, frame.mass())
>>> print(masses[:10])
[3611.    8.    7.    6.    6.    5.    5.    5.    4.    4.]
>>>