From 2f1bc1e638be05e53ca2c30c90c7ad809fcff4f9 Mon Sep 17 00:00:00 2001 From: Geoff Hutchison Date: Sat, 7 Dec 2024 18:41:37 -0500 Subject: [PATCH] If inputParameters is present, set default options for the user Signed-off-by: Geoff Hutchison --- avogadro/qtgui/jsonwidget.cpp | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/avogadro/qtgui/jsonwidget.cpp b/avogadro/qtgui/jsonwidget.cpp index 1e04b9f4ab..8f4ed59e01 100644 --- a/avogadro/qtgui/jsonwidget.cpp +++ b/avogadro/qtgui/jsonwidget.cpp @@ -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)