orGUI 1.0.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (83) hide show
  1. orGUI-1.0.1.dist-info/LICENSE +21 -0
  2. orGUI-1.0.1.dist-info/METADATA +147 -0
  3. orGUI-1.0.1.dist-info/RECORD +83 -0
  4. orGUI-1.0.1.dist-info/WHEEL +5 -0
  5. orGUI-1.0.1.dist-info/entry_points.txt +2 -0
  6. orGUI-1.0.1.dist-info/top_level.txt +1 -0
  7. orgui/__init__.py +36 -0
  8. orgui/app/ArrayTableDialog.py +433 -0
  9. orgui/app/QReflectionSelector.py +538 -0
  10. orgui/app/QScanSelector.py +692 -0
  11. orgui/app/QUBCalculator.py +1210 -0
  12. orgui/app/__init__.py +36 -0
  13. orgui/app/database.py +487 -0
  14. orgui/app/orGUI.py +2613 -0
  15. orgui/app/qutils.py +51 -0
  16. orgui/backend/__init__.py +32 -0
  17. orgui/backend/backends.py +157 -0
  18. orgui/backend/beamline/ID31DiffractLinTilt.py +77 -0
  19. orgui/backend/beamline/P212_tools.py +577 -0
  20. orgui/backend/beamline/__init__.py +36 -0
  21. orgui/backend/beamline/fio_reader.py +110 -0
  22. orgui/backend/beamline/id31_tools.py +651 -0
  23. orgui/backend/scans.py +95 -0
  24. orgui/backend/udefaults.py +163 -0
  25. orgui/backend/universalScanLoader.py +105 -0
  26. orgui/datautils/__init__.py +32 -0
  27. orgui/datautils/util.py +705 -0
  28. orgui/datautils/xrayutils/CTRcalc.py +3022 -0
  29. orgui/datautils/xrayutils/CTRopt.py +623 -0
  30. orgui/datautils/xrayutils/CTRplotutil.py +904 -0
  31. orgui/datautils/xrayutils/DetectorCalibration.py +685 -0
  32. orgui/datautils/xrayutils/HKLVlieg.py +1360 -0
  33. orgui/datautils/xrayutils/ReciprocalNavigation.py +401 -0
  34. orgui/datautils/xrayutils/_CTRcalc_accel.py +181 -0
  35. orgui/datautils/xrayutils/__init__.py +46 -0
  36. orgui/datautils/xrayutils/element_data.py +213 -0
  37. orgui/datautils/xrayutils/test/__init__.py +57 -0
  38. orgui/datautils/xrayutils/test/test_CTRcalc.py +152 -0
  39. orgui/datautils/xrayutils/test/test_DetectorCalibration.py +336 -0
  40. orgui/datautils/xrayutils/test/test_HKLcalc.py +88 -0
  41. orgui/datautils/xrayutils/unitcells/Fe3O4(100).bul +59 -0
  42. orgui/datautils/xrayutils/unitcells/Pt100.bul +7 -0
  43. orgui/datautils/xrayutils/unitcells/Pt100_small.bul +5 -0
  44. orgui/datautils/xrayutils/unitcells/Pt110.bul +5 -0
  45. orgui/datautils/xrayutils/unitcells/Pt111.bul +6 -0
  46. orgui/datautils/xrayutils/unitcells/Pt310.bul +13 -0
  47. orgui/datautils/xrayutils/unitcells/Pt3O4(100).bul +19 -0
  48. orgui/datautils/xrayutils/unitcells/PtO(001).bul +9 -0
  49. orgui/datautils/xrayutils/unitcells/PtO(010).bul +9 -0
  50. orgui/datautils/xrayutils/unitcells/PtO(100).bul +9 -0
  51. orgui/datautils/xrayutils/unitcells/__init__.py +67 -0
  52. orgui/datautils/xrayutils/unitcells/a-PtO2(0001).bul +6 -0
  53. orgui/main.py +101 -0
  54. orgui/resources/__init__.py +40 -0
  55. orgui/resources/icons/alpha.png +0 -0
  56. orgui/resources/icons/alpha.svg +67 -0
  57. orgui/resources/icons/diffractometer_v3.png +0 -0
  58. orgui/resources/icons/disable-image.png +0 -0
  59. orgui/resources/icons/disable-image.svg +68 -0
  60. orgui/resources/icons/document-nx-open.png +0 -0
  61. orgui/resources/icons/document-nx-open.svg +152 -0
  62. orgui/resources/icons/document-nx-save.png +0 -0
  63. orgui/resources/icons/document-nx-save.svg +73 -0
  64. orgui/resources/icons/logo.png +0 -0
  65. orgui/resources/icons/logo.svg +808 -0
  66. orgui/resources/icons/max_image.png +0 -0
  67. orgui/resources/icons/max_image.svg +77 -0
  68. orgui/resources/icons/max_image2.png +0 -0
  69. orgui/resources/icons/max_image2.svg +83 -0
  70. orgui/resources/icons/search-image.png +0 -0
  71. orgui/resources/icons/search-image.svg +94 -0
  72. orgui/resources/icons/search-reflection.png +0 -0
  73. orgui/resources/icons/search-reflection.svg +126 -0
  74. orgui/resources/icons/search.png +0 -0
  75. orgui/resources/icons/search.svg +91 -0
  76. orgui/resources/icons/select-image.png +0 -0
  77. orgui/resources/icons/select-image.svg +60 -0
  78. orgui/resources/icons/set-reflection.png +0 -0
  79. orgui/resources/icons/set-reflection.svg +91 -0
  80. orgui/resources/icons/sum_image.png +0 -0
  81. orgui/resources/icons/sum_image.svg +63 -0
  82. orgui/resources/icons/sum_image2.png +0 -0
  83. orgui/resources/icons/sum_image2.svg +75 -0
