Skip to content

Commit

Permalink
Use relative energies for conformer table
Browse files Browse the repository at this point in the history
Also enable / disable based on changes to the molecule
(probably should be true for other actions, e.g. 1-4 atoms)

Signed-off-by: Geoff Hutchison <[email protected]>
  • Loading branch information
ghutchis committed Dec 4, 2024
1 parent 11c4ccd commit 99cd8f3
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 6 deletions.
11 changes: 8 additions & 3 deletions avogadro/qtplugins/propertytables/propertymodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -423,9 +423,14 @@ QVariant PropertyModel::data(const QModelIndex& index, int role) const
case ConformerDataEnergy: {
double energy = 0.0;
if (m_molecule->hasData("energies")) {
auto energies = m_molecule->data("energies").toList();
std::vector<double> energies = m_molecule->data("energies").toList();
// calculate the minimum
double minEnergy = std::numeric_limits<double>::max();
for (double e : energies) {
minEnergy = std::min(minEnergy, e);
}
if (row < static_cast<int>(energies.size()))
energy = energies[row];
energy = energies[row] - minEnergy;
}
return QString("%L1").arg(energy, 0, 'f', 4);
}
Expand Down Expand Up @@ -558,7 +563,7 @@ QVariant PropertyModel::headerData(int section, Qt::Orientation orientation,
return tr("RMSD (Å)", "root mean squared displacement in Angstrom");
case ConformerDataEnergy:
// should only hit this if we have energies anyway
return hasEnergies ? tr("Energy") : tr("Property");
return hasEnergies ? tr("Energy (kcal/mol)") : tr("Property");
}
} else // row headers
return QString("%L1").arg(section + 1);
Expand Down
13 changes: 12 additions & 1 deletion avogadro/qtplugins/propertytables/propertytables.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,18 @@ void PropertyTables::setMolecule(QtGui::Molecule* mol)

m_molecule = mol;

// check if there are residues
updateActions();

// update if the molecule changes
connect(m_molecule, SIGNAL(changed(unsigned int)), SLOT(updateActions()));
}

void PropertyTables::updateActions()
{
if (m_molecule == nullptr)
return;

// check if we enable / disable the residue and conformer actions
bool haveResidues = (m_molecule->residueCount() > 0);
// technically coordinate sets
bool haveConformers = (m_molecule->coordinate3dCount() > 1);
Expand Down
3 changes: 2 additions & 1 deletion avogadro/qtplugins/propertytables/propertytables.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,13 @@ class PropertyTables : public Avogadro::QtGui::ExtensionPlugin

public slots:
void setMolecule(QtGui::Molecule* mol) override;
void updateActions();

private slots:
void showDialog();

private:
QList<QAction *> m_actions;
QList<QAction*> m_actions;
QtGui::Molecule* m_molecule;
};

Expand Down
5 changes: 4 additions & 1 deletion avogadro/qtplugins/propertytables/propertyview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,10 @@ PropertyView::PropertyView(PropertyType type, QWidget* parent)
// You can select everything (e.g., to copy, select all, etc.)
setCornerButtonEnabled(true);
setSelectionBehavior(QAbstractItemView::SelectRows);
setSelectionMode(QAbstractItemView::ExtendedSelection);
if (type == ConformerType)
setSelectionMode(QAbstractItemView::SingleSelection);
else
setSelectionMode(QAbstractItemView::ExtendedSelection);
// Alternating row colors
setAlternatingRowColors(true);
// Allow sorting the table
Expand Down

0 comments on commit 99cd8f3

Please sign in to comment.