amep.cluster.gyration_tensor#

amep.cluster.gyration_tensor(coords: ndarray, box_boundary: ndarray, mass: ndarray, pbc: bool = True, clusters: list | None = None) ndarray#

Calculate the gyration tensor of one cluster.

Uses th cluster containing the given coordinates. Uses the minimum image convention if pbc is True.

Notes:#

The gyration tensor is a tensor that describes the second moments of position of a collection of particles normalized by particle number. The formula used here is taken from Ref. [1] .

References:#

Parameters:#

coordsnp.ndarray of shape (N,3)

Coordinates of all particles inside the cluster.

box_boundarynp.ndarray of shape (3,2)

Boundary of the simulation box in the form of np.array([[xmin, xmax], [ymin, ymax], [zmin, zmax]]).

massnp.ndarray of shape (N,)

Mass of all particles inside the cluster.

pbcbool, optional

If True, periodic boundary conditions are considered. The default is True.

clusterslist or None, optional

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.

returns:

Gyration tensor of the given coords or each cluster in clusters.

rtype:

np.ndarray of shape (3,3) or (N,3,3)

Examples

>>> import amep
>>> traj = amep.load.traj("../examples/data/lammps.h5amep")
>>> frame = traj[-1]
>>> clusters, idx = amep.cluster.identify(
...     frame.coords(), frame.box, pbc=True
... )
>>> i = 1
>>> coords = frame.coords()[idx==i]
>>> mass = frame.mass()[idx==i]
>>> gt = amep.cluster.gyration_tensor(
...     coords, frame.box, mass, pbc=True
... )
>>> print(gt)
[[2298.3718 1562.3932    0.    ]
 [1562.3932 3079.9683    0.    ]
 [   0.        0.        0.    ]]
>>> gts = amep.cluster.gyration_tensor(
...     frame.coords(), frame.box, frame.mass(),
...     pbc=True, clusters=clusters
... )
>>> print(gts.shape)
(52, 3, 3)
>>>