Fix copyright notices for new C++ code.
[alexxy/gromacs.git] / src / gromacs / selection / nbsearch.h
1 /*
2  * This file is part of the GROMACS molecular simulation package.
3  *
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.
8  *
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.
13  *
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.
18  *
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.
23  *
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.
31  *
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.
34  */
35 /*! \file
36  * \brief API for neighborhood searching.
37  *
38  * The API is documented in more detail on a separate page:
39  * \ref nbsearch
40  *
41  * The functions within this file can be used independently of the other parts
42  * of the library.
43  * The library also uses the functions internally.
44  *
45  * \author Teemu Murtola <teemu.murtola@gmail.com>
46  * \ingroup module_selection
47  */
48 #ifndef GMX_SELECTION_NBSEARCH_H
49 #define GMX_SELECTION_NBSEARCH_H
50
51 #include "../legacyheaders/typedefs.h"
52
53 #include "indexutil.h"
54
55 struct gmx_ana_pos_t;
56
57 /** Data structure for neighborhood searches. */
58 typedef struct gmx_ana_nbsearch_t gmx_ana_nbsearch_t;
59
60 /** Create a new neighborhood search data structure. */
61 gmx_ana_nbsearch_t *
62 gmx_ana_nbsearch_create(real cutoff, int maxn);
63 /** Free memory allocated for neighborhood search. */
64 void
65 gmx_ana_nbsearch_free(gmx_ana_nbsearch_t *d);
66
67 /** Initializes neighborhood search for a new frame. */
68 void
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.  */
71 void
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. */
75 void
76 gmx_ana_nbsearch_set_excl(gmx_ana_nbsearch_t *d, int nexcl, int excl[]);
77 /** Check whether a point is within a neighborhood. */
78 bool
79 gmx_ana_nbsearch_is_within(gmx_ana_nbsearch_t *d, const rvec x);
80 /** Check whether a position is within a neighborhood. */
81 bool
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. */
85 real
86 gmx_ana_nbsearch_mindist(gmx_ana_nbsearch_t *d, const rvec x);
87 /** Calculates the minimun distance from the reference points. */
88 real
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. */
92 bool
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. */
95 bool
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. */
99 bool
100 gmx_ana_nbsearch_next_within(gmx_ana_nbsearch_t *d, int *jp);
101
102 namespace gmx
103 {
104
105 /*
106  * C++ wrapper for neighborhood searching.
107  *
108  */
109 class NeighborhoodSearch
110 {
111     public:
112         NeighborhoodSearch(real cutoff, int maxn)
113             : d_(gmx_ana_nbsearch_create(cutoff, maxn))
114         {
115         }
116         ~NeighborhoodSearch() { gmx_ana_nbsearch_free(d_); }
117
118         void init(t_pbc *pbc, int n, const rvec x[])
119         { gmx_ana_nbsearch_init(d_, pbc, n, x); }
120
121         void init(t_pbc *pbc, const gmx_ana_pos_t *p)
122         { gmx_ana_nbsearch_pos_init(d_, pbc, p); }
123
124         void setExclusions(int nexcl, atom_id *excl)
125         { gmx_ana_nbsearch_set_excl(d_, nexcl, excl); }
126
127
128         bool isWithin(const rvec x)
129         { return gmx_ana_nbsearch_is_within(d_, x); }
130
131         bool isWithin(const gmx_ana_pos_t *p, int i)
132         { return gmx_ana_nbsearch_pos_is_within(d_, p, i); }
133
134         real minimumDistance(const rvec x)
135         { return gmx_ana_nbsearch_mindist(d_, x); }
136
137         real minimumDistance(const gmx_ana_pos_t *p, int i)
138         { return gmx_ana_nbsearch_pos_mindist(d_, p, i); }
139
140         bool firstWithin(const rvec x, int *jp)
141         { return gmx_ana_nbsearch_first_within(d_, x, jp); }
142
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); }
145
146         bool nextWithin(int *jp)
147         { return gmx_ana_nbsearch_next_within(d_, jp); }
148
149     private:
150         gmx_ana_nbsearch_t  *d_;
151 };
152
153 } // namespace gmx
154
155 #endif