<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://biomolmd.org/mw/index.php?action=history&amp;feed=atom&amp;title=Ammm%3AMd_integrator</id>
	<title>Ammm:Md integrator - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://biomolmd.org/mw/index.php?action=history&amp;feed=atom&amp;title=Ammm%3AMd_integrator"/>
	<link rel="alternate" type="text/html" href="https://biomolmd.org/mw/index.php?title=Ammm:Md_integrator&amp;action=history"/>
	<updated>2026-11-16T09:25:29Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.43.1</generator>
	<entry>
		<id>https://biomolmd.org/mw/index.php?title=Ammm:Md_integrator&amp;diff=1573&amp;oldid=prev</id>
		<title>Admin: Created page with &quot;==Integrator==    For numerical integration techniques, the book &#039;&#039;&#039;Numerical Recipes in C&#039;&#039;&#039; is good reference.  As we already know MD simulations is solving Newton&#039;s law   &lt;math&gt;\frac{dU(x)}{dx}=m*\frac{d^2x}{dt^2}&lt;/math&gt;   using finite difference methods. The exact way to solve the ordinary differential equation depends on the integrator. A good integrator should allow   *large time step (However, if the timestep is too large for system, the simulation can &quot;blow up&quot;)...&quot;</title>
		<link rel="alternate" type="text/html" href="https://biomolmd.org/mw/index.php?title=Ammm:Md_integrator&amp;diff=1573&amp;oldid=prev"/>
		<updated>2022-05-10T02:14:44Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;==Integrator==    For numerical integration techniques, the book &amp;#039;&amp;#039;&amp;#039;Numerical Recipes in C&amp;#039;&amp;#039;&amp;#039; is good reference.  As we already know MD simulations is solving Newton&amp;#039;s law   &amp;lt;math&amp;gt;\frac{dU(x)}{dx}=m*\frac{d^2x}{dt^2}&amp;lt;/math&amp;gt;   using finite difference methods. The exact way to solve the ordinary differential equation depends on the integrator. A good integrator should allow   *large time step (However, if the timestep is too large for system, the simulation can &amp;quot;blow up&amp;quot;)...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;==Integrator==&lt;br /&gt;
 &lt;br /&gt;
 For numerical integration techniques, the book &amp;#039;&amp;#039;&amp;#039;Numerical Recipes in C&amp;#039;&amp;#039;&amp;#039; is good reference.&lt;br /&gt;
&lt;br /&gt;
As we already know MD simulations is solving Newton&amp;#039;s law &lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\frac{dU(x)}{dx}=m*\frac{d^2x}{dt^2}&amp;lt;/math&amp;gt; &lt;br /&gt;
&lt;br /&gt;
using finite difference methods. The exact way to solve the ordinary differential equation depends on the integrator. A good integrator should allow &lt;br /&gt;
&lt;br /&gt;
*large time step (However, if the timestep is too large for system, the simulation can &amp;quot;blow up&amp;quot;) &lt;br /&gt;
*conserve energy (small energy) &lt;br /&gt;
*efficeint. Evalute fewer energy and force per step.&lt;br /&gt;
&lt;br /&gt;
==Popular integrators for MD ==&lt;br /&gt;
&lt;br /&gt;
*Verlet leapfrog integrator&lt;br /&gt;
[[File:md_leapfrog.png]]&lt;br /&gt;
&lt;br /&gt;
*Verlet velocity integrator&lt;br /&gt;
[[File:md_velocity.png]]&lt;br /&gt;
 The Verlet velocity algorithm overcomes the out-of-synchrony&lt;br /&gt;
 shortcoming of the Verlet leapfrog method &lt;br /&gt;
&lt;br /&gt;
*Runge–Kutta-4 integrator&lt;br /&gt;
&lt;br /&gt;
 Runge–Kutta-4 is a fourth-order Runge–Kutta method,&lt;br /&gt;
 which is one of the oldest numerical methods for solving ordinary&lt;br /&gt;
 differential equations. The method is self starting but requires four&lt;br /&gt;
 energy evaluations per step.&lt;br /&gt;
