qtas.py 16.3 KB
Newer Older
Tobias WEBER's avatar
Tobias WEBER committed
1
2
3
4
5
6
#
# tascalc gui
# @author Tobias Weber <tweber@ill.fr>
# @date 24-oct-18
# @license see 'LICENSE' file
#
Tobias WEBER's avatar
Tobias WEBER committed
7
8
9
# __ident__ : TAS Calculator
# __descr__ : Calculates triple-axis angles.
#
Tobias WEBER's avatar
Tobias WEBER committed
10

Tobias WEBER's avatar
Tobias WEBER committed
11
12
13
# -----------------------------------------------------------------------------
# dependencies
import sys
Tobias WEBER's avatar
Tobias WEBER committed
14
15
16
17
import tascalc as tas
import numpy as np
import numpy.linalg as la

Tobias WEBER's avatar
Tobias WEBER committed
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# try to import qt5...
try:
	import PyQt5 as qt
	import PyQt5.QtCore as qtc
	import PyQt5.QtWidgets as qtw
	qt_ver = 5
except ImportError:
	# ...and if not possible try to import qt4 instead
	try:
		import PyQt4 as qt
		import PyQt4.QtCore as qtc
		import PyQt4.QtGui as qtw
		qt_ver = 4
	except ImportError:
		print("Error: No suitable version of Qt was found!")
		exit(-1)
# -----------------------------------------------------------------------------
Tobias WEBER's avatar
Tobias WEBER committed
35
36
37



Tobias WEBER's avatar
Tobias WEBER committed
38
39
# -----------------------------------------------------------------------------
# main application
Tobias WEBER's avatar
Tobias WEBER committed
40
41
np.set_printoptions(suppress=True, precision=4)

Tobias WEBER's avatar
Tobias WEBER committed
42
app = qtw.QApplication(sys.argv)
Tobias WEBER's avatar
Tobias WEBER committed
43
app.setApplicationName("qtas")
Tobias WEBER's avatar
Tobias WEBER committed
44
45
46
47
48
#app.setStyle("Fusion")

sett = qtc.QSettings("tobis_stuff", "in20tool")
if sett.contains("mainwnd/theme"):
	app.setStyle(sett.value("mainwnd/theme"))
Tobias WEBER's avatar
Tobias WEBER committed
49
50

tabs = qtw.QTabWidget()
Tobias WEBER's avatar
Tobias WEBER committed
51
# -----------------------------------------------------------------------------
Tobias WEBER's avatar
Tobias WEBER committed
52
53
54
55
56
57
58



# -----------------------------------------------------------------------------
# variables
B = np.array([[1,0,0], [0,1,0], [0,0,1]])
orient_rlu = np.array([1,0,0])
Tobias WEBER's avatar
Tobias WEBER committed
59
#orient2_rlu = np.array([0,1,0])
Tobias WEBER's avatar
Tobias WEBER committed
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
orient_up_rlu = np.array([0,0,1])
# -----------------------------------------------------------------------------



# -----------------------------------------------------------------------------
# helpers
def getfloat(str):
	try:
		return float(str)
	except ValueError:
		return 0.
# -----------------------------------------------------------------------------



# -----------------------------------------------------------------------------
# crystal tab

xtalpanel = qtw.QWidget()
xtallayout = qtw.QGridLayout(xtalpanel)
Tobias WEBER's avatar
Tobias WEBER committed
81
82
scpanel = xtalpanel
sclayout = xtallayout
Tobias WEBER's avatar
Tobias WEBER committed
83
84
85
86
87
88
89

editA = qtw.QLineEdit(xtalpanel)
editB = qtw.QLineEdit(xtalpanel)
editC = qtw.QLineEdit(xtalpanel)
editAlpha = qtw.QLineEdit(xtalpanel)
editBeta = qtw.QLineEdit(xtalpanel)
editGamma = qtw.QLineEdit(xtalpanel)
Tobias WEBER's avatar
Tobias WEBER committed
90
91
separatorXtal = qtw.QFrame(xtalpanel)
separatorXtal.setFrameStyle(qtw.QFrame.HLine)
Tobias WEBER's avatar
Tobias WEBER committed
92
93
94
95
96
97
editAx = qtw.QLineEdit(scpanel)
editAy = qtw.QLineEdit(scpanel)
editAz = qtw.QLineEdit(scpanel)
editBx = qtw.QLineEdit(scpanel)
editBy = qtw.QLineEdit(scpanel)
editBz = qtw.QLineEdit(scpanel)
Tobias WEBER's avatar
Tobias WEBER committed
98
99
editBMat = qtw.QPlainTextEdit(xtalpanel)
editBMat.setReadOnly(True)
Tobias WEBER's avatar
Tobias WEBER committed
100
101
102


