2 * This file is part of the GROMACS molecular simulation package.
4 * Copyright (c) 2009,2010,2011,2012,2013,2014, by the GROMACS development team, led by
5 * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
6 * and including many others, as listed in the AUTHORS file in the
7 * top-level source directory and at http://www.gromacs.org.
9 * GROMACS is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public License
11 * as published by the Free Software Foundation; either version 2.1
12 * of the License, or (at your option) any later version.
14 * GROMACS is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with GROMACS; if not, see
21 * http://www.gnu.org/licenses, or write to the Free Software Foundation,
22 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 * If you want to redistribute modifications to GROMACS, please
25 * consider that scientific software is very special. Version
26 * control is crucial - bugs must be traceable. We will be happy to
27 * consider code for inclusion in the official distribution, but
28 * derived work must not be called official GROMACS. Details are found
29 * in the README & COPYING files - if they are missing, get the
30 * official version at http://www.gromacs.org.
32 * To help us fund GROMACS development, we humbly ask that you cite
33 * the research papers on the package. Check out http://www.gromacs.org.
37 * Implements neighborhood searching for analysis (from nbsearch.h).
40 * The grid implementation could still be optimized in several different ways:
41 * - Triclinic grid cells are not the most efficient shape, but make PBC
43 * - Precalculating the required PBC shift for a pair of cells outside the
44 * inner loop. After this is done, it should be quite straightforward to
45 * move to rectangular cells.
46 * - Pruning grid cells from the search list if they are completely outside
47 * the sphere that is being considered.
48 * - A better heuristic could be added for falling back to simple loops for a
49 * small number of reference particles.
50 * - A better heuristic for selecting the grid size.
51 * - A multi-level grid implementation could be used to be able to use small
52 * grids for short cutoffs with very inhomogeneous particle distributions
53 * without a memory cost.
55 * \author Teemu Murtola <teemu.murtola@gmail.com>
56 * \ingroup module_selection
58 #include "gromacs/selection/nbsearch.h"
66 #include "thread_mpi/mutex.h"
68 #include "gromacs/legacyheaders/names.h"
70 #include "gromacs/math/vec.h"
71 #include "gromacs/pbcutil/pbc.h"
72 #include "gromacs/selection/position.h"
73 #include "gromacs/utility/arrayref.h"
74 #include "gromacs/utility/exceptions.h"
75 #include "gromacs/utility/gmxassert.h"
76 #include "gromacs/utility/smalloc.h"
77 #include "gromacs/utility/stringutil.h"
85 /********************************************************************
86 * Implementation class declarations
89 class AnalysisNeighborhoodSearchImpl
92 typedef AnalysisNeighborhoodPairSearch::ImplPointer
93 PairSearchImplPointer;
94 typedef std::vector<PairSearchImplPointer> PairSearchList;
95 typedef std::vector<std::vector<int> > CellList;
97 explicit AnalysisNeighborhoodSearchImpl(real cutoff);
98 ~AnalysisNeighborhoodSearchImpl();
101 * Initializes the search with a given box and reference positions.
103 * \param[in] mode Search mode to use.
104 * \param[in] bXY Whether to use 2D searching.
105 * \param[in] pbc PBC information.
106 * \param[in] positions Set of reference positions.
108 void init(AnalysisNeighborhood::SearchMode mode,
111 const AnalysisNeighborhoodPositions &positions);
112 PairSearchImplPointer getPairSearch();
114 real cutoffSquared() const { return cutoff2_; }
115 bool usesGridSearch() const { return bGrid_; }
118 //! Calculates offsets to neighboring grid cells that should be considered.
119 void initGridCellNeighborList();
121 * Determines a suitable grid size and sets up the cells.
123 * \param[in] pbc Information about the box.
124 * \returns false if grid search is not suitable.
126 bool initGridCells(const t_pbc &pbc);
128 * Sets ua a search grid for a given box.
130 * \param[in] pbc Information about the box.
131 * \returns false if grid search is not suitable.
133 bool initGrid(const t_pbc &pbc);
135 * Maps a point into a grid cell.
137 * \param[in] x Point to map.
138 * \param[out] cell Indices of the grid cell in which \p x lies.
140 * \p x should be within the triclinic unit cell.
142 void mapPointToGridCell(const rvec x, ivec cell) const;
144 * Calculates linear index of a grid cell.
146 * \param[in] cell Cell indices.
147 * \returns Linear index of \p cell.
149 int getGridCellIndex(const ivec cell) const;
151 * Adds an index into a grid cell.
153 * \param[in] cell Cell into which \p i should be added.
154 * \param[in] i Index to add.
156 void addToGridCell(const ivec cell, int i);
158 //! Whether to try grid searching.
162 //! The cutoff squared.
164 //! Whether to do searching in XY plane only.
167 //! Number of reference points for the current frame.
169 //! Reference point positions.
171 //! Reference position ids (NULL if not available).
176 //! Number of excluded reference positions for current test particle.
178 //! Exclusions for current test particle.
181 //! Whether grid searching is actually used for the current positions.
183 //! Array allocated for storing in-unit-cell reference positions.
185 //! Allocation count for xref_alloc.
187 //! false if the box is rectangular.
189 //! Box vectors of a single grid cell.
191 //! The reciprocal cell vectors as columns; the inverse of \p cellbox.
193 //! Number of cells along each dimension.
195 //! Data structure to hold the grid cell contents.
197 //! Number of neighboring cells to consider.
199 //! Offsets of the neighboring cells to consider.
201 //! Allocation count for \p gnboffs.
204 tMPI::mutex createPairSearchMutex_;
205 PairSearchList pairSearchList_;
207 friend class AnalysisNeighborhoodPairSearchImpl;
209 GMX_DISALLOW_COPY_AND_ASSIGN(AnalysisNeighborhoodSearchImpl);
212 class AnalysisNeighborhoodPairSearchImpl
215 explicit AnalysisNeighborhoodPairSearchImpl(const AnalysisNeighborhoodSearchImpl &search)
219 clear_ivec(testcell_);
223 //! Initializes a search to find reference positions neighboring \p x.
224 void startSearch(const AnalysisNeighborhoodPositions &positions);
225 //! Searches for the next neighbor.
226 template <class Action>
227 bool searchNext(Action action);
228 //! Initializes a pair representing the pair found by searchNext().
229 void initFoundPair(AnalysisNeighborhoodPair *pair) const;
230 //! Advances to the next test position, skipping any remaining pairs.
231 void nextTestPosition();
234 //! Clears the loop indices.
235 void reset(int testIndex);
236 //! Checks whether a reference positiong should be excluded.
237 bool isExcluded(int j);
239 //! Parent search object.
240 const AnalysisNeighborhoodSearchImpl &search_;
241 //! Reference to the test positions.
242 ConstArrayRef<rvec> testPositions_;
243 //! Index of the currently active test position in \p testPositions_.
245 //! Stores test position during a pair loop.
247 //! Stores the previous returned position during a pair loop.
249 //! Stores the pair distance corresponding to previ_;
251 //! Stores the current exclusion index during loops.
253 //! Stores the test particle cell index during loops.
255 //! Stores the current cell neighbor index during pair loops.
257 //! Stores the index within the current cell during pair loops.
260 GMX_DISALLOW_COPY_AND_ASSIGN(AnalysisNeighborhoodPairSearchImpl);
263 /********************************************************************
264 * AnalysisNeighborhoodSearchImpl
267 AnalysisNeighborhoodSearchImpl::AnalysisNeighborhoodSearchImpl(real cutoff)
273 cutoff_ = GMX_REAL_MAX;
276 cutoff2_ = sqr(cutoff_);
282 std::memset(&pbc_, 0, sizeof(pbc_));
293 clear_mat(recipcell_);
294 clear_ivec(ncelldim_);
301 AnalysisNeighborhoodSearchImpl::~AnalysisNeighborhoodSearchImpl()
303 PairSearchList::const_iterator i;
304 for (i = pairSearchList_.begin(); i != pairSearchList_.end(); ++i)
306 GMX_RELEASE_ASSERT(i->unique(),
307 "Dangling AnalysisNeighborhoodPairSearch reference");
313 AnalysisNeighborhoodSearchImpl::PairSearchImplPointer
314 AnalysisNeighborhoodSearchImpl::getPairSearch()
316 tMPI::lock_guard<tMPI::mutex> lock(createPairSearchMutex_);
317 // TODO: Consider whether this needs to/can be faster, e.g., by keeping a
318 // separate pool of unused search objects.
319 PairSearchList::const_iterator i;
320 for (i = pairSearchList_.begin(); i != pairSearchList_.end(); ++i)
327 PairSearchImplPointer pairSearch(new AnalysisNeighborhoodPairSearchImpl(*this));
328 pairSearchList_.push_back(pairSearch);
332 void AnalysisNeighborhoodSearchImpl::initGridCellNeighborList()
334 int maxx, maxy, maxz;
337 /* Find the extent of the sphere in triclinic coordinates */
338 maxz = static_cast<int>(cutoff_ * recipcell_[ZZ][ZZ]) + 1;
339 rvnorm = sqrt(sqr(recipcell_[YY][YY]) + sqr(recipcell_[ZZ][YY]));
340 maxy = static_cast<int>(cutoff_ * rvnorm) + 1;
341 rvnorm = sqrt(sqr(recipcell_[XX][XX]) + sqr(recipcell_[YY][XX])
342 + sqr(recipcell_[ZZ][XX]));
343 maxx = static_cast<int>(cutoff_ * rvnorm) + 1;
345 /* Calculate the number of cells and reallocate if necessary */
346 ngridnb_ = (2 * maxx + 1) * (2 * maxy + 1) * (2 * maxz + 1);
347 if (gnboffs_nalloc_ < ngridnb_)
349 gnboffs_nalloc_ = ngridnb_;
350 srenew(gnboffs_, gnboffs_nalloc_);
353 /* Store the whole cube */
354 /* TODO: Prune off corners that are not needed */
356 for (int x = -maxx; x <= maxx; ++x)
358 for (int y = -maxy; y <= maxy; ++y)
360 for (int z = -maxz; z <= maxz; ++z)
371 bool AnalysisNeighborhoodSearchImpl::initGridCells(const t_pbc &pbc)
373 const real targetsize =
374 pow(pbc.box[XX][XX] * pbc.box[YY][YY] * pbc.box[ZZ][ZZ]
375 * 10 / nref_, static_cast<real>(1./3.));
378 for (int dd = 0; dd < DIM; ++dd)
380 ncelldim_[dd] = static_cast<int>(pbc.box[dd][dd] / targetsize);
381 cellCount *= ncelldim_[dd];
382 if (ncelldim_[dd] < 3)
387 // Never decrease the size of the cell vector to avoid reallocating
388 // memory for the nested vectors. The actual size of the vector is not
389 // used outside this function.
390 if (cells_.size() < static_cast<size_t>(cellCount))
392 cells_.resize(cellCount);
394 for (int ci = 0; ci < cellCount; ++ci)
401 bool AnalysisNeighborhoodSearchImpl::initGrid(const t_pbc &pbc)
403 /* TODO: This check could be improved. */
404 if (0.5*pbc.max_cutoff2 < cutoff2_)
409 if (!initGridCells(pbc))
414 bTric_ = TRICLINIC(pbc.box);
417 for (int dd = 0; dd < DIM; ++dd)
419 svmul(1.0 / ncelldim_[dd], pbc.box[dd], cellbox_[dd]);
421 m_inv_ur0(cellbox_, recipcell_);
425 for (int dd = 0; dd < DIM; ++dd)
427 cellbox_[dd][dd] = pbc.box[dd][dd] / ncelldim_[dd];
428 recipcell_[dd][dd] = 1.0 / cellbox_[dd][dd];
431 initGridCellNeighborList();
435 void AnalysisNeighborhoodSearchImpl::mapPointToGridCell(const rvec x,
442 tmvmul_ur0(recipcell_, x, tx);
443 for (int dd = 0; dd < DIM; ++dd)
445 cell[dd] = static_cast<int>(tx[dd]);
450 for (int dd = 0; dd < DIM; ++dd)
452 cell[dd] = static_cast<int>(x[dd] * recipcell_[dd][dd]);
457 int AnalysisNeighborhoodSearchImpl::getGridCellIndex(const ivec cell) const
459 GMX_ASSERT(cell[XX] >= 0 && cell[XX] < ncelldim_[XX],
460 "Grid cell X index out of range");
461 GMX_ASSERT(cell[YY] >= 0 && cell[YY] < ncelldim_[YY],
462 "Grid cell Y index out of range");
463 GMX_ASSERT(cell[ZZ] >= 0 && cell[ZZ] < ncelldim_[ZZ],
464 "Grid cell Z index out of range");
465 return cell[XX] + cell[YY] * ncelldim_[XX]
466 + cell[ZZ] * ncelldim_[XX] * ncelldim_[YY];
469 void AnalysisNeighborhoodSearchImpl::addToGridCell(const ivec cell, int i)
471 const int ci = getGridCellIndex(cell);
472 cells_[ci].push_back(i);
475 void AnalysisNeighborhoodSearchImpl::init(
476 AnalysisNeighborhood::SearchMode mode,
479 const AnalysisNeighborhoodPositions &positions)
481 GMX_RELEASE_ASSERT(positions.index_ == -1,
482 "Individual indexed positions not supported as reference");
484 if (bXY_ && pbc->ePBC != epbcNONE)
486 if (pbc->ePBC != epbcXY && pbc->ePBC != epbcXYZ)
488 std::string message =
489 formatString("Computations in the XY plane are not supported with PBC type '%s'",
491 GMX_THROW(NotImplementedError(message));
493 if (std::fabs(pbc->box[ZZ][XX]) > GMX_REAL_EPS*pbc->box[ZZ][ZZ] ||
494 std::fabs(pbc->box[ZZ][YY]) > GMX_REAL_EPS*pbc->box[ZZ][ZZ])
496 GMX_THROW(NotImplementedError("Computations in the XY plane are not supported when the last box vector is not parallel to the Z axis"));
498 set_pbc(&pbc_, epbcXY, const_cast<rvec *>(pbc->box));
500 else if (pbc != NULL)
506 pbc_.ePBC = epbcNONE;
508 nref_ = positions.count_;
509 // TODO: Consider whether it would be possible to support grid searching in
511 if (mode == AnalysisNeighborhood::eSearchMode_Simple
512 || pbc_.ePBC != epbcXYZ)
518 // TODO: Actually implement forcing eSearchMode_Grid
519 bGrid_ = initGrid(pbc_);
523 if (xref_nalloc_ < nref_)
525 srenew(xref_alloc_, nref_);
526 xref_nalloc_ = nref_;
530 for (int i = 0; i < nref_; ++i)
532 copy_rvec(positions.x_[i], xref_alloc_[i]);
534 put_atoms_in_triclinic_unitcell(ecenterTRIC, pbc_.box,
536 for (int i = 0; i < nref_; ++i)
540 mapPointToGridCell(xref_[i], refcell);
541 addToGridCell(refcell, i);
546 xref_ = positions.x_;
548 // TODO: Once exclusions are supported, this may need to be initialized.
554 * Sets the exclusions for the next neighborhood search.
556 * \param[in,out] d Neighborhood search data structure.
557 * \param[in] nexcl Number of reference positions to exclude from next
559 * \param[in] excl Indices of reference positions to exclude.
561 * The set exclusions remain in effect until the next call of this function.
564 gmx_ana_nbsearch_set_excl(gmx_ana_nbsearch_t *d, int nexcl, int excl[])
572 /********************************************************************
573 * AnalysisNeighborhoodPairSearchImpl
576 void AnalysisNeighborhoodPairSearchImpl::reset(int testIndex)
578 testIndex_ = testIndex;
579 if (testIndex_ >= 0 && testIndex_ < static_cast<int>(testPositions_.size()))
581 copy_rvec(testPositions_[testIndex_], xtest_);
584 put_atoms_in_triclinic_unitcell(ecenterTRIC,
585 const_cast<rvec *>(search_.pbc_.box),
587 search_.mapPointToGridCell(xtest_, testcell_);
597 void AnalysisNeighborhoodPairSearchImpl::nextTestPosition()
599 if (testIndex_ < static_cast<int>(testPositions_.size()))
606 bool AnalysisNeighborhoodPairSearchImpl::isExcluded(int j)
608 if (exclind_ < search_.nexcl_)
612 while (exclind_ < search_.nexcl_
613 && search_.excl_[exclind_] < search_.refid_[j])
617 if (exclind_ < search_.nexcl_
618 && search_.refid_[j] == search_.excl_[exclind_])
626 while (search_.bGrid_ && exclind_ < search_.nexcl_
627 && search_.excl_[exclind_] < j)
631 if (search_.excl_[exclind_] == j)
641 void AnalysisNeighborhoodPairSearchImpl::startSearch(
642 const AnalysisNeighborhoodPositions &positions)
644 if (positions.index_ < 0)
646 testPositions_ = ConstArrayRef<rvec>(positions.x_, positions.count_);
651 // Somewhat of a hack: setup the array such that only the last position
653 testPositions_ = ConstArrayRef<rvec>(positions.x_, positions.index_ + 1);
654 reset(positions.index_);
658 template <class Action>
659 bool AnalysisNeighborhoodPairSearchImpl::searchNext(Action action)
661 while (testIndex_ < static_cast<int>(testPositions_.size()))
665 GMX_RELEASE_ASSERT(!search_.bXY_, "Grid-based XY searches not implemented");
668 int cai = prevcai_ + 1;
670 for (; nbi < search_.ngridnb_; ++nbi)
674 ivec_add(testcell_, search_.gnboffs_[nbi], cell);
675 cell[XX] = (cell[XX] + search_.ncelldim_[XX]) % search_.ncelldim_[XX];
676 cell[YY] = (cell[YY] + search_.ncelldim_[YY]) % search_.ncelldim_[YY];
677 cell[ZZ] = (cell[ZZ] + search_.ncelldim_[ZZ]) % search_.ncelldim_[ZZ];
679 const int ci = search_.getGridCellIndex(cell);
680 const int cellSize = static_cast<int>(search_.cells_[ci].size());
681 /* TODO: Calculate the required PBC shift outside the inner loop */
682 for (; cai < cellSize; ++cai)
684 const int i = search_.cells_[ci][cai];
690 pbc_dx_aiuc(&search_.pbc_, xtest_, search_.xref_[i], dx);
691 const real r2 = norm2(dx);
692 if (r2 <= search_.cutoff2_)
710 for (int i = previ_ + 1; i < search_.nref_; ++i)
717 if (search_.pbc_.ePBC != epbcNONE)
719 pbc_dx(&search_.pbc_, xtest_, search_.xref_[i], dx);
723 rvec_sub(xtest_, search_.xref_[i], dx);
727 ? dx[XX]*dx[XX] + dx[YY]*dx[YY]
729 if (r2 <= search_.cutoff2_)
745 void AnalysisNeighborhoodPairSearchImpl::initFoundPair(
746 AnalysisNeighborhoodPair *pair) const
750 *pair = AnalysisNeighborhoodPair();
754 *pair = AnalysisNeighborhoodPair(previ_, testIndex_, prevr2_);
758 } // namespace internal
764 * Search action to find the next neighbor.
766 * Used as the action for AnalysisNeighborhoodPairSearchImpl::searchNext() to
767 * find the next neighbor.
769 * Simply breaks the loop on the first found neighbor.
771 bool withinAction(int /*i*/, real /*r2*/)
777 * Search action find the minimum distance.
779 * Used as the action for AnalysisNeighborhoodPairSearchImpl::searchNext() to
780 * find the nearest neighbor.
782 * With this action, AnalysisNeighborhoodPairSearchImpl::searchNext() always
783 * returns false, and the output is put into the variables passed by pointer
784 * into the constructor. If no neighbors are found, the output variables are
785 * not modified, i.e., the caller must initialize them.
791 * Initializes the action with given output locations.
793 * \param[out] closestPoint Index of the closest reference location.
794 * \param[out] minDist2 Minimum distance squared.
796 * The constructor call does not modify the pointed values, but only
797 * stores the pointers for later use.
798 * See the class description for additional semantics.
800 MindistAction(int *closestPoint, real *minDist2)
801 : closestPoint_(*closestPoint), minDist2_(*minDist2)
805 //! Processes a neighbor to find the nearest point.
806 bool operator()(int i, real r2)
820 GMX_DISALLOW_ASSIGN(MindistAction);
825 /********************************************************************
826 * AnalysisNeighborhood::Impl
829 class AnalysisNeighborhood::Impl
832 typedef AnalysisNeighborhoodSearch::ImplPointer SearchImplPointer;
833 typedef std::vector<SearchImplPointer> SearchList;
835 Impl() : cutoff_(0), mode_(eSearchMode_Automatic), bXY_(false)
840 SearchList::const_iterator i;
841 for (i = searchList_.begin(); i != searchList_.end(); ++i)
843 GMX_RELEASE_ASSERT(i->unique(),
844 "Dangling AnalysisNeighborhoodSearch reference");
848 SearchImplPointer getSearch();
850 tMPI::mutex createSearchMutex_;
851 SearchList searchList_;
857 AnalysisNeighborhood::Impl::SearchImplPointer
858 AnalysisNeighborhood::Impl::getSearch()
860 tMPI::lock_guard<tMPI::mutex> lock(createSearchMutex_);
861 // TODO: Consider whether this needs to/can be faster, e.g., by keeping a
862 // separate pool of unused search objects.
863 SearchList::const_iterator i;
864 for (i = searchList_.begin(); i != searchList_.end(); ++i)
871 SearchImplPointer search(new internal::AnalysisNeighborhoodSearchImpl(cutoff_));
872 searchList_.push_back(search);
876 /********************************************************************
877 * AnalysisNeighborhood
880 AnalysisNeighborhood::AnalysisNeighborhood()
885 AnalysisNeighborhood::~AnalysisNeighborhood()
889 void AnalysisNeighborhood::setCutoff(real cutoff)
891 GMX_RELEASE_ASSERT(impl_->searchList_.empty(),
892 "Changing the cutoff after initSearch() not currently supported");
893 impl_->cutoff_ = cutoff;
896 void AnalysisNeighborhood::setXYMode(bool bXY)
901 void AnalysisNeighborhood::setMode(SearchMode mode)
906 AnalysisNeighborhood::SearchMode AnalysisNeighborhood::mode() const
911 AnalysisNeighborhoodSearch
912 AnalysisNeighborhood::initSearch(const t_pbc *pbc,
913 const AnalysisNeighborhoodPositions &positions)
915 Impl::SearchImplPointer search(impl_->getSearch());
916 search->init(mode(), impl_->bXY_, pbc, positions);
917 return AnalysisNeighborhoodSearch(search);
920 /********************************************************************
921 * AnalysisNeighborhoodSearch
924 AnalysisNeighborhoodSearch::AnalysisNeighborhoodSearch()
928 AnalysisNeighborhoodSearch::AnalysisNeighborhoodSearch(const ImplPointer &impl)
933 void AnalysisNeighborhoodSearch::reset()
938 AnalysisNeighborhood::SearchMode AnalysisNeighborhoodSearch::mode() const
940 GMX_RELEASE_ASSERT(impl_, "Accessing an invalid search object");
941 return (impl_->usesGridSearch()
942 ? AnalysisNeighborhood::eSearchMode_Grid
943 : AnalysisNeighborhood::eSearchMode_Simple);
946 bool AnalysisNeighborhoodSearch::isWithin(
947 const AnalysisNeighborhoodPositions &positions) const
949 GMX_RELEASE_ASSERT(impl_, "Accessing an invalid search object");
950 internal::AnalysisNeighborhoodPairSearchImpl pairSearch(*impl_);
951 pairSearch.startSearch(positions);
952 return pairSearch.searchNext(&withinAction);
955 real AnalysisNeighborhoodSearch::minimumDistance(
956 const AnalysisNeighborhoodPositions &positions) const
958 GMX_RELEASE_ASSERT(impl_, "Accessing an invalid search object");
959 internal::AnalysisNeighborhoodPairSearchImpl pairSearch(*impl_);
960 pairSearch.startSearch(positions);
961 real minDist2 = impl_->cutoffSquared();
962 int closestPoint = -1;
963 MindistAction action(&closestPoint, &minDist2);
964 (void)pairSearch.searchNext(action);
965 return sqrt(minDist2);
968 AnalysisNeighborhoodPair
969 AnalysisNeighborhoodSearch::nearestPoint(
970 const AnalysisNeighborhoodPositions &positions) const
972 GMX_RELEASE_ASSERT(impl_, "Accessing an invalid search object");
973 internal::AnalysisNeighborhoodPairSearchImpl pairSearch(*impl_);
974 pairSearch.startSearch(positions);
975 real minDist2 = impl_->cutoffSquared();
976 int closestPoint = -1;
977 MindistAction action(&closestPoint, &minDist2);
978 (void)pairSearch.searchNext(action);
979 return AnalysisNeighborhoodPair(closestPoint, 0, minDist2);
982 AnalysisNeighborhoodPairSearch
983 AnalysisNeighborhoodSearch::startPairSearch(
984 const AnalysisNeighborhoodPositions &positions) const
986 GMX_RELEASE_ASSERT(impl_, "Accessing an invalid search object");
987 Impl::PairSearchImplPointer pairSearch(impl_->getPairSearch());
988 pairSearch->startSearch(positions);
989 return AnalysisNeighborhoodPairSearch(pairSearch);
992 /********************************************************************
993 * AnalysisNeighborhoodPairSearch
996 AnalysisNeighborhoodPairSearch::AnalysisNeighborhoodPairSearch(
997 const ImplPointer &impl)
1002 bool AnalysisNeighborhoodPairSearch::findNextPair(AnalysisNeighborhoodPair *pair)
1004 bool bFound = impl_->searchNext(&withinAction);
1005 impl_->initFoundPair(pair);
1009 void AnalysisNeighborhoodPairSearch::skipRemainingPairsForTestPosition()
1011 impl_->nextTestPosition();