-
Notifications
You must be signed in to change notification settings - Fork 183
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
bug: analysis.calc_rg and analysis.calc_re break when particles are in different periodic images #4689
Comments
It also seems to be broken with Lees-Edwards boundary conditions: import espressomd.lees_edwards
box_l=20
espresso_system=espressomd.System(box_l=[box_l]*3, periodicity=[True,True,True])
espresso_system.time_step = 1
espresso_system.cell_system.skin = 0.1
espresso_system.part.add(id=0, pos = [0.1,0,0])
espresso_system.part.add(id=1, pos = [box_l-0.2,0,0], v=[0.2,0,0])
params_lin = {'initial_pos_offset': -2., 'time_0': 0., 'shear_velocity': 0.}
lin_protocol = espressomd.lees_edwards.LinearShear(**params_lin)
espresso_system.lees_edwards.set_boundary_conditions(
shear_direction="y", shear_plane_normal="x", protocol=lin_protocol)
espresso_system.integrator.run(2)
dist = espresso_system.distance(espresso_system.part.by_id(0),espresso_system.part.by_id(1))
Rg = espresso_system.analysis.calc_rg(chain_start=0, number_of_chains=1, chain_length=2)
Re = espresso_system.analysis.calc_re(chain_start=0, number_of_chains=1, chain_length=2)
print(f'pos=\n{espresso_system.part.all().pos}')
print(f'The distance between the two particles is {dist:.4g}')
print(f'Their end-to-end distance is {Re[0]:.4g} and their radius of gyration is {Rg[0]:.4g}') Actual output:
Expected output:
All polymer-based distance observables rely on |
I looked into the three polymer observables (end-to-end distance, radius of gyration, hydrodynamic radius), and it's not trivial. There are many edge cases to consider. Center of mass definition in periodic boundariesThe weighted barycenter of a collection of points in a periodic system needs to be properly folded. This can be achieved by choosing an arbitrary point in the cloud that serves as a reference point, from which we calculate the distance vector to all other points using the minimum image convention. We compute the mass-average of these distance vectors to get the center of mass, and then offset it by the reference point coordinates. The cluster analysis code uses this algorithm (method With Lees-Edwards boundary conditions, the aforementioned algorithm double-counts the position offset when the reference particle is in the central box. When the reference particle crosses the sheared boundary, the behavior is different. Likewise, the cluster radius of gyration double-counts the position offset while the corresponding polymer observables single-counts it. The GSL fractal dimension seems to underestimate the shear offset by a factor of 1.585. Self-interaction through periodic imagesWhen a polymer grows longer than half the box size, it interacts with its periodic image, at which points the definition of our three polymer observables no longer hold. It is easy to show it with the end-to-end distance with a polymer that grows beyond the unit cell; in the plot below, a box of size 10 is populated with a linear polymer that grows along the x-axis through the insertion of particles that are separated by a distance of 1. Method OutlookWorking on unfolded coordinates seems to be the correct approach here. The discrepancy between folded and unfolded coordinates should not arise in a simulation that is properly set up, i.e. where the box dimensions are always larger than the polymer diameter. Polymer self-interactions through periodic images are generally not desirable, as they introduce unphysical correlations in the polymer dynamics. The only setup I can think of where such correlations would be useful is in energy minimization simulations of polymer crystals. The bug mentioned by @pm-blanco could probably be caught by comparing the distance between consecutive particles in unfolded coordinates against the half box size. If the inter-particle distance is greater, it means the two particles are interacting through periodic images, and thus the polymer was instantiated with inconsistent We should also update the user guide chapter on polymer observables to reflect that they aren't well-defined when self-interactions via periodic images are involved, or when Lees-Edwards periodic boundaries are used. @pm-blanco @RudolfWeeber @kosovan @mebrito @schlaicha @bindgens1 do you have a different take on this matter? |
Meeting discussion summary:
|
Fixes #4689 Description of changes: - disable cluster analysis methods when Lees-Edwards boundary conditions are used - document caveats from chain analysis methods - cleanup doxygen and comment blocks
Fixes espressomd#4689 Description of changes: - disable cluster analysis methods when Lees-Edwards boundary conditions are used - document caveats from chain analysis methods - cleanup doxygen and comment blocks
While debugging a student code I found out the following behavior which looks like a bug to me. If one initializes the system with particles in different periodic images (for example some inside the simulation box and some in the next periodic image) and one calculates the radius of gyration or end-to-end distance, one obtains a value that disregards the periodicity of the system. Here you can find a minimal script that reproduces the bug:
Actual output:
Expected output:
The text was updated successfully, but these errors were encountered: