amepproject / amep

The Active Matter Evaluation Package (AMEP) - a Python library for the analysis of particle-based and continuum simulation data of soft and active matter systems
https://amepproject.de/
GNU General Public License v3.0
12 stars 2 forks source link

BUG: wrong calculation or gyration tensor #78

Closed kay-ro closed 1 week ago

kay-ro commented 4 weeks ago

Description:

As described in discussion #61 , the gration_tensor gives greatly different results for the radius of gyration than the direct calculation of the radius_of_gyration.

Code for reproduction:

path="gyrationstuffex/"
traj= amep.load.traj(path, reload=False)
#need masses for gyration tensor
mass = 5e-2
masses = np.empty(traj[0].n(), dtype=np.double)
masses.fill(mass)

coords=traj[-1].coords()
box_boundary=traj[-1].box
clusters, ids=amep.cluster.identify(coords, box_boundary)
clusters = clusters[-10:]
print(box_boundary)

# sanity check radius of gyration first
gts = amep.cluster.gyration_tensor(coords, box_boundary, masses, pbc=True, clusters=clusters)
rogs = amep.cluster.radius_of_gyration(coords, box_boundary, masses, pbc=True, clusters=clusters)
for i, cluster in enumerate(clusters):
    print(i)
    print("how many particles",len(cluster))
#     print(cluster)
    print("gyration tensor\n",gts[i])
    ev = np.linalg.eigvals(gts[i])
#     print("ev", ev)
#     print("sum ev",np.sum(ev))
    print("sqrt(sum(ev))*0.05", np.sqrt(np.sum(ev))*0.05)
    print("sqrt(sum(ev))", np.sqrt(np.sum(ev)))
    print("rgs", rogs[i])
#     print("sqrt(sum(ev))-rgs",np.sqrt(np.sum(ev))-rgs[i])

Error message:

No response

Python and AMEP versions:

1.0.3

Additional information:

gyrationstuffex.zip The issue seems to be with the calculation of the distances between particles in gyration_tensor. The calculation with pbc_diff returns wrong results. Screenshot from 2024-10-25 14-01-10

How did you install AMEP?

None

kay-ro commented 4 weeks ago

underlying issue is described in issue #79