From 56d5456c200276c19b94993e9a71acbc746ff951 Mon Sep 17 00:00:00 2001 From: Geoff Hutchison Date: Wed, 11 Dec 2024 14:38:33 -0500 Subject: [PATCH 1/2] Add a quick "change elements" command (e.g., setting to dummy) Signed-off-by: Geoff Hutchison --- avogadro/qtplugins/CMakeLists.txt | 19 ++--- avogadro/qtplugins/alchemy/CMakeLists.txt | 10 +++ avogadro/qtplugins/alchemy/alchemy.cpp | 89 +++++++++++++++++++++++ avogadro/qtplugins/alchemy/alchemy.h | 58 +++++++++++++++ 4 files changed, 165 insertions(+), 11 deletions(-) create mode 100644 avogadro/qtplugins/alchemy/CMakeLists.txt create mode 100644 avogadro/qtplugins/alchemy/alchemy.cpp create mode 100644 avogadro/qtplugins/alchemy/alchemy.h diff --git a/avogadro/qtplugins/CMakeLists.txt b/avogadro/qtplugins/CMakeLists.txt index 36122820dc..4c158737f2 100644 --- a/avogadro/qtplugins/CMakeLists.txt +++ b/avogadro/qtplugins/CMakeLists.txt @@ -96,20 +96,26 @@ endfunction() # Now to make the plugins. add_subdirectory(3dmol) -add_subdirectory(applycolors) +add_subdirectory(alchemy) add_subdirectory(aligntool) +add_subdirectory(apbs) +add_subdirectory(applycolors) add_subdirectory(bondcentrictool) add_subdirectory(bonding) add_subdirectory(cartoons) add_subdirectory(centroid) add_subdirectory(configurepython) +add_subdirectory(coordinateeditor) add_subdirectory(copypaste) +add_subdirectory(cp2kinput) add_subdirectory(crystal) add_subdirectory(customelements) # add_subdirectory(dipole) add_subdirectory(editor) add_subdirectory(fetchpdb) add_subdirectory(focus) +add_subdirectory(forcefield) +add_subdirectory(gamessinput) add_subdirectory(hydrogens) add_subdirectory(importpqr) add_subdirectory(insertdna) @@ -135,20 +141,11 @@ if(USE_SPGLIB) add_subdirectory(spacegroup) endif() add_subdirectory(surfaces) +add_subdirectory(svg) add_subdirectory(templatetool) add_subdirectory(vibrations) add_subdirectory(vrml) -# These should work after the QRegExp migration -add_subdirectory(apbs) -add_subdirectory(coordinateeditor) -add_subdirectory(cp2kinput) -add_subdirectory(forcefield) -add_subdirectory(gamessinput) - -# The SVG library changed in Qt6 -add_subdirectory(svg) - # Plugins that require VTK if(USE_VTK) add_subdirectory(coloropacitymap) diff --git a/avogadro/qtplugins/alchemy/CMakeLists.txt b/avogadro/qtplugins/alchemy/CMakeLists.txt new file mode 100644 index 0000000000..4c38b45189 --- /dev/null +++ b/avogadro/qtplugins/alchemy/CMakeLists.txt @@ -0,0 +1,10 @@ +include_directories(${CMAKE_CURRENT_BINARY_DIR}) + +avogadro_plugin(Alchemy + "Change elements" + ExtensionPlugin + alchemy.h + Alchemy + "alchemy.cpp" + "" +) diff --git a/avogadro/qtplugins/alchemy/alchemy.cpp b/avogadro/qtplugins/alchemy/alchemy.cpp new file mode 100644 index 0000000000..7f5162e3d6 --- /dev/null +++ b/avogadro/qtplugins/alchemy/alchemy.cpp @@ -0,0 +1,89 @@ +/****************************************************************************** + This source file is part of the Avogadro project. + This source code is released under the 3-Clause BSD License, (see "LICENSE"). +******************************************************************************/ + +#include "alchemy.h" + +#include +#include + +#include +#include +#include +#include + +#include + +namespace Avogadro::QtPlugins { + +using Core::Array; +using Core::Elements; + +Alchemy::Alchemy(QObject* parent_) + : Avogadro::QtGui::ExtensionPlugin(parent_), + m_action(new QAction(tr("Change Elements…"), this)), m_molecule(nullptr) +{ + m_action->setProperty("menu priority", 750); + + connect(m_action, &QAction::triggered, this, &Alchemy::changeElements); +} + +Alchemy::~Alchemy() {} + +QList Alchemy::actions() const +{ + QList result; + return result << m_action; +} + +QStringList Alchemy::menuPath(QAction*) const +{ + return QStringList() << tr("&Build"); +} + +void Alchemy::setMolecule(QtGui::Molecule* mol) +{ + m_molecule = mol; +} + +void Alchemy::changeElements() +{ + if (!m_molecule) + return; + + // assemble the list of elements + QStringList choices; + for (unsigned char i = 0; i < Elements::elementCount(); ++i) { + QString choice("%1: %2"); + choice = choice.arg(i).arg(Elements::name(i)); + choices << choice; + } + + // get the element of the first selected atom + unsigned char firstElement = 0; + for (Index i = 0; i < m_molecule->atomCount(); ++i) { + if (m_molecule->atomSelected(i)) { + firstElement = m_molecule->atom(i).atomicNumber(); + break; + } + } + + bool ok = false; + QString currentChoice = QInputDialog::getItem( + qobject_cast(parent()), tr("Change Elements"), tr("Element:"), + choices, static_cast(firstElement), false, &ok); + if (!ok) + return; + + unsigned char newElement = currentChoice.section(':', 0, 0).toUShort(); + // loop through the selected atoms and change their elements + for (Index i = 0; i < m_molecule->atomCount(); ++i) { + if (m_molecule->atomSelected(i)) + m_molecule->atom(i).setAtomicNumber(newElement); + } + + m_molecule->emitChanged(QtGui::Molecule::Atoms); +} + +} // namespace Avogadro::QtPlugins diff --git a/avogadro/qtplugins/alchemy/alchemy.h b/avogadro/qtplugins/alchemy/alchemy.h new file mode 100644 index 0000000000..1b28b689aa --- /dev/null +++ b/avogadro/qtplugins/alchemy/alchemy.h @@ -0,0 +1,58 @@ +/****************************************************************************** + This source file is part of the Avogadro project. + + This source code is released under the New BSD License, (the "License"). +******************************************************************************/ + +#ifndef AVOGADRO_QTPLUGINS_BONDING_H +#define AVOGADRO_QTPLUGINS_BONDING_H + +#include +#include + +#include + +namespace Ui { +class BondingDialog; +} + +namespace Avogadro { +namespace QtPlugins { + +/** + * @brief The Bonding class performs bonding operations on demand. + */ +class Alchemy : public QtGui::ExtensionPlugin +{ + Q_OBJECT +public: + explicit Alchemy(QObject* parent_ = nullptr); + ~Alchemy() override; + + QString name() const override { return tr("Alchemy"); } + + QString description() const override + { + return tr("Change elements of atoms."); + } + + QList actions() const override; + + QStringList menuPath(QAction* action) const override; + +public slots: + void setMolecule(QtGui::Molecule* mol) override; + +private slots: + void changeElements(); + +private: + QtGui::Molecule* m_molecule; + + QAction* m_action; +}; + +} // namespace QtPlugins +} // namespace Avogadro + +#endif // AVOGADRO_QTPLUGINS_BONDING_H From 716b9990811dcd8110c65fc0093cc35a939c79db Mon Sep 17 00:00:00 2001 From: Geoff Hutchison Date: Fri, 13 Dec 2024 11:34:17 -0500 Subject: [PATCH 2/2] Fix compile error with Qt6 Signed-off-by: Geoff Hutchison --- avogadro/qtplugins/alchemy/alchemy.cpp | 2 +- avogadro/qtplugins/alchemy/alchemy.h | 9 ++++----- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/avogadro/qtplugins/alchemy/alchemy.cpp b/avogadro/qtplugins/alchemy/alchemy.cpp index 7f5162e3d6..a9bb60dff5 100644 --- a/avogadro/qtplugins/alchemy/alchemy.cpp +++ b/avogadro/qtplugins/alchemy/alchemy.cpp @@ -8,8 +8,8 @@ #include #include +#include #include -#include #include #include diff --git a/avogadro/qtplugins/alchemy/alchemy.h b/avogadro/qtplugins/alchemy/alchemy.h index 1b28b689aa..b7aa459b20 100644 --- a/avogadro/qtplugins/alchemy/alchemy.h +++ b/avogadro/qtplugins/alchemy/alchemy.h @@ -1,11 +1,10 @@ /****************************************************************************** This source file is part of the Avogadro project. - - This source code is released under the New BSD License, (the "License"). + This source code is released under the 3-Clause BSD License, (see "LICENSE"). ******************************************************************************/ -#ifndef AVOGADRO_QTPLUGINS_BONDING_H -#define AVOGADRO_QTPLUGINS_BONDING_H +#ifndef AVOGADRO_QTPLUGINS_ALCHEMY_H +#define AVOGADRO_QTPLUGINS_ALCHEMY_H #include #include @@ -55,4 +54,4 @@ private slots: } // namespace QtPlugins } // namespace Avogadro -#endif // AVOGADRO_QTPLUGINS_BONDING_H +#endif // AVOGADRO_QTPLUGINS_ALCHEMY_H