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