def btAddMatClick(master=None): global w, root, material dial = GenerateMaterialDialog(root) if dial.result is None: return name, conc = dial.result if name == 'alloyAuAg': try: mat = AlloyAuAg(conc) except Exception as err: tkMessageBox.showerror('Error', err) return else: try: # try create material mat = Material(name) except Exception as err: tkMessageBox.showerror('Error', err) return key = gen_mat_key(True) add_material(key, mat) update_materials_tree()
from mstm_studio.nearfield import NearField from mstm_studio.mstm_spectrum import ExplicitSpheres from mstm_studio.alloy_AuAg import AlloyAuAg mat = AlloyAuAg(x_Au=0.0) # silver material nf = NearField(wavelength=385) # near the resonance nf.environment_material = 1.5 # glass matrix nf.set_plane(plane='xz', hmin=-10, hmax=20, vmin=-15, vmax=15, step=0.25) spheres = ExplicitSpheres(2, [0, 0, 0, 5, 0, 0, 11, 3], mat_filename=2 * [mat]) nf.set_spheres(spheres) nf.simulate() nf.plot()
from mstm_studio.alloy_AuAg import AlloyAuAg au1ag2 = AlloyAuAg(x_Au=1. / 3) fig, axs = au1ag2.plot() fig.savefig('mat_au1ag2.png', bbox_inches='tight')
def _eps(self, omega, x_au): drude, cp1, cp2 = self._drude(omega, x_au) kk = drude + cp1 + cp2 eps1 = kk.real eps2 = kk.imag return eps1, eps2 def get_n(self, wls): omega = h * c / wls eps1, eps2 = self._eps(omega, self.x_Au) n = (eps1 + 1j * eps2)**0.5 return n.real def get_k(self, wls): omega = h * c / wls eps1, eps2 = self._eps(omega, self.x_Au) n = (eps1 + 1j * eps2)**0.5 return n.imag if __name__ == '__main__': print('Alloy material test') from mstm_studio.alloy_AuAg import AlloyAuAg mat = AlloyAuAg(0.5) print(mat) # mat.plot() print('n, k = ', mat.get_n(800), mat.get_k(800)) input('Press enter') mat.plot()
self._M = np.zeros(shape=(len(self.wavelengths), len(self.diameters))) self.number_of_params = 2 # else will get error on a check for i, diameter in enumerate(self.diameters): self._M[:, i] = super( MieLognormSpheres, self).calculate(values=[1.0, diameter / 2.0]) self.number_of_params = 3 # ugly, but everything has a price print('Building cache... done') dD = np.ediff1d(self.diameters, to_begin=1e-3) distrib = self.lognorm(self.diameters, values[1], values[2]) result = np.dot(self._M, distrib * dD) return values[0] * result if __name__ == '__main__': # tests come here # ~ cb = ConstantBackground(name='const', wavelengths=[300,400,500,600,700,800]) # ~ print(cb.calculate([3])) # ~ cb.plot([3]) # ~ mie = MieSingleSphere(name='mie', wavelengths=np.linspace(300,800,50)) # ~ mie = MieLognormSpheres(name='mie', wavelengths=np.linspace(300,800,50)) from mstm_studio.contributions import MieLognormSpheresCached from mstm_studio.alloy_AuAg import AlloyAuAg mie = MieLognormSpheresCached(name='mie', wavelengths=np.linspace(300, 800, 50)) mie.set_material(AlloyAuAg(x_Au=1), 1.66) mie.plot([1, 1.5, 0.5]) # scale mu sigma print('See you!')
#!/usr/bin/python # -*- coding: utf-8 -*- from mstm_studio.contributions import MieLognormSpheres from mstm_studio.alloy_AuAg import AlloyAuAg import numpy as np mie = MieLognormSpheres(name='mie', wavelengths=np.linspace(300, 800, 51)) mie.set_material(AlloyAuAg(x_Au=1), 1.5) # golden sphere in glass values = [1, 1.5, 0.5] # scale, mu, sigma fig, _ = mie.plot(values) fig.savefig('mie_contrib.png', bbox_inches='tight') mie.MAX_DIAMETER_TO_PLOT = 20 # 100 nm is by default fig, _ = mie.plot_distrib(values) fig.savefig('mie_distrib.png', bbox_inches='tight')
from mstm_studio.alloy_AuAg import AlloyAuAg from mstm_studio.contrib_spheroid import SpheroidSP import numpy as np wls = np.linspace(300, 800, 51) # range for calculation, in nm SIZE = 20 # nm, particle diameter ASPECT = 1.5 # a / c = horiz. axis / rot. axis sph = SpheroidSP(wavelengths=wls) # create object sph.set_material(AlloyAuAg(x_Au=1), 1.5) # particle and matrix refr. ind. fig, axs = sph.plot_shape([1, SIZE, ASPECT]) fig.savefig('spheroid_shape.png', bbox_inches='tight') ext_sph = sph.calculate([1, SIZE, ASPECT]) fig, axs = sph.plot([1, SIZE, ASPECT]) # scale, diameter, aspect fig.savefig('spheroid_ext.png', bbox_inches='tight')
#!/usr/bin/python # -*- coding: utf-8 -*- from mstm_studio.alloy_AuAg import AlloyAuAg from mstm_studio.contributions import LinearBackground, MieLognormSpheresCached from mstm_studio.mstm_spectrum import ExplicitSpheres, Profiler from mstm_studio.fit_spheres_optic import Fitter, FixConstraint, ConcentricConstraint fitter = Fitter( exp_filename='experiment.dat') # load experiment from tabbed file fitter.set_extra_contributions( [LinearBackground(fitter.wls)], # wavelengths from experiment [0.02, 0.0001]) # initial values for a, b spheres = ExplicitSpheres(2, [0, 0, 0, 10, 0, 0, 0, 12], mat_filename=[AlloyAuAg(1.), AlloyAuAg(0.)]) fitter.set_spheres(spheres) # core-shell Au@Ag particle fitter.set_matrix(1.5) # in glass fitter.add_constraint(ConcentricConstraint(0, 1)) # 0 -> 1 fitter.add_constraint(FixConstraint('x00')) fitter.add_constraint(FixConstraint('y00')) fitter.add_constraint(FixConstraint('z00')) # run fit (takes ~200 seconds on 2GHz CPU) with Profiler(): fitter.run() fitter.report_result() # plot results
return s if __name__ == '__main__': fitter = Fitter('../example/experiment.dat') # test Mie fit from mstm_studio.contributions import LinearBackground, MieSingleSphere, MieLognormSpheresCached from mstm_studio.alloy_AuAg import AlloyAuAg fitter.set_extra_contributions([ LinearBackground(fitter.wls, 'lin bkg'), MieLognormSpheresCached(fitter.wls, 'LN Mie') ], [0.02, -0.001, 0.1, 1.5, 0.5]) #~ MieSingleSphere(fitter.wls, 'Mie')], #~ [0.02, -0.001, #~ 0.1, 10]) fitter.extra_contributions[1].set_material(AlloyAuAg(1.), 1.66) fitter.extra_contributions[1].plot([0.1, 1.5, 0.5]) fitter.extra_contributions[1].plot_distrib([0.1, 1.5, 0.5]) #~ fitter.extra_contributions[1].plot([0.1, 10]) fitter.set_spheres(None) # no spheres, no mstm runs fitter.report_freedom() input('Press enter to run peak fitting') fitter.run() fitter.report_result() input('Press enter to continue') # test peak fit from contributions import LinearBackground, LorentzPeak fitter.set_extra_contributions([ LinearBackground(fitter.wls, 'lin bkg'), LorentzPeak(fitter.wls, 'lorentz peak') ], [0.02, -0.001, 100, 550, 50])
from mstm_studio.mstm_spectrum import LogNormalSpheres from mstm_studio.alloy_AuAg import AlloyAuAg spheres = LogNormalSpheres(9, 10.0, 0.2, 5., AlloyAuAg(1.)) while spheres.check_overlap(): print('spheres are overlapping, regenerating...') spheres = LogNormalSpheres(9, 10.0, 0.2, 5., AlloyAuAg(1.)) print(spheres.a) # ~ Box size estimated as: 77.0 nm # ~ Desired number of particles: 9 # ~ Number of particles in a box: 8 # ~ Resulted number of particles: 8 # ~ spheres are overlapping, regenerating... # ~ Box size estimated as: 77.0 nm # ~ Desired number of particles: 9 # ~ Number of particles in a box: 8 # ~ Resulted number of particles: 8 # ~ [ 9.307773 8.61185299 9.92867988 8.84140858 9.87175352 8.71090184 # ~ 9.71505038 12.40459688]
#!/usr/bin/python # -*- coding: utf-8 -*- from mstm_studio.alloy_AuAg import AlloyAuAg from mstm_studio.contributions import LinearBackground, MieLognormSpheresCached from mstm_studio.fit_spheres_optic import Fitter fitter = Fitter( exp_filename='experiment.dat') # load experiment from tabbed file fitter.set_extra_contributions( [ LinearBackground(fitter.wls), # wavelengths from experiment MieLognormSpheresCached(fitter.wls, 'LN Mie') ], # cached version for faster fittting [0.02, 0.0001, 0.1, 2.0, 0.4]) # initial values for a, b, C, mu, sigma fitter.extra_contributions[1].set_material(AlloyAuAg(1.), 1.5) # gold particles in glass fitter.set_spheres(None) # no spheres - no slow MSTM runs # run fit (takes ~20 seconds on 2GHz CPU) fitter.run() fitter.report_result() # plot results import matplotlib.pyplot as plt plt.plot(fitter.wls, fitter.exp, 'ro', label='exp.') plt.plot(fitter.wls, fitter.calc, 'b-', label='fit') plt.xlabel('Wavelength, nm') plt.ylabel('Exctinction, a.u.') plt.legend() plt.savefig('fit_by_Mie.png', bbox_inches='tight')
print(s) return s if __name__ == '__main__': fitter = Fitter('../example/experiment.dat') # test Mie fit from mstm_studio.contributions import LinearBackground, MieSingleSphere, MieLognormSpheresCached from mstm_studio.alloy_AuAg import AlloyAuAg fitter.set_extra_contributions([LinearBackground(fitter.wls, 'lin bkg'), MieLognormSpheresCached(fitter.wls, 'LN Mie')], [0.02, -0.001, 0.1, 1.5, 0.5]) #~ MieSingleSphere(fitter.wls, 'Mie')], #~ [0.02, -0.001, #~ 0.1, 10]) fitter.extra_contributions[1].set_material(AlloyAuAg(1.), 1.66) fitter.extra_contributions[1].plot([0.1, 1.5, 0.5]) fitter.extra_contributions[1].plot_distrib([0.1, 1.5, 0.5]) #~ fitter.extra_contributions[1].plot([0.1, 10]) fitter.set_spheres(None) # no spheres, no mstm runs fitter.report_freedom() input('Press enter to run peak fitting') fitter.run() fitter.report_result() contribs = fitter.get_extra_contributions() print(contribs) input('Press enter to continue') # test peak fit from contributions import LinearBackground, LorentzPeak fitter.set_extra_contributions([LinearBackground(fitter.wls, 'lin bkg'), LorentzPeak(fitter.wls, 'lorentz peak')],