.. _sec-integration: ******************************** Shell Relaxation and Integration ******************************** .. index:: single: integration In polarizable force fields the positions of the shells (or Drude particles) are not determined by the input structure, they have to be computed for each structure. This is done by minimizing the energy with respect to the shell positions, keeping the atoms fixed, as described in this section. The second part of the section describes the integration of the equations of motion in *alexandria simulate*. .. _sec-shellrelax: ===================== Relaxation of shells ===================== .. index:: single: shell relaxation single: adiabatic approximation single: shell; maximum distance The shells have no mass. In the adiabatic approximation they follow the atoms instantaneously, that is, for each configuration of the atoms they are at the minimum of the potential energy. The shells are moved to this minimum iteratively, using the forces on them, as follows. #. The shells are put on top of their core particle and the energy and forces are computed. #. The mean square force on the :math:`N_s` shells is computed .. math:: F_{ms} ~=~ \frac{1}{N_s}\sum_{s=1}^{N_s} \left|{\bf F}_s\right|^2. :label: fmsshell If :math:`F_{ms}` is at most the tolerance, the shells are converged. The tolerance is given in (kJ/mol nm)\ :sup:`2`, see below. #. Otherwise each shell is displaced along the force on it, .. math:: \Delta{\bf r}_s ~=~ \lambda\,\frac{{\bf F}_s}{k_s},\qquad k_s ~=~ \frac{1}{4\pi\varepsilon_0}\frac{q_s^2}{\alpha_c}, :label: shellstep where :math:`k_s` is the force constant of the core-shell spring, see Eqn. :eq:`vpol`. With :math:`\lambda = 1` this step would bring an isolated shell to its minimum, since the force of the spring then cancels the force :math:`{\bf F}_s` from the other particles. With hyperpolarization, the potential of the core-shell pair has an additional term :math:`k_h\,(r_{cs}-r_h)^4` for distances :math:`r_{cs}` larger than :math:`r_h`. The stiffness of the spring then depends on the direction. For a shell away from its core, the component of :math:`{\bf F}_s` perpendicular to the core-shell vector is divided by the ratio of the core-shell force and the distance .. math:: k_s + 4k_h\,\frac{(r_{cs}-r_h)^3}{r_{cs}}\qquad\mbox{if}\quad r_{cs} > r_h, :label: kshyper and the component along the core-shell vector by the second derivative of the potential .. math:: k_s + 12k_h\,(r_{cs}-r_h)^2\qquad\mbox{if}\quad r_{cs} > r_h. :label: kshyperpar This is a Newton step for an isolated shell. For a shell on top of its core, the quartic term only contributes if :math:`r_h = 0`, and then the displacement :math:`\Delta r` is the solution of :math:`\left|{\bf F}_s\right| = k_s\,\Delta r + 4k_h\,\Delta r^3`. The force constants are computed from the current polarizabilities and shell charges, such that they are correct during training as well. #. Since the shells interact with each other, a full step (:math:`\lambda = 1`) can overshoot. If :math:`F_{ms}` increases, the step is reduced to :math:`\lambda = 1/2` for the rest of the relaxation. Smaller steps are not used, since they can freeze the shells far from their minimum. #. A shell with one core is not allowed to move further away from it than a maximum distance :math:`d_{max}`. If the step brings a shell further away, it is moved back to the sphere with radius :math:`d_{max}` around its core, along the core-shell vector. This prevents the polarization catastrophe, where shells of neighbouring molecules attract each other without limit. With hyperpolarization the quartic term usually prevents it as well, then :math:`d_{max}` can be switched off. #. The forces are computed again and the procedure is repeated from step 2, until the shells are converged or the maximum number of iterations is reached. A shell held at :math:`d_{max}` by a force pointing away from its core can never reach a zero force. For such a shell only the component of the force perpendicular to the core-shell vector :math:`{\bf r}_{cs}` is used in Eqn. :eq:`fmsshell` .. math:: {\bf F}_{s,\perp} ~=~ {\bf F}_s - \frac{{\bf F}_s\cdot{\bf r}_{cs}}{r_{cs}^2}\,{\bf r}_{cs}\qquad\mbox{if}\quad r_{cs} = d_{max}\quad\mbox{and}\quad{\bf F}_s\cdot{\bf r}_{cs} > 0, :label: fperp which is zero at the minimum of the energy on the sphere. When a strong field holds the shell there, which is common with the poor parameters early in training, :math:`{\bf F}_{s,\perp}` is the difference of two large force components. It can then stay well above the tolerance on :math:`F_{ms}`, in a cycle or unchanged, even though the shell is practically at the minimum. Moving the shell over a small angle :math:`\theta` on the sphere changes its energy by about .. math:: \Delta E ~\approx~ \frac{1}{2}\left|{\bf F}_s\right|\,d_{max}\,\theta^2, :label: ewall since the force away from the core acts as a force constant :math:`\left|{\bf F}_s\right|/d_{max}` across the core-shell vector. Therefore, the force of such a shell counts as zero in Eqn. :eq:`fmsshell` if :math:`\left|{\bf F}_{s,\perp}\right| \le 10^{-4}\left|{\bf F}_s\right|`. For :math:`\left|{\bf F}_s\right| = 10^4` kJ/(mol nm) and :math:`d_{max}` = 0.02 nm the energy can then change by about :math:`10^{-6}` kJ/mol. The perpendicular force is computed as :math:`\left|{\bf F}_s\times{\bf r}_{cs}\right|/r_{cs}`, since the difference in Eqn. :eq:`fperp` loses its precision when the perpendicular force is that small compared to the force, in particular with forces in single precision. Without this, a few conformations with shells held at :math:`d_{max}` keep the relaxation of all the others going until the maximum number of iterations. The precision of the forces and of the coordinates also limits how small :math:`F_{ms}` can get. The forces are sums of terms that can be much larger than the force itself. When :math:`F_{ms}` no longer decreases, the relaxation therefore stops if :math:`F_{ms}` is within :math:`(32\,\varepsilon\,F_{max})^2`, where :math:`\varepsilon` is the machine precision and :math:`F_{max}` the largest force component of any particle. Terms that cancel can be larger than :math:`F_{max}`, however. In the test force field *PG-pol-ions.xml*, for instance, chloride has a shell charge of -9 e on a core of about +8 e, which are practically on top of each other since its polarizability is at the lower bound of :math:`10^{-6}` Å\ :sup:`3`. A water shell at 0.3 nm then feels forces of about :math:`6\cdot 10^4` kJ/(mol nm) from both, which nearly cancel. In single precision their rounding errors add up to a few hundredths of a kJ/(mol nm), and in a dimer of water and chloride :math:`F_{ms}` went down to :math:`10^{-5}` (kJ/mol nm)\ :sup:`2` and then cycled between :math:`3\cdot 10^{-4}` and :math:`10^{-3}`. A tolerance of :math:`10^{-8}` was then not reached, while in double precision it was. The energies are as precise as the forces allow, but the conformation counts as not converged, takes the maximum number of iterations, and its shells are not kept with *-shell_keep*. With the default tolerance of :math:`10^{-3}`, and with :math:`10^{-6}`, all conformations converged. Therefore, in single precision, and hence on a GPU, do not use a tolerance far below the default. The coordinates are integers in units of :math:`2^{-56}` nm, about :math:`1.4\cdot 10^{-17}` nm. A shell with a very stiff spring, such as that of the chloride above with :math:`k_s \approx 10^{13}` kJ/(mol nm\ :sup:`2`), does not move when its displacement in Eqn. :eq:`shellstep` is smaller than that unit, which happens at forces of about :math:`10^{-4}` kJ/(mol nm). A conformation of which no shell moved in a step counts as converged, since the next steps would be the same. The maximum distance :math:`d_{max}` is part of the force field, since its parameters are trained with it. It is the option *shellmaxdistance* (in nm) of the polarization in the force field file, .. code-block:: xml