Hi everyone,
I have been using the real position of the particles from box.unwrap(pos,images) to calculate the center of mass . I then wrap it so that it lies inside the box (for binning purposes)
However when I do the same thing with the help of freud.cluster function, I get a different result . Do you know what may be the issue? . I think this is causing the error later in gyration tensor calculations. So can someone please help me out in understanding what am I doing wrong. These are the codes for the 2 approaches:
segment_length=102
overlapping_segments = np.lib.stride_tricks.sliding_window_view(cluster_keys, (segment_length,),axis=1)
overlapping_segments = overlapping_segments.reshape(-1,segment_length)
1st approach :
realposition = box.unwrap(position,image)
realpos = realposition[overlapping_segments]
realpos = realpos.reshape(-1,segment_length,3)
center_of_mass = np.nanmean(realpos, axis=1,keepdims=True)
comwrap = box.wrap(center_of_mass)
differences = realpos -center_of_mass
gyration_tensor = np.nanmean(np.einsum('ijk,ijl->ijkl', differences, differences), axis=1)
2nd approach:
snap =traj[frame]
position = snap.particles.position
image = snap.particles.image
sel_pos = position[overlapping_segments]
sel_pos = sel_pos.reshape(-1,segment_length,3)
gyration_tensor,comwrap,rg2=Rgfunc(sel_pos,box)
def Rgfunc(points,box):
cluster_id = np.arange(0,len(points)).repeat(segment_length,axis=0).reshape(-1,segment_length)
system = (box,points.reshape(-1,3))
clp = freud.cluster.ClusterProperties()
clp.compute(system,cluster_id.reshape(-1))
return clp.gyrations, clp.centers,(clp.radii_of_gyration)**2
best,
Jude