magstructfact.h 4.55 KB
Newer Older
1
2
3
4
5
/**
 * magnetic structure factor tool
 * @author Tobias Weber <tweber@ill.fr>
 * @date Jan-2019
 * @license GPLv3, see 'LICENSE' file
Tobias WEBER's avatar
Tobias WEBER committed
6
 * @desc The present version was forked on 28-Dec-2018 from my privately developed "misc" project (https://github.com/t-weber/misc).
7
8
9
10
11
12
13
14
15
16
17
18
19
20
 */

#ifndef __MAG_SFACT_H__
#define __MAG_SFACT_H__

#include <QtWidgets/QDialog>
#include <QtWidgets/QTableWidget>
#include <QtWidgets/QPlainTextEdit>
#include <QtWidgets/QLineEdit>
#include <QtWidgets/QSpinBox>
#include <QtWidgets/QMenuBar>
#include <QtWidgets/QMenu>
#include <QtWidgets/QLabel>
#include <QtWidgets/QComboBox>
21
#include <QtWidgets/QCheckBox>
22
23
24
25
26
27
#include <QtCore/QSettings>

#include <vector>
#include <sstream>
#include <complex>

Tobias WEBER's avatar
Tobias WEBER committed
28
#include "libs/glplot.h"
Tobias WEBER's avatar
Tobias WEBER committed
29
#include "libs/math20.h"
30
31
32
33
34
35

#include "../structfact/numerictablewidgetitem.h"


using t_real = double;
using t_cplx = std::complex<t_real>;
Tobias WEBER's avatar
Tobias WEBER committed
36
37
using t_vec = tl2::vec<t_real, std::vector>;
using t_vec_cplx = tl2::vec<t_cplx, std::vector>;
Tobias WEBER's avatar
Tobias WEBER committed
38
39
using t_mat = tl2::mat<t_real, std::vector>;
using t_mat_cplx = tl2::mat<t_cplx, std::vector>;
40
41
42
43


struct NuclPos
{
Tobias WEBER's avatar
Tobias WEBER committed
44
45
46
47
48
49
50
	// physically meaningful data
	t_real pos[3];		// position
	t_cplx MAbs{1};		// magnitude of Fourier components
	t_real ReM[3];		// real part of Fourier components
	t_real ImM[3];		// imag part of Fourier components

	// cosmetic data
51
	std::string name;
Tobias WEBER's avatar
Tobias WEBER committed
52
53
	std::string col{"#ff0000"};
	t_real scale{1};	// scaling of Fourier components (only for drawing)
54
55
56
57
58
59
60
};


class MagStructFactDlg : public QDialog
{
public:
	MagStructFactDlg(QWidget* pParent = nullptr);
Tobias WEBER's avatar
Tobias WEBER committed
61
	virtual ~MagStructFactDlg() = default;
62
63
64
65
66

protected:
	QSettings *m_sett = nullptr;
	QMenuBar *m_menu = nullptr;

Tobias WEBER's avatar
Tobias WEBER committed
67
	// unit cell view
68
69
70
	QDialog *m_dlgPlot = nullptr;
	std::shared_ptr<GlPlot> m_plot;
	std::size_t m_sphere = 0;
71
	std::size_t m_arrow = 0;
72
	QLabel *m_status3D = nullptr;
Tobias WEBER's avatar
Tobias WEBER committed
73
74
75
76
77
78

	// super cell view
	QDialog *m_dlgPlotSC = nullptr;
	std::shared_ptr<GlPlot> m_plotSC;
	std::size_t m_sphereSC = 0;
	std::size_t m_arrowSC = 0;
79
	QLabel *m_status3DSC = nullptr;
Tobias WEBER's avatar
Tobias WEBER committed
80

81
82
83
	QLabel *m_labelGlInfos[4] = { nullptr, nullptr, nullptr, nullptr };

	QWidget *m_nucleipanel = nullptr;
84
	QWidget *m_propvecpanel = nullptr;
85
	QTableWidget *m_nuclei = nullptr;
86
	QTableWidget *m_propvecs = nullptr;
87
88
	QPlainTextEdit *m_structfacts = nullptr;
	QPlainTextEdit *m_powderlines = nullptr;
89
	QPlainTextEdit *m_moments = nullptr;
90
91
92
93
94
95
96
97
98
99
100
101

