1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38 package ffx.algorithms.cli;
39
40 import static java.lang.Double.parseDouble;
41 import static java.lang.Integer.parseInt;
42 import static java.lang.String.format;
43
44 import ffx.algorithms.dynamics.Barostat;
45 import ffx.crystal.CrystalPotential;
46 import ffx.potential.MolecularAssembly;
47
48 import java.util.logging.Logger;
49
50 import picocli.CommandLine.ArgGroup;
51 import picocli.CommandLine.Option;
52
53
54
55
56
57
58
59
60 public class BarostatOptions {
61
62
63
64
65
66 public static final String DEFAULT_MAX_DENSITY = "1.6";
67
68
69
70
71 public static final String DEFAULT_MIN_DENSITY = "0.75";
72
73
74
75 public static final String DEFAULT_MAX_ANGLE_MOVE = "0.5";
76
77
78
79 public static final String DEFAULT_MAX_VOLUME_MOVE = "1.0";
80
81
82
83 public static final String DEFAULT_BAROSTAT_INTERVAL = "10";
84
85
86
87 public static final String DEFAULT_BAROSTAT_PRINT_INTERVAL = "1000";
88
89 private static final Logger logger = Logger.getLogger(BarostatOptions.class.getName());
90
91
92
93
94 @ArgGroup(heading = "%n Monte Carlo Pressure Options%n", validate = false)
95 private final BarostatOptionGroup group = new BarostatOptionGroup();
96
97
98
99
100
101
102
103
104
105 public CrystalPotential checkNPT(MolecularAssembly molecularAssembly,
106 CrystalPotential crystalPotential) {
107 if (group.pressure > 0) {
108 return createBarostat(molecularAssembly, crystalPotential);
109 } else {
110 return crystalPotential;
111 }
112 }
113
114
115
116
117
118
119
120
121
122 public Barostat createBarostat(MolecularAssembly assembly, CrystalPotential crystalPotential)
123 throws IllegalArgumentException {
124 if (group.pressure > 0) {
125 Barostat barostat = new Barostat(assembly, crystalPotential);
126 barostat.setPressure(group.pressure);
127 barostat.setIsotropic(group.isotropic);
128 barostat.setMaxDensity(group.maxD);
129 barostat.setMinDensity(group.minD);
130 barostat.setBarostatPrintFrequency(group.barPrint);
131 double dens = barostat.density();
132 if (dens < group.minD) {
133 logger.info(format(
134 " Barostat: initial density %9.4g < minimum density %9.4g, resetting to minimum density",
135 dens, group.minD));
136 barostat.setDensity(group.minD);
137 } else if (dens > group.maxD) {
138 logger.info(format(
139 " Barostat: initial density %9.4g > maximum density %9.4g, resetting to maximum density",
140 dens, group.maxD));
141 barostat.setDensity(group.maxD);
142 }
143 barostat.setMaxAngleMove(group.maxAM);
144 barostat.setMaxVolumeMove(group.maxV);
145 barostat.setMeanBarostatInterval(group.barInt);
146 return barostat;
147 } else {
148 throw new IllegalArgumentException(" Pressure is <= 0; cannot create a Barostat!");
149 }
150 }
151
152
153
154
155
156
157
158 public double getPressure() {
159 return group.pressure;
160 }
161
162 public void setPressure(double pressure) {
163 group.pressure = pressure;
164 }
165
166
167
168
169
170
171
172 public boolean isIsotropic() {
173 return group.isotropic;
174 }
175
176 public void setIsotropic(boolean isotropic) {
177 group.isotropic = isotropic;
178 }
179
180
181
182
183
184
185 public double getMaxD() {
186 return group.maxD;
187 }
188
189 public void setMaxD(double maxD) {
190 group.maxD = maxD;
191 }
192
193
194
195
196
197
198 public double getMinD() {
199 return group.minD;
200 }
201
202 public void setMinD(double minD) {
203 group.minD = minD;
204 }
205
206
207
208
209
210
211 public double getMaxV() {
212 return group.maxV;
213 }
214
215
216
217
218
219
220 public double getMaxAM() {
221 return group.maxAM;
222 }
223
224 public void setMaxAM(double maxAM) {
225 group.maxAM = maxAM;
226 }
227
228 public void setMaxV(double maxV) {
229 group.maxV = maxV;
230 }
231
232
233
234
235
236
237 public int getBarInt() {
238 return group.barInt;
239 }
240
241 public void setBarInt(int barInt) {
242 group.barInt = barInt;
243 }
244
245
246
247
248
249 public int getPrintInt() {
250 return group.barPrint;
251 }
252
253 public void setPrintInt(int printInterval) {
254 group.barPrint = printInterval;
255 }
256
257
258
259
260 private static class BarostatOptionGroup {
261
262
263
264
265
266 @Option(names = {"-p", "--npt"}, paramLabel = "0", defaultValue = "0",
267 description = "Specify use of a MC Barostat at the given pressure; the default 0 disables NPT (atm).")
268 private double pressure = 0;
269
270
271
272
273 @Option(names = {"--iso", "--isotropic"},
274 defaultValue = "false", description = "Restrict the MC Barostat to isotropic moves.")
275 private boolean isotropic = false;
276
277
278
279 @Option(names = {"--maxD", " --maxDensity"},
280 paramLabel = DEFAULT_MAX_DENSITY, defaultValue = DEFAULT_MAX_DENSITY,
281 description = "Specify the maximum density accepted by the MC Barostat (g/cc).")
282 private double maxD = parseDouble(DEFAULT_MAX_DENSITY);
283
284
285
286 @Option(names = {"--minD", " --minDensity"},
287 paramLabel = DEFAULT_MIN_DENSITY, defaultValue = DEFAULT_MIN_DENSITY,
288 description = "Specify the minimum density accepted by the MC Barostat (g/cc).")
289 private double minD = parseDouble(DEFAULT_MIN_DENSITY);
290 @Option(names = {"--maxAM", "--maxAngleMove"},
291 paramLabel = DEFAULT_MAX_ANGLE_MOVE, defaultValue = DEFAULT_MAX_ANGLE_MOVE,
292 description = "Sets the width of proposed crystal angle moves (uniformly distributed) in degrees.")
293 private double maxAM = parseDouble(DEFAULT_MAX_ANGLE_MOVE);
294
295
296
297 @Option(names = {"--maxV", "--maxVolumeMove"},
298 paramLabel = DEFAULT_MAX_VOLUME_MOVE, defaultValue = DEFAULT_MAX_VOLUME_MOVE,
299 description = "Default width of proposed unit cell side length moves (uniformly distributed) in Angstroms.")
300 private double maxV = parseDouble(DEFAULT_MAX_VOLUME_MOVE);
301
302
303
304
305
306 @Option(names = {"--barInt", "--meanBarostatInterval"},
307 paramLabel = DEFAULT_BAROSTAT_INTERVAL, defaultValue = DEFAULT_BAROSTAT_INTERVAL,
308 description = "Sets the mean number of MD steps between barostat move proposals.")
309 private int barInt = parseInt(DEFAULT_BAROSTAT_INTERVAL);
310
311
312
313
314 @Option(names = {"--bpi", "--barostatPrintInterval"},
315 paramLabel = DEFAULT_BAROSTAT_PRINT_INTERVAL, defaultValue = DEFAULT_BAROSTAT_PRINT_INTERVAL,
316 description = "Sets the number of Barostat MC cycles between print statements.")
317 private int barPrint = parseInt(DEFAULT_BAROSTAT_PRINT_INTERVAL);
318 }
319 }