structfact.cpp 56.5 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
/**
 * structure factor tool
 * @author Tobias Weber <tweber@ill.fr>
 * @date Dec-2018
 * @license GPLv3, see 'LICENSE' file
 * @desc The present version was forked on 28-Dec-2018 from the privately developed "misc" project (https://github.com/t-weber/misc).
 */

#include "structfact.h"

Tobias WEBER's avatar
Tobias WEBER committed
11
#include <QtCore/QDir>
12
13
14
15
16
17
#include <QtWidgets/QApplication>
#include <QtWidgets/QGridLayout>
#include <QtWidgets/QHeaderView>
#include <QtWidgets/QTabWidget>
#include <QtWidgets/QLabel>
#include <QtWidgets/QToolButton>
Tobias WEBER's avatar
Tobias WEBER committed
18
19
#include <QtWidgets/QFileDialog>
#include <QtWidgets/QMessageBox>
20
21

#include <iostream>
Tobias WEBER's avatar
Tobias WEBER committed
22
#include <fstream>
Tobias WEBER's avatar
Tobias WEBER committed
23
24
#include <random>
#include <chrono>
Tobias WEBER's avatar
Tobias WEBER committed
25
#include <tuple>
26
27
28

#include <boost/version.hpp>
#include <boost/config.hpp>
Tobias WEBER's avatar
Tobias WEBER committed
29
30
#include <boost/property_tree/ptree.hpp>
#include <boost/property_tree/xml_parser.hpp>
Tobias WEBER's avatar
Tobias WEBER committed
31
#include <boost/algorithm/string.hpp>
32
33
#include <boost/algorithm/string/replace.hpp>
namespace algo = boost::algorithm;
Tobias WEBER's avatar
Tobias WEBER committed
34
namespace pt = boost::property_tree;
35

Tobias WEBER's avatar
Tobias WEBER committed
36
#include "loadcif.h"
Tobias WEBER's avatar
Tobias WEBER committed
37
#include "libs/algos.h"
Tobias WEBER's avatar
Tobias WEBER committed
38
#include "libs/helper.h"
39
40


Tobias WEBER's avatar
Tobias WEBER committed
41
42
//using namespace tl2;
using namespace tl2_ops;
43
44


Tobias WEBER's avatar
Tobias WEBER committed
45
46
47
48
constexpr t_real g_eps = 1e-6;
constexpr int g_prec = 6;


49
50
51
enum : int
{
	COL_NAME = 0,
Tobias WEBER's avatar
Tobias WEBER committed
52
53
54
	COL_SCATLEN_RE,
	COL_SCATLEN_IM,
	COL_X, COL_Y, COL_Z,
Tobias WEBER's avatar
Tobias WEBER committed
55
	COL_RAD,
Tobias WEBER's avatar
Tobias WEBER committed
56
	COL_COL,
Tobias WEBER's avatar
Tobias WEBER committed
57
58

	NUM_COLS
59
60
61
62
63
};


struct PowderLine
{
64
65
66
	t_real Q{};
	t_real I{};
	std::size_t num_peaks = 0;
67
68
69
70
71
72
73
74
	std::string peaks;
};


