Skip to content

Minor fix for scripting orbital rendering - allow integers #1399

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 24, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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