-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathsetup_reflections_mod.py
More file actions
189 lines (176 loc) · 6.87 KB
/
setup_reflections_mod.py
File metadata and controls
189 lines (176 loc) · 6.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
# -*- coding: utf-8 -*-
"""
Created on Thu Aug 8 15:13:47 2024
@author: Jacob Watkiss
"""
"""
-----------------------------------------------
Imports any necessary packages, libraries, modules etc.
-----------------------------------------------
"""
import numpy as np
import globalvariables as g
IErr=g.IErr
"""
-----------------------------------------------
Defines SelectionRules which checks if the
hkl values agree with expected crystal space groups
-----------------------------------------------
"""
def SelectionRules(SSpaceGroupName,Ih,Ik,Il,ISel):
"""F - Face Centred: All odd or all even"""
"""I - Body Centred"""
"""A - A-Face Centred"""
"""B - B-Face Centred"""
"""C - C-Face Centred"""
"""R - Rhombohedral Reverse"""
"""V - Rhombohedral Obverse"""
"""P - Primitive"""
if SSpaceGroupName=="F":
if (np.mod(Ih+Ik,2)==0) and (np.mod(Ik+Il,2)==0) and (np.mod(Il+Ih,2)==0):
ISel=1
elif SSpaceGroupName=="I":
if np.mod(Ih+Ik+Il,2)==0:
ISel=1
elif SSpaceGroupName=="A":
if np.mod(Ik+Il,2)==0:
ISel=1
elif SSpaceGroupName=="B":
if np.mod(Ih+Il,2)==0:
ISel=1
elif SSpaceGroupName=="C":
if np.mod(Ih+Ik,2)==0:
ISel=1
elif SSpaceGroupName=="R":
if np.mod(Ih-Ik+Il,3)==0:
ISel=1
elif SSpaceGroupName=="V":
if np.mod(-Ih+Ik+Il,3)==0:
ISel=1
elif SSpaceGroupName=="P":
ISel=1
else:
ISel=0
IErr=1
print("Error: SSpaceGroupName unrecognised")
return ISel
"""
-----------------------------------------------
Defines HKLMake which fills the list of reciprocal
space vectors Rhkl
-----------------------------------------------
"""
def HKLMake(RZDirC,RarVecM,RbrVecM,RcrVecM,
RInputHKLs,RElectronWaveVectorMagnitude,RgLimit,
SSpaceGroupName,
INhkl,INoOfLacbedPatterns,IMinStrongBeams):
"""A temporary function to write to"""
"""First g is always 0 0 0"""
RhklTemp=np.zeros((1,3),dtype="float")
"""
The upper limit for g-vector magnitudes
Perhaps the tolerance for proximity to
the Ewald sphere needs increasing
"""
"""The k-vector for the incident beam"""
"""We are working in the microscope
frame reference so k is along z"""
Rk=(0.0,0.0,RElectronWaveVectorMagnitude)
"""Get the size of the reciprocal lattice basis vectors"""
RarMag=np.sqrt(np.dot(RarVecM,RarVecM))
RbrMag=np.sqrt(np.dot(RbrVecM,RbrVecM))
RcrMag=np.sqrt(np.dot(RcrVecM,RcrVecM))
"""We work our way out from the origin in shells"""
"""The shell increment is the smallest basis vector"""
RShell=np.min((RarMag,RbrMag,RcrMag))
"""Number of reflections in the pool"""
reflNum=1
"""Number of the shell"""
shellNum=0
"""
Maximum a*,b*,c* limit is determined by
the G magnitude limit
"""
if RgLimit<10**-9:
RgLimit=20*np.pi
else:
"""Make INhkl large and RgLimit will be the cutoff"""
INhkl=66666
a=int(np.rint(RgLimit/RarMag))
b=int(np.rint(RgLimit/RbrMag))
c=int(np.rint(RgLimit/RcrMag))
aArray=np.arange(-a,a)
bArray=np.arange(-b,b)
cArray=np.arange(-c,c)
"""Fill the Rhkl with beams near the Bragg condition"""
while (reflNum<INhkl and shellNum*RShell<RgLimit):
shellNum=shellNum+1
"""Make a hkl"""
"""
This whole set of loops needs to be
changed into a far more efficient process.
At the time of writing, the current method
takes ~2.5 years to run on my laptop...
"""
for Ih in aArray:
print(Ih)
for Ik in bArray:
for Il in cArray:
ISel=0
"""Check that it's allowed by selection rules"""
ISel=SelectionRules(SSpaceGroupName,Ih,Ik,Il,ISel)
"""
Still need to check that we have space in Rhkl
because the while doesn't kick in until we finish
the for loops
"""
if (ISel==1) and (reflNum<INhkl):
"""Make a g-vector"""
"""Miller indices:"""
RGtest=np.array((Ih,Ik,Il),dtype="float")
"""In microscope frame"""
RGtestM=(Ih*RarVecM)+(Ik*RbrVecM)+(Il*RcrVecM)
RGtestMag=np.sqrt(np.dot(RGtestM,RGtestM))
"""Is it in the shell?"""
if (RGtestMag>(shellNum-1)*RShell):
if (RGtestMag<=shellNum*RShell):
"""Is it near a Laue condition |k+g|=|k|"""
RGplusk=RGtestM+Rk
"""Divide by |g| to get a measure of
incident beam tilt"""
RDev=np.abs(RElectronWaveVectorMagnitude-np.sqrt(np.dot(RGplusk,RGplusk)))/RGtestMag
"""
Tolerance of 0.08 here is rather
arbitrary --> might need revisiting
"""
if ((RDev-0.08)<10**-9):
print("Passed all checks")
print(reflNum)
"""
Add it to the pool and increment
the counter. Need to check that we
have space in Rhkl because the while
doesn't kick in until we finish the
do loops.
"""
reflNum=reflNum+1
RhklTemp=np.append(RhklTemp,[RGtest],axis=0)
"""Check to make sure we have enough beams"""
if reflNum<=IMinStrongBeams:
print("Beam pool is too small, please increase RgLimit. Quiting...")
IErr=1
"""QUIT PROGRAM"""
"""Make the beam pool"""
INhkl=reflNum
print("Using a beam pool of",str(INhkl),"reflections")
Rhkl=np.zeros((INhkl,3),dtype="float")
Rhkl=RhklTemp
"""Now check that the required output hkls are in this hkl list"""
for i in range(INoOfLacbedPatterns):
flag=0
for k in range(INhkl):
if (RInputHKLs[i,0]-Rhkl[k,0]<10**-9) and (RInputHKLs[i,1]-Rhkl[k,1]<10**-9) and (RInputHKLs[i,2]-Rhkl[k,2]<10**-9):
flag=1
if flag==0:
print("Input hkl not found:",np.rint(RInputHKLs[i]))
return(INhkl,Rhkl)