// ----------------------------------------------------------------------------
StructFactDlg::StructFactDlg(QWidget* pParent) : QDialog{pParent},
	m_sett{new QSettings{"tobis_stuff", "structfact"}}
{
75
	setWindowTitle("Nuclear Structure Factors");
76
77
78
	setSizeGripEnabled(true);
	setFont(QFontDatabase::systemFont(QFontDatabase::GeneralFont));

Tobias WEBER's avatar
Tobias WEBER committed
79

80
	auto tabs = new QTabWidget(this);
81

Tobias WEBER's avatar
Tobias WEBER committed
82
83
84
85
86

	{ // nuclei panel
		QWidget *nucleipanel = new QWidget(this);

		m_nuclei = new QTableWidget(nucleipanel);
87
88
89
90
91
92
93
94
95
96
		m_nuclei->setShowGrid(true);
		m_nuclei->setSortingEnabled(true);
		m_nuclei->setMouseTracking(true);
		m_nuclei->setSelectionBehavior(QTableWidget::SelectRows);
		m_nuclei->setSelectionMode(QTableWidget::ContiguousSelection);
		m_nuclei->setContextMenuPolicy(Qt::CustomContextMenu);

		m_nuclei->verticalHeader()->setDefaultSectionSize(fontMetrics().lineSpacing() + 4);
		m_nuclei->verticalHeader()->setVisible(false);

Tobias WEBER's avatar
Tobias WEBER committed
97
		m_nuclei->setColumnCount(NUM_COLS);
98
99
100
101
102
103
		m_nuclei->setHorizontalHeaderItem(COL_NAME, new QTableWidgetItem{"Name"});
		m_nuclei->setHorizontalHeaderItem(COL_SCATLEN_RE, new QTableWidgetItem{"Re{b} (fm)"});
		m_nuclei->setHorizontalHeaderItem(COL_SCATLEN_IM, new QTableWidgetItem{"Im{b} (fm)"});
		m_nuclei->setHorizontalHeaderItem(COL_X, new QTableWidgetItem{"x (frac.)"});
		m_nuclei->setHorizontalHeaderItem(COL_Y, new QTableWidgetItem{"y (frac.)"});
		m_nuclei->setHorizontalHeaderItem(COL_Z, new QTableWidgetItem{"z (frac.)"});
Tobias WEBER's avatar
Tobias WEBER committed
104
		m_nuclei->setHorizontalHeaderItem(COL_RAD, new QTableWidgetItem{"Radius"});
Tobias WEBER's avatar
Tobias WEBER committed
105
		m_nuclei->setHorizontalHeaderItem(COL_COL, new QTableWidgetItem{"Colour"});
106

107
		m_nuclei->setColumnWidth(COL_NAME, 90);
108
109
110
111
112
		m_nuclei->setColumnWidth(COL_SCATLEN_RE, 75);
		m_nuclei->setColumnWidth(COL_SCATLEN_IM, 75);
		m_nuclei->setColumnWidth(COL_X, 75);
		m_nuclei->setColumnWidth(COL_Y, 75);
		m_nuclei->setColumnWidth(COL_Z, 75);
Tobias WEBER's avatar
Tobias WEBER committed
113
		m_nuclei->setColumnWidth(COL_RAD, 75);
Tobias WEBER's avatar
Tobias WEBER committed
114
		m_nuclei->setColumnWidth(COL_COL, 75);
115

Tobias WEBER's avatar
Tobias WEBER committed
116
117
118
119
120
		QToolButton *pTabBtnAdd = new QToolButton(nucleipanel);
		QToolButton *pTabBtnDel = new QToolButton(nucleipanel);
		QToolButton *pTabBtnUp = new QToolButton(nucleipanel);
		QToolButton *pTabBtnDown = new QToolButton(nucleipanel);
		QToolButton *pTabBtnSG = new QToolButton(nucleipanel);
121
122
123
124
125
126

		m_nuclei->setSizePolicy(QSizePolicy{QSizePolicy::Expanding, QSizePolicy::Expanding});
		pTabBtnAdd->setSizePolicy(QSizePolicy{QSizePolicy::Expanding, QSizePolicy::Fixed});
		pTabBtnDel->setSizePolicy(QSizePolicy{QSizePolicy::Expanding, QSizePolicy::Fixed});
		pTabBtnUp->setSizePolicy(QSizePolicy{QSizePolicy::Expanding, QSizePolicy::Fixed});
		pTabBtnDown->setSizePolicy(QSizePolicy{QSizePolicy::Expanding, QSizePolicy::Fixed});
Tobias WEBER's avatar
Tobias WEBER committed
127
		pTabBtnSG->setSizePolicy(QSizePolicy{QSizePolicy::Expanding, QSizePolicy::Fixed});
128
129
130
131
132

		pTabBtnAdd->setText("Add Nucleus");
		pTabBtnDel->setText("Delete Nuclei");
		pTabBtnUp->setText("Move Nuclei Up");
		pTabBtnDown->setText("Move Nuclei Down");
Tobias WEBER's avatar
Tobias WEBER committed
133
		pTabBtnSG->setText("Generate");
134

Tobias WEBER's avatar
Tobias WEBER committed
135
136
137
138
139
140
		m_editA = new QLineEdit("5", nucleipanel);
		m_editB = new QLineEdit("5", nucleipanel);
		m_editC = new QLineEdit("5", nucleipanel);
		m_editAlpha = new QLineEdit("90", nucleipanel);
		m_editBeta = new QLineEdit("90", nucleipanel);
		m_editGamma = new QLineEdit("90", nucleipanel);
141

Tobias WEBER's avatar
Tobias WEBER committed
142
		m_comboSG = new QComboBox(nucleipanel);
Tobias WEBER's avatar
Tobias WEBER committed
143
144
145
146
147
148


		// get space groups and symops
		for(auto [sgnum, descr, ops] : get_sgs<t_mat>())
		{
			m_comboSG->addItem(descr.c_str(), m_comboSG->count());
149
			m_SGops.emplace_back(std::move(ops));
Tobias WEBER's avatar
Tobias WEBER committed
150
151
		}

152

Tobias WEBER's avatar
Tobias WEBER committed
153
		auto pTabGrid = new QGridLayout(nucleipanel);
154
155
		pTabGrid->setSpacing(2);
		pTabGrid->setContentsMargins(4,4,4,4);
156
		int y=0;
157
158
		//pTabGrid->addWidget(m_plot.get(), y,0,1,4);
		pTabGrid->addWidget(m_nuclei, y,0,1,4);
159
160
161
162
		pTabGrid->addWidget(pTabBtnAdd, ++y,0,1,1);
		pTabGrid->addWidget(pTabBtnDel, y,1,1,1);
		pTabGrid->addWidget(pTabBtnUp, y,2,1,1);
		pTabGrid->addWidget(pTabBtnDown, y,3,1,1);
163

Tobias WEBER's avatar
Tobias WEBER committed
164
165
166
167
168
		pTabGrid->addWidget(new QLabel("Space Groups:"), ++y,0,1,1);
		pTabGrid->addWidget(m_comboSG, y,1,1,2);
		pTabGrid->addWidget(pTabBtnSG, y,3,1,1);


Tobias WEBER's avatar
Tobias WEBER committed
169
		auto sep1 = new QFrame(nucleipanel); sep1->setFrameStyle(QFrame::HLine);
170
		pTabGrid->addWidget(sep1, ++y,0, 1,4);
171

172
173
		pTabGrid->addWidget(new QLabel("Lattice (A):"), ++y,0,1,1);
		pTabGrid->addWidget(m_editA, y,1,1,1);
174
175
176
177
178
179
		pTabGrid->addWidget(m_editB, y,2,1,1);
		pTabGrid->addWidget(m_editC, y,3,1,1);
		pTabGrid->addWidget(new QLabel("Angles (deg):"), ++y,0,1,1);
		pTabGrid->addWidget(m_editAlpha, y,1,1,1);
		pTabGrid->addWidget(m_editBeta, y,2,1,1);
		pTabGrid->addWidget(m_editGamma, y,3,1,1);
180
181


182
		// table CustomContextMenu
183
184
185
		m_pTabContextMenu = new QMenu(m_nuclei);
		m_pTabContextMenu->addAction("Add Nucleus Before", this, [this]() { this->AddTabItem(-2); });
		m_pTabContextMenu->addAction("Add Nucleus After", this, [this]() { this->AddTabItem(-3); });
186
		m_pTabContextMenu->addAction("Clone Nucleus", this, [this]() { this->AddTabItem(-4); });
187
		m_pTabContextMenu->addAction("Delete Nucleus", this, [this]() { StructFactDlg::DelTabItem(); });
188
189


190
191
192
		// table CustomContextMenu in case nothing is selected
		m_pTabContextMenuNoItem = new QMenu(m_nuclei);
		m_pTabContextMenuNoItem->addAction("Add Nucleus", this, [this]() { this->AddTabItem(); });
193
		m_pTabContextMenuNoItem->addAction("Delete Nucleus", this, [this]() { StructFactDlg::DelTabItem(); });
194
195
196
		//m_pTabContextMenuNoItem->addSeparator();


197
		// signals
Tobias WEBER's avatar
Tobias WEBER committed
198
		for(auto* edit : std::vector<QLineEdit*>{{ m_editA, m_editB, m_editC, m_editAlpha, m_editBeta, m_editGamma }})
Tobias WEBER's avatar
Tobias WEBER committed
199
			connect(edit, &QLineEdit::textEdited, this, [this]() { this->CalcB(); });
Tobias WEBER's avatar
Tobias WEBER committed
200
201

		connect(pTabBtnAdd, &QToolButton::clicked, this, [this]() { this->AddTabItem(-1); });
202
		connect(pTabBtnDel, &QToolButton::clicked, this, [this]() { StructFactDlg::DelTabItem(); });
203
204
		connect(pTabBtnUp, &QToolButton::clicked, this, &StructFactDlg::MoveTabItemUp);
		connect(pTabBtnDown, &QToolButton::clicked, this, &StructFactDlg::MoveTabItemDown);
Tobias WEBER's avatar
Tobias WEBER committed
205
		connect(pTabBtnSG, &QToolButton::clicked, this, &StructFactDlg::GenerateFromSG);
206

207
208
209
210
		connect(m_nuclei, &QTableWidget::currentCellChanged, this, &StructFactDlg::TableCurCellChanged);
		connect(m_nuclei, &QTableWidget::entered, this, &StructFactDlg::TableCellEntered);
		connect(m_nuclei, &QTableWidget::itemChanged, this, &StructFactDlg::TableItemChanged);
		connect(m_nuclei, &QTableWidget::customContextMenuRequested, this, &StructFactDlg::ShowTableContextMenu);
Tobias WEBER's avatar
Tobias WEBER committed
211

Tobias WEBER's avatar
Tobias WEBER committed
212
		tabs->addTab(nucleipanel, "Nuclei");
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
	}


	{	// structure factors panel
		auto sfactpanel = new QWidget(this);
		auto pGrid = new QGridLayout(sfactpanel);
		pGrid->setSpacing(4);
		pGrid->setContentsMargins(4,4,4,4);

		m_structfacts = new QPlainTextEdit(sfactpanel);
		m_structfacts->setReadOnly(true);
		m_structfacts->setFont(QFontDatabase::systemFont(QFontDatabase::FixedFont));

		m_maxBZ = new QSpinBox(sfactpanel);
		m_maxBZ->setMinimum(0);
		m_maxBZ->setMaximum(99);
		m_maxBZ->setValue(4);

231
232
233
234
		m_RemoveZeroes = new QCheckBox("Remove Zeroes", sfactpanel);
		m_RemoveZeroes->setChecked(true);


235
		pGrid->addWidget(m_structfacts, 0,0, 1,4);
236
		pGrid->addWidget(new QLabel("Max. Order:"), 1,0,1,1);
237
		pGrid->addWidget(m_maxBZ, 1,1, 1,1);
238
239
		pGrid->addWidget(m_RemoveZeroes, 1,2, 1,2);

240
241
242

		// signals
		connect(m_maxBZ, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged), this, [this]() { this->Calc(); });
243
		connect(m_RemoveZeroes, static_cast<void (QCheckBox::*)(int)>(&QCheckBox::stateChanged), this, [this]() { this->Calc(); });
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265

		tabs->addTab(sfactpanel, "Structure Factors");
	}


	{	// powder lines panel
		auto powderpanel = new QWidget(this);
		auto pGrid = new QGridLayout(powderpanel);
		pGrid->setSpacing(4);
		pGrid->setContentsMargins(4,4,4,4);

		m_powderlines = new QPlainTextEdit(powderpanel);
		m_powderlines->setReadOnly(true);
		m_powderlines->setFont(QFontDatabase::systemFont(QFontDatabase::FixedFont));
		m_powderlines->setLineWrapMode(QPlainTextEdit::NoWrap);

		pGrid->addWidget(m_powderlines, 0,0, 1,4);

		tabs->addTab(powderpanel, "Powder Lines");
	}


