-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpropertieswindow.cpp
More file actions
142 lines (117 loc) · 4.79 KB
/
propertieswindow.cpp
File metadata and controls
142 lines (117 loc) · 4.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
#include "mainwindow.h"
#include "propertieswindow.h"
#include "ui_propertieswindow.h"
#include <cmath>
#include <QCloseEvent>
#include <QSettings>
#include <QTextStream>
PropertiesWindow::PropertiesWindow(QWidget *parent) :
QWidget(parent, Qt::Tool),
ui(new Ui::PropertiesWindow)
{
ui->setupUi(this);
ui->label->setOpenExternalLinks(false);
ui->label->setWordWrap(true);
connect(ui->label, &QLabel::linkActivated, this, [this](QString link){
const auto orbitalPrefix = QStringLiteral("orbital://");
const auto vibrationPrefix = QStringLiteral("vibration://");
if (link.startsWith(orbitalPrefix))
{
QString surfaceName = link.mid(orbitalPrefix.size());
if(MainWindow *mainwindow = qobject_cast<MainWindow *>(this->parent()))
mainwindow->generateNWChemSurface(surfaceName, 1.0E-02);
}
else if (link.startsWith(vibrationPrefix))
{
int vibrationId = link.mid(vibrationPrefix.size()).toInt();
if(MainWindow *mainwindow = qobject_cast<MainWindow *>(this->parent()))
mainwindow->animateFrequency(vibrationId);
}
});
showData({}, false);
}
PropertiesWindow::~PropertiesWindow()
{
delete ui;
}
void PropertiesWindow::showEvent(QShowEvent *)
{
QSettings appSettings;
if (appSettings.contains("PropertiesWindow/geometry"))
restoreGeometry(appSettings.value("PropertiesWindow/geometry").toByteArray());
}
void PropertiesWindow::hideEvent(QHideEvent *)
{
QSettings().setValue("PropertiesWindow/geometry", saveGeometry());
}
void PropertiesWindow::showData(const MolDocument &document, bool optimizerAvailable)
{
QString newLabelText;
QTextStream stream(&newLabelText);
QString stylesheet = QStringLiteral(
"<style>\n"
"table, th, td {\n"
" border: 1px solid;\n"
" border-collapse: collapse;\n"
" padding: 3px;\n"
" font-weight: normal;\n"
"}\n"
"</style>\n");
stream << stylesheet;
if (!document.calculatedProperties.isEmpty())
{
stream << "<b>Properties:</b><br>\n";
for (auto iter = document.calculatedProperties.begin(); iter != document.calculatedProperties.end(); iter++)
{
stream << iter.key() << ": " << iter.value() << "<br>\n";
}
stream << "<br>\n";
}
/* Based on comparison to the values in this paper ( https://doi.org/10.1021/jp061633o ) the orbital energies
* appear to be given in Hartrees.
*/
if (!document.orbitals.isEmpty())
{
QString formatAvailable = QStringLiteral("<tr><td><a href='orbital://%1'>%1</a></td><td>%2</td><td>%3</td></tr>");
QString formatUnavailable = QStringLiteral("<tr><td>%1</td><td>%2</td><td>%3</td></tr>");
stream << "<b>Orbitals:</b>";
stream << "<table>";
stream << "<tr><th>ID</th><th>Occupancy</th><th>Energy (au)</th></tr>";
int emptyOrbitalCount = 0;
for (auto iter = document.orbitals.begin(); iter != document.orbitals.end(); iter++)
{
//TODO: Ensure proper rounding of values? https://bugreports.qt.io/browse/QTBUG-38171 seems to indicate it may already happen automatically
if (iter->occupancy >= 0.0001)
{
if (optimizerAvailable || document.volumes.contains(iter->id))
stream << formatAvailable.arg(iter->id).arg(iter->occupancy, 0, 'f', 2).arg(iter->energy, 0, 'E', 6);
else
stream << formatUnavailable.arg(iter->id).arg(iter->occupancy, 0, 'f', 2).arg(iter->energy, 0, 'E', 6);
}
else
{
stream << formatUnavailable.arg(iter->id).arg(iter->occupancy, 0, 'f', 2).arg(iter->energy, 0, 'E', 6);
//TODO: Imporve layout so we can display all the empty orbitals without getting cluttered
emptyOrbitalCount++;
if (emptyOrbitalCount > 5)
break;
}
}
stream << "</table><br>";
}
if (!document.frequencies.isEmpty())
{
stream << "<br>\n<b>Frequencies:</b>";
const QString format = QStringLiteral("<tr><td><a href='vibration://%1'>%2</a></td><td>%3</td></tr>");
stream << "<table>";
stream << "<tr><th>Wavenumber (cm<sup>-1</sup>)</th><th>Intensity</th></tr>";
int index = 0;
for (auto iter = document.frequencies.begin(); iter != document.frequencies.end(); iter++)
stream << format.arg(index++).arg(iter->wavenum, 0, 'f', 3).arg(iter->intensity, 0, 'f', 3);
stream << "</table><br>";
}
if (newLabelText.isEmpty())
ui->label->setText("<no data>");
else
ui->label->setText(newLabelText);
}