-
Notifications
You must be signed in to change notification settings - Fork 4
/
vmp_materials.py
1903 lines (1553 loc) · 73.8 KB
/
vmp_materials.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
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
This module allows to work in MEEP with materials from different sources.
It holds tools to work with...
- Meep's medium classes and functions.
- Complex dielectric constant epsilon and complex refractive index N.
Some of its most useful tools are...
import_module : function
Returns Medium instance from string with specified length scale
epsilon_function : function
Generates an interpolation function for epsilon from experimental data.
It's widely based on Meep Materials Library.
@author: vall
"""
import matplotlib.pyplot as plt
import numpy as np
import os
from scipy.interpolate import interp1d
try:
import meep as mp
except:
print("Meep functions not available. Don't worry! You can still use everything else")
import v_save as vs
import vmp_theory as vmt
import v_utilities as vu
syshome = vs.get_sys_home()
home = vs.get_home()
#%% MEEP MEDIUM IMPORT
def import_medium(material, paper="R", from_um_factor=1):
"""Returns Medium instance from string with specified length scale
It's widely based on Meep Materials Library, merely adapted to change
according to the length unit scale used.
Parameters
----------
material: str
Name of the desired material.
paper="R": str
Name of desired source for experimental input data of medium.
from_um_factor=1 : int, float, optional
Factor to transform from SI μm to the chosen length unit. For example,
to work with 100 nm as 1 Meep unit, from_um_factor=.1 must be specified.
Returns
-------
medium : mp.Medium
The mp.Medium instance of the desired material.
Raises
------
"No media called ... is available" : SyntaxError
If no material is found whose name matches the string given.
"""
if "Ag" not in material and "Au" not in material:
raise SyntaxError("No media called {} is available".format(material))
return
# Default unit length is 1 um
eV_from_um_factor = from_um_factor/1.23984193 # Conversion factor: eV to 1/um [=1/hc]
# from_um_factor used to be um_scale (but that's a shady name)
############ GOLD #################################################
if material=="Au" and paper=="R":
#------------------------------------------------------------------
# Elemental metals from A.D. Rakic et al., Applied Optics, Vol. 37, No. 22, pp. 5271-83, 1998
# Wavelength range: 0.2 - 12.4 um
# Gold (Au)
metal_range = mp.FreqRange(min=from_um_factor*1e3/6199.2,
max=from_um_factor*1e3/247.97)
Au_plasma_frq = 9.03*eV_from_um_factor
Au_f0 = 0.760
Au_frq0 = 1e-10
Au_gam0 = 0.053*eV_from_um_factor
Au_sig0 = Au_f0*Au_plasma_frq**2/Au_frq0**2
Au_f1 = 0.024
Au_frq1 = 0.415*eV_from_um_factor # 2.988 um
Au_gam1 = 0.241*eV_from_um_factor
Au_sig1 = Au_f1*Au_plasma_frq**2/Au_frq1**2
Au_f2 = 0.010
Au_frq2 = 0.830*eV_from_um_factor # 1.494 um
Au_gam2 = 0.345*eV_from_um_factor
Au_sig2 = Au_f2*Au_plasma_frq**2/Au_frq2**2
Au_f3 = 0.071
Au_frq3 = 2.969*eV_from_um_factor # 0.418 um
Au_gam3 = 0.870*eV_from_um_factor
Au_sig3 = Au_f3*Au_plasma_frq**2/Au_frq3**2
Au_f4 = 0.601
Au_frq4 = 4.304*eV_from_um_factor # 0.288 um
Au_gam4 = 2.494*eV_from_um_factor
Au_sig4 = Au_f4*Au_plasma_frq**2/Au_frq4**2
Au_f5 = 4.384
Au_frq5 = 13.32*eV_from_um_factor # 0.093 um
Au_gam5 = 2.214*eV_from_um_factor
Au_sig5 = Au_f5*Au_plasma_frq**2/Au_frq5**2
Au_susc = [mp.DrudeSusceptibility(frequency=Au_frq0, gamma=Au_gam0, sigma=Au_sig0),
mp.LorentzianSusceptibility(frequency=Au_frq1, gamma=Au_gam1, sigma=Au_sig1),
mp.LorentzianSusceptibility(frequency=Au_frq2, gamma=Au_gam2, sigma=Au_sig2),
mp.LorentzianSusceptibility(frequency=Au_frq3, gamma=Au_gam3, sigma=Au_sig3),
mp.LorentzianSusceptibility(frequency=Au_frq4, gamma=Au_gam4, sigma=Au_sig4),
mp.LorentzianSusceptibility(frequency=Au_frq5, gamma=Au_gam5, sigma=Au_sig5)]
Au = mp.Medium(epsilon=1.0, E_susceptibilities=Au_susc,
valid_freq_range=metal_range)
Au.from_um_factor = from_um_factor
return Au
elif material=="Au" and paper=="JC":
#------------------------------------------------------------------
# Metals from D. Barchiesi and T. Grosges, J. Nanophotonics, Vol. 8, 08996, 2015
# Wavelength range: 0.4 - 0.8 um
# Gold (Au)
# Fit to P.B. Johnson and R.W. Christy, Physical Review B, Vol. 6, pp. 4370-9, 1972
# metal_visible_range = mp.FreqRange(min=from_um_factor*1e3/800,
# max=from_um_factor*1e3/400)
# Au_JC_visible_frq0 = 1*from_um_factor/0.139779231751333
# Au_JC_visible_gam0 = 1*from_um_factor/26.1269913352870
# Au_JC_visible_sig0 = 1
# Au_JC_visible_frq1 = 1*from_um_factor/0.404064525036786
# Au_JC_visible_gam1 = 1*from_um_factor/1.12834046202759
# Au_JC_visible_sig1 = 2.07118534879440
# Au_JC_visible_susc = [mp.DrudeSusceptibility(frequency=Au_JC_visible_frq0, gamma=Au_JC_visible_gam0, sigma=Au_JC_visible_sig0),
# mp.LorentzianSusceptibility(frequency=Au_JC_visible_frq1, gamma=Au_JC_visible_gam1, sigma=Au_JC_visible_sig1)]
# Au_JC_visible = mp.Medium(epsilon=6.1599,
# E_susceptibilities=Au_JC_visible_susc,
# valid_freq_range=metal_visible_range)
# Au_JC_visible.from_um_factor = from_um_factor
# return Au_JC_visible
#------------------------------------------------------------------
# Metal from my own fit
# Wavelength range: 0.1879 - 1.937 um
# Gold (Au)
# Fit to P.B. Johnson and R.W. Christy, Physical Review B, Vol. 6, pp. 4370-9, 1972
Au_JC_range = mp.FreqRange(min=from_um_factor/1.937,
max=from_um_factor/.1879)
freq_0 = 1.000000082740371e-10 * from_um_factor
gamma_0 = 4.4142682842363e-09 * from_um_factor
sigma_0 = 3.3002903009040977e+21
freq_1 = 0.3260039379724786 * from_um_factor
gamma_1 = 0.03601307014052124 * from_um_factor
sigma_1 = 103.74591029640469
freq_2 = 0.47387215165339414 * from_um_factor
gamma_2 = 0.34294093699162054 * from_um_factor
sigma_2 = 14.168079504545002
freq_3 = 2.3910144662345445 * from_um_factor
gamma_3 = 0.5900378254265015 * from_um_factor
sigma_3 = 0.8155991478264435
freq_4 = 3.3577076082530537 * from_um_factor
gamma_4 = 1.6689250252226686 * from_um_factor
sigma_4 = 2.038193481751111
freq_5 = 8.915719663759013 * from_um_factor
gamma_5 = 7.539763092679264 * from_um_factor
sigma_5 = 3.74409654935571
Au_JC_susc = [mp.DrudeSusceptibility(frequency=freq_0, gamma=gamma_0, sigma=sigma_0),
mp.LorentzianSusceptibility(frequency=freq_1, gamma=gamma_1, sigma=sigma_1),
mp.LorentzianSusceptibility(frequency=freq_2, gamma=gamma_2, sigma=sigma_2),
mp.LorentzianSusceptibility(frequency=freq_3, gamma=gamma_3, sigma=sigma_3),
mp.LorentzianSusceptibility(frequency=freq_4, gamma=gamma_4, sigma=sigma_4),
mp.LorentzianSusceptibility(frequency=freq_5, gamma=gamma_5, sigma=sigma_5)]
Au_JC = mp.Medium(epsilon=1.0,#6.1599,
E_susceptibilities=Au_JC_susc,
valid_freq_range=Au_JC_range)
Au_JC.from_um_factor = from_um_factor
return Au_JC
elif material=="Au" and paper=="P":
#------------------------------------------------------------------
# Metals from D. Barchiesi and T. Grosges, J. Nanophotonics, Vol. 8, 08996, 2015
# Wavelength range: 0.4 - 0.8 um
# Gold (Au)
# Fit to E.D. Palik, Handbook of Optical Constants, Academic Press, 1985
metal_visible_range = mp.FreqRange(min=from_um_factor*1e3/800,
max=from_um_factor*1e3/400)
Au_visible_frq0 = 1*from_um_factor/0.0473629248511456
Au_visible_gam0 = 1*from_um_factor/0.255476199605166
Au_visible_sig0 = 1
Au_visible_frq1 = 1*from_um_factor/0.800619321082804
Au_visible_gam1 = 1*from_um_factor/0.381870287531951
Au_visible_sig1 = -169.060953137985
Au_visible_susc = [mp.DrudeSusceptibility(frequency=Au_visible_frq0, gamma=Au_visible_gam0, sigma=Au_visible_sig0),
mp.LorentzianSusceptibility(frequency=Au_visible_frq1, gamma=Au_visible_gam1, sigma=Au_visible_sig1)]
Au_visible = mp.Medium(epsilon=0.6888, E_susceptibilities=Au_visible_susc,
valid_freq_range=metal_visible_range)
Au_visible.from_um_factor = from_um_factor
return Au_visible
elif material=="Au":
raise ValueError("No source found for Au with that name")
############ SILVER ###############################################
if material=="Ag" and paper=="R":
#------------------------------------------------------------------
# Elemental metals from A.D. Rakic et al., Applied Optics, Vol. 37, No. 22, pp. 5271-83, 1998
# Wavelength range: 0.2 - 12.4 um
# Silver (Ag)
metal_range = mp.FreqRange(min=from_um_factor*1e3/12398,
max=from_um_factor*1e3/247.97)
Ag_plasma_frq = 9.01*eV_from_um_factor
Ag_f0 = 0.845
Ag_frq0 = 1e-10
Ag_gam0 = 0.048*eV_from_um_factor
Ag_sig0 = Ag_f0*Ag_plasma_frq**2/Ag_frq0**2
Ag_f1 = 0.065
Ag_frq1 = 0.816*eV_from_um_factor # 1.519 um
Ag_gam1 = 3.886*eV_from_um_factor
Ag_sig1 = Ag_f1*Ag_plasma_frq**2/Ag_frq1**2
Ag_f2 = 0.124
Ag_frq2 = 4.481*eV_from_um_factor # 0.273 um
Ag_gam2 = 0.452*eV_from_um_factor
Ag_sig2 = Ag_f2*Ag_plasma_frq**2/Ag_frq2**2
Ag_f3 = 0.011
Ag_frq3 = 8.185*eV_from_um_factor # 0.152 um
Ag_gam3 = 0.065*eV_from_um_factor
Ag_sig3 = Ag_f3*Ag_plasma_frq**2/Ag_frq3**2
Ag_f4 = 0.840
Ag_frq4 = 9.083*eV_from_um_factor # 0.137 um
Ag_gam4 = 0.916*eV_from_um_factor
Ag_sig4 = Ag_f4*Ag_plasma_frq**2/Ag_frq4**2
Ag_f5 = 5.646
Ag_frq5 = 20.29*eV_from_um_factor # 0.061 um
Ag_gam5 = 2.419*eV_from_um_factor
Ag_sig5 = Ag_f5*Ag_plasma_frq**2/Ag_frq5**2
Ag_susc = [mp.DrudeSusceptibility(frequency=Ag_frq0, gamma=Ag_gam0, sigma=Ag_sig0),
mp.LorentzianSusceptibility(frequency=Ag_frq1, gamma=Ag_gam1, sigma=Ag_sig1),
mp.LorentzianSusceptibility(frequency=Ag_frq2, gamma=Ag_gam2, sigma=Ag_sig2),
mp.LorentzianSusceptibility(frequency=Ag_frq3, gamma=Ag_gam3, sigma=Ag_sig3),
mp.LorentzianSusceptibility(frequency=Ag_frq4, gamma=Ag_gam4, sigma=Ag_sig4),
mp.LorentzianSusceptibility(frequency=Ag_frq5, gamma=Ag_gam5, sigma=Ag_sig5)]
Ag = mp.Medium(epsilon=1.0, E_susceptibilities=Ag_susc,
valid_freq_range=metal_range)
Ag.from_um_factor = from_um_factor
return Ag
elif material=="Ag" and paper=="JC":
#------------------------------------------------------------------
# Metal from my own fit
# Wavelength range: 0.1879 - 0.8211 um
# Gold (Au)
# Fit to P.B. Johnson and R.W. Christy, Physical Review B, Vol. 6, pp. 4370-9, 1972
# Reduced range to improve convergence
Ag_JC_range = mp.FreqRange(min=from_um_factor*1e3/821.1,
max=from_um_factor*1e3/187.9)
freq_0 = 1.000000082740371e-10 * from_um_factor
gamma_0 = 0.008487871792800084 * from_um_factor
sigma_0 = 5.545340096443978e+21
freq_1 = 0.0008857703799738381 * from_um_factor
gamma_1 = 5.681495075323141 * from_um_factor
sigma_1 = 7.73865735861863
freq_2 = 3.5889483054274587 * from_um_factor
gamma_2 = 0.5142171316339426 * from_um_factor
sigma_2 = 0.3602917089945181
freq_3 = 96.93018042700993 * from_um_factor
gamma_3 = 0.0002454108091400897 * from_um_factor
sigma_3 = 2.2055854266028954
freq_4 = 4.243182517437894 * from_um_factor
gamma_4 = 1.0115197559416669 * from_um_factor
sigma_4 = 0.5560036781232447
freq_5 = 5.375891811139136 * from_um_factor
gamma_5 = 1.6462280921732821 * from_um_factor
sigma_5 = 0.7492696272872168
Ag_JC_susc = [mp.DrudeSusceptibility(frequency=freq_0, gamma=gamma_0, sigma=sigma_0),
mp.LorentzianSusceptibility(frequency=freq_1, gamma=gamma_1, sigma=sigma_1),
mp.LorentzianSusceptibility(frequency=freq_2, gamma=gamma_2, sigma=sigma_2),
mp.LorentzianSusceptibility(frequency=freq_3, gamma=gamma_3, sigma=sigma_3),
mp.LorentzianSusceptibility(frequency=freq_4, gamma=gamma_4, sigma=sigma_4),
mp.LorentzianSusceptibility(frequency=freq_5, gamma=gamma_5, sigma=sigma_5)]
Ag_JC = mp.Medium(epsilon=1.0,#6.1599,
E_susceptibilities=Ag_JC_susc,
valid_freq_range=Ag_JC_range)
Ag_JC.from_um_factor = from_um_factor
return Ag_JC
elif material=="Ag" and paper=="P":
#------------------------------------------------------------------
# Metals from D. Barchiesi and T. Grosges, J. Nanophotonics, Vol. 8, 08996, 2015
# Wavelength range: 0.4 - 0.8 um
## WARNING: unstable; field divergence may occur
# Silver (Au)
# Fit to E.D. Palik, Handbook of Optical Constants, Academic Press, 1985
metal_visible_range = mp.FreqRange(min=from_um_factor*1e3/800,
max=from_um_factor*1e3/400)
Ag_visible_frq0 = 1*from_um_factor/0.142050162130618
Ag_visible_gam0 = 1*from_um_factor/18.0357292925015
Ag_visible_sig0 = 1
Ag_visible_frq1 = 1*from_um_factor/0.115692151792108
Ag_visible_gam1 = 1*from_um_factor/0.257794324096575
Ag_visible_sig1 = 3.74465275944019
Ag_visible_susc = [mp.DrudeSusceptibility(frequency=Ag_visible_frq0, gamma=Ag_visible_gam0, sigma=Ag_visible_sig0),
mp.LorentzianSusceptibility(frequency=Ag_visible_frq1, gamma=Ag_visible_gam1, sigma=Ag_visible_sig1)]
Ag_visible = mp.Medium(epsilon=0.0067526,
E_susceptibilities=Ag_visible_susc,
valid_freq_range=metal_visible_range)
Ag_visible.from_um_factor = from_um_factor
return Ag_visible
elif material=="Ag":
raise ValueError("No source found for Ag with that name")
else:
raise ValueError("No source found for that material")
#%%
def recognize_material(material_or_index, english=True):
materials_dict = {"Vacuum": 1,
"Water": 1.33,
"Glass": 1.54}
materials_short_dict = {"vac": "Vacuum",
"wat": "Water",
"gl": "Glass"}
materials_spanish_dict = {"Vacuum": "Vacío",
"Water": "Agua",
"Glass": "Vidrio"}
materials_keys = list(materials_dict.keys())
materials_values = list(materials_dict.values())
materials_spanish = list(materials_spanish_dict.values())
if isinstance(material_or_index, str):
for short_key, material in materials_short_dict.items():
if short_key in material_or_index.lower():
return materials_dict[material]
raise ValueError(f"Unrecognized material: must be in {materials_keys}")
elif isinstance(material_or_index, float) or isinstance(material_or_index, int):
try:
if english:
return materials_keys[materials_values.index(material_or_index)]
else:
return materials_spanish[materials_values.index(material_or_index)]
except:
raise ValueError(f"Unrecognized material's index': must be in {materials_values}")
else:
raise ValueError(f"Unrecognized format for material: must be in {materials_dict}")
#%% EPSILON INTERPOLATION
def epsilon_interpoler_from_n(wlen, complex_n):
"""
Generates an interpolation function for epsilon from experimental N data.
Parameters
----------
wlen : np.array, list
Wavelength in nm.
complex_n : np.array, list
Complex refractive index N = n + ik, dimensionless.
Returns
-------
epsilon_function : function
Epsilon interpoler that takes wavelength in nm as argument and returns
complex dielectric constant or relative permitivitty
epsilon = epsilon' + i epsilon'', dimensionless.
"""
n_function = interp1d(wlen, np.real(complex_n), kind="cubic")
k_function = interp1d(wlen, np.imag(complex_n), kind="cubic")
N_function = lambda wl : n_function(wl) + 1j * k_function(wl)
epsilon_function = lambda wl : np.power(N_function(wl), 2)
return epsilon_function
def epsilon_interpoler_from_epsilon(wlen, complex_epsilon):
"""
Generates an interpolation function for epsilon from experimental epsilon data.
Parameters
----------
wlen : np.array, list
Wavelength in nm.
complex_epsilon : np.array, list
Complex dielectric constant or relative permitivitty
epsilon = epsilon' + i epsilon'', dimensionless.
Returns
-------
epsilon_function : function
Epsilon interpoler that takes wavelength in nm as argument and returns
complex dielectric constant or relative permitivitty
epsilon = epsilon' + i epsilon'', dimensionless.
"""
real_function = interp1d(wlen, np.real(complex_epsilon), kind="cubic")
imag_function = interp1d(wlen, np.imag(complex_epsilon), kind="cubic")
epsilon_function = lambda wl : real_function(wl) + 1j * imag_function(wl)
return epsilon_function
def epsilon_function_from_meep(material="Au", paper="JC", from_um_factor=1e-3):
"""
Generates a function for isotropic epsilon from Meep Drude-Lorentz fit data.
Parameters
----------
material="Au" : str
Material's chemical symbol. Available: 'Au' for gold.
paper="JC" : str
Paper source of experimental data. Available: 'JC' for Johnson
and Christy, 'R' for Rakic, 'P' for Palik.
from_um_factor=1e-3 : float, optional
Meep factor of length scale implying 1 Meep length unit is
from_um_factor length units in μm. If provided, the function takes
wavelength in Meep units instead of nm.
Returns
-------
epsilon_function : function
Epsilon function that takes wavelength in nm or Meep units as argument
and returns complex dielectric constant or relative permitivitty
epsilon = epsilon' + i epsilon'', dimensionless.
Raises
------
ValueError : "Material should either be..."
When the desired material isn't available.
ValueError : "Reference paper should either be..."
When the desired paper reference of experimental data isn't available.
ValueError : "Data should either be from..."
When the desired data source isn't available.
ValueError : "Experimental data couldn't be found. Sorry!"
When the combination of parameters causes the data not to be found.
"""
available_materials = {"Au": "gold", "Ag": "silver"}
available_papers = {"JC": "Johnson & Christy", "R": "Rakic", "P": "Palik"}
if material not in available_materials.keys():
error = "Data should either be from "
error += vu.enumerate_string(vu.join_strings_dict(available_materials),
"or", True)
raise ValueError(error)
if paper not in available_papers.keys():
error = "Reference paper for experimental data should either be "
error += vu.enumerate_string(vu.join_strings_dict(available_papers),
"or", True)
raise ValueError(error)
medium = import_medium(material,
paper=paper) # This one has from_um_factor=1
print(f"Data loaded using Meep and '{paper}'")
epsilon_function = lambda wlen : medium.epsilon(1/(wlen*from_um_factor))[0,0]
# To pass it to the medium, I transform wavelength from nm (or Meep units) to um
wlen_range = 1/(np.flip(np.array([*medium.valid_freq_range]))*from_um_factor)
epsilon_function._wlen_range_ = wlen_range
epsilon_function._from_um_factor_ = from_um_factor
return epsilon_function
def epsilon_data_from_file(material="Au", paper="JC", reference="RIinfo"):
"""
Loads experimental data for epsilon from file.
Parameters
----------
material="Au" : str
Material's chemical symbol. Available: 'Au' for gold.
paper="JC" : str
Paper source of experimental data. Available: 'JC' for Johnson
and Christy, 'R' for Rakic.
reference="RIinfo" : str
Reference from which the data was extracted, for example a web page.
Available: 'RIinfo' for 'www.refractiveindex.info'
Returns
-------
wavelength : np.array
Wavelength values in nm.
epsilon : np.array
Complex epsilon data, epsilon = epsilon' + i epsilon'', dimensionless.
Raises
------
ValueError : "Material should either be..."
When the desired material isn't available.
ValueError : "Reference paper should either be..."
When the desired paper reference of experimental data isn't available.
ValueError : "Data should either be from..."
When the desired data source isn't available.
ValueError : "Experimental data couldn't be found. Sorry!"
When the combination of parameters causes the data not to be found.
"""
available_materials = {"Au": "gold", "Ag": "silver"}
available_papers = {"JC": "Johnson & Christy",
"R": "Rakic"}
available_references = {"RIinfo": "www.refractiveindex.info"}
if material not in available_materials.keys():
error = "Data should either be from "
error += vu.enumerate_string(vu.join_strings_dict(available_materials),
"or", True)
raise ValueError(error)
if paper not in available_papers.keys():
error = "Reference paper for experimental data should either be "
error += vu.enumerate_string(vu.join_strings_dict(available_papers),
"or", True)
raise ValueError(error)
if reference not in available_references.keys():
error = "Experimental data should either be extracted from "
error += vu.enumerate_string(vu.join_strings_dict(available_references),
"or", True)
raise ValueError(error)
data_series = os.listdir(os.path.join(syshome, 'SupportFiles', 'MaterialsData'))
try:
data_files = []
for df in data_series:
if (f"_{paper}_") in df and material in df and reference in df:
data_files.append( os.path.join(syshome, 'SupportFiles', 'MaterialsData', df) )
except:
raise ValueError("Experimental data couldn't be found. Sorry!")
file = data_files[0]
data = np.loadtxt(file)
wavelength = data[:,0]
if 'N' in file:
epsilon = np.power(data[:,1] + 1j*data[:,2], 2)
print(f"Refractive index data loaded from '{file}'")
elif "eps" in file.lower():
epsilon = data[:,1] + 1j*data[:,2]
print(f"Epsilon data loaded from '{file}'")
else:
raise ValueError("Experimental data couldn't be recognized. Sorry!")
return wavelength, epsilon
def epsilon_function_from_file(material="Au", paper="JC", reference="RIinfo",
from_um_factor=1e-3, plot=False):
"""
Generates an interpolation function for epsilon from experimental data.
Parameters
----------
material="Au" : str
Material's chemical symbol. Available: 'Au' for gold.
paper="JC" : str
Paper source of experimental data. Available: 'JC' for Johnson
and Christy, 'R' for Rakic.
reference="RIinfo" : str
Reference from which the data was extracted, for example a web page.
Available: 'RIinfo' for 'www.refractiveindex.info'
from_um_factor=1e-3 : float, optional
Meep factor of length scale implying 1 Meep length unit is
from_um_factor length units in μm. If provided, the function takes
wavelength in Meep units instead of nm.
plot=False : bool
Parameter that enables a plot of the interpolation and the data used.
Returns
-------
epsilon_function : function
Epsilon function that takes wavelength in nm or Meep units as argument
and returns complex dielectric constant or relative permitivitty
epsilon = epsilon' + i epsilon'', dimensionless.
Raises
------
ValueError : "Material should either be..."
When the desired material isn't available.
ValueError : "Reference paper should either be..."
When the desired paper reference of experimental data isn't available.
ValueError : "Data should either be from..."
When the desired data source isn't available.
ValueError : "Experimental data couldn't be found. Sorry!"
When the combination of parameters causes the data not to be found.
"""
wavelength, epsilon_data = epsilon_data_from_file(material, paper, reference)
meep_wlen = wavelength / (1e3 * from_um_factor)
# Change wavelength units if necessary
# Going from nm to Meep units
epsilon_function = epsilon_interpoler_from_epsilon(meep_wlen, epsilon_data)
meep_wlen_range = [min(meep_wlen), max(meep_wlen)]
epsilon_function._wlen_range_ = np.array(meep_wlen_range)
epsilon_function._from_um_factor_ = from_um_factor
if plot:
wlen_range = [min(wavelength), max(wavelength)]
wlen_long = np.linspace(*wlen_range, 500)
epsilon_interpolated = epsilon_function(wlen_long)
functions = [np.abs, np.real, np.imag]
titles = ["Absolute value", "Real part", "Imaginary part"]
ylabels = [r"|$\epsilon$| [nm$^3$]", r"Re($\epsilon$) [nm$^3$]",
r"Im($\epsilon$) [nm$^3$]"]
nplots = len(functions)
fig = plt.figure(figsize=(nplots*6.4, 6.4))
axes = fig.subplots(ncols=nplots)
max_value = []
min_value = []
for ax, f, t, y in zip(axes, functions, titles, ylabels):
ax.set_title(t)
ax.plot(wavelength, f(epsilon_data), "ob", label="Data")
ax.plot(wlen_long, f(epsilon_interpolated), "-r", label="Interpolation")
ax.xaxis.set_label_text(r"Wavelength $\lambda$ [nm]")
ax.yaxis.set_label_text(y)
ax.legend()
ax.set_xlim(*wlen_range)
max_value.append(max([max(f(epsilon_data)), max(f(epsilon_interpolated))]))
min_value.append(min([min(f(epsilon_data)), min(f(epsilon_interpolated))]))
for ax in axes: ax.set_ylim([min(min_value)-.1*(max(max_value)-min(min_value)),
max(max_value)+.1*(max(max_value)-min(min_value))])
axes[0].text(-.1, -.13, f"{material}{paper}{reference}",
transform=axes[0].transAxes)
return epsilon_function
def epsilon_function(material="Au", paper="JC", reference="RIinfo",
from_um_factor=1e-3):
"""
Generates an interpolation function for epsilon from experimental data.
Parameters
----------
material="Au" : str
Material's chemical symbol. Available: 'Au' for gold.
paper="JC" : str
Reference paper of experimental data. Available: 'JC' for Johnson and
Christy, 'R' for Rakic, 'P' for Palik.
reference="RIinfo" : str
Reference from which the data was extracted, for example a web page.
Available: 'RIinfo' for 'www.refractiveindex.info' and 'Meep' for Meep
materials library that uses a Drude-Lorentz model to fit data.
from_um_factor=1e-3 : float, optional
Meep factor of length scale implying 1 Meep length unit is
from_um_factor length units in μm. If provided, the function takes
wavelength in Meep units instead of nm.
Returns
-------
epsilon_function : function
Epsilon function that takes wavelength in nm or Meep units as argument
and returns complex dielectric constant or relative permitivitty
epsilon = epsilon' + i epsilon'', dimensionless.
Raises
------
ValueError : "Material should either be..."
When the desired material isn't available.
ValueError : "Reference paper should either be..."
When the desired paper reference of experimental data isn't available.
ValueError : "Data should either be from..."
When the desired data source isn't available.
ValueError : "Experimental data couldn't be found. Sorry!"
When the combination of parameters causes the data not to be found.
"""
available_references = {"RIinfo": "www.refractiveindex.info",
"Meep": "Meep materials library & Drude-Lorentz fit"}
if reference not in available_references.keys():
error = "Data should either be from"
error += vu.enumerate_string(vu.join_strings_dict(available_references),
"or", True)
raise ValueError(error)
if reference=="Meep":
epsilon_function = epsilon_function_from_meep(material, paper,
from_um_factor)
else:
epsilon_function = epsilon_function_from_file(material, paper,
reference,
from_um_factor)
return epsilon_function
#%% REFRACTIVE INDEX INTERPOLATION
def n_interpoler_from_n(wlen, complex_n):
"""
Generates an interpolation function for N from experimental N data.
Parameters
----------
wlen : np.array, list
Wavelength in nm.
complex_n : np.array, list
Complex refractive index N = n + ik, dimensionless.
Returns
-------
N_function : function
Refractive index N interpoler that takes wavelength in nm as argument
and returns complex refractive index N = n + i k, dimensionless.
"""
n_function = interp1d(wlen, np.real(complex_n), kind="cubic")
k_function = interp1d(wlen, np.imag(complex_n), kind="cubic")
N_function = lambda wl : n_function(wl) + 1j * k_function(wl)
return N_function
def n_interpoler_from_epsilon(wlen, complex_epsilon):
"""
Generates an interpolation function for N from experimental epsilon data.
Parameters
----------
wlen : np.array, list
Wavelength in nm.
complex_epsilon : np.array, list
Complex dielectric constant or relative permitivitty
epsilon = epsilon' + i epsilon'', dimensionless.
Returns
-------
N_function : function
Refractive index N interpoler that takes wavelength in nm as argument
and returns complex refractive index N = n + i k, dimensionless.
"""
real_function = interp1d(wlen, np.real(complex_epsilon), kind="cubic")
imag_function = interp1d(wlen, np.imag(complex_epsilon), kind="cubic")
epsilon_function = lambda wl : real_function(wl) + 1j * imag_function(wl)
N_function = lambda wl : np.sqrt(epsilon_function(wl))
return N_function
def n_function_from_meep(material="Au", paper="JC", from_um_factor=1e-3):
"""
Generates a function for isotropic N from Meep Drude-Lorentz fit data.
Parameters
----------
material="Au" : str
Material's chemical symbol. Available: 'Au' for gold.
paper="JC" : str
Paper source of experimental data. Available: 'JC' for Johnson
and Christy, 'R' for Rakic, 'P' for Palik.
from_um_factor=1e-3 : float, optional
Meep factor of length scale implying 1 Meep length unit is
from_um_factor length units in μm. If provided, the function takes
wavelength in Meep units instead of nm.
Returns
-------
N_function : function
Refractive index N interpoler that takes wavelength in nm as argument
and returns complex refractive index N = n + i k, dimensionless.
Raises
------
ValueError : "Material should either be..."
When the desired material isn't available.
ValueError : "Reference paper should either be..."
When the desired paper reference of experimental data isn't available.
ValueError : "Data should either be from..."
When the desired data source isn't available.
ValueError : "Experimental data couldn't be found. Sorry!"
When the combination of parameters causes the data not to be found.
"""
available_materials = {"Au": "gold", "Ag": "silver"}
available_papers = {"JC": "Johnson & Christy", "R": "Rakic", "P": "Palik"}
if material not in available_materials.keys():
error = "Data should either be from "
error += vu.enumerate_string(vu.join_strings_dict(available_materials),
"or", True)
raise ValueError(error)
if paper not in available_papers.keys():
error = "Reference paper for experimental data should either be "
error += vu.enumerate_string(vu.join_strings_dict(available_papers),
"or", True)
raise ValueError(error)
medium = import_medium(material,
paper=paper) # This one has from_um_factor=1
print(f"Data loaded using Meep and '{paper}'")
epsilon_function = lambda wlen : medium.epsilon(1/(wlen*from_um_factor))[0,0]
# To pass it to the medium, I transform wavelength from nm (or Meep units) to um
N_function = lambda wlen : np.sqrt(epsilon_function(wlen))
wlen_range = 1/(np.flip(np.array([*medium.valid_freq_range]))*from_um_factor)
N_function._wlen_range_ = wlen_range
N_function._from_um_factor_ = from_um_factor
return N_function
def n_data_from_file(material="Au", paper="JC", reference="RIinfo"):
"""
Loads experimental data for epsilon from file.
Parameters
----------
material="Au" : str
Material's chemical symbol. Available: 'Au' for gold.
paper="JC" : str
Paper source of experimental data. Available: 'JC' for Johnson
and Christy, 'R' for Rakic.
reference="RIinfo" : str
Reference from which the data was extracted, for example a web page.
Available: 'RIinfo' for 'www.refractiveindex.info'
Returns
-------
wavelength : np.array
Wavelength values in nm.
N : np.array
Refractive index N data N = n + i k, dimensionless.
Raises
------
ValueError : "Material should either be..."
When the desired material isn't available.
ValueError : "Reference paper should either be..."
When the desired paper reference of experimental data isn't available.
ValueError : "Data should either be from..."
When the desired data source isn't available.
ValueError : "Experimental data couldn't be found. Sorry!"
When the combination of parameters causes the data not to be found.
"""
available_materials = {"Au": "gold", "Ag": "silver"}
available_papers = {"JC": "Johnson & Christy",
"R": "Rakic"}
available_references = {"RIinfo": "www.refractiveindex.info"}
if material not in available_materials.keys():
error = "Data should either be from "
error += vu.enumerate_string(vu.join_strings_dict(available_materials),
"or", True)
raise ValueError(error)
if paper not in available_papers.keys():
error = "Reference paper for experimental data should either be "
error += vu.enumerate_string(vu.join_strings_dict(available_papers),
"or", True)
raise ValueError(error)
if reference not in available_references.keys():
error = "Experimental data should either be extracted from "
error += vu.enumerate_string(vu.join_strings_dict(available_references),
"or", True)
raise ValueError(error)
data_series = os.listdir(os.path.join(syshome, 'SupportFiles', 'MaterialsData'))
try:
data_files = []
for df in data_series:
if (f"_{paper}_") in df and material in df and reference in df:
data_files.append( os.path.join(syshome, 'SupportFiles', 'MaterialsData', df) )
except:
raise ValueError("Experimental data couldn't be found. Sorry!")
file = data_files[0]
data = np.loadtxt(file)
wavelength = data[:,0]
if 'N' in file:
N = data[:,1] + 1j*data[:,2]
print(f"Refractive index data loaded from '{file}'")
elif "eps" in file.lower():
N = np.sqrt(data[:,1] + 1j*data[:,2])
print(f"Epsilon data loaded from '{file}'")
else:
raise ValueError("Experimental data couldn't be recognized. Sorry!")
return wavelength, N
def n_function_from_file(material="Au", paper="JC", reference="RIinfo",
from_um_factor=1e-3, plot=False):
"""
Generates an interpolation function for N from experimental data.
Parameters
----------
material="Au" : str
Material's chemical symbol. Available: 'Au' for gold.
paper="JC" : str
Paper source of experimental data. Available: 'JC' for Johnson
and Christy, 'R' for Rakic.
reference="RIinfo" : str
Reference from which the data was extracted, for example a web page.
Available: 'RIinfo' for 'www.refractiveindex.info'
from_um_factor=1e-3 : float, optional
Meep factor of length scale implying 1 Meep length unit is
from_um_factor length units in μm. If provided, the function takes
wavelength in Meep units instead of nm.
plot=False : bool
Parameter that enables a plot of the interpolation and the data used.
Returns
-------
N_function : function
Refractive index N interpoler that takes wavelength in nm or Meep units
as argument and returns complex refractive index N = n + i k,
dimensionless.
Raises
------
ValueError : "Material should either be..."
When the desired material isn't available.
ValueError : "Reference paper should either be..."
When the desired paper reference of experimental data isn't available.
ValueError : "Data should either be from..."
When the desired data source isn't available.
ValueError : "Experimental data couldn't be found. Sorry!"
When the combination of parameters causes the data not to be found.
"""
wavelength, N_data = n_data_from_file(material, paper, reference)
meep_wlen = wavelength / (1e3 * from_um_factor)
# Change wavelength units if necessary
# Going from nm to Meep units
N_function = n_interpoler_from_n(meep_wlen, N_data)
meep_wlen_range = [min(meep_wlen), max(meep_wlen)]
N_function._wlen_range_ = np.array(meep_wlen_range)