Skip to content

Commit

Permalink
Make sure to merge properties, not override
Browse files Browse the repository at this point in the history
If the new molecule doesn't have orbitals or vibrations
.. don't ignore our current data

Signed-off-by: Geoff Hutchison <[email protected]>
  • Loading branch information
ghutchis committed Nov 27, 2023
1 parent a724879 commit b01f905
Showing 1 changed file with 24 additions and 8 deletions.
32 changes: 24 additions & 8 deletions avogadro/core/molecule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "mesh.h"
#include "neighborperceiver.h"
#include "residue.h"
#include "slaterset.h"
#include "unitcell.h"

#include <algorithm>
Expand Down Expand Up @@ -77,23 +78,38 @@ Molecule::Molecule(const Molecule& other)

void Molecule::readProperties(const Molecule& other)
{
m_data = other.m_data;
m_partialCharges = other.m_partialCharges;
m_label = other.m_label;
m_colors = other.m_colors;
// merge data maps by iterating through other's map
for (auto it = other.m_data.begin(); it != other.m_data.end(); ++it) {
// even if we have the same key, we want to overwrite
m_data.setValue(it.key(), it.value());
}
// merge partial charge maps
for (auto it = other.m_partialCharges.begin();
it != other.m_partialCharges.end(); ++it) {
m_partialCharges[it.key()] = it.value();
}

// copy orbital information
SlaterSet* slaterSet = dynamic_cast<SlaterSet*>(other.m_basisSet);
if (slaterSet != nullptr) {
m_basisSet = slaterSet->clone();
m_basisSet->setMolecule(this);
}
GaussianSet* gaussianSet = dynamic_cast<GaussianSet*>(other.m_basisSet);
if (gaussianSet) {
if (gaussianSet != nullptr) {
m_basisSet = gaussianSet->clone();
m_basisSet->setMolecule(this);
}

// copy spectra information
m_vibrationFrequencies = other.m_vibrationFrequencies;
m_vibrationIRIntensities = other.m_vibrationIRIntensities;
m_vibrationRamanIntensities = other.m_vibrationRamanIntensities;
m_vibrationLx = other.m_vibrationLx;
// copy over spectra information
if (other.m_vibrationFrequencies.size() > 0) {
m_vibrationFrequencies = other.m_vibrationFrequencies;
m_vibrationIRIntensities = other.m_vibrationIRIntensities;
m_vibrationRamanIntensities = other.m_vibrationRamanIntensities;
m_vibrationLx = other.m_vibrationLx;
}

// Copy over any meshes
for (Index i = 0; i < other.meshCount(); ++i) {
Expand Down

0 comments on commit b01f905

Please sign in to comment.