A Novel Algorithm for Non-Bonded-List Updating ... - Semantic Scholar

5 downloads 11993 Views 243KB Size Report
Thus, efficient non-bonded list processing can speed up the energy ... 1Department of Computer Science, Ben-Gurion University of the Negev, Beer-Sheva, Israel. ..... C.K. is a Ralph Selig Career Development Chair in information theory.
JOURNAL OF COMPUTATIONAL BIOLOGY Volume 13, Number 5, 2006 © Mary Ann Liebert, Inc. Pp. 1041–1048

A Novel Algorithm for Non-Bonded-List Updating in Molecular Simulations TATIANA MAXIMOVA1 and CHEN KEASAR2

ABSTRACT Simulations of molecular systems typically handle interactions within non-bonded pairs. Generating and updating a list of these pairs can be the most time-consuming part of energy calculations for large systems. Thus, efficient non-bonded list processing can speed up the energy calculations significantly. While the asymptotic complexity of current algorithms (namely O(N), where N is the number of particles) is probably the lowest possible, a wide space for optimization is still left. This article offers a heuristic extension to the previously suggested grid based algorithms. We show that, when the average particle movements are slow, simulation time can be reduced considerably. The proposed algorithm has been implemented in the DistanceMatrix class of the molecular modeling package MESHI. MESHI is freely available at . Key words: energy calculations, energy minimization, molecular dynamics, neighbor list, nonbonded list, Verlet table.

1. INTRODUCTION 1.1. General

M

olecular dynamics (MD) and energy minimization play an essential role in computational structural biology and computational chemistry. They are used to study numerous natural phenomena as diverse as liquid fluidity (Allen and Tildesley, 1989), protein unfolding (Beck and Daggett, 2004), and protein structure prediction (Keasar and Levitt, 2003). These methods are inherently computer intensive, and often, computational resources limit their applicability. The current work presents a new algorithm that may speed up molecular simulations, and thus may increase their usability. Molecular simulations are iterative processes. The number of iterations is either user-defined or determined by some convergence criterion. In either case, the total execution time of the simulations cannot be estimated analytically. On the other hand, the execution time of a single iteration is amenable to analysis. The rate-determining step in a single iteration is the evaluation of the system’s energy function, which is a sum of several energy terms. Each term represents some aspect of the molecular system (e.g., covalent bonds, electrostatics). For the discussion of computational complexity, it is useful to distinguish between two classes of terms: bonded and non-bonded ones. Terms that represent interactions between particles 1 Department of Computer Science, Ben-Gurion University of the Negev, Beer-Sheva, Israel. 2 Department of Computer Science, Department of Life Science, Ben-Gurion University of the Negev, Beer-Sheva,

Israel.

1041

1042

MAXIMOVA AND KEASAR

that are close in the network of covalent bonds (up to some fixed number of bonds) are called “bonded” terms. The other terms are known as “non-bonded.” Generally speaking, the energy functions evaluate the interactions between all particles in the system. Their computational complexity is thus at least O(N2 ), where N is the number of particles. In practice, an O(N2 ) complexity would have rendered many important systems inaccessible for computational studies. In order to study such systems, one needs to abandon the general definitions and impose some restrictions on the molecular model and the energy function. These restrictions allow the development of algorithms with complexities down to O(N). Different fields of research suggest different sets of restrictions on the molecular system and the energy function. The restrictions listed in the following paragraphs are rather common in the field of computational structural biology, and serve as the basis to the widely used algorithms presented bellow.

1.2. Restrictions on the molecular system and energy function The most severe restriction on the molecular system that we use is that covalent bonds are not allowed to form or break during the simulation. Thus, the list of bonded-interactions is fixed and its length is O(N). Assuming that the evaluation of a single bonded interaction takes some fixed time, the complexity of all bonded interactions is also O(N). Therefore, they do not affect the computational complexity, as the most efficient algorithms for non-bonded interactions are O(N). Further, in practice, each particle has many more non-bonded interactions than bonded ones. Thus, the execution times of bonded terms are negligible compared with those of the non-bonded ones. The second restriction is that the energy function severely penalizes too short distances between particles. Farther, when particles are covalently bonded, distances that are too long are also severely penalized. Thus, one may assume that after an insignificant number of simulation steps the density of the particles is finite and that the distances between bonded particles are close to the ideal ones. The third restriction is that the non-bonded energy terms diminish to zero at some cutoff distance (Rcut ). That is, each particle interacts only with particles that are within a sphere of radius Rcut around it—its neighbors. Together with the finite density assumption, this restriction implies that the number of interactions a particle may have is finite. In other words, the list of interacting non-bonded particle pairs has an O(N) length. This list is known as the non-bonded-list (NBL) or neighbor list. It should be noted that the NBL is not fixed during the simulation. As the system evolves in time, the particles move and their mutual distances change. In each simulation step some particle-pairs may enter the NBL, and others may leave it. For the sake of simplicity we may again assume that the evaluation of a single non-bonded interaction takes some fixed time. This is indeed true for a large variety of common non-bonded terms such as Lennard-Jones, Culomb-electrostatics, and pair contacts. Under this assumption, the evaluation of the non-bonded energy terms, given an updated NBL, is also O(N). To summarize, under the above three restrictions on the molecular system and energy function, the algorithmic problem is reduced to the problem of updating the non-bonded list.

