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 static edu.uiowa.jopenmm.OpenMMDrudeLibrary.OpenMM_DrudeLangevinIntegrator_computeDrudeTemperature;
41 import static edu.uiowa.jopenmm.OpenMMDrudeLibrary.OpenMM_DrudeLangevinIntegrator_computeSystemTemperature;
42 import static edu.uiowa.jopenmm.OpenMMDrudeLibrary.OpenMM_DrudeLangevinIntegrator_create;
43 import static edu.uiowa.jopenmm.OpenMMDrudeLibrary.OpenMM_DrudeLangevinIntegrator_destroy;
44 import static edu.uiowa.jopenmm.OpenMMDrudeLibrary.OpenMM_DrudeLangevinIntegrator_getDrudeFriction;
45 import static edu.uiowa.jopenmm.OpenMMDrudeLibrary.OpenMM_DrudeLangevinIntegrator_getFriction;
46 import static edu.uiowa.jopenmm.OpenMMDrudeLibrary.OpenMM_DrudeLangevinIntegrator_getTemperature;
47 import static edu.uiowa.jopenmm.OpenMMDrudeLibrary.OpenMM_DrudeLangevinIntegrator_setDrudeFriction;
48 import static edu.uiowa.jopenmm.OpenMMDrudeLibrary.OpenMM_DrudeLangevinIntegrator_setFriction;
49 import static edu.uiowa.jopenmm.OpenMMDrudeLibrary.OpenMM_DrudeLangevinIntegrator_setTemperature;
50 import static edu.uiowa.jopenmm.OpenMMDrudeLibrary.OpenMM_DrudeLangevinIntegrator_step;
51
52 /**
53 * This Integrator simulates systems that include Drude particles. It applies two different Langevin
54 * thermostats to different parts of the system. The first is applied to ordinary particles (ones that
55 * are not part of a Drude particle pair), as well as to the center of mass of each Drude particle pair.
56 * A second thermostat, typically with a much lower temperature, is applied to the relative internal
57 * displacement of each pair.
58 * <p>
59 * This integrator can optionally set an upper limit on how far any Drude particle is ever allowed to
60 * get from its parent particle. This can sometimes help to improve stability. The limit is enforced
61 * with a hard wall constraint. By default the limit is set to 0.02 nm.
62 * <p>
63 * This Integrator requires the System to include a DrudeForce, which it uses to identify the Drude
64 * particles.
65 */
66 public class DrudeLangevinIntegrator extends DrudeIntegrator {
67
68 /**
69 * Create a DrudeLangevinIntegrator.
70 *
71 * @param stepSize the step size with which to integrator the system (in picoseconds)
72 * @param temperature the temperature of the main heat bath (in Kelvin)
73 * @param friction the friction coefficient which couples the system to the main heat bath (in inverse picoseconds)
74 * @param drudeTemperature the temperature of the heat bath applied to internal coordinates of Drude particles (in Kelvin)
75 * @param drudeFriction the friction coefficient which couples the system to the heat bath applied to internal coordinates of Drude particles (in inverse picoseconds)
76 */
77 public DrudeLangevinIntegrator(double stepSize, double temperature, double friction,
78 double drudeTemperature, double drudeFriction) {
79 super(OpenMM_DrudeLangevinIntegrator_create(stepSize, temperature, friction,
80 drudeTemperature, drudeFriction));
81 }
82
83 /**
84 * Compute the instantaneous temperature of the Drude system, measured in Kelvin.
85 * This is calculated based on the kinetic energy of the internal motion of Drude pairs
86 * and should remain close to the prescribed Drude temperature.
87 */
88 public double computeDrudeTemperature() {
89 return OpenMM_DrudeLangevinIntegrator_computeDrudeTemperature(pointer);
90 }
91
92 /**
93 * Compute the instantaneous temperature of the System, measured in Kelvin.
94 * This is calculated based on the kinetic energy of the ordinary particles (ones
95 * not attached to a Drude particle), as well as the center of mass motion of the
96 * Drude particle pairs. It does not include the internal motion of the pairs.
97 * On average, this should be approximately equal to the value returned by
98 * getTemperature().
99 */
100 public double computeSystemTemperature() {
101 return OpenMM_DrudeLangevinIntegrator_computeSystemTemperature(pointer);
102 }
103
104 /**
105 * Destroy the integrator.
106 * <p>
107 * This method releases the memory associated with the DrudeLangevinIntegrator object.
108 * After calling this method, the integrator should not be used.
109 */
110 @Override
111 public void destroy() {
112 if (pointer != null) {
113 OpenMM_DrudeLangevinIntegrator_destroy(pointer);
114 pointer = null;
115 }
116 }
117
118 /**
119 * Get the friction coefficient which determines how strongly the internal coordinates of Drude particles
120 * are coupled to the heat bath (in inverse ps).
121 *
122 * @return the friction coefficient, measured in 1/ps
123 */
124 public double getDrudeFriction() {
125 return OpenMM_DrudeLangevinIntegrator_getDrudeFriction(pointer);
126 }
127
128 /**
129 * Get the friction coefficient which determines how strongly the system is coupled to
130 * the main heat bath (in inverse ps).
131 *
132 * @return the friction coefficient, measured in 1/ps
133 */
134 public double getFriction() {
135 return OpenMM_DrudeLangevinIntegrator_getFriction(pointer);
136 }
137
138 /**
139 * Get the temperature of the main heat bath (in Kelvin).
140 *
141 * @return the temperature of the heat bath, measured in Kelvin
142 */
143 public double getTemperature() {
144 return OpenMM_DrudeLangevinIntegrator_getTemperature(pointer);
145 }
146
147 /**
148 * Set the friction coefficient which determines how strongly the internal coordinates of Drude particles
149 * are coupled to the heat bath (in inverse ps).
150 *
151 * @param friction the friction coefficient, measured in 1/ps
152 */
153 public void setDrudeFriction(double friction) {
154 OpenMM_DrudeLangevinIntegrator_setDrudeFriction(pointer, friction);
155 }
156
157 /**
158 * Set the friction coefficient which determines how strongly the system is coupled to
159 * the main heat bath (in inverse ps).
160 *
161 * @param friction the friction coefficient, measured in 1/ps
162 */
163 public void setFriction(double friction) {
164 OpenMM_DrudeLangevinIntegrator_setFriction(pointer, friction);
165 }
166
167 /**
168 * Set the temperature of the main heat bath (in Kelvin).
169 *
170 * @param temperature the temperature of the heat bath, measured in Kelvin
171 */
172 public void setTemperature(double temperature) {
173 OpenMM_DrudeLangevinIntegrator_setTemperature(pointer, temperature);
174 }
175
176 /**
177 * Advance a simulation through time by taking a series of time steps.
178 *
179 * @param steps the number of time steps to take
180 */
181 @Override
182 public void step(int steps) {
183 OpenMM_DrudeLangevinIntegrator_step(pointer, steps);
184 }
185 }