def xtalChanged():
Tobias WEBER's avatar
Tobias WEBER committed
103
	global B, orient_rlu, orient_up_rlu
Tobias WEBER's avatar
Tobias WEBER committed
104
105
	lattice = np.array([getfloat(editA.text()), getfloat(editB.text()), getfloat(editC.text())])
	angles = np.array([getfloat(editAlpha.text()), getfloat(editBeta.text()), getfloat(editGamma.text())])
Tobias WEBER's avatar
Tobias WEBER committed
106
107
108
	orient_rlu = np.array([getfloat(editAx.text()), getfloat(editAy.text()), getfloat(editAz.text())])
	orient2_rlu = np.array([getfloat(editBx.text()), getfloat(editBy.text()), getfloat(editBz.text())])

Tobias WEBER's avatar
Tobias WEBER committed
109
110
111
	try:
		B = tas.get_B(lattice, angles/180.*np.pi)
		invB = la.inv(B)
Tobias WEBER's avatar
Tobias WEBER committed
112
113
114
115
116
117
118
119
120
121
122
123
124

		metric = tas.get_metric(B)
		ang = tas.angle(orient_rlu, orient2_rlu, metric)

		orient_up_rlu = tas.cross(orient_rlu, orient2_rlu, B)
		orient_up_rlu_norm = orient_up_rlu / la.norm(orient_up_rlu)

		UB = tas.get_UB(B, orient_rlu, orient2_rlu, orient_up_rlu)
		invUB = la.inv(UB)

		editBMat.setPlainText("Scattering plane normal: %s rlu.\n" % str(orient_up_rlu_norm) \
			+"Angle between orientation vectors 1 and 2: %.4g deg.\n" % (ang/np.pi*180.) \
			+"\nB =\n%10.4f %10.4f %10.4f\n%10.4f %10.4f %10.4f\n%10.4f %10.4f %10.4f\n" \
Tobias WEBER's avatar
Tobias WEBER committed
125
			% (B[0,0],B[0,1],B[0,2], B[1,0],B[1,1],B[1,2], B[2,0],B[2,1],B[2,2]) \
Tobias WEBER's avatar
Tobias WEBER committed
126
			+"\nB^(-1) =\n%10.4f %10.4f %10.4f\n%10.4f %10.4f %10.4f\n%10.4f %10.4f %10.4f\n" \
Tobias WEBER's avatar
Tobias WEBER committed
127
128
129
130
131
132
			% (invB[0,0],invB[0,1],invB[0,2], invB[1,0],invB[1,1],invB[1,2], invB[2,0],invB[2,1],invB[2,2]) \
			+"\nUB =\n%10.4f %10.4f %10.4f\n%10.4f %10.4f %10.4f\n%10.4f %10.4f %10.4f\n" \
			% (UB[0,0],UB[0,1],UB[0,2], UB[1,0],UB[1,1],UB[1,2], UB[2,0],UB[2,1],UB[2,2]) \
			+"\n(UB)^(-1) =\n%10.4f %10.4f %10.4f\n%10.4f %10.4f %10.4f\n%10.4f %10.4f %10.4f\n" \
			% (invUB[0,0],invUB[0,1],invUB[0,2], invUB[1,0],invUB[1,1],invUB[1,2], invUB[2,0],invUB[2,1],invUB[2,2]) \
		)
Tobias WEBER's avatar
Tobias WEBER committed
133
	except (ArithmeticError, la.LinAlgError) as err:
Tobias WEBER's avatar
Tobias WEBER committed
134
		editBMat.setPlainText("invalid")
Tobias WEBER's avatar
bugfix    
Tobias WEBER committed
135
	QChanged()
Tobias WEBER's avatar
Tobias WEBER committed
136

