Debian Codegraph @

avogadro/qtplugins/openmminput/openmminputdialog.cpp

raw
1 /******************************************************************************
2 This source file is part of the Avogadro project.
3 This source code is released under the 3-Clause BSD License, (see "LICENSE").
4 ******************************************************************************/
5
6 #include "openmminputdialog.h"
7
8 #include <avogadro/core/atom.h>
9 #include <avogadro/core/bond.h>
10 #include <avogadro/core/elements.h>
11
12 #include <avogadro/io/fileformat.h>
13 #include <avogadro/io/fileformatmanager.h>
14
15 #include <avogadro/qtgui/molecule.h>
16
17 #include <QtWidgets/QFileDialog>
18 #include <QtWidgets/QMessageBox>
19 #include <QtWidgets/QTextEdit>
20
21 #include <QtCore/QDebug>
22 #include <QtCore/QDir>
23 #include <QtCore/QFile>
24 #include <QtCore/QHash>
25 #include <QtCore/QPointer>
26 #include <QtCore/QString>
27 #include <QtCore/QTextStream>
28
29 namespace Avogadro::QtPlugins {
30
31 OpenMMInputDialog::OpenMMInputDialog(QWidget* parent, Qt::WindowFlags flag)
32 : QDialog(parent, flag), m_molecule(nullptr),
33
34 m_forceFieldType(amber99sbildn), m_title("Title"), m_savePath(""),
35 m_waterModelType(tip3p), m_nonBondedType(PME),
36
37 m_constraintType(HBonds), m_integratorType(Langevin),
38 m_barostatType(NoBarostat),
39
40 m_deviceIndex(1), m_openclPlatformIndex(1), m_rigidWater(0),
41 m_temperature(298.15), m_generationTemperature(298.15),
42 m_nonBondedCutoff(1.0),
43
44 m_timeStep(2.0), m_ewaldTolerance(0.0005), m_constraintTolerance(0.00001),
45 m_reportInterval(1000), m_equilibriationSteps(100), m_productionSteps(1000),
46 m_errorTolerance(0.0001), m_collisionRate(1.0), m_pressure(1.0),
47 m_barostatInterval(25),
48
49 m_dumpStep(1),
50
51 m_velocityDistRandom(0), m_platformType(CUDA),
52 m_precisionType(mixedPrecision), m_thermoInterval(50),
53
54 m_minimize(0), m_minimizeSteps(1000), m_DCDReporter(true),
55 m_PDBReporter(false), m_stateDataReporter(true),
56
57 m_output(), m_dirty(false), m_warned(false), readData(false),
58
59 m_jobEdit(nullptr), m_moleculeEdit(nullptr)
60 {
61 ui.setupUi(this);
62 m_jobFileName =
63 (ui.jobScriptEdit->text().isEmpty() ? ui.jobScriptEdit->placeholderText()
64 : ui.jobScriptEdit->text()) +
65 ".py";
66 m_inputCoordFileName =
67 (ui.inputCoordEdit->text().isEmpty() ? ui.inputCoordEdit->placeholderText()
68 : ui.inputCoordEdit->text());
69 m_topologyFileName =
70 (ui.inputTopEdit->text().isEmpty() ? ui.inputTopEdit->placeholderText()
71 : ui.inputTopEdit->text());
72
73 // Connect the GUI elements to the correct slots
74 connect(ui.jobScriptEdit, SIGNAL(textChanged(QString)), this,
75 SLOT(setScriptName()));
76 connect(ui.inputCoordEdit, SIGNAL(textChanged(QString)), this,
77 SLOT(setInputCoordName()));
78 connect(ui.forceFieldCombo, SIGNAL(currentIndexChanged(int)), this,
79 SLOT(setForceField(int)));
80 connect(ui.constraintsCombo, SIGNAL(currentIndexChanged(int)), this,
81 SLOT(setConstraintType(int)));
82 connect(ui.waterModelCombo, SIGNAL(currentIndexChanged(int)), this,
83 SLOT(setWaterModelType(int)));
84 connect(ui.nonBondedMethodCombo, SIGNAL(currentIndexChanged(int)), this,
85 SLOT(setNonBondedType(int)));
86 connect(ui.integratorCombo, SIGNAL(currentIndexChanged(int)), this,
87 SLOT(setIntegratorType(int)));
88 connect(ui.barostatCombo, SIGNAL(currentIndexChanged(int)), this,
89 SLOT(setBarostatType(int)));
90 connect(ui.inputTopEdit, SIGNAL(textChanged(QString)), this,
91 SLOT(setTopologyName()));
92 connect(ui.rigidWaterCombo, SIGNAL(currentIndexChanged(int)), this,
93 SLOT(setRigidWater(int)));
94 connect(ui.temperatureSpin, SIGNAL(valueChanged(double)), this,
95 SLOT(setTemperature(double)));
96 connect(ui.generationTemperatureSpin, SIGNAL(valueChanged(double)), this,
97 SLOT(setGenerationTemperature(double)));
98 connect(ui.nonBondedCutoffSpin, SIGNAL(valueChanged(double)), this,
99 SLOT(setNonBondedCutoff(double)));
100 connect(ui.stepSpin, SIGNAL(valueChanged(double)), this,
101 SLOT(setTimeStep(double)));
102 connect(ui.ewaldToleranceSpin, SIGNAL(valueChanged(double)), this,
103 SLOT(setEwaldTolerance(double)));
104 connect(ui.constraintToleranceSpin, SIGNAL(valueChanged(double)), this,
105 SLOT(setConstraintTolerance(double)));
106 connect(ui.reportIntervalSpin, SIGNAL(valueChanged(int)), this,
107 SLOT(setReportInterval(int)));
108 connect(ui.equilibriationStepsSpin, SIGNAL(valueChanged(int)), this,
109 SLOT(setEquilibriationSteps(int)));
110 connect(ui.productionStepsSpin, SIGNAL(valueChanged(int)), this,
111 SLOT(setProductionSteps(int)));
112 connect(ui.deviceIndexSpin, SIGNAL(valueChanged(int)), this,
113 SLOT(setDeviceIndex(int)));
114 connect(ui.openCLIndexSpin, SIGNAL(valueChanged(int)), this,
115 SLOT(setOpenCLPlatformIndex(int)));
116 connect(ui.errorTolSpin, SIGNAL(valueChanged(double)), this,
117 SLOT(setErrorTolerance(double)));
118 connect(ui.collisionRateSpin, SIGNAL(valueChanged(double)), this,
119 SLOT(setCollisionRate(double)));
120 connect(ui.pressureSpin, SIGNAL(valueChanged(double)), this,
121 SLOT(setPressure(double)));
122 connect(ui.barostatIntervalSpin, SIGNAL(valueChanged(int)), this,
123 SLOT(setBarostatInterval(int)));
124 connect(ui.minimizeCombo, SIGNAL(currentIndexChanged(int)), this,
125 SLOT(setMinimize(int)));
126 connect(ui.minimizeStepsSpin, SIGNAL(valueChanged(int)), this,
127 SLOT(setMinimizeSteps(int)));
128 connect(ui.initVelCombo, SIGNAL(currentIndexChanged(int)), this,
129 SLOT(setVelocityDistRandom(int)));
130 connect(ui.platformCombo, SIGNAL(currentIndexChanged(int)), this,
131 SLOT(setPlatformType(int)));
132 connect(ui.precisionCombo, SIGNAL(currentIndexChanged(int)), this,
133 SLOT(setPrecisionType(int)));
134 connect(ui.dcdCheck, SIGNAL(toggled(bool)), this, SLOT(setDCDReporter(bool)));
135 connect(ui.pdbCheck, SIGNAL(toggled(bool)), this, SLOT(setPDBReporter(bool)));
136 connect(ui.stateDataCheck, SIGNAL(toggled(bool)), this,
137 SLOT(setStateDataReporter(bool)));
138
139 connect(ui.stepIndexCheck, SIGNAL(toggled(bool)), this,
140 SLOT(setStepIndexBoolean(bool)));
141 connect(ui.timeCheck, SIGNAL(toggled(bool)), this,
142 SLOT(setTimeBoolean(bool)));
143 connect(ui.speedCheck, SIGNAL(toggled(bool)), this,
144 SLOT(setSpeedBoolean(bool)));
145 connect(ui.progressCheck, SIGNAL(toggled(bool)), this,
146 SLOT(setProgressBoolean(bool)));
147 connect(ui.potentialEnergyCheck, SIGNAL(toggled(bool)), this,
148 SLOT(setPotentialEnergyBoolean(bool)));
149 connect(ui.kineticEnergyCheck, SIGNAL(toggled(bool)), this,
150 SLOT(setKineticEnergyBoolean(bool)));
151 connect(ui.totalEnergyCheck, SIGNAL(toggled(bool)), this,
152 SLOT(setTotalEnergyBoolean(bool)));
153 connect(ui.temperatureCheck, SIGNAL(toggled(bool)), this,
154 SLOT(setTemperatureBoolean(bool)));
155 connect(ui.volumeCheck, SIGNAL(toggled(bool)), this,
156 SLOT(setVolumeBoolean(bool)));
157 connect(ui.densityCheck, SIGNAL(toggled(bool)), this,
158 SLOT(setDensityBoolean(bool)));
159
160 connect(ui.generateButton, SIGNAL(clicked()), this, SLOT(generateClicked()));
161 connect(ui.resetButton, SIGNAL(clicked()), this, SLOT(resetClicked()));
162
163 connect(ui.enableFormButton, SIGNAL(clicked()), this,
164 SLOT(enableFormClicked()));
165
166 QSettings settings;
167 readSettings(settings);
168
169 resetClicked();
170
171 // Generate an initial preview of the input deck
172 updatePreviewText();
173 addMoleculeDataTab();
174 }
175
176 OpenMMInputDialog::~OpenMMInputDialog()
177 {
178 QSettings settings;
179 writeSettings(settings);
180 }
181
182 void OpenMMInputDialog::showEvent(QShowEvent*)
183 {
184 updatePreviewText();
185 addMoleculeDataTab();
186 }
187
188 void OpenMMInputDialog::updatePreviewText()
189 {
190 if (!isVisible())
191 return;
192
193 int jobTabPosition = 0;
194
195 // Store the currently displayed tab
196 int currIndex = ui.tabWidget->currentIndex();
197
198 // Generate the input deck and display it
199 if (m_dirty) {
200 QString message =
201 tr("Would you like to update the preview text, losing all "
202 "changes made in the OpenMM input deck preview pane?");
203 int response = QMessageBox::question(
204 this, tr("Overwrite modified input files?"), message,
205 QMessageBox::Yes | QMessageBox::No, QMessageBox::No);
206
207 if (static_cast<QMessageBox::StandardButton>(response) == QMessageBox::No) {
208 return;
209 }
210 }
211
212 ui.tabWidget->removeTab(jobTabPosition);
213
214 m_jobEdit = new QTextEdit(this);
215 m_jobEdit->setObjectName(m_jobFileName);
216 m_jobEdit->setFontFamily("monospace");
217 connect(m_jobEdit, SIGNAL(textChanged()), this, SLOT(textEditModified()));
218 m_jobEdit->setText(generateInputDeck());
219 ui.tabWidget->insertTab(jobTabPosition, m_jobEdit, m_jobFileName);
220 deckDirty(false);
221
222 // Restore current tab
223 ui.tabWidget->setCurrentIndex(currIndex);
224 }
225
226 void OpenMMInputDialog::addMoleculeDataTab()
227 {
228 int molTabPosition = 1;
229 if (m_molecule) {
230 ui.tabWidget->removeTab(molTabPosition);
231 std::string molOutput,
232 extension = m_inputCoordFileName.split(".").back().toStdString();
233
234 bool writeSDF = Io::FileFormatManager::instance().writeString(
235 *m_molecule, molOutput, extension);
236 if (writeSDF) {
237 m_moleculeEdit = new QTextEdit(this);
238 m_moleculeEdit->setObjectName(m_inputCoordFileName);
239 m_moleculeEdit->setFontFamily("monospace");
240 m_moleculeEdit->setText(QString::fromStdString(molOutput));
241 ui.tabWidget->insertTab(molTabPosition, m_moleculeEdit,
242 m_inputCoordFileName);
243 }
244 }
245 }
246
247 void OpenMMInputDialog::textEditModified()
248 {
249 if (auto* edit = qobject_cast<QTextEdit*>(sender())) {
250 if (edit->document()->isModified()) {
251 deckDirty(true);
252 } else {
253 deckDirty(false);
254 }
255 }
256 }
257
258 void OpenMMInputDialog::resetClicked()
259 {
260 // Reset the form to defaults
261 deckDirty(false);
262
263 // 1st subdivision
264 ui.precisionCombo->setCurrentIndex(1);
265 ui.forceFieldCombo->setCurrentIndex(2);
266 ui.waterModelCombo->setCurrentIndex(1);
267 ui.platformCombo->setCurrentIndex(3);
268 setPlatformType(3);
269
270 // 2nd subdivision
271 ui.ewaldToleranceSpin->setValue(0.0005);
272 ui.constraintToleranceSpin->setValue(0.00001);
273 ui.nonBondedCutoffSpin->setValue(1.0);
274 ui.generationTemperatureSpin->setValue(298.15);
275 ui.nonBondedMethodCombo->setCurrentIndex(4);
276 setNonBondedType(4);
277 ui.constraintsCombo->setCurrentIndex(1);
278 setConstraintType(1);
279 ui.rigidWaterCombo->setCurrentIndex(0);
280 setRigidWater(0);
281 ui.initVelCombo->setCurrentIndex(0);
282 setVelocityDistRandom(0);
283
284 // 3rd subdivision
285 ui.stepSpin->setValue(2.0);
286 ui.errorTolSpin->setValue(0.0001);
287 ui.collisionRateSpin->setValue(1.0);
288 ui.temperatureSpin->setValue(298.15);
289 ui.pressureSpin->setValue(1.0);
290 ui.barostatIntervalSpin->setValue(25);
291 ui.barostatCombo->setCurrentIndex(0);
292 setBarostatType(0);
293 ui.integratorCombo->setCurrentIndex(0);
294 setIntegratorType(0);
295
296 // 4th subdivision
297 ui.minimizeCombo->setCurrentIndex(0);
298 ui.reportIntervalSpin->setValue(1000);
299 ui.minimizeStepsSpin->setValue(1000);
300 ui.productionStepsSpin->setValue(1000);
301 ui.equilibriationStepsSpin->setValue(100);
302 ui.stepIndexCheck->setChecked(true);
303 ui.timeCheck->setChecked(false);
304 ui.speedCheck->setChecked(true);
305 ui.progressCheck->setChecked(true);
306 ui.potentialEnergyCheck->setChecked(true);
307 ui.kineticEnergyCheck->setChecked(false);
308 ui.totalEnergyCheck->setChecked(false);
309 ui.temperatureCheck->setChecked(true);
310 ui.volumeCheck->setChecked(false);
311 ui.densityCheck->setChecked(false);
312 // Unfortunately, setChecked() does not emit toggled() signal
313 // So the slots have to be invoked
314 setStepIndexBoolean(true);
315 setTimeBoolean(false);
316 setSpeedBoolean(true);
317 setProgressBoolean(true);
318 setPotentialEnergyBoolean(true);
319 setKineticEnergyBoolean(false);
320 setTotalEnergyBoolean(false);
321 setTemperatureBoolean(true);
322 setVolumeBoolean(false);
323 setDensityBoolean(false);
324
325 ui.stateDataCheck->setChecked(true);
326 ui.dcdCheck->setChecked(true);
327 ui.pdbCheck->setChecked(false);
328
329 updatePreviewText();
330 addMoleculeDataTab();
331 }
332
333 void OpenMMInputDialog::generateClicked()
334 {
335 QSettings settings;
336 QString directory =
337 settings.value("openmmInput/outputDirectory", QDir::homePath()).toString();
338 if (directory.isEmpty())
339 directory = QDir::homePath();
340 directory = QFileDialog::getExistingDirectory(
341 this, tr("Select output directory"), directory);
342
343 // User cancel:
344 if (directory.isNull())
345 return;
346
347 settings.setValue("openmmInput/outputDirectory", directory);
348 QDir dir(directory);
349
350 // Check for problems:
351 QStringList errors;
352 bool fatalError = false;
353
354 do { // Do/while to break on fatal errors
355 if (!dir.exists()) {
356 errors << tr("%1: Directory does not exist!").arg(dir.absolutePath());
357 fatalError = true;
358 break;
359 }
360
361 if (!dir.isReadable()) {
362 errors << tr("%1: Directory cannot be read!").arg(dir.absolutePath());
363 fatalError = true;
364 break;
365 }
366
367 QFileInfo jobFileInfo(dir.absoluteFilePath(m_jobFileName));
368
369 if (jobFileInfo.exists()) {
370 errors << tr("%1: File will be overwritten.")
371 .arg(jobFileInfo.absoluteFilePath());
372 }
373
374 // Attempt to open the file for writing
375 if (!QFile(jobFileInfo.absoluteFilePath()).open(QFile::WriteOnly)) {
376 errors
377 << tr("%1: File is not writable.").arg(jobFileInfo.absoluteFilePath());
378 fatalError = true;
379 break;
380 }
381
382 QFileInfo molFileInfo(dir.absoluteFilePath(m_inputCoordFileName));
383
384 if (molFileInfo.exists()) {
385 errors << tr("%1: File will be overwritten.")
386 .arg(molFileInfo.absoluteFilePath());
387 }
388
389 // Attempt to open the file for writing
390 if (!QFile(molFileInfo.absoluteFilePath()).open(QFile::WriteOnly)) {
391 errors
392 << tr("%1: File is not writable.").arg(molFileInfo.absoluteFilePath());
393 fatalError = true;
394 break;
395 }
396 } while (false); // only run once
397
398 // Handle fatal errors:
399 if (fatalError) {
400 QString formattedError;
401 switch (errors.size()) {
402 case 0:
403 formattedError =
404 tr("The input files cannot be written due to an unknown error.");
405 break;
406 case 1:
407 formattedError =
408 tr("The input files cannot be written:\n\n%1").arg(errors.first());
409 break;
410 default: {
411 // If a fatal error occurred, it will be last one in the list. Pop it
412 // off and tell the user that it was the reason we had to stop.
413 QString fatal = errors.last();
414 QStringList tmp(errors);
415 tmp.pop_back();
416 formattedError =
417 tr("The input files cannot be written:\n\n%1\n\nWarnings:\n\n%2")
418 .arg(fatal, tmp.join("\n"));
419 break;
420 }
421 }
422 QMessageBox::critical(this, tr("Output Error"), formattedError);
423 return;
424 }
425
426 // Non-fatal errors:
427 if (!errors.isEmpty()) {
428 QString formattedError = tr("Warning:\n\n%1\n\nWould you like to continue?")
429 .arg(errors.join("\n"));
430
431 QMessageBox::StandardButton reply =
432 QMessageBox::warning(this, tr("Write input files"), formattedError,
433 QMessageBox::Yes | QMessageBox::No, QMessageBox::No);
434
435 if (reply != QMessageBox::Yes)
436 return;
437 }
438
439 bool success = false;
440
441 if (m_jobEdit && m_moleculeEdit) {
442 QFile jobFile(dir.absoluteFilePath(m_jobFileName));
443 if (jobFile.open(QFile::WriteOnly | QFile::Text)) {
444 if (jobFile.write(m_jobEdit->toPlainText().toLocal8Bit()) > 0) {
445 success = true;
446 }
447 jobFile.close();
448 }
449
450 if (!success) {
451 QMessageBox::critical(
452 this, tr("Output Error"),
453 tr("Failed to write to file %1.").arg(jobFile.fileName()));
454 }
455
456 QFile molFile(dir.absoluteFilePath(m_inputCoordFileName));
457 if (molFile.open(QFile::WriteOnly | QFile::Text)) {
458 if (molFile.write(m_moleculeEdit->toPlainText().toLocal8Bit()) > 0) {
459 success = true;
460 }
461 molFile.close();
462 }
463
464 if (!success) {
465 QMessageBox::critical(
466 this, tr("Output Error"),
467 tr("Failed to write to file %1.").arg(molFile.fileName()));
468 }
469 }
470 }
471
472 void OpenMMInputDialog::enableFormClicked()
473 {
474 updatePreviewText();
475 }
476
477 void OpenMMInputDialog::setScriptName()
478 {
479 m_jobFileName =
480 (ui.jobScriptEdit->text().isEmpty() ? ui.jobScriptEdit->placeholderText()
481 : ui.jobScriptEdit->text()) +
482 ".py";
483 updatePreviewText();
484 }
485
486 void OpenMMInputDialog::setInputCoordName()
487 {
488 ui.inputCoordEdit->setStyleSheet("");
489 m_inputCoordFileName =
490 (ui.inputCoordEdit->text().isEmpty() ? ui.inputCoordEdit->placeholderText()
491 : ui.inputCoordEdit->text());
492 QString ext = m_inputCoordFileName.split(".").back();
493 if (ext == tr("inpcrd") || ext == tr("gro")) {
494 ui.forceFieldCombo->setEnabled(false);
495 ui.inputTopEdit->setEnabled(true);
496 if (ext == tr("inpcrd"))
497 ui.inputTopEdit->setPlaceholderText(tr("input.prmtop"));
498 else if (ext == tr("gro")) {
499 ui.inputTopEdit->setPlaceholderText(tr("input.top"));
500 }
501 updatePreviewText();
502 } else if (ext == tr("pdb")) {
503 ui.forceFieldCombo->setEnabled(true);
504 ui.inputTopEdit->setEnabled(false);
505 updatePreviewText();
506 } else {
507 ui.forceFieldCombo->setEnabled(false);
508 ui.inputTopEdit->setEnabled(false);
509 ui.inputCoordEdit->setStyleSheet("color: #FF0000");
510 }
511 addMoleculeDataTab();
512 }
513
514 void OpenMMInputDialog::setTopologyName()
515 {
516 ui.inputCoordEdit->setStyleSheet("");
517 m_topologyFileName =
518 (ui.inputTopEdit->text().isEmpty() ? ui.inputTopEdit->placeholderText()
519 : ui.inputTopEdit->text());
520 QString ext = m_topologyFileName.split(".").back();
521 QString extCoord = m_inputCoordFileName.split(".").back();
522 if (extCoord == tr("inpcrd")) {
523 if (ext != tr("prmtop")) {
524 ui.inputCoordEdit->setStyleSheet("color: #FF0000");
525 }
526 } else if (extCoord == tr("gro")) {
527 if (ext != tr("top")) {
528 ui.inputCoordEdit->setStyleSheet("color: #FF0000");
529 }
530 }
531 updatePreviewText();
532 }
533
534 void OpenMMInputDialog::setForceField(int n)
535 {
536 m_forceFieldType = (OpenMMInputDialog::forceFieldType)n;
537 ui.forceFieldCombo->setEnabled(true);
538 updatePreviewText();
539 }
540
541 void OpenMMInputDialog::setConstraintType(int n)
542 {
543 m_constraintType = static_cast<OpenMMInputDialog::constraintType>(n);
544 ui.constraintsCombo->setEnabled(true);
545 if (m_constraintType == None) {
546 ui.constraintToleranceSpin->setEnabled(false);
547 } else {
548 ui.constraintToleranceSpin->setEnabled(true);
549 }
550 updatePreviewText();
551 }
552
553 void OpenMMInputDialog::setWaterModelType(int n)
554 {
555 m_waterModelType = static_cast<OpenMMInputDialog::waterModelType>(n);
556 ui.waterModelCombo->setEnabled(true);
557 updatePreviewText();
558 }
559
560 void OpenMMInputDialog::setNonBondedType(int n)
561 {
562 m_nonBondedType = static_cast<OpenMMInputDialog::nonBondedType>(n);
563 ui.nonBondedMethodCombo->setEnabled(true);
564 if (m_nonBondedType == NoCutoff) {
565 ui.nonBondedCutoffSpin->setEnabled(false);
566 ui.ewaldToleranceSpin->setEnabled(false);
567 } else if (m_nonBondedType == CutoffPeriodic ||
568 m_nonBondedType == CutoffNonPeriodic) {
569 ui.nonBondedCutoffSpin->setEnabled(true);
570 ui.ewaldToleranceSpin->setEnabled(false);
571 } else if (m_nonBondedType == Ewald || m_nonBondedType == PME) {
572 ui.nonBondedCutoffSpin->setEnabled(true);
573 ui.ewaldToleranceSpin->setEnabled(true);
574 }
575 updatePreviewText();
576 }
577
578 void OpenMMInputDialog::setIntegratorType(int n)
579 {
580 m_integratorType = static_cast<OpenMMInputDialog::integratorType>(n);
581 ui.integratorCombo->setEnabled(true);
582 if (m_integratorType == Langevin || m_integratorType == Brownian ||
583 m_integratorType == VariableLangevin) {
584 if (m_integratorType == Langevin || m_integratorType == Brownian) {
585 ui.stepSpin->setEnabled(true);
586 ui.errorTolSpin->setEnabled(false);
587 } else if (m_integratorType == VariableLangevin) {
588 ui.stepSpin->setEnabled(false);
589 ui.errorTolSpin->setEnabled(true);
590 }
591 ui.collisionRateSpin->setEnabled(true);
592 ui.temperatureSpin->setEnabled(true);
593 ui.barostatCombo->setEnabled(true);
594 if (m_barostatType == NoBarostat) {
595 ui.pressureSpin->setEnabled(false);
596 ui.barostatIntervalSpin->setEnabled(false);
597 } else {
598 ui.pressureSpin->setEnabled(true);
599 ui.barostatIntervalSpin->setEnabled(true);
600 }
601 } else if (m_integratorType == Verlet || m_integratorType == VariableVerlet) {
602 if (m_integratorType == Verlet) {
603 ui.stepSpin->setEnabled(true);
604 ui.errorTolSpin->setEnabled(false);
605 } else if (m_integratorType == VariableVerlet) {
606 ui.stepSpin->setEnabled(false);
607 ui.errorTolSpin->setEnabled(true);
608 }
609 ui.collisionRateSpin->setEnabled(false);
610 ui.temperatureSpin->setEnabled(false);
611 ui.barostatCombo->setEnabled(false);
612 ui.pressureSpin->setEnabled(false);
613 ui.barostatIntervalSpin->setEnabled(false);
614 }
615 updatePreviewText();
616 }
617
618 void OpenMMInputDialog::setBarostatType(int n)
619 {
620 m_barostatType = static_cast<OpenMMInputDialog::barostatType>(n);
621 ui.barostatCombo->setEnabled(true);
622 if (m_barostatType == NoBarostat) {
623 ui.pressureSpin->setEnabled(false);
624 ui.barostatIntervalSpin->setEnabled(false);
625 } else {
626 ui.pressureSpin->setEnabled(true);
627 ui.barostatIntervalSpin->setEnabled(true);
628 }
629 updatePreviewText();
630 }
631
632 void OpenMMInputDialog::setMolecule(QtGui::Molecule* molecule)
633 {
634 // Disconnect the old molecule first...
635 if (molecule == m_molecule)
636 return;
637
638 if (m_molecule)
639 m_molecule->disconnect(this);
640
641 m_molecule = molecule;
642 // Update the preview text whenever primitives are changed
643 connect(molecule, SIGNAL(changed(unsigned int)), SLOT(updatePreviewText()));
644 updatePreviewText();
645 }
646
647 void OpenMMInputDialog::setRigidWater(int n)
648 {
649 m_rigidWater = n;
650 ui.rigidWaterCombo->setEnabled(true);
651 updatePreviewText();
652 }
653
654 void OpenMMInputDialog::setMinimize(int n)
655 {
656 m_minimize = n;
657 ui.minimizeCombo->setEnabled(true);
658 updatePreviewText();
659 }
660
661 void OpenMMInputDialog::setMinimizeSteps(int n)
662 {
663 m_minimizeSteps = n;
664 ui.minimizeStepsSpin->setEnabled(true);
665 updatePreviewText();
666 }
667
668 void OpenMMInputDialog::setTemperature(double n)
669 {
670 m_temperature = n;
671 ui.temperatureSpin->setEnabled(true);
672 updatePreviewText();
673 }
674
675 void OpenMMInputDialog::setNonBondedCutoff(double n)
676 {
677 m_nonBondedCutoff = n;
678 ui.nonBondedCutoffSpin->setEnabled(true);
679 updatePreviewText();
680 }
681
682 void OpenMMInputDialog::setTimeStep(double n)
683 {
684 m_timeStep = n;
685 ui.stepSpin->setEnabled(true);
686 updatePreviewText();
687 }
688
689 void OpenMMInputDialog::setEwaldTolerance(double n)
690 {
691 m_ewaldTolerance = n;
692 ui.ewaldToleranceSpin->setEnabled(true);
693 updatePreviewText();
694 }
695
696 void OpenMMInputDialog::setConstraintTolerance(double n)
697 {
698 m_constraintTolerance = n;
699 ui.constraintToleranceSpin->setEnabled(true);
700 updatePreviewText();
701 }
702
703 void OpenMMInputDialog::setReportInterval(int n)
704 {
705 m_reportInterval = n;
706 ui.reportIntervalSpin->setEnabled(true);
707 updatePreviewText();
708 }
709
710 void OpenMMInputDialog::setEquilibriationSteps(int n)
711 {
712 m_equilibriationSteps = n;
713 ui.equilibriationStepsSpin->setEnabled(true);
714 updatePreviewText();
715 }
716
717 void OpenMMInputDialog::setProductionSteps(int n)
718 {
719 m_productionSteps = n;
720 ui.productionStepsSpin->setEnabled(true);
721 updatePreviewText();
722 }
723
724 void OpenMMInputDialog::setDeviceIndex(int n)
725 {
726 m_deviceIndex = n;
727 ui.deviceIndexSpin->setEnabled(true);
728 updatePreviewText();
729 }
730
731 void OpenMMInputDialog::setOpenCLPlatformIndex(int n)
732 {
733 m_openclPlatformIndex = n;
734 ui.openCLIndexSpin->setEnabled(true);
735 updatePreviewText();
736 }
737
738 void OpenMMInputDialog::setErrorTolerance(double n)
739 {
740 m_errorTolerance = n;
741 ui.errorTolSpin->setEnabled(true);
742 updatePreviewText();
743 }
744
745 void OpenMMInputDialog::setCollisionRate(double n)
746 {
747 m_collisionRate = n;
748 ui.collisionRateSpin->setEnabled(true);
749 updatePreviewText();
750 }
751
752 void OpenMMInputDialog::setPressure(double n)
753 {
754 m_pressure = n;
755 ui.pressureSpin->setEnabled(true);
756 updatePreviewText();
757 }
758
759 void OpenMMInputDialog::setBarostatInterval(int n)
760 {
761 m_barostatInterval = n;
762 ui.barostatIntervalSpin->setEnabled(true);
763 updatePreviewText();
764 }
765
766 void OpenMMInputDialog::setVelocityDistRandom(int n)
767 {
768 m_velocityDistRandom = n;
769 ui.initVelCombo->setEnabled(true);
770 if (m_velocityDistRandom == 1) {
771 ui.generationTemperatureSpin->setEnabled(false);
772 } else {
773 ui.generationTemperatureSpin->setEnabled(true);
774 }
775 updatePreviewText();
776 }
777
778 void OpenMMInputDialog::setGenerationTemperature(double n)
779 {
780 m_generationTemperature = n;
781 ui.generationTemperatureSpin->setEnabled(true);
782 updatePreviewText();
783 }
784
785 void OpenMMInputDialog::setDCDReporter(bool state)
786 {
787 m_DCDReporter = state;
788 ui.dcdCheck->setEnabled(true);
789 updatePreviewText();
790 }
791
792 void OpenMMInputDialog::setPDBReporter(bool state)
793 {
794 m_PDBReporter = state;
795 ui.pdbCheck->setEnabled(true);
796 updatePreviewText();
797 }
798
799 void OpenMMInputDialog::setStepIndexBoolean(bool state)
800 {
801 m_stepIndex = state;
802 ui.stepIndexCheck->setEnabled(true);
803 updatePreviewText();
804 }
805 void OpenMMInputDialog::setTimeBoolean(bool state)
806 {
807 m_time = state;
808 ui.timeCheck->setEnabled(true);
809 updatePreviewText();
810 }
811 void OpenMMInputDialog::setSpeedBoolean(bool state)
812 {
813 m_speed = state;
814 ui.speedCheck->setEnabled(true);
815 updatePreviewText();
816 }
817 void OpenMMInputDialog::setProgressBoolean(bool state)
818 {
819 m_progress = state;
820 ui.progressCheck->setEnabled(true);
821 updatePreviewText();
822 }
823 void OpenMMInputDialog::setPotentialEnergyBoolean(bool state)
824 {
825 m_potentialEnergy = state;
826 ui.potentialEnergyCheck->setEnabled(true);
827 updatePreviewText();
828 }
829 void OpenMMInputDialog::setKineticEnergyBoolean(bool state)
830 {
831 m_kineticEnergy = state;
832 ui.kineticEnergyCheck->setEnabled(true);
833 updatePreviewText();
834 }
835 void OpenMMInputDialog::setTotalEnergyBoolean(bool state)
836 {
837 m_totalEnergy = state;
838 ui.totalEnergyCheck->setEnabled(true);
839 updatePreviewText();
840 }
841 void OpenMMInputDialog::setTemperatureBoolean(bool state)
842 {
843 m_temperature = state;
844 ui.temperatureCheck->setEnabled(true);
845 updatePreviewText();
846 }
847 void OpenMMInputDialog::setVolumeBoolean(bool state)
848 {
849 m_volume = state;
850 ui.volumeCheck->setEnabled(true);
851 updatePreviewText();
852 }
853 void OpenMMInputDialog::setDensityBoolean(bool state)
854 {
855 m_density = state;
856 ui.densityCheck->setEnabled(true);
857 updatePreviewText();
858 }
859
860 void OpenMMInputDialog::setStateDataReporter(bool state)
861 {
862 ui.stepIndexCheck->setEnabled(state);
863 ui.timeCheck->setEnabled(state);
864 ui.speedCheck->setEnabled(state);
865 ui.progressCheck->setEnabled(state);
866 ui.potentialEnergyCheck->setEnabled(state);
867 ui.kineticEnergyCheck->setEnabled(state);
868 ui.totalEnergyCheck->setEnabled(state);
869 ui.temperatureCheck->setEnabled(state);
870 ui.volumeCheck->setEnabled(state);
871 ui.densityCheck->setEnabled(state);
872
873 m_stateDataReporter = state;
874 ui.stateDataCheck->setEnabled(true);
875 updatePreviewText();
876 }
877
878 void OpenMMInputDialog::setPlatformType(int n)
879 {
880 m_platformType = static_cast<OpenMMInputDialog::platformType>(n);
881 ui.platformCombo->setEnabled(true);
882 if (m_platformType == Reference || m_platformType == CPU) {
883 ui.precisionCombo->setEnabled(false);
884 ui.deviceIndexSpin->setEnabled(false);
885 ui.openCLIndexSpin->setEnabled(false);
886 } else {
887 ui.precisionCombo->setEnabled(true);
888 ui.deviceIndexSpin->setEnabled(true);
889 if (m_platformType == OpenCL)
890 ui.openCLIndexSpin->setEnabled(true);
891 else
892 ui.openCLIndexSpin->setEnabled(false);
893 }
894 updatePreviewText();
895 }
896
897 void OpenMMInputDialog::setPrecisionType(int n)
898 {
899 m_precisionType = static_cast<OpenMMInputDialog::precisionType>(n);
900 ui.precisionCombo->setEnabled(true);
901 updatePreviewText();
902 }
903
904 QString OpenMMInputDialog::generateInputDeck()
905 {
906 // Generate an input deck based on the settings of the dialog
907 QString buffer;
908 QTextStream scriptStream(&buffer);
909
910 scriptStream << "############################################################"
911 "##############\n";
912 scriptStream << "# OpenMM input script generated by Avogadro.\n";
913 scriptStream << "# Builder adapted from OpenMM script builder "
914 "http://builder.openmm.org.\n";
915 scriptStream << "############################################################"
916 "##############\n\n";
917 scriptStream << "from __future__ import print_function\n";
918 scriptStream << "from simtk.openmm import app\n";
919 scriptStream << "import simtk.openmm as mm\n";
920 scriptStream << "from simtk import unit\n";
921 scriptStream << "from sys import stdout\n";
922
923 // first two or three lines, that load up the FF and the pdb
924 // these lines end with the start of the function something.createSystem(
925 QString ext = m_inputCoordFileName.split(".").back();
926 if (ext == tr("pdb")) {
927 scriptStream << "\npdb = app.PDBFile(\'" << m_inputCoordFileName << "\')\n";
928 scriptStream << "forcefield = app.ForceField(\'"
929 << getForceFieldType(m_forceFieldType) << ".xml\'";
930 scriptStream << ", \'" << getWaterModelType(m_waterModelType) << ".xml\'";
931 scriptStream << ")\n\n";
932 scriptStream << "system = forcefield.createSystem(pdb.topology, ";
933 } else if (ext == tr("inpcrd")) {
934 scriptStream << "\nprmtop = app.AmberPrmtopFile(\'" << m_topologyFileName
935 << "\')\n";
936 scriptStream << "inpcrd = app.AmberInpcrdFile(\'" << m_inputCoordFileName
937 << "\')\n\n";
938 scriptStream << "system = prmtop.createSystem(";
939 if (m_waterModelType == implicit) {
940 scriptStream << "implicitSolvent=app.OBC2, ";
941 }
942 } else if (ext == tr("gro")) {
943 scriptStream << "\ngro = app.GromacsGroFile(\'" << m_inputCoordFileName
944 << "\')\n";
945 scriptStream << "top = app.GromacsTopFile(\'" << m_topologyFileName
946 << "\')\n\n";
947 scriptStream << "system = top.createSystem(";
948 if (m_waterModelType == implicit) {
949 scriptStream << "implicitSolvent=app.OBC2, ";
950 }
951 } else {
952 // TODO
953 }
954
955 // options for the system
956 scriptStream << "nonbondedMethod="
957 << "app." << getNonBondedType(m_nonBondedType) << ",";
958 if (m_nonBondedCutoff > 0) {
959 scriptStream << " nonbondedCutoff=" << Qt::fixed
960 << qSetRealNumberPrecision(4) << m_nonBondedCutoff
961 << "*unit.nanometers,";
962 }
963 if (m_constraintType == None) {
964 scriptStream << " constraints=" << getConstraintType(m_constraintType);
965 } else {
966 scriptStream << " constraints="
967 << "app." << getConstraintType(m_constraintType);
968 }
969 scriptStream << ", rigidWater=" << getRigidWater(m_rigidWater);
970 if (m_nonBondedType == Ewald || m_nonBondedType == PME) {
971 scriptStream << ", ewaldErrorTolerance=" << Qt::fixed
972 << qSetRealNumberPrecision(5) << m_ewaldTolerance;
973 }
974 scriptStream << ")\n";
975
976 // set the integrator
977 scriptStream << "integrator = mm." << getIntegratorType(m_integratorType)
978 << "Integrator(";
979 if (m_integratorType == Langevin || m_integratorType == Brownian) {
980 scriptStream << m_temperature << "*unit.kelvin, ";
981 scriptStream << m_collisionRate << "/unit.picoseconds, ";
982 }
983 if (m_integratorType == VariableLangevin ||
984 m_integratorType == VariableVerlet) {
985 scriptStream << m_errorTolerance << ")\n";
986 } else {
987 scriptStream << m_timeStep << "*unit.femtoseconds)\n";
988 }
989 if (m_constraintType != None && m_constraintTolerance > 0) {
990 scriptStream << "integrator.setConstraintTolerance("
991 << m_constraintTolerance << ")\n";
992 }
993
994 // add a barostat
995 if (m_barostatType == MonteCarlo) {
996 scriptStream << "system.addForce(mm.MonteCarloBarostat(" << m_pressure
997 << "*unit.atmospheres";
998 scriptStream << ", " << m_temperature << "*unit.kelvin";
999 if (m_barostatInterval > 0) {
1000 scriptStream << ", " << m_barostatInterval;
1001 }
1002 scriptStream << "))\n";
1003 }
1004
1005 // // add a thermostat
1006 // if (m_thermostatType == Andersen) {
1007 // scriptStream << "system.addForce(mm.AndersenThermostat(" <<
1008 // m_temperature << "*unit.kelvin"; scriptStream << ", " <<
1009 // m_collisionRate << "/unit.picoseconds" << "))\n";
1010 // }
1011
1012 scriptStream << "\n";
1013
1014 // set the platform options
1015 scriptStream << "platform = mm.Platform.getPlatformByName(\'"
1016 << getPlatformType(m_platformType) << "\')\n";
1017 if (m_platformType == CUDA) {
1018 scriptStream << R"(properties = {'CudaPrecision': ')"
1019 << getPrecisionType(m_precisionType) << "\'";
1020 if (m_deviceIndex > 0) {
1021 scriptStream << R"(, 'CudaDeviceIndex': ')" << m_deviceIndex << "\'";
1022 }
1023 scriptStream << "}\n";
1024 } else if (m_platformType == OpenCL) {
1025 scriptStream << R"(properties = {'OpenCLPrecision': ')"
1026 << getPrecisionType(m_precisionType) << "\'";
1027 if (m_openclPlatformIndex > 0) {
1028 scriptStream << R"(, 'OpenCLPlatformIndex': ')" << m_openclPlatformIndex
1029 << "\'";
1030 }
1031 if (m_deviceIndex > 0) {
1032 scriptStream << ", ";
1033 if (m_openclPlatformIndex > 0) {
1034 scriptStream << "\n ";
1035 }
1036 scriptStream << R"('OpenCLDeviceIndex': ')" << m_deviceIndex << "\'";
1037 }
1038 scriptStream << "}\n";
1039 }
1040
1041 // create the simulation object
1042 scriptStream << "simulation = app.Simulation("
1043 << (ext == tr("pdb") ? "pdb" : "prmtop")
1044 << ".topology, system, integrator, platform";
1045 if (m_platformType == CUDA || m_platformType == OpenCL) {
1046 scriptStream << ", properties";
1047 }
1048 scriptStream << ")\n";
1049
1050 if (ext == tr("pdb")) {
1051 scriptStream << "simulation.context.setPositions(pdb.positions)\n\n";
1052 } else if (ext == tr("inpcrd")) {
1053 scriptStream << "simulation.context.setPositions(inpcrd.positions)\n\n";
1054 } else if (ext == tr("gro")) {
1055 scriptStream << "simulation.context.setPositions(gro.positions)\n\n";
1056 } else {
1057 // TODO
1058 }
1059
1060 // minimize
1061 if (getMinimize(m_minimize) == tr("True")) {
1062 scriptStream << "print('Minimizing...\')\n";
1063 if (m_minimizeSteps == 0) {
1064 scriptStream << "simulation.minimizeEnergy()\n";
1065 } else {
1066 scriptStream << "simulation.minimizeEnergy(maxIterations="
1067 << m_minimizeSteps << ")\n";
1068 }
1069 }
1070 if (getVelocityDistRandom(m_velocityDistRandom) == tr("True")) {
1071 scriptStream << "\nsimulation.context.setVelocitiesToTemperature("
1072 << m_generationTemperature << "*unit.kelvin)\n";
1073 }
1074
1075 // equilibrate
1076 if (m_equilibriationSteps > 0) {
1077 scriptStream << "print(\'Equilibrating...\')\n";
1078 scriptStream << "simulation.step(" << m_equilibriationSteps << ")\n\n";
1079 }
1080
1081 // add reporters
1082 // if (d.simulation.dcd_reporter == 'True' &&
1083 // d.simulation.statedata_opts.length > 0) {
1084 if (m_DCDReporter) {
1085 scriptStream
1086 << "simulation.reporters.append(app.DCDReporter(\'trajectory.dcd\'";
1087 scriptStream << ", " << m_reportInterval << "))\n";
1088 scriptStream << "\n";
1089 }
1090 if (m_PDBReporter) {
1091 scriptStream
1092 << "simulation.reporters.append(app.PDBReporter(\'trajectory.pdb\'";
1093 scriptStream << ", " << m_reportInterval << "))\n";
1094 scriptStream << "\n";
1095 }
1096 if (m_stateDataReporter) {
1097 scriptStream << "simulation.reporters.append(app.StateDataReporter(";
1098 scriptStream << "stdout";
1099 scriptStream << ", " << m_reportInterval;
1100 if (m_stepIndex)
1101 scriptStream << ", step=True";
1102 if (m_time)
1103 scriptStream << ", time=True";
1104 if (m_potentialEnergy)
1105 scriptStream << ", potentialEnergy=True";
1106 if (m_kineticEnergy)
1107 scriptStream << ", kineticEnergy=True";
1108 if (m_totalEnergy)
1109 scriptStream << ", totalEnergy=True";
1110 if (m_temperatureCheck)
1111 scriptStream << ", temperature=True";
1112 if (m_volume)
1113 scriptStream << ", volume=True";
1114 if (m_density)
1115 scriptStream << ", density=True";
1116 if (m_progress)
1117 scriptStream << ", progress=True, remainingTime=True";
1118 if (m_speed)
1119 scriptStream << ", speed=True";
1120 // if using progress (which also implies remaining time), totalSteps
1121 // is required.
1122 if (m_progress)
1123 scriptStream << ", totalSteps=" << m_productionSteps;
1124 scriptStream << ", separator=\'\\t\'))\n";
1125 scriptStream << "\n";
1126 }
1127
1128 // run
1129 scriptStream << "print(\'Running Production...\')\n";
1130 scriptStream << "simulation.step(" << m_productionSteps << ")\n";
1131 scriptStream << "print(\'Done!\')\n";
1132
1133 return buffer;
1134 }
1135
1136 QString OpenMMInputDialog::getForceFieldType(forceFieldType t)
1137 {
1138 // Translate the enum to text for the output generation
1139 switch (t) {
1140 case amber96:
1141 return "amber96";
1142 case amber99sb:
1143 return "amber99sb";
1144 case amber99sbildn:
1145 return "amber99sbildn";
1146 case amber99sbnmr:
1147 return "amber99sbnmr";
1148 case amber03:
1149 return "amber03";
1150 case amber10:
1151 return "amber10";
1152 default:
1153 return "amber99sbildn";
1154 }
1155 }
1156
1157 QString OpenMMInputDialog::getImplicitSolventType(forceFieldType t)
1158 {
1159 // Translate the enum to text for the output generation
1160 switch (t) {
1161 case amber96:
1162 return "amber96_obc";
1163 case amber99sb:
1164 return "amber99_obc";
1165 case amber99sbildn:
1166 return "amber99_obc";
1167 case amber99sbnmr:
1168 return "amber99_obc";
1169 case amber03:
1170 return "amber03_obc";
1171 case amber10:
1172 return "amber10_obc";
1173 default:
1174 return "amber99_obc";
1175 }
1176 }
1177
1178 QString OpenMMInputDialog::getConstraintType(constraintType t)
1179 {
1180 switch (t) {
1181 case None:
1182 return "None";
1183 case HBonds:
1184 return "HBonds";
1185 case AllBonds:
1186 return "AllBonds";
1187 case HAngles:
1188 return "HAngles";
1189 default:
1190 return "HBonds";
1191 }
1192 }
1193
1194 QString OpenMMInputDialog::getWaterModelType(waterModelType t)
1195 {
1196 switch (t) {
1197 case spce:
1198 return "spce";
1199 case tip3p:
1200 return "tip3p";
1201 case tip4pew:
1202 return "tip4pew";
1203 case tip5p:
1204 return "tip5p";
1205 case implicit:
1206 return getImplicitSolventType(m_forceFieldType);
1207 default:
1208 return "tip3p";
1209 }
1210 }
1211
1212 QString OpenMMInputDialog::getNonBondedType(nonBondedType t)
1213 {
1214 switch (t) {
1215 case NoCutoff:
1216 return "NoCutoff";
1217 case CutoffNonPeriodic:
1218 return "CutoffNonPeriodic";
1219 case CutoffPeriodic:
1220 return "CutoffPeriodic";
1221 case Ewald:
1222 return "Ewald";
1223 case PME:
1224 return "PME";
1225 default:
1226 return "PME";
1227 }
1228 }
1229
1230 QString OpenMMInputDialog::getIntegratorType(integratorType t)
1231 {
1232 switch (t) {
1233 case Langevin:
1234 return "Langevin";
1235 case Verlet:
1236 return "Verlet";
1237 case Brownian:
1238 return "Brownian";
1239 case VariableVerlet:
1240 return "VariableVerlet";
1241 case VariableLangevin:
1242 return "VariableLangevin";
1243 default:
1244 return "Langevin";
1245 }
1246 }
1247
1248 QString OpenMMInputDialog::getBarostatType(barostatType t)
1249 {
1250 switch (t) {
1251 case NoBarostat:
1252 return "None";
1253 case MonteCarlo:
1254 return "MonteCarlo";
1255 default:
1256 return "None";
1257 }
1258 }
1259
1260 QString OpenMMInputDialog::getRigidWater(int t)
1261 {
1262 switch (t) {
1263 case 0:
1264 return "True";
1265 case 1:
1266 return "False";
1267 default:
1268 return "False";
1269 }
1270 }
1271
1272 QString OpenMMInputDialog::getVelocityDistRandom(int t)
1273 {
1274 switch (t) {
1275 case 0:
1276 return "True";
1277 case 1:
1278 return "False";
1279 default:
1280 return "True";
1281 }
1282 }
1283
1284 QString OpenMMInputDialog::getPlatformType(platformType t)
1285 {
1286 switch (t) {
1287 case Reference:
1288 return "Reference";
1289 case OpenCL:
1290 return "OpenCL";
1291 case CUDA:
1292 return "CUDA";
1293 case CPU:
1294 return "CPU";
1295 default:
1296 return "CUDA";
1297 }
1298 }
1299
1300 QString OpenMMInputDialog::getPrecisionType(precisionType t)
1301 {
1302 switch (t) {
1303 case singlePrecision:
1304 return "single";
1305 case mixedPrecision:
1306 return "mixed";
1307 case doublePrecision:
1308 return "double";
1309 default:
1310 return "mixed";
1311 }
1312 }
1313
1314 QString OpenMMInputDialog::getMinimize(int t)
1315 {
1316 switch (t) {
1317 case 0:
1318 return "True";
1319 case 1:
1320 return "False";
1321 default:
1322 return "True";
1323 }
1324 }
1325
1326 void OpenMMInputDialog::deckDirty(bool dirty)
1327 {
1328 m_dirty = dirty;
1329 // ui.titleLine->setEnabled(!dirty);
1330 // ui.calculationCombo->setEnabled(!dirty);
1331 // ui.theoryCombo->setEnabled(!dirty);
1332 // ui.basisCombo->setEnabled(!dirty);
1333 // ui.multiplicitySpin->setEnabled(!dirty);
1334 // ui.chargeSpin->setEnabled(!dirty);
1335 ui.enableFormButton->setEnabled(dirty);
1336 }
1337
1338 void OpenMMInputDialog::readSettings(QSettings& settings)
1339 {
1340 m_savePath = settings.value("openmm/savepath").toString();
1341 }
1342
1343 void OpenMMInputDialog::writeSettings(QSettings& settings) const
1344 {
1345 settings.setValue("openmm/savepath", m_savePath);
1346 }
1347
1348 } // namespace Avogadro::QtPlugins