8eecf7a724677c63ccd9a7196538992d3510936d
[alexxy/gromacs.git] / include / sim_util.h
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.
14
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.
19  * 
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.
26  * 
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.
29  * 
30  * For more info, check our website at http://www.gromacs.org
31  * 
32  * And Hey:
33  * Gromacs Runs On Most of All Computer Systems
34  */
35
36 #ifndef _sim_util_h
37 #define _sim_util_h
38
39 #include <time.h>
40 #include "visibility.h"
41 #include "typedefs.h"
42 #include "enxio.h"
43 #include "mdebin.h"
44 #include "update.h"
45 #include "vcm.h"
46
47 #ifdef __cplusplus
48 extern "C" {
49 #endif
50
51 typedef struct {
52   t_fileio *fp_trn;
53   t_fileio *fp_xtc;
54   int  xtc_prec;
55   ener_file_t fp_ene;
56   const char *fn_cpt;
57   gmx_bool bKeepAndNumCPT;
58   int  eIntegrator;
59   gmx_bool  bExpanded;
60   int elamstats;
61   int  simulation_part;
62   FILE *fp_dhdl;
63   FILE *fp_field;
64 } gmx_mdoutf_t;
65
66 typedef struct gmx_global_stat *gmx_global_stat_t;
67
68 typedef struct {
69   double real;
70 #ifdef GMX_CRAY_XT3
71   double proc;
72 #else
73   clock_t proc;
74 #endif
75   double realtime;
76   double proctime;
77   double time_per_step;
78   double last;
79   gmx_large_int_t nsteps_done;
80 } gmx_runtime_t;
81
82
83 GMX_LIBMD_EXPORT
84 void do_pbc_first(FILE *log,matrix box,t_forcerec *fr,
85                          t_graph *graph,rvec x[]);
86
87 GMX_LIBMD_EXPORT
88 void do_pbc_first_mtop(FILE *fplog,int ePBC,matrix box,
89                               gmx_mtop_t *mtop,rvec x[]);
90
91 GMX_LIBMD_EXPORT
92 void do_pbc_mtop(FILE *fplog,int ePBC,matrix box,
93                         gmx_mtop_t *mtop,rvec x[]);
94
95
96                      
97 /* ROUTINES from stat.c */
98 GMX_LIBMD_EXPORT
99 gmx_global_stat_t global_stat_init(t_inputrec *ir);
100
101 void global_stat_destroy(gmx_global_stat_t gs);
102
103 void global_stat(FILE *log,gmx_global_stat_t gs,
104                         t_commrec *cr,gmx_enerdata_t *enerd,
105                         tensor fvir,tensor svir,rvec mu_tot,
106                         t_inputrec *inputrec,
107                         gmx_ekindata_t *ekind,
108                         gmx_constr_t constr,t_vcm *vcm,
109                         int nsig,real *sig,
110                         gmx_mtop_t *top_global, t_state *state_local, 
111                         gmx_bool bSumEkinhOld, int flags);
112 /* Communicate statistics over cr->mpi_comm_mysim */
113
114 gmx_mdoutf_t *init_mdoutf(int nfile,const t_filenm fnm[],
115                                  int mdrun_flags,
116                                  const t_commrec *cr,const t_inputrec *ir,
117                                  const output_env_t oenv);
118 /* Returns a pointer to a data structure with all output file pointers
119  * and names required by mdrun.
120  */
121
122 GMX_LIBMD_EXPORT
123 void done_mdoutf(gmx_mdoutf_t *of);
124 /* Close all open output files and free the of pointer */
125
126 #define MDOF_X   (1<<0)
127 #define MDOF_V   (1<<1)
128 #define MDOF_F   (1<<2)
129 #define MDOF_XTC (1<<3)
130 #define MDOF_CPT (1<<4)
131
132 GMX_LIBMD_EXPORT
133 void write_traj(FILE *fplog,t_commrec *cr,
134                        gmx_mdoutf_t *of,
135                        int mdof_flags,
136                        gmx_mtop_t *top_global,
137                        gmx_large_int_t step,double t,
138                        t_state *state_local,t_state *state_global,
139                        rvec *f_local,rvec *f_global,
140                        int *n_xtc,rvec **x_xtc);
141 /* Routine that writes frames to trn, xtc and/or checkpoint.
142  * What is written is determined by the mdof_flags defined above.
143  * Data is collected to the master node only when necessary.
144  */
145
146 GMX_LIBMD_EXPORT
147 int do_per_step(gmx_large_int_t step,gmx_large_int_t nstep);
148 /* Return TRUE if io should be done */
149
150 /* ROUTINES from sim_util.c */
151
152 GMX_LIBMD_EXPORT
153 double gmx_gettime();
154
155 GMX_LIBMD_EXPORT
156 void print_time(FILE *out, gmx_runtime_t *runtime,
157                        gmx_large_int_t step,t_inputrec *ir, t_commrec *cr);
158
159 GMX_LIBMD_EXPORT
160 void runtime_start(gmx_runtime_t *runtime);
161
162 GMX_LIBMD_EXPORT
163 void runtime_end(gmx_runtime_t *runtime);
164
165 GMX_LIBMD_EXPORT
166 void runtime_upd_proc(gmx_runtime_t *runtime);
167 /* The processor time should be updated every once in a while,
168  * since on 32-bit manchines it loops after 72 minutes.
169  */
170   
171 GMX_LIBMD_EXPORT
172 void print_date_and_time(FILE *log,int pid,const char *title,
173                                 const gmx_runtime_t *runtime);
174   
175 GMX_LIBMD_EXPORT
176 void finish_run(FILE *log,t_commrec *cr,const char *confout,
177                        t_inputrec *inputrec,
178                        t_nrnb nrnb[],gmx_wallcycle_t wcycle,
179                        gmx_runtime_t *runtime,
180                        wallclock_gpu_t *gputimes,
181                        int omp_nth_pp,
182                        gmx_bool bWriteStat);
183
184 void calc_enervirdiff(FILE *fplog,int eDispCorr,t_forcerec *fr);
185
186 void calc_dispcorr(FILE *fplog,t_inputrec *ir,t_forcerec *fr,
187                    gmx_large_int_t step, int natoms,
188                    matrix box,real lambda,tensor pres,tensor virial,
189                    real *prescorr, real *enercorr, real *dvdlcorr);
190
191 void initialize_lambdas(FILE *fplog,t_inputrec *ir,int *fep_state,real *lambda,double *lam0);
192
193 GMX_LIBMD_EXPORT
194 void do_constrain_first(FILE *log,gmx_constr_t constr,
195                                t_inputrec *inputrec,t_mdatoms *md,
196                                t_state *state,rvec *f,
197                                t_graph *graph,t_commrec *cr,t_nrnb *nrnb,
198                                t_forcerec *fr, gmx_localtop_t *top, tensor shake_vir); 
199                           
200 GMX_LIBMD_EXPORT
201 void init_md(FILE *fplog,
202                     t_commrec *cr,t_inputrec *ir, const output_env_t oenv, 
203                     double *t,double *t0,
204                     real *lambda,int *fep_state, double *lam0,
205                     t_nrnb *nrnb,gmx_mtop_t *mtop,
206                     gmx_update_t *upd,
207                     int nfile,const t_filenm fnm[],
208                     gmx_mdoutf_t **outf,t_mdebin **mdebin,
209                     tensor force_vir,tensor shake_vir,
210                     rvec mu_tot,
211                     gmx_bool *bSimAnn,t_vcm **vcm, 
212                     t_state *state, unsigned long Flags);
213   /* Routine in sim_util.c */
214
215 #ifdef __cplusplus
216 }
217 #endif
218
219 #endif  /* _sim_util_h */