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
81 #include "gromacs/legacyheaders/smalloc.h"
82 #include "gromacs/legacyheaders/typedefs.h"
83 #include "gromacs/legacyheaders/pbc.h"
84 #include "gromacs/legacyheaders/vec.h"
86 #include "gromacs/selection/nbsearch.h"
87 #include "gromacs/selection/position.h"
88 #include "gromacs/utility/gmxassert.h"
91 * Data structure for neighborhood searches.
93 struct gmx_ana_nbsearch_t
97 /** The cutoff squared. */
99 /** Maximum number of reference points. */
102 /** Number of reference points for the current frame. */
104 /** Reference point positions. */
106 /** Reference position ids (NULL if not available). */
111 /** Number of excluded reference positions for current test particle. */
113 /** Exclusions for current test particle. */
116 /** Whether to try grid searching. */
118 /** Whether grid searching is actually used for the current positions. */
120 /** Array allocated for storing in-unit-cell reference positions. */
122 /** Allocation count for xref_alloc. */
124 /** false if the box is rectangular. */
126 /** Box vectors of a single grid cell. */
128 /** The reciprocal cell vectors as columns; the inverse of \p cellbox. */
130 /** Number of cells along each dimension. */
132 /** Total number of cells. */
134 /** Number of reference positions in each cell. */
136 /** List of reference positions in each cell. */
138 /** Allocation counts for each \p catom[i]. */
140 /** Allocation count for the per-cell arrays. */
142 /** Number of neighboring cells to consider. */
144 /** Offsets of the neighboring cells to consider. */
146 /** Allocation count for \p gnboffs. */
149 /** Stores test position during a pair loop. */
151 /** Stores the previous returned position during a pair loop. */
153 /** Stores the current exclusion index during loops. */
155 /** Stores the test particle cell index during loops. */
157 /** Stores the current cell neighbor index during pair loops. */
159 /** Stores the index within the current cell during pair loops. */
164 * \param[in] cutoff Cutoff distance for the search
165 * (<=0 stands for no cutoff).
166 * \param[in] maxn Maximum number of reference particles.
167 * \returns Created neighborhood search data structure.
170 gmx_ana_nbsearch_create(real cutoff, int maxn)
172 gmx_ana_nbsearch_t *d;
178 cutoff = GMX_REAL_MAX;
182 d->cutoff2 = sqr(cutoff);
189 d->xref_alloc = NULL;
199 d->gnboffs_nalloc = 0;
205 * \param d Data structure to free.
207 * After the call, the pointer \p d is no longer valid.
210 gmx_ana_nbsearch_free(gmx_ana_nbsearch_t *d)
212 sfree(d->xref_alloc);
218 for (ci = 0; ci < d->ncells; ++ci)
224 sfree(d->catom_nalloc);
230 * Calculates offsets to neighboring grid cells that should be considered.
232 * \param[in,out] d Grid information.
233 * \param[in] pbc Information about the box.
236 grid_init_cell_nblist(gmx_ana_nbsearch_t *d, t_pbc *pbc)
238 int maxx, maxy, maxz;
242 /* Find the extent of the sphere in triclinic coordinates */
243 maxz = (int)(d->cutoff * d->recipcell[ZZ][ZZ]) + 1;
244 rvnorm = sqrt(sqr(d->recipcell[YY][YY]) + sqr(d->recipcell[ZZ][YY]));
245 maxy = (int)(d->cutoff * rvnorm) + 1;
246 rvnorm = sqrt(sqr(d->recipcell[XX][XX]) + sqr(d->recipcell[YY][XX])
247 + sqr(d->recipcell[ZZ][XX]));
248 maxx = (int)(d->cutoff * rvnorm) + 1;
250 /* Calculate the number of cells and reallocate if necessary */
251 d->ngridnb = (2 * maxx + 1) * (2 * maxy + 1) * (2 * maxz + 1);
252 if (d->gnboffs_nalloc < d->ngridnb)
254 d->gnboffs_nalloc = d->ngridnb;
255 srenew(d->gnboffs, d->gnboffs_nalloc);
258 /* Store the whole cube */
259 /* TODO: Prune off corners that are not needed */
261 for (x = -maxx; x <= maxx; ++x)
263 for (y = -maxy; y <= maxy; ++y)
265 for (z = -maxz; z <= maxz; ++z)
267 d->gnboffs[i][XX] = x;
268 d->gnboffs[i][YY] = y;
269 d->gnboffs[i][ZZ] = z;
277 * Determines a suitable grid size.
279 * \param[in,out] d Grid information.
280 * \param[in] pbc Information about the box.
281 * \returns false if grid search is not suitable.
284 grid_setup_cells(gmx_ana_nbsearch_t *d, t_pbc *pbc)
290 targetsize = cbrt(pbc->box[XX][XX] * pbc->box[YY][YY] * pbc->box[ZZ][ZZ]
293 targetsize = pow(pbc->box[XX][XX] * pbc->box[YY][YY] * pbc->box[ZZ][ZZ]
294 * 10 / d->nref, (real)(1./3.));
298 for (dd = 0; dd < DIM; ++dd)
300 d->ncelldim[dd] = (int)(pbc->box[dd][dd] / targetsize);
301 d->ncells *= d->ncelldim[dd];
302 if (d->ncelldim[dd] < 3)
307 /* Reallocate if necessary */
308 if (d->cells_nalloc < d->ncells)
312 srenew(d->ncatoms, d->ncells);
313 srenew(d->catom, d->ncells);
314 srenew(d->catom_nalloc, d->ncells);
315 for (i = d->cells_nalloc; i < d->ncells; ++i)
318 d->catom_nalloc[i] = 0;
320 d->cells_nalloc = d->ncells;
326 * Sets ua a search grid for a given box.
328 * \param[in,out] d Grid information.
329 * \param[in] pbc Information about the box.
330 * \returns false if grid search is not suitable.
333 grid_set_box(gmx_ana_nbsearch_t *d, t_pbc *pbc)
337 /* TODO: This check could be improved. */
338 if (0.5*pbc->max_cutoff2 < d->cutoff2)
343 if (!grid_setup_cells(d, pbc))
348 d->bTric = TRICLINIC(pbc->box);
351 for (dd = 0; dd < DIM; ++dd)
353 svmul(1.0 / d->ncelldim[dd], pbc->box[dd], d->cellbox[dd]);
355 m_inv_ur0(d->cellbox, d->recipcell);
359 for (dd = 0; dd < DIM; ++dd)
361 d->cellbox[dd][dd] = pbc->box[dd][dd] / d->ncelldim[dd];
362 d->recipcell[dd][dd] = 1 / d->cellbox[dd][dd];
365 grid_init_cell_nblist(d, pbc);
370 * Maps a point into a grid cell.
372 * \param[in] d Grid information.
373 * \param[in] x Point to map.
374 * \param[out] cell Indices of the grid cell in which \p x lies.
376 * \p x should be in the triclinic unit cell.
379 grid_map_onto(gmx_ana_nbsearch_t *d, const rvec x, ivec cell)
387 tmvmul_ur0(d->recipcell, x, tx);
388 for (dd = 0; dd < DIM; ++dd)
390 cell[dd] = (int)tx[dd];
395 for (dd = 0; dd < DIM; ++dd)
397 cell[dd] = (int)(x[dd] * d->recipcell[dd][dd]);
403 * Calculates linear index of a grid cell.
405 * \param[in] d Grid information.
406 * \param[in] cell Cell indices.
407 * \returns Linear index of \p cell.
410 grid_index(gmx_ana_nbsearch_t *d, const ivec cell)
412 return cell[XX] + cell[YY] * d->ncelldim[XX]
413 + cell[ZZ] * d->ncelldim[XX] * d->ncelldim[YY];
417 * Clears all grid cells.
419 * \param[in,out] d Grid information.
422 grid_clear_cells(gmx_ana_nbsearch_t *d)
426 for (ci = 0; ci < d->ncells; ++ci)
433 * Adds an index into a grid cell.
435 * \param[in,out] d Grid information.
436 * \param[in] cell Cell into which \p i should be added.
437 * \param[in] i Index to add.
440 grid_add_to_cell(gmx_ana_nbsearch_t *d, const ivec cell, int i)
442 int ci = grid_index(d, cell);
444 if (d->ncatoms[ci] == d->catom_nalloc[ci])
446 d->catom_nalloc[ci] += 10;
447 srenew(d->catom[ci], d->catom_nalloc[ci]);
449 d->catom[ci][d->ncatoms[ci]++] = i;
453 * \param[in,out] d Neighborhood search data structure.
454 * \param[in] pbc PBC information for the frame.
455 * \param[in] n Number of reference positions for the frame.
456 * \param[in] x \p n reference positions for the frame.
458 * Initializes the data structure \p d such that it can be used to search
459 * for the neighbors of \p x.
462 gmx_ana_nbsearch_init(gmx_ana_nbsearch_t *d, t_pbc *pbc, int n, const rvec x[])
466 // TODO: Consider whether it would be possible to support grid searching in
468 if (pbc == NULL || pbc->ePBC != epbcXYZ)
472 else if (d->bTryGrid)
474 d->bGrid = grid_set_box(d, pbc);
480 if (d->xref_nalloc < n)
482 const int allocCount = std::max(d->maxnref, n);
483 srenew(d->xref_alloc, allocCount);
484 d->xref_nalloc = allocCount;
486 d->xref = d->xref_alloc;
489 for (i = 0; i < n; ++i)
491 copy_rvec(x[i], d->xref[i]);
493 put_atoms_in_triclinic_unitcell(ecenterTRIC, pbc->box, n, d->xref);
494 for (i = 0; i < n; ++i)
498 grid_map_onto(d, d->xref[i], refcell);
499 grid_add_to_cell(d, refcell, i);
504 // Won't be modified in this case, but when a grid is used,
505 // xref _is_ modified, so it can't be const.
506 d->xref = const_cast<rvec *>(x);
512 * \param[in,out] d Neighborhood search data structure.
513 * \param[in] pbc PBC information for the frame.
514 * \param[in] p Reference positions for the frame.
516 * A convenience wrapper for gmx_ana_nbsearch_init().
519 gmx_ana_nbsearch_pos_init(gmx_ana_nbsearch_t *d, t_pbc *pbc, const gmx_ana_pos_t *p)
521 gmx_ana_nbsearch_init(d, pbc, p->nr, p->x);
522 d->refid = p->m.refid;
526 * \param[in,out] d Neighborhood search data structure.
527 * \param[in] nexcl Number of reference positions to exclude from next
529 * \param[in] excl Indices of reference positions to exclude.
531 * The set exclusions remain in effect until the next call of this function.
534 gmx_ana_nbsearch_set_excl(gmx_ana_nbsearch_t *d, int nexcl, int excl[])
542 * Helper function to check whether a reference point should be excluded.
545 is_excluded(gmx_ana_nbsearch_t *d, int j)
547 if (d->exclind < d->nexcl)
551 while (d->exclind < d->nexcl &&d->refid[j] > d->excl[d->exclind])
555 if (d->exclind < d->nexcl && d->refid[j] == d->excl[d->exclind])
563 while (d->bGrid && d->exclind < d->nexcl && d->excl[d->exclind] < j)
567 if (d->excl[d->exclind] == j)
578 * Initializes a grid search to find reference positions neighboring \p x.
581 grid_search_start(gmx_ana_nbsearch_t *d, const rvec x)
583 copy_rvec(x, d->xtest);
586 put_atoms_in_triclinic_unitcell(ecenterTRIC, d->pbc->box, 1, &d->xtest);
587 grid_map_onto(d, d->xtest, d->testcell);
596 * Does a grid search.
599 grid_search(gmx_ana_nbsearch_t *d,
600 bool (*action)(gmx_ana_nbsearch_t *d, int i, real r2))
611 cai = d->prevcai + 1;
613 for (; nbi < d->ngridnb; ++nbi)
617 ivec_add(d->testcell, d->gnboffs[nbi], cell);
618 cell[XX] = (cell[XX] + d->ncelldim[XX]) % d->ncelldim[XX];
619 cell[YY] = (cell[YY] + d->ncelldim[YY]) % d->ncelldim[YY];
620 cell[ZZ] = (cell[ZZ] + d->ncelldim[ZZ]) % d->ncelldim[ZZ];
621 ci = grid_index(d, cell);
622 /* TODO: Calculate the required PBC shift outside the inner loop */
623 for (; cai < d->ncatoms[ci]; ++cai)
625 i = d->catom[ci][cai];
626 if (is_excluded(d, i))
630 pbc_dx_aiuc(d->pbc, d->xtest, d->xref[i], dx);
632 if (r2 <= d->cutoff2)
634 if (action(d, i, r2))
650 for (; i < d->nref; ++i)
652 if (is_excluded(d, i))
658 pbc_dx(d->pbc, d->xtest, d->xref[i], dx);
662 rvec_sub(d->xtest, d->xref[i], dx);
665 if (r2 <= d->cutoff2)
667 if (action(d, i, r2))
679 * Helper function to use with grid_search() to find the next neighbor.
681 * Simply breaks the loop on the first found neighbor.
684 within_action(gmx_ana_nbsearch_t *d, int i, real r2)
690 * Helper function to use with grid_search() to find the minimum distance.
693 mindist_action(gmx_ana_nbsearch_t *d, int i, real r2)
701 * \param[in] d Neighborhood search data structure.
702 * \param[in] x Test position.
703 * \returns true if \p x is within the cutoff of any reference position,
707 gmx_ana_nbsearch_is_within(gmx_ana_nbsearch_t *d, const rvec x)
709 grid_search_start(d, x);
710 return grid_search(d, &within_action);
714 * \param[in] d Neighborhood search data structure.
715 * \param[in] p Test positions.
716 * \param[in] i Use the i'th position in \p p for testing.
717 * \returns true if the test position is within the cutoff of any reference
718 * position, false otherwise.
721 gmx_ana_nbsearch_pos_is_within(gmx_ana_nbsearch_t *d, const gmx_ana_pos_t *p, int i)
723 return gmx_ana_nbsearch_is_within(d, p->x[i]);
727 * \param[in] d Neighborhood search data structure.
728 * \param[in] x Test position.
729 * \returns The distance to the nearest reference position, or the cutoff
730 * value if there are no reference positions within the cutoff.
733 gmx_ana_nbsearch_mindist(gmx_ana_nbsearch_t *d, const rvec x)
737 grid_search_start(d, x);
738 grid_search(d, &mindist_action);
739 mind = sqrt(d->cutoff2);
740 d->cutoff2 = sqr(d->cutoff);
745 * \param[in] d Neighborhood search data structure.
746 * \param[in] p Test positions.
747 * \param[in] i Use the i'th position in \p p for testing.
748 * \returns The distance to the nearest reference position, or the cutoff
749 * value if there are no reference positions within the cutoff.
752 gmx_ana_nbsearch_pos_mindist(gmx_ana_nbsearch_t *d, const gmx_ana_pos_t *p, int i)
754 return gmx_ana_nbsearch_mindist(d, p->x[i]);
758 * \param[in] d Neighborhood search data structure.
759 * \param[in] x Test positions.
760 * \param[out] jp Index of the reference position in the first pair.
761 * \returns true if there are positions within the cutoff.
764 gmx_ana_nbsearch_first_within(gmx_ana_nbsearch_t *d, const rvec x, int *jp)
766 grid_search_start(d, x);
767 return gmx_ana_nbsearch_next_within(d, jp);
771 * \param[in] d Neighborhood search data structure.
772 * \param[in] p Test positions.
773 * \param[in] i Use the i'th position in \p p.
774 * \param[out] jp Index of the reference position in the first pair.
775 * \returns true if there are positions within the cutoff.
778 gmx_ana_nbsearch_pos_first_within(gmx_ana_nbsearch_t *d, const gmx_ana_pos_t *p,
781 return gmx_ana_nbsearch_first_within(d, p->x[i], jp);
785 * \param[in] d Neighborhood search data structure.
786 * \param[out] jp Index of the test position in the next pair.
787 * \returns true if there are positions within the cutoff.
790 gmx_ana_nbsearch_next_within(gmx_ana_nbsearch_t *d, int *jp)
792 if (grid_search(d, &within_action))
807 /********************************************************************
808 * AnalysisNeighborhoodPairSearchImpl
811 class AnalysisNeighborhoodPairSearchImpl
814 AnalysisNeighborhoodPairSearchImpl()
815 : nb_(NULL), testIndex_(0)
819 gmx_ana_nbsearch_t *nb_;
823 /********************************************************************
824 * AnalysisNeighborhoodSearchImpl
827 class AnalysisNeighborhoodSearchImpl
830 typedef AnalysisNeighborhoodPairSearch::ImplPointer
831 PairSearchImplPointer;
833 AnalysisNeighborhoodSearchImpl()
834 : nb_(NULL), pairSearch_(new AnalysisNeighborhoodPairSearchImpl)
837 ~AnalysisNeighborhoodSearchImpl()
839 GMX_RELEASE_ASSERT(pairSearch_.unique(),
840 "Dangling AnalysisNeighborhoodPairSearch reference");
843 gmx_ana_nbsearch_free(nb_);
847 gmx_ana_nbsearch_t *nb_;
848 PairSearchImplPointer pairSearch_;
851 } // namespace internal
853 /********************************************************************
854 * AnalysisNeighborhood::Impl
857 class AnalysisNeighborhood::Impl
860 typedef AnalysisNeighborhoodSearch::ImplPointer SearchImplPointer;
863 : search_(new internal::AnalysisNeighborhoodSearchImpl), bTryGrid_(false)
868 GMX_RELEASE_ASSERT(search_.unique(),
869 "Dangling AnalysisNeighborhoodSearch reference");
872 SearchImplPointer search_;
876 /********************************************************************
877 * AnalysisNeighborhood
880 AnalysisNeighborhood::AnalysisNeighborhood()
885 AnalysisNeighborhood::~AnalysisNeighborhood()
889 void AnalysisNeighborhood::setCutoff(real cutoff)
891 GMX_RELEASE_ASSERT(impl_->search_->nb_ == NULL,
892 "Multiple calls to setCutoff() not currently supported");
893 impl_->search_->nb_ = gmx_ana_nbsearch_create(cutoff, 0);
894 impl_->search_->pairSearch_->nb_ = impl_->search_->nb_;
895 impl_->bTryGrid_ = impl_->search_->nb_->bTryGrid;
898 void AnalysisNeighborhood::setMode(SearchMode mode)
900 GMX_RELEASE_ASSERT(impl_->search_->nb_ != NULL,
901 "setParameters() not called");
902 // TODO: Actually implement eSearchMode_Grid.
905 case eSearchMode_Automatic:
906 impl_->search_->nb_->bTryGrid = impl_->bTryGrid_;
908 case eSearchMode_Simple:
909 impl_->search_->nb_->bTryGrid = false;
911 case eSearchMode_Grid:
912 impl_->search_->nb_->bTryGrid = impl_->bTryGrid_;
917 AnalysisNeighborhood::SearchMode AnalysisNeighborhood::mode() const
919 GMX_RELEASE_ASSERT(impl_->search_->nb_ != NULL,
920 "setParameters() not called");
921 if (!impl_->search_->nb_->bTryGrid)
923 return eSearchMode_Simple;
925 return eSearchMode_Automatic;
928 AnalysisNeighborhoodSearch
929 AnalysisNeighborhood::initSearch(const t_pbc *pbc, int n, const rvec x[])
931 GMX_RELEASE_ASSERT(impl_->search_->nb_ != NULL,
932 "setParameters() not called");
933 GMX_RELEASE_ASSERT(impl_->search_.unique(),
934 "Multiple concurrent searches not currently supported");
935 gmx_ana_nbsearch_init(impl_->search_->nb_, const_cast<t_pbc *>(pbc), n, x);
936 return AnalysisNeighborhoodSearch(impl_->search_);
939 AnalysisNeighborhoodSearch
940 AnalysisNeighborhood::initSearch(const t_pbc *pbc, const gmx_ana_pos_t *p)
942 GMX_RELEASE_ASSERT(impl_->search_->nb_ != NULL,
943 "setParameters() not called");
944 GMX_RELEASE_ASSERT(impl_->search_.unique(),
945 "Multiple concurrent searches not currently supported");
946 gmx_ana_nbsearch_pos_init(impl_->search_->nb_, const_cast<t_pbc *>(pbc), p);
947 return AnalysisNeighborhoodSearch(impl_->search_);
950 /********************************************************************
951 * AnalysisNeighborhoodSearch
954 AnalysisNeighborhoodSearch::AnalysisNeighborhoodSearch()
958 AnalysisNeighborhoodSearch::AnalysisNeighborhoodSearch(const ImplPointer &impl)
963 void AnalysisNeighborhoodSearch::reset()
968 AnalysisNeighborhood::SearchMode AnalysisNeighborhoodSearch::mode() const
970 GMX_RELEASE_ASSERT(impl_, "Accessing an invalid search object");
971 return (impl_->nb_->bGrid
972 ? AnalysisNeighborhood::eSearchMode_Grid
973 : AnalysisNeighborhood::eSearchMode_Simple);
976 bool AnalysisNeighborhoodSearch::isWithin(const rvec x) const
978 GMX_RELEASE_ASSERT(impl_, "Accessing an invalid search object");
979 GMX_RELEASE_ASSERT(impl_->pairSearch_.unique(),
980 "Calls to other methods concurrently with a pair search "
981 "not currently supported");
982 return gmx_ana_nbsearch_is_within(impl_->nb_, x);
985 bool AnalysisNeighborhoodSearch::isWithin(const gmx_ana_pos_t *p, int i) const
987 GMX_RELEASE_ASSERT(impl_, "Accessing an invalid search object");
988 GMX_RELEASE_ASSERT(impl_->pairSearch_.unique(),
989 "Calls to other methods concurrently with a pair search "
990 "not currently supported");
991 return gmx_ana_nbsearch_pos_is_within(impl_->nb_, p, i);
994 real AnalysisNeighborhoodSearch::minimumDistance(const rvec x) const
996 GMX_RELEASE_ASSERT(impl_, "Accessing an invalid search object");
997 GMX_RELEASE_ASSERT(impl_->pairSearch_.unique(),
998 "Calls to other methods concurrently with a pair search "
999 "not currently supported");
1000 return gmx_ana_nbsearch_mindist(impl_->nb_, x);
1003 real AnalysisNeighborhoodSearch::minimumDistance(const gmx_ana_pos_t *p, int i) const
1005 GMX_RELEASE_ASSERT(impl_, "Accessing an invalid search object");
1006 GMX_RELEASE_ASSERT(impl_->pairSearch_.unique(),
1007 "Calls to other methods concurrently with a pair search "
1008 "not currently supported");
1009 return gmx_ana_nbsearch_pos_mindist(impl_->nb_, p, i);
1012 AnalysisNeighborhoodPair
1013 AnalysisNeighborhoodSearch::nearestPoint(const rvec x) const
1015 GMX_RELEASE_ASSERT(impl_, "Accessing an invalid search object");
1016 GMX_RELEASE_ASSERT(impl_->pairSearch_.unique(),
1017 "Calls to other methods concurrently with a pair search "
1018 "not currently supported");
1019 (void)gmx_ana_nbsearch_mindist(impl_->nb_, x);
1020 return AnalysisNeighborhoodPair(impl_->nb_->previ, 0);
1023 AnalysisNeighborhoodPair
1024 AnalysisNeighborhoodSearch::nearestPoint(const gmx_ana_pos_t *p, int i) const
1026 GMX_RELEASE_ASSERT(impl_, "Accessing an invalid search object");
1027 GMX_RELEASE_ASSERT(impl_->pairSearch_.unique(),
1028 "Calls to other methods concurrently with a pair search "
1029 "not currently supported");
1030 (void)gmx_ana_nbsearch_pos_mindist(impl_->nb_, p, i);
1031 return AnalysisNeighborhoodPair(impl_->nb_->previ, i);
1034 AnalysisNeighborhoodPairSearch
1035 AnalysisNeighborhoodSearch::startPairSearch(const rvec x)
1037 GMX_RELEASE_ASSERT(impl_, "Accessing an invalid search object");
1038 GMX_RELEASE_ASSERT(impl_->pairSearch_.unique(),
1039 "Multiple concurrent searches not currently supported");
1040 grid_search_start(impl_->nb_, x);
1041 impl_->pairSearch_->testIndex_ = 0;
1042 return AnalysisNeighborhoodPairSearch(impl_->pairSearch_);
1045 AnalysisNeighborhoodPairSearch
1046 AnalysisNeighborhoodSearch::startPairSearch(const gmx_ana_pos_t *p, int i)
1048 GMX_RELEASE_ASSERT(impl_, "Accessing an invalid search object");
1049 GMX_RELEASE_ASSERT(impl_->pairSearch_.unique(),
1050 "Multiple concurrent searches not currently supported");
1051 grid_search_start(impl_->nb_, p->x[i]);
1052 impl_->pairSearch_->testIndex_ = i;
1053 return AnalysisNeighborhoodPairSearch(impl_->pairSearch_);
1056 /********************************************************************
1057 * AnalysisNeighborhoodPairSearch
1060 AnalysisNeighborhoodPairSearch::AnalysisNeighborhoodPairSearch(
1061 const ImplPointer &impl)
1066 bool AnalysisNeighborhoodPairSearch::findNextPair(AnalysisNeighborhoodPair *pair)
1068 if (grid_search(impl_->nb_, &within_action))
1070 *pair = AnalysisNeighborhoodPair(impl_->nb_->previ, impl_->testIndex_);
1073 *pair = AnalysisNeighborhoodPair();