2 * This file is part of the GROMACS molecular simulation package.
4 * Copyright (c) 2009,2010,2011,2012, 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.
36 * \brief API for neighborhood searching.
38 * The API is documented in more detail on a separate page:
41 * The functions within this file can be used independently of the other parts
43 * The library also uses the functions internally.
45 * \author Teemu Murtola <teemu.murtola@gmail.com>
46 * \ingroup module_selection
48 #ifndef GMX_SELECTION_NBSEARCH_H
49 #define GMX_SELECTION_NBSEARCH_H
51 #include "../legacyheaders/typedefs.h"
53 #include "indexutil.h"
57 /** Data structure for neighborhood searches. */
58 typedef struct gmx_ana_nbsearch_t gmx_ana_nbsearch_t;
60 /** Create a new neighborhood search data structure. */
62 gmx_ana_nbsearch_create(real cutoff, int maxn);
63 /** Free memory allocated for neighborhood search. */
65 gmx_ana_nbsearch_free(gmx_ana_nbsearch_t *d);
67 /** Initializes neighborhood search for a new frame. */
69 gmx_ana_nbsearch_init(gmx_ana_nbsearch_t *d, t_pbc *pbc, int n, const rvec x[]);
70 /** Initializes neighborhood search for a frame using \c gmx_ana_pos_t. */
72 gmx_ana_nbsearch_pos_init(gmx_ana_nbsearch_t *d, t_pbc *pbc,
73 const struct gmx_ana_pos_t *p);
74 /** Sets the exclusions for the next neighborhood search. */
76 gmx_ana_nbsearch_set_excl(gmx_ana_nbsearch_t *d, int nexcl, int excl[]);
77 /** Check whether a point is within a neighborhood. */
79 gmx_ana_nbsearch_is_within(gmx_ana_nbsearch_t *d, const rvec x);
80 /** Check whether a position is within a neighborhood. */
82 gmx_ana_nbsearch_pos_is_within(gmx_ana_nbsearch_t *d,
83 const struct gmx_ana_pos_t *p, int i);
84 /** Calculates the minimun distance from the reference points. */
86 gmx_ana_nbsearch_mindist(gmx_ana_nbsearch_t *d, const rvec x);
87 /** Calculates the minimun distance from the reference points. */
89 gmx_ana_nbsearch_pos_mindist(gmx_ana_nbsearch_t *d,
90 const struct gmx_ana_pos_t *p, int i);
91 /** Finds the first reference position within the cutoff. */
93 gmx_ana_nbsearch_first_within(gmx_ana_nbsearch_t *d, const rvec x, int *jp);
94 /** Finds the first reference position within the cutoff. */
96 gmx_ana_nbsearch_pos_first_within(gmx_ana_nbsearch_t *d,
97 const struct gmx_ana_pos_t *p, int i, int *jp);
98 /** Finds the next reference position within the cutoff. */
100 gmx_ana_nbsearch_next_within(gmx_ana_nbsearch_t *d, int *jp);
106 * C++ wrapper for neighborhood searching.
109 class NeighborhoodSearch
112 NeighborhoodSearch(real cutoff, int maxn)
113 : d_(gmx_ana_nbsearch_create(cutoff, maxn))
116 ~NeighborhoodSearch() { gmx_ana_nbsearch_free(d_); }
118 void init(t_pbc *pbc, int n, const rvec x[])
119 { gmx_ana_nbsearch_init(d_, pbc, n, x); }
121 void init(t_pbc *pbc, const gmx_ana_pos_t *p)
122 { gmx_ana_nbsearch_pos_init(d_, pbc, p); }
124 void setExclusions(int nexcl, atom_id *excl)
125 { gmx_ana_nbsearch_set_excl(d_, nexcl, excl); }
128 bool isWithin(const rvec x)
129 { return gmx_ana_nbsearch_is_within(d_, x); }
131 bool isWithin(const gmx_ana_pos_t *p, int i)
132 { return gmx_ana_nbsearch_pos_is_within(d_, p, i); }
134 real minimumDistance(const rvec x)
135 { return gmx_ana_nbsearch_mindist(d_, x); }
137 real minimumDistance(const gmx_ana_pos_t *p, int i)
138 { return gmx_ana_nbsearch_pos_mindist(d_, p, i); }
140 bool firstWithin(const rvec x, int *jp)
141 { return gmx_ana_nbsearch_first_within(d_, x, jp); }
143 bool firstWithin(const gmx_ana_pos_t *p, int i, int *jp)
144 { return gmx_ana_nbsearch_pos_first_within(d_, p, i, jp); }
146 bool nextWithin(int *jp)
147 { return gmx_ana_nbsearch_next_within(d_, jp); }
150 gmx_ana_nbsearch_t *d_;