Reorganize files for reference manual
[alexxy/gromacs.git] / docs / reference-manual / analysis / curve-fitting.rst
1 Curve fitting in |Gromacs|
2 --------------------------
3
4 Sum of exponential functions
5 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
6
7 Sometimes it is useful to fit a curve to an analytical function, for
8 example in the case of autocorrelation functions with noisy tails.
9 |Gromacs| is not a general purpose curve-fitting tool however and
10 therefore |Gromacs| only supports a limited number of functions.
11 :numref:`Table %s <table-fitfn>`  lists the available options with the corresponding
12 command-line options. The underlying routines for fitting use the
13 Levenberg-Marquardt algorithm as implemented in the lmfit package \ :ref:`162 <reflmfit>`
14 (a bare-bones version of which is included in |Gromacs| in which an
15 option for error-weighted fitting was implemented).
16
17 .. |exp|  replace:: :math:`e^{-t/{a_0}}`                                                       
18 .. |aexp| replace:: :math:`a_1e^{-t/{a_0}}`                                                    
19 .. |exp2| replace:: :math:`a_1e^{-t/{a_0}}+(1-a_1)e^{-t/{a_2}}`                                
20 .. |exp5| replace:: :math:`a_1e^{-t/{a_0}}+a_3e^{-t/{a_2}}+a_4`                                
21 .. |exp7| replace:: :math:`a_1e^{-t/{a_0}}+a_3e^{-t/{a_2}}+a_5e^{-t/{a_4}}+a_6`                
22 .. |exp9| replace:: :math:`a_1e^{-t/{a_0}}+a_3e^{-t/{a_2}}+a_5e^{-t/{a_4}}+a_7e^{-t/{a_6}}+a_8`
23 .. |nexp2| replace:: :math:`a_2\ge a_0\ge 0`               
24 .. |nexp5| replace:: :math:`a_2\ge a_0\ge 0`               
25 .. |nexp7| replace:: :math:`a_4\ge a_2\ge a_0 \ge0`        
26 .. |nexp9| replace:: :math:`a_6\ge a_4\ge a_2\ge a_0\ge 0` 
27
28 .. _table-fitfn:
29
30 .. table:: Overview of fitting functions supported in (most) analysis tools 
31     that compute autocorrelation functions. The **Note** column describes 
32     properties of the output parameters.
33     :align: center
34     :widths: auto
35
36     +-------------+------------------------------+---------------------+
37     | Command     | Functional form :math:`f(t)` | Note                |
38     | line option |                              |                     |
39     +=============+==============================+=====================+
40     | exp         | |exp|                        |                     |
41     +-------------+------------------------------+---------------------+
42     | aexp        | |aexp|                       |                     |
43     +-------------+------------------------------+---------------------+
44     | exp_exp     | |exp2|                       | |nexp2|             |
45     +-------------+------------------------------+---------------------+
46     | exp5        | |exp5|                       | |nexp5|             |
47     +-------------+------------------------------+---------------------+
48     | exp7        | |exp7|                       | |nexp7|             |
49     +-------------+------------------------------+---------------------+
50     | exp9        | |exp9|                       | |nexp9|             |
51     +-------------+------------------------------+---------------------+
52
53
54 Error estimation
55 ~~~~~~~~~~~~~~~~
56
57 Under the hood |Gromacs| implements some more fitting functions, namely a
58 function to estimate the error in time-correlated data due to Hess \ :ref:`149 <refHess2002a>`:
59
60 .. math::
61
62    \varepsilon^2(t) =
63    \alpha\tau_1\left(1+\frac{\tau_1}{t}\left(e^{-t/\tau_1}-1\right)\right)
64          + (1-\alpha)\tau_2\left(1+\frac{\tau_2}{t}\left(e^{-t/\tau_2}-1\right)\right)
65
66 where :math:`\tau_1` and :math:`\tau_2` are time constants (with
67 :math:`\tau_2 \ge \tau_1`) and :math:`\alpha` usually is close to 1 (in
68 the fitting procedure it is enforced that :math:`0\leq\alpha\leq 1`).
69 This is used in :ref:`gmx analyze <gmx analyze>` for error estimation using
70
71 .. math:: \lim_{t\rightarrow\infty}\varepsilon(t) = \sigma\sqrt{\frac{2(\alpha\tau_1+(1-\alpha)\tau_2)}{T}}
72
73 where :math:`\sigma` is the standard deviation of the data set and
74 :math:`T` is the total simulation time \ :ref:`149 <refHess2002a>`.
75
76 Interphase boundary demarcation
77 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
78
79 In order to determine the position and width of an interface,
80 Steen-Sæthre *et al.* fitted a density profile to the following function
81
82 .. math::
83
84    f(x) ~=~ \frac{a_0+a_1}{2} - \frac{a_0-a_1}{2}{\rm
85      erf}\left(\frac{x-a_2}{a_3^2}\right)
86
87 where :math:`a_0` and :math:`a_1` are densities of different phases,
88 :math:`x` is the coordinate normal to the interface, :math:`a_2` is the
89 position of the interface and :math:`a_3` is the width of the
90 interface \ :ref:`163 <refSteen-Saethre2014a>`. This is implemented
91 in :ref:`gmx densorder <gmx densorder>`.
92
93 Transverse current autocorrelation function
94 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
95
96 In order to establish the transverse current autocorrelation function
97 (useful for computing viscosity  \ :ref:`164 <refPalmer1994a>`) the following function is
98 fitted:
99
100 .. math::
101
102    f(x) ~=~ e^{-\nu}\left({\rm cosh}(\omega\nu)+\frac{{\rm
103        sinh}(\omega\nu)}{\omega}\right)
104
105 with :math:`\nu = x/(2a_0)` and :math:`\omega = \sqrt{1-a_1}`. This is
106 implemented in :ref:`gmx tcaf <gmx tcaf>`.
107
108 Viscosity estimation from pressure autocorrelation function
109 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
110
111 The viscosity is a notoriously difficult property to extract from
112 simulations \ :ref:`149 <refHess2002a>`, :ref:`165 <refWensink2003a>`. It is *in principle*
113 possible to determine it by integrating the pressure autocorrelation
114 function \ :ref:`160 <refPSmith93c>`, however this is often hampered by
115 the noisy tail of the ACF. A workaround to this is fitting the ACF to
116 the following function \ :ref:`166 <refGuo2002b>`:
117
118 .. math::
119
120    f(t)/f(0) = (1-C) {\rm cos}(\omega t) e^{-(t/\tau_f)^{\beta_f}} + C
121    e^{-(t/\tau_s)^{\beta_s}}
122
123 where :math:`\omega` is the frequency of rapid pressure oscillations
124 (mainly due to bonded forces in molecular simulations), :math:`\tau_f`
125 and :math:`\beta_f` are the time constant and exponent of fast
126 relaxation in a stretched-exponential approximation, :math:`\tau_s` and
127 :math:`\beta_s` are constants for slow relaxation and :math:`C` is the
128 pre-factor that determines the weight between fast and slow relaxation.
129 After a fit, the integral of the function :math:`f(t)` is used to
130 compute the viscosity:
131
132 .. math:: \eta = \frac{V}{k_B T}\int_0^{\infty} f(t) dt
133
134 This equation has been applied to computing the bulk and shear
135 viscosity using different elements from the pressure tensor \ :ref:`167 <refFanourgakis2012a>`.