Debian Codegraph @

avogadro/qtplugins/gamessinput/gamessinputdialog.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 "gamessinputdialog.h"
7 #include "gamesshighlighter.h"
8
9 #include <avogadro/core/atom.h>
10 #include <avogadro/core/bond.h>
11 #include <avogadro/core/elements.h>
12
13 #include <avogadro/molequeue/molequeuedialog.h>
14 #include <avogadro/molequeue/molequeuemanager.h>
15 #include <avogadro/qtgui/molecule.h>
16
17 #include <avogadro/molequeue/client/jobobject.h>
18 #include <qjsonarray.h>
19 #include <qjsonobject.h>
20 #include <qjsonvalue.h>
21
22 #include <QtWidgets/QFileDialog>
23 #include <QtWidgets/QMessageBox>
24 #include <QtWidgets/QProgressDialog>
25
26 #include <QtCore/QFile>
27 #include <QtCore/QSettings>
28 #include <QtCore/QString>
29 #include <QtCore/QTimer>
30
31 using Avogadro::MoleQueue::JobObject;
32 using Avogadro::MoleQueue::MoleQueueDialog;
33 using Avogadro::MoleQueue::MoleQueueManager;
34
35 namespace Avogadro::QtPlugins {
36
37 enum CalculateOption
38 {
39 CalculateSinglePoint = 0,
40 CalculateEquilibriumGeometry,
41 CalculateTransitionState,
42 CalculateForces,
43 CalculateFrequencies,
44 CalculateMakeEFP,
45
46 CalculateCount
47 };
48
49 enum TheoryOption
50 {
51 TheoryAM1 = 0,
52 TheoryPM3,
53 TheoryRHF,
54 TheoryB3LYP,
55 TheoryPBE0,
56 TheorywB97X,
57 TheorywB97XD,
58 TheoryMP2,
59 TheoryCCSDT,
60 TheoryCRCCL,
61 TheoryEOMCCSD,
62
63 TheoryCount
64 };
65
66 enum BasisOption
67 {
68 BasisSTO3G = 0,
69 BasisSTO4G,
70 BasisSTO5G,
71 BasisSTO6G,
72 BasisMINI,
73 Basis321G,
74 Basis631Gd,
75 Basis631Gdp,
76 Basis631PlusGdp,
77 Basis631PlusG2dp,
78 Basis6311PlusPlusG2dp,
79 BasisMakeEFP,
80 BasisCCD,
81 BasisCCT,
82 BasisCCQ,
83 BasisCC5,
84 BasisCC6,
85 BasisAUGCCD,
86 BasisAUGCCT,
87 BasisAUGCCQ,
88 BasisAUGCC5,
89 BasisAUGCC6,
90 BasisCorePotential,
91
92 BasisCount
93 };
94
95 enum StateOption
96 {
97 StateGas = 0,
98 StateWater,
99
100 StateCount
101 };
102
103 enum MultiplicityOption
104 {
105 MultiplicitySinglet = 0,
106 MultiplicityDoublet,
107 MultiplicityTriplet,
108
109 MultiplicityCount
110 };
111
112 enum ChargeOption
113 {
114 ChargeDication = 0,
115 ChargeCation,
116 ChargeNeutral,
117 ChargeAnion,
118 ChargeDianion,
119
120 ChargeCount
121 };
122
123 enum DispersionCorrectionOption
124 {
125 DispersionNone = 0,
126 DispersionD1,
127 DispersionD2,
128 DispersionD3,
129 DispersionD4,
130
131 DispersionCount
132 };
133
134 GamessInputDialog::GamessInputDialog(QWidget* parent_, Qt::WindowFlags f)
135 : QDialog(parent_, f), m_molecule(nullptr), m_highlighter(nullptr),
136 m_updatePending(false)
137 {
138 ui.setupUi(this);
139 m_highlighter = new GamessHighlighter(ui.previewText->document());
140
141 buildOptions();
142
143 connectBasic();
144 connectPreview();
145 connectButtons();
146
147 setBasicDefaults();
148
149 updatePreviewText();
150 }
151
152 GamessInputDialog::~GamessInputDialog() {}
153
154 void GamessInputDialog::setMolecule(QtGui::Molecule* mol)
155 {
156 if (mol == m_molecule)
157 return;
158
159 if (m_molecule)
160 m_molecule->disconnect(this);
161
162 m_molecule = mol;
163
164 connect(mol, SIGNAL(changed(unsigned int)), SLOT(updatePreviewText()));
165 connect(mol, SIGNAL(changed(unsigned int)), SLOT(updateTitlePlaceholder()));
166
167 updateTitlePlaceholder();
168 updatePreviewText();
169 }
170
171 void GamessInputDialog::showEvent(QShowEvent* e)
172 {
173 QWidget::showEvent(e);
174
175 // Update the preview text if an update was requested while hidden. Use a
176 // single shot to allow the dialog to show before popping up any warnings.
177 if (m_updatePending)
178 QTimer::singleShot(0, this, SLOT(updatePreviewText()));
179 }
180
181 void GamessInputDialog::connectBasic()
182 {
183 connect(ui.titleEdit, SIGNAL(textChanged(QString)), this,
184 SLOT(updatePreviewText()));
185 connect(ui.calculateCombo, SIGNAL(currentIndexChanged(int)), this,
186 SLOT(updatePreviewText()));
187 connect(ui.calculateCombo, SIGNAL(currentIndexChanged(int)), this,
188 SLOT(updateTitlePlaceholder()));
189 connect(ui.theoryCombo, SIGNAL(currentIndexChanged(int)), this,
190 SLOT(updatePreviewText()));
191 connect(ui.theoryCombo, SIGNAL(currentIndexChanged(int)), this,
192 SLOT(updateTitlePlaceholder()));
193 connect(ui.basisCombo, SIGNAL(currentIndexChanged(int)), this,
194 SLOT(updatePreviewText()));
195 connect(ui.basisCombo, SIGNAL(currentIndexChanged(int)), this,
196 SLOT(updateTitlePlaceholder()));
197 connect(ui.DCVerCombo, SIGNAL(currentIndexChanged(int)), this,
198 SLOT(updatePreviewText()));
199 connect(ui.DCVerCombo, SIGNAL(currentIndexChanged(int)), this,
200 SLOT(updateTitlePlaceholder()));
201 connect(ui.stateCombo, SIGNAL(currentIndexChanged(int)), this,
202 SLOT(updatePreviewText()));
203 connect(ui.multiplicityCombo, SIGNAL(currentIndexChanged(int)), this,
204 SLOT(updatePreviewText()));
205 connect(ui.chargeCombo, SIGNAL(currentIndexChanged(int)), this,
206 SLOT(updatePreviewText()));
207 connect(ui.maxscfspinBox, SIGNAL(valueChanged(int)), this,
208 SLOT(updatePreviewText()));
209 connect(ui.convergeSpinBox, SIGNAL(valueChanged(double)), this,
210 SLOT(updatePreviewText()));
211 }
212
213 void GamessInputDialog::connectPreview() {}
214
215 void GamessInputDialog::connectButtons()
216 {
217 connect(ui.resetAllButton, SIGNAL(clicked()), SLOT(resetClicked()));
218 connect(ui.defaultsButton, SIGNAL(clicked()), SLOT(defaultsClicked()));
219 connect(ui.generateButton, SIGNAL(clicked()), SLOT(generateClicked()));
220 connect(ui.computeButton, SIGNAL(clicked()), SLOT(computeClicked()));
221 connect(ui.closeButton, SIGNAL(clicked()), SLOT(close()));
222 }
223
224 void GamessInputDialog::buildOptions()
225 {
226 buildCalculateOptions();
227 buildTheoryOptions();
228 buildBasisOptions();
229 buildDispersionCorrectionOptions();
230 buildStateOptions();
231 buildMultiplicityOptions();
232 buildChargeOptions();
233 }
234
235 void GamessInputDialog::updateOptionCache()
236 {
237 m_optionCache.clear();
238 m_optionCache.insert(ui.calculateCombo, ui.calculateCombo->currentIndex());
239 m_optionCache.insert(ui.theoryCombo, ui.theoryCombo->currentIndex());
240 m_optionCache.insert(ui.basisCombo, ui.basisCombo->currentIndex());
241 m_optionCache.insert(ui.DCVerCombo, ui.DCVerCombo->currentIndex());
242 m_optionCache.insert(ui.stateCombo, ui.stateCombo->currentIndex());
243 m_optionCache.insert(ui.multiplicityCombo,
244 ui.multiplicityCombo->currentIndex());
245 m_optionCache.insert(ui.chargeCombo, ui.chargeCombo->currentIndex());
246 }
247
248 void GamessInputDialog::restoreOptionCache()
249 {
250 foreach (QComboBox* combo, m_optionCache.keys()) {
251 combo->blockSignals(true);
252 combo->setCurrentIndex(m_optionCache.value(combo, 0));
253 combo->blockSignals(false);
254 }
255 }
256
257 void GamessInputDialog::buildCalculateOptions()
258 {
259 for (int i = 0; i < static_cast<int>(CalculateCount); ++i) {
260 QString text = "";
261 switch (static_cast<CalculateOption>(i)) {
262 case CalculateSinglePoint:
263 text = tr("Single Point");
264 break;
265 case CalculateEquilibriumGeometry:
266 text = tr("Equilibrium Geometry");
267 break;
268 case CalculateForces:
269 text = tr("Forces");
270 break;
271 case CalculateTransitionState:
272 text = tr("Transition State");
273 break;
274 case CalculateFrequencies:
275 text = tr("Frequencies");
276 break;
277 case CalculateMakeEFP:
278 text = tr("Make EFP");
279 break;
280 default:
281 break;
282 }
283 ui.calculateCombo->addItem(text);
284 }
285 }
286
287 void GamessInputDialog::buildTheoryOptions()
288 {
289 for (int i = 0; i < static_cast<int>(TheoryCount); ++i) {
290 QString text = "";
291 switch (static_cast<TheoryOption>(i)) {
292 case TheoryAM1:
293 text = "AM1";
294 break;
295 case TheoryPM3:
296 text = "PM3";
297 break;
298 case TheoryRHF:
299 text = "RHF";
300 break;
301 case TheoryB3LYP:
302 text = "B3LYP";
303 break;
304 case TheoryPBE0:
305 text = "PBE0";
306 break;
307 case TheorywB97X:
308 text = "wB97X";
309 break;
310 case TheorywB97XD:
311 text = "wB97X-D";
312 break;
313 case TheoryMP2:
314 text = "MP2";
315 break;
316 case TheoryCCSDT:
317 text = "CCSD(T)";
318 break;
319 case TheoryCRCCL:
320 text = "CR-CCL";
321 break;
322 case TheoryEOMCCSD:
323 text = "EOM-CCSD";
324 break;
325 default:
326 break;
327 }
328 ui.theoryCombo->addItem(text);
329 }
330 }
331
332 void GamessInputDialog::buildBasisOptions()
333 {
334 for (int i = 0; i < static_cast<int>(BasisCount); ++i) {
335 QString text = "";
336 switch (static_cast<BasisOption>(i)) {
337 case BasisSTO3G:
338 text = "STO-3G";
339 break;
340 case BasisSTO4G:
341 text = "STO-4G";
342 break;
343 case BasisSTO5G:
344 text = "STO-5G";
345 break;
346 case BasisSTO6G:
347 text = "STO-6G";
348 break;
349 case BasisMINI:
350 text = "MINI";
351 break;
352 case Basis321G:
353 text = "3-21 G";
354 break;
355 case Basis631Gd:
356 text = "6-31 G(d)";
357 break;
358 case Basis631Gdp:
359 text = "6-31 G(d,p)";
360 break;
361 case Basis631PlusGdp:
362 text = "6-31+G(d,p)";
363 break;
364 case Basis631PlusG2dp:
365 text = "6-31+G(2d,p)";
366 break;
367 case Basis6311PlusPlusG2dp:
368 text = "6-311++G(2d,p)";
369 break;
370 case BasisMakeEFP:
371 text = "6-311++G(3df,2p)";
372 break;
373 case BasisCCD:
374 text = "cc-pVDZ";
375 break;
376 case BasisCCT:
377 text = "cc-pVTZ";
378 break;
379 case BasisCCQ:
380 text = "cc-pVQZ";
381 break;
382 case BasisCC5:
383 text = "cc-pV5Z";
384 break;
385 case BasisCC6:
386 text = "cc-pV6Z";
387 break;
388 case BasisAUGCCD:
389 text = "aug-cc-pVDZ";
390 break;
391 case BasisAUGCCT:
392 text = "aug-cc-pVTZ";
393 break;
394 case BasisAUGCCQ:
395 text = "aug-cc-pVQZ";
396 break;
397 case BasisAUGCC5:
398 text = "aug-cc-pV5Z";
399 break;
400 case BasisAUGCC6:
401 text = "aug-cc-pV6Z";
402 break;
403 case BasisCorePotential:
404 text = tr("Core Potential");
405 break;
406 default:
407 break;
408 }
409 ui.basisCombo->addItem(text);
410 }
411 }
412
413 void GamessInputDialog::buildDispersionCorrectionOptions()
414 {
415 for (int i = 0; i < static_cast<int>(DispersionCount); ++i) {
416 QString text = "";
417 switch (static_cast<DispersionCorrectionOption>(i)) {
418 case DispersionNone:
419 text = tr("None");
420 break;
421 case DispersionD1:
422 text = tr("D1");
423 break;
424 case DispersionD2:
425 text = tr("D2");
426 break;
427 case DispersionD3:
428 text = tr("D3");
429 break;
430 case DispersionD4:
431 text = tr("D4");
432 break;
433 default:
434 break;
435 }
436 ui.DCVerCombo->addItem(text);
437 }
438 }
439
440 void GamessInputDialog::buildStateOptions()
441 {
442 for (int i = 0; i < static_cast<int>(StateCount); ++i) {
443 QString text = "";
444 switch (static_cast<StateOption>(i)) {
445 case StateGas:
446 text = tr("Gas");
447 break;
448 case StateWater:
449 text = tr("Water");
450 break;
451 default:
452 break;
453 }
454 ui.stateCombo->addItem(text);
455 }
456 }
457
458 void GamessInputDialog::buildMultiplicityOptions()
459 {
460 for (int i = 0; i < static_cast<int>(MultiplicityCount); ++i) {
461 QString text = "";
462 switch (static_cast<MultiplicityOption>(i)) {
463 case MultiplicitySinglet:
464 text = tr("Singlet");
465 break;
466 case MultiplicityDoublet:
467 text = tr("Doublet");
468 break;
469 case MultiplicityTriplet:
470 text = tr("Triplet");
471 break;
472 default:
473 break;
474 }
475 ui.multiplicityCombo->addItem(text);
476 }
477 }
478
479 void GamessInputDialog::buildChargeOptions()
480 {
481 for (int i = 0; i < static_cast<int>(ChargeCount); ++i) {
482 QString text = "";
483 switch (static_cast<ChargeOption>(i)) {
484 case ChargeDication:
485 text = tr("Dication");
486 break;
487 case ChargeCation:
488 text = tr("Cation");
489 break;
490 case ChargeNeutral:
491 text = tr("Neutral");
492 break;
493 case ChargeAnion:
494 text = tr("Anion");
495 break;
496 case ChargeDianion:
497 text = tr("Dianion");
498 break;
499 default:
500 break;
501 }
502 ui.chargeCombo->addItem(text);
503 }
504 }
505
506 void GamessInputDialog::setBasicDefaults()
507 {
508 ui.titleEdit->setText(QString());
509 ui.calculateCombo->setCurrentIndex(CalculateSinglePoint);
510 ui.theoryCombo->setCurrentIndex(TheorywB97X);
511 ui.basisCombo->setCurrentIndex(Basis631Gd);
512 ui.DCVerCombo->setCurrentIndex(DispersionD4);
513 ui.stateCombo->setCurrentIndex(StateGas);
514 ui.multiplicityCombo->setCurrentIndex(MultiplicitySinglet);
515 ui.chargeCombo->setCurrentIndex(ChargeNeutral);
516 }
517
518 QString GamessInputDialog::generateJobTitle() const
519 {
520 QString calculation(ui.calculateCombo->currentText());
521 QString theory(ui.theoryCombo->currentText());
522 QString basis(ui.basisCombo->currentText());
523 QString formula(m_molecule ? QString::fromStdString(m_molecule->formula())
524 : tr("[no molecule]"));
525
526 // Merge theory/basis into theory
527 theory += "/" + basis;
528 theory.replace(QRegularExpression("\\s+"), "");
529
530 return QString("%1 | %2 | %3").arg(formula, calculation, theory);
531 }
532
533 void GamessInputDialog::updatePreviewText()
534 {
535 // If the dialog is not shown, delay the update in case we need to prompt the
536 // user to overwrite changes. Set the m_updatePending flag to true so we'll
537 // know to update in the show event.
538 if (!isVisible()) {
539 m_updatePending = true;
540 return;
541 }
542
543 m_updatePending = false;
544
545 // Has the preview text been modified?
546 if (ui.previewText->document()->isModified()) {
547 QString message = tr("The input file has been modified. "
548 "Would you like to overwrite your changes to reflect "
549 "the new geometry or job options?");
550 int response = QMessageBox::question(
551 this, tr("Overwrite modified input file?"), message,
552 QMessageBox::Yes | QMessageBox::No, QMessageBox::No);
553 if (static_cast<QMessageBox::StandardButton>(response) !=
554 QMessageBox::Yes) {
555 restoreOptionCache();
556 return;
557 }
558 }
559
560 // Gather options:
561 QString title(ui.titleEdit->text());
562 if (title.isEmpty())
563 title = generateJobTitle();
564
565 auto calculate(
566 static_cast<CalculateOption>(ui.calculateCombo->currentIndex()));
567 auto theory(static_cast<TheoryOption>(ui.theoryCombo->currentIndex()));
568 auto basis(static_cast<BasisOption>(ui.basisCombo->currentIndex()));
569 auto dispersion(
570 static_cast<DispersionCorrectionOption>(ui.DCVerCombo->currentIndex()));
571 auto state(static_cast<StateOption>(ui.stateCombo->currentIndex()));
572 auto multiplicity(
573 static_cast<MultiplicityOption>(ui.multiplicityCombo->currentIndex()));
574 auto charge(static_cast<ChargeOption>(ui.chargeCombo->currentIndex()));
575
576 // Disable basis selection for semiempirical methods.
577 ui.basisCombo->setEnabled(theory != TheoryAM1 && theory != TheoryPM3);
578 bool is_dft = (theory == TheoryB3LYP || theory == TheoryPBE0 ||
579 theory == TheorywB97X || theory == TheorywB97XD);
580 ui.DCVerCombo->setEnabled(is_dft);
581
582 // Generate text.
583 // Variables:
584 QString runTyp;
585 QString scfTyp;
586 QString gBasis;
587 QString mult;
588 QString iCharg;
589
590 // Extra options for lines
591 QString extraBasis;
592 QString extraContrl;
593 QString extraDFT;
594
595 // Optional lines
596 QString statPt;
597 QString force;
598 QString pcm;
599 QString maxSCF = QString::number(ui.maxscfspinBox->value());
600 QString convthresh = QString::number(ui.convergeSpinBox->value());
601
602 switch (calculate) {
603 case CalculateSinglePoint:
604 runTyp = "ENERGY";
605 break;
606 case CalculateEquilibriumGeometry:
607 runTyp = "OPTIMIZE";
608 statPt = " $STATPT OPTTOL=0.0001 NSTEP=20 $END\n";
609 break;
610 case CalculateTransitionState:
611 runTyp = "SADPOINT";
612 statPt = " $STATPT OPTTOL=0.0001 NSTEP=20 $END\n";
613 break;
614 case CalculateForces:
615 runTyp = "FORCE";
616 force = " $FORCE METHOD=ANALYTIC $END\n";
617 break;
618 case CalculateFrequencies:
619 runTyp = "HESSIAN";
620 force = " $FORCE METHOD=ANALYTIC VIBANL=.TRUE. $END\n";
621 break;
622 case CalculateMakeEFP:
623 runTyp = "MAKEFP";
624 basis = BasisMakeEFP;
625 break;
626 default:
627 break;
628 }
629
630 switch (theory) {
631 case TheoryAM1:
632 gBasis = "AM1";
633 break;
634 case TheoryPM3:
635 gBasis = "PM3";
636 break;
637 case TheoryRHF:
638 break;
639 case TheoryB3LYP:
640 extraDFT += " DFTTYP=B3LYP";
641 break;
642 case TheoryPBE0:
643 extraDFT += " DFTTYP=PBE0";
644 break;
645 case TheorywB97X:
646 extraDFT += " DFTTYP=wB97X";
647 break;
648 case TheorywB97XD:
649 extraDFT += " DFTTYP=wB97X-D";
650 break;
651 case TheoryMP2:
652 extraContrl += " MPLEVL=2";
653 break;
654 case TheoryCCSDT:
655 extraContrl += " CCTYP=CCSD(T)";
656 break;
657 case TheoryCRCCL:
658 extraContrl += " CCTYP=CR-CCL";
659 break;
660 case TheoryEOMCCSD:
661 extraContrl += " CCTYP=EOM-CCSD";
662 break;
663 default:
664 break;
665 }
666
667 if (theory != TheoryAM1 && theory != TheoryPM3) {
668 switch (basis) {
669 case BasisSTO3G:
670 gBasis = "STO";
671 extraBasis += " NGAUSS=3";
672 break;
673 case BasisSTO4G:
674 gBasis = "STO";
675 extraBasis += " NGAUSS=4";
676 break;
677 case BasisSTO5G:
678 gBasis = "STO";
679 extraBasis += " NGAUSS=5";
680 break;
681 case BasisSTO6G:
682 gBasis = "STO";
683 extraBasis += " NGAUSS=6";
684 break;
685 case BasisMINI:
686 gBasis = "MINI";
687 break;
688 case Basis321G:
689 gBasis = "N21";
690 extraBasis += " NGAUSS=3";
691 break;
692 case Basis631Gd:
693 gBasis = "N31";
694 extraBasis += " NGAUSS=6 NDFUNC=1";
695 break;
696 case Basis631Gdp:
697 gBasis = "N31";
698 extraBasis += " NGAUSS=6 NDFUNC=1 NPFUNC=1";
699 break;
700 case Basis631PlusGdp:
701 gBasis = "N31";
702 extraBasis += " NGAUSS=6 NDFUNC=1 NPFUNC=1 DIFFSP=.TRUE.";
703 break;
704 case Basis631PlusG2dp:
705 gBasis = "N31";
706 extraBasis += " NGAUSS=6 NDFUNC=2 NPFUNC=1 DIFFSP=.TRUE.";
707 break;
708 case Basis6311PlusPlusG2dp:
709 gBasis = "N311";
710 extraBasis += " NGAUSS=6 NDFUNC=2 NPFUNC=1 DIFFSP=.TRUE. DIFFS=.TRUE.";
711 break;
712 case BasisMakeEFP:
713 gBasis = "N311";
714 extraBasis +=
715 " NGAUSS=6 NDFUNC=3 NPFUNC=2 NFFUNC=3 \n DIFFSP=.TRUE. DIFFS=.TRUE.";
716 break;
717 case BasisCCD:
718 gBasis = "ccd";
719 break;
720 case BasisCCT:
721 gBasis = "cct";
722 break;
723 case BasisCCQ:
724 gBasis = "ccq";
725 break;
726 case BasisCC5:
727 gBasis = "cc5";
728 break;
729 case BasisCC6:
730 gBasis = "cc6";
731 break;
732 case BasisAUGCCD:
733 gBasis = "accd";
734 break;
735 case BasisAUGCCT:
736 gBasis = "acct";
737 break;
738 case BasisAUGCCQ:
739 gBasis = "accq";
740 break;
741 case BasisAUGCC5:
742 gBasis = "acc5";
743 break;
744 case BasisAUGCC6:
745 gBasis = "acc6";
746 break;
747 case BasisCorePotential:
748 gBasis = "SBK";
749 extraBasis += " NGAUSS=3 NDFUNC=1";
750 extraContrl += " ECP=SBK";
751 break;
752 default:
753 break;
754 }
755 }
756
757 switch (state) {
758 case StateGas:
759 break;
760 case StateWater:
761 pcm = " $PCM SOLVNT=WATER $END\n";
762 break;
763 default:
764 break;
765 }
766
767 switch (multiplicity) {
768 case MultiplicitySinglet:
769 scfTyp = "RHF";
770 mult = "1";
771 break;
772 case MultiplicityDoublet:
773 scfTyp = "ROHF";
774 mult = "2";
775 break;
776 case MultiplicityTriplet:
777 scfTyp = "ROHF";
778 mult = "3";
779 break;
780 default:
781 break;
782 }
783
784 switch (charge) {
785 case ChargeDication:
786 iCharg = "2";
787 break;
788 case ChargeCation:
789 iCharg = "1";
790 break;
791 case ChargeNeutral:
792 iCharg = "0";
793 break;
794 case ChargeAnion:
795 iCharg = "-1";
796 break;
797 case ChargeDianion:
798 iCharg = "-2";
799 break;
800 default:
801 break;
802 }
803
804 if (is_dft) {
805 switch (dispersion) {
806 case DispersionNone:
807 extraDFT += " DC=.F. ";
808 break;
809 case DispersionD1:
810 extraDFT += " DC=.T. IDCVER=1";
811 break;
812 case DispersionD2:
813 extraDFT += " DC=.T. IDCVER=2";
814 break;
815 case DispersionD3:
816 extraDFT += " DC=.T. IDCVER=3";
817 break;
818 case DispersionD4:
819 extraDFT += " DC=.T. IDCVER=4";
820 break;
821 default:
822 break;
823 }
824 }
825
826 // build up the input file:
827 QString file;
828 file += "! Input file generated by Avogadro\n";
829 file += QString(" $BASIS GBASIS=%1%2 $END\n").arg(gBasis, extraBasis);
830 file += pcm;
831 file += QString(" $CONTRL SCFTYP=%1 RUNTYP=%2 ICHARG=%3 MULT=%4%5 $END\n")
832 .arg(scfTyp, runTyp, iCharg, mult, extraContrl);
833 file += QString(" $CONTRL ISPHER=1 MAXIT=%1 $END\n").arg(maxSCF);
834 file += QString(" $SCF DIRSCF=.T. CONV=%1 $END\n").arg(convthresh);
835 if (is_dft) {
836 file += QString(" $DFT %1 $END\n").arg(extraDFT);
837 }
838 file += statPt;
839 file += force;
840 file += "\n";
841 file += " $DATA\n";
842 file += QString("%1\n").arg(title);
843 file += "C1\n";
844
845 if (m_molecule) {
846 for (size_t i = 0; i < m_molecule->atomCount(); ++i) {
847 Core::Atom atom = m_molecule->atom(i);
848 file += QString("%1 %2 %3 %4 %5\n")
849 .arg(Core::Elements::symbol(atom.atomicNumber()), -3)
850 .arg(static_cast<float>(atom.atomicNumber()), 5, 'f', 1)
851 .arg(atom.position3d().x(), 9, 'f', 5)
852 .arg(atom.position3d().y(), 9, 'f', 5)
853 .arg(atom.position3d().z(), 9, 'f', 5);
854 }
855 }
856
857 file += " $END\n";
858
859 ui.previewText->setText(file);
860 ui.previewText->document()->setModified(false);
861 updateOptionCache();
862 }
863
864 void GamessInputDialog::resetClicked()
865 {
866 setBasicDefaults();
867 updatePreviewText();
868 }
869
870 void GamessInputDialog::defaultsClicked()
871 {
872 setBasicDefaults();
873 updatePreviewText();
874 }
875
876 void GamessInputDialog::generateClicked()
877 {
878 QSettings settings;
879 QString fileName =
880 (ui.baseNameEdit->text().isEmpty() ? ui.baseNameEdit->placeholderText()
881 : ui.baseNameEdit->text()) +
882 ".inp";
883 QString targetFile =
884 settings.value("gamessInput/outputDirectory", QDir::homePath()).toString();
885 targetFile =
886 QDir(QFileInfo(targetFile).absoluteDir()).absoluteFilePath(fileName);
887
888 fileName = QFileDialog::getSaveFileName(this, tr("Save GAMESS input file"),
889 targetFile);
890
891 // User cancel:
892 if (fileName.isNull())
893 return;
894
895 settings.setValue("gamessInput/outputDirectory", fileName);
896
897 QFile file(fileName);
898 bool success = false;
899 if (file.open(QFile::WriteOnly | QFile::Text)) {
900 if (file.write(ui.previewText->toPlainText().toLocal8Bit()) > 0) {
901 success = true;
902 }
903 file.close();
904 }
905
906 if (!success) {
907 QMessageBox::critical(this, tr("Output Error"),
908 tr("Failed to write to file %1.").arg(fileName));
909 }
910 }
911
912 void GamessInputDialog::computeClicked()
913 {
914 // Verify that molequeue is running:
915 MoleQueueManager& mqManager = MoleQueueManager::instance();
916 if (!mqManager.connectIfNeeded()) {
917 QMessageBox::information(this, tr("Cannot connect to MoleQueue"),
918 tr("Cannot connect to MoleQueue server. Please "
919 "ensure that it is running and try again."));
920 return;
921 }
922
923 QString description(ui.titleEdit->text());
924 if (description.isEmpty())
925 description = generateJobTitle();
926
927 QString fileNameBase = ui.baseNameEdit->text().isEmpty()
928 ? ui.baseNameEdit->placeholderText()
929 : ui.baseNameEdit->text();
930
931 JobObject job;
932 job.setProgram("GAMESS");
933 job.setDescription(description);
934 job.setInputFile(QString("%1.inp").arg(fileNameBase),
935 ui.previewText->toPlainText());
936
937 MoleQueueDialog::SubmitStatus submitStatus =
938 MoleQueueDialog::submitJob(this, tr("Submit GAMESS Calculation"), job,
939 MoleQueueDialog::WaitForSubmissionResponse |
940 MoleQueueDialog::SelectProgramFromTemplate);
941
942 switch (submitStatus) {
943 default:
944 case MoleQueueDialog::SubmissionSuccessful:
945 case MoleQueueDialog::SubmissionFailed:
946 case MoleQueueDialog::SubmissionAttempted:
947 case MoleQueueDialog::SubmissionAborted:
948 // The dialog handles these cases adequately, we don't need to do
949 // anything.
950 break;
951
952 case MoleQueueDialog::JobFailed:
953 // Inform the user:
954 QMessageBox::information(this, tr("Job Failed"),
955 tr("The job did not complete successfully."),
956 QMessageBox::Ok);
957 break;
958
959 case MoleQueueDialog::JobFinished:
960 // Let the world know that the job is ready to open. job has been
961 // overwritten with the final job details.
962 emit openJobOutput(job);
963 hide();
964 break;
965 }
966 }
967
968 void GamessInputDialog::updateTitlePlaceholder()
969 {
970 ui.titleEdit->setPlaceholderText(generateJobTitle());
971 }
972
973 } // namespace Avogadro::QtPlugins