Remove no-inline-max-size and suppress remark
[alexxy/gromacs.git] / src / gromacs / legacyheaders / pbc.h
1 /*
2  * This file is part of the GROMACS molecular simulation package.
3  *
4  * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
5  * Copyright (c) 2001-2004, The GROMACS development team.
6  * Copyright (c) 2012,2014, by the GROMACS development team, led by
7  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
8  * and including many others, as listed in the AUTHORS file in the
9  * top-level source directory and at http://www.gromacs.org.
10  *
11  * GROMACS is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU Lesser General Public License
13  * as published by the Free Software Foundation; either version 2.1
14  * of the License, or (at your option) any later version.
15  *
16  * GROMACS is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
19  * Lesser General Public License for more details.
20  *
21  * You should have received a copy of the GNU Lesser General Public
22  * License along with GROMACS; if not, see
23  * http://www.gnu.org/licenses, or write to the Free Software Foundation,
24  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA.
25  *
26  * If you want to redistribute modifications to GROMACS, please
27  * consider that scientific software is very special. Version
28  * control is crucial - bugs must be traceable. We will be happy to
29  * consider code for inclusion in the official distribution, but
30  * derived work must not be called official GROMACS. Details are found
31  * in the README & COPYING files - if they are missing, get the
32  * official version at http://www.gromacs.org.
33  *
34  * To help us fund GROMACS development, we humbly ask that you cite
35  * the research papers on the package. Check out http://www.gromacs.org.
36  */
37
38 #ifndef _types_pbc_h
39 #define _types_pbc_h
40
41 #include "sysstuff.h"
42 #include "typedefs.h"
43
44 #ifdef __cplusplus
45 extern "C" {
46 #endif
47
48 #define TRICLINIC(box) (box[YY][XX] != 0 || box[ZZ][XX] != 0 || box[ZZ][YY] != 0)
49
50 #define NTRICIMG 14
51 #define NCUCVERT 24
52 #define NCUCEDGE 36
53
54 enum {
55     ecenterTRIC, /* 0.5*(a+b+c)                  */
56     ecenterRECT, /* (0.5*a[x],0.5*b[y],0.5*c[z]) */
57     ecenterZERO, /* (0,0,0)                      */
58     ecenterDEF = ecenterTRIC
59 };
60
61 int ePBC2npbcdim(int ePBC);
62 /* Returns the number of dimensions that use pbc, starting at X */
63
64 int inputrec2nboundeddim(t_inputrec *ir);
65 /* Returns the number of dimensions in which
66  * the coordinates of the particles are bounded, starting at X.
67  */
68
69 void dump_pbc(FILE *fp, t_pbc *pbc);
70 /* Dump the contents of the pbc structure to the file */
71
72 const char *check_box(int ePBC, matrix box);
73 /* Returns NULL if the box is supported by Gromacs.
74  * Otherwise is returns a string with the problem.
75  * When ePBC=-1, the type of pbc is guessed from the box matrix.
76  */
77
78 real max_cutoff2(int ePBC, matrix box);
79 /* Returns the square of the maximum cut-off allowed for the box,
80  * taking into account that the grid neighborsearch code and pbc_dx
81  * only check combinations of single box-vector shifts.
82  */
83
84 int guess_ePBC(matrix box);
85 /* Guesses the type of periodic boundary conditions using the box */
86
87 gmx_bool correct_box(FILE *fplog, int step, tensor box, t_graph *graph);
88 /* Checks for un-allowed box angles and corrects the box
89  * and the integer shift vectors in the graph (if graph!=NULL) if necessary.
90  * Returns TRUE when the box was corrected.
91  */
92
93 int ndof_com(t_inputrec *ir);
94 /* Returns the number of degrees of freedom of the center of mass */
95
96 void set_pbc(t_pbc *pbc, int ePBC, matrix box);
97 /* Initiate the periodic boundary conditions.
98  * pbc_dx will not use pbc and return the normal difference vector
99  * when one or more of the diagonal elements of box are zero.
100  * When ePBC=-1, the type of pbc is guessed from the box matrix.
101  */
102
103 t_pbc *set_pbc_dd(t_pbc *pbc, int ePBC,
104                   gmx_domdec_t *dd, gmx_bool bSingleDir, matrix box);
105 /* As set_pbc, but additionally sets that correct distances can
106  * be obtained using (combinations of) single box-vector shifts.
107  * Should be used with pbc_dx_aiuc.
108  * If dd!=NULL pbc is not used for directions
109  * with dd->nc[i]==1 with bSingleDir==TRUE or
110  * with dd->nc[i]<=2 with bSingleDir==FALSE.
111  * Returns pbc when pbc operations are required, NULL otherwise.
112  */
113
114 void pbc_dx(const t_pbc *pbc, const rvec x1, const rvec x2, rvec dx);
115 /* Calculate the correct distance vector from x2 to x1 and put it in dx.
116  * set_pbc must be called before ever calling this routine.
117  *
118  * For triclinic boxes pbc_dx does not necessarily return the shortest
119  * distance vector. If pbc->bLimitDistance=TRUE an atom pair with
120  * distance vector dx with norm2(dx) > pbc->limit_distance2 could
121  * have a shorter distance, but not shorter than sqrt(pbc->limit_distance2).
122  * pbc->limit_distance2 is always larger than max_cutoff2(box).
123  * For the standard rhombic dodecahedron and truncated octahedron
124  * pbc->bLimitDistance=FALSE and thus all distances are correct.
125  */
126
127 int pbc_dx_aiuc(const t_pbc *pbc, const rvec x1, const rvec x2, rvec dx);
128 /* Calculate the correct distance vector from x2 to x1 and put it in dx,
129  * This function can only be used when all atoms are in the rectangular
130  * or triclinic unit-cell.
131  * Returns the ishift required to shift x1 at closest distance to x2;
132  * i.e. if 0<=ishift<SHIFTS then x1 - x2 + shift_vec[ishift] = dx
133  * (see calc_shifts below on how to obtain shift_vec)
134  * set_pbc_dd or set_pbc must be called before ever calling this routine.
135  */
136 void pbc_dx_d(const t_pbc *pbc, const dvec x1, const dvec x2, dvec dx);
137 /* As pbc_dx, but for double precision vectors.
138  * set_pbc must be called before ever calling this routine.
139  */
140
141 gmx_bool image_rect(ivec xi, ivec xj, ivec box_size,
142                     real rlong2, int *shift, real *r2);
143 /* Calculate the distance between xi and xj for a rectangular box.
144  * When the distance is SMALLER than rlong2 return TRUE, return
145  * the shift code in shift and the distance in r2. When the distance is
146  * >= rlong2 return FALSE;
147  * It is assumed that rlong2 is scaled the same way as the ivecs xi and xj.
148  */
149
150 gmx_bool image_tri(ivec xi, ivec xj, imatrix box,
151                    real rlong2, int *shift, real *r2);
152 /* Calculate the distance between xi and xj for a triclinic box.
153  * When the distance is SMALLER than rlong2 return TRUE, return
154  * the shift code in shift and the distance in r2. When the distance is
155  * >= rlong2 return FALSE;
156  * It is assumed that rlong2 is scaled the same way as the ivecs xi and xj.
157  */
158
159 gmx_bool image_cylindric(ivec xi, ivec xj, ivec box_size, real rlong2,
160                          int *shift, real *r2);
161 /* Calculate the distance between xi and xj for a rectangular box
162  * using a cylindric cutoff for long-range only.
163  * When the distance is SMALLER than rlong2 (in X and Y dir.)
164  * return TRUE, return
165  * the shift code in shift and the distance in r2. When the distance is
166  * >= rlong2 return FALSE;
167  * It is assumed that rlong2 is scaled the same way as the ivecs xi and xj.
168  */
169
170 void calc_shifts(matrix box, rvec shift_vec[]);
171 /* This routine calculates ths shift vectors necessary to use the
172  * ns routine.
173  */
174
175 void calc_box_center(int ecenter, matrix box, rvec box_center);
176 /* Calculates the center of the box.
177  * See the description for the enum ecenter above.
178  */
179
180 void calc_triclinic_images(matrix box, rvec img[]);
181 /* Calculates the NTRICIMG box images */
182
183 void calc_compact_unitcell_vertices(int ecenter, matrix box,
184                                     rvec vert[]);
185 /* Calculates the NCUCVERT vertices of a compact unitcell */
186
187 int *compact_unitcell_edges(void);
188 /* Return an array of unitcell edges of length NCUCEDGE*2,
189  * this is an index in vert[], which is calculated by calc_unitcell_vertices.
190  * The index consists of NCUCEDGE pairs of vertex indices.
191  * The index does not change, so it needs to be retrieved only once.
192  */
193
194 void put_atoms_in_box_omp(int ePBC, matrix box, int natoms, rvec x[]);
195 /* This wrapper function around put_atoms_in_box() with the ugly manual
196  * workload splitting is needed toavoid silently introducing multithreading
197  * in tools.
198  * */
199
200
201 void put_atoms_in_box(int ePBC, matrix box, int natoms, rvec x[]);
202 /* These routines puts ONE or ALL atoms in the box, not caring
203  * about charge groups!
204  * Also works for triclinic cells.
205  */
206
207 void put_atoms_in_triclinic_unitcell(int ecenter, matrix box,
208                                      int natoms, rvec x[]);
209 /* This puts ALL atoms in the triclinic unit cell, centered around the
210  * box center as calculated by calc_box_center.
211  */
212
213 const char *put_atoms_in_compact_unitcell(int ePBC, int ecenter,
214                                           matrix box,
215                                           int natoms, rvec x[]);
216 /* This puts ALL atoms at the closest distance for the center of the box
217  * as calculated by calc_box_center.
218  * Will return NULL is everything went ok and a warning string if not
219  * all atoms could be placed in the unitcell. This can happen for some
220  * triclinic unitcells, see the comment at pbc_dx above.
221  * When ePBC=-1, the type of pbc is guessed from the box matrix.
222  */
223
224 #ifdef __cplusplus
225 }
226 #endif
227
228 #endif  /* _pbc_h */