Tobias WEBER's avatar
Tobias WEBER committed
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
	{ // find space group panel
		auto findsgpanel = new QWidget(this);

		m_nuclei_FindSG = new QTableWidget(findsgpanel);
		m_nuclei_FindSG->setShowGrid(true);
		m_nuclei_FindSG->setSortingEnabled(true);
		m_nuclei_FindSG->setMouseTracking(true);
		m_nuclei_FindSG->setSelectionBehavior(QTableWidget::SelectRows);
		m_nuclei_FindSG->setSelectionMode(QTableWidget::ContiguousSelection);
		m_nuclei_FindSG->setContextMenuPolicy(Qt::CustomContextMenu);

		m_nuclei_FindSG->verticalHeader()->setDefaultSectionSize(fontMetrics().lineSpacing() + 4);
		m_nuclei_FindSG->verticalHeader()->setVisible(false);

		m_nuclei_FindSG->setColumnCount(3);
		m_nuclei_FindSG->setHorizontalHeaderItem(0, new QTableWidgetItem{"x (frac.)"});
		m_nuclei_FindSG->setHorizontalHeaderItem(1, new QTableWidgetItem{"y (frac.)"});
		m_nuclei_FindSG->setHorizontalHeaderItem(2, new QTableWidgetItem{"z (frac.)"});

		m_nuclei_FindSG->setColumnWidth(0, 200);
		m_nuclei_FindSG->setColumnWidth(1, 200);
		m_nuclei_FindSG->setColumnWidth(2, 200);

		m_sgmatches = new QPlainTextEdit(findsgpanel);
		m_sgmatches->setReadOnly(true);
		m_sgmatches->setFont(QFontDatabase::systemFont(QFontDatabase::FixedFont));


		QToolButton *pTabBtnAdd = new QToolButton(findsgpanel);
		QToolButton *pTabBtnDel = new QToolButton(findsgpanel);
		QToolButton *pTabBtnUp = new QToolButton(findsgpanel);
		QToolButton *pTabBtnDown = new QToolButton(findsgpanel);
298
		QToolButton *pBtnCalc = new QToolButton(findsgpanel);
Tobias WEBER's avatar
Tobias WEBER committed
299
300
301
302
303
304

		m_nuclei_FindSG->setSizePolicy(QSizePolicy{QSizePolicy::Expanding, QSizePolicy::Expanding});
		pTabBtnAdd->setSizePolicy(QSizePolicy{QSizePolicy::Expanding, QSizePolicy::Fixed});
		pTabBtnDel->setSizePolicy(QSizePolicy{QSizePolicy::Expanding, QSizePolicy::Fixed});
		pTabBtnUp->setSizePolicy(QSizePolicy{QSizePolicy::Expanding, QSizePolicy::Fixed});
		pTabBtnDown->setSizePolicy(QSizePolicy{QSizePolicy::Expanding, QSizePolicy::Fixed});
305
		pBtnCalc->setSizePolicy(QSizePolicy{QSizePolicy::Expanding, QSizePolicy::Fixed});
Tobias WEBER's avatar
Tobias WEBER committed
306
307
308
309
310

		pTabBtnAdd->setText("Add Nucleus");
		pTabBtnDel->setText("Delete Nuclei");
		pTabBtnUp->setText("Move Nuclei Up");
		pTabBtnDown->setText("Move Nuclei Down");
311
		pBtnCalc->setText("Find Matching Space Groups");
Tobias WEBER's avatar
Tobias WEBER committed
312
313
314
315
316
317
318
319
320
321
322
323


		auto pTabGrid = new QGridLayout(findsgpanel);
		pTabGrid->setSpacing(2);
		pTabGrid->setContentsMargins(4,4,4,4);
		int y=0;
		pTabGrid->addWidget(m_nuclei_FindSG, y,0,1,4);
		pTabGrid->addWidget(m_sgmatches, ++y,0,1,4);
		pTabGrid->addWidget(pTabBtnAdd, ++y,0,1,1);
		pTabGrid->addWidget(pTabBtnDel, y,1,1,1);
		pTabGrid->addWidget(pTabBtnUp, y,2,1,1);
		pTabGrid->addWidget(pTabBtnDown, y,3,1,1);
324
		pTabGrid->addWidget(pBtnCalc, ++y,2,1,2);
Tobias WEBER's avatar
Tobias WEBER committed
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345


		// table CustomContextMenu
		m_pTabContextMenu_FindSG = new QMenu(m_nuclei_FindSG);
		m_pTabContextMenu_FindSG->addAction("Add Nucleus Before", this, [this]() { this->AddTabItem_FindSG(-2); });
		m_pTabContextMenu_FindSG->addAction("Add Nucleus After", this, [this]() { this->AddTabItem_FindSG(-3); });
		m_pTabContextMenu_FindSG->addAction("Clone Nucleus", this, [this]() { this->AddTabItem_FindSG(-4); });
		m_pTabContextMenu_FindSG->addAction("Delete Nucleus", this, [this]() { StructFactDlg::DelTabItem_FindSG(); });


		// table CustomContextMenu in case nothing is selected
		m_pTabContextMenuNoItem_FindSG = new QMenu(m_nuclei_FindSG);
		m_pTabContextMenuNoItem_FindSG->addAction("Add Nucleus", this, [this]() { this->AddTabItem_FindSG(); });
		m_pTabContextMenuNoItem_FindSG->addAction("Delete Nucleus", this, [this]() { StructFactDlg::DelTabItem_FindSG(); });


		// signals
		connect(pTabBtnAdd, &QToolButton::clicked, this, [this]() { this->AddTabItem_FindSG(-1); });
		connect(pTabBtnDel, &QToolButton::clicked, this, [this]() { StructFactDlg::DelTabItem_FindSG(); });
		connect(pTabBtnUp, &QToolButton::clicked, this, &StructFactDlg::MoveTabItemUp_FindSG);
		connect(pTabBtnDown, &QToolButton::clicked, this, &StructFactDlg::MoveTabItemDown_FindSG);
346
		connect(pBtnCalc, &QToolButton::clicked, this, &StructFactDlg::FindSG);
Tobias WEBER's avatar
Tobias WEBER committed
347
348
349
350
351
352
353
354

		connect(m_nuclei_FindSG, &QTableWidget::itemChanged, this, &StructFactDlg::TableItemChanged_FindSG);
		connect(m_nuclei_FindSG, &QTableWidget::customContextMenuRequested, this, &StructFactDlg::ShowTableContextMenu_FindSG);

		tabs->addTab(findsgpanel, "Match Space Group");
	}


355
356
357
358
359
360
	{	// info panel
		auto infopanel = new QWidget(this);
		auto pGrid = new QGridLayout(infopanel);
		pGrid->setSpacing(4);
		pGrid->setContentsMargins(4,4,4,4);

361
362
363
364
365
366
367
		// table grid
		for(int i=0; i<4; ++i)
		{
			m_labelGlInfos[i] = new QLabel("", infopanel);
			m_labelGlInfos[i]->setSizePolicy(QSizePolicy::Ignored, m_labelGlInfos[i]->sizePolicy().verticalPolicy());
		}

368
369
370
371
372
373
374
		auto sep1 = new QFrame(infopanel); sep1->setFrameStyle(QFrame::HLine);
		auto sep2 = new QFrame(infopanel); sep2->setFrameStyle(QFrame::HLine);
		auto sep3 = new QFrame(infopanel); sep3->setFrameStyle(QFrame::HLine);

		std::string strBoost = BOOST_LIB_VERSION;
		algo::replace_all(strBoost, "_", ".");

375
		auto labelTitle = new QLabel("Nuclear Structure Factor Calculator", infopanel);
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
		auto fontTitle = labelTitle->font();
		fontTitle.setBold(true);
		labelTitle->setFont(fontTitle);
		labelTitle->setAlignment(Qt::AlignHCenter);

		auto labelAuthor = new QLabel("Written by Tobias Weber <tweber@ill.fr>.", infopanel);
		labelAuthor->setAlignment(Qt::AlignHCenter);

		auto labelDate = new QLabel("December 2018.", infopanel);
		labelDate->setAlignment(Qt::AlignHCenter);

		int y = 0;
		pGrid->addWidget(labelTitle, y++,0, 1,1);
		pGrid->addWidget(labelAuthor, y++,0, 1,1);
		pGrid->addWidget(labelDate, y++,0, 1,1);
		pGrid->addItem(new QSpacerItem(16,16, QSizePolicy::Minimum, QSizePolicy::Fixed), y++,0, 1,1);
		pGrid->addWidget(sep1, y++,0, 1,1);
		pGrid->addWidget(new QLabel(QString("Compiler: ") + QString(BOOST_COMPILER) + ".", infopanel), y++,0, 1,1);
		pGrid->addWidget(new QLabel(QString("C++ Library: ") + QString(BOOST_STDLIB) + ".", infopanel), y++,0, 1,1);
		pGrid->addWidget(new QLabel(QString("Build Date: ") + QString(__DATE__) + ", " + QString(__TIME__) + ".", infopanel), y++,0, 1,1);
		pGrid->addWidget(sep2, y++,0, 1,1);
		pGrid->addWidget(new QLabel(QString("Qt Version: ") + QString(QT_VERSION_STR) + ".", infopanel), y++,0, 1,1);
		pGrid->addWidget(new QLabel(QString("Boost Version: ") + strBoost.c_str() + ".", infopanel), y++,0, 1,1);
		pGrid->addWidget(sep3, y++,0, 1,1);
400
401
		for(int i=0; i<4; ++i)
			pGrid->addWidget(m_labelGlInfos[i], y++,0, 1,1);
402
403
404
405
406
407
408
409
410
411
412
413
414
		pGrid->addItem(new QSpacerItem(16,16, QSizePolicy::Minimum, QSizePolicy::Expanding), y++,0, 1,1);

		tabs->addTab(infopanel, "Infos");
	}


	// main grid
	auto pmainGrid = new QGridLayout(this);
	pmainGrid->setSpacing(4);
	pmainGrid->setContentsMargins(4,4,4,4);
	pmainGrid->addWidget(tabs, 0,0, 1,1);


