Merge branch 'release-4-5-patches' of git.gromacs.org:gromacs into release-4-5-patches
[gromacs/rigid-bodies.git] / include / mdrun.h
blob7bf44346d9528d580771fabfc9fa84c8648b4f99
1 /*
2 *
3 * This source code is part of
4 *
5 * G R O M A C S
6 *
7 * GROningen MAchine for Chemical Simulations
8 *
9 * VERSION 3.2.0
10 * Written by David van der Spoel, Erik Lindahl, Berk Hess, and others.
11 * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
12 * Copyright (c) 2001-2004, The GROMACS development team,
13 * check out http://www.gromacs.org for more information.
15 * This program is free software; you can redistribute it and/or
16 * modify it under the terms of the GNU General Public License
17 * as published by the Free Software Foundation; either version 2
18 * of the License, or (at your option) any later version.
20 * If you want to redistribute modifications, please consider that
21 * scientific software is very special. Version control is crucial -
22 * bugs must be traceable. We will be happy to consider code for
23 * inclusion in the official distribution, but derived work must not
24 * be called official GROMACS. Details are found in the README & COPYING
25 * files - if they are missing, get the official version at www.gromacs.org.
27 * To help us fund GROMACS development, we humbly ask that you cite
28 * the papers on the package - you can find them in the top README file.
30 * For more info, check our website at http://www.gromacs.org
32 * And Hey:
33 * Gromacs Runs On Most of All Computer Systems
36 #ifndef _mdrun_h
37 #define _mdrun_h
39 #include <stdio.h>
40 #include <time.h>
41 #include "typedefs.h"
42 #include "network.h"
43 #include "tgroup.h"
44 #include "filenm.h"
45 #include "mshift.h"
46 #include "force.h"
47 #include "edsam.h"
48 #include "mdebin.h"
49 #include "vcm.h"
50 #include "vsite.h"
51 #include "pull.h"
52 #include "update.h"
54 #ifdef __cplusplus
55 extern "C" {
56 #endif
58 #define MD_POLARISE (1<<2)
59 #define MD_IONIZE (1<<3)
60 #define MD_RERUN (1<<4)
61 #define MD_RERUN_VSITE (1<<5)
62 #define MD_FFSCAN (1<<6)
63 #define MD_SEPPOT (1<<7)
64 #define MD_PARTDEC (1<<9)
65 #define MD_DDBONDCHECK (1<<10)
66 #define MD_DDBONDCOMM (1<<11)
67 #define MD_CONFOUT (1<<12)
68 #define MD_REPRODUCIBLE (1<<13)
69 #define MD_READ_RNG (1<<14)
70 #define MD_APPENDFILES (1<<15)
71 #define MD_KEEPANDNUMCPT (1<<16)
72 #define MD_READ_EKIN (1<<17)
73 #define MD_STARTFROMCPT (1<<18)
74 #define MD_RESETCOUNTERSHALFWAY (1<<19)
76 /* Define a number of flags to better control the information
77 * passed to compute_globals in md.c and global_stat.
80 /* We are rerunning the simulation */
81 #define CGLO_RERUNMD (1<<1)
82 /* we are computing the kinetic energy from average velocities */
83 #define CGLO_EKINAVEVEL (1<<2)
84 /* we are removing the center of mass momenta */
85 #define CGLO_STOPCM (1<<3)
86 /* bGStat is defined in do_md */
87 #define CGLO_GSTAT (1<<4)
88 /* Sum the energy terms in global computation */
89 #define CGLO_ENERGY (1<<6)
90 /* Sum the kinetic energy terms in global computation */
91 #define CGLO_TEMPERATURE (1<<7)
92 /* Sum the kinetic energy terms in global computation */
93 #define CGLO_PRESSURE (1<<8)
94 /* Sum the constraint term in global computation */
95 #define CGLO_CONSTRAINT (1<<9)
96 /* we are using an integrator that requires iteration over some steps - currently not used*/
97 #define CGLO_ITERATE (1<<10)
98 /* it is the first time we are iterating (or, only once through is required */
99 #define CGLO_FIRSTITERATE (1<<11)
100 /* Reading ekin from the trajectory */
101 #define CGLO_READEKIN (1<<12)
102 /* we need to reset the ekin rescaling factor here */
103 #define CGLO_SCALEEKIN (1<<13)
105 enum {
106 ddnoSEL, ddnoINTERLEAVE, ddnoPP_PME, ddnoCARTESIAN, ddnoNR
109 typedef struct {
110 double real;
111 #ifdef GMX_CRAY_XT3
112 double proc;
113 #else
114 clock_t proc;
115 #endif
116 double realtime;
117 double proctime;
118 double time_per_step;
119 double last;
120 gmx_large_int_t nsteps_done;
121 } gmx_runtime_t;
123 typedef struct {
124 t_fileio *fp_trn;
125 t_fileio *fp_xtc;
126 int xtc_prec;
127 ener_file_t fp_ene;
128 const char *fn_cpt;
129 gmx_bool bKeepAndNumCPT;
130 int eIntegrator;
131 int simulation_part;
132 FILE *fp_dhdl;
133 FILE *fp_field;
134 } gmx_mdoutf_t;
136 /* Variables for temporary use with the deform option,
137 * used in runner.c and md.c.
138 * (These variables should be stored in the tpx file.)
140 extern gmx_large_int_t deform_init_init_step_tpx;
141 extern matrix deform_init_box_tpx;
142 #ifdef GMX_THREADS
143 extern tMPI_Thread_mutex_t deform_init_box_mutex;
145 /* The minimum number of atoms per thread. With fewer atoms than this,
146 * the number of threads will get lowered.
148 #define MIN_ATOMS_PER_THREAD 90
149 #endif
152 typedef double gmx_integrator_t(FILE *log,t_commrec *cr,
153 int nfile,const t_filenm fnm[],
154 const output_env_t oenv, gmx_bool bVerbose,
155 gmx_bool bCompact, int nstglobalcomm,
156 gmx_vsite_t *vsite,gmx_constr_t constr,
157 int stepout,
158 t_inputrec *inputrec,
159 gmx_mtop_t *mtop,t_fcdata *fcd,
160 t_state *state,
161 t_mdatoms *mdatoms,
162 t_nrnb *nrnb,gmx_wallcycle_t wcycle,
163 gmx_edsam_t ed,
164 t_forcerec *fr,
165 int repl_ex_nst,int repl_ex_seed,
166 real cpt_period,real max_hours,
167 const char *deviceOptions,
168 unsigned long Flags,
169 gmx_runtime_t *runtime);
171 typedef struct gmx_global_stat *gmx_global_stat_t;
173 /* ROUTINES from md.c */
175 gmx_integrator_t do_md;
177 gmx_integrator_t do_md_openmm;
179 /* ROUTINES from minimize.c */
181 gmx_integrator_t do_steep;
182 /* Do steepest descents EM */
184 gmx_integrator_t do_cg;
185 /* Do conjugate gradient EM */
187 gmx_integrator_t do_lbfgs;
188 /* Do conjugate gradient L-BFGS */
190 gmx_integrator_t do_nm;
191 /* Do normal mode analysis */
193 /* ROUTINES from tpi.c */
195 gmx_integrator_t do_tpi;
196 /* Do test particle insertion */
199 /* ROUTINES from sim_util.c */
200 void do_pbc_first(FILE *log,matrix box,t_forcerec *fr,
201 t_graph *graph,rvec x[]);
203 void do_pbc_first_mtop(FILE *fplog,int ePBC,matrix box,
204 gmx_mtop_t *mtop,rvec x[]);
206 void do_pbc_mtop(FILE *fplog,int ePBC,matrix box,
207 gmx_mtop_t *mtop,rvec x[]);
210 /* ROUTINES from stat.c */
211 gmx_global_stat_t global_stat_init(t_inputrec *ir);
213 void global_stat_destroy(gmx_global_stat_t gs);
215 void global_stat(FILE *log,gmx_global_stat_t gs,
216 t_commrec *cr,gmx_enerdata_t *enerd,
217 tensor fvir,tensor svir,rvec mu_tot,
218 t_inputrec *inputrec,
219 gmx_ekindata_t *ekind,
220 gmx_constr_t constr,t_vcm *vcm,
221 int nsig,real *sig,
222 gmx_mtop_t *top_global, t_state *state_local,
223 gmx_bool bSumEkinhOld, int flags);
224 /* Communicate statistics over cr->mpi_comm_mysim */
226 gmx_mdoutf_t *init_mdoutf(int nfile,const t_filenm fnm[],
227 int mdrun_flags,
228 const t_commrec *cr,const t_inputrec *ir,
229 const output_env_t oenv);
230 /* Returns a pointer to a data structure with all output file pointers
231 * and names required by mdrun.
234 void done_mdoutf(gmx_mdoutf_t *of);
235 /* Close all open output files and free the of pointer */
237 #define MDOF_X (1<<0)
238 #define MDOF_V (1<<1)
239 #define MDOF_F (1<<2)
240 #define MDOF_XTC (1<<3)
241 #define MDOF_CPT (1<<4)
243 void write_traj(FILE *fplog,t_commrec *cr,
244 gmx_mdoutf_t *of,
245 int mdof_flags,
246 gmx_mtop_t *top_global,
247 gmx_large_int_t step,double t,
248 t_state *state_local,t_state *state_global,
249 rvec *f_local,rvec *f_global,
250 int *n_xtc,rvec **x_xtc);
251 /* Routine that writes frames to trn, xtc and/or checkpoint.
252 * What is written is determined by the mdof_flags defined above.
253 * Data is collected to the master node only when necessary.
256 int do_per_step(gmx_large_int_t step,gmx_large_int_t nstep);
257 /* Return TRUE if io should be done */
259 int do_any_io(int step, t_inputrec *ir);
261 /* ROUTINES from sim_util.c */
263 double gmx_gettime();
265 void print_time(FILE *out, gmx_runtime_t *runtime,
266 gmx_large_int_t step,t_inputrec *ir, t_commrec *cr);
268 void runtime_start(gmx_runtime_t *runtime);
270 void runtime_end(gmx_runtime_t *runtime);
272 void runtime_upd_proc(gmx_runtime_t *runtime);
273 /* The processor time should be updated every once in a while,
274 * since on 32-bit manchines it loops after 72 minutes.
277 void print_date_and_time(FILE *log,int pid,const char *title,
278 const gmx_runtime_t *runtime);
280 void nstop_cm(FILE *log,t_commrec *cr,
281 int start,int nr_atoms,real mass[],rvec x[],rvec v[]);
283 void finish_run(FILE *log,t_commrec *cr,const char *confout,
284 t_inputrec *inputrec,
285 t_nrnb nrnb[],gmx_wallcycle_t wcycle,
286 gmx_runtime_t *runtime,
287 gmx_bool bWriteStat);
289 void calc_enervirdiff(FILE *fplog,int eDispCorr,t_forcerec *fr);
291 void calc_dispcorr(FILE *fplog,t_inputrec *ir,t_forcerec *fr,
292 gmx_large_int_t step, int natoms,
293 matrix box,real lambda,tensor pres,tensor virial,
294 real *prescorr, real *enercorr, real *dvdlcorr);
296 typedef enum
298 LIST_SCALARS =0001,
299 LIST_INPUTREC =0002,
300 LIST_TOP =0004,
301 LIST_X =0010,
302 LIST_V =0020,
303 LIST_F =0040,
304 LIST_LOAD =0100
305 } t_listitem;
307 void check_nnodes_top(char *fn,t_topology *top);
308 /* Reset the tpr file to work with one node if necessary */
311 /* check the version */
312 void check_ir_old_tpx_versions(t_commrec *cr,FILE *fplog,
313 t_inputrec *ir,gmx_mtop_t *mtop);
315 /* Allocate and initialize node-local state entries. */
316 void set_state_entries(t_state *state,const t_inputrec *ir,int nnodes);
318 /* Broadcast the data for a simulation, and allocate node-specific settings
319 such as rng generators. */
320 void init_parallel(FILE *log, t_commrec *cr, t_inputrec *inputrec,
321 gmx_mtop_t *mtop);
324 void do_constrain_first(FILE *log,gmx_constr_t constr,
325 t_inputrec *inputrec,t_mdatoms *md,
326 t_state *state,rvec *f,
327 t_graph *graph,t_commrec *cr,t_nrnb *nrnb,
328 t_forcerec *fr, gmx_localtop_t *top, tensor shake_vir);
330 void dynamic_load_balancing(gmx_bool bVerbose,t_commrec *cr,real capacity[],
331 int dimension,t_mdatoms *md,t_topology *top,
332 rvec x[],rvec v[],matrix box);
333 /* Perform load balancing, i.e. split the particles over processors
334 * based on their coordinates in the "dimension" direction.
337 int mdrunner(int nthreads_requested, FILE *fplog,t_commrec *cr,int nfile,
338 const t_filenm fnm[], const output_env_t oenv, gmx_bool bVerbose,
339 gmx_bool bCompact, int nstglobalcomm, ivec ddxyz,int dd_node_order,
340 real rdd, real rconstr, const char *dddlb_opt,real dlb_scale,
341 const char *ddcsx,const char *ddcsy,const char *ddcsz,
342 int nstepout, int resetstep, int nmultisim, int repl_ex_nst,
343 int repl_ex_seed, real pforce,real cpt_period,real max_hours,
344 const char *deviceOptions, unsigned long Flags);
345 /* Driver routine, that calls the different methods */
347 void md_print_warning(const t_commrec *cr,FILE *fplog,const char *buf);
348 /* Print a warning message to stderr on the master node
349 * and to fplog if fplog!=NULL.
352 void init_md(FILE *fplog,
353 t_commrec *cr,t_inputrec *ir, const output_env_t oenv,
354 double *t,double *t0,
355 real *lambda,double *lam0,
356 t_nrnb *nrnb,gmx_mtop_t *mtop,
357 gmx_update_t *upd,
358 int nfile,const t_filenm fnm[],
359 gmx_mdoutf_t **outf,t_mdebin **mdebin,
360 tensor force_vir,tensor shake_vir,
361 rvec mu_tot,
362 gmx_bool *bSimAnn,t_vcm **vcm,
363 t_state *state, unsigned long Flags);
364 /* Routine in sim_util.c */
366 #ifdef __cplusplus
368 #endif
370 #endif /* _mdrun_h */