Introduction to PyRETIS and rare event methods¶
PyRETIS is a computational library for performing molecular simulations of rare events with a focus on transition interface sampling (TIS) [1] and replica exchange transition interface sampling (RETIS) [2]. PyRETIS 4 runs RETIS with infinite swapping on parallel workers (∞RETIS) [5] [6], and has Monte Carlo moves and methods that came after PyRETIS 3. Both are introduced at the end of this page, in Infinite swapping and parallel path sampling and Newer Monte Carlo moves and methods.
Rare events are called rare because they happen at time or length scales much longer than we are able to simulate through brute-force simulations. Raindrops form every day, but compared to the motion of water molecules, raindrop formation is rare, and simulating it through brute-force simulations would take forever and a day.
Rare event methods aim to sample these rare events inaccessible through brute-force simulation.
Transition Interface Sampling¶
To explain the basic concepts, we consider an illustrative example: The transition between two stable states, from the reactant (labeled A) to the product (labeled B) as illustrated in Fig. 1.
Fig. 1 A potential energy barrier separating two stable states A and B. The order parameter measures the extent of the reaction in this particular energy landscape and a possible trajectory for a particle making the transition is illustrated as a black arrow.¶
These two states are defined by a progress coordinate (or order parameter), \(\lambda\), where state A is for \(\lambda \leq \lambda_\text{A}\) and state B for \(\lambda \geq \lambda_\text{B}\). The central quantity calculated in TIS/RETIS simulations is the rate constant \(k_\text{AB}\) for the transition \(\text{A} \to \text{B}\) which can be expressed as:
and we see that it contains two parts:
The initial flux \(f_\text{A}\) which measures how often trajectories start off at the foot of the reaction barrier from the reaction side \(\lambda_\text{A}\). In TIS this is obtained from a molecular dynamics (MD) simulation which in PyRETIS is requested by running a md-flux simulation. Note that this is not needed for the RETIS method as explained.
The crossing probability \(\mathcal{P}_{\text{A}} (\lambda_\text{B} \vert \lambda_\text{A})\) of reaching \(\lambda_\text{B}\) before \(\lambda_\text{A}\) given that \(\lambda_\text{A}\) has just been crossed. In PyRETIS this can be accomplished by running a tis or retis simulation.
As this is a rare event, the crossing probability is extremely small and nearly impossible to compute in brute-force simulations. Transition interface sampling divides the region between A and B into sub-regions using interfaces, denoted \(\lambda_i\) (see Fig. 2). The first interface, \(\lambda_0\) is positioned at the interface defining state A (\(\lambda_A\)), and the next interface, \(\lambda_1\) is put at \(\lambda_1 > \lambda_0\) such that the probability of reaching \(\lambda_1\) from \(\lambda_0\) is no longer extremely small. We can continue in this fashion and place \(N\) more interfaces until we reach \(\lambda_{N} = \lambda_\text{B}\). What we effectively have done with these \(N+1\) interfaces is to split up the computation of the extremely small crossing probability into the computation of many, not-so small, crossing probabilities:
Here, the intermediate crossing probabilities, \(P_{\text{A}} (\lambda_{i+1}|\lambda_{i})\), are formally defined as the probability of a path crossing \(\lambda_{i+1}\) given that it originated from \(\lambda_\text{A}\), ended in \(\lambda_\text{A}\) or \(\lambda_\text{B}\), and had at least one crossing with \(\lambda_i\) in the past.
The interfaces we have placed define the so-called path ensembles. A path ensemble comprises all possible trajectories that start at the foot of reaction barrier from the reactant side (\(\lambda_\text{A}\)), end in it or at the product region (\(\lambda_\text{B}\)) and having reached a certain threshold value (\(\lambda_i\)) between the start point and the final point. This path ensemble is labelled as \(\left[i^{+} \right]\). The probabilities, \(\mathcal{P}_{\text{A}} (\lambda_{i+1} \vert \lambda_{i})\) can then be obtained as the fraction of paths in the \(\left[i^+\right]\) ensemble that also cross \(\lambda_{i+1}\).
Fig. 2 Illustration of TIS interfaces placed along the order parameter in a system where a potential energy barrier separates two stable states A and B. The interfaces define different ensembles and here, two trajectories are shown. One (black) is reactive, reaching the final state, while the other (orange) just reaches the intermediate \(\lambda_2\) interface.¶
What is left now, is to have an efficient way of generating trajectories for the various path ensembles. This is in fact done by making use of a selection of Monte Carlo (MC) moves. For TIS [1] we choose between two moves:
The shooting move which is adapted from the transition path sampling (TPS) shooting algorithm [3] [4] to allow variable trajectory length. In this move, we generate a new trajectory from an existing trajectory one by:
Picking randomly one of the discrete MD steps in the present trajectory.
Modifying the velocities of this phase point (e.g. by randomly drawing new velocities from a Maxwellian distribution).
Generating a new trajectory from this new phase point by integrating (i.e. running MD simulations) forward and backward in time until A or B is reached. The new trajectory is then obtained by merging the backward and forward trajectories.
The new trajectory is accepted as part of \([i^+]\) only if all the following criteria are satisfied:
A detailed balance condition for the energy and path length. [1]
It starts at \(\lambda_A\)
It has at least one crossing with \(\lambda_i\) before ending in A or B.
The shooting move gives a much higher chance to generate a valid trajectory at each trial compared to simply starting from a random phase point within the reactant well.
The time reversal move which generates trajectories by simply changing the time direction of a path. [1]
These two moves are illustrated in Fig. 4. See Move types for a complete list of all move type codes used in PyRETIS output and input files.
Replica Exchange Transition Interface Sampling¶
The RETIS method is similar to TIS and employs both the shooting and time reversal moves. In addition, RETIS makes use of the swapping move and defines a new ensemble \([0^-]\) which consist of trajectories that explore the reactant state (see the illustration in Fig. 3).
Fig. 3 Illustration of RETIS interfaces placed along the order parameter in a system where a potential energy barrier separates two stable states A and B. The interfaces define different ensembles and here, two trajectories are shown. One (black) is reactive, reaching the final state, while the other (orange) just reaches the intermediate \(\lambda_2\) interface. In RETIS a special path ensemble, \([0^-]\) is also considered as described in the text.¶
The swapping move acts between different path simulations. If two simulations generate simultaneously two paths that are valid for each other’s path ensemble, these two paths can be swapped. The swapping moves increase with negligible extra computational cost the number of accepted paths in the ensembles and decrease significantly the correlations between the consecutive paths within the same ensemble. All the moves used for generating trajectories are illustrated in Fig. 4.
Fig. 4 Illustration of the RETIS moves for generating trajectories. A contour plot of a hypothetical free energy surface along a progress coordinate and an arbitrary second coordinate is shown and 4 interfaces (\(\lambda_0\), \(\lambda_1\), \(\lambda_2\) and \(\lambda_3\)) have been positioned along the progress coordinate. Three different RETIS moves (shooting, time reversal and swapping) are shown for the \([i^+] = [2^+]\) path ensemble. The old paths are in blue and the new paths after (a successful) completion of the MC moves are shown in red. The orange line show the interface that needs to be crossed for a valid path in the current ensemble.¶
There is one notable exception where the swapping move is more computationally demanding: the swap between the \([0^+]\) and \([0^-]\) ensembles requires MD simulations. [2]
In a TIS simulation, as explained above, we have to perform an extra simulation in order to calculate the initial flux. In RETIS, this initial flux can directly be obtained by:
where \(\left \langle t_{\rm path}^{[0^+]} \right \rangle\) is the average path length in the \([0^+]\) ensemble and \(\left \langle t_{\rm path}^{[0^-]}\right \rangle\) the average path length in the \([0^-]\) ensemble.
In PyRETIS, RETIS simulations are requested by setting the simulation task to RETIS.
Infinite swapping and parallel path sampling¶
In RETIS, a swap move exchanges the paths of two neighbouring ensembles, and only when each path is valid in the other ensemble. The swap needs no new MD, but it moves only two paths at a time, and it needs both paths at the same moment: in a parallel run, the ensembles have to finish their current moves before swaps can be attempted. The paths of the higher ensembles are longer and take more MD steps, so the simulations of the lower ensembles end up waiting for them.
Infinite swapping removes both limits [5]. Imagine that, between two shooting moves, we attempted an infinite number of swap moves. The paths would then be shuffled over the ensembles in every arrangement that puts each path in an ensemble where it is valid. The probability that a given ensemble holds a given path then follows directly from permanents (determinants in which every term has a plus sign) of the matrix that tells in which ensembles each path is valid, and with which weight for the high-acceptance moves described below. An ensemble then no longer counts only the path it holds: it counts every current path that is valid in it, each with its probability. These swaps cost no MD at all. The zero swap between \([0^-]\) and \([0^+]\), which needs MD, stays an ordinary move.
∞RETIS [6] uses these probabilities to run in parallel without a common waiting point. A pool of workers each run one Monte Carlo move at a time. A worker that is free draws an ensemble and a path from the infinite-swapping probabilities of the ensembles and paths that no other worker holds, runs a move on them (a shooting move, for instance), and hands back the result, after which the probabilities are updated. As no swap waits for two moves to end together, the workers run asynchronously, a run can have fewer workers than ensembles, and the run time drops nearly in proportion to the number of workers over a far wider range than with synchronous swaps [6].
In PyRETIS 4, every path-sampling run uses this scheduler, with any
engine. The number of workers is the
workers keyword of the
[runner] section: at most the number of
live path ensembles, and one less in a run that swaps paths. A run
without the section has one worker. A RETIS run samples with infinite swapping, while a TIS run
shoots each ensemble on its own path. As an ensemble can hold several
paths at once, a cycle of a RETIS run can show several rows in
pathensemble.txt, each with its
share of the ensemble (the FracInc column), and pyretis analyse
analyses the run as any other RETIS run. The
infinite-swapping tutorial runs an example,
and Monte Carlo moves gives the details.
Newer Monte Carlo moves and methods¶
The shooting, time reversal and swapping moves described above remain the basis of path sampling. PyRETIS adds moves that give a new path less correlated with the old one, or that are rejected less often, and tasks that apply path sampling to other questions. Monte Carlo moves describes each of them with its keywords.
Sub-trajectory moves. A shooting move integrates one long trajectory, which is rejected when it does not meet the conditions of the ensemble. Stone skipping and web throwing [7], and wire fencing [8], instead generate a series of short sub-trajectories near the interface of the ensemble and extend one of them into the new path, which then has little in common with the old one. They help on barriers where ordinary shooting decorrelates slowly. In their high-acceptance form, a valid trial path is always accepted and carries a weight, which the infinite-swapping probabilities and the analysis take into account. Wire fencing always works this way, and so suits ∞RETIS, where few moves are then lost to rejections.
Biased shooting. The shooting point is picked more often in the important part of a path, near the top of the barrier for instance, and an exact correction in the acceptance keeps the sampled ensemble, and so the rate, unchanged.
Partial paths. For diffusive processes, full paths become very long. Partial path TIS (PPTIS) [9] samples only the part of a path around the interface of each ensemble, assuming that the dynamics lose the memory of their past over the distance between interfaces, and rebuilds the rate from these short paths. REPPTIS [10] adds replica exchange between the partial-path ensembles.
Both directions in one run. The
biretistask runs one ladder of ensembles from each state, which can meet in shared ensembles, best placed at the top of the barrier, and gives the rate constants of \(\text{A} \to \text{B}\) and of \(\text{B} \to \text{A}\) from one simulation. It runs with one worker.Two engines. With QuanTIS, the \([0^-]\) ensemble runs with the engine of its own
[engine0]section, and an energy test keeps the zero swap between the two engines exact.Permeability. The mirror and target swap moves of the \([0^-]\) ensemble serve the permeability method [11], which computes the permeability of a membrane from path sampling. They run with one worker.