Tobias WEBER's avatar
Tobias WEBER committed
415
416
417
418
419
420
421
422
	// menu bar
	{
		m_menu = new QMenuBar(this);
		m_menu->setNativeMenuBar(m_sett ? m_sett->value("native_gui", false).toBool() : false);

		auto menuFile = new QMenu("File", m_menu);
		auto menuView = new QMenu("View", m_menu);

Tobias WEBER's avatar
Tobias WEBER committed
423
		auto acNew = new QAction("New", menuFile);
Tobias WEBER's avatar
Tobias WEBER committed
424
425
426
427
428
429
430
		auto acLoad = new QAction("Load...", menuFile);
		auto acSave = new QAction("Save...", menuFile);
		auto acImportCIF = new QAction("Import CIF...", menuFile);
		auto acExportTAZ = new QAction("Export TAZ...", menuFile);
		auto acExit = new QAction("Exit", menuFile);
		auto ac3DView = new QAction("3D View...", menuFile);

Tobias WEBER's avatar
Tobias WEBER committed
431
432
		menuFile->addAction(acNew);
		menuFile->addSeparator();
Tobias WEBER's avatar
Tobias WEBER committed
433
434
435
436
437
438
439
440
441
		menuFile->addAction(acLoad);
		menuFile->addAction(acSave);
		menuFile->addSeparator();
		menuFile->addAction(acImportCIF);
		menuFile->addAction(acExportTAZ);
		menuFile->addSeparator();
		menuFile->addAction(acExit);
		menuView->addAction(ac3DView);

Tobias WEBER's avatar
Tobias WEBER committed
442
443
444
445
446
447
448
449
450
451
452
453
454
455
		connect(acNew, &QAction::triggered, this,  [this]()
		{
			// clear old table
			DelTabItem(-1);

			// set some defaults
			m_comboSG->setCurrentIndex(0);
			m_editA->setText("5");
			m_editB->setText("5");
			m_editC->setText("5");
			m_editAlpha->setText("90");
			m_editBeta->setText("90");
			m_editGamma->setText("90");
		});
Tobias WEBER's avatar
Tobias WEBER committed
456
457
458
459
460
461
462
463
464
465
466
467
468
469
		connect(acLoad, &QAction::triggered, this, &StructFactDlg::Load);
		connect(acSave, &QAction::triggered, this, &StructFactDlg::Save);
		connect(acImportCIF, &QAction::triggered, this, &StructFactDlg::ImportCIF);
		connect(acExportTAZ, &QAction::triggered, this, &StructFactDlg::ExportTAZ);
		connect(acExit, &QAction::triggered, this, &QDialog::close);
		connect(ac3DView, &QAction::triggered, this, [this]()
		{
			// plot widget
			if(!m_dlgPlot)
			{
				m_dlgPlot = new QDialog(this);
				m_dlgPlot->setWindowTitle("Unit Cell - 3D View");

				m_plot = std::make_shared<GlPlot>(this);
Tobias WEBER's avatar
Tobias WEBER committed
470
471
				m_plot->GetImpl()->SetLight(0, tl2::create<t_vec3_gl>({ 5, 5, 5 }));
				m_plot->GetImpl()->SetLight(1, tl2::create<t_vec3_gl>({ -5, -5, -5 }));
Tobias WEBER's avatar
Tobias WEBER committed
472
				m_plot->GetImpl()->SetCoordMax(1.);
Tobias WEBER's avatar
Tobias WEBER committed
473
474
				m_plot->GetImpl()->SetCamBase(tl2::create<t_mat_gl>({1,0,0,0,  0,0,1,0,  0,-1,0,-1.5,  0,0,0,1}),
					tl2::create<t_vec_gl>({1,0,0,0}), tl2::create<t_vec_gl>({0,0,1,0}));
Tobias WEBER's avatar
Tobias WEBER committed
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524


				auto labCoordSys = new QLabel("Coordinate System:", /*m_dlgPlot*/ this);
				auto comboCoordSys = new QComboBox(/*m_dlgPlot*/ this);
				m_status3D = new QLabel(/*m_dlgPlot*/ this);

				comboCoordSys->addItem("Fractional Units (rlu)");
				comboCoordSys->addItem("Lab Units (A)");


				m_plot->setSizePolicy(QSizePolicy{QSizePolicy::Expanding, QSizePolicy::Expanding});
				labCoordSys->setSizePolicy(QSizePolicy{QSizePolicy::Fixed, QSizePolicy::Fixed});

				auto grid = new QGridLayout(m_dlgPlot);
				grid->setSpacing(2);
				grid->setContentsMargins(4,4,4,4);
				grid->addWidget(m_plot.get(), 0,0,1,2);
				grid->addWidget(labCoordSys, 1,0,1,1);
				grid->addWidget(comboCoordSys, 1,1,1,1);
				grid->addWidget(m_status3D, 2,0,1,2);


				connect(m_plot.get(), &GlPlot::AfterGLInitialisation, this, &StructFactDlg::AfterGLInitialisation);
				connect(m_plot->GetImpl(), &GlPlot_impl::PickerIntersection, this, &StructFactDlg::PickerIntersection);
				connect(m_plot.get(), &GlPlot::MouseDown, this, &StructFactDlg::PlotMouseDown);
				connect(m_plot.get(), &GlPlot::MouseUp, this, &StructFactDlg::PlotMouseUp);
				connect(comboCoordSys, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), this, [this](int val)
				{
					if(this->m_plot)
						this->m_plot->GetImpl()->SetCoordSys(val);
				});


				if(m_sett && m_sett->contains("geo_3dview"))
					m_dlgPlot->restoreGeometry(m_sett->value("geo_3dview").toByteArray());
				else
					m_dlgPlot->resize(500,500);
			}

			m_dlgPlot->show();
			m_dlgPlot->raise();
			m_dlgPlot->focusWidget();
		});

		m_menu->addMenu(menuFile);
		m_menu->addMenu(menuView);
		pmainGrid->setMenuBar(m_menu);
	}


Tobias WEBER's avatar
Tobias WEBER committed
525
	// restore window size and position
526
527
528
529
530
531
532
533
534
535
	if(m_sett && m_sett->contains("geo"))
		restoreGeometry(m_sett->value("geo").toByteArray());
	else
		resize(600, 500);


	m_ignoreChanges = 0;
}


Tobias WEBER's avatar
Tobias WEBER committed
536

Tobias WEBER's avatar
Tobias WEBER committed
537
538
539
// ============================================================================
// functions for nuclei tab

Tobias WEBER's avatar
Tobias WEBER committed
540
// ----------------------------------------------------------------------------
Tobias WEBER's avatar
Tobias WEBER committed
541

Tobias WEBER's avatar
Tobias WEBER committed
542
void StructFactDlg::AddTabItem(int row, 
Tobias WEBER's avatar
Tobias WEBER committed
543
	const std::string& name, t_real bRe, t_real bIm, t_real x, t_real y, t_real z, t_real scale, const std::string& col)
544
{
545
	bool bclone = 0;
546
547
548
549
550
551
552
553
	m_ignoreChanges = 1;

	if(row == -1)	// append to end of table
		row = m_nuclei->rowCount();
	else if(row == -2 && m_iCursorRow >= 0)	// use row from member variable
		row = m_iCursorRow;
	else if(row == -3 && m_iCursorRow >= 0)	// use row from member variable +1
		row = m_iCursorRow + 1;
554
555
556
557
558
	else if(row == -4 && m_iCursorRow >= 0)	// use row from member variable +1
	{
		row = m_iCursorRow + 1;
		bclone = 1;
	}
559
560
561
562
563

	//bool sorting = m_nuclei->isSortingEnabled();
	m_nuclei->setSortingEnabled(false);
	m_nuclei->insertRow(row);

564
565
	if(bclone)
	{
Tobias WEBER's avatar
Tobias WEBER committed
566
		for(int thecol=0; thecol<NUM_COLS; ++thecol)
567
568
569
570
			m_nuclei->setItem(row, thecol, m_nuclei->item(m_iCursorRow, thecol)->clone());
	}
	else
	{
Tobias WEBER's avatar
Tobias WEBER committed
571
572
573
574
575
576
		m_nuclei->setItem(row, COL_NAME, new QTableWidgetItem(name.c_str()));
		m_nuclei->setItem(row, COL_SCATLEN_RE, new NumericTableWidgetItem<t_real>(bRe));
		m_nuclei->setItem(row, COL_SCATLEN_IM, new NumericTableWidgetItem<t_real>(bIm));
		m_nuclei->setItem(row, COL_X, new NumericTableWidgetItem<t_real>(x));
		m_nuclei->setItem(row, COL_Y, new NumericTableWidgetItem<t_real>(y));
		m_nuclei->setItem(row, COL_Z, new NumericTableWidgetItem<t_real>(z));
Tobias WEBER's avatar
Tobias WEBER committed
577
		m_nuclei->setItem(row, COL_RAD, new NumericTableWidgetItem<t_real>(scale));
Tobias WEBER's avatar
Tobias WEBER committed
578
		m_nuclei->setItem(row, COL_COL, new QTableWidgetItem(col.c_str()));
579
580
	}

581
	Add3DItem(row);
582
583
584
585
586
587
588
589
590
591
592

	m_nuclei->scrollToItem(m_nuclei->item(row, 0));
	m_nuclei->setCurrentCell(row, 0);

	m_nuclei->setSortingEnabled(/*sorting*/ true);

	m_ignoreChanges = 0;
	Calc();
}


593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
/**
 * add 3d object
 */