1.3. The slow change assumption The typical simulated systems are dense, and often include polymer chains. In these systems any significant movement of a particle is coupled to the movements of many other particles. Thus, many iterations of the simulation are required for an average particle to change its position significantly. Unlike the above restrictions, the slow change is not explicitly imposed upon the simulation protocol. It was observed however in many system and serves as the basis for heuristic algorithms including the one we present here.

1.4. Current algorithms for NBL update An algorithm for NBL update is accurate if, at any step of the simulation, all particle pairs (P i , P j ) with inter-particle distance (Dij ) below Rcut are included in the NBL. Failure of the algorithm will render the calling method (typically MD or energy minimization) instable. Energy minimization methods in particular are extremely sensitive to such a failure. Note that the NBL may include particles that are more than Rcut apart (see sections 1.4.1 and 1.4.2), as these pairs are assumed not to contribute to the energy function.

NOVEL ALGORITHM FOR NON-BONDED-LIST GENERATION

1043

1.4.1. Considerable performance gain may be achieved by grouping particles that are covalently connected (by some fixed number of bonds) to a central one. It is assumed (and in practice enforced by the bond energy term) that such a group is contained within a small sphere of radius Rg around the central particle. Two particles cannot be in a less than Rcut distance, if the central particles of their groups are farther apart than Rcut + 2Rg . Thus, for most pairs of groups in a large system a single measurement of the distance between the central particles may render the other measurements unnecessary (Glikman, 1996; Yip and Elber, 1989; Petrella et al., 2002; M. Levitt, personal communication). When this technique is used, the rate-limiting step is the calculation of distances between the central particles of the groups. This can be done either by an all-vs.-all search or by any of the techniques presented below. 1.4.2. The “Verlet table algorithm” (Verlet, 1967) relies heavily on the slow change assumption. In this algorithm, a buffer layer of width Rbuff wraps the initial sphere of interacting neighbors around each particle. Thus, a pair of particles (P i , P j ) with inter particle distance Dij , is included in the NBL if Dij < Rcut + Rbuff . Now, the NBL includes particle pairs that do not contribute to the energy but the NBL need not be updated in each step. The slow change assumption implies that a pair of particles that is not included in the NBL at the time of the last NBL update, must spend some iterations in the buffer region before (if at all) it starts to contribute to the energy. A proper choice of nint , the interval between consecutive NBL updates and Rbuff may result in a very efficient protocol. Indeed, each NBL update (and thus the whole algorithm) is O(N2 ). But, as this heavy process is executed only intermittently, the overall performance is good, at least for small to medium size systems. Obviously the choices Rbuff and nint are related. The larger Rbuff is, the larger may also nint be. Heuristics for the choice of these parameters have been suggested (Chialvo and Debenedetti, 1991, 1992). The efficiency of this algorithm declines when the molecular system includes particles with different mobility, as the update rate needs to be adapted to the fastest particles (for a partial solution, see Glikman et al., 1996). A more fundamental problem of this algorithm is that it is not guaranteed to be accurate. It may well be that occasionally a pair of particles does “sneak in” and crosses the Rbuff buffer between two consecutive updates of the NBL. MD simulations may tolerate such events as long as they are very rare. Minimization algorithms, on the other hand, are much less robust and are likely to break down if such event occurs even once during the simulation. This hazard is accounted for by a variant of the Verlet table algorithm. In this variant, the NBL is updated when the sum of the two largest displacements of particles reaches Rbuff (Yao et al., 2004; Fincham and Ralston, 1981). In this case, the accuracy is guaranteed, but with the high price of frequent updates. 1.4.3. Grid-based algorithms divide the simulation space to discrete cells (Levinthal, 1966). All the significant interactions of any particle within a given cell can be found in the same cell or in the finite-size set of adjacent ones (third restriction). Since the number of particles per cell is also finite (due to the second restriction above), the NBL update requires a finite number of distance calculations per particle. The overall complexity of these algorithms is thus O(N) and they are guaranteed to be accurate. The two major versions of this approach differ in the grid cell length (GCL). The “cell-linked list” algorithm (Hockney and Eastwood, 1981; Allen and Tildesley, 1987; Grest et al., 1989; Petrella et al., 2002) uses cells with edges that are not smaller than Rcut . The alternative, the “grid-cell” algorithm (Yip and Elber, 1989; Everaers and Kremer, 1994; Mattson and Rice, 1999; Heinz and Hünenberger, 2004), uses much smaller grid-cells with edges comparable to atomic distances. Thus, each cell may be empty or contain very few particles. The latter approach reduces the number of distance calculations but pays an extra overhead for iterating over a large number of neighboring cells and handling empty ones.

