calc-expansion-coeffs-spectra.py 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. #!/usr/bin/env python
  2. # -*- coding: UTF-8 -*-
  3. #
  4. # Copyright (C) 2018 Konstantin Ladutenko <kostyfisik@gmail.com>
  5. #
  6. # This file is part of python-scattnlay
  7. #
  8. # This program is free software: you can redistribute it and/or modify
  9. # it under the terms of the GNU General Public License as published by
  10. # the Free Software Foundation, either version 3 of the License, or
  11. # (at your option) any later version.
  12. #
  13. # This program is distributed in the hope that it will be useful,
  14. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. # GNU General Public License for more details.
  17. #
  18. # The only additional remark is that we expect that all publications
  19. # describing work using this software, or all commercial products
  20. # using it, cite the following reference:
  21. # [1] O. Pena and U. Pal, "Scattering of electromagnetic radiation by
  22. # a multilayered sphere," Computer Physics Communications,
  23. # vol. 180, Nov. 2009, pp. 2348-2354.
  24. #
  25. # You should have received a copy of the GNU General Public License
  26. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  27. # This script reproduces Fig.2a from "Nonradiating anapole modes in
  28. # dielectric nanoparticles" by Miroshnichenko, Andrey E. et al in
  29. # Nature Communications DOI:10.1038/ncomms9069
  30. from scattnlay import fieldnlay, scattnlay, expansioncoeffs, scattcoeffs
  31. import cmath
  32. import matplotlib.pyplot as plt
  33. import numpy as np
  34. x = np.ones((1), dtype = np.float64)
  35. m = np.ones((1), dtype = np.complex128)
  36. WL=550 #nm
  37. core_r = 180
  38. index_NP = 4.0
  39. from_R = 120/2.0
  40. to_R = 240/2.0
  41. npts = 151
  42. ext = ".png"
  43. npts = 351
  44. # ext = ".pdf"
  45. comment='bulk-NP-WL'+str(WL)
  46. val_all = []
  47. all_R = np.linspace(from_R, to_R, npts)
  48. for core_r in all_R:
  49. x[0] = 2.0*np.pi*core_r/WL
  50. m[0] = index_NP
  51. terms, Qext, Qsca, Qabs, Qbk, Qpr, g, Albedo, S1, S2 = scattnlay(np.array([x]), np.array([m]))
  52. terms, an, bn = scattcoeffs(np.array([x]), np.array([m]),terms)
  53. terms, aln, bln, cln, dln = expansioncoeffs(np.array([x]), np.array([m]), terms)
  54. order = 0
  55. val_all.append([#Qsca,
  56. np.abs(aln[0][-1][order]),np.abs(dln[0][0][order])
  57. #,np.abs(an[0][order])
  58. ])
  59. #print( )
  60. val_all = np.array(val_all)
  61. #print()
  62. #print(terms, np.abs(dln))
  63. fig, axs = plt.subplots(1,1)#, sharey=True, sharex=True)
  64. fig.tight_layout()
  65. fig.subplots_adjust(hspace=0.3, wspace=-0.1)
  66. all_R = all_R*2
  67. plt.plot(all_R, val_all[:,0],label="electric dipole, scatt.")
  68. plt.plot(all_R, val_all[:,1],label="electric dipole, internal")
  69. plt.legend()
  70. #plt.plot(all_R, val_all[:,2])
  71. plt.ylim(0,4)
  72. plt.xlabel("D, nm")
  73. plt.ylabel("Mie coefficients")
  74. plt.savefig(comment+"-R"+str(int(round(x[-1]*WL/2.0/np.pi)))+ext,
  75. pad_inches=0.02, bbox_inches='tight')
  76. plt.show()
  77. plt.clf()
  78. plt.close()
  79. #print("end")