2 * This file is part of the GROMACS molecular simulation package.
4 * Copyright (c) 2009,2010,2011,2012,2013, by the GROMACS development team, led by
5 * David van der Spoel, Berk Hess, Erik Lindahl, and including many
6 * others, as listed in the AUTHORS file in the top-level source
7 * 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.
35 /*! \page nbsearch Neighborhood search routines
37 * Functions to find particles within a neighborhood of a set of particles
38 * are defined in nbsearch.h.
39 * The usage is simple: a data structure is allocated with
40 * gmx_ana_nbsearch_create(), and the box shape and reference positions for a
41 * frame are set using gmx_ana_nbsearch_init() or gmx_ana_nbsearch_pos_init().
42 * Searches can then be performed with gmx_ana_nbsearch_is_within() and
43 * gmx_ana_nbsearch_mindist(), or with versions that take the \c gmx_ana_pos_t
45 * When the data structure is no longer required, it can be freed with
46 * gmx_ana_nbsearch_free().
51 * The grid implementation could still be optimized in several different ways:
52 * - Triclinic grid cells are not the most efficient shape, but make PBC
54 * - Precalculating the required PBC shift for a pair of cells outside the
55 * inner loop. After this is done, it should be quite straightforward to
56 * move to rectangular cells.
57 * - Pruning grid cells from the search list if they are completely outside
58 * the sphere that is being considered.
59 * - A better heuristic could be added for falling back to simple loops for a
60 * small number of reference particles.
61 * - A better heuristic for selecting the grid size.
62 * - A multi-level grid implementation could be used to be able to use small
63 * grids for short cutoffs with very inhomogeneous particle distributions
64 * without a memory cost.
68 * Implements functions in nbsearch.h.
70 * \author Teemu Murtola <teemu.murtola@gmail.com>
71 * \ingroup module_selection
82 #include "gromacs/legacyheaders/smalloc.h"
83 #include "gromacs/legacyheaders/typedefs.h"
84 #include "gromacs/legacyheaders/pbc.h"
85 #include "gromacs/legacyheaders/vec.h"
86 #include "gromacs/legacyheaders/thread_mpi/mutex.h"
88 #include "gromacs/selection/nbsearch.h"
89 #include "gromacs/selection/position.h"
90 #include "gromacs/utility/gmxassert.h"
93 * Data structure for neighborhood searches.
95 struct gmx_ana_nbsearch_t
99 /** The cutoff squared. */
101 /** Maximum number of reference points. */
104 /** Number of reference points for the current frame. */
106 /** Reference point positions. */
108 /** Reference position ids (NULL if not available). */
113 /** Number of excluded reference positions for current test particle. */
115 /** Exclusions for current test particle. */
118 /** Whether to try grid searching. */
120 /** Whether grid searching is actually used for the current positions. */
122 /** Array allocated for storing in-unit-cell reference positions. */
124 /** Allocation count for xref_alloc. */
126 /** false if the box is rectangular. */
128 /** Box vectors of a single grid cell. */
130 /** The reciprocal cell vectors as columns; the inverse of \p cellbox. */
132 /** Number of cells along each dimension. */
134 /** Total number of cells. */
136 /** Number of reference positions in each cell. */
138 /** List of reference positions in each cell. */
140 /** Allocation counts for each \p catom[i]. */
142 /** Allocation count for the per-cell arrays. */
144 /** Number of neighboring cells to consider. */
146 /** Offsets of the neighboring cells to consider. */
148 /** Allocation count for \p gnboffs. */
151 /** Stores test position during a pair loop. */
153 /** Stores the previous returned position during a pair loop. */
155 /** Stores the current exclusion index during loops. */
157 /** Stores the test particle cell index during loops. */
159 /** Stores the current cell neighbor index during pair loops. */
161 /** Stores the index within the current cell during pair loops. */
166 * \param[in] cutoff Cutoff distance for the search
167 * (<=0 stands for no cutoff).
168 * \param[in] maxn Maximum number of reference particles.
169 * \returns Created neighborhood search data structure.
172 gmx_ana_nbsearch_create(real cutoff, int maxn)
174 gmx_ana_nbsearch_t *d;
180 cutoff = GMX_REAL_MAX;
184 d->cutoff2 = sqr(cutoff);
191 d->xref_alloc = NULL;
201 d->gnboffs_nalloc = 0;
207 * \param d Data structure to free.
209 * After the call, the pointer \p d is no longer valid.
212 gmx_ana_nbsearch_free(gmx_ana_nbsearch_t *d)
214 sfree(d->xref_alloc);
220 for (ci = 0; ci < d->ncells; ++ci)
226 sfree(d->catom_nalloc);
232 * Calculates offsets to neighboring grid cells that should be considered.
234 * \param[in,out] d Grid information.
235 * \param[in] pbc Information about the box.
238 grid_init_cell_nblist(gmx_ana_nbsearch_t *d, t_pbc *pbc)
240 int maxx, maxy, maxz;
244 /* Find the extent of the sphere in triclinic coordinates */
245 maxz = (int)(d->cutoff * d->recipcell[ZZ][ZZ]) + 1;
246 rvnorm = sqrt(sqr(d->recipcell[YY][YY]) + sqr(d->recipcell[ZZ][YY]));
247 maxy = (int)(d->cutoff * rvnorm) + 1;
248 rvnorm = sqrt(sqr(d->recipcell[XX][XX]) + sqr(d->recipcell[YY][XX])
249 + sqr(d->recipcell[ZZ][XX]));
250 maxx = (int)(d->cutoff * rvnorm) + 1;
252 /* Calculate the number of cells and reallocate if necessary */
253 d->ngridnb = (2 * maxx + 1) * (2 * maxy + 1) * (2 * maxz + 1);
254 if (d->gnboffs_nalloc < d->ngridnb)
256 d->gnboffs_nalloc = d->ngridnb;
257 srenew(d->gnboffs, d->gnboffs_nalloc);
260 /* Store the whole cube */
261 /* TODO: Prune off corners that are not needed */
263 for (x = -maxx; x <= maxx; ++x)
265 for (y = -maxy; y <= maxy; ++y)
267 for (z = -maxz; z <= maxz; ++z)
269 d->gnboffs[i][XX] = x;
270 d->gnboffs[i][YY] = y;
271 d->gnboffs[i][ZZ] = z;
279 * Determines a suitable grid size.
281 * \param[in,out] d Grid information.
282 * \param[in] pbc Information about the box.
283 * \returns false if grid search is not suitable.
286 grid_setup_cells(gmx_ana_nbsearch_t *d, t_pbc *pbc)
292 targetsize = cbrt(pbc->box[XX][XX] * pbc->box[YY][YY] * pbc->box[ZZ][ZZ]
295 targetsize = pow(pbc->box[XX][XX] * pbc->box[YY][YY] * pbc->box[ZZ][ZZ]
296 * 10 / d->nref, (real)(1./3.));
300 for (dd = 0; dd < DIM; ++dd)
302 d->ncelldim[dd] = (int)(pbc->box[dd][dd] / targetsize);
303 d->ncells *= d->ncelldim[dd];
304 if (d->ncelldim[dd] < 3)
309 /* Reallocate if necessary */
310 if (d->cells_nalloc < d->ncells)
314 srenew(d->ncatoms, d->ncells);
315 srenew(d->catom, d->ncells);
316 srenew(d->catom_nalloc, d->ncells);
317 for (i = d->cells_nalloc; i < d->ncells; ++i)
320 d->catom_nalloc[i] = 0;
322 d->cells_nalloc = d->ncells;
328 * Sets ua a search grid for a given box.
330 * \param[in,out] d Grid information.
331 * \param[in] pbc Information about the box.
332 * \returns false if grid search is not suitable.
335 grid_set_box(gmx_ana_nbsearch_t *d, t_pbc *pbc)
339 /* TODO: This check could be improved. */
340 if (0.5*pbc->max_cutoff2 < d->cutoff2)
345 if (!grid_setup_cells(d, pbc))
350 d->bTric = TRICLINIC(pbc->box);
353 for (dd = 0; dd < DIM; ++dd)
355 svmul(1.0 / d->ncelldim[dd], pbc->box[dd], d->cellbox[dd]);
357 m_inv_ur0(d->cellbox, d->recipcell);
361 for (dd = 0; dd < DIM; ++dd)
363 d->cellbox[dd][dd] = pbc->box[dd][dd] / d->ncelldim[dd];
364 d->recipcell[dd][dd] = 1 / d->cellbox[dd][dd];
367 grid_init_cell_nblist(d, pbc);
372 * Maps a point into a grid cell.
374 * \param[in] d Grid information.
375 * \param[in] x Point to map.
376 * \param[out] cell Indices of the grid cell in which \p x lies.
378 * \p x should be in the triclinic unit cell.
381 grid_map_onto(gmx_ana_nbsearch_t *d, const rvec x, ivec cell)
389 tmvmul_ur0(d->recipcell, x, tx);
390 for (dd = 0; dd < DIM; ++dd)
392 cell[dd] = (int)tx[dd];
397 for (dd = 0; dd < DIM; ++dd)
399 cell[dd] = (int)(x[dd] * d->recipcell[dd][dd]);
405 * Calculates linear index of a grid cell.
407 * \param[in] d Grid information.
408 * \param[in] cell Cell indices.
409 * \returns Linear index of \p cell.
412 grid_index(gmx_ana_nbsearch_t *d, const ivec cell)
414 return cell[XX] + cell[YY] * d->ncelldim[XX]
415 + cell[ZZ] * d->ncelldim[XX] * d->ncelldim[YY];
419 * Clears all grid cells.
421 * \param[in,out] d Grid information.
424 grid_clear_cells(gmx_ana_nbsearch_t *d)
428 for (ci = 0; ci < d->ncells; ++ci)
435 * Adds an index into a grid cell.
437 * \param[in,out] d Grid information.
438 * \param[in] cell Cell into which \p i should be added.
439 * \param[in] i Index to add.
442 grid_add_to_cell(gmx_ana_nbsearch_t *d, const ivec cell, int i)
444 int ci = grid_index(d, cell);
446 if (d->ncatoms[ci] == d->catom_nalloc[ci])
448 d->catom_nalloc[ci] += 10;
449 srenew(d->catom[ci], d->catom_nalloc[ci]);
451 d->catom[ci][d->ncatoms[ci]++] = i;
455 * \param[in,out] d Neighborhood search data structure.
456 * \param[in] pbc PBC information for the frame.
457 * \param[in] n Number of reference positions for the frame.
458 * \param[in] x \p n reference positions for the frame.
460 * Initializes the data structure \p d such that it can be used to search
461 * for the neighbors of \p x.
464 gmx_ana_nbsearch_init(gmx_ana_nbsearch_t *d, t_pbc *pbc, int n, const rvec x[])
468 // TODO: Consider whether it would be possible to support grid searching in
470 if (pbc == NULL || pbc->ePBC != epbcXYZ)
474 else if (d->bTryGrid)
476 d->bGrid = grid_set_box(d, pbc);
482 if (d->xref_nalloc < n)
484 const int allocCount = std::max(d->maxnref, n);
485 srenew(d->xref_alloc, allocCount);
486 d->xref_nalloc = allocCount;
488 d->xref = d->xref_alloc;
491 for (i = 0; i < n; ++i)
493 copy_rvec(x[i], d->xref[i]);
495 put_atoms_in_triclinic_unitcell(ecenterTRIC, pbc->box, n, d->xref);
496 for (i = 0; i < n; ++i)
500 grid_map_onto(d, d->xref[i], refcell);
501 grid_add_to_cell(d, refcell, i);
506 // Won't be modified in this case, but when a grid is used,
507 // xref _is_ modified, so it can't be const.
508 d->xref = const_cast<rvec *>(x);
514 * \param[in,out] d Neighborhood search data structure.
515 * \param[in] pbc PBC information for the frame.
516 * \param[in] p Reference positions for the frame.
518 * A convenience wrapper for gmx_ana_nbsearch_init().
521 gmx_ana_nbsearch_pos_init(gmx_ana_nbsearch_t *d, t_pbc *pbc, const gmx_ana_pos_t *p)
523 gmx_ana_nbsearch_init(d, pbc, p->nr, p->x);
524 d->refid = p->m.refid;
528 * \param[in,out] d Neighborhood search data structure.
529 * \param[in] nexcl Number of reference positions to exclude from next
531 * \param[in] excl Indices of reference positions to exclude.
533 * The set exclusions remain in effect until the next call of this function.
536 gmx_ana_nbsearch_set_excl(gmx_ana_nbsearch_t *d, int nexcl, int excl[])
544 * Helper function to check whether a reference point should be excluded.
547 is_excluded(gmx_ana_nbsearch_t *d, int j)
549 if (d->exclind < d->nexcl)
553 while (d->exclind < d->nexcl &&d->refid[j] > d->excl[d->exclind])
557 if (d->exclind < d->nexcl && d->refid[j] == d->excl[d->exclind])
565 while (d->bGrid && d->exclind < d->nexcl && d->excl[d->exclind] < j)
569 if (d->excl[d->exclind] == j)
580 * Initializes a grid search to find reference positions neighboring \p x.
583 grid_search_start(gmx_ana_nbsearch_t *d, const rvec x)
585 copy_rvec(x, d->xtest);
588 put_atoms_in_triclinic_unitcell(ecenterTRIC, d->pbc->box, 1, &d->xtest);
589 grid_map_onto(d, d->xtest, d->testcell);
598 * Does a grid search.
601 grid_search(gmx_ana_nbsearch_t *d,
602 bool (*action)(gmx_ana_nbsearch_t *d, int i, real r2))
613 cai = d->prevcai + 1;
615 for (; nbi < d->ngridnb; ++nbi)
619 ivec_add(d->testcell, d->gnboffs[nbi], cell);
620 cell[XX] = (cell[XX] + d->ncelldim[XX]) % d->ncelldim[XX];
621 cell[YY] = (cell[YY] + d->ncelldim[YY]) % d->ncelldim[YY];
622 cell[ZZ] = (cell[ZZ] + d->ncelldim[ZZ]) % d->ncelldim[ZZ];
623 ci = grid_index(d, cell);
624 /* TODO: Calculate the required PBC shift outside the inner loop */
625 for (; cai < d->ncatoms[ci]; ++cai)
627 i = d->catom[ci][cai];
628 if (is_excluded(d, i))
632 pbc_dx_aiuc(d->pbc, d->xtest, d->xref[i], dx);
634 if (r2 <= d->cutoff2)
636 if (action(d, i, r2))
652 for (; i < d->nref; ++i)
654 if (is_excluded(d, i))
660 pbc_dx(d->pbc, d->xtest, d->xref[i], dx);
664 rvec_sub(d->xtest, d->xref[i], dx);
667 if (r2 <= d->cutoff2)
669 if (action(d, i, r2))
681 * Helper function to use with grid_search() to find the next neighbor.
683 * Simply breaks the loop on the first found neighbor.
686 within_action(gmx_ana_nbsearch_t *d, int i, real r2)
692 * Helper function to use with grid_search() to find the minimum distance.
695 mindist_action(gmx_ana_nbsearch_t *d, int i, real r2)
703 * \param[in] d Neighborhood search data structure.
704 * \param[in] x Test position.
705 * \returns true if \p x is within the cutoff of any reference position,
709 gmx_ana_nbsearch_is_within(gmx_ana_nbsearch_t *d, const rvec x)
711 grid_search_start(d, x);
712 return grid_search(d, &within_action);
716 * \param[in] d Neighborhood search data structure.
717 * \param[in] p Test positions.
718 * \param[in] i Use the i'th position in \p p for testing.
719 * \returns true if the test position is within the cutoff of any reference
720 * position, false otherwise.
723 gmx_ana_nbsearch_pos_is_within(gmx_ana_nbsearch_t *d, const gmx_ana_pos_t *p, int i)
725 return gmx_ana_nbsearch_is_within(d, p->x[i]);
729 * \param[in] d Neighborhood search data structure.
730 * \param[in] x Test position.
731 * \returns The distance to the nearest reference position, or the cutoff
732 * value if there are no reference positions within the cutoff.
735 gmx_ana_nbsearch_mindist(gmx_ana_nbsearch_t *d, const rvec x)
739 grid_search_start(d, x);
740 grid_search(d, &mindist_action);
741 mind = sqrt(d->cutoff2);
742 d->cutoff2 = sqr(d->cutoff);
747 * \param[in] d Neighborhood search data structure.
748 * \param[in] p Test positions.
749 * \param[in] i Use the i'th position in \p p for testing.
750 * \returns The distance to the nearest reference position, or the cutoff
751 * value if there are no reference positions within the cutoff.
754 gmx_ana_nbsearch_pos_mindist(gmx_ana_nbsearch_t *d, const gmx_ana_pos_t *p, int i)
756 return gmx_ana_nbsearch_mindist(d, p->x[i]);
760 * \param[in] d Neighborhood search data structure.
761 * \param[in] x Test positions.
762 * \param[out] jp Index of the reference position in the first pair.
763 * \returns true if there are positions within the cutoff.
766 gmx_ana_nbsearch_first_within(gmx_ana_nbsearch_t *d, const rvec x, int *jp)
768 grid_search_start(d, x);
769 return gmx_ana_nbsearch_next_within(d, jp);
773 * \param[in] d Neighborhood search data structure.
774 * \param[in] p Test positions.
775 * \param[in] i Use the i'th position in \p p.
776 * \param[out] jp Index of the reference position in the first pair.
777 * \returns true if there are positions within the cutoff.
780 gmx_ana_nbsearch_pos_first_within(gmx_ana_nbsearch_t *d, const gmx_ana_pos_t *p,
783 return gmx_ana_nbsearch_first_within(d, p->x[i], jp);
787 * \param[in] d Neighborhood search data structure.
788 * \param[out] jp Index of the test position in the next pair.
789 * \returns true if there are positions within the cutoff.
792 gmx_ana_nbsearch_next_within(gmx_ana_nbsearch_t *d, int *jp)
794 if (grid_search(d, &within_action))
809 /********************************************************************
810 * AnalysisNeighborhoodPairSearchImpl
813 class AnalysisNeighborhoodPairSearchImpl
816 explicit AnalysisNeighborhoodPairSearchImpl(gmx_ana_nbsearch_t *nb)
817 : nb_(nb), testIndex_(0)
821 gmx_ana_nbsearch_t *nb_;
825 /********************************************************************
826 * AnalysisNeighborhoodSearchImpl
829 class AnalysisNeighborhoodSearchImpl
832 typedef AnalysisNeighborhoodPairSearch::ImplPointer
833 PairSearchImplPointer;
835 // TODO: This is not strictly exception-safe.
836 AnalysisNeighborhoodSearchImpl(real cutoff)
837 : nb_(gmx_ana_nbsearch_create(cutoff, 0)),
838 pairSearch_(new AnalysisNeighborhoodPairSearchImpl(nb_))
840 bTryGrid_ = nb_->bTryGrid;
842 ~AnalysisNeighborhoodSearchImpl()
844 GMX_RELEASE_ASSERT(pairSearch_.unique(),
845 "Dangling AnalysisNeighborhoodPairSearch reference");
846 gmx_ana_nbsearch_free(nb_);
849 void setMode(AnalysisNeighborhood::SearchMode mode);
851 gmx_ana_nbsearch_t *nb_;
853 PairSearchImplPointer pairSearch_;
856 void AnalysisNeighborhoodSearchImpl::setMode(AnalysisNeighborhood::SearchMode mode)
858 // TODO: Actually implement eSearchMode_Grid.
861 case AnalysisNeighborhood::eSearchMode_Automatic:
862 nb_->bTryGrid = bTryGrid_;
864 case AnalysisNeighborhood::eSearchMode_Simple:
865 nb_->bTryGrid = false;
867 case AnalysisNeighborhood::eSearchMode_Grid:
868 nb_->bTryGrid = bTryGrid_;
873 } // namespace internal
875 /********************************************************************
876 * AnalysisNeighborhood::Impl
879 class AnalysisNeighborhood::Impl
882 typedef AnalysisNeighborhoodSearch::ImplPointer SearchImplPointer;
883 typedef std::vector<SearchImplPointer> SearchList;
885 Impl() : cutoff_(0), mode_(eSearchMode_Automatic)
890 SearchList::const_iterator i;
891 for (i = searchList_.begin(); i != searchList_.end(); ++i)
893 GMX_RELEASE_ASSERT(i->unique(),
894 "Dangling AnalysisNeighborhoodSearch reference");
898 SearchImplPointer getSearch();
900 tMPI::mutex createSearchMutex_;
901 SearchList searchList_;
906 AnalysisNeighborhood::Impl::SearchImplPointer
907 AnalysisNeighborhood::Impl::getSearch()
909 tMPI::lock_guard<tMPI::mutex> lock(createSearchMutex_);
910 // TODO: Consider whether this needs to/can be faster, e.g., by keeping a
911 // separate pool of unused search objects.
912 SearchList::const_iterator i;
913 for (i = searchList_.begin(); i != searchList_.end(); ++i)
920 SearchImplPointer search(new internal::AnalysisNeighborhoodSearchImpl(cutoff_));
921 searchList_.push_back(search);
925 /********************************************************************
926 * AnalysisNeighborhood
929 AnalysisNeighborhood::AnalysisNeighborhood()
934 AnalysisNeighborhood::~AnalysisNeighborhood()
938 void AnalysisNeighborhood::setCutoff(real cutoff)
940 GMX_RELEASE_ASSERT(impl_->searchList_.empty(),
941 "Changing the cutoff after initSearch() not currently supported");
942 impl_->cutoff_ = cutoff;
945 void AnalysisNeighborhood::setMode(SearchMode mode)
950 AnalysisNeighborhood::SearchMode AnalysisNeighborhood::mode() const
955 AnalysisNeighborhoodSearch
956 AnalysisNeighborhood::initSearch(const t_pbc *pbc, int n, const rvec x[])
958 Impl::SearchImplPointer search(impl_->getSearch());
959 search->setMode(mode());
960 gmx_ana_nbsearch_init(search->nb_, const_cast<t_pbc *>(pbc), n, x);
961 return AnalysisNeighborhoodSearch(search);
964 AnalysisNeighborhoodSearch
965 AnalysisNeighborhood::initSearch(const t_pbc *pbc, const gmx_ana_pos_t *p)
967 Impl::SearchImplPointer search(impl_->getSearch());
968 search->setMode(mode());
969 gmx_ana_nbsearch_pos_init(search->nb_, const_cast<t_pbc *>(pbc), p);
970 return AnalysisNeighborhoodSearch(search);
973 /********************************************************************
974 * AnalysisNeighborhoodSearch
977 AnalysisNeighborhoodSearch::AnalysisNeighborhoodSearch()
981 AnalysisNeighborhoodSearch::AnalysisNeighborhoodSearch(const ImplPointer &impl)
986 void AnalysisNeighborhoodSearch::reset()
991 AnalysisNeighborhood::SearchMode AnalysisNeighborhoodSearch::mode() const
993 GMX_RELEASE_ASSERT(impl_, "Accessing an invalid search object");
994 return (impl_->nb_->bGrid
995 ? AnalysisNeighborhood::eSearchMode_Grid
996 : AnalysisNeighborhood::eSearchMode_Simple);
999 bool AnalysisNeighborhoodSearch::isWithin(const rvec x) const
1001 GMX_RELEASE_ASSERT(impl_, "Accessing an invalid search object");
1002 GMX_RELEASE_ASSERT(impl_->pairSearch_.unique(),
1003 "Calls to other methods concurrently with a pair search "
1004 "not currently supported");
1005 return gmx_ana_nbsearch_is_within(impl_->nb_, x);
1008 bool AnalysisNeighborhoodSearch::isWithin(const gmx_ana_pos_t *p, int i) const
1010 GMX_RELEASE_ASSERT(impl_, "Accessing an invalid search object");
1011 GMX_RELEASE_ASSERT(impl_->pairSearch_.unique(),
1012 "Calls to other methods concurrently with a pair search "
1013 "not currently supported");
1014 return gmx_ana_nbsearch_pos_is_within(impl_->nb_, p, i);
1017 real AnalysisNeighborhoodSearch::minimumDistance(const rvec x) const
1019 GMX_RELEASE_ASSERT(impl_, "Accessing an invalid search object");
1020 GMX_RELEASE_ASSERT(impl_->pairSearch_.unique(),
1021 "Calls to other methods concurrently with a pair search "
1022 "not currently supported");
1023 return gmx_ana_nbsearch_mindist(impl_->nb_, x);
1026 real AnalysisNeighborhoodSearch::minimumDistance(const gmx_ana_pos_t *p, int i) const
1028 GMX_RELEASE_ASSERT(impl_, "Accessing an invalid search object");
1029 GMX_RELEASE_ASSERT(impl_->pairSearch_.unique(),
1030 "Calls to other methods concurrently with a pair search "
1031 "not currently supported");
1032 return gmx_ana_nbsearch_pos_mindist(impl_->nb_, p, i);
1035 AnalysisNeighborhoodPair
1036 AnalysisNeighborhoodSearch::nearestPoint(const rvec x) const
1038 GMX_RELEASE_ASSERT(impl_, "Accessing an invalid search object");
1039 GMX_RELEASE_ASSERT(impl_->pairSearch_.unique(),
1040 "Calls to other methods concurrently with a pair search "
1041 "not currently supported");
1042 (void)gmx_ana_nbsearch_mindist(impl_->nb_, x);
1043 return AnalysisNeighborhoodPair(impl_->nb_->previ, 0);
1046 AnalysisNeighborhoodPair
1047 AnalysisNeighborhoodSearch::nearestPoint(const gmx_ana_pos_t *p, int i) const
1049 GMX_RELEASE_ASSERT(impl_, "Accessing an invalid search object");
1050 GMX_RELEASE_ASSERT(impl_->pairSearch_.unique(),
1051 "Calls to other methods concurrently with a pair search "
1052 "not currently supported");
1053 (void)gmx_ana_nbsearch_pos_mindist(impl_->nb_, p, i);
1054 return AnalysisNeighborhoodPair(impl_->nb_->previ, i);
1057 AnalysisNeighborhoodPairSearch
1058 AnalysisNeighborhoodSearch::startPairSearch(const rvec x)
1060 GMX_RELEASE_ASSERT(impl_, "Accessing an invalid search object");
1061 GMX_RELEASE_ASSERT(impl_->pairSearch_.unique(),
1062 "Multiple concurrent searches not currently supported");
1063 grid_search_start(impl_->nb_, x);
1064 impl_->pairSearch_->testIndex_ = 0;
1065 return AnalysisNeighborhoodPairSearch(impl_->pairSearch_);
1068 AnalysisNeighborhoodPairSearch
1069 AnalysisNeighborhoodSearch::startPairSearch(const gmx_ana_pos_t *p, int i)
1071 GMX_RELEASE_ASSERT(impl_, "Accessing an invalid search object");
1072 GMX_RELEASE_ASSERT(impl_->pairSearch_.unique(),
1073 "Multiple concurrent searches not currently supported");
1074 grid_search_start(impl_->nb_, p->x[i]);
1075 impl_->pairSearch_->testIndex_ = i;
1076 return AnalysisNeighborhoodPairSearch(impl_->pairSearch_);
1079 /********************************************************************
1080 * AnalysisNeighborhoodPairSearch
1083 AnalysisNeighborhoodPairSearch::AnalysisNeighborhoodPairSearch(
1084 const ImplPointer &impl)
1089 bool AnalysisNeighborhoodPairSearch::findNextPair(AnalysisNeighborhoodPair *pair)
1091 if (grid_search(impl_->nb_, &within_action))
1093 *pair = AnalysisNeighborhoodPair(impl_->nb_->previ, impl_->testIndex_);
1096 *pair = AnalysisNeighborhoodPair();