-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdielectricfun.py
More file actions
283 lines (231 loc) · 8.14 KB
/
dielectricfun.py
File metadata and controls
283 lines (231 loc) · 8.14 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
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
# -*- coding: utf-8 -*-
"""
Created on Mon Jan 11 09:31:32 2021
library to access n, k database. still in a very early form. At some point it
would be good to have a common database format. But I am not sure what is the
way to implement something like that. Also there are python implementations
that enable access to the refractiveindex.info database. Now also some
functions for calculations/rotations of dielectric tensors are included.
@author: m.rabe
"""
import specage.unit_convert as uc
import numpy as np
import pkg_resources
import sympy as _sp
DB_PATH = pkg_resources.resource_filename('specage', 'dielectricDB/')
def readnkdbfile(file, xunit):
'''
needs to be implemented
Parameters
----------
file : TYPE
DESCRIPTION.
xunit : TYPE
DESCRIPTION.
Returns
-------
None.
'''
pass
def writenkdbfile(file, x, n, k, source = '', cmt=''):
'''
needs to be implemented
Parameters
----------
file : TYPE
DESCRIPTION.
x : TYPE
DESCRIPTION.
n : TYPE
DESCRIPTION.
k : TYPE
DESCRIPTION.
source : TYPE, optional
DESCRIPTION. The default is ''.
cmt : TYPE, optional
DESCRIPTION. The default is ''.
Returns
-------
None.
'''
pass
def geBurnett_n(wavelength):
'''
n for Ge according to :
J. H. Burnett, S. G. Kaplan, E. Stover, A. Phenis.
Refractive index measurements of Ge, Proc. SPIE 9974, 99740X (2016).
https://doi.org/10.1117/12.2237978
Returns
-------
(n, nan)
'''
n=(1
+0.4886331/(1-1.393959/wavelength**2)
+14.5142535/(1-0.1626427/wavelength**2)
+0.0091224/(1-752.190/wavelength**2)
)**.5
return n
def siChandler_Horowitz_n(wavelength):
'''not functional at the moment '''
# TODO: program that if needed
# n=(11.67316
# +1/(x**2)
# +0.004482633/(x**2-1.108205**2))**.5
pass
def D2O_MaxChapados_nk(wvlofinterest):
fulldata=np.loadtxt(DB_PATH + 'nk_H2O_D2O_MaxChapados2009.txt',
skiprows=4)
#the dataset is in wavenumbers and the first value is 0, thus:
wvl = uc.wavenum2nm(fulldata[1:,0])*1E-3
#for the interpolation x must increase, thus it should be double checked
if ~np.all(np.diff(wvl)>0):
wvl = np.flipud(wvl)
nk = np.flipud(fulldata[1:,3:5])
return (np.interp(wvlofinterest, wvl, nk[:,0]),
np.interp(wvlofinterest, wvl, nk[:,1]))
def H2O_MaxChapados_nk(wvlofinterest):
fulldata=np.loadtxt(DB_PATH + 'nk_H2O_D2O_MaxChapados2009.txt',
skiprows=4)
#the dataset is in wavenumbers and the first value is 0, thus:
wvl = uc.wavenum2nm(fulldata[1:,0])*1E-3
#for the interpolation x must increase, thus it should be double checked
if ~np.all(np.diff(wvl)>0):
wvl = np.flipud(wvl)
nk = np.flipud(fulldata[1:,1:3])
return (np.interp(wvlofinterest, wvl, nk[:,0]),
np.interp(wvlofinterest, wvl, nk[:,1]))
def nkdatabase(material, wavelength):
'''
return vavelength dependent refractive index and absorption coefficient
(n, k) values retrieved from database.
Parameters
----------
material : (str)
Name of material.
wavelength : (numpy.array)
Wavelength [micrometer].
Returns
-------
n : (numpy.array)
refractive index
k : (numpy.array)
absorption coefficient
'''
# definition of the data base. this might be improved (maybe put in separate file?):
alldatadict = {'Ge_n':geBurnett_n,
'Si_n':siChandler_Horowitz_n,
'D2O_nk':D2O_MaxChapados_nk,
'H2O_nk':H2O_MaxChapados_nk
}
return alldatadict[material](wavelength)
def LorentzOscillator(w, eps_inf, S, w_res, fwhm):
'''Returns epsilon for lorentz oscillator model with several resonances
... usage comes here
works for frequencies (and wavenumbers) of any unit
'''
epsilon = eps_inf
for (Sj, w_res_j, fwhm_j) in zip(S, w_res, fwhm):
epsilon += (Sj*(w_res_j**2))/((w_res_j**2)-(w**2)-1j*w*fwhm_j)
return epsilon
def LorentzianAbsorbance(kmax, nu_0, hwhh, n_inf, nu):
"""
Returns refractive KK conform index of refraction (n) and absorption
coefficient from an antisymmetric linear combination of the Lorentzian
functions presented by Huang and Urban (Appl. Spectrosc., 1992, 46, 1666–1672.).
Parameters
----------
kmax : np.array
maximum (peak) k values at nu_0
nu_0 : np.array
wavenumbers of k maxima (peaks)
hwhh : np.array
Half widths at half maximum (peak widths)
n_inf : numeric scalar
refractive index far away from peaks (background n)
nu : numpy.array
wavenumbers.
Returns
-------
n : numpy.array
refractive indeces at nu
k : numpy.array
absorption coefficients at nu
"""
k = np.zeros(nu.shape)
n = n_inf*np.ones(nu.shape)
for (km, u_0, hw) in zip(kmax, nu_0, hwhh):
k += ( ((km*hw**2)/((nu-u_0)**2 + hw**2))
-((km*hw**2)/((nu+u_0)**2 + hw**2)) )
n += ( - (((nu-u_0)*km*hw)/((nu-u_0)**2 + hw**2))
+ (((nu+u_0)*km*hw)/((nu+u_0)**2 + hw**2)) )
return n, k
def euler_rotmat(Phi, Theta, Psi):
"""
Returns the orthogonal rotation matrix from the Euler angles φ, θ, and ψ
(phi, theta, and psi) for active rotation. As defined in Goldstein, Poole
and Safko, "Classical Mechanics" (3rd Edition), 2002, p.153, eq(4.47).
This is the zx'z' convention of definition of Euler angles. Positive angles
mean counter-clockwise rotations watching along the positive rotation axis
towards the origin.
Parameters
----------
Phi : numeric or symbolic
Azimuth angle in radians.
Theta : numeric or symbolic
Tilt angle in radians.
Psi : numeric or symbolic
Twist angle in radians.
Returns
-------
sympy matrix
Rotation matrix for active rotation by Euler angles.
"""
phi, theta, psi = _sp.symbols('φ θ ψ')
s=_sp.sin
c=_sp.cos
R = _sp.Matrix([
[c(psi)*c(phi) - c(theta)*s(phi)*s(psi), #1st row
-s(psi)*c(phi) - c(theta)*s(phi)*c(psi),
s(theta)*s(phi)],
[c(psi)*s(phi) + c(theta)*c(phi)*s(psi), # 2nd row
-s(psi)*s(phi) + c(theta)*c(phi)*c(psi),
-s(theta)*c(phi)],
[s(theta)*s(psi), #3rd row
s(theta)*c(psi),
c(theta)]])
return R.subs([(phi, Phi), (theta, Theta), (psi, Psi)])
def euler_rotmat_zyz(Phi, Theta, Psi):
"""
Returns the orthogonal rotation matrix from the Euler angles φ, θ, and ψ
(phi, theta, and psi) for active rotation. As defined in Wilson, Decius,
Cross „Molecular Vibrations“ , 1955 p. 285.
This is the zy'z' convention of definition of Euler angles. Positive angles
mean counter-clockwise rotations watching along the positive rotation axis
towards the origin.
Parameters
----------
Phi : numeric or symbolic
Azimuth angle in radians.
Theta : numeric or symbolic
Tilt angle in radians.
Psi : numeric or symbolic
Twist angle in radians.
Returns
-------
sympy matrix
Rotation matrix for active rotation by Euler angles.
"""
phi, theta, psi = _sp.symbols('φ θ ψ')
s=_sp.sin
c=_sp.cos
R = _sp.Matrix([
[c(theta)*c(phi)*c(psi)-s(phi)*s(psi), #1st row
c(theta)*s(phi)*c(psi)+c(phi)*s(psi),
-s(theta)*c(psi)],
[-c(theta)*c(phi)*s(psi)-s(phi)*c(psi), # 2nd row
-c(theta)*s(phi)*s(psi)+c(phi)*c(psi),
s(theta)*s(psi)],
[s(theta)*c(phi), #3rd row
s(theta)*s(phi),
c(theta)]])
return R.transpose().subs([(phi, Phi), (theta, Theta), (psi, Psi)]) #we need the transpose since we need it for active rotation