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 ffx.algorithms.AlgorithmListener;
41 import ffx.algorithms.dynamics.MDEngine;
42 import ffx.algorithms.dynamics.MolecularDynamics;
43 import ffx.algorithms.dynamics.integrators.Integrator;
44 import ffx.algorithms.dynamics.integrators.IntegratorEnum;
45 import ffx.algorithms.dynamics.thermostats.Thermostat;
46 import ffx.algorithms.dynamics.thermostats.ThermostatEnum;
47 import ffx.numerics.Potential;
48 import ffx.potential.MolecularAssembly;
49 import ffx.potential.cli.WriteoutOptions;
50 import ffx.utilities.Constants;
51 import picocli.CommandLine.ArgGroup;
52 import picocli.CommandLine.Option;
53
54 import javax.annotation.Nullable;
55 import java.util.logging.Logger;
56
57
58
59
60
61
62
63
64 public class DynamicsOptions {
65
66 private static final Logger logger = Logger.getLogger(DynamicsOptions.class.getName());
67
68
69
70 public ThermostatEnum thermostat;
71
72
73
74 public IntegratorEnum integrator;
75
76
77
78
79 @ArgGroup(heading = "%n Dynamics Options%n", validate = false)
80 private final DynamicsOptionGroup group = new DynamicsOptionGroup();
81 private MDEngine engine = null;
82
83
84
85
86
87
88 public double getCheckpoint() {
89 return group.checkpoint;
90 }
91
92
93
94
95
96
97
98 public int getCheckpointFrequency(int defaultFrequency) {
99 if (group.checkpoint > getDtPsec()) {
100 return (int) (group.checkpoint / getDtPsec());
101 }
102 return defaultFrequency;
103 }
104
105 public void setCheckpoint(double checkpoint) {
106 group.checkpoint = checkpoint;
107 }
108
109
110
111
112
113
114
115 public double getDt() {
116 return group.dt;
117 }
118
119 public double getDtPsec() {
120 return group.dt * Constants.FSEC_TO_PSEC;
121 }
122
123 public void setDt(double dt) {
124 group.dt = dt;
125 }
126
127
128
129
130
131
132
133
134
135
136 public MolecularDynamics getDynamics(WriteoutOptions writeoutOptions, Potential potential,
137 MolecularAssembly activeAssembly, AlgorithmListener algorithmListener) {
138 return getDynamics(writeoutOptions, potential, activeAssembly, algorithmListener, engine);
139 }
140
141
142
143
144
145
146
147
148
149
150
151 public MolecularDynamics getDynamics(WriteoutOptions writeoutOptions, Potential potential,
152 MolecularAssembly activeAssembly, AlgorithmListener algorithmListener,
153 @Nullable MDEngine requestedEngine) {
154 MolecularDynamics molDyn;
155
156 if (requestedEngine == null) {
157 molDyn = MolecularDynamics.dynamicsFactory(activeAssembly, potential, algorithmListener,
158 thermostat, integrator);
159 } else {
160 molDyn = MolecularDynamics.dynamicsFactory(activeAssembly, potential, algorithmListener,
161 thermostat, integrator, requestedEngine);
162 }
163 molDyn.setFileType(writeoutOptions.getFileType());
164 molDyn.setRestartFrequency(group.checkpoint);
165 molDyn.setIntervalSteps(group.trajSteps);
166
167 return molDyn;
168 }
169
170 public long getNumSteps() {
171 return group.steps;
172 }
173
174
175
176
177
178
179 public boolean getOptimize() {
180 return group.optimize;
181 }
182
183
184
185
186
187
188 public double getReport() {
189 return group.report;
190 }
191
192
193
194
195
196
197
198 public int getReportFrequency(int defaultFrequency) {
199 if (group.report > getDtPsec()) {
200 return (int) (group.report / getDtPsec());
201 }
202 return defaultFrequency;
203 }
204
205 public void setReport(double report) {
206 group.report = report;
207 }
208
209
210
211
212
213
214 public double getSnapshotInterval() {
215 return group.write;
216 }
217
218
219
220
221
222
223 public double getTemperature() {
224 return group.temperature;
225 }
226
227 public void setTemperature(double temperature) {
228 group.temperature = temperature;
229 }
230
231
232
233
234 public void init() {
235 thermostat = Thermostat.parseThermostat(group.thermostatString);
236 integrator = Integrator.parseIntegrator(group.integratorString);
237 if (group.engineString != null) {
238 try {
239 engine = MDEngine.valueOf(group.engineString.toUpperCase());
240 } catch (Exception ex) {
241 logger.warning(String.format(
242 " Could not parse %s as a valid dynamics engine! Defaulting to the Platform-recommended engine.",
243 group.engineString));
244 engine = null;
245 }
246 }
247 }
248
249
250
251
252
253
254 public String getThermostatString() {
255 return group.thermostatString;
256 }
257
258
259
260
261
262
263 public void setThermostat(ThermostatEnum thermostat) {
264 this.thermostat = thermostat;
265 }
266
267
268
269
270
271
272 public void setIntegrator(IntegratorEnum integrator) {
273 this.integrator = integrator;
274 }
275
276 public void setThermostatString(String thermostatString) {
277 group.thermostatString = thermostatString;
278 }
279
280
281
282
283
284
285 public String getIntegratorString() {
286 return group.integratorString;
287 }
288
289 public void setIntegratorString(String integratorString) {
290 group.integratorString = integratorString;
291 }
292
293
294
295
296
297
298 public double getWrite() {
299 return group.write;
300 }
301
302 public void setWrite(double write) {
303 group.write = write;
304 }
305
306
307
308
309
310
311 public long getSteps() {
312 return group.steps;
313 }
314
315 public void setSteps(long steps) {
316 group.steps = steps;
317 }
318
319
320
321
322
323
324 public int getTrajSteps() {
325 return group.trajSteps;
326 }
327
328 public void setTrajSteps(int trajSteps) {
329 group.trajSteps = trajSteps;
330 }
331
332
333
334
335
336
337 public boolean isOptimize() {
338 return group.optimize;
339 }
340
341 public void setOptimize(boolean optimize) {
342 group.optimize = optimize;
343 }
344
345
346
347
348
349
350 public String getEngineString() {
351 return group.engineString;
352 }
353
354 public void setEngineString(String engineString) {
355 group.engineString = engineString;
356 }
357
358
359
360
361 private static class DynamicsOptionGroup {
362
363
364
365
366
367 @Option(names = {"-d", "--dt"}, paramLabel = "1.0", defaultValue = "1.0",
368 description = "Time discretization step in femtoseconds.")
369 private double dt = 1.0;
370
371
372
373
374
375 @Option(names = {"-b", "--thermostat"}, paramLabel = "Bussi", defaultValue = "Bussi",
376 description = "Thermostat: [Adiabatic / Berendsen / Bussi].")
377 private String thermostatString = "Bussi";
378
379
380
381
382
383 @Option(names = {"-i", "--integrator"}, paramLabel = "Verlet", defaultValue = "Verlet",
384 description = "Integrator: [Beeman / Respa / Stochastic / Verlet].")
385 private String integratorString = "Verlet";
386
387
388
389
390 @Option(names = {"-r", "--report"}, paramLabel = "0.25", defaultValue = "0.25",
391 description = "Interval in psec to report thermodynamics (psec).")
392 private double report = 0.25;
393
394
395
396
397 @Option(names = {"-w", "--write"}, paramLabel = "10.0", defaultValue = "10.0",
398 description = "Interval in psec to write out coordinates (psec).")
399 private double write = 10.0;
400
401
402
403
404 @Option(names = {"-t", "--temperature"}, paramLabel = "298.15", defaultValue = "298.15",
405 description = "Temperature (Kelvin).")
406 private double temperature = 298.15;
407
408
409
410
411 @Option(names = {"-n", "--numberOfSteps"}, paramLabel = "1000000", defaultValue = "1000000",
412 description = "Number of molecular dynamics steps.")
413 private long steps = 1000000;
414
415
416
417
418 @Option(names = {"-z", "--trajSteps"}, paramLabel = "100", defaultValue = "100",
419 description = "Number of steps per MD cycle (--mdE = OpenMM only).")
420 private int trajSteps = 100;
421
422
423
424
425 @Option(names = {"-o", "--optimize"}, defaultValue = "false",
426 description = "Optimize and save low-energy snapshots.")
427 private boolean optimize = false;
428
429
430
431
432 @Option(names = {"-k", "--checkpoint"}, paramLabel = "1.0", defaultValue = "1.0",
433 description = "Interval in psec to write out restart files (.dyn, .his, etc).")
434 private double checkpoint = 1.0;
435
436
437
438
439
440 @Option(names = {"--mdE", "--molecularDynamicsEngine"}, paramLabel = "FFX",
441 description = "Use FFX or OpenMM to integrate dynamics.")
442 private String engineString = "FFX";
443 }
444 }