2. NOVEL NBL UPDATING ALGORITHM Our new algorithm is an extension of the above grid-based approach that takes into account the slow movement assumption. In order to do that, it borrows the concept of a buffer region from the Verlet table algorithm. The essence of the new algorithm is that the NBL is represented by a sparse matrix that is updated by rows. The i-th row of the matrix contains particle pairs (P i , P j ) with inter particle distance Dij < Rcut + Rbuff . The i-th row is updated only if the corresponding particle has made a significant movement (a third of the buffer size) since the last row update. The raw update itself is done using a grid, ensuring an O(N) overall complexity. When the slow movement assumption holds, only a small fraction

1044

MAXIMOVA AND KEASAR

of the rows is updated per iteration. Thus, a considerable performance gain is achieved over the original grid-based algorithm. If this assumption does not hold, we simply converge to the original performance. A formal proof of the accuracy of the new algorithm is presented in the results section below.

3. IMPLEMENTATION The new algorithm is implemented in the DistanceMatrix class of the molecular modeling package MESHI (Kalisman et al., 2006). Within DistanceMatrix, the NBL is represented by a sparse matrix of distances. These distances are updated once during the NBL update. The various energy functions (e.g., Lennard-Jones, solvation, angles, torsions, hydrogen-bonds) acquire the distances they need from this matrix. Thus, each distance between non-bonded particles is calculated at most once per energy evaluation regardless of how many energy terms require it. The same heuristics that allow the efficient update of the NBL also allow a time and space efficient design of the DistanceMatrix.

4. RESULTS 4.1. Proof of accuracy The problem: Let Rcut and Rbuff be the maximal distance of non-zero interactions and some arbitrary buffer size respectively. Let P i and P j be two particles positioned at Xis and Xj s, respectively, at some simulation step s. Let Xiprev and Xj prev be the positions of P i and P j respectively, at the time their corresponding rows were last updated (Fig. 1). Thus, 1. |Xiprev − Xis | < 1/3Rbuff and |Xj prev − Xj s | < 1/3Rbuff . We need to show that if the pair (P i , P j ) is not included in the NBL in s, then |Xis − Xj s | >= Rcut . Lemma. If the pair (Pi , Pj ) is not included in the NBL in s, then |Xiprev − Xjprev | >= Rcut + 2/3Rbuff . Proof.

Note that our claim is immediately derivable from this lemma.

2. |Xiprev − Xjprev | >= Rcut + 2/3Rbuff (lemma) 3. |Xis − Xjprev | >= Rcut + 1/3Rbuff (1 & 2) 4. |Xis − Xjs | >= Rcut (3 & 1). Proof of the lemma by induction on the simulation step s. 1. If s = 1 then both P i and P j are updated. That is Xiprev = Xis and Xjprev = Xjs . Thus, if the pair (P i , P j ) is not included in the NBL then |Xiprev − Xj prev | >= Rcut + Rbuff . 2. Assuming that the lemma is correct for step s, we should prove it is also correct for step s + 1. 3. If our claim is true for step s, then there are two possibilities for step s + 1: (a) If neither P i nor P j are updated at step s + 1, then neither Xiprev nor Xjprev change. Thus, the claim is trivially correct. (b) If (without loss of generality) P j is updated at step s + 1 (Fig. 2) then: i. |Xis+1 − Xj s+1 | >= Rcut + Rbuff (otherwise the pair (P i , P j ) would have entered the NBL). ii. Xjs+1 = Xj prev (Xjprev was just set) iii. |Xjprev − Xis+1 | >= Rcut + Rbuff (i & ii) iv. | Xiprev − Xis+1 | < 1/3Rbuff (1) v. |Xiprev − Xj prev | >= Rcut + 2/3Rbuff (iii & iv)

