diff --git a/avogadro/qtplugins/applycolors/applycolors.cpp b/avogadro/qtplugins/applycolors/applycolors.cpp index 4ca45fc4a7..28c5f66fd6 100644 --- a/avogadro/qtplugins/applycolors/applycolors.cpp +++ b/avogadro/qtplugins/applycolors/applycolors.cpp @@ -12,10 +12,12 @@ #include #include -#include #include #include #include +#include + +#include using namespace tinycolormap; @@ -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(); @@ -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); @@ -568,4 +576,4 @@ void ApplyColors::applyShapelyColors() m_molecule->emitChanged(QtGui::Molecule::Atoms); } -} // namespace Avogadro +} // namespace Avogadro::QtPlugins diff --git a/avogadro/quantumio/orca.cpp b/avogadro/quantumio/orca.cpp index 4a317db3f8..52c15598f6 100644 --- a/avogadro/quantumio/orca.cpp +++ b/avogadro/quantumio/orca.cpp @@ -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()) { @@ -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);