From 1336a7353391f4b894e91bc38435beee5720bf02 Mon Sep 17 00:00:00 2001 From: Kay-Robert Dormann Date: Fri, 18 Oct 2024 09:15:38 +0200 Subject: [PATCH] reordered folding and shifting coordinates. fixes #65 --- amep/pbc.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/amep/pbc.py b/amep/pbc.py index 8c15ce3..116b6ec 100644 --- a/amep/pbc.py +++ b/amep/pbc.py @@ -635,20 +635,19 @@ def kdtree( # get center of the simulation box center = np.mean(box_boundary, axis=1) - # fold coords back into box (to avoid errors) - coords = fold(coords, box_boundary) - # shift all coordinates to be within [0,L_i), i=x,y,z # (this is required by the KDTree algorithm) coords = coords + box/2. - center + # fold coords back into box (to avoid errors) + coords = fold(coords, box_boundary) + # shift particles at the right border to the left border # to avoid errors occuring if a particle is placed at L_i coords[coords[:,0]==box[0],0]=0 coords[coords[:,1]==box[1],1]=0 coords[coords[:,2]==box[2],2]=0 - # print(box_boundary, box) - # print(np.max(coords, axis=0)) + return KDTree(coords, boxsize=box) # =============================================================================