NOVEL ALGORITHM FOR NON-BONDED-LIST GENERATION

1045

FIG. 1. The accuracy of the new algorithm is proven from the lemma by the use of the triangle inequality. P i and P j are two particles positioned at Xis and Xjs respectively at some simulation step s. Xiprev and Xj prev were the positions of P i and P j respectively when each was last updated. Given that the (P i , P j ) pair is not in the NBL, the lemma states that the distance between Xiprev and Xjprev is larger than Rcut + 2/3Rbuff . The distances between Xi and Xiprev never exceed 1/3Rbuff , as a larger distance triggers updating of P i and then the Xi − Xiprev distance becomes zero. The same reasoning also applies to Xj and Xj prev .

FIG. 2. The induction step in the proof of the lemma is again proven using the triangle inequality. The annotation is the same as in Figure 1. Given that (without loss of generality) P j has just been updated, and that the (P i , P j ) pair has not entered the NBL, Xj s+1 equals Xjprev , and the P i − P j distance is above Rcut + Rbuff .

1046

MAXIMOVA AND KEASAR

4.2. Performance We demonstrate the efficiency of our algorithm using minimization simulations with two molecular systems. The first system, which provided a handy benchmark for development, is a cluster of helium atoms where the only energy term is Lennard-Jones with Rcut of 6Å (Figs. 3a, 3b). The other one, which much more reflects our true interests, is poly-alanine (Figs. 3c, 3d). In this case, the energy function includes, in addition to the Lennard-Jones term (again with Rcut of 6Å), bond, angle, torsions, plane, and out-of-plain terms. In both systems, initial random configurations were energy minimized using the LBFGS (Nocendal and Wright, 1999) algorithm. In order to compare the performance of the new algorithm with the performance of the grid based algorithms, the simulations were performed in sets. Each set used a different combination of GCL and Rbuff . When Rbuff equals zero, the program practically converges to either the naive O(N2 ) all-vs.-all algorithm (GCL = 1000), to the linked-list algorithm (GCL = Rcut ), or to the grid-cell algorithm (GCL = Rcut /2, Rcut /3, etc). With a non-zero value of Rbuff our new algorithm takes effect (GCL equals to Rmax = Rcut + 2/3Rbuff (see Lemma p.4.1) or to Rmax /2, Rmax /3, etc). Figure 3 presents the system-size dependence of simulation time (a,c) and the number of distance calculations (b,d) for a selected number sets. For each GCL, zero and the best performing buffer size are presented. Other values of buffer size, from 0.2 to 5Å, resulted in qualitatively similar results (data not shown). Generally speaking, our new algorithm outperforms

FIG. 3. Average time cost (a,c) and number of distance calculations (b,d) per minimization step as a function of particles number. The simulations were performed on two systems: helium cluster (a,b) and poly-alanine (c,d). Results present a full relaxation of helium and first 10,000 steps of poly-alanine relaxation. BL, bonded list. Each simulation was repeated 10 times with different random initial configurations. The maximum standard error of each data point is below 3%. Thus, error bars are omitted for clarity. Simulations were performed using the freely available software package MESHI with Java 1.5. Helium simulations were performed on Intel Pentium IV, 2.80 GHz, 3 GB RAM, and 512 KB cache. Poly-alanine simulations were performed on AMD Opteron Processor 252, 2.6 GHz, 4 GB RAM, and 1024 cache. Operating system in both cases was Mandrake Linux.

NOVEL ALGORITHM FOR NON-BONDED-LIST GENERATION

1047

the original grid-based algorithm for all cell sizes, with the best combination being (GCL = 3 13 Å, Rcut = 6Å, Rbuff = 1Å).