&lt;br /&gt;
*Beeman (http://en.wikipedia.org/wiki/Beeman%27s_algorithm)&lt;br /&gt;
Beeman is closely related to Verlet integration. It produces identical positions to Verlet, but is more accurate in velocities.&lt;br /&gt;
The formula used to compute the positions at time &amp;lt;math&amp;gt;t + \Delta t&amp;lt;/math&amp;gt; is:&lt;br /&gt;
&lt;br /&gt;
:&amp;lt;math&amp;gt;x(t+\Delta t) = x(t) + v(t) \Delta t + \frac{2}{3}a(t) \Delta t^2 - \frac{1}{6} a(t - \Delta t) \Delta t^2 + O( \Delta t^4)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
and this is the formula used to update the velocities:&lt;br /&gt;
&lt;br /&gt;
:&amp;lt;math&amp;gt;v(t + \Delta t) = v(t) + \frac{1}{3}a(t + \Delta t) \Delta t + \frac{5}{6}a(t) \Delta t - \frac{1}{6}a(t - \Delta t) \Delta t + O(\Delta t^3)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
where&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;math&amp;gt;t&amp;lt;/math&amp;gt; is present time (ie: independent variable)&lt;br /&gt;
*&amp;lt;math&amp;gt;\Delta t&amp;lt;/math&amp;gt; is the time step size&lt;br /&gt;
*&amp;lt;math&amp;gt;x(t)&amp;lt;/math&amp;gt; is the position at time t&lt;br /&gt;
*&amp;lt;math&amp;gt;v(t)&amp;lt;/math&amp;gt; is the velocity at time t&lt;br /&gt;
*&amp;lt;math&amp;gt;a(t)&amp;lt;/math&amp;gt; is the acceleration at time t&lt;br /&gt;
*the last term is the error term, using the big O notation&lt;br /&gt;
&lt;br /&gt;
==which one is better?==&lt;br /&gt;
* Beeman is my favorite for MD. &lt;br /&gt;
* try different time-steps and see whether the average energy change.&lt;br /&gt;
* for rigibd body there are different integrators&lt;br /&gt;
* for motorsport simulations: http://www.motorsport-sim.org/&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==Constraint==&lt;br /&gt;
(http://en.wikipedia.org/wiki/Constraint_algorithm) &lt;br /&gt;
To use even large time step, constraint is used to &amp;quot;fix&amp;quot; the fast vibrating bonds. In most Molecular dynamics simulation, constraints are enforced using the method of Lagrange multipliers. Given a set of &amp;#039;&amp;#039;n&amp;#039;&amp;#039; linear (holonomic) constraints at the time &amp;#039;&amp;#039;t&amp;#039;&amp;#039;, &lt;br /&gt;
&lt;br /&gt;
 &amp;lt;math&amp;gt;\sigma_k^{(t)} := \| \mathbf x_{k\alpha}^{(t)} - \mathbf x_{k\beta}^{(t)} \|_2^2 - d_k^2 = 0, \quad k=1 \dots n &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
where x ar ethe positions of the two atoms involved in the kth constraint (e.g. O and H in OH constraint) at the time &amp;#039;&amp;#039;t&amp;#039;&amp;#039; and &amp;quot;d&amp;quot; is the prescribed inter-particle distance.&lt;br /&gt;
&lt;br /&gt;
These constraint equations, are added to the potential energy function in the equations of motion, resulting in, for each of the &amp;#039;&amp;#039;N&amp;#039;&amp;#039; particles in the system &lt;br /&gt;
&lt;br /&gt;
 &amp;lt;math&amp;gt;\frac{\partial^2 \mathbf x_i^{(t)}}{\partial t^2} m_i = \frac{\partial}{\partial \mathbf x_i} \left[ V(\mathbf x_i^{(t)}) + \sum_{k=1}^n \lambda_k \sigma_k^{(t)} \right], \quad i=1 \dots N.&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Adding the constraint equations to the potential does not change it, since all &amp;lt;math&amp;gt;\sigma_k^{(t)}&amp;lt;/math&amp;gt; should, ideally, be zero. &lt;br /&gt;
&lt;br /&gt;
Integrating both sides of the equations of motion twice in time yields the constrained particle positions at the time &amp;lt;span class=&amp;quot;texhtml&amp;quot;&amp;gt;&amp;#039;&amp;#039;t&amp;#039;&amp;#039; + Δ&amp;#039;&amp;#039;t&amp;#039;&amp;#039;&amp;lt;/span&amp;gt; &lt;br /&gt;
&lt;br /&gt;
 &amp;lt;math&amp;gt;\mathbf x^{(t + \Delta t)}_i = \hat{\mathbf x}^{(t + \Delta t)}_i + \sum_{k=1}^n \lambda_k \frac{\partial\sigma_k^{(t)}}{\partial \mathbf x_i}\left(\Delta t\right)^2m_i^{-1}, \quad i=1 \dots N&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
where &amp;lt;math&amp;gt;\hat{\mathbf x}^{(t + \Delta t)}_i&amp;lt;/math&amp;gt; is the unconstrained (or uncorrected) position of the &amp;#039;&amp;#039;i&amp;#039;&amp;#039;th particle after integrating the unconstrained equations of motion. &lt;br /&gt;
&lt;br /&gt;
To satisfy the constraints &amp;lt;math&amp;gt;\sigma_k^{(t + \Delta t)}&amp;lt;/math&amp;gt; in the next timestep, the Lagrange multipliers must be chosen such that &lt;br /&gt;
&lt;br /&gt;
 &amp;lt;math&amp;gt;\sigma_k^{(t + \Delta t)} = \left\| \mathbf x_{k\alpha}^{(t+\Delta t)} - \mathbf x_{k\beta}^{(t+\Delta t)}\right\|_2^2 - d_k^2 = 0.&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This implies solving a system of &amp;lt;span class=&amp;quot;texhtml&amp;quot;&amp;gt;&amp;#039;&amp;#039;n&amp;#039;&amp;#039;&amp;lt;/span&amp;gt; non-linear equations &lt;br /&gt;
&lt;br /&gt;
 &amp;lt;math&amp;gt;\sigma_j^{(t + \Delta t)} = \left\| \hat{\mathbf x}_{j\alpha}^{(t+\Delta t)} - \hat{\mathbf x}_{j\beta}^{(t+\Delta t)}  +    \sum_{k=1}^n \lambda_k \left[ \frac{\partial\sigma_k^{(t)}}{\partial \mathbf x_{j\alpha}}m_{j\alpha}^{-1} -  \frac{\partial\sigma_k^{(t)}}{\partial \mathbf x_{j\beta}}m_{j\beta}^{-1}\right] \right\|_2^2 - d_j^2 = 0, \quad j = 1 \dots n&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
simultaneously for the &amp;lt;span class=&amp;quot;texhtml&amp;quot;&amp;gt;&amp;#039;&amp;#039;n&amp;#039;&amp;#039;&amp;lt;/span&amp;gt; unknown Lagrange multipliers &amp;lt;span class=&amp;quot;texhtml&amp;quot;&amp;gt;λ&amp;lt;sub&amp;gt;&amp;#039;&amp;#039;k&amp;#039;&amp;#039;&amp;lt;/sub&amp;gt;&amp;lt;/span&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
This system of &amp;lt;span class=&amp;quot;texhtml&amp;quot;&amp;gt;&amp;#039;&amp;#039;n&amp;#039;&amp;#039;&amp;lt;/span&amp;gt; non-linear equations in &amp;lt;span class=&amp;quot;texhtml&amp;quot;&amp;gt;&amp;#039;&amp;#039;n&amp;#039;&amp;#039;&amp;lt;/span&amp;gt; unknowns is best solved using Newton&amp;#039;s method (oterwise matrix inversion)where the solution vector &amp;lt;math&amp;gt;\underline{\lambda}&amp;lt;/math&amp;gt; is updated iteratively using &lt;br /&gt;
&lt;br /&gt;
 &amp;lt;math&amp;gt;\underline{\lambda}^{(l+1)} \leftarrow \underline{\lambda}^{(l)} - \mathbf J_\sigma^{-1} \underline{\sigma}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
where &amp;lt;math&amp;gt;\mathbf J_\sigma&amp;lt;/math&amp;gt; is the Jacobian of the equations σ&amp;lt;sub&amp;gt;&amp;#039;&amp;#039;k&amp;#039;&amp;#039;&amp;lt;/sub&amp;gt;: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;J=\left( \begin{matrix}&lt;br /&gt;
   \frac{\partial {{\sigma }_{1}}}{\partial {{\lambda }_{1}}} &amp;amp; \frac{\partial {{\sigma }_{1}}}{\partial {{\lambda }_{2}}} &amp;amp; \ldots  &amp;amp; \frac{\partial {{\sigma }_{1}}}{\partial {{\lambda }_{n}}}  \\&lt;br /&gt;
   \frac{\partial {{\sigma }_{2}}}{\partial {{\lambda }_{1}}} &amp;amp; {} &amp;amp; \ddots  &amp;amp; {}  \\&lt;br /&gt;
   \vdots  &amp;amp; {} &amp;amp; {} &amp;amp; {}  \\&lt;br /&gt;
   \frac{\partial {{\sigma }_{n}}}{\partial {{\lambda }_{1}}} &amp;amp; {} &amp;amp; {} &amp;amp; \frac{\partial {{\sigma }_{n}}}{\partial {{\lambda }_{n}}}  \\&lt;br /&gt;
\end{matrix} \right)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;Since not all particles are involved in all constraints, &amp;lt;math&amp;gt;\mathbf J_\sigma&amp;lt;/math&amp;gt; is blockwise-diagonal and can be solved blockwise, i.e. molecule for molecule. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\hat{\mathbf x}_i^{(t+\Delta t)} \leftarrow \hat{\mathbf x}_i^{(t+\Delta t)} + \sum_{k=1}^n \lambda_k^{(l)}\frac{\partial \sigma_k}{\partial \mathbf x_i}&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This is repeated until the constraint equations &amp;lt;math&amp;gt;\sigma_k^{(t+\Delta t)}&amp;lt;/math&amp;gt; are satisfied up to &amp;#039;&amp;#039;&amp;#039;a prescribed tolerance&amp;#039;&amp;#039;&amp;#039; \&lt;br /&gt;
 or it will blow up after a number of itrations and two atoms are now far away from each other... &lt;br /&gt;
&lt;br /&gt;
Although there are a number of algorithms, SHAKE and RATTLE etc., to compute the Lagrange multipliers, they differ only in how they solve the system of equations, usually using Quasi-Newton methods.&lt;/div&gt;</summary>
		<author><name>Admin</name></author>
	</entry>
</feed>