Skip to content

Commit

Permalink
Based on feedback, only use OB (library) or obmm if no Python (#1602)
Browse files Browse the repository at this point in the history
* Based on feedback, only use OB (library) or obmm if no Python

The new Python energy scripts are preferred
- more flexible (e.g., Open Babel or RDKit)
- can use requirements via pip / conda

Signed-off-by: Geoff Hutchison <[email protected]>
  • Loading branch information
ghutchis authored Feb 10, 2024
1 parent ec07059 commit 71d9057
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
13 changes: 7 additions & 6 deletions avogadro/qtplugins/forcefield/forcefield.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,18 +65,19 @@ Forcefield::Forcefield(QObject* parent_)
m_gradientTolerance = settings.value("gradientTolerance", 1.0e-4).toDouble();
settings.endGroup();

// prefer to use Python interface scripts if available
refreshScripts();

// add the openbabel calculators in case they don't exist
#ifdef BUILD_GPL_PLUGINS
// These directly use Open Babel and are fast
qDebug() << " registering GPL plugins";
Calc::EnergyManager::registerModel(new OBEnergy("MMFF94"));
Calc::EnergyManager::registerModel(new OBEnergy("UFF"));
Calc::EnergyManager::registerModel(new OBEnergy("GAFF"));
#endif

refreshScripts();

#ifndef BUILD_GPL_PLUGINS
// These call obmm and can be slow
#else
// These call obmm and can be slower
qDebug() << " registering obmm plugins";
Calc::EnergyManager::registerModel(new OBMMEnergy("MMFF94"));
Calc::EnergyManager::registerModel(new OBMMEnergy("UFF"));
Calc::EnergyManager::registerModel(new OBMMEnergy("GAFF"));
Expand Down
14 changes: 14 additions & 0 deletions avogadro/qtplugins/forcefield/obenergy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include <openbabel/obconversion.h>
#include <openbabel/obiter.h>

#include <QCoreApplication>
#include <QDebug>
#include <QDir>

Expand All @@ -43,12 +44,25 @@ OBEnergy::OBEnergy(const std::string& method)
: m_identifier(method), m_name(method), m_molecule(nullptr)
{
d = new Private;

// make sure we set the Open Babel variables for data files
#ifdef _WIN32
QByteArray dataDir =
QString(QCoreApplication::applicationDirPath() + "/data").toLocal8Bit();
qputenv("BABEL_DATADIR", dataDir);
#endif
// Ensure the plugins are loaded
OBPlugin::LoadAllPlugins();

d->m_forceField = static_cast<OBForceField*>(
OBPlugin::GetPlugin("forcefields", method.c_str()));

qDebug() << "OBEnergy: method: " << method.c_str();
if (d->m_forceField == nullptr) {
qDebug() << "OBEnergy: method not found: " << method.c_str();
qDebug() << OBPlugin::ListAsString("forcefields").c_str();
}

if (method == "UFF") {
m_description = tr("Universal Force Field");
m_elements.reset();
Expand Down

0 comments on commit 71d9057

Please sign in to comment.