| 1 |
/****************************************************************************** |
| 2 |
This source file is part of the Avogadro project. |
| 3 |
This source code is released under the 3-Clause BSD License, (see "LICENSE"). |
| 4 |
******************************************************************************/ |
| 5 |
|
| 6 |
#ifndef AVOGADRO_QTPLUGINS_ORBITALTABLEMODEL_H |
| 7 |
#define AVOGADRO_QTPLUGINS_ORBITALTABLEMODEL_H |
| 8 |
|
| 9 |
#include <QAbstractTableModel> |
| 10 |
#include <QSortFilterProxyModel> |
| 11 |
|
| 12 |
#include <avogadro/core/basisset.h> |
| 13 |
|
| 14 |
namespace Avogadro::Core { |
| 15 |
class BasisSet; |
| 16 |
} |
| 17 |
|
| 18 |
namespace Avogadro::QtPlugins { |
| 19 |
|
| 20 |
struct calcInfo; |
| 21 |
|
| 22 |
struct Orbital |
| 23 |
{ |
| 24 |
double energy; |
| 25 |
int index; |
| 26 |
Core::BasisSet::ElectronType electronType; // Paired, Alpha, or Beta |
| 27 |
QString description; // (HOMO|LUMO)[(+|-)N] |
| 28 |
QString symmetry; // e.g., A1g (with subscripts) |
| 29 |
calcInfo* queueEntry; |
| 30 |
float occupation; // 0, 1, or 2 (supports future fractional) |
| 31 |
}; |
| 32 |
|
| 33 |
// Used for sorting: |
| 34 |
class OrbitalSortingProxyModel : public QSortFilterProxyModel |
| 35 |
{ |
| 36 |
Q_OBJECT |
| 37 |
|
| 38 |
public: |
| 39 |
OrbitalSortingProxyModel(QObject* parent = nullptr) |
| 40 |
: QSortFilterProxyModel(parent), m_HOMOFirst(false){}; |
| 41 |
|
| 42 |
bool isHOMOFirst() { return m_HOMOFirst; }; |
| 43 |
void HOMOFirst(bool b) { m_HOMOFirst = b; }; |
| 44 |
|
| 45 |
protected: |
| 46 |
// Compare orbital values |
| 47 |
bool lessThan(const QModelIndex& left, |
| 48 |
const QModelIndex& right) const override |
| 49 |
{ |
| 50 |
if (m_HOMOFirst) |
| 51 |
return left.row() < right.row(); |
| 52 |
else |
| 53 |
return left.row() > right.row(); |
| 54 |
} |
| 55 |
|
| 56 |
private: |
| 57 |
bool m_HOMOFirst; |
| 58 |
}; |
| 59 |
|
| 60 |
class OrbitalTableModel : public QAbstractTableModel |
| 61 |
{ |
| 62 |
Q_OBJECT |
| 63 |
|
| 64 |
public: |
| 65 |
enum Column |
| 66 |
{ |
| 67 |
C_Description = 0, |
| 68 |
C_Energy, |
| 69 |
C_Symmetry, |
| 70 |
C_Occupation, // Shows arrows: ⇅ for paired, ↑ for alpha, ↓ for beta |
| 71 |
C_ElectronType, // hidden column for alpha/beta tracking |
| 72 |
|
| 73 |
COUNT |
| 74 |
}; |
| 75 |
|
| 76 |
//! Constructor |
| 77 |
explicit OrbitalTableModel(QWidget* parent = nullptr); |
| 78 |
//! Deconstructor |
| 79 |
~OrbitalTableModel() override; |
| 80 |
|
| 81 |
int rowCount(const QModelIndex&) const override { return m_orbitals.size(); }; |
| 82 |
int columnCount(const QModelIndex&) const override; |
| 83 |
|
| 84 |
QVariant data(const QModelIndex& index, |
| 85 |
int role = Qt::DisplayRole) const override; |
| 86 |
QVariant headerData(int section, Qt::Orientation orientation, |
| 87 |
int role) const override; |
| 88 |
|
| 89 |
QModelIndex HOMO() const; |
| 90 |
QModelIndex LUMO() const; |
| 91 |
|
| 92 |
//! Get the orbital index (into basis set) for a given row |
| 93 |
int orbitalIndex(int row) const; |
| 94 |
//! Get the electron type for a given row |
| 95 |
Core::BasisSet::ElectronType electronType(int row) const; |
| 96 |
|
| 97 |
bool setOrbitals(const Core::BasisSet* basis); |
| 98 |
bool clearOrbitals(); |
| 99 |
|
| 100 |
private: |
| 101 |
QList<Orbital*> m_orbitals; |
| 102 |
}; |
| 103 |
} // namespace Avogadro::QtPlugins |
| 104 |
|
| 105 |
#endif |