From 0cb539272e13bf71f6b99551fc8585243f2d587f Mon Sep 17 00:00:00 2001 From: Teemu Murtola Date: Tue, 13 Jan 2015 20:48:41 +0200 Subject: [PATCH] Remove AnalysisNeighborhood::setUseBoundingBox() Originally, this was added to provide more control for the caller about how the search is done, with main user probably being more comprehensive tests. This method was possible because at that time, all the coordinates were clamped to the edges of the grid when determining the cell, so it was at most a bit inefficient if some positions were outside the grid. But now, there is no clamping, so this method no longer works correctly: the grid must cover all the reference positions (i.e., be at least the size of the bounding box), so that the reference positions really are within the grid cell to which they belong. Otherwise, when the grid cells to search are pruned based on their distance from the test position, some pairs could be missed. Change-Id: I94ae4081f456c08ff89779ef20b91be0ca061d96 --- src/gromacs/selection/nbsearch.cpp | 27 ++++++--------------------- src/gromacs/selection/nbsearch.h | 22 ---------------------- 2 files changed, 6 insertions(+), 43 deletions(-) diff --git a/src/gromacs/selection/nbsearch.cpp b/src/gromacs/selection/nbsearch.cpp index 2fe48376b8..8d808900fc 100644 --- a/src/gromacs/selection/nbsearch.cpp +++ b/src/gromacs/selection/nbsearch.cpp @@ -132,15 +132,12 @@ class AnalysisNeighborhoodSearchImpl * Initializes the search with a given box and reference positions. * * \param[in] mode Search mode to use. - * \param[in] bUseBoundingBox Whether to use bounding box for - * non-periodic grids. * \param[in] bXY Whether to use 2D searching. * \param[in] excls Exclusions. * \param[in] pbc PBC information. * \param[in] positions Set of reference positions. */ void init(AnalysisNeighborhood::SearchMode mode, - bool bUseBoundingBox, bool bXY, const t_blocka *excls, const t_pbc *pbc, @@ -176,14 +173,11 @@ class AnalysisNeighborhoodSearchImpl * \param[in] pbc Information about the box. * \param[in] posCount Number of positions in \p x. * \param[in] x Reference positions that will be put on the grid. - * \param[in] bUseBoundingBox If `true`, non-periodic grid dimensions - * will use the bounding box of \p x instead of the box. * \param[in] bForce If `true`, grid searching will be used if at all * possible, even if a simple search might give better performance. * \returns `false` if grid search is not suitable. */ - bool initGrid(const t_pbc &pbc, int posCount, const rvec x[], - bool bUseBoundingBox, bool bForce); + bool initGrid(const t_pbc &pbc, int posCount, const rvec x[], bool bForce); /*! \brief * Maps a point into a grid cell. * @@ -600,8 +594,7 @@ bool AnalysisNeighborhoodSearchImpl::initGridCells( } bool AnalysisNeighborhoodSearchImpl::initGrid( - const t_pbc &pbc, int posCount, const rvec x[], bool bUseBoundingBox, - bool bForce) + const t_pbc &pbc, int posCount, const rvec x[], bool bForce) { if (posCount == 0) { @@ -641,7 +634,7 @@ bool AnalysisNeighborhoodSearchImpl::initGrid( clear_rvec(gridOrigin_); for (int dd = 0; dd < DIM; ++dd) { - if (bUseBoundingBox && !bGridPBC_[dd] && !bSingleCell[dd]) + if (!bGridPBC_[dd] && !bSingleCell[dd]) { gridOrigin_[dd] = origin[dd]; clear_rvec(box[dd]); @@ -879,7 +872,6 @@ int AnalysisNeighborhoodSearchImpl::shiftCell(const ivec cell, rvec shift) const void AnalysisNeighborhoodSearchImpl::init( AnalysisNeighborhood::SearchMode mode, - bool bUseBoundingBox, bool bXY, const t_blocka *excls, const t_pbc *pbc, @@ -925,7 +917,7 @@ void AnalysisNeighborhoodSearchImpl::init( } else if (bTryGrid_) { - bGrid_ = initGrid(pbc_, positions.count_, positions.x_, bUseBoundingBox, + bGrid_ = initGrid(pbc_, positions.count_, positions.x_, mode == AnalysisNeighborhood::eSearchMode_Grid); } refIndices_ = positions.indices_; @@ -1240,8 +1232,7 @@ class AnalysisNeighborhood::Impl typedef std::vector SearchList; Impl() - : cutoff_(0), excls_(NULL), mode_(eSearchMode_Automatic), - bUseBoundingBox_(true), bXY_(false) + : cutoff_(0), excls_(NULL), mode_(eSearchMode_Automatic), bXY_(false) { } ~Impl() @@ -1261,7 +1252,6 @@ class AnalysisNeighborhood::Impl real cutoff_; const t_blocka *excls_; SearchMode mode_; - bool bUseBoundingBox_; bool bXY_; }; @@ -1304,11 +1294,6 @@ void AnalysisNeighborhood::setCutoff(real cutoff) impl_->cutoff_ = cutoff; } -void AnalysisNeighborhood::setUseBoundingBox(bool bUseBoundingBox) -{ - impl_->bUseBoundingBox_ = bUseBoundingBox; -} - void AnalysisNeighborhood::setXYMode(bool bXY) { impl_->bXY_ = bXY; @@ -1336,7 +1321,7 @@ AnalysisNeighborhood::initSearch(const t_pbc *pbc, const AnalysisNeighborhoodPositions &positions) { Impl::SearchImplPointer search(impl_->getSearch()); - search->init(mode(), impl_->bUseBoundingBox_, impl_->bXY_, impl_->excls_, + search->init(mode(), impl_->bXY_, impl_->excls_, pbc, positions); return AnalysisNeighborhoodSearch(search); } diff --git a/src/gromacs/selection/nbsearch.h b/src/gromacs/selection/nbsearch.h index bc5baba8d1..d5ae8d41c4 100644 --- a/src/gromacs/selection/nbsearch.h +++ b/src/gromacs/selection/nbsearch.h @@ -252,28 +252,6 @@ class AnalysisNeighborhood * Does not throw. */ void setCutoff(real cutoff); - /*! \brief - * Sets the search to prefer a grid that covers the bounding box of - * reference positions. - * - * By default, non-periodic dimensions will ignore the size of the box - * passed to initSearch() and construct a grid based on the bounding - * box of the reference positions. - * - * If you call this method with `false`, the size of the box will be - * used instead to set the grid. If one of the box vectors is zero, - * then grid searching will not be used for that dimension. This - * allows you to control the size of the used grid in case the default - * is not suitable. However, in this case the grid will currently - * always start at the origin. - * - * Currently, this only influences cases where the grid is not - * periodic in some dimensions, i.e., `pbc` passed to initSearch() is - * NULL, `epbcNONE`, or `epbcXY`. - * - * Does not throw. - */ - void setUseBoundingBox(bool bUseBoundingBox); /*! \brief * Sets the search to only happen in the XY plane. * -- 2.22.0