Tobias WEBER's avatar
Tobias WEBER committed
137
def planeChanged():
Tobias WEBER's avatar
Tobias WEBER committed
138
139
	xtalChanged()
	#QChanged()
Tobias WEBER's avatar
Tobias WEBER committed
140
141


Tobias WEBER's avatar
Tobias WEBER committed
142
143
144
145
146
147
editA.textEdited.connect(xtalChanged)
editB.textEdited.connect(xtalChanged)
editC.textEdited.connect(xtalChanged)
editAlpha.textEdited.connect(xtalChanged)
editBeta.textEdited.connect(xtalChanged)
editGamma.textEdited.connect(xtalChanged)
Tobias WEBER's avatar
Tobias WEBER committed
148
149
150
151
152
153
154
editAx.textEdited.connect(planeChanged)
editAy.textEdited.connect(planeChanged)
editAz.textEdited.connect(planeChanged)
editBx.textEdited.connect(planeChanged)
editBy.textEdited.connect(planeChanged)
editBz.textEdited.connect(planeChanged)

Tobias WEBER's avatar
Tobias WEBER committed
155

Tobias WEBER's avatar
Tobias WEBER committed
156
157
158
159
160
161
162
163
164
165
166
167
editA.setText("%.6g" % sett.value("qtas/a", 5., type=float))
editB.setText("%.6g" % sett.value("qtas/b", 5., type=float))
editC.setText("%.6g" % sett.value("qtas/c", 5., type=float))
editAlpha.setText("%.6g" % sett.value("qtas/alpha", 90., type=float))
editBeta.setText("%.6g" % sett.value("qtas/beta", 90., type=float))
editGamma.setText("%.6g" % sett.value("qtas/gamma", 90., type=float))
editAx.setText("%.6g" % sett.value("qtas/ax", 1., type=float))
editAy.setText("%.6g" % sett.value("qtas/ay", 0., type=float))
editAz.setText("%.6g" % sett.value("qtas/az", 0., type=float))
editBx.setText("%.6g" % sett.value("qtas/bx", 0., type=float))
editBy.setText("%.6g" % sett.value("qtas/by", 1., type=float))
editBz.setText("%.6g" % sett.value("qtas/bz", 0., type=float))
Tobias WEBER's avatar
Tobias WEBER committed
168

Tobias WEBER's avatar
Tobias WEBER committed
169
xtallayout.addWidget(qtw.QLabel(u"a (\u212b):", xtalpanel), 0,0, 1,1)
Tobias WEBER's avatar
Tobias WEBER committed
170
xtallayout.addWidget(editA, 0,1, 1,3)
Tobias WEBER's avatar
Tobias WEBER committed
171
xtallayout.addWidget(qtw.QLabel(u"b (\u212b):", xtalpanel), 1,0, 1,1)
Tobias WEBER's avatar
Tobias WEBER committed
172
xtallayout.addWidget(editB, 1,1, 1,3)
Tobias WEBER's avatar
Tobias WEBER committed
173
xtallayout.addWidget(qtw.QLabel(u"c (\u212b):", xtalpanel), 2,0, 1,1)
Tobias WEBER's avatar
Tobias WEBER committed
174
xtallayout.addWidget(editC, 2,1, 1,3)
Tobias WEBER's avatar
Tobias WEBER committed
175
xtallayout.addWidget(qtw.QLabel(u"\u03b1 (deg):", xtalpanel), 3,0, 1,1)
Tobias WEBER's avatar
Tobias WEBER committed
176
xtallayout.addWidget(editAlpha, 3,1, 1,3)
Tobias WEBER's avatar
Tobias WEBER committed
177
xtallayout.addWidget(qtw.QLabel(u"\u03b2 (deg):", xtalpanel), 4,0, 1,1)
Tobias WEBER's avatar
Tobias WEBER committed
178
xtallayout.addWidget(editBeta, 4,1, 1,3)
Tobias WEBER's avatar
Tobias WEBER committed
179
xtallayout.addWidget(qtw.QLabel(u"\u03b3 (deg):", xtalpanel), 5,0, 1,1)
Tobias WEBER's avatar
Tobias WEBER committed
180
xtallayout.addWidget(editGamma, 5,1, 1,3)
Tobias WEBER's avatar
Tobias WEBER committed
181
182
183
184
185
186
187
188
189
190
xtallayout.addWidget(separatorXtal, 6,0, 1,4)
sclayout.addWidget(qtw.QLabel("Orient. 1 (rlu):", scpanel), 7,0, 1,1)
sclayout.addWidget(editAx, 7,1, 1,1)
sclayout.addWidget(editAy, 7,2, 1,1)
sclayout.addWidget(editAz, 7,3, 1,1)
sclayout.addWidget(qtw.QLabel("Orient. 2 (rlu):", scpanel), 8,0, 1,1)
sclayout.addWidget(editBx, 8,1, 1,1)
sclayout.addWidget(editBy, 8,2, 1,1)
sclayout.addWidget(editBz, 8,3, 1,1)
xtallayout.addWidget(editBMat, 9,0, 2,4)
Tobias WEBER's avatar
Tobias WEBER committed
191
192
193
194
195
196
197
198
199
200
201

