Skip to content

Commit

Permalink
If inputParameters is present, set default options for the user
Browse files Browse the repository at this point in the history
Signed-off-by: Geoff Hutchison <[email protected]>
  • Loading branch information
ghutchis committed Dec 7, 2024
1 parent 3638fd7 commit 2f1bc1e
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions avogadro/qtgui/jsonwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,28 @@ void JsonWidget::setMolecule(QtGui::Molecule* mol)

setOption("Charge", charge);
setOption("Multiplicity", multiplicity);

// check the molecule for "inputParameters" from CJSON
// e.g.
// https://github.com/OpenChemistry/chemicaljson/blob/main/chemicaljson.py#L130
if (m_molecule->hasData("inputParameters")) {
QByteArray data(m_molecule->data("inputParameters").toString().c_str());
QJsonDocument doc = QJsonDocument::fromJson(data);
if (!doc.isNull() && doc.isObject()) {
QJsonObject inputParameters = doc.object();
// check for a few known keys
if (inputParameters.contains("processors"))
setOption("Processor Cores", inputParameters["processors"].toInt());
else if (inputParameters.contains("memory"))
setOption("Memory", inputParameters["memory"].toInt());
else if (inputParameters.contains("basis"))
setOption("Basis", inputParameters["basis"].toString());
else if (inputParameters.contains("functional"))
setOption("Theory", inputParameters["functional"].toString());
else if (inputParameters.contains("task"))
setOption("Calculation Type", inputParameters["task"].toString());
}
}
}

if (mol == m_molecule)
Expand Down

0 comments on commit 2f1bc1e

Please sign in to comment.