5. DISCUSSION In this work, we present a new algorithm of non-bonded list update. Although similar in spirit to several existing algorithms (most notably to the second option in Glikman et al., 1996), it is unique in being both robust and very efficient. Similarly to the grid-based methods, its accuracy does not depend on any assumptions about the simulated system. At the same time, it resembles the Verlet table algorithm by taking full advantage of the slow movements of the system. Further, since each particle is updated separately, efficiency is not reduced when some particles are faster than the others. We tested the efficiency of our approach using two systems. The first system (the helium cluster minimization) was chosen for its simplicity, which helped us in the development process. The other system (poly-alanine minimization) was chosen since, while it is still simple and manageable, it is more related to protein structure prediction (Keasar and Levitt, 2003). Comparing the performance of alternative algorithms is a delicate task. The computation time depends heavily on the available hardware and the details of implementation. To circumvent the hardware problem, we only compared simulations that were done on identical computers. The implementation problem is harder to solve. It may well be that our implementation of a given algorithm is not the optimal one. As a partial remedy, we presented, in addition to simulation time, the number of distance calculations. Distance calculation is required by all pair-wise energy terms that we are aware of. Thus, the time required for the distance calculations is a lower limit on the simulation time. A single distance calculation takes constant time, and thus, the number of distance calculations is a good measure of the algorithm’s efficiency. It should be noted that the number of distances below Rcut is a lower limit of the number of distance calculations. On both systems and with both efficiency measures, our algorithm was shown to outperform grid-based methods. Similarly to the original grid-based algorithms, the current method is orthogonal to the Verlet-table and the particle-grouping algorithms. Thus, it can be combined with them to yield an even more efficient algorithm. Preliminary work (data not shown) suggests that the Verlet-table approach, important as it is in the field of MD, may not be useful in our systems. Due to the low numerical stability of the minimization algorithms, wide buffer regions are required. The particle-grouping algorithm, on the other hand, may prove useful. A Java implementation of the algorithm is freely available as part of the MESHI package (Kalisman et al., 2005).

ACKNOWLEDGMENTS C.K. is a Ralph Selig Career Development Chair in information theory. T.M. is supported by the grant from Israeli Science Absorption Center. The EU 6th Framework Program is gratefully acknowledged for support to the GeneFun project, contract No: LSHG-CT-2004-503567.

REFERENCES Allen, M.P., and Tildesley, D.J. 1987. Computer Simulation of Liquids, Oxford University Press, New York. Beck, D.A.C., and Daggett, V. 2004. Methods for molecular dynamics simulations of protein folding/unfolding in solution. Methods 34, 112–120. Chialvo, A.A., and Debenedetti, P.G. 1991. On the performance of an automated Verlet neighbor list algorithm for large systems on a vector processor. Comput. Phys. Commun. 64(1), 15. Chialvo, A.A., and Debenedetti, P.G. 1992. An automated Verlet neighbor list algorithm with a multiple time-step approach for the simulation of large systems. Comput. Phys. Commun. 70(3), 467. Everaers, R., and Kremer, K. 1994. A fast grid search algorithm for molecular-dynamics simulations with short-range interactions. Comput. Phys. Commun. 81(1–2), 19.

1048

MAXIMOVA AND KEASAR

Fincham, D., and Ralston, B.J. 1981. Molecular dynamics simulation using the CRAY-1 vector processing computer. Comput. Phys. Commun. 23, 127–134. Grest, G.S., Dunweg, B., and Kremer, K. 1989. Vectorized link cell Fortran code for molecular dynamics simulations for a large number of particles. Comput. Phys. Commun. 55, 269–285. Heinz, D.J., and Hünenberger, P. 2004. A fast pairlist-construction algorithm for molecular simulations under periodic boundary conditions. J. Comput. Chem. 25, 1474. Hockney, R.W., and Eastwood, J.W. 1981. Computer Simulations Using Particles, McGraw-Hill, New York. Kalisman, N., et al. 2005. MESHI—A new library of Java classes for molecular modeling. Bioinformatics, 21(20), 3931–3932. Keasar, C., and Levitt, M. 2003. A novel approach to decoy set generation: Designing a physical energy function having local minima with native structure characteristics. J. Mol. Biol. 329(1), 159–174. Levinthal, C. 1966. Molecular model-building by computer. Sci. Am. 214, 42. Mattson, W., and Rice, B.M. 1999. Near-neighbor calculations using a modified cell-linked list method. Comput. Phys. Commun. 119, 135. Nocendal, J., and Wright, S.J. 1999. Numerical Optimization, Springer-Verlag, New York. Petrella, R.J., et al. 2002. An improved method for nonbonded list generation: Rapid determination of near neighbor pairs. J. Comput. Chem. 24, 222. Verlet, L. 1967. Computer “experiments” on classical fluids. I. Thermodynamical properties of Lennard-Jones molecules. Phys. Rev. 159, 98. Yao, Z., et al. 2004. Improved neighbor list algorithm in molecular simulations using cell decomposition and data sorting method. Comput. Phys. Commun. 161, 27. Yip, V., and Elber, R. 1989. Calculations of a list of neighbors in molecular-dynamics simulations. J. Comput. Chem. 10(7), 921.

Address correspondence to: Chen Keasar Department of Computer Science Ben-Gurion University of the Negev P.O. Box 653 Beer-Sheva, 84105, Israel E-mail: [email protected]