Skip to content

Commit

Permalink
Generate the density matrix if needed for the electron density surface
Browse files Browse the repository at this point in the history
  • Loading branch information
ghutchis committed Nov 28, 2023
1 parent 57e0dd6 commit 4e52a46
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
9 changes: 8 additions & 1 deletion avogadro/core/gaussiansettools.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,13 @@ double GaussianSetTools::calculateMolecularOrbital(const Vector3& position,
}

bool GaussianSetTools::calculateElectronDensity(Cube& cube) const
{
{
const MatrixX& matrix = m_basis->densityMatrix();
if (matrix.rows() == 0 || matrix.cols() == 0) {
// we don't have a density matrix, so generate one
m_basis->generateDensityMatrix();
}

for (size_t i = 0; i < cube.data()->size(); ++i) {
Vector3 pos = cube.position(i);
cube.setValue(i, calculateElectronDensity(pos));
Expand All @@ -67,6 +73,7 @@ double GaussianSetTools::calculateElectronDensity(const Vector3& position) const
{
const MatrixX& matrix = m_basis->densityMatrix();
int matrixSize(static_cast<int>(m_basis->moMatrix().rows()));

if (matrix.rows() != matrixSize || matrix.cols() != matrixSize) {
return 0.0;
}
Expand Down
12 changes: 9 additions & 3 deletions avogadro/qtplugins/surfaces/gaussiansetconcurrent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ void GaussianSetConcurrent::setMolecule(Core::Molecule* mol)
if (!mol)
return;
m_set = dynamic_cast<GaussianSet*>(mol->basisSet());
delete m_tools;

delete m_tools;
m_tools = new GaussianSetTools(mol);
}

Expand All @@ -76,6 +76,12 @@ bool GaussianSetConcurrent::calculateMolecularOrbital(Core::Cube* cube,

bool GaussianSetConcurrent::calculateElectronDensity(Core::Cube* cube)
{
const MatrixX& matrix = m_set->densityMatrix();
if (matrix.rows() == 0 || matrix.cols() == 0) {
// we don't have a density matrix, so calculate one
m_set->generateDensityMatrix();
}

return setUpCalculation(cube, 0, GaussianSetConcurrent::processDensity);
}

Expand Down Expand Up @@ -141,4 +147,4 @@ void GaussianSetConcurrent::processSpinDensity(GaussianShell& shell)
Vector3 pos = shell.tCube->position(shell.pos);
shell.tCube->setValue(shell.pos, shell.tools->calculateSpinDensity(pos));
}
}
} // namespace Avogadro::QtPlugins

1 comment on commit 4e52a46

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ERROR: clang-format-diff detected formatting issues. See the artifact for a patch or run clang-format on your branch.

Please sign in to comment.