Skip to content

Commit

Permalink
Use a deferred start to initialize force fields
Browse files Browse the repository at this point in the history
Significantly speeds startup on my Mac

Signed-off-by: Geoff Hutchison <[email protected]>
  • Loading branch information
ghutchis committed Nov 30, 2024
1 parent c18cf3a commit 6f2dfec
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 20 deletions.
5 changes: 3 additions & 2 deletions avogadro/qtplugins/forcefield/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -61,5 +61,6 @@ if (NOT BUILD_GPL_PLUGINS)
)
endif()

install(PROGRAMS ${forcefields}
DESTINATION "${INSTALL_LIBRARY_DIR}/avogadro2/scripts/energy/")
# Don't install the scripts - we'll use these as plugins
# install(PROGRAMS ${forcefields}
# DESTINATION "${INSTALL_LIBRARY_DIR}/avogadro2/scripts/energy/")
44 changes: 26 additions & 18 deletions avogadro/qtplugins/forcefield/forcefield.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

#include <QtCore/QDebug>
#include <QtCore/QSettings>
#include <QtCore/QTimer>

#include <QAction>
#include <QtWidgets/QMessageBox>
Expand Down Expand Up @@ -65,24 +66,6 @@ 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"));
#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"));
#endif

QAction* action = new QAction(this);
action->setEnabled(true);
action->setText(tr("Optimize Geometry"));
Expand Down Expand Up @@ -133,6 +116,9 @@ Forcefield::Forcefield(QObject* parent_)
action->setData(unfreezeAction);
connect(action, SIGNAL(triggered()), SLOT(unfreezeSelected()));
m_actions.push_back(action);

// single-shot timer to allow the GUI to start up
QTimer::singleShot(500, this, SLOT(deferredStart()));
}

Forcefield::~Forcefield() {}
Expand All @@ -142,6 +128,28 @@ QList<QAction*> Forcefield::actions() const
return m_actions;
}

void Forcefield::deferredStart()
{

// 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"));
#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"));
#endif
}

QStringList Forcefield::menuPath(QAction* action) const
{
QStringList path;
Expand Down
2 changes: 2 additions & 0 deletions avogadro/qtplugins/forcefield/forcefield.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ private slots:
void freezeSelected();
void unfreezeSelected();

void deferredStart();

private:
QList<QAction*> m_actions;
QtGui::Molecule* m_molecule = nullptr;
Expand Down

0 comments on commit 6f2dfec

Please sign in to comment.