Skip to content

Commit

Permalink
Some cleanups of unused code
Browse files Browse the repository at this point in the history
Signed-off-by: Geoff Hutchison <[email protected]>
  • Loading branch information
ghutchis committed Feb 2, 2024
1 parent 5631f0d commit d095e6b
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 60 deletions.
10 changes: 5 additions & 5 deletions avogadro/qtplugins/forcefield/forcefield.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,6 @@

#include <cppoptlib/meta.h>
#include <cppoptlib/problem.h>
#include <cppoptlib/solver/bfgssolver.h>
#include <cppoptlib/solver/conjugatedgradientdescentsolver.h>
#include <cppoptlib/solver/gradientdescentsolver.h>
#include <cppoptlib/solver/lbfgssolver.h>

namespace Avogadro {
Expand Down Expand Up @@ -132,7 +129,11 @@ QList<QAction*> Forcefield::actions() const
QStringList Forcefield::menuPath(QAction* action) const
{
QStringList path;
path << tr("&Extensions") << tr("&Calculate");
if (action->data().toInt() == optimizeAction)
path << tr("&Extensions");
else
path << tr("&Extensions") << tr("&Calculate");

return path;
}

Expand Down Expand Up @@ -229,7 +230,6 @@ void Forcefield::optimize()
m_molecule->undoMolecule()->setInteractive(true);

cppoptlib::LbfgsSolver<EnergyCalculator> solver;
// cppoptlib::ConjugatedGradientDescentSolver<EnergyCalculator> solver;

int n = m_molecule->atomCount();

Expand Down
53 changes: 3 additions & 50 deletions avogadro/qtplugins/forcefield/obmmenergy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,52 +17,6 @@

namespace Avogadro::QtPlugins {

class OBMMEnergy::ProcessListener : public QObject
{
Q_OBJECT
public:
ProcessListener(QProcess* proc)
: QObject(), m_finished(false), m_process(proc)
{
}

bool waitForOutput(QByteArray output, int msTimeout = 2000)
{
connect(m_process, SIGNAL(readyRead()), SLOT(readyRead()));
if (!wait(msTimeout))
return false;

// success!
output = m_output;
disconnect(m_process, nullptr, nullptr, nullptr);
m_finished = false;
return true;
}

public slots:
void readyRead()
{
m_finished = true;
m_output = m_process->readAllStandardOutput();
}

private:
bool wait(int msTimeout)
{
QTimer timer;
timer.start(msTimeout);

while (timer.isActive() && !m_finished)
qApp->processEvents(QEventLoop::AllEvents, 500);

return m_finished;
}

QProcess* m_process;
bool m_finished;
QByteArray m_output;
};

OBMMEnergy::OBMMEnergy(const std::string& method)
: m_identifier(method), m_name(method), m_process(nullptr),
m_molecule(nullptr),
Expand Down Expand Up @@ -127,8 +81,7 @@ QByteArray OBMMEnergy::writeAndRead(const QByteArray& input)
QByteArray result, line;
m_process->write(input + "\n");
QThread::msleep(1);
m_process->waitForReadyRead(50);
bool gotInvalid = false;
m_process->waitForReadyRead(5);
while (m_process->canReadLine() && !line.startsWith("command >")) {
line = m_process->readLine();
result += line;
Expand All @@ -137,7 +90,7 @@ QByteArray OBMMEnergy::writeAndRead(const QByteArray& input)
if (!result.contains("invalid command\n command >")) {
m_process->write(" \n");
QThread::msleep(1);
m_process->waitForReadyRead(50);
m_process->waitForReadyRead(5);
while (m_process->canReadLine()) {
line = m_process->readLine();
result += line;
Expand Down Expand Up @@ -241,7 +194,7 @@ void OBMMEnergy::setMolecule(Core::Molecule* mol)
}

QByteArray input, line, result;
bool ready = m_process->waitForReadyRead();
m_process->waitForReadyRead();
result.clear();
while (!result.contains("command >")) {
result += m_process->readLine();
Expand Down
5 changes: 0 additions & 5 deletions avogadro/qtplugins/forcefield/obmmenergy.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,6 @@ namespace Io {
class FileFormat;
}

namespace QtGui {
class PythonScript;
}

namespace QtPlugins {

class OBMMEnergy : public Avogadro::Calc::EnergyCalculator
Expand Down Expand Up @@ -73,7 +69,6 @@ class OBMMEnergy : public Avogadro::Calc::EnergyCalculator
/**
* @brief Synchronous use of the QProcess.
*/
class ProcessListener;
QByteArray writeAndRead(const QByteArray& input);

private:
Expand Down

0 comments on commit d095e6b

Please sign in to comment.