| 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 "cp2kinputdialog.h" |
| 7 |
|
| 8 |
#include <avogadro/core/atom.h> |
| 9 |
#include <avogadro/core/bond.h> |
| 10 |
#include <avogadro/core/elements.h> |
| 11 |
#include <avogadro/core/unitcell.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 |
#include <map> |
| 32 |
#include <vector> |
| 33 |
|
| 34 |
using Avogadro::MoleQueue::JobObject; |
| 35 |
using Avogadro::MoleQueue::MoleQueueDialog; |
| 36 |
using Avogadro::MoleQueue::MoleQueueManager; |
| 37 |
|
| 38 |
namespace Avogadro::QtPlugins { |
| 39 |
|
| 40 |
enum FunctionalOption |
| 41 |
{ |
| 42 |
FunctionalBLYP = 0, |
| 43 |
FunctionalBP, |
| 44 |
FunctionalHCTH120, |
| 45 |
FunctionalPADE, |
| 46 |
FunctionalPBE, |
| 47 |
|
| 48 |
FunctionalCount |
| 49 |
}; |
| 50 |
|
| 51 |
enum MethodOption |
| 52 |
{ |
| 53 |
DFT = 0, |
| 54 |
MolecularMechanics, |
| 55 |
HybridQuantumClassical, |
| 56 |
|
| 57 |
MethodCount |
| 58 |
}; |
| 59 |
|
| 60 |
// MM tab |
| 61 |
enum EWALDTypeOption |
| 62 |
{ |
| 63 |
EWALD = 0, |
| 64 |
ewaldNONE, |
| 65 |
PME, |
| 66 |
SPME, |
| 67 |
|
| 68 |
EWALDTypeCount |
| 69 |
}; |
| 70 |
// QM tab |
| 71 |
enum SCFGuessOption |
| 72 |
{ |
| 73 |
ATOMIC = 0, |
| 74 |
CORE, |
| 75 |
DENSITIES, |
| 76 |
HISTORY_RESTART, |
| 77 |
MOPAC, |
| 78 |
scfNONE, |
| 79 |
RANDOM, |
| 80 |
RESTART, |
| 81 |
SPARSE, |
| 82 |
|
| 83 |
SCFGuessCount |
| 84 |
}; |
| 85 |
|
| 86 |
enum OTMinimizerOption |
| 87 |
{ |
| 88 |
CG = 0, |
| 89 |
BROYDEN, |
| 90 |
DIIS, |
| 91 |
SD, |
| 92 |
|
| 93 |
OTMinimizerCount |
| 94 |
}; |
| 95 |
|
| 96 |
Cp2kInputDialog::Cp2kInputDialog(QWidget* parent_, Qt::WindowFlags f) |
| 97 |
: QDialog(parent_, f), m_molecule(nullptr), |
| 98 |
// m_highlighter(NULL), |
| 99 |
m_updatePending(false) |
| 100 |
{ |
| 101 |
ui.setupUi(this); |
| 102 |
// m_highlighter = new Cp2kHighlighter(ui.previewText->document()); |
| 103 |
|
| 104 |
buildOptions(); |
| 105 |
|
| 106 |
connectBasic(); |
| 107 |
connectPreview(); |
| 108 |
connectButtons(); |
| 109 |
|
| 110 |
setBasicDefaults(); |
| 111 |
|
| 112 |
updatePreviewText(); |
| 113 |
} |
| 114 |
|
| 115 |
Cp2kInputDialog::~Cp2kInputDialog() {} |
| 116 |
|
| 117 |
void Cp2kInputDialog::setMolecule(QtGui::Molecule* mol) |
| 118 |
{ |
| 119 |
if (mol == m_molecule) |
| 120 |
return; |
| 121 |
|
| 122 |
if (m_molecule) |
| 123 |
m_molecule->disconnect(this); |
| 124 |
|
| 125 |
m_molecule = mol; |
| 126 |
|
| 127 |
connect(mol, SIGNAL(changed(unsigned int)), SLOT(updatePreviewText())); |
| 128 |
connect(mol, SIGNAL(changed(unsigned int)), SLOT(updateTitlePlaceholder())); |
| 129 |
|
| 130 |
updateTitlePlaceholder(); |
| 131 |
updatePreviewText(); |
| 132 |
} |
| 133 |
|
| 134 |
void Cp2kInputDialog::showEvent(QShowEvent* e) |
| 135 |
{ |
| 136 |
QWidget::showEvent(e); |
| 137 |
|
| 138 |
// Update the preview text if an update was requested while hidden. Use a |
| 139 |
// single shot to allow the dialog to show before popping up any warnings. |
| 140 |
if (m_updatePending) |
| 141 |
QTimer::singleShot(0, this, SLOT(updatePreviewText())); |
| 142 |
} |
| 143 |
|
| 144 |
void Cp2kInputDialog::connectBasic() |
| 145 |
{ |
| 146 |
connect(ui.titleEdit, SIGNAL(textChanged(QString)), this, |
| 147 |
SLOT(updatePreviewText())); |
| 148 |
connect(ui.calculateCombo, SIGNAL(currentIndexChanged(int)), this, |
| 149 |
SLOT(updatePreviewText())); |
| 150 |
connect(ui.calculateCombo, SIGNAL(currentIndexChanged(int)), this, |
| 151 |
SLOT(updateTitlePlaceholder())); |
| 152 |
connect(ui.functionalCombo, SIGNAL(currentIndexChanged(int)), this, |
| 153 |
SLOT(updatePreviewText())); |
| 154 |
connect(ui.functionalCombo, SIGNAL(currentIndexChanged(int)), this, |
| 155 |
SLOT(updateTitlePlaceholder())); |
| 156 |
connect(ui.basisCombo, SIGNAL(currentIndexChanged(int)), this, |
| 157 |
SLOT(updatePreviewText())); |
| 158 |
connect(ui.basisCombo, SIGNAL(currentIndexChanged(int)), this, |
| 159 |
SLOT(updateTitlePlaceholder())); |
| 160 |
connect(ui.methodCombo, SIGNAL(currentIndexChanged(int)), this, |
| 161 |
SLOT(updatePreviewText())); |
| 162 |
connect(ui.ewaldtypeCombo, SIGNAL(currentIndexChanged(int)), this, |
| 163 |
SLOT(updatePreviewText())); |
| 164 |
connect(ui.emaxSplineSpin, SIGNAL(valueChanged(double)), this, |
| 165 |
SLOT(updatePreviewText())); |
| 166 |
connect(ui.rcutnbSplineSpin, SIGNAL(valueChanged(double)), this, |
| 167 |
SLOT(updatePreviewText())); |
| 168 |
connect(ui.ewaldalphaSpin, SIGNAL(valueChanged(double)), this, |
| 169 |
SLOT(updatePreviewText())); |
| 170 |
connect(ui.ewaldgmaxSpin, SIGNAL(valueChanged(double)), this, |
| 171 |
SLOT(updatePreviewText())); |
| 172 |
connect(ui.lsdcheckBox, SIGNAL(stateChanged(bool)), this, |
| 173 |
SLOT(updatePreviewText())); |
| 174 |
connect(ui.maxscfspinBox, SIGNAL(valueChanged(int)), this, |
| 175 |
SLOT(updatePreviewText())); |
| 176 |
connect(ui.epsscfSpinBox, SIGNAL(valueChanged(double)), this, |
| 177 |
SLOT(updatePreviewText())); |
| 178 |
connect(ui.outerMaxscfSpinBox, SIGNAL(valueChanged(int)), this, |
| 179 |
SLOT(updatePreviewText())); |
| 180 |
connect(ui.outerEpsscfSpinBox, SIGNAL(valueChanged(double)), this, |
| 181 |
SLOT(updatePreviewText())); |
| 182 |
connect(ui.scfguessComboBox, SIGNAL(currentIndexChanged(int)), this, |
| 183 |
SLOT(updatePreviewText())); |
| 184 |
connect(ui.otminimizerComboBox, SIGNAL(currentIndexChanged(int)), this, |
| 185 |
SLOT(updatePreviewText())); |
| 186 |
} |
| 187 |
|
| 188 |
void Cp2kInputDialog::connectPreview() {} |
| 189 |
|
| 190 |
void Cp2kInputDialog::connectButtons() |
| 191 |
{ |
| 192 |
connect(ui.resetAllButton, SIGNAL(clicked()), SLOT(resetClicked())); |
| 193 |
connect(ui.defaultsButton, SIGNAL(clicked()), SLOT(defaultsClicked())); |
| 194 |
connect(ui.generateButton, SIGNAL(clicked()), SLOT(generateClicked())); |
| 195 |
connect(ui.computeButton, SIGNAL(clicked()), SLOT(computeClicked())); |
| 196 |
connect(ui.closeButton, SIGNAL(clicked()), SLOT(close())); |
| 197 |
} |
| 198 |
|
| 199 |
void Cp2kInputDialog::buildOptions() |
| 200 |
{ |
| 201 |
buildCalculateOptions(); |
| 202 |
buildFunctionalOptions(); |
| 203 |
buildBasisOptions(); |
| 204 |
buildMethodOptions(); |
| 205 |
buildEWALDTypeOptions(); |
| 206 |
buildSCFGuessOptions(); |
| 207 |
buildOTMinimizerOptions(); |
| 208 |
} |
| 209 |
|
| 210 |
void Cp2kInputDialog::updateOptionCache() |
| 211 |
{ |
| 212 |
m_optionCache.clear(); |
| 213 |
m_optionCache.insert(ui.calculateCombo, ui.calculateCombo->currentIndex()); |
| 214 |
m_optionCache.insert(ui.functionalCombo, ui.functionalCombo->currentIndex()); |
| 215 |
m_optionCache.insert(ui.basisCombo, ui.basisCombo->currentIndex()); |
| 216 |
m_optionCache.insert(ui.methodCombo, ui.methodCombo->currentIndex()); |
| 217 |
m_optionCache.insert(ui.ewaldtypeCombo, ui.ewaldtypeCombo->currentIndex()); |
| 218 |
m_optionCache.insert(ui.scfguessComboBox, |
| 219 |
ui.scfguessComboBox->currentIndex()); |
| 220 |
m_optionCache.insert(ui.otminimizerComboBox, |
| 221 |
ui.otminimizerComboBox->currentIndex()); |
| 222 |
} |
| 223 |
|
| 224 |
void Cp2kInputDialog::restoreOptionCache() |
| 225 |
{ |
| 226 |
foreach (QComboBox* combo, m_optionCache.keys()) { |
| 227 |
combo->blockSignals(true); |
| 228 |
combo->setCurrentIndex(m_optionCache.value(combo, 0)); |
| 229 |
combo->blockSignals(false); |
| 230 |
} |
| 231 |
} |
| 232 |
|
| 233 |
QString Cp2kInputDialog::fromCalcEnum(CalculateOption option) |
| 234 |
{ |
| 235 |
switch (option) { |
| 236 |
case CalculateEnergy: |
| 237 |
return "ENERGY"; |
| 238 |
case CalculateEnergyAndForces: |
| 239 |
return "ENERGY_FORCE"; |
| 240 |
case CalculateMolecularDynamics: |
| 241 |
return "MOLECULAR_DYNAMICS"; |
| 242 |
case CalculateGeometryOptimization: |
| 243 |
return "GEO_OPT"; |
| 244 |
default: |
| 245 |
throw std::invalid_argument{ __func__ }; // unreachable |
| 246 |
} |
| 247 |
} |
| 248 |
|
| 249 |
void Cp2kInputDialog::buildCalculateOptions() |
| 250 |
{ |
| 251 |
for (int i = 0; i < static_cast<int>(CalculateCount); ++i) { |
| 252 |
QString text = ""; |
| 253 |
switch (static_cast<CalculateOption>(i)) { |
| 254 |
case CalculateEnergy: |
| 255 |
text = tr("Energy"); |
| 256 |
break; |
| 257 |
case CalculateEnergyAndForces: |
| 258 |
text = tr("Energy and Forces"); |
| 259 |
break; |
| 260 |
case CalculateMolecularDynamics: |
| 261 |
text = tr("Molecular Dynamics"); |
| 262 |
break; |
| 263 |
case CalculateGeometryOptimization: |
| 264 |
text = tr("Geometry Optimization"); |
| 265 |
break; |
| 266 |
default: |
| 267 |
break; |
| 268 |
} |
| 269 |
ui.calculateCombo->addItem(text); |
| 270 |
} |
| 271 |
} |
| 272 |
|
| 273 |
void Cp2kInputDialog::buildFunctionalOptions() |
| 274 |
{ |
| 275 |
for (int i = 0; i < static_cast<int>(FunctionalCount); ++i) { |
| 276 |
QString text = ""; |
| 277 |
switch (static_cast<FunctionalOption>(i)) { |
| 278 |
case FunctionalBLYP: |
| 279 |
text = "BLYP"; |
| 280 |
break; |
| 281 |
case FunctionalBP: |
| 282 |
text = "BP"; |
| 283 |
break; |
| 284 |
case FunctionalHCTH120: |
| 285 |
text = "HCTH120"; |
| 286 |
break; |
| 287 |
case FunctionalPADE: |
| 288 |
text = "PADE"; |
| 289 |
break; |
| 290 |
case FunctionalPBE: |
| 291 |
text = "PBE"; |
| 292 |
break; |
| 293 |
default: |
| 294 |
break; |
| 295 |
} |
| 296 |
ui.functionalCombo->addItem(text); |
| 297 |
} |
| 298 |
} |
| 299 |
|
| 300 |
void Cp2kInputDialog::buildBasisOptions() |
| 301 |
{ |
| 302 |
for (int i = 0; i < static_cast<int>(BasisCount); ++i) { |
| 303 |
QString text = ""; |
| 304 |
switch (static_cast<BasisOption>(i)) { |
| 305 |
case BasisSZVGTH: |
| 306 |
text = "SZV-GTH"; |
| 307 |
break; |
| 308 |
case BasisDZVGTH: |
| 309 |
text = "DZV-GTH"; |
| 310 |
break; |
| 311 |
case BasisDZVPGTH: |
| 312 |
text = "DZVP-GTH"; |
| 313 |
break; |
| 314 |
case BasisTZVPGTH: |
| 315 |
text = "TZVP-GTH"; |
| 316 |
break; |
| 317 |
case BasisTZV2PGTH: |
| 318 |
text = "TZV2P-GTH"; |
| 319 |
break; |
| 320 |
default: |
| 321 |
break; |
| 322 |
} |
| 323 |
ui.basisCombo->addItem(text); |
| 324 |
} |
| 325 |
} |
| 326 |
|
| 327 |
void Cp2kInputDialog::buildMethodOptions() |
| 328 |
{ |
| 329 |
for (int i = 0; i < static_cast<int>(MethodCount); ++i) { |
| 330 |
QString text = ""; |
| 331 |
switch (static_cast<MethodOption>(i)) { |
| 332 |
case DFT: |
| 333 |
text = tr("Electronic structure methods (DFT)"); |
| 334 |
break; |
| 335 |
case MolecularMechanics: |
| 336 |
text = tr("Molecular Mechanics"); |
| 337 |
break; |
| 338 |
case HybridQuantumClassical: |
| 339 |
text = tr("Hybrid quantum classical (Not yet supported)"); |
| 340 |
break; |
| 341 |
default: |
| 342 |
break; |
| 343 |
} |
| 344 |
ui.methodCombo->addItem(text); |
| 345 |
} |
| 346 |
} |
| 347 |
|
| 348 |
void Cp2kInputDialog::buildEWALDTypeOptions() |
| 349 |
{ |
| 350 |
for (int i = 0; i < static_cast<int>(EWALDTypeCount); ++i) { |
| 351 |
QString text = ""; |
| 352 |
switch (static_cast<EWALDTypeOption>(i)) { |
| 353 |
case EWALD: |
| 354 |
text = tr("EWALD"); |
| 355 |
break; |
| 356 |
case ewaldNONE: |
| 357 |
text = tr("NONE"); |
| 358 |
break; |
| 359 |
case PME: |
| 360 |
text = tr("PME"); |
| 361 |
break; |
| 362 |
case SPME: |
| 363 |
text = tr("SPME"); |
| 364 |
break; |
| 365 |
default: |
| 366 |
break; |
| 367 |
} |
| 368 |
ui.ewaldtypeCombo->addItem(text); |
| 369 |
} |
| 370 |
} |
| 371 |
void Cp2kInputDialog::buildSCFGuessOptions() |
| 372 |
{ |
| 373 |
for (int i = 0; i < static_cast<int>(SCFGuessCount); ++i) { |
| 374 |
QString text = ""; |
| 375 |
switch (static_cast<SCFGuessOption>(i)) { |
| 376 |
case ATOMIC: |
| 377 |
text = tr("ATOMIC"); |
| 378 |
break; |
| 379 |
case CORE: |
| 380 |
text = tr("CORE"); |
| 381 |
break; |
| 382 |
case DENSITIES: |
| 383 |
text = tr("DENSITIES"); |
| 384 |
break; |
| 385 |
case HISTORY_RESTART: |
| 386 |
text = tr("HISTORY_RESTART"); |
| 387 |
break; |
| 388 |
case MOPAC: |
| 389 |
text = tr("MOPAC"); |
| 390 |
break; |
| 391 |
case scfNONE: |
| 392 |
text = tr("NONE"); |
| 393 |
break; |
| 394 |
case RANDOM: |
| 395 |
text = tr("RANDOM"); |
| 396 |
break; |
| 397 |
case RESTART: |
| 398 |
text = tr("RESTART"); |
| 399 |
break; |
| 400 |
case SPARSE: |
| 401 |
text = tr("SPARSE"); |
| 402 |
break; |
| 403 |
default: |
| 404 |
break; |
| 405 |
} |
| 406 |
ui.scfguessComboBox->addItem(text); |
| 407 |
} |
| 408 |
} |
| 409 |
void Cp2kInputDialog::buildOTMinimizerOptions() |
| 410 |
{ |
| 411 |
for (int i = 0; i < static_cast<int>(OTMinimizerCount); ++i) { |
| 412 |
QString text = ""; |
| 413 |
switch (static_cast<OTMinimizerOption>(i)) { |
| 414 |
case BROYDEN: |
| 415 |
text = tr("BROYDEN"); |
| 416 |
break; |
| 417 |
case CG: |
| 418 |
text = tr("Conjugate Gradients"); |
| 419 |
break; |
| 420 |
case DIIS: |
| 421 |
text = tr("DIIS"); |
| 422 |
break; |
| 423 |
case SD: |
| 424 |
text = tr("Steepest descent"); |
| 425 |
break; |
| 426 |
default: |
| 427 |
break; |
| 428 |
} |
| 429 |
ui.otminimizerComboBox->addItem(text); |
| 430 |
} |
| 431 |
} |
| 432 |
|
| 433 |
void Cp2kInputDialog::setBasicDefaults() |
| 434 |
{ |
| 435 |
ui.titleEdit->setText(QString()); |
| 436 |
ui.calculateCombo->setCurrentIndex(CalculateEnergy); |
| 437 |
ui.functionalCombo->setCurrentIndex(FunctionalBLYP); |
| 438 |
ui.basisCombo->setCurrentIndex(BasisSZVGTH); |
| 439 |
ui.methodCombo->setCurrentIndex(DFT); |
| 440 |
ui.ewaldtypeCombo->setCurrentIndex(SPME); |
| 441 |
ui.scfguessComboBox->setCurrentIndex(ATOMIC); |
| 442 |
ui.otminimizerComboBox->setCurrentIndex(CG); |
| 443 |
} |
| 444 |
|
| 445 |
QString Cp2kInputDialog::generateJobTitle() const |
| 446 |
{ |
| 447 |
QString calculation(fromCalcEnum( |
| 448 |
static_cast<CalculateOption>(ui.calculateCombo->currentIndex()))); |
| 449 |
QString basis(ui.basisCombo->currentText()); |
| 450 |
QString formula(m_molecule ? QString::fromStdString(m_molecule->formula()) |
| 451 |
: tr("[no molecule]")); |
| 452 |
|
| 453 |
// Merge theory/basis into theory |
| 454 |
// replace(QRegExp("\\s+"), ""); |
| 455 |
|
| 456 |
return QString("%1_%2_%3").arg(formula, calculation, basis); |
| 457 |
} |
| 458 |
|
| 459 |
void Cp2kInputDialog::updatePreviewText() |
| 460 |
{ |
| 461 |
std::map<QString, int> valencee; |
| 462 |
|
| 463 |
valencee["H"] = 1; |
| 464 |
valencee["He"] = 2; // Z=2 |
| 465 |
valencee["Li"] = 3; |
| 466 |
valencee["Be"] = 4; |
| 467 |
valencee["B"] = 3; |
| 468 |
valencee["C"] = 4; |
| 469 |
valencee["N"] = 5; |
| 470 |
valencee["O"] = 6; |
| 471 |
valencee["F"] = 7; |
| 472 |
valencee["Ne"] = 8; // Z=10 |
| 473 |
valencee["Na"] = 9; |
| 474 |
valencee["Mg"] = 10; |
| 475 |
valencee["Al"] = 3; |
| 476 |
valencee["Si"] = 4; |
| 477 |
valencee["P"] = 5; |
| 478 |
valencee["S"] = 6; |
| 479 |
valencee["Cl"] = 7; |
| 480 |
valencee["Ar"] = 8; // Z=18 |
| 481 |
valencee["K"] = 9; |
| 482 |
valencee["Ca"] = 10; |
| 483 |
valencee["Sc"] = 11; |
| 484 |
valencee["Ti"] = 12; |
| 485 |
valencee["V"] = 13; |
| 486 |
valencee["Cr"] = 14; |
| 487 |
valencee["Mn"] = 15; |
| 488 |
valencee["Fe"] = 16; |
| 489 |
valencee["Co"] = 17; |
| 490 |
valencee["Ni"] = 18; |
| 491 |
valencee["Cu"] = 11; |
| 492 |
valencee["Zn"] = 12; |
| 493 |
valencee["Ga"] = 13; |
| 494 |
valencee["Ge"] = 4; |
| 495 |
valencee["As"] = 5; |
| 496 |
valencee["Se"] = 6; |
| 497 |
valencee["Br"] = 7; |
| 498 |
valencee["Kr"] = 8; // Z=36 |
| 499 |
valencee["Rb"] = 9; |
| 500 |
valencee["Sr"] = 10; |
| 501 |
valencee["Y"] = 11; |
| 502 |
valencee["Zr"] = 12; |
| 503 |
valencee["Nb"] = 13; |
| 504 |
valencee["Mo"] = 14; |
| 505 |
valencee["Tc"] = 15; |
| 506 |
valencee["Ru"] = 16; |
| 507 |
valencee["Rh"] = 17; |
| 508 |
valencee["Pd"] = 18; |
| 509 |
valencee["Ag"] = 11; |
| 510 |
valencee["Cd"] = 12; |
| 511 |
valencee["In"] = 13; |
| 512 |
valencee["Sn"] = 4; |
| 513 |
valencee["Sb"] = 5; |
| 514 |
valencee["Te"] = 6; |
| 515 |
valencee["I"] = 7; |
| 516 |
valencee["Xe"] = 8; // Z=54 |
| 517 |
valencee["Cs"] = 9; |
| 518 |
valencee["Ba"] = 10; |
| 519 |
valencee["W"] = 14; |
| 520 |
valencee["Pt"] = 10; |
| 521 |
valencee["Au"] = 11; |
| 522 |
valencee["Hg"] = 12; |
| 523 |
valencee["Pb"] = 14; |
| 524 |
valencee["Bi"] = 15; |
| 525 |
valencee["Rn"] = 8; // Z=86 |
| 526 |
|
| 527 |
// If the dialog is not shown, delay the update in case we need to prompt the |
| 528 |
// user to overwrite changes. Set the m_updatePending flag to true so we'll |
| 529 |
// know to update in the show event. |
| 530 |
if (!isVisible()) { |
| 531 |
m_updatePending = true; |
| 532 |
return; |
| 533 |
} |
| 534 |
|
| 535 |
m_updatePending = false; |
| 536 |
|
| 537 |
// Has the preview text been modified? |
| 538 |
if (ui.previewText->document()->isModified()) { |
| 539 |
QString message = tr("The input file has been modified. " |
| 540 |
"Would you like to overwrite your changes to reflect " |
| 541 |
"the new geometry or job options?"); |
| 542 |
int response = QMessageBox::question( |
| 543 |
this, tr("Overwrite modified input file?"), message, |
| 544 |
QMessageBox::Yes | QMessageBox::No, QMessageBox::No); |
| 545 |
if (static_cast<QMessageBox::StandardButton>(response) != |
| 546 |
QMessageBox::Yes) { |
| 547 |
restoreOptionCache(); |
| 548 |
return; |
| 549 |
} |
| 550 |
} |
| 551 |
|
| 552 |
// Gather options: |
| 553 |
QString title(ui.titleEdit->text()); |
| 554 |
if (title.isEmpty()) |
| 555 |
title = generateJobTitle(); |
| 556 |
|
| 557 |
auto calculate( |
| 558 |
static_cast<CalculateOption>(ui.calculateCombo->currentIndex())); |
| 559 |
auto functional( |
| 560 |
static_cast<FunctionalOption>(ui.functionalCombo->currentIndex())); |
| 561 |
auto basis(static_cast<BasisOption>(ui.basisCombo->currentIndex())); |
| 562 |
auto method(static_cast<MethodOption>(ui.methodCombo->currentIndex())); |
| 563 |
auto EWALDType( |
| 564 |
static_cast<EWALDTypeOption>(ui.ewaldtypeCombo->currentIndex())); |
| 565 |
auto SCFGuess( |
| 566 |
static_cast<SCFGuessOption>(ui.scfguessComboBox->currentIndex())); |
| 567 |
auto OTMinimizer( |
| 568 |
static_cast<OTMinimizerOption>(ui.otminimizerComboBox->currentIndex())); |
| 569 |
|
| 570 |
QString emaxSpline = QString::number(ui.emaxSplineSpin->value()); |
| 571 |
QString rcutnb = QString::number(ui.rcutnbSplineSpin->value()); |
| 572 |
QString ewaldalpha = QString::number(ui.ewaldalphaSpin->value()); |
| 573 |
QString ewaldgmax = QString::number(ui.ewaldgmaxSpin->value()); |
| 574 |
|
| 575 |
QString maxSCF = QString::number(ui.maxscfspinBox->value()); |
| 576 |
QString epsSCF = QString::number(ui.epsscfSpinBox->value()); |
| 577 |
QString outermaxSCF = QString::number(ui.outerMaxscfSpinBox->value()); |
| 578 |
QString outerepsSCF = QString::number(ui.outerEpsscfSpinBox->value()); |
| 579 |
|
| 580 |
// Generate text. |
| 581 |
// Variables: |
| 582 |
QString runTyp; |
| 583 |
QString scfTyp; |
| 584 |
QString gbasis; |
| 585 |
QString gfunc; |
| 586 |
QString gmethod; |
| 587 |
QString mult; |
| 588 |
QString ewaldtype; |
| 589 |
QString lsd; |
| 590 |
|
| 591 |
QString scfGuess; |
| 592 |
QString otMinimizer; |
| 593 |
|
| 594 |
// Extra options for lines |
| 595 |
QString extraBasis; |
| 596 |
QString extraContrl; |
| 597 |
|
| 598 |
// Optional lines |
| 599 |
QString statPt; |
| 600 |
QString force; |
| 601 |
QString pcm; |
| 602 |
|
| 603 |
runTyp = fromCalcEnum(calculate); |
| 604 |
|
| 605 |
switch (functional) { |
| 606 |
case FunctionalBLYP: |
| 607 |
gfunc = "BLYP"; |
| 608 |
break; |
| 609 |
case FunctionalBP: |
| 610 |
gfunc = "BP"; |
| 611 |
break; |
| 612 |
case FunctionalHCTH120: |
| 613 |
gfunc = "HCTH120"; |
| 614 |
break; |
| 615 |
case FunctionalPADE: |
| 616 |
gfunc = "PADE"; |
| 617 |
break; |
| 618 |
case FunctionalPBE: |
| 619 |
gfunc = "PBE"; |
| 620 |
break; |
| 621 |
default: |
| 622 |
break; |
| 623 |
} |
| 624 |
|
| 625 |
switch (basis) { |
| 626 |
case BasisSZVGTH: |
| 627 |
gbasis = "SZV-GTH"; |
| 628 |
break; |
| 629 |
case BasisDZVGTH: |
| 630 |
gbasis = "DZV-GTH"; |
| 631 |
break; |
| 632 |
case BasisDZVPGTH: |
| 633 |
gbasis = "DZVP-GTH"; |
| 634 |
break; |
| 635 |
case BasisTZVPGTH: |
| 636 |
gbasis = "TZVP-GTH"; |
| 637 |
break; |
| 638 |
case BasisTZV2PGTH: |
| 639 |
gbasis = "TZV2P-GTH"; |
| 640 |
break; |
| 641 |
default: |
| 642 |
break; |
| 643 |
} |
| 644 |
|
| 645 |
switch (method) { |
| 646 |
case DFT: |
| 647 |
gmethod = "QS"; |
| 648 |
break; |
| 649 |
case MolecularMechanics: |
| 650 |
gmethod = "FIST"; |
| 651 |
break; |
| 652 |
case HybridQuantumClassical: |
| 653 |
gmethod = "QMMM"; |
| 654 |
break; |
| 655 |
default: |
| 656 |
break; |
| 657 |
} |
| 658 |
|
| 659 |
switch (EWALDType) { |
| 660 |
case EWALD: |
| 661 |
ewaldtype = "EWALD"; |
| 662 |
break; |
| 663 |
case ewaldNONE: |
| 664 |
ewaldtype = "NONE"; |
| 665 |
break; |
| 666 |
case PME: |
| 667 |
ewaldtype = "PME"; |
| 668 |
break; |
| 669 |
case SPME: |
| 670 |
ewaldtype = "SPME"; |
| 671 |
break; |
| 672 |
default: |
| 673 |
break; |
| 674 |
} |
| 675 |
|
| 676 |
switch (SCFGuess) { |
| 677 |
case ATOMIC: |
| 678 |
scfGuess = "ATOMIC"; |
| 679 |
break; |
| 680 |
case CORE: |
| 681 |
scfGuess = "CORE"; |
| 682 |
break; |
| 683 |
case DENSITIES: |
| 684 |
scfGuess = "DENSITIES"; |
| 685 |
break; |
| 686 |
case HISTORY_RESTART: |
| 687 |
scfGuess = "HISTORY_RESTART"; |
| 688 |
break; |
| 689 |
case MOPAC: |
| 690 |
scfGuess = "MOPAC"; |
| 691 |
break; |
| 692 |
case scfNONE: |
| 693 |
scfGuess = "NONE"; |
| 694 |
break; |
| 695 |
case RANDOM: |
| 696 |
scfGuess = "RANDOM"; |
| 697 |
break; |
| 698 |
case RESTART: |
| 699 |
scfGuess = "RESTART"; |
| 700 |
break; |
| 701 |
case SPARSE: |
| 702 |
scfGuess = "SPARSE"; |
| 703 |
break; |
| 704 |
default: |
| 705 |
break; |
| 706 |
} |
| 707 |
|
| 708 |
switch (OTMinimizer) { |
| 709 |
case BROYDEN: |
| 710 |
otMinimizer = "BROYDEN"; |
| 711 |
break; |
| 712 |
case CG: |
| 713 |
otMinimizer = "CG"; |
| 714 |
break; |
| 715 |
case DIIS: |
| 716 |
otMinimizer = "DIIS"; |
| 717 |
break; |
| 718 |
case SD: |
| 719 |
otMinimizer = "SD"; |
| 720 |
break; |
| 721 |
default: |
| 722 |
break; |
| 723 |
} |
| 724 |
/* |
| 725 |
switch (lsdbool) { |
| 726 |
case true: |
| 727 |
lsd = "TRUE"; |
| 728 |
break; |
| 729 |
case false: |
| 730 |
lsd = "FALSE"; |
| 731 |
break; |
| 732 |
|
| 733 |
}*/ |
| 734 |
|
| 735 |
// build up the input file: |
| 736 |
QString file; |
| 737 |
|
| 738 |
file += "&GLOBAL\n"; |
| 739 |
file += QString(" PROJECT %1\n").arg(title); |
| 740 |
|
| 741 |
file += QString(" RUN_TYPE %1\n").arg(runTyp); |
| 742 |
|
| 743 |
file += " PRINT_LEVEL LOW\n"; |
| 744 |
file += "&END GLOBAL\n\n"; |
| 745 |
|
| 746 |
file += "&FORCE_EVAL\n"; |
| 747 |
|
| 748 |
file += QString(" METHOD %1\n").arg(gmethod); |
| 749 |
|
| 750 |
file += " &SUBSYS\n"; |
| 751 |
|
| 752 |
if (m_molecule) { |
| 753 |
std::vector<unsigned int> atomList; |
| 754 |
bool inlist = true; |
| 755 |
|
| 756 |
for (size_t i = 0; i < m_molecule->atomCount(); ++i) { |
| 757 |
Core::Atom atom = m_molecule->atom(i); |
| 758 |
for (unsigned iat : atomList) { |
| 759 |
if (iat == atom.atomicNumber()) { |
| 760 |
inlist = false; |
| 761 |
break; |
| 762 |
} else { |
| 763 |
inlist = true; |
| 764 |
} |
| 765 |
} |
| 766 |
if (inlist) { |
| 767 |
atomList.push_back(atom.atomicNumber()); |
| 768 |
QString symbol = Core::Elements::symbol(atom.atomicNumber()); |
| 769 |
file += QString(" &KIND %1\n").arg(symbol); |
| 770 |
file += QString(" ELEMENT %1\n") |
| 771 |
.arg(Core::Elements::symbol(atom.atomicNumber())); |
| 772 |
file += QString(" BASIS_SET %1\n").arg(gbasis); |
| 773 |
const auto e = valencee.find(symbol); |
| 774 |
const auto suffix = |
| 775 |
e != valencee.cend() ? QString("-q%1").arg(e->second) : ""; |
| 776 |
file += QString( |
| 777 |
" ! XXX you may have to manually modify/append '-qn' suffix, " |
| 778 |
"where n is the number of valence electrons\n"); |
| 779 |
file += QString(" POTENTIAL GTH-%1%2\n").arg(gfunc).arg(suffix); |
| 780 |
file += QString(" &END KIND\n"); |
| 781 |
} |
| 782 |
} |
| 783 |
} |
| 784 |
|
| 785 |
// unit cell |
| 786 |
file += " &CELL\n"; |
| 787 |
if (const Core::UnitCell* cell = m_molecule->unitCell()) { |
| 788 |
Vector3f a = cell->aVector().cast<float>(); |
| 789 |
Vector3f b = cell->bVector().cast<float>(); |
| 790 |
Vector3f c = cell->cVector().cast<float>(); |
| 791 |
|
| 792 |
file += QStringLiteral(" A%1%2%3\n") |
| 793 |
.arg(a.x(), 16, 'f', 7) |
| 794 |
.arg(a.y(), 16, 'f', 7) |
| 795 |
.arg(a.z(), 16, 'f', 7); |
| 796 |
file += QStringLiteral(" B%1%2%3\n") |
| 797 |
.arg(b.x(), 16, 'f', 7) |
| 798 |
.arg(b.y(), 16, 'f', 7) |
| 799 |
.arg(b.z(), 16, 'f', 7); |
| 800 |
file += QStringLiteral(" C%1%2%3\n") |
| 801 |
.arg(c.x(), 16, 'f', 7) |
| 802 |
.arg(c.y(), 16, 'f', 7) |
| 803 |
.arg(c.z(), 16, 'f', 7); |
| 804 |
|
| 805 |
} else { |
| 806 |
file += " ! XXX please manually adjust cell size\n"; |
| 807 |
file += " A 10.00000000 0.000000000 0.000000000\n"; |
| 808 |
file += " B 0.000000000 10.00000000 0.000000000\n"; |
| 809 |
file += " C 0.000000000 0.000000000 10.00000000\n"; |
| 810 |
file += " PERIODIC NONE\n"; |
| 811 |
} |
| 812 |
file += " &END CELL\n"; |
| 813 |
|
| 814 |
if (m_molecule) { |
| 815 |
file += " &COORD\n"; |
| 816 |
for (size_t i = 0; i < m_molecule->atomCount(); ++i) { |
| 817 |
Core::Atom atom = m_molecule->atom(i); |
| 818 |
file += QString(" %1 %2 %3 %4\n") |
| 819 |
.arg(Core::Elements::symbol(atom.atomicNumber()), -3) |
| 820 |
.arg(atom.position3d().x(), 9, 'f', 5) |
| 821 |
.arg(atom.position3d().y(), 9, 'f', 5) |
| 822 |
.arg(atom.position3d().z(), 9, 'f', 5); |
| 823 |
} |
| 824 |
file += " &END COORD\n"; |
| 825 |
} |
| 826 |
|
| 827 |
file += " &END SUBSYS\n"; |
| 828 |
|
| 829 |
if (gmethod == "QS") { |
| 830 |
file += " &DFT\n"; |
| 831 |
file += " ! XXX: you may have to manually modify the file names, " |
| 832 |
"depending on the system and calculation level\n"; |
| 833 |
file += " BASIS_SET_FILE_NAME BASIS_SET\n"; |
| 834 |
file += " POTENTIAL_FILE_NAME GTH_POTENTIALS\n"; |
| 835 |
if (ui.lsdcheckBox->isChecked()) |
| 836 |
file += " LSD TRUE\n"; |
| 837 |
|
| 838 |
file += " &QS\n"; |
| 839 |
file += " EPS_DEFAULT 1.0E-10\n"; |
| 840 |
file += " &END QS\n"; |
| 841 |
file += QString(" LSD %1\n").arg(lsd); |
| 842 |
|
| 843 |
file += " &MGRID\n"; |
| 844 |
file += " CUTOFF 280\n"; |
| 845 |
file += " COMMENSURATE\n"; |
| 846 |
file += " &END MGRID\n"; |
| 847 |
|
| 848 |
file += " &SCF\n"; |
| 849 |
file += QString(" MAX_SCF %1\n").arg(maxSCF); |
| 850 |
file += QString(" EPS_SCF %1\n").arg(epsSCF); |
| 851 |
file += QString(" SCF_GUESS %1\n").arg(scfGuess); |
| 852 |
file += " &OUTER_SCF\n"; |
| 853 |
file += QString(" MAX_SCF %1\n").arg(outermaxSCF); |
| 854 |
file += QString(" EPS_SCF %1\n").arg(outerepsSCF); |
| 855 |
file += " &END\n"; |
| 856 |
file += " &OT T\n"; |
| 857 |
file += QString(" MINIMIZER %1\n").arg(otMinimizer); |
| 858 |
file += " N_DIIS 7\n"; |
| 859 |
file += " &END OT\n"; |
| 860 |
|
| 861 |
file += " &END SCF\n"; |
| 862 |
|
| 863 |
file += " &XC\n"; |
| 864 |
file += QString(" &XC_FUNCTIONAL %1\n").arg(gfunc); |
| 865 |
file += " &END XC_FUNCTIONAL\n"; |
| 866 |
file += " &END XC\n"; |
| 867 |
|
| 868 |
file += " &END DFT\n"; |
| 869 |
file += " &PRINT\n"; |
| 870 |
file += " &FORCES ON\n"; |
| 871 |
file += " &END FORCES\n"; |
| 872 |
file += " &END PRINT\n"; |
| 873 |
} else if (gmethod == "FIST") { |
| 874 |
|
| 875 |
file += " &TOPOLOGY\n"; |
| 876 |
file += " CHARGE_BETA\n"; |
| 877 |
file += " CONNECTIVITY AMBER\n"; |
| 878 |
file += |
| 879 |
" CONN_FILE_NAME ! Add file name that contains connectivity data\n"; |
| 880 |
file += " &END TOPOLOGY \n"; |
| 881 |
|
| 882 |
file += " &PRINT\n"; |
| 883 |
file += " &TOPOLOGY_INFO\n"; |
| 884 |
file += " AMBER_INFO\n"; |
| 885 |
file += " &END\n"; |
| 886 |
file += " &END \n"; |
| 887 |
file += " &END SUBSYS\n"; |
| 888 |
|
| 889 |
file += " &MM\n"; |
| 890 |
|
| 891 |
file += " &FORCEFIELD\n"; |
| 892 |
file += " PARM_FILE_NAME ! Add file name that contains force field " |
| 893 |
"parameters\n"; |
| 894 |
file += " PARMTYPE AMBER\n"; |
| 895 |
|
| 896 |
file += " &SPLINE\n"; |
| 897 |
file += QString(" EMAX_SPLINE %1\n").arg(emaxSpline); |
| 898 |
file += QString(" RCUT_NB %1\n").arg(rcutnb); |
| 899 |
file += " &END SPLINE\n"; |
| 900 |
file += " &END FORCEFIELD\n"; |
| 901 |
|
| 902 |
file += " &POISSON\n"; |
| 903 |
file += " &EWALD\n"; |
| 904 |
file += QString(" EWALD_TYPE %1\n").arg(ewaldtype); |
| 905 |
file += QString(" ALPHA %1\n").arg(ewaldalpha); |
| 906 |
file += QString(" GMAX %1\n").arg(ewaldgmax); |
| 907 |
file += " &END EWALD\n"; |
| 908 |
file += " &END POISSON\n"; |
| 909 |
|
| 910 |
file += " &PRINT\n"; |
| 911 |
file += " &FF_INFO\n"; |
| 912 |
file += " $END\n"; |
| 913 |
file += " &FF_PARAMETER_FILE\n"; |
| 914 |
file += " &END\n"; |
| 915 |
file += " &END PRINT\n"; |
| 916 |
|
| 917 |
file += " &END MM\n"; |
| 918 |
} |
| 919 |
|
| 920 |
file += "&END FORCE_EVAL\n"; |
| 921 |
|
| 922 |
ui.previewText->setText(file); |
| 923 |
ui.previewText->document()->setModified(false); |
| 924 |
updateOptionCache(); |
| 925 |
} |
| 926 |
|
| 927 |
void Cp2kInputDialog::resetClicked() |
| 928 |
{ |
| 929 |
setBasicDefaults(); |
| 930 |
updatePreviewText(); |
| 931 |
} |
| 932 |
|
| 933 |
void Cp2kInputDialog::defaultsClicked() |
| 934 |
{ |
| 935 |
setBasicDefaults(); |
| 936 |
updatePreviewText(); |
| 937 |
} |
| 938 |
|
| 939 |
void Cp2kInputDialog::generateClicked() |
| 940 |
{ |
| 941 |
QSettings settings; |
| 942 |
QString fileName = |
| 943 |
(ui.baseNameEdit->text().isEmpty() ? ui.baseNameEdit->placeholderText() |
| 944 |
: ui.baseNameEdit->text()) + |
| 945 |
".inp"; |
| 946 |
QString targetFile = |
| 947 |
settings.value("cp2kInput/outputDirectory", QDir::homePath()).toString(); |
| 948 |
targetFile = |
| 949 |
QDir(QFileInfo(targetFile).absoluteDir()).absoluteFilePath(fileName); |
| 950 |
|
| 951 |
fileName = |
| 952 |
QFileDialog::getSaveFileName(this, tr("Save CP2K input file"), targetFile); |
| 953 |
|
| 954 |
// User cancel: |
| 955 |
if (fileName.isNull()) |
| 956 |
return; |
| 957 |
|
| 958 |
settings.setValue("cp2kInput/outputDirectory", fileName); |
| 959 |
|
| 960 |
QFile file(fileName); |
| 961 |
bool success = false; |
| 962 |
if (file.open(QFile::WriteOnly | QFile::Text)) { |
| 963 |
if (file.write(ui.previewText->toPlainText().toLatin1()) > 0) { |
| 964 |
success = true; |
| 965 |
} |
| 966 |
file.close(); |
| 967 |
} |
| 968 |
|
| 969 |
if (!success) { |
| 970 |
QMessageBox::critical(this, tr("Output Error"), |
| 971 |
tr("Failed to write to file %1.").arg(fileName)); |
| 972 |
} |
| 973 |
} |
| 974 |
|
| 975 |
void Cp2kInputDialog::computeClicked() |
| 976 |
{ |
| 977 |
// Verify that molequeue is running: |
| 978 |
MoleQueueManager& mqManager = MoleQueueManager::instance(); |
| 979 |
if (!mqManager.connectIfNeeded()) { |
| 980 |
QMessageBox::information(this, tr("Cannot connect to MoleQueue"), |
| 981 |
tr("Cannot connect to MoleQueue server. Please " |
| 982 |
"ensure that it is running and try again.")); |
| 983 |
return; |
| 984 |
} |
| 985 |
|
| 986 |
QString description(ui.titleEdit->text()); |
| 987 |
if (description.isEmpty()) |
| 988 |
description = generateJobTitle(); |
| 989 |
|
| 990 |
QString fileNameBase = ui.baseNameEdit->text().isEmpty() |
| 991 |
? ui.baseNameEdit->placeholderText() |
| 992 |
: ui.baseNameEdit->text(); |
| 993 |
|
| 994 |
JobObject job; |
| 995 |
job.setProgram("CP2K"); |
| 996 |
job.setDescription(description); |
| 997 |
job.setInputFile(QString("%1.inp").arg(fileNameBase), |
| 998 |
ui.previewText->toPlainText()); |
| 999 |
|
| 1000 |
MoleQueueDialog::SubmitStatus submitStatus = |
| 1001 |
MoleQueueDialog::submitJob(this, tr("Submit CP2K Calculation"), job, |
| 1002 |
MoleQueueDialog::WaitForSubmissionResponse | |
| 1003 |
MoleQueueDialog::SelectProgramFromTemplate); |
| 1004 |
|
| 1005 |
switch (submitStatus) { |
| 1006 |
default: |
| 1007 |
case MoleQueueDialog::SubmissionSuccessful: |
| 1008 |
case MoleQueueDialog::SubmissionFailed: |
| 1009 |
case MoleQueueDialog::SubmissionAttempted: |
| 1010 |
case MoleQueueDialog::SubmissionAborted: |
| 1011 |
// The dialog handles these cases adequately, we don't need to do |
| 1012 |
// anything. |
| 1013 |
break; |
| 1014 |
|
| 1015 |
case MoleQueueDialog::JobFailed: |
| 1016 |
// Inform the user: |
| 1017 |
QMessageBox::information(this, tr("Job Failed"), |
| 1018 |
tr("The job did not complete successfully."), |
| 1019 |
QMessageBox::Ok); |
| 1020 |
break; |
| 1021 |
|
| 1022 |
case MoleQueueDialog::JobFinished: |
| 1023 |
// Let the world know that the job is ready to open. job has been |
| 1024 |
// overwritten with the final job details. |
| 1025 |
emit openJobOutput(job); |
| 1026 |
hide(); |
| 1027 |
break; |
| 1028 |
} |
| 1029 |
} |
| 1030 |
|
| 1031 |
void Cp2kInputDialog::updateTitlePlaceholder() |
| 1032 |
{ |
| 1033 |
ui.titleEdit->setPlaceholderText(generateJobTitle()); |
| 1034 |
} |
| 1035 |
|
| 1036 |
} // namespace Avogadro::QtPlugins |