Enforced rotation: fixed torque calculation for FLEX potential when using mass-weighting
[gromacs/adressmacs.git] / src / tools / geminate.h
blob89faf23bad841b533a9915451ef0ed5d7381281a
1 #ifndef _GEMINATE_H
2 #define _GEMINATE_H
4 enum { gemNULL, gemNONE, gemDD, gemAD, gemAA, gemA4, gemNR};
5 static const char *gemType[] = {NULL, "none", "dd", "ad", "aa", "a4", NULL};
7 /* The first few sections of this file contain functions that were adopted,
8 * and to some extent modified, by Erik Marklund (erikm[aT]xray.bmc.uu.se,
9 * http://folding.bmc.uu.se) from code written by Omer Markovitch (email, url).
10 * This is also the case with the function eq10v2() in geminate.c.
12 * The parts menetioned in the previous paragraph were contributed under a BSD license.
15 /* This first part is derived from complex.c which I recieved from Omer Markowitch.
16 * - Erik Marklund
18 * ------------- from complex.c ------------- */
20 #include <math.h>
21 /* definition of PI */
22 #ifndef PI
23 #define PI (acos(-1.0))
24 #endif
26 /* definition of the type complex */
27 typedef struct
29 double r,i;
30 } gem_complex;
33 /* ------------ end of complex.c ------------ */
35 /* This next part was derived from cerror.c and rerror.c,
36 * also received from Omer Markovitch.
37 * ------------- from [cr]error.c ------------- */
39 #ifndef sPI
40 #define sPI (sqrt(PI))
41 #endif
43 /* ------------ end of [cr]error.c ------------ */
45 /* ///////////////// REVERSIBLE GEMINATE RECOMBINATION ///////////////////
46 * Here follow routines and structs for reversible geminate recombination.
49 typedef struct{
50 size_t n;
51 double *y;
52 double tDelta;
53 int nexp;
54 } balData;
57 typedef struct {
58 /* Used in the rewritten version of Omer's gem. recomb. analysis */
59 double ka, kd; /* -- || -- results[] */
60 double sigma; /* -- || -- sigma */
61 double D; /* The diffusion coefficient */
62 double kD; /* Replaces kD in analyse_corr_gem3d() */
64 /* The following members are for calcsquare() and takeAwayBallistic() */
65 double tDelta; /* Time between frames */
66 /* double logAfterTime; /\* Time after which we do the lsq calculations on a logarithmic timescale. *\/ */
67 int nFitPoints; /* Number of points to take from the ACF for fitting */
68 double begFit; /* Fit from this time (ps) */
69 double endFit; /* Fit up to this time (ps) */
70 /* double logDelta; */
71 /* double logPF; */
72 /* To get an equal number of points in the lin and log regime,
73 * we'll use logDelta to calculate where to sample the ACF.
74 * if i and j are indices in the linear and log regime, then:
75 * j = Cexp(A(i+nLin)),
76 * where C = (nLin**2 / len) and A = log(len/nLin) / nLin.
77 * This expands to j = (nLin**2 / len) * exp((i+nLin) * log(len/nLin) / nLin).
78 * We'll save part of our brains and some computing time if we pre-calculate
79 * 1) logDelta = log(len/nLin) / nLin
80 * 2) logPF = nLin**2 / len
81 * and get j = logPF * exp((i+nLin) * logDelta). */
83 /* I will redo this for a fit done entirely in log-log.
84 * j' = j+1
85 * nFitPoints' = nFitPoints-1
87 * j' = Cexp(Ai)
88 * (j'= 1 <=> i=0)
89 * => C=1
90 * (j'=len <=> i=nFitPoints')
91 * => A=log(len)/nFitPoints'
92 * => j = exp(i*log(len)/(nFitPoints-1)) -1
93 **/
94 /* #define GETLOGINDEX(i,params) (params)->logPF * exp(((i)+(params)->nLin) * (params)->logDelta)
96 double logQuota;
97 int nLin; /* Number of timepoints in the linear regime */
98 int len; /* Length of time and ct arrays */
99 int nExpFit; /* Number of exponentials to fit */
100 real ballistic; /* Time before which the ballistic term should be fitted */
101 gmx_bool bDt; /* TRUE => use time derivative at time 0
102 * to find fastest component.
103 * FALSE => use coefficient in exponenetial
104 * to find fastest component. */
105 } t_gemParams;
108 typedef struct{
109 size_t n; /* Number of data points (lin-log) */
110 double *y; /* The datapoints */
111 double *ctTheory; /* The theoretical ct which will be built by gemFunc_f. */
112 double *LinLog;
113 double *time;
114 double ka;
115 double kd;
116 double tDelta; /* time difference between subsequent datapoints */
117 size_t nData; /* real size of the data */
118 int *logtime;
119 double *doubleLogTime;
120 t_gemParams *params;
121 } gemFitData;
123 extern void takeAwayBallistic(double *ct, double *t,
124 int len, real tMax,
125 int nexp, gmx_bool bDerivative);
128 extern t_gemParams *init_gemParams(const double sigma, const double D,
129 const real *t, const int len, const int nFitPoints,
130 const real begFit, const real endFit,
131 const real ballistic, const int nBalExp, const gmx_bool bDt);
133 /* Fit to geminate recombination model.
134 Returns root mean square error of fit. */
135 extern real fitGemRecomb(double *ct, double *time, double **ctFit,
136 const int nData, t_gemParams *params);
138 extern void dumpN(const real *e, const int nn, char *fn);
140 #endif