Forum Navigation
You need to log in to create posts and topics.

Radius of Gyration of each cluster

I am doing a cluster analysis on a very very low density material. The cluster analysis was pretty straightforward. Now that I have the clusters, I want to calculate the radius of gyration of each one of the clusters. I have a feeling that it can be done with a python script but don't know how to proceed.

This is the script I have until now.


pipeline = import_file("")

pipeline.modifiers.append(ClusterAnalysisModifier(cutoff=1.0, sort_by_size=True,compute_com=True))

# Let OVITO compute the results.

data = pipeline.compute()

cluster_sizes = numpy.bincount(data.particles['Cluster'])

numpy.savetxt("cluster_sizes.txt", cluster_sizes)






I think you could do something along the following lines:

from import *
import numpy as np

def modify(frame, data):
    cluster_ids = data.tables['clusters'].x
    R = np.zeros(len(cluster_ids))
    types = data.particles.particle_types
    for id in cluster_ids:
        # Look up center of mass of this cluster
        com = data.tables['clusters']['Center of Mass'][id-1]
        #Find all particles that belong to this cluster
        cluster_particles = np.where(data.particles['Cluster']== id)[0]
        #Calculate their distances from center of mass
        s = data.cell.delta_vector(data.particles.positions[cluster_particles], com) 
        R[id-1] = np.sqrt( np.sum([,x) for x in s])/len(cluster_particles))   
    #Save as Data Table
    table = DataTable(title='Radius of gyration', plot_mode=DataTable.PlotMode.Scatter)
    table.y = table.create_property('R_g', data=R)
    table.x = table.create_property('Cluster', data=cluster_ids)

but you should use this with caution. Currently, for the computation of the center of mass of each cluster, the particle mass is not taken into account by the Cluster analysis modifier (and also in line 15).  Also note, that in line 14  minimum image convention is used, i.e. the results will be invalid if clusters will be larger than half of the box size.

If you like you can try this and let me know what you think.

I tried this script on my .ovito but it gives me nothing: no error message and no data table.


This is to inform you and all other users that in the mean-time, the calculation of the radius of gyration and gyration tensors is now available in the Cluster Analysis modifier in the GUI.