tabs.addTab(xtalpanel, "Crystal")
# -----------------------------------------------------------------------------



# -----------------------------------------------------------------------------
# tas tab

taspanel = qtw.QWidget()
taslayout = qtw.QGridLayout(taspanel)
Tobias WEBER's avatar
Tobias WEBER committed
202
203
Qpanel = taspanel
Qlayout = taslayout
Tobias WEBER's avatar
Tobias WEBER committed
204
205
206
207
208
209
210

editA1 = qtw.QLineEdit(taspanel)
editA2 = qtw.QLineEdit(taspanel)
editA3 = qtw.QLineEdit(taspanel)
editA4 = qtw.QLineEdit(taspanel)
editA5 = qtw.QLineEdit(taspanel)
editA6 = qtw.QLineEdit(taspanel)
Tobias WEBER's avatar
Tobias WEBER committed
211

Tobias WEBER's avatar
Tobias WEBER committed
212
213
214
editDm = qtw.QLineEdit(taspanel)
editDa = qtw.QLineEdit(taspanel)

Tobias WEBER's avatar
Tobias WEBER committed
215
216
217
218
219
220
edith = qtw.QLineEdit(Qpanel)
editk = qtw.QLineEdit(Qpanel)
editl = qtw.QLineEdit(Qpanel)
editE = qtw.QLineEdit(Qpanel)
editKi = qtw.QLineEdit(Qpanel)
editKf = qtw.QLineEdit(Qpanel)
Tobias WEBER's avatar
Tobias WEBER committed
221
222
editQAbs = qtw.QLineEdit(Qpanel)
editQAbs.setReadOnly(True)
Tobias WEBER's avatar
Tobias WEBER committed
223

Tobias WEBER's avatar
Tobias WEBER committed
224
225
tasstatus = qtw.QLabel(taspanel)

Tobias WEBER's avatar
Tobias WEBER committed
226
227
separatorTas = qtw.QFrame(Qpanel)
separatorTas.setFrameStyle(qtw.QFrame.HLine)
Tobias WEBER's avatar
Tobias WEBER committed
228
229
separatorTas2 = qtw.QFrame(Qpanel)
separatorTas2.setFrameStyle(qtw.QFrame.HLine)
Tobias WEBER's avatar
Tobias WEBER committed
230

Tobias WEBER's avatar
Tobias WEBER committed
231
232

def TASChanged():
Tobias WEBER's avatar
Tobias WEBER committed
233
234
	global orient_rlu, orient_up_rlu

Tobias WEBER's avatar
Tobias WEBER committed
235
236
237
238
239
240
241
242
243
244
245
246
	a1 = getfloat(editA1.text()) / 180. * np.pi
	a2 = a1 * 2.
	a3 = getfloat(editA3.text()) / 180. * np.pi
	a4 = getfloat(editA4.text()) / 180. * np.pi
	a5 = getfloat(editA5.text()) / 180. * np.pi
	a6 = a5 * 2.
	dmono = getfloat(editDm.text())
	dana = getfloat(editDa.text())

	editA2.setText("%.6g" % (a2 / np.pi * 180.))
	editA6.setText("%.6g" % (a6 / np.pi * 180.))

