Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.Sign up
Neighbor search with nsgrid.FastNS yields different pairs for swapped coords and search_coords #2229
Let's say one has A and B particles. It should make no difference if one constructs
In some cases one gets different pairs depending on the order.
Code to reproduce the behavior
This script searches pairs of A-B within a cutoff of 3. With PBC A and B are well within this distance.
import MDAnalysis from MDAnalysis.lib.nsgrid import FastNS u = MDAnalysis.Universe("simple.gro") max_cutoff = 3 configuration = u.select_atoms("name A").positions reference = u.select_atoms("name B").positions box = u.trajectory.dimensions gridsearch = FastNS(max_cutoff, configuration, box=box) results = gridsearch.search(reference) pairs = results.get_pairs() print("Constructed with A; searched with B:", pairs) gridsearch = FastNS(max_cutoff, reference, box=box) results = gridsearch.search(configuration) pairs = results.get_pairs() print("Constructed with B; searched with A:", pairs)
If one now removes the last decimal place of the first box vector every thing works as expected. One finds the pair no matter which order. So the bug only happens under special circumstances.
Current version of MDAnalysis
Using the script from above this seems to work, but if one changes the z coordinates a bit,
@ezavod Thanks for posting the bug. It seems like it is one of those problematic edge cases. Although I must agree the behavior is strange.
I am not sure at this point but I suspect the problem is in one of the floating point operations/ floating to integer conversion somewhere in
Meanwhile, if someone wants to fix the problem, I would suggest checking if the bug resides in
@orbeckst yes, both errors also occur with latest development branch (9428866).
Edit: clicked wrong button and accidentally closed the issue
@ayushsuhane @richardjgowers @jbarnoud @NinadBhat @tylerjereddy do we have sufficiently extensive tests for
As pointed out by @ezavod we now use
It might be a good start for testing to compare the results of