void StructFactDlg::Add3DItem(int row)
{
	if(!m_plot) return;

	// add all items
	if(row < 0)
	{
		for(int row=0; row<m_nuclei->rowCount(); ++row)
			Add3DItem(row);
		return;
	}

Tobias WEBER's avatar
Tobias WEBER committed
608
	auto *itemName = m_nuclei->item(row, COL_NAME);
609
610
611
	auto *itemx = m_nuclei->item(row, COL_X);
	auto *itemy = m_nuclei->item(row, COL_Y);
	auto *itemz = m_nuclei->item(row, COL_Z);
Tobias WEBER's avatar
Tobias WEBER committed
612
	auto *itemsc = m_nuclei->item(row, COL_RAD);
Tobias WEBER's avatar
Tobias WEBER committed
613
614
	auto *itemCol = m_nuclei->item(row, COL_COL);

Tobias WEBER's avatar
Tobias WEBER committed
615
	t_real_gl posx=0, posy=0, posz=0, scale=1;
616
617
618
	std::istringstream{itemx->text().toStdString()} >> posx;
	std::istringstream{itemy->text().toStdString()} >> posy;
	std::istringstream{itemz->text().toStdString()} >> posz;
Tobias WEBER's avatar
Tobias WEBER committed
619
	std::istringstream{itemsc->text().toStdString()} >> scale;
620

Tobias WEBER's avatar
Tobias WEBER committed
621
622
623
624
625
	qreal r=1, g=1, b=1;
	QColor col{itemCol->text()};
	col.getRgbF(&r, &g, &b);

	auto obj = m_plot->GetImpl()->AddLinkedObject(m_sphere, 0,0,0, r,g,b,1);
Tobias WEBER's avatar
Tobias WEBER committed
626
	//auto obj = m_plot->GetImpl()->AddSphere(0.05, 0,0,0, r,g,b,1);
Tobias WEBER's avatar
Tobias WEBER committed
627
	m_plot->GetImpl()->SetObjectMatrix(obj, tl2::hom_translation<t_mat_gl>(posx, posy, posz)*tl2::hom_scaling<t_mat_gl>(scale,scale,scale));
Tobias WEBER's avatar
Tobias WEBER committed
628
	m_plot->GetImpl()->SetObjectLabel(obj, itemName->text().toStdString());
629
630
631
632
633
634
	m_plot->update();

	m_nuclei->item(row, COL_NAME)->setData(Qt::UserRole, unsigned(obj));
}


635
void StructFactDlg::DelTabItem(int begin, int end)
636
637
638
639
{
	m_ignoreChanges = 1;

	// if nothing is selected, clear all items
640
	if(begin == -1 || m_nuclei->selectedItems().count() == 0)
641
	{
642
643
644
645
646
647
648
		if(m_plot)
		{
			for(int row=0; row<m_nuclei->rowCount(); ++row)
				if(std::size_t obj = m_nuclei->item(row, COL_NAME)->data(Qt::UserRole).toUInt(); obj)
					m_plot->GetImpl()->RemoveObject(obj);
			m_plot->update();
		}
Tobias WEBER's avatar
Tobias WEBER committed
649

650
651
652
		m_nuclei->clearContents();
		m_nuclei->setRowCount(0);
	}
653
	else if(begin == -2)	// clear selected
Tobias WEBER's avatar
Tobias WEBER committed
654
	{
Tobias WEBER's avatar
Tobias WEBER committed
655
656
657
		for(int row : GetSelectedRows(true))
		{
			// remove 3d object
658
659
660
661
662
663
			if(m_plot)
			{
				if(std::size_t obj = m_nuclei->item(row, COL_NAME)->data(Qt::UserRole).toUInt(); obj)
					m_plot->GetImpl()->RemoveObject(obj);
				m_plot->update();
			}
Tobias WEBER's avatar
Tobias WEBER committed
664

Tobias WEBER's avatar
Tobias WEBER committed
665
666
			m_nuclei->removeRow(row);
		}
Tobias WEBER's avatar
Tobias WEBER committed
667
	}
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
	else if(begin >= 0 && end >= 0)		// clear given range
	{
		for(int row=end-1; row>=begin; --row)
		{
			// remove 3d object
			if(m_plot)
			{
				if(std::size_t obj = m_nuclei->item(row, COL_NAME)->data(Qt::UserRole).toUInt(); obj)
					m_plot->GetImpl()->RemoveObject(obj);
				m_plot->update();
			}

			m_nuclei->removeRow(row);
		}
	}
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756

	m_ignoreChanges = 0;
	Calc();
}


void StructFactDlg::MoveTabItemUp()
{
	m_ignoreChanges = 1;
	m_nuclei->setSortingEnabled(false);

	auto selected = GetSelectedRows(false);
	for(int row : selected)
	{
		if(row == 0)
			continue;

		auto *item = m_nuclei->item(row, 0);
		if(!item || !item->isSelected())
			continue;

		m_nuclei->insertRow(row-1);
		for(int col=0; col<m_nuclei->columnCount(); ++col)
			m_nuclei->setItem(row-1, col, m_nuclei->item(row+1, col)->clone());
		m_nuclei->removeRow(row+1);
	}

	for(int row=0; row<m_nuclei->rowCount(); ++row)
	{
		if(auto *item = m_nuclei->item(row, 0);
			item && std::find(selected.begin(), selected.end(), row+1) != selected.end())
		{
			for(int col=0; col<m_nuclei->columnCount(); ++col)
				m_nuclei->item(row, col)->setSelected(true);
		}
	}

	m_ignoreChanges = 0;
}


void StructFactDlg::MoveTabItemDown()
{
	m_ignoreChanges = 1;
	m_nuclei->setSortingEnabled(false);

	auto selected = GetSelectedRows(true);
	for(int row : selected)
	{
		if(row == m_nuclei->rowCount()-1)
			continue;

		auto *item = m_nuclei->item(row, 0);
		if(!item || !item->isSelected())
			continue;

		m_nuclei->insertRow(row+2);
		for(int col=0; col<m_nuclei->columnCount(); ++col)
			m_nuclei->setItem(row+2, col, m_nuclei->item(row, col)->clone());
		m_nuclei->removeRow(row);
	}

	for(int row=0; row<m_nuclei->rowCount(); ++row)
	{
		if(auto *item = m_nuclei->item(row, 0);
			item && std::find(selected.begin(), selected.end(), row-1) != selected.end())
		{
			for(int col=0; col<m_nuclei->columnCount(); ++col)
				m_nuclei->item(row, col)->setSelected(true);
		}
	}

	m_ignoreChanges = 0;
}
Tobias WEBER's avatar
Tobias WEBER committed
757
758
// ----------------------------------------------------------------------------

759
760


761

Tobias WEBER's avatar
Tobias WEBER committed
762
// ----------------------------------------------------------------------------
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
std::vector<int> StructFactDlg::GetSelectedRows(bool sort_reversed) const
{
	std::vector<int> vec;
	vec.reserve(m_nuclei->selectedItems().size());

	for(int row=0; row<m_nuclei->rowCount(); ++row)
	{
		if(auto *item = m_nuclei->item(row, 0); item && item->isSelected())
			vec.push_back(row);
	}

	if(sort_reversed)
	{
		std::stable_sort(vec.begin(), vec.end(), [](int row1, int row2)
		{ return row1 > row2; });
	}

	return vec;
}


/**
 * selected a new row
 */
void StructFactDlg::TableCurCellChanged(int rowNew, int colNew, int rowOld, int colOld)
{
}


/**
 * hovered over new row
 */
void StructFactDlg::TableCellEntered(const QModelIndex& idx)
{
}


/**
 * item contents changed
 */
void StructFactDlg::TableItemChanged(QTableWidgetItem *item)
{
Tobias WEBER's avatar
Tobias WEBER committed
805
	// update associated 3d object
806
	if(item && m_plot)
Tobias WEBER's avatar
Tobias WEBER committed
807
808
809
810
	{
		int row = item->row();
		if(std::size_t obj = m_nuclei->item(row, COL_NAME)->data(Qt::UserRole).toUInt(); obj)
		{
Tobias WEBER's avatar
Tobias WEBER committed
811
			auto *itemName = m_nuclei->item(row, COL_NAME);
Tobias WEBER's avatar
Tobias WEBER committed
812
813
814
			auto *itemx = m_nuclei->item(row, COL_X);
			auto *itemy = m_nuclei->item(row, COL_Y);
			auto *itemz = m_nuclei->item(row, COL_Z);
Tobias WEBER's avatar
Tobias WEBER committed
815
			auto *itemsc = m_nuclei->item(row, COL_RAD);
Tobias WEBER's avatar
Tobias WEBER committed
816
817
			auto *itemCol = m_nuclei->item(row, COL_COL);

Tobias WEBER's avatar
Tobias WEBER committed
818
			t_real_gl posx=0, posy=0, posz=0, scale=1;
Tobias WEBER's avatar
Tobias WEBER committed
819
820
821
			std::istringstream{itemx->text().toStdString()} >> posx;
			std::istringstream{itemy->text().toStdString()} >> posy;
			std::istringstream{itemz->text().toStdString()} >> posz;
Tobias WEBER's avatar
Tobias WEBER committed
822
			std::istringstream{itemsc->text().toStdString()} >> scale;
Tobias WEBER's avatar
Tobias WEBER committed
823

Tobias WEBER's avatar
Tobias WEBER committed
824
825
826
827
			qreal r=1, g=1, b=1;
			QColor col{itemCol->text()};
			col.getRgbF(&r, &g, &b);

Tobias WEBER's avatar
Tobias WEBER committed
828
			m_plot->GetImpl()->SetObjectMatrix(obj, tl2::hom_translation<t_mat_gl>(posx, posy, posz)*tl2::hom_scaling<t_mat_gl>(scale,scale,scale));
Tobias WEBER's avatar
Tobias WEBER committed
829
830
			m_plot->GetImpl()->SetObjectCol(obj, r, g, b, 1);
			m_plot->GetImpl()->SetObjectLabel(obj, itemName->text().toStdString());
Tobias WEBER's avatar
Tobias WEBER committed
831
832
833
834
			m_plot->update();
		}
	}

835
836
837
838
839
840
841
842
	if(!m_ignoreChanges)
		Calc();
}


