8f8cb28ab6fc6d9eb90c63a7b3189e753e58b42a
[alexxy/gromacs.git] / include / pbc.h
1 /*
2  * $Id$
3  * 
4  *       This source code is part of
5  * 
6  *        G   R   O   M   A   C   S
7  * 
8  * GROningen MAchine for Chemical Simulations
9  * 
10  *               VERSION 2.0
11  * 
12  * Copyright (c) 1991-1999
13  * BIOSON Research Institute, Dept. of Biophysical Chemistry
14  * University of Groningen, The Netherlands
15  * 
16  * Please refer to:
17  * GROMACS: A message-passing parallel molecular dynamics implementation
18  * H.J.C. Berendsen, D. van der Spoel and R. van Drunen
19  * Comp. Phys. Comm. 91, 43-56 (1995)
20  * 
21  * Also check out our WWW page:
22  * http://md.chem.rug.nl/~gmx
23  * or e-mail to:
24  * gromacs@chem.rug.nl
25  * 
26  * And Hey:
27  * Good ROcking Metal Altar for Chronical Sinners
28  */
29
30 #ifndef _pbc_h
31 #define _pbc_h
32
33 static char *SRCID_pbc_h = "$Id$";
34
35 #ifdef HAVE_CONFIG_H
36 #include <config.h>
37 #endif
38
39 #ifdef HAVE_IDENT
40 #ident  "@(#) pbc.h 1.17 2/2/97"
41 #endif /* HAVE_IDENT */
42 #include "sysstuff.h"
43 #include "typedefs.h"
44
45 #ifdef CPLUSPLUS
46 extern "C" { 
47 #endif
48
49 #define BOX_MARGIN 0.5001
50 /* margin factor for checking if the box is too skewed */
51
52 #define TRICLINIC(box) (box[YY][XX]!=0 || box[ZZ][XX]!=0 || box[ZZ][YY]!=0)
53
54 #define NTRICIMG 14
55 #define NCUCVERT 24
56 #define NCUCEDGE 36
57
58 extern char *check_box(matrix box);
59 /* Returns NULL if the box is supported by Gromacs.
60  * Otherwise is returns a string with the problem.
61  */
62
63 extern void init_pbc(matrix box,bool bNotUsed);
64 /* Initiate the periodic boundary conditions. */
65
66 extern void pbc_dx(const rvec x1, const rvec x2, rvec dx);
67 /* Calculate the correct distance vector from x1 and x2 and put it in
68  * dx. init_pbc must be called before ever calling this routine
69  * (this is done by put_charge_groups_in_box).
70  */
71
72 extern bool image_rect(ivec xi,ivec xj,ivec box_size,
73                        real rlong2,int *shift,real *r2);
74 /* Calculate the distance between xi and xj for a rectangular box.
75  * When the distance is SMALLER than rlong2 return TRUE, return
76  * the shift code in shift and the distance in r2. When the distance is
77  * >= rlong2 return FALSE;
78  * It is assumed that rlong2 is scaled the same way as the ivecs xi and xj.
79  */
80
81 extern bool image_tri(ivec xi,ivec xj,imatrix box,
82                       real rlong2,int *shift,real *r2);
83 /* Calculate the distance between xi and xj for a triclinic box.
84  * When the distance is SMALLER than rlong2 return TRUE, return
85  * the shift code in shift and the distance in r2. When the distance is
86  * >= rlong2 return FALSE;
87  * It is assumed that rlong2 is scaled the same way as the ivecs xi and xj.
88  */
89
90 extern bool image_cylindric(ivec xi,ivec xj,ivec box_size,real rlong2,
91                             int *shift,real *r2);
92 /* Calculate the distance between xi and xj for a rectangular box
93  * using a cylindric cutoff for long-range only.
94  * When the distance is SMALLER than rlong2 (in X and Y dir.)
95  * return TRUE, return
96  * the shift code in shift and the distance in r2. When the distance is
97  * >= rlong2 return FALSE;
98  * It is assumed that rlong2 is scaled the same way as the ivecs xi and xj.
99  */
100
101 extern void calc_shifts(matrix box,rvec box_size,rvec shift_vec[],
102                         bool bNotUsed);
103 /* This routine calculates ths shift vectors necessary to use the
104  * ns routine. Note that for the truncated octahedron case too many
105  * shift vectors can be calculated: The ones for which exactly
106  * 2 of the k,l,m indexes are not 0 (12 vectors lying along the box
107  * edges. This can be compensated for by removing all the shift_vecs with
108  * (k+l+m) even. This is a feature of the way in which the counting is 
109  * done. It implies that, when using truncated octahedron,
110  * the shift codes 1,3,5,7,9,11,15,17,19,21,23,25 should never occur,
111  * that is, every second entry, EXCEPT the central box.
112  */
113
114 extern void calc_cgcm(FILE *log,int cg0,int cg1,t_block *cgs,
115                       rvec pos[],rvec cg_cm[]);
116 /* Routine to compute centers of geometry of charge groups. No periodicity
117  * is used.
118  */
119    
120 extern void put_charge_groups_in_box (FILE *log,int cg0,int cg1,bool bNotUsed,
121                                       matrix box,rvec box_size,t_block *cgs,
122                                       rvec pos[],
123                                       rvec cg_cm[]);
124                             
125 /* This routine puts charge groups in the periodic box, keeping them
126  * together.
127  */
128
129 extern void calc_box_center(matrix box,rvec box_center);
130 /* Calculates the center of the box */
131
132 extern void calc_triclinic_images(matrix box,rvec img[]);
133 /* Calculates the NTRICIMG box images */
134
135 extern void calc_compact_unitcell_vertices(matrix box,rvec vert[]);
136 /* Calculates the NCUCVERT vertices of a compact unitcell */
137
138 extern int *compact_unitcell_edges(void);
139 /* Return an array of unitcell edges of length NCUCEDGE*2,
140  * this is an index in vert[], which is calculated by calc_unitcell_vertices.
141  * The index consists of NCUCEDGE pairs of vertex indices.
142  * The index does not change, so it needs to be retrieved only once.
143  */
144
145 extern void put_atoms_in_box(matrix box,int natoms,rvec x[]);
146 /* This puts ALL atoms in the box, not caring about charge groups!
147  * Also works for triclinic cells.
148  */
149
150 extern void put_atoms_in_triclinic_unitcell(matrix box,int natoms,rvec x[]);
151 /* This puts ALL atoms in the triclinic unit cell, centered around the
152  * box center as calculated by calc_box_center.
153  */
154
155 extern void put_atoms_in_compact_unitcell(matrix box,int natoms,rvec x[]);
156 /* This puts ALL atoms at the closest distance for the center of the box
157  * as calculated by calc_box_center.
158  */
159
160 #ifdef CPLUSPLUS
161 }
162 #endif
163
164 #endif  /* _pbc_h */