From f0458e8280e7ad3a0db4ecee5ed669592998b0e8 Mon Sep 17 00:00:00 2001 From: Geoff Hutchison Date: Thu, 30 Nov 2023 21:41:51 -0500 Subject: [PATCH] Fix vibration animation Fixes #1445 - animation would "wiggle" from previous frames Optimization steps are now cleared before vibrational modes added Signed-off-by: Geoff Hutchison --- avogadro/core/molecule.cpp | 8 +++++++- avogadro/core/molecule.h | 5 +++++ avogadro/qtplugins/spectra/spectra.cpp | 3 ++- 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/avogadro/core/molecule.cpp b/avogadro/core/molecule.cpp index e064e8ca44..f82d5a3b44 100644 --- a/avogadro/core/molecule.cpp +++ b/avogadro/core/molecule.cpp @@ -81,7 +81,8 @@ void Molecule::readProperties(const Molecule& other) 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.constBegin(); it != other.m_data.constEnd(); ++it) { + for (auto it = other.m_data.constBegin(); it != other.m_data.constEnd(); + ++it) { // even if we have the same key, we want to overwrite m_data.setValue(it->first, it->second); } @@ -1218,6 +1219,11 @@ bool Molecule::setCoordinate3d(int coord) return false; } +void Molecule::clearCoordinate3d() +{ + m_coordinates3d.clear(); +} + Array Molecule::coordinate3d(int index) const { return m_coordinates3d[index]; diff --git a/avogadro/core/molecule.h b/avogadro/core/molecule.h index a242be6ed7..cf05ca2ba3 100644 --- a/avogadro/core/molecule.h +++ b/avogadro/core/molecule.h @@ -553,6 +553,11 @@ class AVOGADROCORE_EXPORT Molecule Array coordinate3d(int index) const; bool setCoordinate3d(const Array& coords, int index); + /** + * Clear coordinate sets (except the default set) + */ + void clearCoordinate3d(); + /** * Timestep property is used when molecular dynamics trajectories are read */ diff --git a/avogadro/qtplugins/spectra/spectra.cpp b/avogadro/qtplugins/spectra/spectra.cpp index d3e1341a7d..09c7e25ee3 100644 --- a/avogadro/qtplugins/spectra/spectra.cpp +++ b/avogadro/qtplugins/spectra/spectra.cpp @@ -139,10 +139,11 @@ void Spectra::setMode(int mode) m_molecule->setForceVector(atom, v); ++atom; } - m_molecule->emitChanged(QtGui::Molecule::Atoms | QtGui::Molecule::Added); + // m_molecule->emitChanged(QtGui::Molecule::Atoms | QtGui::Molecule::Added); int frames = 5; // TODO: needs an option int frameCounter = 0; + m_molecule->clearCoordinate3d(); m_molecule->setCoordinate3d(atomPositions, frameCounter++); // Current coords + displacement.