a2a8a446aa1dd5a02ff1006dd240924b94f7c640
[alexxy/gromacs.git] / src / gromacs / legacyheaders / statutil.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 _statutil_h
37 #define _statutil_h
38
39 #include "typedefs.h"
40 #include "filenm.h"
41 #include "readinp.h"
42 #include "pdbio.h"
43 #include "oenv.h"
44 #include "gmxfio.h"
45
46 #ifdef __cplusplus
47 extern "C" {
48 #endif
49 #if 0 /* avoid screwing up indentation */
50 }
51 #endif
52
53
54 /* The code below is to facilitate controlled begin and end of
55    trajectory reading. Corresponding routines in
56    src/gmxlib/tcontrol.c
57  */
58 enum {
59     TBEGIN, TEND, TDELTA, TNR
60 };
61
62 gmx_bool bTimeSet(int tcontrol);
63
64 real rTimeValue(int tcontrol);
65
66 void setTimeValue(int tcontrol, real value);
67
68 /* End trajectory time control */
69
70 /* a dedicated status type contains fp, etc. */
71 typedef struct t_trxstatus t_trxstatus;
72
73 /* I/O function types */
74
75
76 /* LEGACY FUNCTIONS
77
78    The program names, command lines, etc. are now also set in the output_env
79    structure. That is now the preferred location, but the functions here
80    are still available as legacy functions. Because they all act on inherently
81    global informaion, their existence in a multi-threaded environment is not
82    a real problem. */
83
84 /* set the program name to the provided string, but note
85  * that it must be a real file - we determine the library
86  * directory from its location!
87  */
88 const char *Program(void);
89 /* Id. without leading directory */
90 const char *ShortProgram(void);
91
92 /************************************************
93  *             Trajectory functions
94  ************************************************/
95
96 int prec2ndec(real prec);
97 /* Convert precision in 1/(nm) to number of decimal places */
98
99 void clear_trxframe(t_trxframe *fr, gmx_bool bFirst);
100 /* Set all content gmx_booleans to FALSE.
101  * When bFirst = TRUE, set natoms=-1, all pointers to NULL
102  *                     and all data to zero.
103  */
104
105 void set_trxframe_ePBC(t_trxframe *fr, int ePBC);
106 /* Set the type of periodic boundary conditions, ePBC=-1 is not set */
107
108 int nframes_read(t_trxstatus *status);
109 /* Returns the number of frames read from the trajectory */
110
111 int write_trxframe_indexed(t_trxstatus *status, t_trxframe *fr, int nind,
112                            const atom_id *ind, gmx_conect gc);
113 /* Write an indexed frame to a TRX file, see write_trxframe. gc may be NULL */
114
115 int write_trxframe(t_trxstatus *status, t_trxframe *fr, gmx_conect gc);
116 /* Write a frame to a TRX file.
117  * Only entries for which the gmx_boolean is TRUE will be written,
118  * except for step, time, lambda and/or box, which may not be
119  * omitted for certain trajectory formats.
120  * The precision for .xtc and .gro is fr->prec, when fr->bPrec=FALSE,
121  * the precision is set to 1000.
122  * gc is important for pdb file writing only and may be NULL.
123  */
124
125 int write_trx(t_trxstatus *status, int nind, const atom_id *ind, t_atoms *atoms,
126               int step, real time, matrix box, rvec x[], rvec *v,
127               gmx_conect gc);
128 /* Write an indexed frame to a TRX file.
129  * v can be NULL.
130  * atoms can be NULL for file types which don't need atom names.
131  */
132
133 void close_trx(t_trxstatus *status);
134 /* Close trj file as opened with read_first_x, read_frist_frame
135  * or open_trx. Identical to close_trj.
136  */
137
138 t_trxstatus *open_trx(const char *outfile, const char *filemode);
139 /* Open a TRX file and return an allocated status pointer */
140
141 /* get a fileio from a trxstatus */
142 t_fileio *trx_get_fileio(t_trxstatus *status);
143
144
145 gmx_bool bRmod_fd(double a, double b, double c, gmx_bool bDouble);
146 /* Returns TRUE when (a - b) MOD c = 0, using a margin which is slightly
147  * larger than the float/double precision.
148  */
149
150 #ifdef GMX_DOUBLE
151 #define bRmod(a, b, c) bRmod_fd(a, b, c, TRUE)
152 #else
153 #define bRmod(a, b, c) bRmod_fd(a, b, c, FALSE)
154 #endif
155
156 int check_times2(real t, real t0, gmx_bool bDouble);
157 /* This routine checkes if the read-in time is correct or not;
158  * returns -1 if t<tbegin or t MOD dt = t0,
159  *          0 if tbegin <= t <=tend+margin,
160  *          1 if t>tend
161  * where margin is 0.1*min(t-tp,tp-tpp), if this positive, 0 otherwise.
162  * tp and tpp should be the time of the previous frame and the one before.
163  * The mod is done with single or double precision accuracy depending
164  * on the value of bDouble.
165  */
166
167 int check_times(real t);
168 /* This routine checkes if the read-in time is correct or not;
169  * returns -1 if t<tbegin,
170  *          0 if tbegin <= t <=tend,
171  *          1 if t>tend
172  */
173
174
175
176
177
178 /* For trxframe.flags, used in trxframe read routines.
179  * When a READ flag is set, the field will be read when present,
180  * but a frame might be returned which does not contain the field.
181  * When a NEED flag is set, frames not containing the field will be skipped.
182  */
183 #define TRX_READ_X    (1<<0)
184 #define TRX_NEED_X    (1<<1)
185 #define TRX_READ_V    (1<<2)
186 #define TRX_NEED_V    (1<<3)
187 #define TRX_READ_F    (1<<4)
188 #define TRX_NEED_F    (1<<5)
189 /* Useful for reading natoms from a trajectory without skipping */
190 #define TRX_DONT_SKIP (1<<6)
191
192 /* For trxframe.not_ok */
193 #define HEADER_NOT_OK (1<<0)
194 #define DATA_NOT_OK   (1<<1)
195 #define FRAME_NOT_OK  (HEADER_NOT_OK | DATA_NOT_OK)
196
197 int read_first_frame(const output_env_t oenv, t_trxstatus **status,
198                      const char *fn, t_trxframe *fr, int flags);
199 /* Read the first frame which is in accordance with flags, which are
200  * defined further up in this file.
201  * Returns natoms when succeeded, 0 otherwise.
202  * Memory will be allocated for flagged entries.
203  * The flags are copied to fr for subsequent calls to read_next_frame.
204  * Returns TRUE when succeeded, FALSE otherwise.
205  */
206
207 gmx_bool read_next_frame(const output_env_t oenv, t_trxstatus *status,
208                          t_trxframe *fr);
209 /* Reads the next frame which is in accordance with fr->flags.
210  * Returns TRUE when succeeded, FALSE otherwise.
211  */
212
213 int read_first_x(const output_env_t oenv, t_trxstatus **status,
214                  const char *fn, real *t, rvec **x, matrix box);
215 /* These routines read first coordinates and box, and allocates
216  * memory for the coordinates, for a trajectory file.
217  * The routine returns the number of atoms, or 0 when something is wrong.
218  * The integer in status should be passed to calls of read_next_x
219  */
220
221 gmx_bool read_next_x(const output_env_t oenv, t_trxstatus *status, real *t, rvec x[], matrix box);
222 /* Read coordinates and box from a trajectory file. Return TRUE when all well,
223  * or FALSE when end of file (or last frame requested by user).
224  * status is the integer set in read_first_x.
225  */
226
227 void close_trj(t_trxstatus *status);
228 /* Close trj file as opened with read_first_x, read_frist_frame
229  * or open_trx. Identical to close_trx.
230  */
231
232 void rewind_trj(t_trxstatus *status);
233 /* Rewind trj file as opened with read_first_x */
234
235 t_topology *read_top(const char *fn, int *ePBC);
236 /* Extract a topology data structure from a topology file.
237  * If ePBC!=NULL *ePBC gives the pbc type.
238  */
239
240 /*****************************************************
241  *         Some command line parsing routines
242  *****************************************************/
243
244 #define PCA_CAN_VIEW       (1<<5)
245 /* add option -w to view output files (must be implemented in program) */
246 #define PCA_CAN_BEGIN      (1<<6)
247 #define PCA_CAN_END        (1<<7)
248 #define PCA_CAN_DT         (1<<14)
249 #define PCA_CAN_TIME       (PCA_CAN_BEGIN | PCA_CAN_END | PCA_CAN_DT)
250 /* adds options -b and -e for begin and end time for reading trajectories */
251 #define PCA_TIME_UNIT      (1<<15)
252 /* set time unit for output */
253 #define PCA_KEEP_ARGS      (1<<8)
254 /* keep parsed args in argv (doesn't make sense without NOEXIT_ON_ARGS) */
255 #define PCA_CAN_SET_DEFFNM (1<<10)
256 /* does something for non-master mdrun nodes */
257 #define PCA_NOEXIT_ON_ARGS (1<<11)
258 /* no fatal_error when invalid options are encountered */
259 #define PCA_QUIET          (1<<12)
260 /* does something for non-master mdrun nodes */
261 #define PCA_BE_NICE        (1<<13)
262 /* Default to low priority, unless configured with --disable-nice */
263 #define PCA_NOT_READ_NODE  (1<<16)
264 /* Is this node not reading: for parallel all nodes but the master */
265
266 int iscan(int argc, char *argv[], int *i);
267 /* Scan an int from the argument at *i. If the argument length
268  * is > 2, the int is assumed to be in the remainder of the arg,
269  * eg: -p32, else the int is assumed to be in the next argument
270  * eg: -p 32. If neither is the case the routine exits with an error,
271  * otherwise it returns the value found. If the value is in the next
272  * argument *i is incremented. You typically would want to pass
273  * a loop variable to this routine.
274  */
275 gmx_large_int_t istepscan(int argc, char *argv[], int *i);
276 /* Same as above, but for large integer values */
277
278 double dscan(int argc, char *argv[], int *i);
279 /* Routine similar to the above, but working on doubles. */
280
281 char *sscan(int argc, char *argv[], int *i);
282 /* Routine similar to the above, but working on strings. The pointer
283  * returned is a pointer to the argv field.
284  */
285
286 void vscan(int argc, char *argv[], int *i, rvec *vec);
287 /* Routine similar to the above, but working on rvecs. */
288
289 int nenum(const char *const enumc[]);
290 /* returns ordinal number of selected enum from args
291  * depends on enumc[0] pointing to one of the other elements
292  * array must be terminated by a NULL pointer
293  */
294
295 gmx_bool parse_common_args(int *argc, char *argv[], unsigned long Flags,
296                            int nfile, t_filenm fnm[], int npargs, t_pargs *pa,
297                            int ndesc, const char **desc,
298                            int nbugs, const char **bugs,
299                            output_env_t *oenv);
300 /* Get arguments from the arg-list. The arguments extracted
301  * are removed from the list. If manual is NULL a default message is displayed
302  * when errors are encountered. The Flags argument, when non-0 enables
303  * some input checks. Using this routine also means that the arguments
304  * -b and -e will be used for begin and end time, whether this is
305  * appropriate or not!
306  */
307
308 #ifdef __cplusplus
309 }
310 #endif
311
312 #endif