From 96abbe86663b032f7ebbcc01439aa48557de8386 Mon Sep 17 00:00:00 2001 From: Geoff Hutchison Date: Fri, 6 Dec 2024 16:02:53 -0500 Subject: [PATCH] Don't bother calculating dipole moments for empty or 1-atom mols Signed-off-by: Geoff Hutchison --- avogadro/calc/chargemanager.cpp | 4 ++++ avogadro/calc/chargemodel.cpp | 3 +++ 2 files changed, 7 insertions(+) diff --git a/avogadro/calc/chargemanager.cpp b/avogadro/calc/chargemanager.cpp index e4a397b869..21775a98b6 100644 --- a/avogadro/calc/chargemanager.cpp +++ b/avogadro/calc/chargemanager.cpp @@ -164,6 +164,10 @@ Vector3 ChargeManager::dipoleMoment(const std::string& identifier, return Vector3(0.0, 0.0, 0.0); } + if (molecule.atomCount() < 2) { + return Vector3(0.0, 0.0, 0.0); + } + const auto id = m_identifiers[lowerId]; const ChargeModel* model = m_models[id]; return model->dipoleMoment(molecule); diff --git a/avogadro/calc/chargemodel.cpp b/avogadro/calc/chargemodel.cpp index 995aea758c..eedfd68fb9 100644 --- a/avogadro/calc/chargemodel.cpp +++ b/avogadro/calc/chargemodel.cpp @@ -23,6 +23,9 @@ constexpr double M_PI = 3.14159265358979323846; Vector3 ChargeModel::dipoleMoment(const Molecule& mol) const { + if (mol.atomCount() < 2) + return Vector3(0.0, 0.0, 0.0); + // default is to get the set of partial atomic charges // (some models might do something more sophisticated) const MatrixX charges = partialCharges(mol);