Skip to content

Commit

Permalink
Don't bother calculating dipole moments for empty or 1-atom mols
Browse files Browse the repository at this point in the history
Signed-off-by: Geoff Hutchison <[email protected]>
  • Loading branch information
ghutchis committed Dec 6, 2024
1 parent aacaa48 commit 96abbe8
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
4 changes: 4 additions & 0 deletions avogadro/calc/chargemanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
3 changes: 3 additions & 0 deletions avogadro/calc/chargemodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 96abbe8

Please sign in to comment.