From 67cc0022d77ff5b8313c090cbff097a55599348f Mon Sep 17 00:00:00 2001 From: Aritz Erkiaga Date: Wed, 13 Jul 2022 21:46:10 +0200 Subject: [PATCH] Workaround charge models locking up or not running Signed-off-by: Aritz Erkiaga --- avogadro/core/molecule.cpp | 1 + avogadro/qtplugins/openbabel/obcharges.cpp | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/avogadro/core/molecule.cpp b/avogadro/core/molecule.cpp index f2f814cb8a..da19638982 100644 --- a/avogadro/core/molecule.cpp +++ b/avogadro/core/molecule.cpp @@ -258,6 +258,7 @@ MatrixX Molecule::partialCharges(const std::string& type) const return search->second; // value from the map } else { MatrixX charges(atomCount(), 1); + charges.fill(0.0); return charges; } } diff --git a/avogadro/qtplugins/openbabel/obcharges.cpp b/avogadro/qtplugins/openbabel/obcharges.cpp index 68641ea344..b2c2c9d405 100644 --- a/avogadro/qtplugins/openbabel/obcharges.cpp +++ b/avogadro/qtplugins/openbabel/obcharges.cpp @@ -198,6 +198,10 @@ MatrixX OBCharges::partialCharges(Core::Molecule& molecule) const charges(i, 0) = output[i]; } + // workaround failed runs causing the code to freeze + if (abs(charges(0, 0)) < 0.00001) + charges(0, 0) = 0.0001; + // cache the charges and allow them to show up in output molecule.setPartialCharges(m_identifier, charges); return charges;