Tobias WEBER's avatar
Tobias WEBER committed
247
248
249
250
251
252
253
254
255
256
257
258
259
260
	try:
		ki = tas.get_monok(a1, dmono)
		kf = tas.get_monok(a5, dana)
		E = tas.get_E(ki, kf)
		Qlen = tas.get_Q(ki, kf, a4)
		Qvec = tas.get_hkl(ki, kf, a3, Qlen, orient_rlu, orient_up_rlu, B)

		edith.setText("%.6g" % Qvec[0])
		editk.setText("%.6g" % Qvec[1])
		editl.setText("%.6g" % Qvec[2])
		editQAbs.setText("%.6g" % Qlen)
		editKi.setText("%.6g" % ki)
		editKf.setText("%.6g" % kf)
		editE.setText("%.6g" % E)
Tobias WEBER's avatar
Tobias WEBER committed
261
	except (ArithmeticError, la.LinAlgError) as err:
Tobias WEBER's avatar
Tobias WEBER committed
262
263
264
265
266
267
		edith.setText("invalid")
		editk.setText("invalid")
		editl.setText("invalid")
		editKi.setText("invalid")
		editKf.setText("invalid")
		editE.setText("invalid")
Tobias WEBER's avatar
Tobias WEBER committed
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283


def A2Changed():
	a2 = getfloat(editA2.text()) / 180. * np.pi
	editA1.setText("%.6g" % (0.5*a2 / np.pi * 180.))
	TASChanged()

def A6Changed():
	a6 = getfloat(editA6.text()) / 180. * np.pi
	editA5.setText("%.6g" % (0.5*a6 / np.pi * 180.))
	TASChanged()

def DChanged():
	QChanged()

def QChanged():
Tobias WEBER's avatar
Tobias WEBER committed
284
	global orient_rlu, orient_up_rlu
Tobias WEBER's avatar
Tobias WEBER committed
285
286
287
288
289

	Q_rlu = np.array([getfloat(edith.text()), getfloat(editk.text()), getfloat(editl.text())])
	ki = getfloat(editKi.text())
	kf = getfloat(editKf.text())

Tobias WEBER's avatar
Tobias WEBER committed
290
291
	try:
		[a1, a2] = tas.get_a1a2(ki, getfloat(editDm.text()))
Tobias WEBER's avatar
Tobias WEBER committed
292

Tobias WEBER's avatar
Tobias WEBER committed
293
294
		editA1.setText("%.6g" % (a1 / np.pi * 180.))
		editA2.setText("%.6g" % (a2 / np.pi * 180.))
Tobias WEBER's avatar
Tobias WEBER committed
295
	except (ArithmeticError, la.LinAlgError) as err:
Tobias WEBER's avatar
Tobias WEBER committed
296
297
298
299
300
301
302
303
		editA1.setText("invalid")
		editA2.setText("invalid")

	try:
		[a5, a6] = tas.get_a1a2(kf, getfloat(editDa.text()))

		editA5.setText("%.6g" % (a5 / np.pi * 180.))
		editA6.setText("%.6g" % (a6 / np.pi * 180.))
Tobias WEBER's avatar
Tobias WEBER committed
304
	except (ArithmeticError, la.LinAlgError) as err:
Tobias WEBER's avatar
Tobias WEBER committed
305
306
307
308
		editA5.setText("invalid")
		editA6.setText("invalid")

	try:
Tobias WEBER's avatar
Tobias WEBER committed
309
		[a3, a4, dist_Q_plane] = tas.get_a3a4(ki, kf, Q_rlu, orient_rlu, orient_up_rlu, B)
Tobias WEBER's avatar
Tobias WEBER committed
310
		Qlen = tas.get_Q(ki, kf, a4)
Tobias WEBER's avatar
Tobias WEBER committed
311
		Q_in_plane = np.abs(dist_Q_plane) < 1e-4
Tobias WEBER's avatar
Tobias WEBER committed
312
313
314
315

		editA3.setText("%.6g" % (a3 / np.pi * 180.))
		editA4.setText("%.6g" % (a4 / np.pi * 180.))
		editQAbs.setText("%.6g" % Qlen)
Tobias WEBER's avatar
Tobias WEBER committed
316
317
318
319
		if Q_in_plane:
			tasstatus.setText("")
		else:
			tasstatus.setText(u"WARNING: Q is out of the plane by %.4g / \u212b!" % dist_Q_plane)
