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-2025.
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.openmm.drude;
39  
40  import com.sun.jna.ptr.PointerByReference;
41  import ffx.openmm.Integrator;
42  
43  import static edu.uiowa.jopenmm.OpenMMDrudeLibrary.OpenMM_DrudeIntegrator_create;
44  import static edu.uiowa.jopenmm.OpenMMDrudeLibrary.OpenMM_DrudeIntegrator_destroy;
45  import static edu.uiowa.jopenmm.OpenMMDrudeLibrary.OpenMM_DrudeIntegrator_getDrudeTemperature;
46  import static edu.uiowa.jopenmm.OpenMMDrudeLibrary.OpenMM_DrudeIntegrator_getMaxDrudeDistance;
47  import static edu.uiowa.jopenmm.OpenMMDrudeLibrary.OpenMM_DrudeIntegrator_getRandomNumberSeed;
48  import static edu.uiowa.jopenmm.OpenMMDrudeLibrary.OpenMM_DrudeIntegrator_setDrudeTemperature;
49  import static edu.uiowa.jopenmm.OpenMMDrudeLibrary.OpenMM_DrudeIntegrator_setMaxDrudeDistance;
50  import static edu.uiowa.jopenmm.OpenMMDrudeLibrary.OpenMM_DrudeIntegrator_setRandomNumberSeed;
51  import static edu.uiowa.jopenmm.OpenMMDrudeLibrary.OpenMM_DrudeIntegrator_step;
52  
53  /**
54   * A base class to encapsulate features common to Drude integrators.
55   */
56  public class DrudeIntegrator extends Integrator {
57  
58    /**
59     * Create a DrudeIntegrator.
60     *
61     * @param pointer A pointer to the native OpenMM Drude integrator object.
62     */
63    public DrudeIntegrator(PointerByReference pointer) {
64      super(pointer);
65    }
66  
67    /**
68     * Create a DrudeIntegrator.
69     *
70     * @param stepSize the step size with which to integrator the system (in picoseconds)
71     */
72    public DrudeIntegrator(double stepSize) {
73      super(OpenMM_DrudeIntegrator_create(stepSize));
74    }
75  
76    /**
77     * Destroy the integrator.
78     * <p>
79     * This method releases the memory associated with the DrudeIntegrator object.
80     * After calling this method, the integrator should not be used.
81     */
82    @Override
83    public void destroy() {
84      if (pointer != null) {
85        OpenMM_DrudeIntegrator_destroy(pointer);
86        pointer = null;
87      }
88    }
89  
90    /**
91     * Get the temperature of the heat bath applied to internal coordinates of Drude particles (in Kelvin).
92     *
93     * @return the temperature of the heat bath, measured in Kelvin
94     */
95    public double getDrudeTemperature() {
96      return OpenMM_DrudeIntegrator_getDrudeTemperature(pointer);
97    }
98  
99    /**
100    * Get the maximum distance a Drude particle can ever move from its parent particle, measured in nm.  This is implemented
101    * with a hard wall constraint.  The default value is 0.02.  If this distance is set to 0, the hard wall constraint is omitted.
102    */
103   public double getMaxDrudeDistance() {
104     return OpenMM_DrudeIntegrator_getMaxDrudeDistance(pointer);
105   }
106 
107   /**
108    * Get the random number seed.  See setRandomNumberSeed() for details.
109    */
110   public int getRandomNumberSeed() {
111     return OpenMM_DrudeIntegrator_getRandomNumberSeed(pointer);
112   }
113 
114   /**
115    * Set the temperature of the heat bath applied to internal coordinates of Drude particles (in Kelvin).
116    *
117    * @param temperature the temperature of the heat bath, measured in Kelvin
118    */
119   public void setDrudeTemperature(double temperature) {
120     OpenMM_DrudeIntegrator_setDrudeTemperature(pointer, temperature);
121   }
122 
123   /**
124    * Set the maximum distance a Drude particle can ever move from its parent particle, measured in nm.  This is implemented
125    * with a hard wall constraint.  The default value is 0.02.  If this distance is set to 0, the hard wall constraint is omitted.
126    */
127   public void setMaxDrudeDistance(double distance) {
128     OpenMM_DrudeIntegrator_setMaxDrudeDistance(pointer, distance);
129   }
130 
131   /**
132    * Set the random number seed.  The precise meaning of this parameter is undefined, and is left up
133    * to each Platform to interpret in an appropriate way.  It is guaranteed that if two simulations
134    * are run with different random number seeds, the sequence of random forces will be different.  On
135    * the other hand, no guarantees are made about the behavior of simulations that use the same seed.
136    * In particular, Platforms are permitted to use non-deterministic algorithms which produce different
137    * results on successive runs, even if those runs were initialized identically.
138    * <p>
139    * If seed is set to 0 (which is the default value assigned), a unique seed is chosen when a Context
140    * is created from this Force. This is done to ensure that each Context receives unique random seeds
141    * without you needing to set them explicitly.
142    */
143   public void setRandomNumberSeed(int seed) {
144     OpenMM_DrudeIntegrator_setRandomNumberSeed(pointer, seed);
145   }
146 
147   /**
148    * Advance a simulation through time by taking a series of time steps.
149    *
150    * @param steps the number of time steps to take
151    */
152   @Override
153   public void step(int steps) {
154     OpenMM_DrudeIntegrator_step(pointer, steps);
155   }
156 }