AbstractMiddleRespaIntegrator¶
- class ufedmm.AbstractMiddleRespaIntegrator(temperature, step_size, num_rattles=0, scheme='VV-Middle', respa_loops=None, bath_loops=1, intertwine=True, embodied_force_groups=None, unroll_loops=True)[source]¶
An abstract class for middle-type, multiple time-scale integrators.
Warning
This class is meant for inheritance only and does not actually include thermostatting. Concrete subclasses are available, such as
MiddleMassiveNHCIntegratorandGeodesicLangevinIntegrator, for instance.Child classes will differ by the thermostat algorithm, which must be implemented by overriding the _bath method (see the example below). Temperature is treated as a per-dof parameter so as to allow adiabatic simulations.
The following ODE system is solved for every degree of freedom in the system, with possibly \(n_c\) holonomic constraints and with forces possibly split into \(m\) parts according to their characteristic time scales:
\[\begin{split}& \dot{r}_i = v_i \\ & \dot{v}_i = \frac{\sum_{k=1}^m F_i^{[k]}}{m_i} + \sum_{k=1}^{n_c} \lambda_k \nabla_{r_i} \sigma_k + \mathrm{bath}(T_i, v_i) \\ & \sigma_k(\mathbf{r}) = 0\end{split}\]An approximate solution is obtained by applying the Trotter-Suzuki splitting formula. In the particular case of two time scales, the default splitting scheme goes as follows:
\[e^{\Delta t\mathcal{L}} = e^{\frac{\Delta t}{2}\mathcal{L}^{[1]}_v} \left[ e^{\frac{\Delta t}{2 n_0}\mathcal{L}^{[0]}_v} \left( e^{\frac{\Delta t}{2 n_0 n_b}\mathcal{L}_r} e^{\frac{\Delta t}{n_0 n_b}\mathcal{L}_\mathrm{bath}} e^{\frac{\Delta t}{2 n_0 n_b}\mathcal{L}_r} \right)^{n_b} e^{\frac{\Delta t}{2 n_0}\mathcal{L}^{[0]}_v} \right]^{n_0} e^{\frac{\Delta t}{2}\mathcal{L}^{[1]}_v}\]Each exponential operator is the solution of a particular subsystem of equations. If \(\mathrm{bath}(T_i, v_i) = 0\), the scheme above is time-reversible, measure-preserving, and symplectic. It is referred to as the
VV-Middlescheme [3], where VV stands for Velocity Verlet. An alternative approach is also available, which is:\[e^{\Delta t\mathcal{L}} = \left[ \left( e^{\frac{\Delta t}{2 n_0 n_b}\mathcal{L}_r} e^{\frac{\Delta t}{n_0 n_b}\mathcal{L}_\mathrm{bath}} e^{\frac{\Delta t}{2 n_0 n_b}\mathcal{L}_r} \right)^{n_b} e^{\frac{\Delta t}{n_0}\mathcal{L}^{[0]}_v} \right]^{n_0} e^{\Delta t \mathcal{L}^{[1]}_v}\]This is referred to as the
LF-Middlescheme [3], where LF stands for Leap-Frog. In contrast to the previous scheme, it is not time-reversible. However, in single time-scale simulations, the two approaches result in equivalent coordinate trajectories, while the latter provides a velocity trajectory more consistent with the Maxwell-Boltzmann distribution at the specified temperature [3].- Parameters:
temperature (unit.Quantity) – The temperature of the heat bath.
step_size (float or unit.Quantity) – The outer step size with which to integrate the equations of motion.
- Keyword Arguments:
num_rattles (int, default=0) – The number of RATTLE computations for geodesic integration [4]. If
num_rattles=0, then no constraints are considered at all.scheme (str, default='VV-Middle') – Which splitting scheme will be used. Valid options are ‘VV-Middle’ and ‘LF-Middle’.
respa_loops (list(int), default=[1]) – A list of m integers, where respa_loops[k] determines how many substeps with force group k are internally executed for every step with force group k+1.
bath_loops (int, default=1) – The number of iterations of the bath operator per each step at time scale 0. This is useful when the bath operator is not exact, but derived from a splitting solution.
embodied_force_groups (list(int), default=[]) – A list of indices of force groups. The presence of an index i is this list means that the contribution of force group i is embodied in force group i+1. Therefore, such contribution must be properly subtracted during the integration at time scale i+1.
unroll_loops (bool, default=True) – Whether the integrator loops should be unrolled for improving efficiency. Using
unroll_loops=Falsecan be useful for printing the integrator steps.
Example
>>> from ufedmm import integrators >>> from openmm import unit >>> class MiddleNoseHooverIntegrator(integrators.AbstractMiddleRespaIntegrator): ... def __init__(self, ndof, tau, temperature, step_size, num_rattles=1): ... super().__init__( ... temperature, step_size, num_rattles, 'VV-Middle', [1], 1 ... ) ... kB = 8.3144626E-3*unit.kilojoules_per_mole/unit.kelvin ... gkT = ndof*unit.MOLAR_GAS_CONSTANT_R*temperature ... self.addGlobalVariable('gkT', gkT) ... self.addGlobalVariable('Q', gkT*tau**2) ... self.addGlobalVariable('v_eta', 0) ... self.addGlobalVariable('twoK', 0) ... self.addGlobalVariable('scaling', 1) ... def _bath(self, fraction): ... self.addComputeSum('twoK', 'm*v*v') ... self.addComputeGlobal( ... 'v_eta', f'v_eta + {0.5*fraction}*dt*(twoK - gkT)/Q' ... ) ... self.addComputeGlobal('scaling', f'exp(-{fraction}*dt*v_eta)') ... self.addComputePerDof('v', f'v*scaling') ... self.addComputeGlobal( ... 'v_eta', f'v_eta + {0.5*fraction}*dt*(scaling^2*twoK - gkT)/Q' ... ) >>> integrator = MiddleNoseHooverIntegrator( ... 500, 10*unit.femtoseconds, 300*unit.kelvin, ... 1*unit.femtoseconds, num_rattles=0 ... ) >>> print(integrator) Per-dof variables: kT Global variables: gkT = 1247.169392722986 Q = 0.1247169392722986 v_eta = 0.0 twoK = 0.0 scaling = 1.0 Computation steps: 0: allow forces to update the context state 1: v <- v + 0.5*dt*f/m 2: x <- x + 0.5*dt*v 3: constrain positions 4: twoK <- sum(m*v*v) 5: v_eta <- v_eta + 0.5*dt*(twoK - gkT)/Q 6: scaling <- exp(-1.0*dt*v_eta) 7: v <- v*scaling 8: v_eta <- v_eta + 0.5*dt*(scaling^2*twoK - gkT)/Q 9: x <- x + 0.5*dt*v 10: constrain positions 11: v <- v + 0.5*dt*f/m