Tobias WEBER's avatar
Tobias WEBER committed
320
	except (ArithmeticError, la.LinAlgError) as err:
Tobias WEBER's avatar
Tobias WEBER committed
321
322
		editA3.setText("invalid")
		editA4.setText("invalid")
Tobias WEBER's avatar
Tobias WEBER committed
323

Tobias WEBER's avatar
Tobias WEBER committed
324
325
326
327
def KiKfChanged():
	ki = getfloat(editKi.text())
	kf = getfloat(editKf.text())

Tobias WEBER's avatar
Tobias WEBER committed
328
329
330
	try:
		E = tas.get_E(ki, kf)
		editE.setText("%.6g" % E)
Tobias WEBER's avatar
Tobias WEBER committed
331
332
333

		QChanged()
	except (ArithmeticError, la.LinAlgError) as err:
Tobias WEBER's avatar
Tobias WEBER committed
334
		editE.setText("invalid")
Tobias WEBER's avatar
Tobias WEBER committed
335
336
337
338

def EChanged():
	E = getfloat(editE.text())
	kf = getfloat(editKf.text())
Tobias WEBER's avatar
Tobias WEBER committed
339
340
341
342

	try:
		ki = tas.get_ki(kf, E)
		editKi.setText("%.6g" % ki)
Tobias WEBER's avatar
Tobias WEBER committed
343
344
345

		QChanged()
	except (ArithmeticError, la.LinAlgError) as err:
Tobias WEBER's avatar
Tobias WEBER committed
346
		editKi.setText("invalid")
Tobias WEBER's avatar
Tobias WEBER committed
347

Tobias WEBER's avatar
Tobias WEBER committed
348
349
350
351
352
353
354
355
356

editA1.textEdited.connect(TASChanged)
editA3.textEdited.connect(TASChanged)
editA4.textEdited.connect(TASChanged)
editA5.textEdited.connect(TASChanged)
editA2.textEdited.connect(A2Changed)
editA6.textEdited.connect(A6Changed)
editDm.textEdited.connect(DChanged)
editDa.textEdited.connect(DChanged)
Tobias WEBER's avatar
Tobias WEBER committed
357
358
359
edith.textEdited.connect(QChanged)
editk.textEdited.connect(QChanged)
editl.textEdited.connect(QChanged)
Tobias WEBER's avatar
Tobias WEBER committed
360
361
editKi.textEdited.connect(KiKfChanged)
editKf.textEdited.connect(KiKfChanged)
Tobias WEBER's avatar
Tobias WEBER committed
362
363
364
editE.textEdited.connect(EChanged)


Tobias WEBER's avatar
Tobias WEBER committed
365
366
367
368
369
370
371
372
editDm.setText("%.6g" % sett.value("qtas/dm", 3.355, type=float))
editDa.setText("%.6g" % sett.value("qtas/da", 3.355, type=float))
edith.setText("%.6g" % sett.value("qtas/h", 1., type=float))
editk.setText("%.6g" % sett.value("qtas/k", 0., type=float))
editl.setText("%.6g" % sett.value("qtas/l", 0., type=float))
#editE.setText("%.6g" % sett.value("qtas/E", 0., type=float))
editKi.setText("%.6g" % sett.value("qtas/ki", 2.662, type=float))
editKf.setText("%.6g" % sett.value("qtas/kf", 2.662, type=float))
Tobias WEBER's avatar
Tobias WEBER committed
373
374