void StructFactDlg::ShowTableContextMenu(const QPoint& pt)
{
	auto ptGlob = m_nuclei->mapToGlobal(pt);
843
844
845
846
847
848
849
850
851
852
853
854

	if(const auto* item = m_nuclei->itemAt(pt); item)
	{
		m_iCursorRow = item->row();
		ptGlob.setY(ptGlob.y() + m_pTabContextMenu->sizeHint().height()/2);
		m_pTabContextMenu->popup(ptGlob);
	}
	else
	{
		ptGlob.setY(ptGlob.y() + m_pTabContextMenuNoItem->sizeHint().height()/2);
		m_pTabContextMenuNoItem->popup(ptGlob);
	}
855
}
Tobias WEBER's avatar
Tobias WEBER committed
856
// ----------------------------------------------------------------------------
Tobias WEBER's avatar
Tobias WEBER committed
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
// ============================================================================




// ============================================================================
// functions for space group finder tab

// ----------------------------------------------------------------------------

void StructFactDlg::AddTabItem_FindSG(int row, t_real x, t_real y, t_real z)
{
	bool bclone = 0;

	if(row == -1)	// append to end of table
		row = m_nuclei_FindSG->rowCount();
	else if(row == -2 && m_iCursorRow_FindSG >= 0)	// use row from member variable
		row = m_iCursorRow_FindSG;
	else if(row == -3 && m_iCursorRow_FindSG >= 0)	// use row from member variable +1
		row = m_iCursorRow_FindSG + 1;
	else if(row == -4 && m_iCursorRow_FindSG >= 0)	// use row from member variable +1
	{
		row = m_iCursorRow_FindSG + 1;
		bclone = 1;
	}

	m_nuclei_FindSG->setSortingEnabled(false);
	m_nuclei_FindSG->insertRow(row);

	if(bclone)
	{
		for(int thecol=0; thecol<3; ++thecol)
			m_nuclei_FindSG->setItem(row, thecol, m_nuclei_FindSG->item(m_iCursorRow_FindSG, thecol)->clone());
	}
	else
	{
		m_nuclei_FindSG->setItem(row, 0, new NumericTableWidgetItem<t_real>(x));
		m_nuclei_FindSG->setItem(row, 1, new NumericTableWidgetItem<t_real>(y));
		m_nuclei_FindSG->setItem(row, 2, new NumericTableWidgetItem<t_real>(z));
	}

	m_nuclei_FindSG->scrollToItem(m_nuclei_FindSG->item(row, 0));
	m_nuclei_FindSG->setCurrentCell(row, 0);
	m_nuclei_FindSG->setSortingEnabled(true);

902
	//FindSG();
Tobias WEBER's avatar
Tobias WEBER committed
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
}



void StructFactDlg::DelTabItem_FindSG(int begin, int end)
{
	// if nothing is selected, clear all items
	if(begin == -1 || m_nuclei_FindSG->selectedItems().count() == 0)
	{
		m_nuclei_FindSG->clearContents();
		m_nuclei_FindSG->setRowCount(0);
	}
	else if(begin == -2)	// clear selected
	{
		for(int row : GetSelectedRows_FindSG(true))
			m_nuclei_FindSG->removeRow(row);
	}
	else if(begin >= 0 && end >= 0)		// clear given range
	{
		for(int row=end-1; row>=begin; --row)
			m_nuclei_FindSG->removeRow(row);
	}

926
	//FindSG();
Tobias WEBER's avatar
Tobias WEBER committed
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
}


void StructFactDlg::MoveTabItemUp_FindSG()
{
	m_nuclei_FindSG->setSortingEnabled(false);

	auto selected = GetSelectedRows_FindSG(false);
	for(int row : selected)
	{
		if(row == 0)
			continue;

		auto *item = m_nuclei_FindSG->item(row, 0);
		if(!item || !item->isSelected())
			continue;

		m_nuclei_FindSG->insertRow(row-1);
		for(int col=0; col<m_nuclei_FindSG->columnCount(); ++col)
			m_nuclei_FindSG->setItem(row-1, col, m_nuclei_FindSG->item(row+1, col)->clone());
		m_nuclei_FindSG->removeRow(row+1);
	}

	for(int row=0; row<m_nuclei_FindSG->rowCount(); ++row)
	{
		if(auto *item = m_nuclei_FindSG->item(row, 0);
		   item && std::find(selected.begin(), selected.end(), row+1) != selected.end())
		   {
			   for(int col=0; col<m_nuclei_FindSG->columnCount(); ++col)
				   m_nuclei_FindSG->item(row, col)->setSelected(true);
		   }
	}
}


void StructFactDlg::MoveTabItemDown_FindSG()
{
	m_nuclei_FindSG->setSortingEnabled(false);

	auto selected = GetSelectedRows_FindSG(true);
	for(int row : selected)
	{
		if(row == m_nuclei_FindSG->rowCount()-1)
			continue;

		auto *item = m_nuclei_FindSG->item(row, 0);
		if(!item || !item->isSelected())
			continue;

		m_nuclei_FindSG->insertRow(row+2);
		for(int col=0; col<m_nuclei_FindSG->columnCount(); ++col)
			m_nuclei_FindSG->setItem(row+2, col, m_nuclei_FindSG->item(row, col)->clone());
		m_nuclei_FindSG->removeRow(row);
	}

	for(int row=0; row<m_nuclei_FindSG->rowCount(); ++row)
	{
		if(auto *item = m_nuclei_FindSG->item(row, 0);
		   item && std::find(selected.begin(), selected.end(), row-1) != selected.end())
		   {
			   for(int col=0; col<m_nuclei_FindSG->columnCount(); ++col)
				   m_nuclei_FindSG->item(row, col)->setSelected(true);
		   }
	}
}
// ----------------------------------------------------------------------------



// ----------------------------------------------------------------------------
std::vector<int> StructFactDlg::GetSelectedRows_FindSG(bool sort_reversed) const
{
	std::vector<int> vec;
	vec.reserve(m_nuclei_FindSG->selectedItems().size());

	for(int row=0; row<m_nuclei_FindSG->rowCount(); ++row)
	{
		if(auto *item = m_nuclei_FindSG->item(row, 0); item && item->isSelected())
			vec.push_back(row);
	}

	if(sort_reversed)
	{
		std::stable_sort(vec.begin(), vec.end(), [](int row1, int row2)
		{ return row1 > row2; });
	}

	return vec;
}


/**
 * item contents changed
 */
void StructFactDlg::TableItemChanged_FindSG(QTableWidgetItem *item)
{
1023
	//FindSG();
Tobias WEBER's avatar
Tobias WEBER committed
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
}


void StructFactDlg::ShowTableContextMenu_FindSG(const QPoint& pt)
{
	auto ptGlob = m_nuclei_FindSG->mapToGlobal(pt);

	if(const auto* item = m_nuclei_FindSG->itemAt(pt); item)
	{
		m_iCursorRow_FindSG = item->row();
		ptGlob.setY(ptGlob.y() + m_pTabContextMenu_FindSG->sizeHint().height()/2);
		m_pTabContextMenu_FindSG->popup(ptGlob);
	}
	else
	{
		ptGlob.setY(ptGlob.y() + m_pTabContextMenuNoItem_FindSG->sizeHint().height()/2);
		m_pTabContextMenuNoItem_FindSG->popup(ptGlob);
	}
}
// ----------------------------------------------------------------------------



/**
 * find a matching space group for the given nucleus positions
 */
void StructFactDlg::FindSG()
{
	m_sgmatches->setPlainText("");

	std::vector<t_vec> vecFinal;
	std::ostringstream ostr;
	ostr.precision(g_prec);

	ostr << "Full set of nuclear positions to match:\n";
	for(int row=0; row<m_nuclei_FindSG->rowCount(); ++row)
	{
		auto *itemx = m_nuclei_FindSG->item(row, 0);
		auto *itemy = m_nuclei_FindSG->item(row, 1);
		auto *itemz = m_nuclei_FindSG->item(row, 2);

		if(!itemx || !itemy || !itemz)
			return;

		t_real posx=0, posy=0, posz=0;
		std::istringstream{itemx->text().toStdString()} >> posx;
		std::istringstream{itemy->text().toStdString()} >> posy;
		std::istringstream{itemz->text().toStdString()} >> posz;

		ostr << "\t(" << (row+1) << "): (" << posx << ", " << posy << ", " << posz << ")\n";
		vecFinal.emplace_back(t_vec{{posx, posy, posz}});
	}

	ostr << "\n";
	std::vector<t_vec> vecInit = vecFinal;

	while(1)
	{
		ostr << "\n--------------------------------------------------------------------------------\n";
		ostr << "Base set of nuclear positions:\n";
		std::size_t ctr = 1;
		for(const auto& pos : vecInit)
			ostr << "\t(" << ctr++ << ") " << pos << "\n";
		ostr << std::endl;

		auto matchingSGs = find_matching_sgs<t_vec, t_mat, t_real>(vecInit, vecFinal, g_eps);

		if(matchingSGs.size())
		{
			ostr << "Matching space groups:\n";
			ctr = 1;
			for(const auto& sg : matchingSGs)
				ostr << "\t(" << ctr++ << ") " << std::get<1>(sg) << "\n";
		}
		else
		{
			ostr << "No matching space groups.\n";
		}
		ostr << "--------------------------------------------------------------------------------\n\n";

		vecInit.pop_back();
		if(vecInit.size() == 0)
			break;
	}

	m_sgmatches->setPlainText(ostr.str().c_str());
}
1111

