Debian Codegraph @

avogadro/qtplugins/surfaces/surfacedialog.cpp

raw
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 #include "surfacedialog.h"
7
8 #include "ui_surfacedialog.h"
9
10 namespace Avogadro::QtPlugins {
11
12 SurfaceDialog::SurfaceDialog(QWidget* parent_, Qt::WindowFlags f)
13 : QDialog(parent_, f), m_ui(new Ui::SurfaceDialog),
14 m_automaticResolution(true)
15 {
16 m_ui->setupUi(this);
17
18 setupSteps(1);
19
20 m_ui->orbitalCombo->setVisible(false);
21 m_ui->spinCombo->setVisible(false);
22 m_ui->recordButton->setVisible(false);
23
24 // set the data for the default items
25 m_ui->surfaceCombo->addItem(tr("Van der Waals"), Surfaces::Type::VanDerWaals);
26 m_ui->surfaceCombo->addItem(tr("Solvent Accessible"),
27 Surfaces::Type::SolventAccessible);
28 m_ui->surfaceCombo->addItem(tr("Solvent Excluded"),
29 Surfaces::Type::SolventExcluded);
30
31 connect(m_ui->surfaceCombo, SIGNAL(currentIndexChanged(int)),
32 SLOT(surfaceComboChanged(int)));
33 connect(m_ui->propertyCombo, SIGNAL(currentIndexChanged(int)),
34 SLOT(propertyComboChanged(int)));
35 connect(m_ui->resolutionCombo, SIGNAL(currentIndexChanged(int)),
36 SLOT(resolutionComboChanged(int)));
37 connect(m_ui->smoothingCombo, SIGNAL(currentIndexChanged(int)),
38 SLOT(smoothingComboChanged(int)));
39 connect(m_ui->stepValue, SIGNAL(valueChanged(int)), SIGNAL(stepChanged(int)));
40 connect(m_ui->calculateButton, SIGNAL(clicked()), SLOT(calculateClicked()));
41 connect(m_ui->recordButton, SIGNAL(clicked()), SLOT(record()));
42 }
43
44 SurfaceDialog::~SurfaceDialog()
45 {
46 delete m_ui;
47 }
48
49 void SurfaceDialog::surfaceComboChanged(int n)
50 {
51 int type = m_ui->surfaceCombo->itemData(n).toInt();
52 if (type == Surfaces::Type::MolecularOrbital ||
53 type == Surfaces::Type::FromFile) {
54 m_ui->orbitalCombo->setEnabled(true);
55 m_ui->propertyCombo->setEnabled(false);
56 m_ui->propertyCombo->setCurrentIndex(0); // None
57 m_ui->colormapCombo->setEnabled(false);
58 } else {
59 m_ui->orbitalCombo->setEnabled(false);
60 m_ui->propertyCombo->setEnabled(true);
61 }
62 }
63
64 void SurfaceDialog::propertyComboChanged(int n)
65 {
66 switch (n) {
67 case 0: // None
68 m_ui->colormapCombo->setEnabled(false);
69 m_ui->modelCombo->setEnabled(false);
70 m_ui->modelCombo->clear();
71 break;
72 case 1: // Electrostatic Potential
73 m_ui->colormapCombo->setEnabled(true);
74 m_ui->modelCombo->setEnabled(true);
75 for (const auto& model : m_chargeModels)
76 m_ui->modelCombo->addItem(model.first.c_str(), model.second.c_str());
77 }
78 }
79
80 void SurfaceDialog::resolutionComboChanged(int n)
81 {
82 m_automaticResolution = false;
83 // resolutions are in Angstrom
84 switch (n) {
85 case 0: // Very low resolution
86 m_ui->resolutionDoubleSpinBox->setValue(0.5);
87 m_ui->resolutionDoubleSpinBox->setEnabled(false);
88 break;
89 case 1: // Low resolution
90 m_ui->resolutionDoubleSpinBox->setValue(0.35);
91 m_ui->resolutionDoubleSpinBox->setEnabled(false);
92 break;
93 case 2: // Medium resolution
94 m_ui->resolutionDoubleSpinBox->setValue(0.18);
95 m_ui->resolutionDoubleSpinBox->setEnabled(false);
96 break;
97 case 3: // High resolution
98 m_ui->resolutionDoubleSpinBox->setValue(0.1);
99 m_ui->resolutionDoubleSpinBox->setEnabled(false);
100 break;
101 case 4: // Very high resolution
102 m_ui->resolutionDoubleSpinBox->setValue(0.05);
103 m_ui->resolutionDoubleSpinBox->setEnabled(false);
104 break;
105 case 5: // Automatic resolution
106 m_automaticResolution = true;
107 m_ui->resolutionDoubleSpinBox->setEnabled(false);
108 break;
109 case 6: // Custom resolution
110 m_ui->resolutionDoubleSpinBox->setValue(0.18);
111 m_ui->resolutionDoubleSpinBox->setEnabled(true);
112 break;
113 default:
114 m_ui->resolutionDoubleSpinBox->setValue(0.18);
115 m_ui->resolutionDoubleSpinBox->setEnabled(false);
116 break;
117 }
118 }
119
120 void SurfaceDialog::smoothingComboChanged(int n)
121 {
122 switch (n) {
123 case 0: // No smoothing
124 m_ui->smoothingPassesSpinBox->setValue(0);
125 m_ui->smoothingPassesSpinBox->setEnabled(false);
126 break;
127 case 2: // Medium smoothing
128 m_ui->smoothingPassesSpinBox->setValue(5);
129 m_ui->smoothingPassesSpinBox->setEnabled(false);
130 break;
131 case 3: // Strong smoothing
132 m_ui->smoothingPassesSpinBox->setValue(9);
133 m_ui->smoothingPassesSpinBox->setEnabled(false);
134 break;
135 case 4: // Custom smoothing
136 m_ui->smoothingPassesSpinBox->setValue(5);
137 m_ui->smoothingPassesSpinBox->setEnabled(true);
138 break;
139 case 1: // Light smoothing
140 default:
141 m_ui->smoothingPassesSpinBox->setValue(1);
142 m_ui->smoothingPassesSpinBox->setEnabled(false);
143 break;
144 }
145 }
146
147 void SurfaceDialog::setupBasis(int numElectrons, int numMOs, bool beta)
148 {
149 // only if we have electrons
150 if (numMOs < 1)
151 return;
152
153 m_ui->orbitalCombo->setVisible(true);
154 auto n = m_ui->surfaceCombo->currentIndex();
155 int type = m_ui->surfaceCombo->itemData(n).toInt();
156 if (type == Surfaces::Type::MolecularOrbital ||
157 type == Surfaces::Type::FromFile)
158 m_ui->orbitalCombo->setEnabled(true);
159 else
160 m_ui->orbitalCombo->setEnabled(false);
161
162 if (m_ui->surfaceCombo->findData(Surfaces::Type::MolecularOrbital) == -1)
163 m_ui->surfaceCombo->addItem(tr("Molecular Orbital"),
164 Surfaces::Type::MolecularOrbital);
165 if (m_ui->surfaceCombo->findData(Surfaces::Type::ElectronDensity) == -1)
166 m_ui->surfaceCombo->addItem(tr("Electron Density"),
167 Surfaces::Type::ElectronDensity);
168
169 if (beta) {
170 m_ui->spinCombo->setVisible(true);
171 m_ui->spinCombo->setEnabled(true);
172 if (m_ui->surfaceCombo->findData(Surfaces::Type::SpinDensity) == -1)
173 m_ui->surfaceCombo->addItem(tr("Spin Density"),
174 Surfaces::Type::SpinDensity);
175 } else {
176 auto pos = m_ui->surfaceCombo->findData(Surfaces::Type::SpinDensity);
177 if (pos != -1)
178 m_ui->surfaceCombo->removeItem(pos);
179 }
180
181 // TODO: get this from the basis information
182 QString text;
183 m_ui->orbitalCombo->clear();
184 for (int i = 1; i <= numMOs; ++i) {
185 text = tr("MO %L1", "Molecular orbital").arg(i);
186 if (i == numElectrons / 2)
187 text += ' ' + tr("(HOMO)", "Highest occupied molecular orbital");
188 if (i == numElectrons / 2 + 1)
189 text += ' ' + tr("(LUMO)", "Lowest unoccupied molecular orbital");
190 m_ui->orbitalCombo->addItem(text);
191 }
192
193 m_ui->orbitalCombo->setCurrentIndex(numElectrons / 2);
194 }
195
196 void SurfaceDialog::setupCubes(QStringList cubeNames)
197 {
198 if (cubeNames.size() < 1)
199 return;
200
201 m_ui->orbitalCombo->setVisible(true);
202 m_ui->orbitalCombo->setEnabled(true);
203
204 m_ui->surfaceCombo->addItem(tr("From File"), Surfaces::Type::FromFile);
205
206 for (int i = 0; i < cubeNames.size(); ++i) {
207 m_ui->orbitalCombo->addItem(cubeNames[i]);
208 }
209 m_ui->orbitalCombo->setCurrentIndex(0);
210 }
211
212 void SurfaceDialog::setupSteps(int stepCount)
213 {
214 if (stepCount < 2) {
215 m_ui->frameLabel->hide();
216 m_ui->stepValue->setEnabled(false);
217 m_ui->stepValue->hide();
218 m_ui->recordButton->setEnabled(false);
219 m_ui->recordButton->hide();
220 m_ui->vcrBack->setEnabled(false);
221 m_ui->vcrBack->hide();
222 m_ui->vcrPlay->setEnabled(false);
223 m_ui->vcrPlay->hide();
224 m_ui->vcrForward->setEnabled(false);
225 m_ui->vcrForward->hide();
226 } else {
227 m_ui->frameLabel->show();
228 m_ui->stepValue->setEnabled(true);
229 m_ui->stepValue->setRange(1, stepCount);
230 m_ui->stepValue->setSuffix(tr(" of %0").arg(stepCount));
231 m_ui->stepValue->show();
232 m_ui->recordButton->setEnabled(true);
233 m_ui->recordButton->show();
234 /* Disable for now, this would be nice in future.
235 m_ui->vcrBack->setEnabled(true);
236 m_ui->vcrBack->setVisible(true);
237 m_ui->vcrPlay->setEnabled(true);
238 m_ui->vcrPlay->setVisible(true);
239 m_ui->vcrForward->setEnabled(true);
240 m_ui->vcrForward->setVisible(true);
241 */
242 }
243 }
244
245 void SurfaceDialog::setupModels(
246 const std::set<std::pair<std::string, std::string>>& chargeModels)
247 {
248 m_chargeModels = chargeModels;
249 }
250
251 Surfaces::Type SurfaceDialog::surfaceType()
252 {
253 return static_cast<Surfaces::Type>(m_ui->surfaceCombo->currentData().toInt());
254 }
255
256 Surfaces::ColorProperty SurfaceDialog::colorProperty()
257 {
258 return static_cast<Surfaces::ColorProperty>(
259 m_ui->propertyCombo->currentIndex());
260 }
261
262 QString SurfaceDialog::colorModel()
263 {
264 return m_ui->modelCombo->currentData().toString();
265 }
266
267 QString SurfaceDialog::colormapName()
268 {
269 return m_ui->colormapCombo->currentText();
270 }
271
272 int SurfaceDialog::surfaceIndex()
273 {
274 return m_ui->orbitalCombo->currentIndex();
275 }
276
277 bool SurfaceDialog::beta()
278 {
279 return m_ui->spinCombo->currentIndex() == 1;
280 }
281
282 float SurfaceDialog::isosurfaceValue()
283 {
284 return static_cast<float>(m_ui->isosurfaceDoubleSpinBox->value());
285 }
286
287 int SurfaceDialog::smoothingPassesValue()
288 {
289 return static_cast<int>(m_ui->smoothingPassesSpinBox->value());
290 }
291
292 float SurfaceDialog::resolution()
293 {
294 return static_cast<float>(m_ui->resolutionDoubleSpinBox->value());
295 }
296
297 bool SurfaceDialog::automaticResolution()
298 {
299 return m_automaticResolution;
300 }
301
302 int SurfaceDialog::step()
303 {
304 return m_ui->stepValue->value();
305 }
306
307 void SurfaceDialog::setStep(int step)
308 {
309 m_ui->stepValue->setValue(step);
310 }
311
312 void SurfaceDialog::calculateClicked()
313 {
314 m_ui->calculateButton->setEnabled(false);
315 emit calculateClickedSignal();
316 }
317
318 void SurfaceDialog::reenableCalculateButton()
319 {
320 m_ui->calculateButton->setEnabled(true);
321 }
322
323 void SurfaceDialog::record()
324 {
325 m_ui->calculateButton->setEnabled(false);
326 m_ui->recordButton->setEnabled(false);
327 emit recordClicked();
328 }
329
330 void SurfaceDialog::enableRecord()
331 {
332 m_ui->calculateButton->setEnabled(true);
333 m_ui->recordButton->setEnabled(true);
334 }
335
336 } // namespace Avogadro::QtPlugins