From b10ab7b689dbcee6e2bb0f48be3a8755f435c0f1 Mon Sep 17 00:00:00 2001 From: Geoff Hutchison Date: Thu, 21 Nov 2024 11:48:39 -0500 Subject: [PATCH 1/6] For now, disable dipole moment rendering until crash is fixed Signed-off-by: Geoff Hutchison --- avogadro/qtplugins/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/avogadro/qtplugins/CMakeLists.txt b/avogadro/qtplugins/CMakeLists.txt index 1926f7f749..36122820dc 100644 --- a/avogadro/qtplugins/CMakeLists.txt +++ b/avogadro/qtplugins/CMakeLists.txt @@ -106,7 +106,7 @@ add_subdirectory(configurepython) add_subdirectory(copypaste) add_subdirectory(crystal) add_subdirectory(customelements) -add_subdirectory(dipole) +# add_subdirectory(dipole) add_subdirectory(editor) add_subdirectory(fetchpdb) add_subdirectory(focus) From c93388c6aa12b8560a0835be29d6f164103d48f8 Mon Sep 17 00:00:00 2001 From: Geoff Hutchison Date: Wed, 20 Nov 2024 17:41:19 -0500 Subject: [PATCH 2/6] Fix some minor bugs with vector support in the Variant class Signed-off-by: Geoff Hutchison Signed-off-by: Geoff Hutchison --- avogadro/core/variant-inline.h | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/avogadro/core/variant-inline.h b/avogadro/core/variant-inline.h index 77379df89c..cc884d6aba 100644 --- a/avogadro/core/variant-inline.h +++ b/avogadro/core/variant-inline.h @@ -411,7 +411,8 @@ inline const Vector3& Variant::value() const if (m_type == Vector) return *m_value.vector; - return Vector3::Zero(); + static Vector3 nullVector(0, 0, 0); + return nullVector; } inline void Variant::clear() @@ -422,6 +423,9 @@ inline void Variant::clear() } else if (m_type == Matrix) { delete m_value.matrix; m_value.matrix = 0; + } else if (m_type == Vector) { + delete m_value.vector; + m_value.vector = 0; } m_type = Null; @@ -527,6 +531,8 @@ inline Variant& Variant::operator=(const Variant& variant) m_value.string = new std::string(variant.toString()); else if (m_type == Matrix) m_value.matrix = new MatrixX(*variant.m_value.matrix); + else if (m_type == Vector) + m_value.vector = new Vector3(*variant.m_value.vector); else if (m_type != Null) m_value = variant.m_value; } From 12ca1348b3c610fa99b7baf5d4dbcbdee0683f1a Mon Sep 17 00:00:00 2001 From: Geoff Hutchison Date: Thu, 21 Nov 2024 13:22:26 -0500 Subject: [PATCH 3/6] Allow editing molecule name, charge and spin Signed-off-by: Geoff Hutchison --- .../molecularproperties/molecularmodel.cpp | 58 ++++++++++++++++--- .../molecularproperties/molecularview.cpp | 1 + 2 files changed, 51 insertions(+), 8 deletions(-) diff --git a/avogadro/qtplugins/molecularproperties/molecularmodel.cpp b/avogadro/qtplugins/molecularproperties/molecularmodel.cpp index d28aa37f9f..ce58cef17d 100644 --- a/avogadro/qtplugins/molecularproperties/molecularmodel.cpp +++ b/avogadro/qtplugins/molecularproperties/molecularmodel.cpp @@ -243,9 +243,10 @@ QVariant MolecularModel::data(const QModelIndex& index, int role) const else if (key == " 7residues") return QVariant::fromValue(m_molecule->residueCount()); else if (key == " 9totalCharge") - return QVariant::fromValue(m_molecule->totalCharge()); + return QVariant::fromValue(static_cast(m_molecule->totalCharge())); else if (key == " 9totalSpinMultiplicity") - return QVariant::fromValue(m_molecule->totalSpinMultiplicity()); + return QVariant::fromValue( + static_cast(m_molecule->totalSpinMultiplicity())); return QString::fromStdString(it->second.toString()); } @@ -336,6 +337,19 @@ Qt::ItemFlags MolecularModel::flags(const QModelIndex& index) const // for the types and columns that can be edited auto editable = Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsEditable; + int row = index.row(); + int col = index.column(); + + if (row == 0) // name + return editable; + + const auto map = m_propertiesCache; + auto it = map.begin(); + std::advance(it, row); + auto key = it->first; + if (key == " 9totalCharge" || key == " 9totalSpinMultiplicity") + return editable; + return QAbstractItemModel::flags(index); } @@ -348,7 +362,35 @@ bool MolecularModel::setData(const QModelIndex& index, const QVariant& value, if (role != Qt::EditRole) return false; - // TODO allow editing name, total charge, total spin multiplicity + int row = index.row(); + int col = index.column(); + + if (row == 0) { // name should always be the first row + m_name = value.toString(); + m_autoName = false; + m_molecule->setData("name", m_name.toStdString()); + emit dataChanged(index, index); + return true; + } + + const auto map = m_propertiesCache; + auto it = map.begin(); + std::advance(it, row); + auto key = it->first; + if (key == " 9totalCharge") { + m_molecule->setData("totalCharge", value.toInt()); + emit dataChanged(index, index); + return true; + } else if (key == " 9totalSpinMultiplicity") { + int spin = value.toInt(); + if (spin < 0) + return false; + + m_molecule->setData("totalSpinMultiplicity", value.toInt()); + emit dataChanged(index, index); + return true; + } + return false; } @@ -391,11 +433,11 @@ void MolecularModel::updateTable(unsigned int flags) m_propertiesCache.setValue(" 8chains", chainCount); } - if (m_molecule->totalCharge() != 0) - m_propertiesCache.setValue(" 9totalCharge", m_molecule->totalCharge()); - if (m_molecule->totalSpinMultiplicity() != 1) - m_propertiesCache.setValue(" 9totalSpinMultiplicity", - m_molecule->totalSpinMultiplicity()); + m_propertiesCache.setValue(" 9totalCharge", + static_cast(m_molecule->totalCharge())); + m_propertiesCache.setValue( + " 9totalSpinMultiplicity", + static_cast(m_molecule->totalSpinMultiplicity())); if (m_molecule->hasData("dipoleMoment")) { auto dipole = m_molecule->data("dipoleMoment").toVector3(); QString moment = QString::number(dipole.norm(), 'f', 3); diff --git a/avogadro/qtplugins/molecularproperties/molecularview.cpp b/avogadro/qtplugins/molecularproperties/molecularview.cpp index 81721b3165..a95cb62003 100644 --- a/avogadro/qtplugins/molecularproperties/molecularview.cpp +++ b/avogadro/qtplugins/molecularproperties/molecularview.cpp @@ -174,6 +174,7 @@ void MolecularView::openExportDialogBox() // Write the data rows for (int row = 0; row < model()->rowCount(); ++row) { + stream << model()->headerData(row, Qt::Vertical).toString() << ","; for (int col = 0; col < model()->columnCount(); ++col) { stream << model()->index(row, col).data().toString(); if (col < model()->columnCount() - 1) { From a403569367e60a8139c2eb0c6e30480b9208bdce Mon Sep 17 00:00:00 2001 From: Geoff Hutchison Date: Thu, 21 Nov 2024 17:56:11 -0500 Subject: [PATCH 4/6] Fix minor unused variable warning Signed-off-by: Geoff Hutchison --- avogadro/qtplugins/molecularproperties/molecularmodel.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/avogadro/qtplugins/molecularproperties/molecularmodel.cpp b/avogadro/qtplugins/molecularproperties/molecularmodel.cpp index ce58cef17d..fcff9b5345 100644 --- a/avogadro/qtplugins/molecularproperties/molecularmodel.cpp +++ b/avogadro/qtplugins/molecularproperties/molecularmodel.cpp @@ -338,7 +338,6 @@ Qt::ItemFlags MolecularModel::flags(const QModelIndex& index) const auto editable = Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsEditable; int row = index.row(); - int col = index.column(); if (row == 0) // name return editable; @@ -363,7 +362,6 @@ bool MolecularModel::setData(const QModelIndex& index, const QVariant& value, return false; int row = index.row(); - int col = index.column(); if (row == 0) { // name should always be the first row m_name = value.toString(); From 7e917e209b70738486bc49bf5fef3c390a0ff5f6 Mon Sep 17 00:00:00 2001 From: Geoff Hutchison Date: Thu, 21 Nov 2024 17:57:55 -0500 Subject: [PATCH 5/6] Set default charge and spin for most script input generators Signed-off-by: Geoff Hutchison --- avogadro/molequeue/inputgeneratorwidget.cpp | 13 +++++++++++-- avogadro/qtgui/jsonwidget.cpp | 14 +++++++++++++- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/avogadro/molequeue/inputgeneratorwidget.cpp b/avogadro/molequeue/inputgeneratorwidget.cpp index f6f4c5f699..4c1ae8914b 100644 --- a/avogadro/molequeue/inputgeneratorwidget.cpp +++ b/avogadro/molequeue/inputgeneratorwidget.cpp @@ -64,8 +64,10 @@ void InputGeneratorWidget::setMolecule(QtGui::Molecule* mol) m_molecule->disconnect(this); m_molecule = mol; - if (mol) { + // make sure to call the base class method + QtGui::JsonWidget::setMolecule(mol); + connect(mol, SIGNAL(changed(unsigned int)), SLOT(updatePreviewText())); connect(mol, SIGNAL(changed(unsigned int)), SLOT(updateTitlePlaceholder())); } @@ -120,6 +122,13 @@ void InputGeneratorWidget::showEvent(QShowEvent* e) { QWidget::showEvent(e); + if (m_molecule != nullptr) { + int charge = static_cast(m_molecule->totalCharge()); + int multiplicity = static_cast(m_molecule->totalSpinMultiplicity()); + setOption("Charge", charge); + setOption("Multiplicity", multiplicity); + } + // Update the preview text if an update was requested while hidden. Use a // single shot to allow the dialog to show before popping up any warnings. if (m_updatePending) @@ -649,4 +658,4 @@ void InputGeneratorWidget::updateOptions() setOptionDefaults(); } -} // namespace Avogadro +} // namespace Avogadro::MoleQueue diff --git a/avogadro/qtgui/jsonwidget.cpp b/avogadro/qtgui/jsonwidget.cpp index 237745c235..1e04b9f4ab 100644 --- a/avogadro/qtgui/jsonwidget.cpp +++ b/avogadro/qtgui/jsonwidget.cpp @@ -40,6 +40,15 @@ JsonWidget::~JsonWidget() {} void JsonWidget::setMolecule(QtGui::Molecule* mol) { + if (m_molecule != nullptr) { + // update charge and multiplicity if needed + int charge = static_cast(m_molecule->totalCharge()); + int multiplicity = static_cast(m_molecule->totalSpinMultiplicity()); + + setOption("Charge", charge); + setOption("Multiplicity", multiplicity); + } + if (mol == m_molecule) return; @@ -816,8 +825,11 @@ QJsonObject JsonWidget::collectOptions() const void JsonWidget::applyOptions(const QJsonObject& opts) { - foreach (const QString& label, opts.keys()) + foreach (const QString& label, opts.keys()) { setOption(label, opts[label]); + + qDebug() << "Setting option" << label << "to" << opts[label]; + } } QString JsonWidget::generateJobTitle() const From e2fc0b8ff1822c820d703cb1c8c2b92447a05efd Mon Sep 17 00:00:00 2001 From: Geoff Hutchison Date: Thu, 21 Nov 2024 18:36:26 -0500 Subject: [PATCH 6/6] Fix typo with minimum spin value Signed-off-by: Geoff Hutchison --- avogadro/qtplugins/molecularproperties/molecularmodel.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/avogadro/qtplugins/molecularproperties/molecularmodel.cpp b/avogadro/qtplugins/molecularproperties/molecularmodel.cpp index fcff9b5345..ccd2ae7408 100644 --- a/avogadro/qtplugins/molecularproperties/molecularmodel.cpp +++ b/avogadro/qtplugins/molecularproperties/molecularmodel.cpp @@ -381,7 +381,7 @@ bool MolecularModel::setData(const QModelIndex& index, const QVariant& value, return true; } else if (key == " 9totalSpinMultiplicity") { int spin = value.toInt(); - if (spin < 0) + if (spin < 1) return false; m_molecule->setData("totalSpinMultiplicity", value.toInt());