	QLineEdit *m_editA = nullptr;
	QLineEdit *m_editB = nullptr;
	QLineEdit *m_editC = nullptr;
	QLineEdit *m_editAlpha = nullptr;
	QLineEdit *m_editBeta = nullptr;
	QLineEdit *m_editGamma = nullptr;

	QComboBox *m_comboSG = nullptr;
	std::vector<std::vector<t_mat>> m_SGops;

	QSpinBox *m_maxBZ = nullptr;
102
	QCheckBox *m_RemoveZeroes = nullptr;
Tobias WEBER's avatar
Tobias WEBER committed
103
	QSpinBox *m_maxSC[3] = { nullptr, nullptr, nullptr };
104

Tobias WEBER's avatar
Tobias WEBER committed
105
106
	t_mat m_crystA = tl2::unit<t_mat>(3);
	t_mat m_crystB = tl2::unit<t_mat>(3);
107
108

protected:
109
110
111
112
113
114
115
	// general table operations
	void MoveTabItemUp(QTableWidget *pTab);
	void MoveTabItemDown(QTableWidget *pTab);
	void ShowTableContextMenu(QTableWidget *pTab, QMenu *pMenu, QMenu *pMenuNoItem, const QPoint& pt);
	std::vector<int> GetSelectedRows(QTableWidget *pTab, bool sort_reversed = false) const;

	// Fourier components table
116
117
118
119
120
121
	void AddTabItem(int row=-1, const std::string& name="n/a", t_real MMag=1.,
		t_real x=0., t_real y=0., t_real z=0., 
		t_real ReMx=0., t_real ReMy=0., t_real ReMz=1.,
		t_real ImMx=0., t_real ImMy=0., t_real ImMz=0., 
		t_real scale=1., const std::string &col="#ff0000");
	void DelTabItem(int begin=-2, int end=-2);
122
123
124
125
126
127
	void TableCurCellChanged(int rowNew, int colNew, int rowOld, int colOld);
	void TableCellEntered(const QModelIndex& idx);
	void TableItemChanged(QTableWidgetItem *item);

	// propagation vectors table
	void AddPropItem(int row=-1, const std::string& name="n/a", 
Tobias WEBER's avatar
Tobias WEBER committed
128
		t_real x=0., t_real y=0., t_real z=0., bool bConjFC=0);
129
130
	void DelPropItem(int begin=-2, int end=-2);
	void PropItemChanged(QTableWidgetItem *item);
131
132

	void Add3DItem(int row=-1);
133
	void Sync3DItem(int row=-1);
134
135
136
137
138
139
140
141
142
143
144
145

	void Load();
	void Save();
	void ImportCIF();
	void GenerateFromSG();

	std::vector<NuclPos> GetNuclei() const;
	void CalcB(bool bFullRecalc=true);
	void Calc();

	void PlotMouseDown(bool left, bool mid, bool right);
	void PickerIntersection(const t_vec3_gl* pos, std::size_t objIdx, const t_vec3_gl* posSphere);
146
	void PickerIntersectionSC(const t_vec3_gl* pos, std::size_t objIdx, const t_vec3_gl* posSphere);
147
	void AfterGLInitialisation();
Tobias WEBER's avatar
Tobias WEBER committed
148
	void AfterGLInitialisationSC();
Tobias WEBER's avatar
Tobias WEBER committed
149
	void SetGLInfos();
150
151
152
153
154

	virtual void closeEvent(QCloseEvent *evt) override;

private:
	int m_iCursorRow = -1;
Tobias WEBER's avatar
Tobias WEBER committed
155

156
	bool m_ignoreChanges = 1;
157
	bool m_ignoreCalc = 0;
158
159

	long m_curPickedObj = -1;
Tobias WEBER's avatar
Tobias WEBER committed
160
161

	std::vector<std::size_t> m_3dobjsSC;
162
163
164
165
};


#endif