@@ -0,0 +1,401 @@
1
+ # -*- coding: utf-8 -*-
2
+ # /*##########################################################################
3
+ #
4
+ # Copyright (c) 2020-2024 Timo Fuchs
5
+ #
6
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ # of this software and associated documentation files (the "Software"), to deal
8
+ # in the Software without restriction, including without limitation the rights
9
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ # copies of the Software, and to permit persons to whom the Software is
11
+ # furnished to do so, subject to the following conditions:
12
+ #
13
+ # The above copyright notice and this permission notice shall be included in
14
+ # all copies or substantial portions of the Software.
15
+ #
16
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22
+ # THE SOFTWARE.
23
+ #
24
+ # ###########################################################################*/
25
+ __author__ = "Timo Fuchs"
26
+ __copyright__ = "Copyright 2020-2024 Timo Fuchs"
27
+ __license__ = "MIT License"
28
+ __version__ = "1.0.0"
29
+ __maintainer__ = "Timo Fuchs"
30
+ __email__ = "fuchs@physik.uni-kiel.de"
31
+
32
+ from . import CTRcalc, HKLVlieg, DetectorCalibration
33
+ import numpy as np
34
+
35
+ import numpy.linalg as LA
36
+ from typing import Union
37
+
38
+
39
+ def allowedReflections(xtal: Union[CTRcalc.SXRDCrystal,CTRcalc.UnitCell],order: int = 5,**keyargs):
40
+ """
41
+ returns Bragg-reflections of the unit cell or SXRDCrystal
42
+ brute force algorithm... has the advantage that it always works ;)
43
+
44
+ params:
45
+ xtal: CTRcalc.UnitCell or CTRcalc.SXRDCrystal
46
+
47
+ order: calculate list of reflections up
48
+ to max{ h, k, l} = order - 1 (default: 5)
49
+ (i.e. maximum order**3 reflections)
50
+
51
+ keyargs:
52
+
53
+ negative: bool take negative values of h k l into account (default: False)
54
+
55
+ returnF : bool returns structure factor of the unit cell at the Bragg-reflection
56
+
57
+ hklrange : (h,k,l) : tuple with arrays with the values of h,k,l to compute
58
+
59
+ returns:
60
+ ndarray shape (n,3) with all n valid reflections
61
+ sorted via absolute value of momentum transfer
62
+
63
+ if returnF: tuple of hkls, (F, Q)
64
+ F: structure factor (complex)
65
+ Q: momentum transfer (in inverse Angstroms)
66
+
67
+ """
68
+ if 'hklrange' in keyargs:
69
+ h,k,l = keyargs['hklrange']
70
+ hkls = np.array(np.meshgrid(h,k,l)).T.reshape(-1,3)
71
+ else:
72
+ if 'negative' in keyargs and keyargs['negative']:
73
+ miller= np.arange(-order+1,order)
74
+ else:
75
+ miller= np.arange(order)
76
+ hkls = np.array(np.meshgrid(miller,miller,miller)).T.reshape(-1,3)
77
+
78
+
79
+ if isinstance(xtal,CTRcalc.SXRDCrystal):
80
+ F = xtal.uc_bulk.F_uc(*hkls.T)
81
+ G = LA.norm(xtal.uc_bulk.reciprocalVectorCart(hkls).T,axis=1)
82
+ else:
83
+ F = xtal.F_uc(*hkls.T)
84
+ G = LA.norm(xtal.reciprocalVectorCart(hkls).T,axis=1)
85
+
86
+ indices_valid = np.abs(F) > 1e-3
87
+
88
+ hkls = hkls[indices_valid]
89
+ F = F[indices_valid]
90
+ G = G[indices_valid]
91
+
92
+ sortarg = np.argsort(G)
93
+ if 'returnF' in keyargs and keyargs['returnF']:
94
+ return hkls[sortarg], (F[sortarg],G[sortarg])
95
+ else:
96
+ return hkls[sortarg]
97
+
98
+
99
+ def allowedReflections_G(xtal: Union[CTRcalc.SXRDCrystal,CTRcalc.UnitCell],maxQ: float = 12.0,**keyargs):
100
+ if isinstance(xtal,CTRcalc.SXRDCrystal):
101
+ b = xtal.uc_bulk.b
102
+ #_,_,b,_ = xtal.uc_bulk.getLatticeParameters()
103
+ else:
104
+ #_,_,b,_ = xtal.getLatticeParameters()
105
+ b = xtal.b
106
+ hklmax = np.floor(maxQ/b).astype(np.int64)
107
+ if 'negative' in keyargs and keyargs['negative']:
108
+ h = np.arange(-hklmax[0]+1,hklmax[0])
109
+ k = np.arange(-hklmax[1]+1,hklmax[1])
110
+ l = np.arange(-hklmax[2]+1,hklmax[2])
111
+ else:
112
+ h = np.arange(hklmax[0])
113
+ k = np.arange(hklmax[1])
114
+ l = np.arange(hklmax[2])
115
+
116
+ keyargs['hklrange'] = (h,k,l)
117
+
118
+ if 'returnF' in keyargs:
119
+ returnF = keyargs['returnF']
120
+ else:
121
+ returnF = False
122
+
123
+ keyargs['returnF'] = True
124
+ hkls, (F,G) = allowedReflections(xtal, 1, **keyargs)
125
+ if not keyargs.get('singleAxis',False):
126
+ Qinrange = G < maxQ
127
+ hkls = hkls[Qinrange]
128
+ F = F[Qinrange]
129
+ G = G[Qinrange]
130
+ if returnF:
131
+ return hkls, (F,G)
132
+ else:
133
+ return hkls
134
+
135
+
136
+
137
+
138
+ def allowedCTRs(xtal: Union[CTRcalc.SXRDCrystal,CTRcalc.UnitCell],order: int = 5,**keyargs):
139
+ if 'returnF' in keyargs and keyargs['returnF']:
140
+ hkls, (F,G) = allowedReflections(xtal, order, **keyargs)
141
+ hk, indx = np.unique(hkls[:,:2],axis=0,return_index=True)
142
+ F = F[indx]
143
+ G = G[indx]
144
+ return hk, (F,G)
145
+ else:
146
+ return np.unique(allowedReflections(xtal,order, **keyargs)[:,:2],axis=0)
147
+
148
+ def allowedCTRs_G(xtal: Union[CTRcalc.SXRDCrystal,CTRcalc.UnitCell],maxQ: float = 12.0,**keyargs):
149
+ keyargs['singleAxis'] = True
150
+ if 'returnF' in keyargs and keyargs['returnF']:
151
+ hkls, (F,G) = allowedReflections_G(xtal, maxQ, **keyargs)
152
+ hk, indx = np.unique(hkls[:,:2],axis=0,return_index=True)
153
+ hkls = hkls[indx]
154
+ F = F[indx]
155
+ hkls[:,2] = 0.
156
+ if isinstance(xtal,CTRcalc.SXRDCrystal):
157
+ G = LA.norm(xtal.uc_bulk.reciprocalVectorCart(hkls).T,axis=1)
158
+ else:
159
+ G = LA.norm(xtal.reciprocalVectorCart(hkls).T,axis=1)
160
+
161
+ Qinrange = G < maxQ
162
+ hk = hk[Qinrange]
163
+ F = F[Qinrange]
164
+ G = G[Qinrange]
165
+ return hk, (F,G)
166
+ else:
167
+ hkls = allowedReflections_G(xtal, maxQ, **keyargs)
168
+ hk, indx = np.unique(hkls[:,:2],axis=0,return_index=True)
169
+ hkls = hkls[indx]
170
+ hkls[:,2] = 0.
171
+ if isinstance(xtal,CTRcalc.SXRDCrystal):
172
+ G = LA.norm(xtal.uc_bulk.reciprocalVectorCart(hkls).T,axis=1)
173
+ else:
174
+ G = LA.norm(xtal.reciprocalVectorCart(hkls).T,axis=1)
175
+ Qinrange = G < maxQ
176
+ hk = hk[Qinrange]
177
+ return hk
178
+
179
+ # pos = [ALPHA, DELTA, GAMMA, OMEGA, CHI, PHI] (angles)
180
+ def thscanBragg(xtal: Union[CTRcalc.SXRDCrystal,CTRcalc.UnitCell],
181
+ ub : HKLVlieg.UBCalculator,
182
+ fixedangle : float,
183
+ sxrddetector : DetectorCalibration.Detector2D_SXRD,
184
+ omrange : tuple, **keyargs):
185
+ """
186
+ don't forget to set the correct azimuthal reference in Detector2D_SXRD!
187
+
188
+ Parameters
189
+ ----------
190
+ xtal : Union[CTRcalc.SXRDCrystal,CTRcalc.UnitCell]
191
+ DESCRIPTION.
192
+ ub : HKLVlieg.UBCalculator
193
+ DESCRIPTION.
194
+ fixedangle : float
195
+ in rad!!!
196
+ sxrddetector : DetectorCalibration.Detector2D_SXRD
197
+ DESCRIPTION.
198
+ omrange : tuple(float,float)
199
+ in rad!!!
200
+ **keyargs : TYPE
201
+ DESCRIPTION.
202
+
203
+ Returns
204
+ -------
205
+ None.
206
+
207
+ """
208
+ ommin, ommax = omrange[0], omrange[1]
209
+ chi = keyargs.get('chi',0.)
210
+ phi = keyargs.get('phi',0.)
211
+ fixed = keyargs.get('fixed','in')
212
+ if fixed != 'in':
213
+ raise NotImplementedError("Angle of incidence needed... Have to calculate this here in the future")
214
+ alpha = fixedangle
215
+ keyargs['ub'] = ub
216
+ keyargs['mirror'] = 'both'
217
+ keyargs['negative'] = True
218
+
219
+ Qmax = sxrddetector.Qmax # np.abs(sxrddetector.qArray()).max() / 10. # to Angstrom-1
220
+
221
+ hkls, angles = anglesAllowedReflections_G(xtal,None, alpha,Qmax,**keyargs)
222
+
223
+ ommask = np.logical_and(angles[:,3] > ommin , angles[:,3] < ommax)
224
+
225
+ #Lmask = hkls[:,2] > 0.1
226
+
227
+ #mask = np.logical_and(Lmask,ommask)
228
+
229
+ mask = ommask
230
+
231
+ hkls = hkls[mask]
232
+ angles = angles[mask]
233
+
234
+ delta = angles[:,1]
235
+ gamma = angles[:,2]
236
+
237
+ yx = sxrddetector.pixelsSurfaceAngles(gamma, delta, alpha)
238
+
239
+ ymask = np.logical_and(yx[:,0] >= 0, yx[:,0] < sxrddetector.detector.shape[0])
240
+ xmask = np.logical_and(yx[:,1] >= 0, yx[:,1] < sxrddetector.detector.shape[1])
241
+
242
+ mask = np.logical_and(xmask,ymask)
243
+
244
+ yx = yx[mask]
245
+ angles = angles[mask]
246
+ hkls = hkls[mask]
247
+
248
+ return hkls, yx, angles
249
+
250
+
251
+ def thscanCTRs(xtal: Union[CTRcalc.SXRDCrystal,CTRcalc.UnitCell],
252
+ ub : HKLVlieg.UBCalculator,
253
+ fixedangle : float,
254
+ sxrddetector : DetectorCalibration.Detector2D_SXRD,
255
+ omrange : tuple, **keyargs):
256
+ """
257
+
258
+ don't forget to set the correct azimuthal reference in Detector2D_SXRD!
259
+
260
+ Parameters
261
+ ----------
262
+ xtal : Union[CTRcalc.SXRDCrystal,CTRcalc.UnitCell]
263
+ DESCRIPTION.
264
+ ub : HKLVlieg.UBCalculator
265
+ DESCRIPTION.
266
+ fixedangle : float
267
+ in rad!!!
268
+ sxrddetector : DetectorCalibration.Detector2D_SXRD
269
+ DESCRIPTION.
270
+ omrange : tuple(float,float)
271
+ in rad!!!
272
+ **keyargs : TYPE
273
+ om : omega positions where pixel positions should be calculated
274
+ hk : calculate
275
+
276
+ Returns
277
+ -------
278
+ None.
279
+
280
+ """
281
+
282
+ chi = keyargs.pop('chi',0.)
283
+ phi = keyargs.pop('phi',0.)
284
+ fixed = keyargs.pop('fixed','in')
285
+ if fixed != 'in':
286
+ raise NotImplementedError("Angle of incidence needed... Have to calculate this here in the future")
287
+ alpha = fixedangle
288
+ gamma_range, delta_range = sxrddetector.rangegamdel(alpha)
289
+ gam_min, gam_max = gamma_range
290
+ del_min, del_max = delta_range
291
+ delabsmax = max(abs(del_min),abs(del_max))
292
+
293
+ Qmaxinplane = ((4*np.pi)/ub.getLambda())*np.sin(delabsmax)
294
+
295
+ possible_hk = allowedCTRs_G(xtal,Qmaxinplane,negative=True)
296
+ angle_calc = HKLVlieg.VliegAngles(ub)
297
+
298
+ found_hk = []
299
+ xmirror = []
300
+
301
+ degrange = np.rad2deg(np.abs(omrange[0] - omrange[1]))
302
+ testom = np.linspace(omrange[0],omrange[1],int(np.ceil(degrange)))
303
+
304
+ for hk in possible_hk:
305
+ (L1,gam1,delta1), (L2,gam2,delta2) = angle_calc.hkIntersect(hk,alpha,testom,phi,chi)
306
+ mask1 = ~np.isnan(L1)
307
+ mask2 = ~np.isnan(L2)
308
+ if np.all(~mask1) and np.all(~mask2):
309
+ continue
310
+
311
+ yx1 = sxrddetector.pixelsSurfaceAngles(gam1[mask1], delta1[mask1], alpha)
312
+ yx2 = sxrddetector.pixelsSurfaceAngles(gam2[mask2], delta2[mask2], alpha)
313
+
314
+ ymask1 = np.logical_and(yx1[:,0] >= 0, yx1[:,0] < sxrddetector.detector.shape[0])
315
+ xmask1 = np.logical_and(yx1[:,1] >= 0, yx1[:,1] < sxrddetector.detector.shape[1])
316
+ yxmask1 = np.logical_and(xmask1,ymask1)
317
+
318
+ ymask2 = np.logical_and(yx2[:,0] >= 0, yx2[:,0] < sxrddetector.detector.shape[0])
319
+ xmask2 = np.logical_and(yx2[:,1] >= 0, yx2[:,1] < sxrddetector.detector.shape[1])
320
+ yxmask2 = np.logical_and(xmask2,ymask2)
321
+
322
+ if np.any(yxmask1):
323
+ found_hk.append(hk)
324
+ xmirror.append(np.sum(delta1[mask1] < 0.) > delta1[mask1].size/2)
325
+
326
+ if np.any(yxmask2):
327
+ found_hk.append(hk)
328
+ xmirror.append(np.sum(delta2[mask2] < 0.) > delta2[mask2].size/2)
329
+
330
+ return found_hk, xmirror
331
+
332
+ # pos = [ALPHA, DELTA, GAMMA, OMEGA, CHI, PHI] (angles)
333
+
334
+ def anglesAllowedReflections(xtal,energy, fixedangle,order = 5,**keyargs):
335
+ if 'ub' in keyargs:
336
+ ub = keyargs['ub']
337
+ elif isinstance(xtal,CTRcalc.SXRDCrystal):
338
+ ub = HKLVlieg.UBCalculator(xtal.uc_bulk, energy)
339
+ ub.defaultU() # Grazing incidence, for TSD you could use either chi or phi = 90deg
340
+ else:
341
+ ub = HKLVlieg.UBCalculator(xtal, energy)
342
+ ub.defaultU() # Grazing incidence, for TSD you could use either chi or phi = 90deg
343
+
344
+
345
+ angle_calc = HKLVlieg.VliegAngles(ub)
346
+
347
+ hkls = allowedReflections(xtal,order,**keyargs)
348
+
349
+ chi = keyargs.pop('chi',0.)
350
+ phi = keyargs.pop('phi',0.)
351
+
352
+ fixed = keyargs.pop('fixed','in')
353
+
354
+ mirror = keyargs.pop('mirror',False)
355
+
356
+ if mirror == 'both':
357
+ rightangles = angle_calc.anglesZmode(hkls.T, fixedangle, fixed,chi,phi,mirrorx=False)
358
+ leftangles = angle_calc.anglesZmode(hkls.T, fixedangle, fixed,chi,phi,mirrorx=True)
359
+ hkls = np.hstack((hkls,hkls)).reshape((-1,3))
360
+ angles = np.hstack((rightangles,leftangles)).reshape((-1,6))
361
+ else:
362
+ angles = angle_calc.anglesZmode(hkls.T, fixedangle, fixed,chi,phi,mirrorx=mirror)
363
+
364
+ return hkls, angles
365
+
366
+
367
+ def anglesAllowedReflections_G(xtal,energy, fixedangle,maxQ: float = 12.0,**keyargs):
368
+ if 'ub' in keyargs:
369
+ ub = keyargs['ub']
370
+ elif isinstance(xtal,CTRcalc.SXRDCrystal):
371
+ ub = HKLVlieg.UBCalculator(xtal.uc_bulk, energy)
372
+ ub.defaultU() # Grazing incidence, for TSD you could use either chi or phi = 90deg
373
+ else:
374
+ ub = HKLVlieg.UBCalculator(xtal, energy)
375
+ ub.defaultU() # Grazing incidence, for TSD you could use either chi or phi = 90deg
376
+
377
+ angle_calc = HKLVlieg.VliegAngles(ub)
378
+
379
+ hkls = allowedReflections_G(xtal,maxQ,**keyargs)
380
+
381
+ chi = keyargs.pop('chi',0.)
382
+ phi = keyargs.pop('phi',0.)
383
+
384
+ fixed = keyargs.pop('fixed','in')
385
+
386
+ mirror = keyargs.pop('mirror',False)
387
+
388
+ if mirror == 'both':
389
+ rightangles = angle_calc.anglesZmode(hkls.T, fixedangle, fixed,chi,phi,mirrorx=False)
390
+ leftangles = angle_calc.anglesZmode(hkls.T, fixedangle, fixed,chi,phi,mirrorx=True)
391
+ hkls = np.hstack((hkls,hkls)).reshape((-1,3))
392
+ angles = np.hstack((rightangles,leftangles)).reshape((-1,6))
393
+ else:
394
+ angles = angle_calc.anglesZmode(hkls.T, fixedangle, fixed,chi,phi,mirrorx=mirror)
395
+
396
+ return hkls, angles
397
+
398
+
399
+
400
+
401
+
@@ -0,0 +1,181 @@
1
+ # -*- coding: utf-8 -*-
2
+ # /*##########################################################################
3
+ #
4
+ # Copyright (c) 2020-2024 Timo Fuchs
5
+ #
6
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ # of this software and associated documentation files (the "Software"), to deal
8
+ # in the Software without restriction, including without limitation the rights
9
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ # copies of the Software, and to permit persons to whom the Software is
11
+ # furnished to do so, subject to the following conditions:
12
+ #
13
+ # The above copyright notice and this permission notice shall be included in
14
+ # all copies or substantial portions of the Software.
15
+ #
16
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22
+ # THE SOFTWARE.
23
+ #
24
+ # ###########################################################################*/
25
+ __author__ = "Timo Fuchs"
26
+ __copyright__ = "Copyright 2020-2024 Timo Fuchs"
27
+ __license__ = "MIT License"
28
+ __version__ = "1.0.0"
29
+ __maintainer__ = "Timo Fuchs"
30
+ __email__ = "fuchs@physik.uni-kiel.de"
31
+
32
+
33
+ from numba import njit, prange
34
+
35
+ import numpy as np
36
+
37
+
38
+ # returns the structure factor of the unit cell
39
+ # h,k,l have to be 1d arrays
40
+
41
+ @njit('c16[:](f8[::1], f8[::1], f8[::1], f8, f8[:,::1], f8[:,::1], f8[:,::1], f8[:,::1], f8[:,::1], f8[:,::1], f8[:,:,::1], f8[::1] , f8)', nogil=True, cache=True)
42
+ def unitcell_F_uc_bulk(h,k,l,atten,
43
+ basis,
44
+ f_factors,
45
+ refHKLTransform,
46
+ B_mat,
47
+ R_mat,
48
+ R_mat_inv,
49
+ coherentDomainMatrix,
50
+ coherentDomainOccupancy,
51
+ volume
52
+ ):
53
+ F = np.zeros(h.size,dtype=np.complex128)
54
+ f = np.zeros(h.size,dtype=np.complex128)
55
+ hkl = refHKLTransform @ np.vstack((h,k,l))
56
+ Q_cart2 = (B_mat @ hkl)**2
57
+ Q_para2 = np.sum(Q_cart2[:2],axis=0) #squared!!!
58
+ Q_perp2 = Q_cart2[2] #squared!!!
59
+ Q2 = Q_para2 + Q_perp2 #squared!!!
60
+
61
+ domainmatrix = np.empty((coherentDomainMatrix.shape[0],3,3))
62
+ for i in range(coherentDomainMatrix.shape[0]):
63
+ domainmatrix[i] = R_mat_inv @ coherentDomainMatrix[i,:,:-1] @ R_mat
64
+
65
+ #domainmatrix = [R_mat_inv @ mat[:,:-1] @ R_mat for mat in coherentDomainMatrix]
66
+
67
+ for i in range(basis.shape[0]):
68
+ f[:] = f_factors[i][10] + f_factors[i][11] + 1j*f_factors[i][12]
69
+ for j in range(5):
70
+ f += f_factors[i][j]*np.exp(- f_factors[i][j+5]*Q2)
71
+ f *= np.exp(- (basis[i][4] * Q_para2 + basis[i][5] * Q_perp2)/ (16*np.pi**2))
72
+ f *= basis[i][6]
73
+ for mat, weight, eff_mat in zip(coherentDomainMatrix,coherentDomainOccupancy, domainmatrix):
74
+ xyz_rel = eff_mat @ basis[i][1:4] + mat[:,-1]
75
+ F += weight * f * np.exp(2j*np.pi * np.sum(hkl.T * xyz_rel,axis=1) ) * np.exp(atten*xyz_rel[2])
76
+ return F/volume
77
+
78
+ # returns the structure factor of the unit cell
79
+ # h,k,l have to be 1d arrays
80
+ @njit('c16[:](f8[::1], f8[::1], f8[::1], f8, f8[:,::1], f8[:,::1], f8[:,::1], f8[:,::1], f8[:,::1], f8[:,::1], f8[:,:,::1], f8[::1] , f8)', nogil=True, cache=True)
81
+ def unitcell_F_uc_bulk_direct(h,k,l,atten,
82
+ basis,
83
+ f_factors,
84
+ refHKLTransform,
85
+ B_mat,
86
+ R_mat,
87
+ R_mat_inv,
88
+ coherentDomainMatrix,
89
+ coherentDomainOccupancy,
90
+ volume
91
+ ):
92
+ F = np.zeros(h.size,dtype=np.complex128)
93
+ f = np.zeros(h.size,dtype=np.complex128)
94
+ hkl = np.vstack((h,k,l))
95
+ Q_cart2 = (B_mat @ hkl)**2
96
+ Q_para2 = np.sum(Q_cart2[:2],axis=0) #squared!!!
97
+ Q_perp2 = Q_cart2[2] #squared!!!
98
+ Q2 = Q_para2 + Q_perp2 #squared!!!
99
+
100
+ domainmatrix = np.empty((coherentDomainMatrix.shape[0],3,3))
101
+ for i in range(coherentDomainMatrix.shape[0]):
102
+ domainmatrix[i] = R_mat_inv @ coherentDomainMatrix[i,:,:-1] @ R_mat
103
+
104
+ #domainmatrix = [R_mat_inv @ mat[:,:-1] @ R_mat for mat in coherentDomainMatrix]
105
+
106
+ for i in range(basis.shape[0]):
107
+ f[:] = f_factors[i][10] + f_factors[i][11] + 1j*f_factors[i][12]
108
+ for j in range(5):
109
+ f += f_factors[i][j]*np.exp(- f_factors[i][j+5]*Q2)
110
+ f *= np.exp(- (basis[i][4] * Q_para2 + basis[i][5] * Q_perp2)/ (16*np.pi**2))
111
+ f *= basis[i][6]
112
+ for mat, weight, eff_mat in zip(coherentDomainMatrix,coherentDomainOccupancy, domainmatrix):
113
+ xyz_rel = eff_mat @ basis[i][1:4] + mat[:,-1]
114
+ F += weight * f * np.exp(2j*np.pi * np.sum(hkl.T * xyz_rel,axis=1) ) * np.exp(atten*xyz_rel[2])
115
+ return F/volume
116
+
117
+ @njit('c16[:](f8[::1], f8[::1], f8[::1], f8, f8[:,::1], f8[:,::1], f8[:,::1], f8[:,::1], f8[:,::1], f8[:,::1], f8[:,:,::1], f8[::1] , f8)', nogil=True, cache=True)
118
+ def unitcell_F_bulk(h,k,l,atten,
119
+ basis,
120
+ f_factors,
121
+ refHKLTransform,
122
+ B_mat,
123
+ R_mat,
124
+ R_mat_inv,
125
+ coherentDomainMatrix,
126
+ coherentDomainOccupancy,
127
+ volume
128
+ ):
129
+ hkl = refHKLTransform @ np.vstack((h,k,l))
130
+ Fuc = unitcell_F_uc_bulk_direct(hkl[0], hkl[1], hkl[2],atten,
131
+ basis,
132
+ f_factors,
133
+ refHKLTransform,
134
+ B_mat,
135
+ R_mat,
136
+ R_mat_inv,
137
+ coherentDomainMatrix,
138
+ coherentDomainOccupancy,
139
+ volume)
140
+ return Fuc/(1- np.exp(- 2j*np.pi * l - atten ))
141
+
142
+ @njit('c16[:](f8[::1], f8[::1], f8[::1], f8[:,::1], f8[:,::1], f8[:,::1], f8[:,::1], f8[:,::1], f8[:,::1], f8[:,:,::1], f8[::1] , f8)', nogil=True, cache=True)
143
+ def unitcell_F_uc(h,k,l,
144
+ basis,
145
+ f_factors,
146
+ refHKLTransform,
147
+ B_mat,
148
+ R_mat,
149
+ R_mat_inv,
150
+ coherentDomainMatrix,
151
+ coherentDomainOccupancy,
152
+ volume
153
+ ):
154
+ F = np.zeros(h.size,dtype=np.complex128)
155
+ f = np.zeros(h.size,dtype=np.complex128)
156
+ hkl = refHKLTransform @ np.vstack((h,k,l))
157
+ Q_cart2 = (B_mat @ hkl)**2
158
+ Q_para2 = np.sum(Q_cart2[:2],axis=0) #squared!!!
159
+ Q_perp2 = Q_cart2[2] #squared!!!
160
+ Q2 = Q_para2 + Q_perp2 #squared!!!
161
+
162
+ domainmatrix = np.empty((coherentDomainMatrix.shape[0],3,3))
163
+ for i in range(coherentDomainMatrix.shape[0]):
164
+ domainmatrix[i] = R_mat_inv @ coherentDomainMatrix[i,:,:-1] @ R_mat
165
+
166
+ #domainmatrix = [R_mat_inv @ mat[:,:-1] @ R_mat for mat in coherentDomainMatrix]
167
+
168
+ for i in range(basis.shape[0]):
169
+ f[:] = f_factors[i][10] + f_factors[i][11] + 1j*f_factors[i][12]
170
+ for j in range(5):
171
+ f += f_factors[i][j]*np.exp(- f_factors[i][j+5]*Q2)
172
+ f *= np.exp(- (basis[i][4] * Q_para2 + basis[i][5] * Q_perp2)/ (16*np.pi**2))
173
+ f *= basis[i][6]
174
+ for mat, weight, eff_mat in zip(coherentDomainMatrix,coherentDomainOccupancy, domainmatrix):
175
+ xyz_rel = eff_mat @ basis[i][1:4] + mat[:,-1]
176
+ F += weight * f * np.exp(2j*np.pi * np.sum(hkl.T * xyz_rel,axis=1) )
177
+ return F/volume
178
+
179
+
180
+
181
+
@@ -0,0 +1,46 @@
1
+ # -*- coding: utf-8 -*-
2
+ # /*##########################################################################
3
+ #
4
+ # Copyright (c) 2020-2024 Timo Fuchs
5
+ #
6
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ # of this software and associated documentation files (the "Software"), to deal
8
+ # in the Software without restriction, including without limitation the rights
9
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ # copies of the Software, and to permit persons to whom the Software is
11
+ # furnished to do so, subject to the following conditions:
12
+ #
13
+ # The above copyright notice and this permission notice shall be included in
14
+ # all copies or substantial portions of the Software.
15
+ #
16
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22
+ # THE SOFTWARE.
23
+ #
24
+ # ###########################################################################*/
25
+ __author__ = "Timo Fuchs"
26
+ __copyright__ = "Copyright 2020-2024 Timo Fuchs"
27
+ __license__ = "MIT License"
28
+ __version__ = "1.0.0"
29
+ __maintainer__ = "Timo Fuchs"
30
+ __email__ = "fuchs@physik.uni-kiel.de"
31
+
32
+ __all__ = ['CTRcalc','CTRplotutil', 'DetectorCalibration', 'HKLVlieg', 'id31_tools','P212_tools']
33
+
34
+ import importlib
35
+ from warnings import warn
36
+
37
+ deprecated_names = {"id31_tools_5" : "id31_tools"}
38
+ backend_names = ["id31_tools" , "P212_tools"]
39
+
40
+ def __getattr__(name):
41
+ if name in deprecated_names:
42
+ warn(f"{name} is deprecated and will be removed in the future", FutureWarning)
43
+ return importlib.import_module("...backend.beamline." + deprecated_names[name], __name__)
44
+ if name in backend_names:
45
+ return importlib.import_module("...backend.beamline." + name, __name__)
46
+ raise AttributeError(f"module {__name__} has no attribute {name}")