From adfdbc1302abf0689f1b8ee850e5fb58350c46e6 Mon Sep 17 00:00:00 2001 From: Shun Sakuraba Date: Fri, 15 Nov 2019 18:27:04 +0900 Subject: [PATCH 2/3] Fixed incorrect boundary conditions in gmx spatial The boundary conditions used in gmx spatial had corner cases when the coordinate is exactly on the boundary. --- src/gromacs/gmxana/gmx_spatial.cpp | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/gromacs/gmxana/gmx_spatial.cpp b/src/gromacs/gmxana/gmx_spatial.cpp index 6cbf6572cf..c28bcc714b 100644 --- a/src/gromacs/gmxana/gmx_spatial.cpp +++ b/src/gromacs/gmxana/gmx_spatial.cpp @@ -253,18 +253,19 @@ int gmx_spatial(int argc, char *argv[]) for (i = 0; i < nidx; i++) { - if (fr.x[index[i]][XX] < MINBIN[XX] || fr.x[index[i]][XX] > MAXBIN[XX] || - fr.x[index[i]][YY] < MINBIN[YY] || fr.x[index[i]][YY] > MAXBIN[YY] || - fr.x[index[i]][ZZ] < MINBIN[ZZ] || fr.x[index[i]][ZZ] > MAXBIN[ZZ]) + x = static_cast(std::floor((fr.x[index[i]][XX]-MINBIN[XX])/rBINWIDTH)); + y = static_cast(std::floor((fr.x[index[i]][YY]-MINBIN[YY])/rBINWIDTH)); + z = static_cast(std::floor((fr.x[index[i]][ZZ]-MINBIN[ZZ])/rBINWIDTH)); + if (x < 0 || x >= nbin[XX] || + y < 0 || y >= nbin[YY] || + z < 0 || z >= nbin[ZZ]) { printf("There was an item outside of the allocated memory. Increase the value given with the -nab option.\n"); printf("Memory was allocated for [%f,%f,%f]\tto\t[%f,%f,%f]\n", MINBIN[XX], MINBIN[YY], MINBIN[ZZ], MAXBIN[XX], MAXBIN[YY], MAXBIN[ZZ]); printf("Memory was required for [%f,%f,%f]\n", fr.x[index[i]][XX], fr.x[index[i]][YY], fr.x[index[i]][ZZ]); exit(1); } - x = static_cast(std::floor((fr.x[index[i]][XX]-MINBIN[XX])/rBINWIDTH)); - y = static_cast(std::floor((fr.x[index[i]][YY]-MINBIN[YY])/rBINWIDTH)); - z = static_cast(std::floor((fr.x[index[i]][ZZ]-MINBIN[ZZ])/rBINWIDTH)); + ++bin[x][y][z]; if (x < minx) { -- 2.17.1