Tobias WEBER's avatar
Tobias WEBER committed
1112
// ============================================================================
1113

1114
1115


Tobias WEBER's avatar
Tobias WEBER committed
1116
// ----------------------------------------------------------------------------
1117
1118
void StructFactDlg::Load()
{
1119
1120
	m_ignoreCalc = 1;

Tobias WEBER's avatar
Tobias WEBER committed
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
	try
	{
		QString dirLast = m_sett->value("dir", "").toString();
		QString filename = QFileDialog::getOpenFileName(this, "Load File", dirLast, "XML Files (*.xml *.XML)");
		if(filename=="" || !QFile::exists(filename))
			return;
		m_sett->setValue("dir", QFileInfo(filename).path());


		pt::ptree node;

		std::ifstream ifstr{filename.toStdString()};
		pt::read_xml(ifstr, node);

		// check signature
		if(auto opt = node.get_optional<std::string>("sfact.meta.info"); !opt || *opt!=std::string{"sfact_tool"})
		{
			QMessageBox::critical(this, "Structure Factors", "Unrecognised file format.");
			return;
		}


		// clear old nuclei
1144
		DelTabItem(-1);
Tobias WEBER's avatar
Tobias WEBER committed
1145
1146
1147

		if(auto opt = node.get_optional<t_real>("sfact.xtal.a"); opt)
		{
Tobias WEBER's avatar
Tobias WEBER committed
1148
			std::ostringstream ostr; ostr.precision(g_prec); ostr << *opt;
Tobias WEBER's avatar
Tobias WEBER committed
1149
1150
1151
1152
			m_editA->setText(ostr.str().c_str());
		}
		if(auto opt = node.get_optional<t_real>("sfact.xtal.b"); opt)
		{
Tobias WEBER's avatar
Tobias WEBER committed
1153
			std::ostringstream ostr; ostr.precision(g_prec); ostr << *opt;
Tobias WEBER's avatar
Tobias WEBER committed
1154
1155
1156
1157
			m_editB->setText(ostr.str().c_str());
		}
		if(auto opt = node.get_optional<t_real>("sfact.xtal.c"); opt)
		{
Tobias WEBER's avatar
Tobias WEBER committed
1158
			std::ostringstream ostr; ostr.precision(g_prec); ostr << *opt;
Tobias WEBER's avatar
Tobias WEBER committed
1159
1160
1161
1162
			m_editC->setText(ostr.str().c_str());
		}
		if(auto opt = node.get_optional<t_real>("sfact.xtal.alpha"); opt)
		{
Tobias WEBER's avatar
Tobias WEBER committed
1163
			std::ostringstream ostr; ostr.precision(g_prec); ostr << *opt;
Tobias WEBER's avatar
Tobias WEBER committed
1164
1165
1166
1167
			m_editAlpha->setText(ostr.str().c_str());
		}
		if(auto opt = node.get_optional<t_real>("sfact.xtal.beta"); opt)
		{
Tobias WEBER's avatar
Tobias WEBER committed
1168
			std::ostringstream ostr; ostr.precision(g_prec); ostr << *opt;
Tobias WEBER's avatar
Tobias WEBER committed
1169
1170
1171
1172
			m_editBeta->setText(ostr.str().c_str());
		}
		if(auto opt = node.get_optional<t_real>("sfact.xtal.gamma"); opt)
		{
Tobias WEBER's avatar
Tobias WEBER committed
1173
			std::ostringstream ostr; ostr.precision(g_prec); ostr << *opt;
Tobias WEBER's avatar
Tobias WEBER committed
1174
1175
1176
1177
1178
1179
			m_editGamma->setText(ostr.str().c_str());
		}
		if(auto opt = node.get_optional<int>("sfact.order"); opt)
		{
			m_maxBZ->setValue(*opt);
		}
1180
1181
1182
1183
		if(auto opt = node.get_optional<int>("sfact.removezeroes"); opt)
		{
			m_RemoveZeroes->setChecked(*opt != 0);
		}
1184
1185
1186
1187
		if(auto opt = node.get_optional<int>("sfact.sg_idx"); opt)
		{
			m_comboSG->setCurrentIndex(*opt);
		}
Tobias WEBER's avatar
Tobias WEBER committed
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200


		// nuclei
		if(auto nuclei = node.get_child_optional("sfact.nuclei"); nuclei)
		{
			for(const auto &nucl : *nuclei)
			{
				auto optName = nucl.second.get<std::string>("name", "n/a");
				auto optbRe = nucl.second.get<t_real>("b_Re", 0.);
				auto optbIm = nucl.second.get<t_real>("b_Im", 0.);
				auto optX = nucl.second.get<t_real>("x", 0.);
				auto optY = nucl.second.get<t_real>("y", 0.);
				auto optZ = nucl.second.get<t_real>("z", 0.);
Tobias WEBER's avatar
Tobias WEBER committed
1201
				auto optRad = nucl.second.get<t_real>("rad", 1.);
Tobias WEBER's avatar
Tobias WEBER committed
1202
				auto optCol = nucl.second.get<std::string>("col", "#ff0000");
Tobias WEBER's avatar
Tobias WEBER committed
1203

Tobias WEBER's avatar
Tobias WEBER committed
1204
				AddTabItem(-1, optName, optbRe, optbIm, optX,  optY, optZ, optRad, optCol);
Tobias WEBER's avatar
Tobias WEBER committed
1205
1206
1207
1208
1209
1210
1211
			}
		}
	}
	catch(const std::exception& ex)
	{
		QMessageBox::critical(this, "Structure Factors", ex.what());
	}
1212
1213
1214
1215
1216


	m_ignoreCalc = 0;
	CalcB(false);
	Calc();
1217
1218
1219
1220
1221
}


void StructFactDlg::Save()
{
Tobias WEBER's avatar
Tobias WEBER committed
1222
1223
1224
1225
1226
1227
	QString dirLast = m_sett->value("dir", "").toString();
	QString filename = QFileDialog::getSaveFileName(this, "Save File", dirLast, "XML Files (*.xml *.XML)");
	if(filename=="")
		return;
	m_sett->setValue("dir", QFileInfo(filename).path());

1228

Tobias WEBER's avatar
Tobias WEBER committed
1229
1230
1231
	pt::ptree node;
	node.put<std::string>("sfact.meta.info", "sfact_tool");
	node.put<std::string>("sfact.meta.date", tl2::epoch_to_str<t_real>(tl2::epoch<t_real>()));
1232

Tobias WEBER's avatar
Tobias WEBER committed
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249

	// lattice
	t_real a,b,c, alpha,beta,gamma;
	std::istringstream{m_editA->text().toStdString()} >> a;
	std::istringstream{m_editB->text().toStdString()} >> b;
	std::istringstream{m_editC->text().toStdString()} >> c;
	std::istringstream{m_editAlpha->text().toStdString()} >> alpha;
	std::istringstream{m_editBeta->text().toStdString()} >> beta;
	std::istringstream{m_editGamma->text().toStdString()} >> gamma;

	node.put<t_real>("sfact.xtal.a", a);
	node.put<t_real>("sfact.xtal.b", b);
	node.put<t_real>("sfact.xtal.c", c);
	node.put<t_real>("sfact.xtal.alpha", alpha);
	node.put<t_real>("sfact.xtal.beta", beta);
	node.put<t_real>("sfact.xtal.gamma", gamma);
	node.put<int>("sfact.order", m_maxBZ->value());
1250
	node.put<int>("sfact.removezeroes", m_RemoveZeroes->isChecked());
1251
	node.put<int>("sfact.sg_idx", m_comboSG->currentIndex());
Tobias WEBER's avatar
Tobias WEBER committed
1252
1253
1254
1255

	// nucleus list
	for(int row=0; row<m_nuclei->rowCount(); ++row)
	{
1256
		t_real bRe{},bIm{}, x{},y{},z{}, scale{};
Tobias WEBER's avatar
Tobias WEBER committed
1257
1258
1259
1260
1261
		std::istringstream{m_nuclei->item(row, COL_SCATLEN_RE)->text().toStdString()} >> bRe;
		std::istringstream{m_nuclei->item(row, COL_SCATLEN_IM)->text().toStdString()} >> bIm;
		std::istringstream{m_nuclei->item(row, COL_X)->text().toStdString()} >> x;
		std::istringstream{m_nuclei->item(row, COL_Y)->text().toStdString()} >> y;
		std::istringstream{m_nuclei->item(row, COL_Z)->text().toStdString()} >> z;
Tobias WEBER's avatar
Tobias WEBER committed
1262
		std::istringstream{m_nuclei->item(row, COL_RAD)->text().toStdString()} >> scale;
Tobias WEBER's avatar
Tobias WEBER committed
1263
1264
1265
1266
1267
1268
1269
1270

		pt::ptree itemNode;
		itemNode.put<std::string>("name", m_nuclei->item(row, COL_NAME)->text().toStdString());
		itemNode.put<t_real>("b_Re", bRe);
		itemNode.put<t_real>("b_Im", bIm);
		itemNode.put<t_real>("x", x);
		itemNode.put<t_real>("y", y);
		itemNode.put<t_real>("z", z);
Tobias WEBER's avatar
Tobias WEBER committed
1271
		itemNode.put<t_real>("rad", scale);
Tobias WEBER's avatar
Tobias WEBER committed
1272
		itemNode.put<std::string>("col", m_nuclei->item(row, COL_COL)->text().toStdString());
Tobias WEBER's avatar
Tobias WEBER committed
1273
1274
1275
1276
1277

		node.add_child("sfact.nuclei.nucleus", itemNode);
	}

	std::ofstream ofstr{filename.toStdString()};
Tobias WEBER's avatar
Tobias WEBER committed
1278
1279
1280
1281
1282
1283
	if(!ofstr)
	{
		QMessageBox::critical(this, "Structure Factors", "Cannot open file for writing.");
		return;
	}
	ofstr.precision(g_prec);
Tobias WEBER's avatar
Tobias WEBER committed
1284
1285
	pt::write_xml(ofstr, node, pt::xml_writer_make_settings('\t', 1, std::string{"utf-8"}));
}
Tobias WEBER's avatar
Tobias WEBER committed
1286
1287


