# Radius of Gyration of each cluster

Quote from Rajendra Thapa on July 7, 2020, 4:42 pmI 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("Voids.xyz")

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)

print(len(cluster_sizes))

Thanks,

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("Voids.xyz")

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)

print(len(cluster_sizes))

Thanks,

Quote from Constanze Kalcher on July 9, 2020, 4:06 pmHi,

I think you could do something along the following lines:

from ovito.data 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([np.dot(x,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) data.objects.append(table)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.

Hi,

I think you could do something along the following lines:

from ovito.data 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([np.dot(x,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) data.objects.append(table)

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.

Quote from Rajendra Thapa on July 10, 2020, 2:49 pmI tried this script on my .ovito but it gives me nothing: no error message and no data table.

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