Update clusters information

Hello,

I am using ClusterAnalysisModifier in Python, I want to update the cluster ID, so that all single particles and small clusters are counted as one cluster, but how can I ask OVITO to recalculate the center of mass?

Thanks

I would have two alternative suggestions:

  1. You could first select all isolated particles and then apply the ClusterAnalysisModifier a second time. This time restrict it to the subset of selected particles and use a very large cutoff radius parameter such that all selected particles become part of a single cluster.
  2. You could calculate the center of mass of the isolated particles yourself using a NumPy array expression. The center-of-mass computation is straightforward: Simply sum up the particle coordinates (possibly weighted by mass) and divide by the number of particles. This should be Python one-liner, I guess.

Keep in mind though that the center-of-mass calculation is generally ill-defined if you are using periodic boundary conditions and the involved particles are scattered throughout the simulation cell.

Thank you for the reply.

But the selection is fixed for all the frames, right? Because the clusters are changing, and particles are joining and leaving the cluster.

Thats why I didnt calculate it myself!

No, the selection can be dynamically computed for each frame, e.g. by using a Python modifier that retrieves the cluster size for each cluster ID from the “Cluster list” data table and then selects the particles associated with those cluster IDs.
If you activate the option “Sort by size” in the Cluster analysis modifier, the Cluster IDs will be sorted by descending particle count.

Yes, like Constanze said, particles selections are typically calculated dynamically in OVITO as long as they are created by a modifier in the pipeline (which may be a user-defined Python modifier function).

How to deal with the PBCs correctly and in a meaningful way is something you probably have to figure out yourself as it generally depends on the details of your model. The Cluster Analysis modifier uses the minimum image convention to deal with clusters that extend across periodic boundaries of the simulation box and to compute the center of mass of such clusters correctly. But this trick only works in situations where the typical distance between neighboring particles in the cluster are small compared to the simulation box size. It will fail if the particles are located all over the place.

I don’t know why you want to calculate the center of mass of this group of particles, but if this is about calculating a displacement, then it could make sense to calculate the change in the center of mass directly from the atomic displacements of the particles in the group. Then you can avoid the PBC problem.