Qlayout.addWidget(qtw.QLabel("h (rlu):", Qpanel), 0,0, 1,1)
Tobias WEBER's avatar
Tobias WEBER committed
375
Qlayout.addWidget(edith, 0,1, 1,2)
Tobias WEBER's avatar
Tobias WEBER committed
376
Qlayout.addWidget(qtw.QLabel("k (rlu):", Qpanel), 1,0, 1,1)
Tobias WEBER's avatar
Tobias WEBER committed
377
Qlayout.addWidget(editk, 1,1, 1,2)
Tobias WEBER's avatar
Tobias WEBER committed
378
Qlayout.addWidget(qtw.QLabel("l (rlu):", Qpanel), 2,0, 1,1)
Tobias WEBER's avatar
Tobias WEBER committed
379
Qlayout.addWidget(editl, 2,1, 1,2)
Tobias WEBER's avatar
Tobias WEBER committed
380
Qlayout.addWidget(qtw.QLabel("E (meV):", Qpanel), 3,0, 1,1)
Tobias WEBER's avatar
Tobias WEBER committed
381
Qlayout.addWidget(editE, 3,1, 1,2)
Tobias WEBER's avatar
Tobias WEBER committed
382
Qlayout.addWidget(qtw.QLabel(u"ki, kf (1/\u212b):", Qpanel), 4,0, 1,1)
Tobias WEBER's avatar
Tobias WEBER committed
383
Qlayout.addWidget(editKi, 4,1, 1,1)
Tobias WEBER's avatar
Tobias WEBER committed
384
Qlayout.addWidget(editKf, 4,2, 1,1)
Tobias WEBER's avatar
Tobias WEBER committed
385
386
387
388
389
390
391
392
393
394
395
396
Qlayout.addWidget(qtw.QLabel(u"|Q| (1/\u212b):", Qpanel), 5,0, 1,1)
Qlayout.addWidget(editQAbs, 5,1, 1,2)
Qlayout.addWidget(separatorTas, 6,0,1,3)
taslayout.addWidget(qtw.QLabel("a1, a2 (deg):", taspanel), 7,0, 1,1)
taslayout.addWidget(editA1, 7,1, 1,1)
taslayout.addWidget(editA2, 7,2, 1,1)
taslayout.addWidget(qtw.QLabel("a3, a4 (deg):", taspanel), 8,0, 1,1)
taslayout.addWidget(editA3, 8,1, 1,1)
taslayout.addWidget(editA4, 8,2, 1,1)
taslayout.addWidget(qtw.QLabel("a5, a6 (deg):", taspanel), 9,0, 1,1)
taslayout.addWidget(editA5, 9,1, 1,1)
taslayout.addWidget(editA6, 9,2, 1,1)
Tobias WEBER's avatar
Tobias WEBER committed
397
398
399
400
401
402
taslayout.addWidget(separatorTas2, 10,0, 1,3)
taslayout.addWidget(qtw.QLabel("Mono., Ana. d (A):", taspanel), 11,0, 1,1)
taslayout.addWidget(editDm, 11,1, 1,1)
taslayout.addWidget(editDa, 11,2, 1,1)
taslayout.addItem(qtw.QSpacerItem(16,16, qtw.QSizePolicy.Minimum, qtw.QSizePolicy.Expanding), 12,0, 1,3)
taslayout.addWidget(tasstatus, 13,0, 1,3)
Tobias WEBER's avatar
Tobias WEBER committed
403

Tobias WEBER's avatar
Tobias WEBER committed
404
tabs.addTab(taspanel, "TAS")
Tobias WEBER's avatar
Tobias WEBER committed
405
406
407
408
# -----------------------------------------------------------------------------



Tobias WEBER's avatar
Tobias WEBER committed
409
410
411
412
413
414
415
416
# -----------------------------------------------------------------------------
# info/settings tab
infopanel = qtw.QWidget()
infolayout = qtw.QGridLayout(infopanel)

comboA3 = qtw.QComboBox(infopanel)
comboA3.addItems(["Takin", "NOMAD", "SICS", "NICOS"])
a3_offs = [np.pi/2., np.pi, 0., 0.]
Tobias WEBER's avatar
Tobias WEBER committed
417
comboA3.setCurrentIndex(sett.value("qtas/a3_conv", 1, type=int))
Tobias WEBER's avatar
Tobias WEBER committed
418
419
420
421
422
423
424
425
426

def comboA3ConvChanged():
	idx = comboA3.currentIndex()
	tas.set_a3_offs(a3_offs[idx])
	QChanged()

comboA3.currentIndexChanged.connect(comboA3ConvChanged)


Tobias WEBER's avatar
Tobias WEBER committed
427
428
429
430
separatorInfo = qtw.QFrame(infopanel)
separatorInfo.setFrameStyle(qtw.QFrame.HLine)


