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_BrownianIntegrator_create;
41 import static edu.uiowa.jopenmm.OpenMMLibrary.OpenMM_BrownianIntegrator_destroy;
42 import static edu.uiowa.jopenmm.OpenMMLibrary.OpenMM_BrownianIntegrator_getFriction;
43 import static edu.uiowa.jopenmm.OpenMMLibrary.OpenMM_BrownianIntegrator_getRandomNumberSeed;
44 import static edu.uiowa.jopenmm.OpenMMLibrary.OpenMM_BrownianIntegrator_getTemperature;
45 import static edu.uiowa.jopenmm.OpenMMLibrary.OpenMM_BrownianIntegrator_setFriction;
46 import static edu.uiowa.jopenmm.OpenMMLibrary.OpenMM_BrownianIntegrator_setRandomNumberSeed;
47 import static edu.uiowa.jopenmm.OpenMMLibrary.OpenMM_BrownianIntegrator_setTemperature;
48 import static edu.uiowa.jopenmm.OpenMMLibrary.OpenMM_BrownianIntegrator_step;
49
50 /**
51 * This is an Integrator which simulates a System using Brownian dynamics.
52 */
53 public class BrownianIntegrator extends Integrator {
54
55 /**
56 * Create a BrownianIntegrator.
57 *
58 * @param temperature the temperature of the heat bath (in Kelvin)
59 * @param frictionCoeff the friction coefficient which couples the system to the heat bath, measured in 1/ps
60 * @param stepSize the step size with which to integrate the system (in picoseconds)
61 */
62 public BrownianIntegrator(double temperature, double frictionCoeff, double stepSize) {
63 super(OpenMM_BrownianIntegrator_create(temperature, frictionCoeff, stepSize));
64 }
65
66 /**
67 * Destroy the integrator.
68 */
69 @Override
70 public void destroy() {
71 if (pointer != null) {
72 OpenMM_BrownianIntegrator_destroy(pointer);
73 pointer = null;
74 }
75 }
76
77 /**
78 * Get the friction coefficient which determines how strongly the system is coupled to
79 * the heat bath (in inverse ps).
80 *
81 * @return the friction coefficient, measured in 1/ps
82 */
83 public double getFriction() {
84 return OpenMM_BrownianIntegrator_getFriction(pointer);
85 }
86
87 /**
88 * Get the random number seed. See setRandomNumberSeed() for details.
89 */
90 public int getRandomNumberSeed() {
91 return OpenMM_BrownianIntegrator_getRandomNumberSeed(pointer);
92 }
93
94 /**
95 * Get the temperature of the heat bath (in Kelvin).
96 *
97 * @return the temperature of the heat bath (in Kelvin).
98 */
99 public double getTemperature() {
100 return OpenMM_BrownianIntegrator_getTemperature(pointer);
101 }
102
103 /**
104 * Set the friction coefficient which determines how strongly the system is coupled to
105 * the heat bath (in inverse ps).
106 *
107 * @param coeff the friction coefficient, measured in 1/ps
108 */
109 public void setFriction(double coeff) {
110 OpenMM_BrownianIntegrator_setFriction(pointer, coeff);
111 }
112
113 /**
114 * Set the random number seed. The precise meaning of this parameter is undefined, and is left up
115 * to each Platform to interpret in an appropriate way. It is guaranteed that if two simulations
116 * are run with different random number seeds, the sequence of random forces will be different. On
117 * the other hand, no guarantees are made about the behavior of simulations that use the same seed.
118 * In particular, Platforms are permitted to use non-deterministic algorithms which produce different
119 * results on successive runs, even if those runs were initialized identically.
120 * <p>
121 * If seed is set to 0 (which is the default value assigned), a unique seed is chosen when a Context
122 * is created from this Force. This is done to ensure that each Context receives unique random seeds
123 * without you needing to set them explicitly.
124 */
125 public void setRandomNumberSeed(int seed) {
126 OpenMM_BrownianIntegrator_setRandomNumberSeed(pointer, seed);
127 }
128
129 /**
130 * Set the temperature of the heat bath (in Kelvin).
131 *
132 * @param temp the temperature of the heat bath, measured in Kelvin.
133 */
134 public void setTemperature(double temp) {
135 OpenMM_BrownianIntegrator_setTemperature(pointer, temp);
136 }
137
138 /**
139 * Advance a simulation through time by taking a series of time steps.
140 *
141 * @param steps the number of time steps to take
142 */
143 public void step(int steps) {
144 OpenMM_BrownianIntegrator_step(pointer, steps);
145 }
146 }