diff --git a/avogadro/calc/energycalculator.cpp b/avogadro/calc/energycalculator.cpp index 89222b569d..9a264d3ad6 100644 --- a/avogadro/calc/energycalculator.cpp +++ b/avogadro/calc/energycalculator.cpp @@ -26,12 +26,10 @@ void EnergyCalculator::cleanGradients(TVector& grad) } // freeze any masked atoms or coordinates - /* if (m_mask.rows() == size) grad = grad.cwiseProduct(m_mask); else std::cerr << "Error: mask size " << m_mask.rows() << " " << grad.rows() << std::endl; - */ } } // namespace Avogadro diff --git a/avogadro/qtgui/pythonscript.cpp b/avogadro/qtgui/pythonscript.cpp index 8b567ceb43..0825912dba 100644 --- a/avogadro/qtgui/pythonscript.cpp +++ b/avogadro/qtgui/pythonscript.cpp @@ -224,8 +224,8 @@ void PythonScript::processFinished(int, QProcess::ExitStatus) void PythonScript::asyncTerminate() { if (m_process != nullptr) { - m_process->terminate(); disconnect(m_process, SIGNAL(finished()), this, SLOT(processFinished())); + m_process->kill(); m_process->deleteLater(); m_process = nullptr; } diff --git a/avogadro/qtplugins/forcefield/CMakeLists.txt b/avogadro/qtplugins/forcefield/CMakeLists.txt index 238d46ba9f..737130ce3e 100644 --- a/avogadro/qtplugins/forcefield/CMakeLists.txt +++ b/avogadro/qtplugins/forcefield/CMakeLists.txt @@ -16,9 +16,12 @@ target_link_libraries(Forcefield PRIVATE Avogadro::Calc) # Bundled forcefield scripts set(forcefields + scripts/gaff.py scripts/gfn1.py scripts/gfn2.py scripts/gfnff.py + scripts/mmff94.py + scripts/uff.py ) install(PROGRAMS ${forcefields} diff --git a/avogadro/qtplugins/forcefield/forcefield.cpp b/avogadro/qtplugins/forcefield/forcefield.cpp index 217c343c23..68c12b016f 100644 --- a/avogadro/qtplugins/forcefield/forcefield.cpp +++ b/avogadro/qtplugins/forcefield/forcefield.cpp @@ -29,9 +29,8 @@ #include #include - +#include #include -// not currently used #include #include @@ -125,9 +124,8 @@ void Forcefield::optimize() bool isInteractive = m_molecule->undoMolecule()->isInteractive(); m_molecule->undoMolecule()->setInteractive(true); - //cppoptlib::LbfgsSolver solver; - //cppoptlib::ConjugatedGradientDescentSolver solver; - cppoptlib::GradientDescentSolver solver; + cppoptlib::ConjugatedGradientDescentSolver solver; + //cppoptlib::GradientDescentSolver solver; int n = m_molecule->atomCount(); // we have to cast the current 3d positions into a VectorXd @@ -146,17 +144,17 @@ void Forcefield::optimize() cppoptlib::Criteria crit = cppoptlib::Criteria::defaults(); // e.g., every N steps, update coordinates - crit.iterations = 10; + crit.iterations = m_nSteps; // we don't set function or gradient criteria // .. these seem to be broken in the solver code // .. so we handle ourselves solver.setStopCriteria(crit); // set the method - std::string recommended = "MMFF94"; + std::string recommended = recommendedForceField(); qDebug() << "Energy method: " << recommended.c_str(); - if (m_method == nullptr) { + if (m_method == nullptr || m_method->identifier() != recommended) { // we have to create the calculator m_method = Calc::EnergyManager::instance().model(recommended); } @@ -181,6 +179,8 @@ void Forcefield::optimize() for (unsigned int i = 0; i < m_maxSteps / crit.iterations; ++i) { solver.minimize(*m_method, positions); + qApp->processEvents(QEventLoop::AllEvents, 500); + currentEnergy = m_method->value(positions); // get the current gradient for force visualization m_method->gradient(positions, gradient); @@ -204,7 +204,7 @@ void Forcefield::optimize() pos[i] = Vector3(*(d), *(d + 1), *(d + 2)); d += 3; - forces[i] = -1.0 * Vector3(gradient[3 * i], gradient[3 * i + 1], + forces[i] = -0.1 * Vector3(gradient[3 * i], gradient[3 * i + 1], gradient[3 * i + 2]); } } @@ -246,7 +246,7 @@ void Forcefield::energy() std::string recommended = recommendedForceField(); qDebug() << "Energy method: " << recommended.c_str(); - if (m_method == nullptr) { + if (m_method == nullptr || m_method->identifier() != recommended) { // we have to create the calculator m_method = Calc::EnergyManager::instance().model(recommended); } diff --git a/avogadro/qtplugins/forcefield/scriptenergy.cpp b/avogadro/qtplugins/forcefield/scriptenergy.cpp index 939d6ca1b8..60671b2cb4 100644 --- a/avogadro/qtplugins/forcefield/scriptenergy.cpp +++ b/avogadro/qtplugins/forcefield/scriptenergy.cpp @@ -154,7 +154,6 @@ void ScriptEnergy::gradient(const Eigen::VectorXd& x, Eigen::VectorXd& grad) // parse the result // first split on newlines QStringList lines = QString(result).remove('\r').split('\n'); - double energy = 0.0; unsigned int i = 0; bool readingGrad = false; for (auto line : lines) { @@ -166,9 +165,9 @@ void ScriptEnergy::gradient(const Eigen::VectorXd& x, Eigen::VectorXd& grad) if (readingGrad) { QStringList items = line.split(" "); if (items.size() == 3) { - grad[i] = items[0].toDouble(); - grad[i + 1] = items[1].toDouble(); - grad[i + 2] = items[2].toDouble(); + grad[i] = -1.0*items[0].toDouble(); + grad[i + 1] = -1.0*items[1].toDouble(); + grad[i + 2] = -1.0*items[2].toDouble(); i += 3; }