Skip to content

Commit

Permalink
Merge branch 'master' into add-orca-coord-sets
Browse files Browse the repository at this point in the history
Signed-off-by: Geoff Hutchison <[email protected]>
  • Loading branch information
ghutchis authored Nov 22, 2024
2 parents 6aa00f3 + 16a8ef4 commit dc25b47
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 12 deletions.
13 changes: 11 additions & 2 deletions avogadro/molequeue/inputgeneratorwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()));
}
Expand Down Expand Up @@ -120,6 +122,13 @@ void InputGeneratorWidget::showEvent(QShowEvent* e)
{
QWidget::showEvent(e);

if (m_molecule != nullptr) {
int charge = static_cast<int>(m_molecule->totalCharge());
int multiplicity = static_cast<int>(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)
Expand Down Expand Up @@ -649,4 +658,4 @@ void InputGeneratorWidget::updateOptions()
setOptionDefaults();
}

} // namespace Avogadro
} // namespace Avogadro::MoleQueue
14 changes: 13 additions & 1 deletion avogadro/qtgui/jsonwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<int>(m_molecule->totalCharge());
int multiplicity = static_cast<int>(m_molecule->totalSpinMultiplicity());

setOption("Charge", charge);
setOption("Multiplicity", multiplicity);
}

if (mol == m_molecule)
return;

Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion avogadro/qtplugins/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
56 changes: 48 additions & 8 deletions avogadro/qtplugins/molecularproperties/molecularmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<int>(m_molecule->totalCharge()));
else if (key == " 9totalSpinMultiplicity")
return QVariant::fromValue(m_molecule->totalSpinMultiplicity());
return QVariant::fromValue(
static_cast<int>(m_molecule->totalSpinMultiplicity()));

return QString::fromStdString(it->second.toString());
}
Expand Down Expand Up @@ -336,6 +337,18 @@ 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();

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);
}

Expand All @@ -348,7 +361,34 @@ 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();

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 < 1)
return false;

m_molecule->setData("totalSpinMultiplicity", value.toInt());
emit dataChanged(index, index);
return true;
}

return false;
}

Expand Down Expand Up @@ -391,11 +431,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<int>(m_molecule->totalCharge()));
m_propertiesCache.setValue(
" 9totalSpinMultiplicity",
static_cast<int>(m_molecule->totalSpinMultiplicity()));
if (m_molecule->hasData("dipoleMoment")) {
auto dipole = m_molecule->data("dipoleMoment").toVector3();
QString moment = QString::number(dipole.norm(), 'f', 3);
Expand Down
1 change: 1 addition & 0 deletions avogadro/qtplugins/molecularproperties/molecularview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit dc25b47

Please sign in to comment.