fcc7042171a52f80887fa64d01afb0ed21dd60ae
[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 #. **External potential** This takes the potential acting on the reaction
72    coordinate from another module. Current only the Accelerated Weight
73    Histogram method (see sec. :doc:`awh`) is supported, which provides
74    adaptive biasing of pull coordinates.
75
76 In addition, there are different types of reaction coordinates,
77 so-called pull geometries. These are set with the :ref:`mdp`
78 option ``pull-coord?-geometry``.
79
80 Definition of the center of mass
81 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
82
83 In |Gromacs|, there are three ways to define the center of mass of a
84 group. The standard way is a “plain” center of mass, possibly with
85 additional weighting factors. With periodic boundary conditions it is no
86 longer possible to uniquely define the center of mass of a group of
87 atoms. Therefore, a reference atom is used. For determining the center
88 of mass, for all other atoms in the group, the closest periodic image to
89 the reference atom is used. This uniquely defines the center of mass. By
90 default, the middle (determined by the order in the topology) atom is
91 used as a reference atom, but the user can also select any other atom if
92 it would be closer to center of the group.
93
94 When there are large pull groups, such as a
95 lipid bilayer, ``pull-pbc-ref-prev-step-com`` can be used to avoid potential
96 large movements of the center of mass in case that atoms in the pull group
97 move so much that the reference atom is too far from the intended center of mass.
98 With this option enabled the center of mass from the previous step is used,
99 instead of the position of the reference atom, to determine the reference position.
100 The position of the reference atom is still used for the first step. For large pull
101 groups it is important to select a reference atom that is close to the intended
102 center of mass, i.e. do not use ``pull-group?-pbcatom = 0``.
103
104 For a layered system, for instance a lipid bilayer, it may be of
105 interest to calculate the PMF of a lipid as function of its distance
106 from the whole bilayer. The whole bilayer can be taken as reference
107 group in that case, but it might also be of interest to define the
108 reaction coordinate for the PMF more locally. The :ref:`mdp`
109 option ``pull-coord?-geometry = cylinder`` does not use all
110 the atoms of the reference group, but instead dynamically only those
111 within a cylinder with radius ``pull-cylinder-r`` around the
112 pull vector going through the pull group. This only works for distances
113 defined in one dimension, and the cylinder is oriented with its long
114 axis along this one dimension. To avoid jumps in the pull force,
115 contributions of atoms are weighted as a function of distance (in
116 addition to the mass weighting):
117
118 .. math:: \begin{aligned}
119           w(r < r_\mathrm{cyl}) & = &
120           1-2 \left(\frac{r}{r_\mathrm{cyl}}\right)^2 + \left(\frac{r}{r_\mathrm{cyl}}\right)^4 \\
121           w(r \geq r_\mathrm{cyl}) & = & 0\end{aligned}
122           :label: eqnpulldistmassweight
123
124 Note that the radial dependence on the weight causes a radial force on
125 both cylinder group and the other pull group. This is an undesirable,
126 but unavoidable effect. To minimize this effect, the cylinder radius
127 should be chosen sufficiently large. The effective mass is 0.47 times
128 that of a cylinder with uniform weights and equal to the mass of uniform
129 cylinder of 0.79 times the radius.
130
131 .. _fig-pullref:
132
133 .. figure:: plots/pullref.*
134    :width: 6.00000cm
135
136    Comparison of a plain center of mass reference group versus a
137    cylinder reference group applied to interface systems. C is the
138    reference group. The circles represent the center of mass of two
139    groups plus the reference group, :math:`d_c` is the reference
140    distance.
141
142 For a group of molecules in a periodic system, a plain reference group
143 might not be well-defined. An example is a water slab that is connected
144 periodically in :math:`x` and :math:`y`, but has two liquid-vapor
145 interfaces along :math:`z`. In such a setup, water molecules can
146 evaporate from the liquid and they will move through the vapor, through
147 the periodic boundary, to the other interface. Such a system is
148 inherently periodic and there is no proper way of defining a “plain”
149 center of mass along :math:`z`. A proper solution is to using a cosine
150 shaped weighting profile for all atoms in the reference group. The
151 profile is a cosine with a single period in the unit cell. Its phase is
152 optimized to give the maximum sum of weights, including mass weighting.
153 This provides a unique and continuous reference position that is nearly
154 identical to the plain center of mass position in case all atoms are all
155 within a half of the unit-cell length. See ref :ref:`136 <refEngin2010a>`
156 for details.
157
158 When relative weights :math:`w_i` are used during the calculations,
159 either by supplying weights in the input or due to cylinder geometry or
160 due to cosine weighting, the weights need to be scaled to conserve
161 momentum:
162
163 .. math:: w'_i = w_i
164           \left. \sum_{j=1}^N w_j \, m_j \right/ \sum_{j=1}^N w_j^2 \, m_j
165           :label: eqnpullmassscale
166
167 where :math:`m_j` is the mass of atom :math:`j` of the group. The mass
168 of the group, required for calculating the constraint force, is:
169
170 .. math:: M = \sum_{i=1}^N w'_i \, m_i
171           :label: eqnpullconstraint
172
173 The definition of the weighted center of mass is:
174
175 .. math:: \mathbf{r}_{com} = \left. \sum_{i=1}^N w'_i \, m_i \, \mathbf{r}_i \right/ M
176           :label: eqnpullcom
177
178 From the centers of mass the AFM, constraint, or umbrella force
179 :math:`\mathbf{F}_{\!com}` on each group can be
180 calculated. The force on the center of mass of a group is redistributed
181 to the atoms as follows:
182
183 .. math:: \mathbf{F}_{\!i} = \frac{w'_i \, m_i}{M} \, \mathbf{F}_{\!com}
184           :label: eqnpullcomforce
185
186 Definition of the pull direction
187 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
188
189 The most common setup is to pull along the direction of the vector
190 containing the two pull groups, this is selected with
191 ``pull-coord?-geometry = distance``. You might want to pull
192 along a certain vector instead, which is selected with
193 ``pull-coord?-geometry = direction``. But this can cause
194 unwanted torque forces in the system, unless you pull against a
195 reference group with (nearly) fixed orientation, e.g. a membrane protein
196 embedded in a membrane along x/y while pulling along z. If your
197 reference group does not have a fixed orientation, you should probably
198 use ``pull-coord?-geometry = direction-relative``, see
199 :numref:`Fig. %s <fig-pulldirrel>`. Since the potential now depends
200 on the coordinates of two additional groups defining the orientation,
201 the torque forces will work on these two groups.
202
203 .. _fig-pulldirrel:
204
205 .. figure:: plots/pulldirrel.*
206    :width: 5.00000cm
207
208    The pull setup for geometry ``direction-relative``. The
209    “normal” pull groups are 1 and 2. Groups 3 and 4 define the pull
210    direction and thus the direction of the normal pull forces (red).
211    This leads to reaction forces (blue) on groups 3 and 4, which are
212    perpendicular to the pull direction. Their magnitude is given by the
213    “normal” pull force times the ratio of :math:`d_p` and the distance
214    between groups 3 and 4.
215
216 Definition of the angle and dihedral pull geometries
217 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
218
219 Four pull groups are required for ``pull-coord?-geometry =
220 angle``. In the same way as for geometries with two groups, each
221 consecutive pair of groups :math:`i` and :math:`i+1` define a vector
222 connecting the COMs of groups :math:`i` and :math:`i+1`. The angle is
223 defined as the angle between the two resulting vectors. E.g., the
224 :ref:`mdp` option ``pull-coord?-groups = 1 2 2 4``
225 defines the angle between the vector from the COM of group 1 to the COM
226 of group 2 and the vector from the COM of group 2 to the COM of group 4.
227 The angle takes values in the closed interval [0, 180] deg. For
228 ``pull-coord?-geometry = angle-axis`` the angle is defined
229 with respect to a reference axis given by
230 ``pull-coord?-vec`` and only two groups need to be given.
231 The dihedral geometry requires six pull groups. These pair up in the
232 same way as described above and so define three vectors. The dihedral
233 angle is defined as the angle between the two planes spanned by the two
234 first and the two last vectors. Equivalently, the dihedral angle can be
235 seen as the angle between the first and the third vector when these
236 vectors are projected onto a plane normal to the second vector (the axis
237 vector). As an example, consider a dihedral angle involving four groups:
238 1, 5, 8 and 9. Here, the :ref:`mdp` option
239 ``pull-coord?-groups = 8 1 1 5 5 9`` specifies the three
240 vectors that define the dihedral angle: the first vector is the COM
241 distance vector from group 8 to 1, the second vector is the COM distance
242 vector from group 1 to 5, and the third vector is the COM distance
243 vector from group 5 to 9. The dihedral angle takes values in the
244 interval (-180, 180] deg and has periodic boundaries.
245
246 The transformation pull coordinate
247 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
248
249 The transformation pull coordinate is a "meta" pull coordinate type that
250 can transform one or more other pull coordinates using an arbitrary
251 mathematical expression. This is a powerful tool for generating
252 complex reaction coordinates like a contact coordinate
253 using a non-linear transformation of a distance, a sum of contacts or
254 arbitrary (non-)linear combinations of two or more pull coordinates.
255 A simple example is a contact coordinate using a non-linear transformation
256 of a distance. More complex examples are a (non-)linear combination of
257 two or more pull coordinates or a sum of contacts.
258
259 Typically, the force constant for pull coordinate(s) the transformation
260 coordinates acts on should be zero. This avoids
261 unintended addition of direct forces on the pull coordinate(s)
262 to the indirect forces from the transition pull coordinate. This is not
263 a requirement, but have both a direct and indirect, from the tranformation
264 coordinate, force working on them is almost never desirable.
265 If the transformation is a linear combination of multiple distances,
266 it is useful to normalize the coefficients
267 such that the transformation coordinate also has units of nanometer.
268 That makes both the choice of the force constant and the interpretation easier.
269
270 Limitations
271 ^^^^^^^^^^^
272
273 There is one theoretical limitation: strictly speaking, constraint
274 forces can only be calculated between groups that are not connected by
275 constraints to the rest of the system. If a group contains part of a
276 molecule of which the bond lengths are constrained, the pull constraint
277 and LINCS or SHAKE bond constraint algorithms should be iterated
278 simultaneously. This is not done in |Gromacs|. This means that for
279 simulations with ``constraints = all-bonds`` in the :ref:`mdp` file pulling is,
280 strictly speaking, limited to whole molecules or groups of molecules. In
281 some cases this limitation can be avoided by using the free energy code,
282 see sec. :ref:`fepmf`. In practice, the errors caused by not iterating
283 the two constraint algorithms can be negligible when the pull group
284 consists of a large amount of atoms and/or the pull force is small. In
285 such cases, the constraint correction displacement of the pull group is
286 small compared to the bond lengths.