9dc45af3a3fd11acfa831fd4b5f7c0c597312f6a
[alexxy/gromacs.git] / include / force.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  * check out http://www.gromacs.org for more information.
7  * Copyright (c) 2012,2013, by the GROMACS development team, led by
8  * David van der Spoel, Berk Hess, Erik Lindahl, and including many
9  * others, as listed in the AUTHORS file in the top-level source
10  * directory and at http://www.gromacs.org.
11  *
12  * GROMACS is free software; you can redistribute it and/or
13  * modify it under the terms of the GNU Lesser General Public License
14  * as published by the Free Software Foundation; either version 2.1
15  * of the License, or (at your option) any later version.
16  *
17  * GROMACS is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
20  * Lesser General Public License for more details.
21  *
22  * You should have received a copy of the GNU Lesser General Public
23  * License along with GROMACS; if not, see
24  * http://www.gnu.org/licenses, or write to the Free Software Foundation,
25  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA.
26  *
27  * If you want to redistribute modifications to GROMACS, please
28  * consider that scientific software is very special. Version
29  * control is crucial - bugs must be traceable. We will be happy to
30  * consider code for inclusion in the official distribution, but
31  * derived work must not be called official GROMACS. Details are found
32  * in the README & COPYING files - if they are missing, get the
33  * official version at http://www.gromacs.org.
34  *
35  * To help us fund GROMACS development, we humbly ask that you cite
36  * the research papers on the package. Check out http://www.gromacs.org.
37  */
38
39 #ifndef _force_h
40 #define _force_h
41
42 #include "visibility.h"
43 #include "typedefs.h"
44 #include "types/force_flags.h"
45 #include "pbc.h"
46 #include "network.h"
47 #include "tgroup.h"
48 #include "vsite.h"
49 #include "genborn.h"
50
51
52 #ifdef __cplusplus
53 extern "C" {
54 #endif
55
56 static const char *sepdvdlformat = "  %-30s V %12.5e  dVdl %12.5e\n";
57
58 void calc_vir(FILE *fplog, int nxf, rvec x[], rvec f[], tensor vir,
59               gmx_bool bScrewPBC, matrix box);
60 /* Calculate virial for nxf atoms, and add it to vir */
61
62 void f_calc_vir(FILE *fplog, int i0, int i1, rvec x[], rvec f[], tensor vir,
63                 t_graph *g, rvec shift_vec[]);
64 /* Calculate virial taking periodicity into account */
65
66 real RF_excl_correction(FILE *fplog,
67                         const t_forcerec *fr, t_graph *g,
68                         const t_mdatoms *mdatoms, const t_blocka *excl,
69                         rvec x[], rvec f[], rvec *fshift, const t_pbc *pbc,
70                         real lambda, real *dvdlambda);
71 /* Calculate the reaction-field energy correction for this node:
72  * epsfac q_i q_j (k_rf r_ij^2 - c_rf)
73  * and force correction for all excluded pairs, including self pairs.
74  */
75
76 void calc_rffac(FILE *fplog, int eel, real eps_r, real eps_rf,
77                 real Rc, real Temp,
78                 real zsq, matrix box,
79                 real *kappa, real *krf, real *crf);
80 /* Determine the reaction-field constants */
81
82 void init_generalized_rf(FILE *fplog,
83                          const gmx_mtop_t *mtop, const t_inputrec *ir,
84                          t_forcerec *fr);
85 /* Initialize the generalized reaction field parameters */
86
87
88 /* In wall.c */
89 void make_wall_tables(FILE *fplog, const output_env_t oenv,
90                       const t_inputrec *ir, const char *tabfn,
91                       const gmx_groups_t *groups,
92                       t_forcerec *fr);
93
94 real do_walls(t_inputrec *ir, t_forcerec *fr, matrix box, t_mdatoms *md,
95               rvec x[], rvec f[], real lambda, real Vlj[], t_nrnb *nrnb);
96
97 GMX_LIBMD_EXPORT
98 t_forcerec *mk_forcerec(void);
99
100 #define GMX_MAKETABLES_FORCEUSER  (1<<0)
101 #define GMX_MAKETABLES_14ONLY     (1<<1)
102
103 t_forcetable make_tables(FILE *fp, const output_env_t oenv,
104                          const t_forcerec *fr, gmx_bool bVerbose,
105                          const char *fn, real rtab, int flags);
106 /* Return tables for inner loops. When bVerbose the tables are printed
107  * to .xvg files
108  */
109
110 bondedtable_t make_bonded_table(FILE *fplog, char *fn, int angle);
111 /* Return a table for bonded interactions,
112  * angle should be: bonds 0, angles 1, dihedrals 2
113  */
114
115 /* Return a table for GB calculations */
116 t_forcetable make_gb_table(FILE *out, const output_env_t oenv,
117                            const t_forcerec *fr,
118                            const char *fn,
119                            real rtab);
120
121 /* Read a table for AdResS Thermo Force calculations */
122 extern t_forcetable make_atf_table(FILE *out, const output_env_t oenv,
123                                    const t_forcerec *fr,
124                                    const char *fn,
125                                    matrix box);
126
127 GMX_LIBMD_EXPORT
128 void pr_forcerec(FILE *fplog, t_forcerec *fr, t_commrec *cr);
129
130 void
131 forcerec_set_ranges(t_forcerec *fr,
132                     int ncg_home, int ncg_force,
133                     int natoms_force,
134                     int natoms_force_constr, int natoms_f_novirsum);
135 /* Set the number of cg's and atoms for the force calculation */
136
137 GMX_LIBMD_EXPORT
138 gmx_bool can_use_allvsall(const t_inputrec *ir, const gmx_mtop_t *mtop,
139                           gmx_bool bPrintNote, t_commrec *cr, FILE *fp);
140 /* Returns if we can use all-vs-all loops.
141  * If bPrintNote==TRUE, prints a note, if necessary, to stderr
142  * and fp (if !=NULL) on the master node.
143  */
144
145 GMX_LIBMD_EXPORT
146 gmx_bool uses_simple_tables(int                 cutoff_scheme,
147                             nonbonded_verlet_t *nbv,
148                             int                 group);
149 /* Returns whether simple tables (i.e. not for use with GPUs) are used
150  * with the type of kernel indicated.
151  */
152
153 GMX_LIBMD_EXPORT
154 void init_interaction_const_tables(FILE                *fp,
155                                    interaction_const_t *ic,
156                                    gmx_bool             bSimpleTable,
157                                    real                 rtab);
158 /* Initializes the tables in the interaction constant data structure.
159  * Setting verlet_kernel_type to -1 always initializes tables for
160  * use with group kernels.
161  */
162
163 void init_interaction_const(FILE                 *fp,
164                             interaction_const_t **interaction_const,
165                             const t_forcerec     *fr,
166                             real                  rtab);
167 /* Initializes the interaction constant data structure. Currently it
168  * uses forcerec as input.
169  */
170
171 GMX_LIBMD_EXPORT
172 void init_forcerec(FILE              *fplog,
173                    const output_env_t oenv,
174                    t_forcerec        *fr,
175                    t_fcdata          *fcd,
176                    const t_inputrec  *ir,
177                    const gmx_mtop_t  *mtop,
178                    const t_commrec   *cr,
179                    matrix             box,
180                    gmx_bool           bMolEpot,
181                    const char        *tabfn,
182                    const char        *tabafn,
183                    const char        *tabpfn,
184                    const char        *tabbfn,
185                    const char        *nbpu_opt,
186                    gmx_bool           bNoSolvOpt,
187                    real               print_force);
188 /* The Force rec struct must be created with mk_forcerec
189  * The gmx_booleans have the following meaning:
190  * bSetQ:    Copy the charges [ only necessary when they change ]
191  * bMolEpot: Use the free energy stuff per molecule
192  * print_force >= 0: print forces for atoms with force >= print_force
193  */
194
195 GMX_LIBMD_EXPORT
196 void forcerec_set_excl_load(t_forcerec *fr,
197                             const gmx_localtop_t *top, const t_commrec *cr);
198 /* Set the exclusion load for the local exclusions and possibly threads */
199
200 GMX_LIBMD_EXPORT
201 void init_enerdata(int ngener, int n_lambda, gmx_enerdata_t *enerd);
202 /* Intializes the energy storage struct */
203
204 void destroy_enerdata(gmx_enerdata_t *enerd);
205 /* Free all memory associated with enerd */
206
207 void reset_foreign_enerdata(gmx_enerdata_t *enerd);
208 /* Resets only the foreign energy data */
209
210 void reset_enerdata(t_grpopts *opts,
211                     t_forcerec *fr, gmx_bool bNS,
212                     gmx_enerdata_t *enerd,
213                     gmx_bool bMaster);
214 /* Resets the energy data, if bNS=TRUE also zeros the long-range part */
215
216 void sum_epot(t_grpopts *opts, gmx_grppairener_t *grpp, real *epot);
217 /* Locally sum the non-bonded potential energy terms */
218
219 GMX_LIBMD_EXPORT
220 void sum_dhdl(gmx_enerdata_t *enerd, real *lambda, t_lambda *fepvals);
221 /* Sum the free energy contributions */
222
223 void update_forcerec(FILE *fplog, t_forcerec *fr, matrix box);
224 /* Updates parameters in the forcerec that are time dependent */
225
226 /* Compute the average C6 and C12 params for LJ corrections */
227 void set_avcsixtwelve(FILE *fplog, t_forcerec *fr,
228                       const gmx_mtop_t *mtop);
229
230 GMX_LIBMD_EXPORT
231 extern void do_force(FILE *log, t_commrec *cr,
232                      t_inputrec *inputrec,
233                      gmx_large_int_t step, t_nrnb *nrnb, gmx_wallcycle_t wcycle,
234                      gmx_localtop_t *top,
235                      gmx_mtop_t *mtop,
236                      gmx_groups_t *groups,
237                      matrix box, rvec x[], history_t *hist,
238                      rvec f[],
239                      tensor vir_force,
240                      t_mdatoms *mdatoms,
241                      gmx_enerdata_t *enerd, t_fcdata *fcd,
242                      real *lambda, t_graph *graph,
243                      t_forcerec *fr,
244                      gmx_vsite_t *vsite, rvec mu_tot,
245                      double t, FILE *field, gmx_edsam_t ed,
246                      gmx_bool bBornRadii,
247                      int flags);
248
249 /* Communicate coordinates (if parallel).
250  * Do neighbor searching (if necessary).
251  * Calculate forces.
252  * Communicate forces (if parallel).
253  * Spread forces for vsites (if present).
254  *
255  * f is always required.
256  */
257
258 GMX_LIBMD_EXPORT
259 void ns(FILE              *fplog,
260         t_forcerec        *fr,
261         rvec               x[],
262         matrix             box,
263         gmx_groups_t      *groups,
264         t_grpopts         *opts,
265         gmx_localtop_t    *top,
266         t_mdatoms         *md,
267         t_commrec         *cr,
268         t_nrnb            *nrnb,
269         real              *lambda,
270         real              *dvdlambda,
271         gmx_grppairener_t *grppener,
272         gmx_bool           bFillGrid,
273         gmx_bool           bDoLongRangeNS);
274 /* Call the neighborsearcher */
275
276 extern void do_force_lowlevel(FILE         *fplog,
277                               gmx_large_int_t   step,
278                               t_forcerec   *fr,
279                               t_inputrec   *ir,
280                               t_idef       *idef,
281                               t_commrec    *cr,
282                               t_nrnb       *nrnb,
283                               gmx_wallcycle_t wcycle,
284                               t_mdatoms    *md,
285                               t_grpopts    *opts,
286                               rvec         x[],
287                               history_t    *hist,
288                               rvec         f_shortrange[],
289                               rvec         f_longrange[],
290                               gmx_enerdata_t *enerd,
291                               t_fcdata     *fcd,
292                               gmx_mtop_t     *mtop,
293                               gmx_localtop_t *top,
294                               gmx_genborn_t *born,
295                               t_atomtypes  *atype,
296                               gmx_bool         bBornRadii,
297                               matrix       box,
298                               t_lambda     *fepvals,
299                               real         *lambda,
300                               t_graph      *graph,
301                               t_blocka     *excl,
302                               rvec         mu_tot[2],
303                               int          flags,
304                               float        *cycles_pme);
305 /* Call all the force routines */
306
307 #ifdef __cplusplus
308 }
309 #endif
310
311 #endif  /* _force_h */