Remove some include order dependencies
[alexxy/gromacs.git] / src / gromacs / gmxana / geminate.h
1 /*
2  * This file is part of the GROMACS molecular simulation package.
3  *
4  * Copyright (c) 2010,2011,2013,2014, by the GROMACS development team, led by
5  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
6  * and including many others, as listed in the AUTHORS file in the
7  * top-level source directory and at http://www.gromacs.org.
8  *
9  * GROMACS is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public License
11  * as published by the Free Software Foundation; either version 2.1
12  * of the License, or (at your option) any later version.
13  *
14  * GROMACS is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17  * Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with GROMACS; if not, see
21  * http://www.gnu.org/licenses, or write to the Free Software Foundation,
22  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA.
23  *
24  * If you want to redistribute modifications to GROMACS, please
25  * consider that scientific software is very special. Version
26  * control is crucial - bugs must be traceable. We will be happy to
27  * consider code for inclusion in the official distribution, but
28  * derived work must not be called official GROMACS. Details are found
29  * in the README & COPYING files - if they are missing, get the
30  * official version at http://www.gromacs.org.
31  *
32  * To help us fund GROMACS development, we humbly ask that you cite
33  * the research papers on the package. Check out http://www.gromacs.org.
34  */
35 #ifndef _GEMINATE_H
36 #define _GEMINATE_H
37
38 #include <stddef.h>
39
40 #include "gromacs/utility/basedefinitions.h"
41 #include "gromacs/utility/real.h"
42
43 enum {
44     gemNULL, gemNONE, gemDD, gemAD, gemAA, gemA4, gemNR
45 };
46 static const char *gemType[] = {NULL, "none", "dd", "ad", "aa", "a4", NULL};
47
48 /* The first few sections of this file contain functions that were adopted,
49  * and to some extent modified, by Erik Marklund (erikm[aT]xray.bmc.uu.se,
50  * http://folding.bmc.uu.se) from code written by Omer Markovitch (email, url).
51  * This is also the case with the function eq10v2() in geminate.c.
52  *
53  * The parts menetioned in the previous paragraph were contributed under a BSD license.
54  */
55
56 /* This first part is derived from complex.c which I recieved from Omer Markowitch.
57  * - Erik Marklund
58  *
59  * ------------- from complex.c ------------- */
60
61 #include <math.h>
62 /* definition of PI */
63 #ifndef PI
64 #define PI (acos(-1.0))
65 #endif
66
67 /* definition of the type complex */
68 typedef struct
69 {
70     double r, i;
71 } gem_complex;
72
73
74 /* ------------ end of complex.c ------------ */
75
76 /* This next part was derived from cerror.c and rerror.c,
77  * also received from Omer Markovitch.
78  * ------------- from [cr]error.c ------------- */
79
80 #ifndef sPI
81 #define sPI (sqrt(PI))
82 #endif
83
84 /* ------------ end of [cr]error.c ------------ */
85
86 /* ///////////////// REVERSIBLE GEMINATE RECOMBINATION ///////////////////
87  * Here follow routines and structs for reversible geminate recombination.
88  */
89
90 typedef struct {
91     size_t  n;
92     double *y;
93     double  tDelta;
94     int     nexp;
95 } balData;
96
97
98 typedef struct {
99     /* Used in the rewritten version of Omer's gem. recomb. analysis */
100     double ka, kd;               /* -- || -- results[]  */
101     double sigma;                /* -- || -- sigma      */
102     double D;                    /* The diffusion coefficient */
103     double kD;                   /* Replaces kD in analyse_corr_gem3d() */
104
105     /* The following members are for calcsquare() and takeAwayBallistic() */
106     double tDelta;            /* Time between frames */
107     /* double logAfterTime;        /\* Time after which we do the lsq calculations on a logarithmic timescale. *\/ */
108     int    nFitPoints;        /* Number of points to take from the ACF for fitting */
109     double begFit;            /* Fit from this time (ps) */
110     double endFit;            /* Fit up to this time (ps) */
111 /*   double logDelta; */
112 /*   double logPF; */
113 /* To get an equal number of points in the lin and log regime,
114  * we'll use logDelta to calculate where to sample the ACF.
115  * if i and j are indices in the linear and log regime, then:
116  *   j = Cexp(A(i+nLin)),
117  * where C = (nLin**2 / len) and A = log(len/nLin) / nLin.
118  * This expands to j = (nLin**2 / len) * exp((i+nLin) * log(len/nLin) / nLin).
119  * We'll save part of our brains and some computing time if we pre-calculate
120  *  1) logDelta = log(len/nLin) / nLin
121  *  2) logPF    = nLin**2 / len
122  * and get j = logPF * exp((i+nLin) * logDelta). */
123
124     /* I will redo this for a fit done entirely in log-log.
125      *  j' = j+1
126      *  nFitPoints' = nFitPoints-1
127      *
128      *  j' = Cexp(Ai)
129      *  (j'= 1 <=> i=0)
130      *     => C=1
131      *  (j'=len <=> i=nFitPoints')
132      *     => A=log(len)/nFitPoints'
133      *     => j = exp(i*log(len)/(nFitPoints-1)) -1
134      **/
135 /* #define GETLOGINDEX(i,params) (params)->logPF * exp(((i)+(params)->nLin) * (params)->logDelta)
136  */
137     double   logQuota;
138     int      nLin;          /* Number of timepoints in the linear regime */
139     int      len;           /* Length of time and ct arrays */
140     int      nExpFit;       /* Number of exponentials to fit */
141     real     ballistic;     /* Time before which the ballistic term should be fitted */
142     gmx_bool bDt;           /* TRUE =>  use time derivative at time 0
143                              *          to find fastest component.
144                              * FALSE => use coefficient in exponenetial
145                              *          to find fastest component. */
146 } t_gemParams;
147
148
149 typedef struct {
150     size_t       n;        /* Number of data points (lin-log) */
151     double      *y;        /* The datapoints */
152     double      *ctTheory; /* The theoretical ct which will be built by gemFunc_f. */
153     double      *LinLog;
154     double      *time;
155     double       ka;
156     double       kd;
157     double       tDelta; /* time difference between subsequent datapoints */
158     size_t       nData;  /* real size of the data */
159     int         *logtime;
160     double      *doubleLogTime;
161     t_gemParams *params;
162 } gemFitData;
163
164 extern void takeAwayBallistic(double *ct, double *t,
165                               int len, real tMax,
166                               int nexp, gmx_bool bDerivative);
167
168
169 extern t_gemParams *init_gemParams(const double sigma, const double D,
170                                    const real *t, const int len, const int nFitPoints,
171                                    const real begFit, const real endFit,
172                                    const real ballistic, const int nBalExp);
173
174 /* Fit to geminate recombination model.
175    Returns root mean square error of fit. */
176 extern real fitGemRecomb(double *ct, double *time, double **ctFit,
177                          const int nData, t_gemParams *params);
178
179 extern void dumpN(const real *e, const int nn, char *fn);
180
181 /* Fix NaN that might appear in the theoretical acf. */
182 extern void fixGemACF(double *ct, int len);
183
184 #endif