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 edu.uiowa.jopenmm.OpenMM_Vec3;
41
42 import static edu.uiowa.jopenmm.OpenMMLibrary.OpenMM_Boolean.OpenMM_True;
43 import static edu.uiowa.jopenmm.OpenMMLibrary.OpenMM_MonteCarloAnisotropicBarostat_create;
44 import static edu.uiowa.jopenmm.OpenMMLibrary.OpenMM_MonteCarloAnisotropicBarostat_destroy;
45 import static edu.uiowa.jopenmm.OpenMMLibrary.OpenMM_MonteCarloAnisotropicBarostat_getDefaultPressure;
46 import static edu.uiowa.jopenmm.OpenMMLibrary.OpenMM_MonteCarloAnisotropicBarostat_getDefaultTemperature;
47 import static edu.uiowa.jopenmm.OpenMMLibrary.OpenMM_MonteCarloAnisotropicBarostat_getFrequency;
48 import static edu.uiowa.jopenmm.OpenMMLibrary.OpenMM_MonteCarloAnisotropicBarostat_getRandomNumberSeed;
49 import static edu.uiowa.jopenmm.OpenMMLibrary.OpenMM_MonteCarloAnisotropicBarostat_getScaleX;
50 import static edu.uiowa.jopenmm.OpenMMLibrary.OpenMM_MonteCarloAnisotropicBarostat_getScaleY;
51 import static edu.uiowa.jopenmm.OpenMMLibrary.OpenMM_MonteCarloAnisotropicBarostat_getScaleZ;
52 import static edu.uiowa.jopenmm.OpenMMLibrary.OpenMM_MonteCarloAnisotropicBarostat_setDefaultPressure;
53 import static edu.uiowa.jopenmm.OpenMMLibrary.OpenMM_MonteCarloAnisotropicBarostat_setDefaultTemperature;
54 import static edu.uiowa.jopenmm.OpenMMLibrary.OpenMM_MonteCarloAnisotropicBarostat_setFrequency;
55 import static edu.uiowa.jopenmm.OpenMMLibrary.OpenMM_MonteCarloAnisotropicBarostat_setRandomNumberSeed;
56 import static edu.uiowa.jopenmm.OpenMMLibrary.OpenMM_MonteCarloAnisotropicBarostat_usesPeriodicBoundaryConditions;
57
58 /**
59 * This class uses a Monte Carlo algorithm to adjust the size of the periodic box,
60 * simulating the effect of constant pressure. It assumes the simulation is running
61 * at constant temperature, and the box size is adjusted to maintain constant pressure.
62 * Unlike MonteCarloBarostat, this version allows independent scaling of the three
63 * box dimensions, making it suitable for anisotropic systems.
64 * <p>
65 * This class is most useful for simulating a system at constant pressure when
66 * anisotropic scaling is desired, such as for layered materials or systems with
67 * preferred orientations.
68 */
69 public class MonteCarloAnisotropicBarostat extends Force {
70
71 /**
72 * Create a MonteCarloAnisotropicBarostat.
73 *
74 * @param defaultPressure The default pressure acting on each axis (in bar).
75 * @param defaultTemperature The default temperature at which the system is being maintained (in Kelvin).
76 * @param scaleX Whether to scale the X dimension of the periodic box.
77 * @param scaleY Whether to scale the Y dimension of the periodic box.
78 * @param scaleZ Whether to scale the Z dimension of the periodic box.
79 * @param frequency The frequency at which Monte Carlo pressure changes should be attempted (in time steps).
80 */
81 public MonteCarloAnisotropicBarostat(OpenMM_Vec3 defaultPressure, double defaultTemperature,
82 int scaleX, int scaleY, int scaleZ, int frequency) {
83 super(OpenMM_MonteCarloAnisotropicBarostat_create(defaultPressure, defaultTemperature, scaleX, scaleY, scaleZ, frequency));
84 }
85
86 /**
87 * Destroy the force.
88 */
89 @Override
90 public void destroy() {
91 if (pointer != null) {
92 OpenMM_MonteCarloAnisotropicBarostat_destroy(pointer);
93 pointer = null;
94 }
95 }
96
97 /**
98 * Get the default pressure (in bar).
99 *
100 * @return The default pressure acting on each axis.
101 */
102 public OpenMM_Vec3 getDefaultPressure() {
103 return OpenMM_MonteCarloAnisotropicBarostat_getDefaultPressure(pointer);
104 }
105
106 /**
107 * Get the default temperature at which the system is being maintained (in Kelvin).
108 *
109 * @return The default temperature.
110 */
111 public double getDefaultTemperature() {
112 return OpenMM_MonteCarloAnisotropicBarostat_getDefaultTemperature(pointer);
113 }
114
115 /**
116 * Get the frequency (in time steps) at which Monte Carlo pressure changes should be attempted.
117 *
118 * @return The frequency of pressure change attempts.
119 */
120 public int getFrequency() {
121 return OpenMM_MonteCarloAnisotropicBarostat_getFrequency(pointer);
122 }
123
124 /**
125 * Get the random number seed. See setRandomNumberSeed() for details.
126 *
127 * @return The random number seed.
128 */
129 public int getRandomNumberSeed() {
130 return OpenMM_MonteCarloAnisotropicBarostat_getRandomNumberSeed(pointer);
131 }
132
133 /**
134 * Get whether to scale the X dimension of the periodic box.
135 *
136 * @return 1 if the X dimension should be scaled, 0 otherwise.
137 */
138 public int getScaleX() {
139 return OpenMM_MonteCarloAnisotropicBarostat_getScaleX(pointer);
140 }
141
142 /**
143 * Get whether to scale the Y dimension of the periodic box.
144 *
145 * @return 1 if the Y dimension should be scaled, 0 otherwise.
146 */
147 public int getScaleY() {
148 return OpenMM_MonteCarloAnisotropicBarostat_getScaleY(pointer);
149 }
150
151 /**
152 * Get whether to scale the Z dimension of the periodic box.
153 *
154 * @return 1 if the Z dimension should be scaled, 0 otherwise.
155 */
156 public int getScaleZ() {
157 return OpenMM_MonteCarloAnisotropicBarostat_getScaleZ(pointer);
158 }
159
160 /**
161 * Set the default pressure acting on each axis (in bar).
162 *
163 * @param pressure The default pressure acting on each axis.
164 */
165 public void setDefaultPressure(OpenMM_Vec3 pressure) {
166 OpenMM_MonteCarloAnisotropicBarostat_setDefaultPressure(pointer, pressure);
167 }
168
169 /**
170 * Set the default temperature at which the system is being maintained (in Kelvin).
171 *
172 * @param temperature The default temperature.
173 */
174 public void setDefaultTemperature(double temperature) {
175 OpenMM_MonteCarloAnisotropicBarostat_setDefaultTemperature(pointer, temperature);
176 }
177
178 /**
179 * Set the frequency (in time steps) at which Monte Carlo pressure changes should be attempted.
180 *
181 * @param frequency The frequency of pressure change attempts.
182 */
183 public void setFrequency(int frequency) {
184 OpenMM_MonteCarloAnisotropicBarostat_setFrequency(pointer, frequency);
185 }
186
187 /**
188 * Set the random number seed. The precise meaning of this parameter is undefined, and is left up
189 * to each Platform to interpret in an appropriate way. It is guaranteed that if two simulations
190 * are run with different random number seeds, the sequence of random numbers will be different.
191 * On the other hand, no guarantees are made about the behavior of simulations that use the same seed.
192 * In particular, Platforms are permitted to use non-deterministic algorithms which produce different
193 * results on successive runs, even if those runs were initialized identically.
194 * <p>
195 * If seed is set to 0 (which is the default value assigned), a unique seed is chosen when a Context
196 * is created from this Force. This is done to ensure that each Context receives unique random seeds
197 * without you needing to set them explicitly.
198 *
199 * @param seed The random number seed.
200 */
201 public void setRandomNumberSeed(int seed) {
202 OpenMM_MonteCarloAnisotropicBarostat_setRandomNumberSeed(pointer, seed);
203 }
204
205 /**
206 * Returns whether this force makes use of periodic boundary conditions.
207 *
208 * @return True if the force uses periodic boundary conditions.
209 */
210 @Override
211 public boolean usesPeriodicBoundaryConditions() {
212 int pbc = OpenMM_MonteCarloAnisotropicBarostat_usesPeriodicBoundaryConditions(pointer);
213 return pbc == OpenMM_True;
214 }
215 }