Skip to content

Commit

Permalink
Fixup partial charge parsing in Orca and display in colors
Browse files Browse the repository at this point in the history
Signed-off-by: Geoff Hutchison <geoff.hutchison@gmail.com>
  • Loading branch information
ghutchis committed Nov 25, 2024
1 parent a27910c commit 3e1149c
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 12 deletions.
16 changes: 12 additions & 4 deletions avogadro/qtplugins/applycolors/applycolors.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,12 @@
#include <avogadro/core/vector.h>
#include <avogadro/qtgui/molecule.h>

#include <QStringList>
#include <QAction>
#include <QColorDialog>
#include <QInputDialog>
#include <QStringList>

#include <QDebug>

using namespace tinycolormap;

Expand Down Expand Up @@ -248,14 +250,14 @@ void ApplyColors::applyChargeColors()

// populate the dialog to choose the model and colormap
ChargeColorDialog dialog;
for (const auto &model : identifiers) {
for (const auto& model : identifiers) {
auto name = Calc::ChargeManager::instance().nameForModel(model);
dialog.modelCombo->addItem(name.c_str(), model.c_str());
}
dialog.exec();
if (dialog.result() != QDialog::Accepted)
return;

// get the model and colormap
const auto model = dialog.modelCombo->currentData().toString().toStdString();
const auto colormapName = dialog.colorMapCombo->currentText();
Expand All @@ -267,6 +269,12 @@ void ApplyColors::applyChargeColors()
float maxCharge = 0.0f;
auto charges =
Calc::ChargeManager::instance().partialCharges(model, *m_molecule);
// check if the model string is already a partial charge type
if (m_molecule->partialChargeTypes().find(model) !=
m_molecule->partialChargeTypes().end()) {
charges = m_molecule->partialCharges(model);
}

for (Index i = 0; i < numAtoms; ++i) {
float charge = charges(i, 0);
minCharge = std::min(minCharge, charge);
Expand Down Expand Up @@ -568,4 +576,4 @@ void ApplyColors::applyShapelyColors()
m_molecule->emitChanged(QtGui::Molecule::Atoms);
}

} // namespace Avogadro
} // namespace Avogadro::QtPlugins
19 changes: 11 additions & 8 deletions avogadro/quantumio/orca.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,6 @@ bool ORCAOutput::read(std::istream& in, Core::Molecule& molecule)
return false;
}

// add the partial charges
if (m_partialCharges.size() > 0) {
for (auto it = m_partialCharges.begin(); it != m_partialCharges.end();
++it) {
molecule.setPartialCharges(it->first, it->second);
}
}

if (m_frequencies.size() > 0 &&
m_frequencies.size() == m_vibDisplacements.size() &&
m_frequencies.size() == m_IRintensities.size()) {
Expand Down Expand Up @@ -143,6 +135,17 @@ bool ORCAOutput::read(std::istream& in, Core::Molecule& molecule)
basis->setMolecule(&molecule);
load(basis);

// we have to do a few things *after* any modifications to bonds / atoms
// because those automatically clear partial charges and data

// add the partial charges
if (m_partialCharges.size() > 0) {
for (auto it = m_partialCharges.begin(); it != m_partialCharges.end();
++it) {
molecule.setPartialCharges(it->first, it->second);
}
}

molecule.setData("totalCharge", m_charge);
molecule.setData("totalSpinMultiplicity", m_spin);
molecule.setData("dipoleMoment", m_dipoleMoment);
Expand Down

0 comments on commit 3e1149c

Please sign in to comment.