-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathvmp_theory.py
581 lines (489 loc) · 20 KB
/
vmp_theory.py
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
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
# -*- coding: utf-8 -*-
"""
This module contains functions with electromagnetic plasmonics theory.
It holds tools to work with...
- Complex dielectric constant and refractive index
- Polarizability
- Induced dipolar moment
- Electric field
- Scattering, absorption and extinction
- Power and temperature
These functions compute physical magnitudes by applying different
electromagnetic models and aproximations. Cuasistatic dipolar
approximation, Clausius-Mosotti and Kuwata models, Mie theory and
Gaussian beam expressions are used.
Some of its most useful tools are...
alpha_Clausius_Mosotti : function
Returns Clausius-Mosotti polarizability alpha for a sphere in units of volume.
alpha_Kuwata : function
Returns Kuwata polarizability alpha for a sphere in units of volume.
p_induced : function
Returns induced dipolar moment for a sphere in units of volume times field.
E : function
Returns electric field for a sphere for all positions in units of field.
sigma_scatt : function
Calculates scattering cross section using Mie theory for a spherical NP.
sigma_abs : function
Calculates absorption cross section using Mie theory for a spherical NP.
delta_T : function
Surface temperature increasement caused by a focused Gaussian beam on a NP.
P : function
Gaussian focused power that causes a surface temperature change on a NP.
@author: Vall
"""
import numpy as np
try:
import PyMieScatt as ps
except:
raise OSError("Must install PyMieScatt module using, for example, `pip install PyMieScatt`")
#%% REFRACTIVE INDEX AND MATERIAL CONSTANTS
def N_from_epsilon(epsilon, mu=1):
return np.sqrt(epsilon * mu)
def epsilon_from_N(N):
return np.power(N, 2)
#%% CLAUSIUS-MOSETTI: POLARIZABILITY
def alpha_Clausius_Mosotti(epsilon, r, epsilon_ext=1):
"""Returns Clausius-Mosotti polarizability alpha in units of volume"""
alpha = 4 * np.pi * (r**3)
alpha = alpha * ( epsilon - epsilon_ext ) / ( epsilon + 2 * epsilon_ext )
return alpha
# In units of nm^3
#%% KUWATA: POLARIZABILITY
def alpha_Kuwata(epsilon, wlen, r, epsilon_ext=1):
"""Returns alternative Kuwata polarizability alpha in units of volume"""
aux_d = 2 * np.pi * r * epsilon_ext / wlen # Withouth units, so no need for from_um_factor * 1e3
aux_vol = 4 * np.pi * (r**3) / 3
alpha = 3 * aux_vol * ( 1 - ( (epsilon + epsilon_ext) * ( aux_d**2 ) / ( 40 * epsilon_ext ) ) )
aux_den = 1 + ( 3 * epsilon_ext / ( epsilon - epsilon_ext ) )
aux_den = aux_den - ( epsilon + 10 * epsilon_ext ) * ( aux_d**2 ) / ( 40 * epsilon_ext )
aux_den = aux_den - 2 * 1j * aux_d**3 / 3
alpha = alpha / aux_den
return alpha
#%% DIPOLAR APROXIMATION: INDUCED DIPOLE MOMENT
def p_induced(epsilon, alpha, E0, epsilon_ext=1):
"""Returns induced dipolar moment in units of volume times field.
Units asume vacuum permitivity epsilon_0 = 1.
"""
if isinstance(epsilon, np.ndarray):
aux = np.array([e * epsilon_ext * a for e, a in zip(epsilon, alpha)])
p = np.array([E0 * a for a in aux])
else:
p = epsilon * epsilon_ext * alpha * E0
return p
#%% DIPOLAR APROXIMATION: ELECTRIC FIELD
def E_in(epsilon, E0, epsilon_ext=1):
"""Returns electric field inside the sphere in units of field.
Units asume vacuum permitivity epsilon_0 = 1.
"""
aux = 3 * epsilon_ext / (epsilon + 2 * epsilon_ext)
if isinstance(aux, np.ndarray):
E_in = np.array([E0 * a for a in aux])
else:
E_in = E0 * aux
return E_in
def E_out(epsilon, alpha, E0, rvec, epsilon_ext=1):
"""Returns electric field outside the sphere in units of field.
Units asume vacuum permitivity epsilon_0 = 1.
"""
rmod = np.linalg.norm(rvec)
rver = rvec / rmod
p = p_induced(epsilon, alpha, E0)
if p.ndim > 1:
aux = np.array([3 * rver * np.dot(rver, pi) - pi for pi in p])
else:
aux = 3 * rver * np.dot(rver, p) - p
if isinstance(aux, np.ndarray) and isinstance(epsilon, np.ndarray):
Eout = np.array([E0 + a / (4 * np.pi * e * epsilon_ext * (rmod**3)) for a, e in zip(aux, epsilon)])
else:
Eout = E0 + aux / (4 * np.pi * epsilon * epsilon_ext * (rmod**3))
# Eout = E0 + aux / (4 * np.pi * epsilon * epsilon_ext * (rmod**3))
return Eout
def E(epsilon, alpha, E0, rvec, r, epsilon_ext=1):
"""Returns electric field for a sphere for all positions in units of field.
Units asume vacuum permitivity epsilon_0 = 1.
"""
rmod = np.linalg.norm(rvec)
if rmod <= r:
return E_in(epsilon, E0)
else:
return E_out(epsilon, alpha, E0, rvec)
# First index: wavelength
# Second index: direction
#%% SCATTERING AND ABSORPTION CROSS SECTION
def sigma_scatt_dipolar(r, wlen, alpha, surrounding_N=1, asEfficiency=False):
"""
Calculates scattering cross section using dipolar approximation for a spherical NP.
Parameters
----------
r : float
Spherical NP radius. Measured in nm.
wlen : float, list, np.array
Incident light wavelength. Measured in nm.
inner_N=1.458 : float, list, np.array
Spherical NP inner medium's complex refractive index. The default is
1.458 for fused-silica.
surrounding_N=1 : float, list, np.array
Surrounding medium's complex refractive index. The default is
1 for vacuum.
asEfficiency : bool, optional
If false, scattering cross section sigma is returned, measured in nm^2.
If true, scattering effienciency Q is returned, dimensionless and
related to scattering cross section by sigma = pi r^2 Q
for a spherical NP. The default is False.
Returns
-------
sigma_scatt : float, np.array
The scattering cross section calculated using Mie theory and measured
in nm^2. In case `asEfficiency=True`, scattering effiency is returned
instead, dimensionless.
Raises
------
ValueError : "Must have as many inner refractive index values as..."
If the length of `wlen` and `inner_N` differ.
ValueError : "Must have as many surrounding refractive index values as..."
If the length of `wlen` and `surrounding_N` differ.
"""
try:
wlen = np.array([*wlen])
except:
wlen = np.array([wlen])
try:
if len(alpha)==len(wlen):
alpha = np.array([*alpha])
else:
raise ValueError("Must have as many inner polarizability values as wavelength values")
except:
alpha = [*[alpha]*len(wlen)]
try:
if len(surrounding_N)==len(wlen):
surrounding_N = np.array([*surrounding_N])
else:
raise ValueError("Must have as many surrounding refractive index values as wavelength values")
except:
surrounding_N = [*[surrounding_N]*len(wlen)]
# k = 2 * np.pi * surrounding_N / wlen
# return k**4 * np.abs(alpha)**2 / (6 * np.pi)
if not asEfficiency:
return 8 * np.pi**3 * np.abs(alpha)**2 * (surrounding_N / wlen)**4 / 3
else:
return 8 * (np.pi * np.abs(alpha))**2 * (surrounding_N / wlen)**4 / ( 3 * r**2 )
def sigma_ext_dipolar(r, wlen, alpha, surrounding_N=1, asEfficiency=False):
"""
Calculates extinction cross section using dipolar approximation for a spherical NP.
Parameters
----------
r : float
Spherical NP radius. Measured in nm.
wlen : float, list, np.array
Incident light wavelength. Measured in nm.
inner_N=1.458 : float, list, np.array
Spherical NP inner medium's complex refractive index. The default is
1.458 for fused-silica.
surrounding_N=1 : float, list, np.array
Surrounding medium's complex refractive index. The default is
1 for vacuum.
asEfficiency : bool, optional
If false, extinction cross section sigma is returned, measured in nm^2.
If true, extinction effienciency Q is returned, dimensionless and
related to extinction cross section by sigma = pi r^2 Q
for a spherical NP. The default is False.
Returns
-------
sigma_ext : float, np.array
The extinction cross section calculated using Mie theory and measured
in nm^2. In case `asEfficiency=True`, extinction effiency is returned
instead, dimensionless.
Raises
------
ValueError : "Must have as many inner refractive index values as..."
If the length of `wlen` and `inner_N` differ.
ValueError : "Must have as many surrounding refractive index values as..."
If the length of `wlen` and `surrounding_N` differ.
"""
try:
wlen = np.array([*wlen])
except:
wlen = np.array([wlen])
try:
if len(alpha)==len(wlen):
alpha = np.array([*alpha])
else:
raise ValueError("Must have as many inner polarizability values as wavelength values")
except:
alpha = [*[alpha]*len(wlen)]
try:
if len(surrounding_N)==len(wlen):
surrounding_N = np.array([*surrounding_N])
else:
raise ValueError("Must have as many surrounding refractive index values as wavelength values")
except:
surrounding_N = [*[surrounding_N]*len(wlen)]
# k = 2 * np.pi * surrounding_N / wlen
# return k * np.imag(alpha)
if not asEfficiency:
return 2 * np.pi * surrounding_N * np.imag(alpha) / wlen
else:
return 2 * surrounding_N * np.imag(alpha) / ( wlen * r**2 )
def sigma_abs_dipolar(r, wlen, alpha, surrounding_N=1, asEfficiency=False):
"""
Calculates absorption cross section using dipolar approximation for a spherical NP.
Parameters
----------
r : float
Spherical NP radius. Measured in nm.
wlen : float, list, np.array
Incident light wavelength. Measured in nm.
inner_N=1.458 : float, list, np.array
Spherical NP inner medium's complex refractive index. The default is
1.458 for fused-silica.
surrounding_N=1 : float, list, np.array
Surrounding medium's complex refractive index. The default is
1 for vacuum.
asEfficiency : bool, optional
If false, absorption cross section sigma is returned, measured in nm^2.
If true, absorption effienciency Q is returned, dimensionless and
related to absorption cross section by sigma = pi r^2 Q
for a spherical NP. The default is False.
Returns
-------
sigma_ext : float, np.array
The absorption cross section calculated using Mie theory and measured
in nm^2. In case `asEfficiency=True`, absorption effiency is returned
instead, dimensionless.
Raises
------
ValueError : "Must have as many inner refractive index values as..."
If the length of `wlen` and `inner_N` differ.
ValueError : "Must have as many surrounding refractive index values as..."
If the length of `wlen` and `surrounding_N` differ.
"""
sigma_scatt = sigma_scatt_dipolar(r, wlen, alpha, surrounding_N, asEfficiency)
sigma_ext = sigma_ext_dipolar(r, wlen, alpha, surrounding_N, asEfficiency)
return sigma_ext - sigma_scatt
# def sigma_scatt(r, wlen, inner_N=1.458, surrounding_N=1, asEfficiency=False):
def sigma_scatt_Mie(r, wlen, inner_N=1.458, surrounding_N=1, asEfficiency=False):
"""
Calculates scattering cross section using Mie theory for a spherical NP.
Parameters
----------
r : float
Spherical NP radius. Measured in nm.
wlen : float, list, np.array
Incident light wavelength. Measured in nm.
inner_N=1.458 : float, list, np.array
Spherical NP inner medium's complex refractive index. The default is
1.458 for fused-silica.
surrounding_N=1 : float, list, np.array
Surrounding medium's complex refractive index. The default is
1 for vacuum.
asEfficiency : bool, optional
If false, scattering cross section sigma is returned, measured in nm^2.
If true, scattering effienciency Q is returned, dimensionless and
related to scattering cross section by sigma = pi r^2 Q
for a spherical NP. The default is False.
Returns
-------
sigma_scatt : float, np.array
The scattering cross section calculated using Mie theory and measured
in nm^2. In case `asEfficiency=True`, scattering effiency is returned
instead, dimensionless.
Raises
------
ValueError : "Must have as many inner refractive index values as..."
If the length of `wlen` and `inner_N` differ.
ValueError : "Must have as many surrounding refractive index values as..."
If the length of `wlen` and `surrounding_N` differ.
"""
try:
wlen = np.array([*wlen])
except:
wlen = np.array([wlen])
try:
if len(inner_N)==len(wlen):
inner_N = np.array([*inner_N])
else:
raise ValueError("Must have as many inner refractive index values as wavelength values")
except:
inner_N = [*[inner_N]*len(wlen)]
try:
if len(surrounding_N)==len(wlen):
surrounding_N = np.array([*surrounding_N])
else:
raise ValueError("Must have as many surrounding refractive index values as wavelength values")
except:
surrounding_N = [*[surrounding_N]*len(wlen)]
sigma_scatt = np.array([ps.MieQ(
iN, wl, 2*r, nMedium=sN, asCrossSection=not(asEfficiency))[1]
for wl, iN, sN in zip(wlen, inner_N, surrounding_N)])
if len(sigma_scatt)>1:
return sigma_scatt
else:
return sigma_scatt[0]
def sigma_abs_Mie(r, wlen, inner_N=1.458, surrounding_N=1, asEfficiency=False):
# def sigma_abs(r, wlen, inner_N=1.458, surrounding_N=1, asEfficiency=False):
"""
Calculates absorption cross section using Mie theory for a spherical NP.
Parameters
----------
r : float
Spherical NP radius. Measured in nm.
wlen : float, list, np.array
Incident light wavelength. Measured in nm.
inner_N=1.458 : float, list, np.array
Spherical NP inner medium's complex refractive index. The default is
1.458 for fused-silica.
surrounding_N=1 : float, list, np.array
Surrounding medium's complex refractive index. The default is
1 for vacuum.
asEfficiency : bool, optional
If false, scattering cross section sigma is returned, measured in nm^2.
If true, scattering effienciency Q is returned, dimensionless and
related to scattering cross section by sigma = pi r^2 Q
for a spherical NP. The default is False.
Returns
-------
sigma_abs : float, np.array
The scattering cross section calculated using Mie theory and measured
in nm^2. In case `asEfficiency=True`, scattering effiency is returned
instead, dimensionless.
Raises
------
ValueError : "Must have as many inner refractive index values as..."
If the length of `wlen` and `inner_N` differ.
ValueError : "Must have as many surrounding refractive index values as..."
If the length of `wlen` and `surrounding_N` differ.
"""
try:
wlen = np.array([*wlen])
except:
wlen = np.array([wlen])
try:
if len(inner_N)==len(wlen):
inner_N = np.array([*inner_N])
else:
raise ValueError("Must have as many inner refractive index values as wavelength values")
except:
inner_N = [*[inner_N]*len(wlen)]
try:
if len(surrounding_N)==len(wlen):
surrounding_N = np.array([*surrounding_N])
else:
raise ValueError("Must have as many surrounding refractive index values as wavelength values")
except:
surrounding_N = [*[surrounding_N]*len(wlen)]
sigma_abs = np.array([ps.MieQ(
iN, wl, 2*r, nMedium=sN, asCrossSection=not(asEfficiency))[2]
for wl, iN, sN in zip(wlen, inner_N, surrounding_N)])
if len(sigma_abs)>1:
return sigma_abs
else:
return sigma_abs[0]
def sigma_ext_Mie(r, wlen, inner_N=1.458, surrounding_N=1, asEfficiency=False):
"""
Calculates extinction cross section using Mie theory for a spherical NP.
Parameters
----------
r : float
Spherical NP radius. Measured in nm.
wlen : float, list, np.array
Incident light wavelength. Measured in nm.
inner_N=1.458 : float, list, np.array
Spherical NP inner medium's complex refractive index. The default is
1.458 for fused-silica.
surrounding_N=1 : float, list, np.array
Surrounding medium's complex refractive index. The default is
1 for vacuum.
asEfficiency : bool, optional
If false, extinction cross section sigma is returned, measured in nm^2.
If true, extinction effienciency Q is returned, dimensionless and
related to extinction cross section by sigma = pi r^2 Q
for a spherical NP. The default is False.
Returns
-------
sigma_scatt : float, np.array
The extinction cross section calculated using Mie theory and measured
in nm^2. In case `asEfficiency=True`, extinction effiency is returned
instead, dimensionless.
Raises
------
ValueError : "Must have as many inner refractive index values as..."
If the length of `wlen` and `inner_N` differ.
ValueError : "Must have as many surrounding refractive index values as..."
If the length of `wlen` and `surrounding_N` differ.
"""
try:
wlen = np.array([*wlen])
except:
wlen = np.array([wlen])
try:
if len(inner_N)==len(wlen):
inner_N = np.array([*inner_N])
else:
raise ValueError("Must have as many inner refractive index values as wavelength values")
except:
inner_N = [*[inner_N]*len(wlen)]
try:
if len(surrounding_N)==len(wlen):
surrounding_N = np.array([*surrounding_N])
else:
raise ValueError("Must have as many surrounding refractive index values as wavelength values")
except:
surrounding_N = [*[surrounding_N]*len(wlen)]
sigma_ext = np.array([ps.MieQ(
iN, wl, 2*r, nMedium=sN, asCrossSection=not(asEfficiency))[0]
for wl, iN, sN in zip(wlen, inner_N, surrounding_N)])
if len(sigma_ext)>1:
return sigma_ext
else:
return sigma_ext[0]
#%% TEMPERATURE
def delta_T(P, sigma_abs, w0, r, kappa):
"""
Surface temperature increasement caused by a focused Gaussian beam on a NP.
Parameters
----------
P : float
Total power of the beam. Measured in mW.
sigma_abs : float
Absorption cross section of the nanoparticle NP. Measured in nm^2.
kappa : float
Thermal conductivity of the sourrounding medium where the NP is
inmersed. Measured in W / K m.
r : float
Radius of the NP. Measured in nm.
w0 : float
Laser beam waist. Measured in nm.
Returns
-------
delta_T : float
Temperature increasement caused by the focused Gaussian beam on the
surface of the NP. Measured in K or ºC.
"""
kappa = kappa * 1000 / (1e9) # From W/Km to mW/Knm
delta_T = sigma_abs * P / (2 * (np.pi**2) * kappa * r * (w0**2))
return delta_T
def P(delta_T, sigma_abs, w0, r, kappa):
"""
Gaussian focused power that causes a surface temperature change on a NP.
Parameters
----------
delta_T : float
Temperature increasement caused by the focused Gaussian beam on the
surface of the NP. Measured in K or ºC.
sigma_abs : float
Absorption cross section of the nanoparticle NP. Measured in nm^2.
kappa : float
Thermal conductivity of the sourrounding medium where the NP is
inmersed. Measured in W / K m.
r : float
Radius of the NP. Measured in nm.
w0 : float
Laser beam waist. Measured in nm.
Returns
-------
delta_T : float
Total power of the focused Gaussian beam. Measured in mW.
"""
kappa = kappa * 1000 / (1e9) # From W/Km to mW/Knm
P = 2 * (np.pi**2) * kappa * r * (w0**2) * delta_T / sigma_abs
return P