2a08303fbc4519aa07764cb9dac8dc001ef47742
[alexxy/gromacs.git] / docs / reference-manual / special / pulling.rst
1 Non-equilibrium pulling
2 -----------------------
3
4 When the distance between two groups is changed continuously, work is
5 applied to the system, which means that the system is no longer in
6 equilibrium. Although in the limit of very slow pulling the system is
7 again in equilibrium, for many systems this limit is not reachable
8 within reasonable computational time. However, one can use the Jarzynski
9 relation \ :ref:`135 <refJarzynski1997a>` to obtain the equilibrium free-energy difference
10 :math:`\Delta G` between two distances from many non-equilibrium
11 simulations:
12
13 .. math:: \Delta G_{AB} = -k_BT \log \left\langle e^{-\beta W_{AB}} \right\rangle_A
14           :label: eqJarz
15
16 where :math:`W_{AB}` is the work performed to force the system along
17 one path from state A to B, the angular bracket denotes averaging over a
18 canonical ensemble of the initial state A and :math:`\beta=1/k_B T`.
19
20 .. _pull:
21
22 The pull code
23 -------------
24
25 :ref:`pull` The pull code applies forces or constraints between the
26 centers of mass of one or more pairs of groups of atoms. Each pull
27 reaction coordinate is called a “coordinate” and it operates on usually
28 two, but sometimes more, pull groups. A pull group can be part of one or
29 more pull coordinates. Furthermore, a coordinate can also operate on a
30 single group and an absolute reference position in space. The distance
31 between a pair of groups can be determined in 1, 2 or 3 dimensions, or
32 can be along a user-defined vector. The reference distance can be
33 constant or can change linearly with time. Normally all atoms are
34 weighted by their mass, but an additional weighting factor can also be
35 used.
36
37 .. _fig-pull:
38
39 .. figure:: plots/pull.*
40    :width: 6.00000cm
41
42    Schematic picture of pulling a lipid out of a lipid bilayer with
43    umbrella pulling. :math:`V_{rup}` is the velocity at which the spring
44    is retracted, :math:`Z_{link}` is the atom to which the spring is
45    attached and :math:`Z_{spring}` is the location of the spring.
46
47 Several different pull types, i.e. ways to apply the pull force, are
48 supported, and in all cases the reference distance can be constant or
49 linearly changing with time.
50
51 #. **Umbrella pulling** A harmonic potential is applied between the
52    centers of mass of two groups. Thus, the force is proportional to the
53    displacement.
54
55 #. **Constraint pulling** The distance between the centers of mass of
56    two groups is constrained. The constraint force can be written to a
57    file. This method uses the SHAKE algorithm but only needs 1 iteration
58    to be exact if only two groups are constrained.
59
60 #. **Constant force pulling** A constant force is applied between the
61    centers of mass of two groups. Thus, the potential is linear. In this
62    case there is no reference distance of pull rate.
63
64 #. **Flat bottom pulling** Like umbrella pulling, but the potential and
65    force are zero for coordinate values below
66    (``pull-coord?-type = flat-bottom``) or above
67    (``pull-coord?-type = flat-bottom-high``) a reference
68    value. This is useful for restraining e.g. the distance between two
69    molecules to a certain region.
70
71 In addition, there are different types of reaction coordinates,
72 so-called pull geometries. These are set with the :ref:`mdp`
73 option ``pull-coord?-geometry``.
74
75 Definition of the center of mass
76 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
77
78 In |Gromacs|, there are three ways to define the center of mass of a
79 group. The standard way is a “plain” center of mass, possibly with
80 additional weighting factors. With periodic boundary conditions it is no
81 longer possible to uniquely define the center of mass of a group of
82 atoms. Therefore, a reference atom is used. For determining the center
83 of mass, for all other atoms in the group, the closest periodic image to
84 the reference atom is used. This uniquely defines the center of mass. By
85 default, the middle (determined by the order in the topology) atom is
86 used as a reference atom, but the user can also select any other atom if
87 it would be closer to center of the group.
88
89 When there are large pull groups, such as a
90 lipid bilayer, ``pull-pbc-ref-prev-step-com`` can be used to avoid potential
91 large movements of the center of mass in case that atoms in the pull group
92 move so much that the reference atom is too far from the intended center of mass.
93 With this option enabled the center of mass from the previous step is used,
94 instead of the position of the reference atom, to determine the reference position.
95 The position of the reference atom is still used for the first step. For large pull
96 groups it is important to select a reference atom that is close to the intended
97 center of mass, i.e. do not use ``pull-group?-pbcatom = 0``.
98
99 For a layered system, for instance a lipid bilayer, it may be of
100 interest to calculate the PMF of a lipid as function of its distance
101 from the whole bilayer. The whole bilayer can be taken as reference
102 group in that case, but it might also be of interest to define the
103 reaction coordinate for the PMF more locally. The :ref:`mdp`
104 option ``pull-coord?-geometry = cylinder`` does not use all
105 the atoms of the reference group, but instead dynamically only those
106 within a cylinder with radius ``pull-cylinder-r`` around the
107 pull vector going through the pull group. This only works for distances
108 defined in one dimension, and the cylinder is oriented with its long
109 axis along this one dimension. To avoid jumps in the pull force,
110 contributions of atoms are weighted as a function of distance (in
111 addition to the mass weighting):
112
113 .. math::
114
115    \begin{aligned}
116    w(r < r_\mathrm{cyl}) & = &
117    1-2 \left(\frac{r}{r_\mathrm{cyl}}\right)^2 + \left(\frac{r}{r_\mathrm{cyl}}\right)^4 \\
118    w(r \geq r_\mathrm{cyl}) & = & 0\end{aligned}
119
120 Note that the radial dependence on the weight causes a radial force on
121 both cylinder group and the other pull group. This is an undesirable,
122 but unavoidable effect. To minimize this effect, the cylinder radius
123 should be chosen sufficiently large. The effective mass is 0.47 times
124 that of a cylinder with uniform weights and equal to the mass of uniform
125 cylinder of 0.79 times the radius.
126
127 .. _fig-pullref:
128
129 .. figure:: plots/pullref.*
130    :width: 6.00000cm
131
132    Comparison of a plain center of mass reference group versus a
133    cylinder reference group applied to interface systems. C is the
134    reference group. The circles represent the center of mass of two
135    groups plus the reference group, :math:`d_c` is the reference
136    distance.
137
138 For a group of molecules in a periodic system, a plain reference group
139 might not be well-defined. An example is a water slab that is connected
140 periodically in :math:`x` and :math:`y`, but has two liquid-vapor
141 interfaces along :math:`z`. In such a setup, water molecules can
142 evaporate from the liquid and they will move through the vapor, through
143 the periodic boundary, to the other interface. Such a system is
144 inherently periodic and there is no proper way of defining a “plain”
145 center of mass along :math:`z`. A proper solution is to using a cosine
146 shaped weighting profile for all atoms in the reference group. The
147 profile is a cosine with a single period in the unit cell. Its phase is
148 optimized to give the maximum sum of weights, including mass weighting.
149 This provides a unique and continuous reference position that is nearly
150 identical to the plain center of mass position in case all atoms are all
151 within a half of the unit-cell length. See ref :ref:`136 <refEngin2010a>`
152 for details.
153
154 When relative weights :math:`w_i` are used during the calculations,
155 either by supplying weights in the input or due to cylinder geometry or
156 due to cosine weighting, the weights need to be scaled to conserve
157 momentum:
158
159 .. math::
160
161    w'_i = w_i
162    \left. \sum_{j=1}^N w_j \, m_j \right/ \sum_{j=1}^N w_j^2 \, m_j
163
164 where :math:`m_j` is the mass of atom :math:`j` of the group. The mass
165 of the group, required for calculating the constraint force, is:
166
167 .. math:: M = \sum_{i=1}^N w'_i \, m_i
168
169 The definition of the weighted center of mass is:
170
171 .. math:: \mathbf{r}_{com} = \left. \sum_{i=1}^N w'_i \, m_i \, \mathbf{r}_i \right/ M
172
173 From the centers of mass the AFM, constraint, or umbrella force
174 :math:`\mathbf{F}_{\!com}` on each group can be
175 calculated. The force on the center of mass of a group is redistributed
176 to the atoms as follows:
177
178 .. math:: \mathbf{F}_{\!i} = \frac{w'_i \, m_i}{M} \, \mathbf{F}_{\!com}
179
180 Definition of the pull direction
181 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
182
183 The most common setup is to pull along the direction of the vector
184 containing the two pull groups, this is selected with
185 ``pull-coord?-geometry = distance``. You might want to pull
186 along a certain vector instead, which is selected with
187 ``pull-coord?-geometry = direction``. But this can cause
188 unwanted torque forces in the system, unless you pull against a
189 reference group with (nearly) fixed orientation, e.g. a membrane protein
190 embedded in a membrane along x/y while pulling along z. If your
191 reference group does not have a fixed orientation, you should probably
192 use ``pull-coord?-geometry = direction-relative``, see
193 :numref:`Fig. %s <fig-pulldirrel>`. Since the potential now depends
194 on the coordinates of two additional groups defining the orientation,
195 the torque forces will work on these two groups.
196
197 .. _fig-pulldirrel:
198
199 .. figure:: plots/pulldirrel.*
200    :width: 5.00000cm
201
202    The pull setup for geometry ``direction-relative``. The
203    “normal” pull groups are 1 and 2. Groups 3 and 4 define the pull
204    direction and thus the direction of the normal pull forces (red).
205    This leads to reaction forces (blue) on groups 3 and 4, which are
206    perpendicular to the pull direction. Their magnitude is given by the
207    “normal” pull force times the ratio of :math:`d_p` and the distance
208    between groups 3 and 4.
209
210 Definition of the angle and dihedral pull geometries
211 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
212
213 Four pull groups are required for ``pull-coord?-geometry =
214 angle``. In the same way as for geometries with two groups, each
215 consecutive pair of groups :math:`i` and :math:`i+1` define a vector
216 connecting the COMs of groups :math:`i` and :math:`i+1`. The angle is
217 defined as the angle between the two resulting vectors. E.g., the
218 :ref:`mdp` option ``pull-coord?-groups = 1 2 2 4``
219 defines the angle between the vector from the COM of group 1 to the COM
220 of group 2 and the vector from the COM of group 2 to the COM of group 4.
221 The angle takes values in the closed interval [0, 180] deg. For
222 ``pull-coord?-geometry = angle-axis`` the angle is defined
223 with respect to a reference axis given by
224 ``pull-coord?-vec`` and only two groups need to be given.
225 The dihedral geometry requires six pull groups. These pair up in the
226 same way as described above and so define three vectors. The dihedral
227 angle is defined as the angle between the two planes spanned by the two
228 first and the two last vectors. Equivalently, the dihedral angle can be
229 seen as the angle between the first and the third vector when these
230 vectors are projected onto a plane normal to the second vector (the axis
231 vector). As an example, consider a dihedral angle involving four groups:
232 1, 5, 8 and 9. Here, the :ref:`mdp` option
233 ``pull-coord?-groups = 8 1 1 5 5 9`` specifies the three
234 vectors that define the dihedral angle: the first vector is the COM
235 distance vector from group 8 to 1, the second vector is the COM distance
236 vector from group 1 to 5, and the third vector is the COM distance
237 vector from group 5 to 9. The dihedral angle takes values in the
238 interval (-180, 180] deg and has periodic boundaries.
239
240 Limitations
241 ^^^^^^^^^^^
242
243 There is one theoretical limitation: strictly speaking, constraint
244 forces can only be calculated between groups that are not connected by
245 constraints to the rest of the system. If a group contains part of a
246 molecule of which the bond lengths are constrained, the pull constraint
247 and LINCS or SHAKE bond constraint algorithms should be iterated
248 simultaneously. This is not done in |Gromacs|. This means that for
249 simulations with ``constraints = all-bonds`` in the :ref:`mdp` file pulling is,
250 strictly speaking, limited to whole molecules or groups of molecules. In
251 some cases this limitation can be avoided by using the free energy code,
252 see sec. :ref:`fepmf`. In practice, the errors caused by not iterating
253 the two constraint algorithms can be negligible when the pull group
254 consists of a large amount of atoms and/or the pull force is small. In
255 such cases, the constraint correction displacement of the pull group is
256 small compared to the bond lengths.