View Javadoc
1   // ******************************************************************************
2   //
3   // Title:       Force Field X.
4   // Description: Force Field X - Software for Molecular Biophysics.
5   // Copyright:   Copyright (c) Michael J. Schnieders 2001-2024.
6   //
7   // This file is part of Force Field X.
8   //
9   // Force Field X is free software; you can redistribute it and/or modify it
10  // under the terms of the GNU General Public License version 3 as published by
11  // the Free Software Foundation.
12  //
13  // Force Field X is distributed in the hope that it will be useful, but WITHOUT
14  // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15  // FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
16  // details.
17  //
18  // You should have received a copy of the GNU General Public License along with
19  // Force Field X; if not, write to the Free Software Foundation, Inc., 59 Temple
20  // Place, Suite 330, Boston, MA 02111-1307 USA
21  //
22  // Linking this library statically or dynamically with other modules is making a
23  // combined work based on this library. Thus, the terms and conditions of the
24  // GNU General Public License cover the whole combination.
25  //
26  // As a special exception, the copyright holders of this library give you
27  // permission to link this library with independent modules to produce an
28  // executable, regardless of the license terms of these independent modules, and
29  // to copy and distribute the resulting executable under terms of your choice,
30  // provided that you also meet, for each linked independent module, the terms
31  // and conditions of the license of that module. An independent module is a
32  // module which is not derived from or based on this library. If you modify this
33  // library, you may extend this exception to your version of the library, but
34  // you are not obligated to do so. If you do not wish to do so, delete this
35  // exception statement from your version.
36  //
37  // ******************************************************************************
38  package ffx.algorithms.dynamics.integrators;
39  
40  import static ffx.utilities.Constants.KCAL_TO_GRAM_ANG2_PER_PS2;
41  
42  import ffx.potential.SystemState;
43  import ffx.numerics.Potential;
44  
45  /**
46   * Integrate Newton's equations of motion using a Beeman multistep recursion formula; the actual
47   * coefficients are Brooks' "Better Beeman" values.
48   *
49   * @author Michael J. Schnieders
50   * @since 1.0
51   */
52  public class BetterBeeman extends Integrator {
53  
54    private double dt2_8;
55    private double dt_8;
56  
57    /**
58     * Constructor for BetterBeeman.
59     *
60     * @param state The current state of the molecular dynamics simulation to operate on.
61     */
62    public BetterBeeman(SystemState state) {
63      super(state);
64      dt_8 = 0.125 * dt;
65      dt2_8 = dt * dt_8;
66    }
67  
68    /**
69     * {@inheritDoc}
70     *
71     * <p>Use Newton's second law to get the next acceleration and find the full-step velocities using
72     * the Beeman recursion.
73     */
74    @Override
75    public void postForce(double[] gradient) {
76      copyAccelerationToPrevious();
77      double[] a = state.a();
78      double[] v = state.v();
79      double[] mass = state.getMass();
80      double[] aPrevious = state.aPrevious();
81      for (int i = 0; i < state.getNumberOfVariables(); i++) {
82        double m = mass[i];
83        if (m > 0.0) {
84          a[i] = -KCAL_TO_GRAM_ANG2_PER_PS2 * gradient[i] / m;
85          v[i] += (3.0 * a[i] + aPrevious[i]) * dt_8;
86        }
87      }
88    }
89  
90    /**
91     * {@inheritDoc}
92     *
93     * <p>Store the current atom positions, then find new atom positions and half-step velocities via
94     * Beeman recursion.
95     */
96    @Override
97    public void preForce(Potential potential) {
98      double[] x = state.x();
99      double[] a = state.a();
100     double[] v = state.v();
101     double[] mass = state.getMass();
102     double[] aPrevious = state.aPrevious();
103     for (int i = 0; i < state.getNumberOfVariables(); i++) {
104       double m = mass[i];
105       if (m > 0.0) {
106         double temp = 5.0 * a[i] - aPrevious[i];
107         x[i] += v[i] * dt + temp * dt2_8;
108         v[i] += temp * dt_8;
109       }
110     }
111   }
112 
113   /** {@inheritDoc} */
114   @Override
115   public void setTimeStep(double dt) {
116     this.dt = dt;
117     dt_8 = 0.125 * dt;
118     dt2_8 = dt * dt_8;
119   }
120 
121   /** {@inheritDoc} */
122   @Override
123   public String toString() {
124     return "Better Beeman";
125   }
126 }