Skip to content

Commit

Permalink
Merge pull request #1399 from ghutchis/use-int-orbital-scripting
Browse files Browse the repository at this point in the history
Minor fix for scripting orbital rendering - allow integers
  • Loading branch information
ghutchis authored Oct 24, 2023
2 parents c5d6d24 + df5c428 commit 3c58251
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions avogadro/qtplugins/surfaces/surfaces.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,14 @@ bool Surfaces::handleCommand(const QString& command, const QVariantMap& options)
homo = m_basis->homo();
if (options.contains("orbital")) {
// check if options contains "homo" or "lumo"
bool string = options["orbital"].canConvert<QString>();
if (string) {
bool ok = false;
if (options["orbital"].canConvert<int>()) {
// internally, we count orbitals from zero
// if the conversion worked, ok = true
// and we'll skip the next conditional
index = options.value("orbital").toInt(&ok) - 1;
}
if (!ok && options["orbital"].canConvert<QString>()) {
// should be something like "homo-1" or "lumo+2"
QString name = options["orbital"].toString();
QString expression, modifier;
Expand All @@ -181,9 +187,6 @@ bool Surfaces::handleCommand(const QString& command, const QVariantMap& options)
index = index + n;
}
index = index - 1; // start from zero
} else {
// internally, we count orbitals from zero
index = options.value("index").toInt() - 1;
}
}
bool beta = false;
Expand Down

0 comments on commit 3c58251

Please sign in to comment.