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;
39  
40  import static edu.uiowa.jopenmm.OpenMMLibrary.OpenMM_AndersenThermostat_create;
41  import static edu.uiowa.jopenmm.OpenMMLibrary.OpenMM_AndersenThermostat_destroy;
42  import static edu.uiowa.jopenmm.OpenMMLibrary.OpenMM_AndersenThermostat_getDefaultCollisionFrequency;
43  import static edu.uiowa.jopenmm.OpenMMLibrary.OpenMM_AndersenThermostat_getDefaultTemperature;
44  import static edu.uiowa.jopenmm.OpenMMLibrary.OpenMM_AndersenThermostat_getRandomNumberSeed;
45  import static edu.uiowa.jopenmm.OpenMMLibrary.OpenMM_AndersenThermostat_setDefaultCollisionFrequency;
46  import static edu.uiowa.jopenmm.OpenMMLibrary.OpenMM_AndersenThermostat_setDefaultTemperature;
47  import static edu.uiowa.jopenmm.OpenMMLibrary.OpenMM_AndersenThermostat_setRandomNumberSeed;
48  import static edu.uiowa.jopenmm.OpenMMLibrary.OpenMM_AndersenThermostat_usesPeriodicBoundaryConditions;
49  import static edu.uiowa.jopenmm.OpenMMLibrary.OpenMM_Boolean.OpenMM_False;
50  
51  /**
52   * This class uses the Andersen method to maintain constant temperature.
53   */
54  public class AndersenThermostat extends Force {
55  
56    /**
57     * Create an AndersenThermostat.
58     *
59     * @param defaultTemperature        the default temperature of the heat bath (in Kelvin)
60     * @param defaultCollisionFrequency the default collision frequency (in 1/ps)
61     */
62    public AndersenThermostat(double defaultTemperature, double defaultCollisionFrequency) {
63      super(OpenMM_AndersenThermostat_create(defaultTemperature, defaultCollisionFrequency));
64    }
65  
66    /**
67     * Destroy the force.
68     */
69    @Override
70    public void destroy() {
71      if (pointer != null) {
72        OpenMM_AndersenThermostat_destroy(pointer);
73        pointer = null;
74      }
75    }
76  
77    /**
78     * Get the default collision frequency (in 1/ps).
79     *
80     * @return the default collision frequency (in 1/ps).
81     */
82    public double getDefaultCollisionFrequency() {
83      return OpenMM_AndersenThermostat_getDefaultCollisionFrequency(pointer);
84    }
85  
86    /**
87     * Get the default temperature of the heat bath (in Kelvin).
88     *
89     * @return the default temperature of the heat bath, measured in Kelvin.
90     */
91    public double getDefaultTemperature() {
92      return OpenMM_AndersenThermostat_getDefaultTemperature(pointer);
93    }
94  
95    /**
96     * Get the random number seed.  See setRandomNumberSeed() for details.
97     */
98    public int getRandomNumberSeed() {
99      return OpenMM_AndersenThermostat_getRandomNumberSeed(pointer);
100   }
101 
102   /**
103    * Set the default collision frequency.  This will affect any new Contexts you create,
104    * but not ones that already exist.
105    *
106    * @param frequency the default collision frequency (in 1/ps)
107    */
108   public void setDefaultCollisionFrequency(double frequency) {
109     OpenMM_AndersenThermostat_setDefaultCollisionFrequency(pointer, frequency);
110   }
111 
112   /**
113    * Set the default temperature of the heat bath.  This will affect any new Contexts you create,
114    * but not ones that already exist.
115    *
116    * @param temperature the default temperature of the heat bath (in Kelvin)
117    */
118   public void setDefaultTemperature(double temperature) {
119     OpenMM_AndersenThermostat_setDefaultTemperature(pointer, temperature);
120   }
121 
122   /**
123    * Set the random number seed.  The precise meaning of this parameter is undefined, and is left up
124    * to each Platform to interpret in an appropriate way.  It is guaranteed that if two simulations
125    * are run with different random number seeds, the sequence of collisions will be different.  On
126    * the other hand, no guarantees are made about the behavior of simulations that use the same seed.
127    * In particular, Platforms are permitted to use non-deterministic algorithms which produce different
128    * results on successive runs, even if those runs were initialized identically.
129    * <p>
130    * If seed is set to 0 (which is the default value assigned), a unique seed is chosen when a Context
131    * is created from this Force. This is done to ensure that each Context receives unique random seeds
132    * without you needing to set them explicitly.
133    *
134    * @param seed the random number seed.
135    */
136   public void setRandomNumberSeed(int seed) {
137     OpenMM_AndersenThermostat_setRandomNumberSeed(pointer, seed);
138   }
139 
140   /**
141    * Returns whether or not this force makes use of periodic boundary
142    * conditions.
143    *
144    * @return true if force uses PBC and false otherwise
145    */
146   @Override
147   public boolean usesPeriodicBoundaryConditions() {
148     int pbc = OpenMM_AndersenThermostat_usesPeriodicBoundaryConditions(pointer);
149     return pbc != OpenMM_False;
150   }
151 }