Tobias WEBER's avatar
Tobias WEBER committed
431
432
433
infolayout.addWidget(qtw.QLabel("TAS Calculator.", infopanel), 0,0, 1,2)
infolayout.addWidget(qtw.QLabel("Written by Tobias Weber <tweber@ill.fr>.", infopanel), 1,0, 1,2)
infolayout.addWidget(qtw.QLabel("Date: October 24, 2018.", infopanel), 2,0, 1,2)
Tobias WEBER's avatar
Tobias WEBER committed
434
435
436
437
438
439
440
infolayout.addWidget(separatorInfo, 3,0, 1,2)
infolayout.addWidget(qtw.QLabel("Interpreter Version: " + sys.version + ".", infopanel), 4,0, 1,2)
infolayout.addWidget(qtw.QLabel("Numpy Version: " + np.__version__ + ".", infopanel), 5,0, 1,2)
infolayout.addWidget(qtw.QLabel("Qt Version: " + qtc.QT_VERSION_STR + ".", infopanel), 6,0, 1,2)
infolayout.addItem(qtw.QSpacerItem(16,16, qtw.QSizePolicy.Minimum, qtw.QSizePolicy.Expanding), 7,0, 1,2)
infolayout.addWidget(qtw.QLabel("A3 Convention:", infopanel), 8,0, 1,1)
infolayout.addWidget(comboA3, 8,1, 1,1)
Tobias WEBER's avatar
Tobias WEBER committed
441
442
443
444
445

tabs.addTab(infopanel, "Infos")
# -----------------------------------------------------------------------------


Tobias WEBER's avatar
Tobias WEBER committed
446
447
448
449
450
451
452
453
454

# -----------------------------------------------------------------------------
# main dialog window

dlg = qtw.QDialog()
dlg.setWindowTitle("TAS Calculator")
mainlayout = qtw.QGridLayout(dlg)
mainlayout.addWidget(tabs)

Tobias WEBER's avatar
Tobias WEBER committed
455
456
if sett.contains("qtas/geo"):
	geo = sett.value("qtas/geo")
Tobias WEBER's avatar
Tobias WEBER committed
457
458
459
	if qt_ver == 4:
		geo = geo.toByteArray()
	dlg.restoreGeometry(geo)
Tobias WEBER's avatar
Tobias WEBER committed
460

Tobias WEBER's avatar
Tobias WEBER committed
461
xtalChanged()
Tobias WEBER's avatar
Tobias WEBER committed
462
KiKfChanged()
Tobias WEBER's avatar
Tobias WEBER committed
463
464
comboA3ConvChanged()
#QChanged()
Tobias WEBER's avatar
Tobias WEBER committed
465

Tobias WEBER's avatar
Tobias WEBER committed
466
dlg.show()
Tobias WEBER's avatar
Tobias WEBER committed
467
468
469
470
app.exec_()


# save settings
Tobias WEBER's avatar
Tobias WEBER committed
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
sett.setValue("qtas/a", getfloat(editA.text()))
sett.setValue("qtas/b", getfloat(editB.text()))
sett.setValue("qtas/c", getfloat(editC.text()))
sett.setValue("qtas/alpha", getfloat(editAlpha.text()))
sett.setValue("qtas/beta", getfloat(editBeta.text()))
sett.setValue("qtas/gamma", getfloat(editGamma.text()))
sett.setValue("qtas/ax", getfloat(editAx.text()))
sett.setValue("qtas/ay", getfloat(editAy.text()))
sett.setValue("qtas/az", getfloat(editAz.text()))
sett.setValue("qtas/bx", getfloat(editBx.text()))
sett.setValue("qtas/by", getfloat(editBy.text()))
sett.setValue("qtas/bz", getfloat(editBz.text()))
sett.setValue("qtas/dm", getfloat(editDm.text()))
sett.setValue("qtas/da", getfloat(editDa.text()))
sett.setValue("qtas/h", getfloat(edith.text()))
sett.setValue("qtas/k", getfloat(editk.text()))
sett.setValue("qtas/l", getfloat(editl.text()))
#sett.setValue("qtas/E", getfloat(editE.text()))
sett.setValue("qtas/ki", getfloat(editKi.text()))
sett.setValue("qtas/kf", getfloat(editKf.text()))
sett.setValue("qtas/a3_conv", comboA3.currentIndex())
sett.setValue("qtas/geo", dlg.saveGeometry())
Tobias WEBER's avatar
Tobias WEBER committed
493
# -----------------------------------------------------------------------------