Code beautification with uncrustify
[alexxy/gromacs.git] / src / gromacs / legacyheaders / gstat.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 _gstat_h
37 #define _gstat_h
38
39 #include "typedefs.h"
40 #include "statutil.h"
41 #include "mshift.h"
42 #include "rmpbc.h"
43
44 #ifdef __cplusplus
45 extern "C" {
46 #endif
47
48 /***********************************************
49  *
50  *     A U T O C O R R E L A T I O N
51  *
52  ***********************************************/
53
54 real LegendreP(real x, unsigned long m);
55
56 #define eacNormal (1<<0)
57 #define eacCos    (1<<1)
58 #define eacVector (1<<2)
59 #define eacRcross (1<<3  | eacVector)
60 #define eacP0     (1<<4  | eacVector)
61 #define eacP1     (1<<5  | eacVector)
62 #define eacP2     (1<<6  | eacVector)
63 #define eacP3     (1<<7  | eacVector)
64 #define eacP4     (1<<8  | eacVector)
65 #define eacIden   (1<<9)
66
67 enum {
68     effnNONE, effnEXP1, effnEXP2, effnEXP3,   effnVAC,
69     effnEXP5, effnEXP7, effnEXP9, effnERF, effnERREST, effnNR
70 };
71
72 /* must correspond with 'leg' g_chi.c:727 */
73 enum {
74     edPhi = 0, edPsi, edOmega, edChi1, edChi2, edChi3, edChi4, edChi5, edChi6, edMax
75 };
76
77 enum {
78     edPrintST = 0, edPrintRO
79 };
80
81 #define NHISTO 360
82 #define NONCHI 3
83 #define MAXCHI edMax-NONCHI
84 #define NROT 4  /* number of rotamers: 1=g(-), 2=t, 3=g(+), 0=other */
85
86 typedef struct {
87     int minO, minC, H, N, C, O, Cn[MAXCHI+3];
88 } t_dihatms; /* Cn[0]=N, Cn[1]=Ca, Cn[2]=Cb etc. */
89
90 typedef struct {
91     char       name[12];
92     int        resnr;
93     int        index;     /* Index for amino acids (histograms) */
94     int        j0[edMax]; /* Index in dih array (phi angle is first...) */
95     t_dihatms  atm;
96     int        b[edMax];
97     int        ntr[edMax];
98     real       S2[edMax];
99     real       rot_occ[edMax][NROT];
100
101 } t_dlist;
102
103 extern const int   nfp_ffn[effnNR];
104
105 extern const char *s_ffn[effnNR+2];
106
107 extern const char *longs_ffn[effnNR];
108
109 int sffn2effn(const char **sffn);
110 /* Returns the ffn enum corresponding to the selected enum option in sffn */
111
112 t_pargs *add_acf_pargs(int *npargs, t_pargs *pa);
113 /* Add options for autocorr to the current set of options.
114  * *npargs must be initialised to the number of elements in pa,
115  * it will be incremented appropriately.
116  */
117
118 void cross_corr(int n, real f[], real g[], real corr[]);
119 /* Simple minded cross correlation algorithm */
120
121 real fit_acf(int ncorr, int fitfn, const output_env_t oenv, gmx_bool bVerbose,
122              real tbeginfit, real tendfit, real dt, real c1[], real *fit);
123 /* Fit an ACF to a given function */
124
125 void do_autocorr(const char *fn, const output_env_t oenv,
126                  const char *title,
127                  int nframes, int nitem, real **c1,
128                  real dt, unsigned long mode, gmx_bool bAver);
129 /* Calls low_do_autocorr (see below). After calling add_acf_pargs */
130
131 void low_do_autocorr(const char *fn, const output_env_t oenv,
132                      const char *title, int  nframes, int nitem,
133                      int nout, real **c1, real dt, unsigned long mode,
134                      int nrestart, gmx_bool bAver, gmx_bool bNormalize,
135                      gmx_bool bVerbose, real tbeginfit, real tendfit,
136                      int nfitparm, int nskip);
137 /*
138  * do_autocorr calculates autocorrelation functions for many things.
139  * It takes a 2 d array containing nitem arrays of length nframes
140  * for each item the ACF is calculated.
141  *
142  * A number of "modes" exist for computation of the ACF
143  *
144  * if (mode == eacNormal) {
145  *   C(t) = < X (tau) * X (tau+t) >
146  * }
147  * else if (mode == eacCos) {
148  *   C(t) = < cos (X(tau) - X(tau+t)) >
149  * }
150  * else if (mode == eacIden) { **not fully supported yet**
151  *   C(t) = < (X(tau) == X(tau+t)) >
152  * }
153  * else if (mode == eacVector) {
154  *   C(t) = < X(tau) * X(tau+t)
155  * }
156  * else if (mode == eacP1) {
157  *   C(t) = < cos (X(tau) * X(tau+t) >
158  * }
159  * else if (mode == eacP2) {
160  *   C(t) = 1/2 * < 3 cos (X(tau) * X(tau+t) - 1 >
161  * }
162  * else if (mode == eacRcross) {
163  *   C(t) = < ( X(tau) * X(tau+t) )^2 >
164  * }
165  *
166  * For modes eacVector, eacP1, eacP2 and eacRcross the input should be
167  * 3 x nframes long, where each triplet is taken as a 3D vector
168  *
169  * For mode eacCos inputdata must be in radians, not degrees!
170  *
171  * Other parameters are:
172  *
173  * fn is output filename (.xvg) where the correlation function(s) are printed
174  * title is the title in the output file
175  * nframes is the number of frames in the time series
176  * nitem is the number of items
177  * c1       is an array of dimension [ 0 .. nitem-1 ] [ 0 .. nframes-1 ]
178  *          on output, this array is filled with the correlation function
179  *          to reduce storage
180  * nrestart     is the number of steps between restarts for direct ACFs
181  *              (i.e. without FFT) When set to 1 all points are used as
182  *              time origin for averaging
183  * dt       is the time between frames
184  * bAver    If set, all ndih C(t) functions are averaged into a single
185  *          C(t)
186  * (bFour       If set, will use fast fourier transform (FFT) for evaluating
187  *              the ACF: removed option, now on the command line only)
188  * bNormalize   If set, all ACFs will be normalized to start at 0
189  * nskip        Determines whether steps a re skipped in the output
190  */
191
192 typedef struct {
193     const char *name;    /* Description of the J coupling constant */
194     real        A, B, C; /* Karplus coefficients */
195     real        offset;  /* Offset for dihedral angle in histogram (e.g. -M_PI/3) */
196     real        Jc;      /* Resulting Jcoupling */
197     real        Jcsig;   /* Standard deviation in Jc */
198 } t_karplus;
199
200 void calc_distribution_props(int nh, int histo[],
201                              real start, int  nkkk, t_karplus kkk[],
202                              real *S2);
203 /* This routine takes a dihedral distribution and calculates
204  * coupling constants and dihedral order parameters of it.
205  *
206  * nh      is the number of points
207  * histo   is the array of datapoints which is assumed to span
208  *         2 M_PI radians
209  * start   is the starting angle of the histogram, this can be either 0
210  *         or -M_PI
211  * nkkk    is the number of karplus sets (multiple coupling constants may be
212  *         derived from a single angle)
213  * kkk     are the constants for calculating J coupling constants using a
214  *         Karplus equation according to
215  *
216  *                  2
217  *         J = A cos theta + B cos theta + C
218  *
219  *         where theta is phi - offset (phi is the angle in the histogram)
220  * offset  is subtracted from phi before substitution in the Karplus
221  *         equation
222  * S2      is the resulting dihedral order parameter
223  *
224  */
225
226
227 /***********************************************
228  *
229  *     F I T   R O U T I N E S
230  *
231  ***********************************************/
232 void do_expfit(int ndata, real c1[], real dt,
233                real begintimefit, real endtimefit);
234
235 void expfit(int n, real x[], real y[], real Dy[],
236             real *a, real *sa,
237             real *b, real *sb);
238 /* This procedure fits y=exp(a+bx) for n (x,y) pairs to determine a and b.
239  * The uncertainties in the y values must be in the vector Dy.
240  * The standard deviations of a and b, sa and sb, are also calculated.
241  *
242  * Routine from Computers in physics, 7(3) (1993), p. 280-285.
243  */
244
245 void ana_dih_trans(const char *fn_trans, const char *fn_histo,
246                    real **dih, int nframes, int nangles,
247                    const char *grpname, real *time, gmx_bool bRb,
248                    const output_env_t oenv);
249 /*
250  * Analyse dihedral transitions, by counting transitions per dihedral
251  * and per frame. The total number of transitions is printed to
252  * stderr, as well as the average time between transitions.
253  *
254  * is wrapper to low_ana_dih_trans, which also passes in and out the
255      number of transitions per dihedral per residue. that uses struc dlist
256      which is not external, so pp2shift.h must be included.
257
258  * Dihedrals are supposed to be in either of three minima,
259  * (trans, gauche+, gauche-)
260  *
261  * fn_trans  output file name for #transitions per timeframe
262  * fn_histo  output file name for transition time histogram
263  * dih       the actual dihedral angles
264  * nframes   number of times frames
265  * nangles   number of angles
266  * grpname   a string for the header of plots
267  * time      array (size nframes) of times of trajectory frames
268  * bRb       determines whether the polymer convention is used
269  *           (trans = 0)
270  */
271
272 void low_ana_dih_trans(gmx_bool bTrans, const char *fn_trans,
273                        gmx_bool bHisto, const char *fn_histo, int maxchi,
274                        real **dih, int nlist, t_dlist dlist[],
275                        int nframes, int nangles, const char *grpname,
276                        int multiplicity[], real *time, gmx_bool bRb,
277                        real core_frac, const output_env_t oenv);
278 /* as above but passes dlist so can copy occupancies into it, and multiplicity[]
279  *  (1..nangles, corresp to dih[this][], so can have non-3 multiplicity of
280  * rotamers. Also production of xvg output files is conditional
281  * and the fractional width of each rotamer can be set ie for a 3 fold
282  * dihedral with core_frac = 0.5 only the central 60 degrees is assigned
283  * to each rotamer, the rest goes to rotamer zero */
284
285
286
287 void read_ang_dih(const char *trj_fn,
288                   gmx_bool bAngles, gmx_bool bSaveAll, gmx_bool bRb, gmx_bool bPBC,
289                   int maxangstat, int angstat[],
290                   int *nframes, real **time,
291                   int isize, atom_id index[],
292                   real **trans_frac,
293                   real **aver_angle,
294                   real *dih[],
295                   const output_env_t oenv);
296 /*
297  * Read a trajectory and calculate angles and dihedrals.
298  *
299  * trj_fn      file name of trajectory
300  * tpb_fn      file name of tpb file
301  * bAngles     do we have to read angles or dihedrals
302  * bSaveAll    do we have to store all in the dih array
303  * bRb         do we have Ryckaert-Bellemans dihedrals (trans = 0)
304  * bPBC        compute angles module 2 Pi
305  * maxangstat  number of entries in distribution array
306  * angstat     angle distribution
307  * *nframes    number of frames read
308  * time        simulation time at each time frame
309  * isize       number of entries in the index, when angles 3*number of angles
310  *             else 4*number of angles
311  * index       atom numbers that define the angles or dihedrals
312  *             (i,j,k) resp (i,j,k,l)
313  * trans_frac  number of dihedrals in trans
314  * aver_angle  average angle at each time frame
315  * dih         all angles at each time frame
316  */
317
318 void make_histo(FILE *log,
319                 int ndata, real data[], int npoints, int histo[],
320                 real minx, real maxx);
321 /*
322  * Make a histogram from data. The min and max of the data array can
323  * be determined (if minx == 0 and maxx == 0)
324  * and the index in the histogram is computed from
325  * ind = npoints/(max(data) - min(data))
326  *
327  * log       write error output to this file
328  * ndata     number of points in data
329  * data      data points
330  * npoints   number of points in histogram
331  * histo     histogram array. This is NOT set to zero, to allow you
332  *           to add multiple histograms
333  * minx      start of the histogram
334  * maxx      end of the histogram
335  *           if both are 0, these values are computed by the routine itself
336  */
337
338 void normalize_histo(int npoints, int histo[], real dx, real normhisto[]);
339 /*
340  * Normalize a histogram so that the integral over the histo is 1
341  *
342  * npoints    number of points in the histo array
343  * histo      input histogram
344  * dx         distance between points on the X-axis
345  * normhisto  normalized output histogram
346  */
347
348 real fit_function(int eFitFn, real *parm, real x);
349 /* Returns the value of fit function eFitFn at x */
350
351 /* Use Levenberg-Marquardt method to fit to a nfitparm parameter exponential */
352 /* or to a transverse current autocorrelation function */
353 /* Or: "There is no KILL like OVERKILL", Dr. Ir. D. van der Spoel */
354 real do_lmfit(int ndata, real c1[], real sig[], real dt, real *x,
355               real begintimefit, real endtimefit, const output_env_t oenv,
356               gmx_bool bVerbose, int eFitFn, real fitparms[], int fix);
357 /* Returns integral.
358  * If x == NULL, the timestep dt will be used to create a time axis.
359  * fix fixes fit parameter i at it's starting value, when the i'th bit
360  * of fix is set.
361  */
362
363 real evaluate_integral(int n, real x[], real y[], real dy[],
364                        real aver_start, real *stddev);
365 /* Integrate data in y, and, if given, use dy as weighting
366  * aver_start should be set to a value where the function has
367  * converged to 0.
368  */
369
370 real print_and_integrate(FILE *fp, int n, real dt,
371                          real c[], real *fit, int nskip);
372 /* Integrate the data in c[] from 0 to n using trapezium rule.
373  * If fp != NULL output is written to it
374  * nskip determines whether all elements are written to the output file
375  * (written when i % nskip == 0)
376  * If fit != NULL the fit is also written.
377  */
378
379 int get_acfnout(void);
380 /* Return the output length for the correlation function
381  * Works only AFTER do_auto_corr has been called!
382  */
383
384 int get_acffitfn(void);
385 /* Return the fit function type.
386  * Works only AFTER do_auto_corr has been called!
387  */
388
389 /* Routines from pp2shift (anadih.c etc.) */
390
391 void do_pp2shifts(FILE *fp, int nframes,
392                   int nlist, t_dlist dlist[], real **dih);
393
394 gmx_bool has_dihedral(int Dih, t_dlist *dl);
395
396 t_dlist *mk_dlist(FILE *log,
397                   t_atoms *atoms, int *nlist,
398                   gmx_bool bPhi, gmx_bool bPsi, gmx_bool bChi, gmx_bool bHChi,
399                   int maxchi, int r0, gmx_residuetype_t rt);
400
401 void pr_dlist(FILE *fp, int nl, t_dlist dl[], real dt,  int printtype,
402               gmx_bool bPhi, gmx_bool bPsi, gmx_bool bChi, gmx_bool bOmega, int maxchi);
403
404 int pr_trans(FILE *fp, int nl, t_dlist dl[], real dt, int Xi);
405
406 void mk_chi_lookup (int **lookup, int maxchi, real **dih,
407                     int nlist, t_dlist dlist[]);
408
409 void mk_multiplicity_lookup (int *multiplicity, int maxchi, real **dih,
410                              int nlist, t_dlist dlist[], int nangle);
411
412 void get_chi_product_traj (real **dih, int nframes, int nangles,
413                            int nlist, int maxchi, t_dlist dlist[],
414                            real time[], int **lookup, int *multiplicity,
415                            gmx_bool bRb, gmx_bool bNormalize,
416                            real core_frac, gmx_bool bAll, const char *fnall,
417                            const output_env_t oenv);
418
419 void print_one (const output_env_t oenv, const char *base,
420                 const char *name,
421                 const char *title, const char *ylabel, int nf,
422                 real time[], real data[]);
423
424 /* Routines from g_hbond */
425 void analyse_corr(int n, real t[], real ct[], real nt[], real kt[],
426                   real sigma_ct[], real sigma_nt[], real sigma_kt[],
427                   real fit_start, real temp, real smooth_tail_start,
428                   const output_env_t oenv);
429
430 void compute_derivative(int nn, real x[], real y[], real dydx[]);
431
432 #ifdef __cplusplus
433 }
434 #endif
435
436 #endif