Tobias WEBER's avatar
Tobias WEBER committed
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
/**
 * save a TAZ file
 */
void StructFactDlg::ExportTAZ()
{
	QString dirLast = m_sett->value("dir_taz", "").toString();
	QString filename = QFileDialog::getSaveFileName(this, "Export TAZ", dirLast, "TAZ Files (*.taz *.TAZ)");
	if(filename=="" || !QFile::exists(filename))
		return;
	m_sett->setValue("dir_taz", QFileInfo(filename).path());

	std::ofstream ofstr{filename.toStdString()};
	if(!ofstr)
	{
		QMessageBox::critical(this, "Structure Factors", "Cannot open file for writing.");
		return;
	}
	ofstr.precision(g_prec);

	ofstr << "<taz>\n";
	ofstr << "\t<meta><info>Exported from IN20Tools/Structfact.</info></meta>\n";

	// sample infos
	ofstr << "\t<sample>\n";
	ofstr << "\t\t<a>" << m_editA->text().toStdString() << "</a>\n";
	ofstr << "\t\t<b>" << m_editB->text().toStdString() << "</b>\n";
	ofstr << "\t\t<c>" << m_editC->text().toStdString() << "</c>\n";
	ofstr << "\t\t<alpha>" << m_editAlpha->text().toStdString() << "</alpha>\n";
	ofstr << "\t\t<beta>" << m_editBeta->text().toStdString() << "</beta>\n";
	ofstr << "\t\t<gamma>" << m_editGamma->text().toStdString() << "</gamma>\n";

	// P1 only has the identity trafo, so we can directly output all raw nucleus positions
	ofstr << "\t\t<spacegroup>P1</spacegroup>\n";

	// nucleus list
	ofstr << "\t\t<atoms>\n";
	ofstr << "\t\t\t<num>" << m_nuclei->rowCount() << "</num>\n";
	for(int row=0; row<m_nuclei->rowCount(); ++row)
	{
		ofstr << "\t\t\t<" << row << ">\n";
		ofstr << "\t\t\t\t<name>" << m_nuclei->item(row, COL_NAME)->text().toStdString() << "</name>\n";
		ofstr << "\t\t\t\t<x>" << m_nuclei->item(row, COL_X)->text().toStdString() << "</x>\n";
		ofstr << "\t\t\t\t<y>" << m_nuclei->item(row, COL_Y)->text().toStdString() << "</y>\n";
		ofstr << "\t\t\t\t<z>" << m_nuclei->item(row, COL_Z)->text().toStdString() << "</z>\n";
		ofstr << "\t\t\t</" << row << ">\n";
	}

	ofstr << "\t\t</atoms>\n";
	ofstr << "\t</sample>\n";

	ofstr << "</taz>\n";
}


/**
 * load a CIF
 */
Tobias WEBER's avatar
Tobias WEBER committed
1345
1346
void StructFactDlg::ImportCIF()
{
1347
	m_ignoreCalc = 1;
Tobias WEBER's avatar
Tobias WEBER committed
1348

1349
	try
Tobias WEBER's avatar
Tobias WEBER committed
1350
	{
1351
1352
1353
1354
1355
		QString dirLast = m_sett->value("dir_cif", "").toString();
		QString filename = QFileDialog::getOpenFileName(this, "Import CIF", dirLast, "CIF Files (*.cif *.CIF)");
		if(filename=="" || !QFile::exists(filename))
			return;
		m_sett->setValue("dir_cif", QFileInfo(filename).path());
Tobias WEBER's avatar
Tobias WEBER committed
1356

Tobias WEBER's avatar
Tobias WEBER committed
1357
1358
		auto [errstr, atoms, generatedatoms, atomnames, lattice, symops] = 
			load_cif<t_vec, t_mat>(filename.toStdString(), g_eps);
Tobias WEBER's avatar
Tobias WEBER committed
1359
		if(errstr != "")
1360
		{
Tobias WEBER's avatar
Tobias WEBER committed
1361
			QMessageBox::critical(this, "Structure Factors", errstr.c_str());
1362
1363
			return;
		}
Tobias WEBER's avatar
Tobias WEBER committed
1364
1365


1366
1367
		// clear old nuclei
		DelTabItem(-1);
Tobias WEBER's avatar
Tobias WEBER committed
1368

1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
		// lattice
		{
			std::ostringstream ostr; ostr.precision(g_prec); ostr << lattice.a;
			m_editA->setText(ostr.str().c_str());
		}
		{
			std::ostringstream ostr; ostr.precision(g_prec); ostr << lattice.b;
			m_editB->setText(ostr.str().c_str());
		}
		{
			std::ostringstream ostr; ostr.precision(g_prec); ostr << lattice.c;
			m_editC->setText(ostr.str().c_str());
		}
		{
			std::ostringstream ostr; ostr.precision(g_prec); ostr << lattice.alpha;
			m_editAlpha->setText(ostr.str().c_str());
		}
		{
			std::ostringstream ostr; ostr.precision(g_prec); ostr << lattice.beta;
			m_editBeta->setText(ostr.str().c_str());
		}
		{
			std::ostringstream ostr; ostr.precision(g_prec); ostr << lattice.gamma;
			m_editGamma->setText(ostr.str().c_str());
		}
Tobias WEBER's avatar
Tobias WEBER committed
1394
	
1395
1396
1397
1398

		// atoms
		std::mt19937 gen{tl2::epoch<unsigned int>()};
		for(std::size_t atomnum=0; atomnum<atoms.size(); ++atomnum)
Tobias WEBER's avatar
Tobias WEBER committed
1399
		{
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
			// random colour
			std::ostringstream ostrcol;
			std::uniform_int_distribution<int> dist{0, 255};
			ostrcol << "#" << std::hex << std::setw(2) << std::setfill('0') << dist(gen) 
				<< std::setw(2) << std::setfill('0') << dist(gen) 
				<< std::setw(2) << std::setfill('0') << dist(gen);

			for(std::size_t symnr=0; symnr<generatedatoms[atomnum].size(); ++symnr)
			{
				AddTabItem(-1, atomnames[atomnum], 0, 0, 
					generatedatoms[atomnum][symnr][0],  generatedatoms[atomnum][symnr][1], generatedatoms[atomnum][symnr][2], 
					1, ostrcol.str());
			}
Tobias WEBER's avatar
Tobias WEBER committed
1413
1414
		}
	}
1415
1416
1417
1418
1419
1420
1421
1422
1423
	catch(const std::exception& ex)
	{
		QMessageBox::critical(this, "Structure Factors", ex.what());
	}


	m_ignoreCalc = 0;
	CalcB(false);
	Calc();
Tobias WEBER's avatar
Tobias WEBER committed
1424
}
1425
1426
1427
// ----------------------------------------------------------------------------


Tobias WEBER's avatar
Tobias WEBER committed
1428
1429
1430
1431
1432
/**
 * generate symmetric nuclei from space group
 */
void StructFactDlg::GenerateFromSG()
{
1433
	m_ignoreCalc = 1;
1434