def __init__(self,d=[],rho=[],sigma=[],comp=[],elem_z=[],theta=[],params={}): """ Parameters: ----------- All these should be num arrays, dtype = double * d array of layer thicknesses (angstroms) * rho array of corresponding densities (g/cm^3) * sigma array of interface roughnesses (angstroms) * comp is the composition array * elem_z are the Z values of each element in the model * theta array of theta values (degrees) * params is a dictionary of model parameters (see set_params) """ self.iff = Ifeffit(screen_echo = 0) self.nlayer = 0 self.nelem = 0 self.nthet = 0 self.fp = [] self.fpp = [] self.amu = [] self.mu_at = [] self._init_params() # some flags self._init_en = True self._init_fy = True self._init_carr = True self._init_ptr = True # init self.init_model(d=d,rho=rho,sigma=sigma,comp=comp,elem_z=elem_z,theta=theta) self.set_params(**params)
def __init__(self, d=[], rho=[], sigma=[], comp=[], elem_z=[], theta=[], params={}): """ Parameters: ----------- All these should be num arrays, dtype = double * d array of layer thicknesses (angstroms) * rho array of corresponding densities (g/cm^3) * sigma array of interface roughnesses (angstroms) * comp is the composition array * elem_z are the Z values of each element in the model * theta array of theta values (degrees) * params is a dictionary of model parameters (see set_params) """ self.iff = Ifeffit(screen_echo=0) self.nlayer = 0 self.nelem = 0 self.nthet = 0 self.fp = [] self.fpp = [] self.amu = [] self.mu_at = [] self._init_params() # some flags self._init_en = True self._init_fy = True self._init_carr = True self._init_ptr = True # init self.init_model(d=d, rho=rho, sigma=sigma, comp=comp, elem_z=elem_z, theta=theta) self.set_params(**params)
def __init__(self, load=None): self.root = Tk() # launch Ifeffit in screen_echo = 0 mode Ifeffit.__init__(self, screen_echo = 0) self.root.option_add('*font', ('Helvetica', 12)) self.drawsplash(self.root) Pmw.initialise(self.root) self.root.withdraw() self.root.title('G.I.Feffit') self.inp_buff = [] # command buffer self.ind_ = 0 # index in inp_buff self.plot_opts = self.reset_plot_opts() self.prefs = {} self.feff_paths= {} self.ask_exit = 1 self.iff_com = self.do_ifeffit self.balloon = Pmw.Balloon(self.root) self.inp_buff.append("") ; self.createMenubar(self.root) self.createMainWin(self.root) self.root.mainloop()
class RefModel(_XrayRefl): """ Reflectivity model See wrxrr._XrayRefl for details regarding the initialization - we need to make sure that the arrays/data are appropriate to pass to the c library. """ def __init__(self,d=[],rho=[],sigma=[],comp=[],elem_z=[],theta=[],params={}): """ Parameters: ----------- All these should be num arrays, dtype = double * d array of layer thicknesses (angstroms) * rho array of corresponding densities (g/cm^3) * sigma array of interface roughnesses (angstroms) * comp is the composition array * elem_z are the Z values of each element in the model * theta array of theta values (degrees) * params is a dictionary of model parameters (see set_params) """ self.iff = Ifeffit(screen_echo = 0) self.nlayer = 0 self.nelem = 0 self.nthet = 0 self.fp = [] self.fpp = [] self.amu = [] self.mu_at = [] self._init_params() # some flags self._init_en = True self._init_fy = True self._init_carr = True self._init_ptr = True # init self.init_model(d=d,rho=rho,sigma=sigma,comp=comp,elem_z=elem_z,theta=theta) self.set_params(**params) ########################################################################### def init_model(self, d=None, rho=None, sigma=None, comp=None, elem_z=None, theta=None): """ Initialize/modify model data and arrays. Note that arrays should be passed in as numpy arrays, and will be assigned by reference!! See wrxrr._XrayRefl._init_model for array creation """ if d != None: self.nlayer = len(d) if (d.dtype == DTYPE): self.d = d else: raise exceptions.ValueError self._init_carr = True self._init_ptr = True # if rho != None: if len(rho) != self.nlayer: raise exceptions.ValueError if (rho.dtype == DTYPE): self.rho = rho else: raise exceptions.ValueError self._init_ptr = True # if sigma != None: if len(sigma) != self.nlayer-1: raise exceptions.ValueError if (sigma.dtype == DTYPE): self.sigma = sigma else: raise exceptions.ValueError self._init_ptr = True # if comp != None: if (comp.dtype != DTYPE): raise exceptions.ValueError nel,nz = comp.shape if nz != self.nlayer: raise exceptions.ValueError self.comp = comp if nel != self.nelem: self.nelem = nel self._init_en = True self._init_fy = True self._init_ptr = True # if elem_z != None: if len(elem_z) != self.nelem: raise exceptions.ValueError if (elem_z.dtype == DTYPE): self.elem_z = elem_z else: raise exceptions.ValueError self._init_en = True self._init_fy = True self._init_ptr = True # if theta != None: self.nthet = len(theta) if (theta.dtype == DTYPE): self.theta = theta else: raise exceptions.ValueError self._init_carr = True self._init_ptr = True ########################################################## def set_params(self,**params): """ Parameters: ----------- * energy (eV) is the incident energy # calc_params[0] * wconv (degrees) is the concolution width # calc_params[1] * slen (mm) is the sample length # calc_params[2] * bvert (mm) is the vertical beam dim # calc_params[3] * bhorz (mm) is the horizontal beam dim # calc_params[4] * aflag is a flag for area calcs # calc_params[6] * fyidx is the index of the element for FY # calc_params[6] * fyenergy (eV) is the energy of FY # calc_params[7] * adet (deg) is the angle of the detector # calc_params[8] * tnorm (deg) is the theta for normalizatio # calc_params[9] * rflag is the roughness flag # calc_params[10] * delz (ang) is the delta z for integration # calc_params[11] * pdepth is the substrate FY clac flag # calc_params[12] * rscale is a scale factor for reflectivity # calc_params[13] """ if len(params) == 0: return if params.has_key('energy'): self.calc_params[0] = params['energy'] self._init_en = True if params.has_key('wconv'): self.calc_params[1] = params['wconv'] if params.has_key('slen'): self.calc_params[2] = params['slen'] if params.has_key('bvert'): self.calc_params[3] = params['bvert'] if params.has_key('bhorz'): self.calc_params[4] = params['bhorz'] if params.has_key('aflag'): self.calc_params[5] = params['aflag'] if params.has_key('fyidx'): self.calc_params[6] = params['fyidx'] if params.has_key('fyenergy'): self.calc_params[7] = params['fyenergy'] self._init_fy = True if params.has_key('adet'): self.calc_params[8] = params['adet'] if params.has_key('tnorm'): self.calc_params[9] = params['tnorm'] if params.has_key('rflag'): self.calc_params[10] = params['rflag'] if params.has_key('delz'): self.calc_params[11] = params['delz'] if params.has_key('pdepth'): self.calc_params[12] = params['pdepth'] if params.has_key('rscale'): self.calc_params[13] = params['rscale'] ########################################################## def get_params(self,**params): """ return params """ params = {} params['energy'] = self.calc_params[0] params['wconv'] = self.calc_params[1] params['slen'] = self.calc_params[2] params['bvert'] = self.calc_params[3] params['bhorz'] = self.calc_params[4] params['aflag'] = self.calc_params[5] params['fyidx'] = self.calc_params[6] params['fyenergy'] = self.calc_params[7] params['adet'] = self.calc_params[8] params['tnorm'] = self.calc_params[9] params['rflag'] = self.calc_params[10] params['delz'] = self.calc_params[11] params['pdepth'] = self.calc_params[12] params['rscale'] = self.calc_params[13] return params ########################################################## def init_energy(self,): """ Change the incident energy of the calc get fp,fpp from ifeffit for index of refraction calcs """ if len(self.fp) != self.nelem: self.fp = num.zeros(self.nelem, dtype=num.double) self.fpp = num.zeros(self.nelem, dtype=num.double) self.amu = num.zeros(self.nelem, dtype=num.double) self._init_ptr = True energy = self.calc_params[0] for j in range(self.nelem): en = [energy, energy + 1.] self.iff.put_array('calc.en',en) cmd = 'f1f2(energy=calc.en,z=%i)' % self.elem_z[j] self.iff.ifeffit(cmd) fp = self.iff.get_array('calc.f1') fpp = self.iff.get_array('calc.f2') # self.fp[j] = fp[0] self.fpp[j] = fpp[0] self.amu[j] = elements.amu(self.elem_z[j]) self._init_en = False ########################################################## def init_fy(self,): """ Get fpp from ifeffit and use this to est mu_atomic for fy. This will be a decent estimate for high z and E however, these are approx since we are ignoring coherent and incoherent scattering cross sections to computing total (ie this is photoeffect only) """ if len(self.mu_at) != self.nelem: self.mu_at = num.zeros(self.nelem, dtype=num.double) self._init_ptr = True #below is 2*Na*r_e*hc (in cm^2*eV*mole/atom) con = 4.20792637233e07 fy_energy = self.calc_params[7] if fy_energy == 0.0: self.mu_at = num.zeros(self.nelem, dtype=num.double) else: for j in range(self.nelem): en = [fy_energy, fy_energy + 1.] self.iff.put_array('calc.en',en) cmd = 'f1f2(energy=calc.en,z=%i)' % self.elem_z[j] self.iff.ifeffit(cmd) fp = self.iff.get_array('calc.f1') fpp = self.iff.get_array('calc.f2') fpp = float(fpp[0]) mu = con*fpp/(fy_energy*self.amu[j]) # self.mu_at[j] = mu self._init_fy = False ########################################################## def calc_R(self,ret=False): """ Calc reflectivity """ # save fy_idx to reset tmp = self.calc_params[6] self.calc_params[6] = -1.0 # if self._init_en: self.init_energy() if self._init_fy: self.init_fy() # self._calc(init_ptrs=self._init_ptr,init_arrs=self._init_carr) # if self._init_ptr == True: self._init_ptr = False if self._init_carr == True: self._init_carr = False # self.calc_params[6] = tmp # if ret: return (self.R.copy()) ########################################################## def calc_FY(self,ret=False): """ Calc fluorescent yield """ # check some stuff fy_idx = self.calc_params[6] if (fy_idx < 0.) or (fy_idx > self.nelem-1): print "Error, fy_idx out of range" return delz = self.calc_params[11] if delz < 1. : print "Error, zint too small, min = 1 ang." return # if self._init_en: self.init_energy() if self._init_fy: self.init_fy() # self._calc(init_ptrs=self._init_ptr, init_arrs=self._init_carr) # if self._init_ptr == True: self._init_ptr = False if self._init_carr == True: self._init_carr = False # if ret: return (self.Y.copy(), self.R.copy()) ########################################################## def make_mole_fractions(self): """ make composition into mole fractions """ self.comp = self.comp / self.comp.sum(0) return
class RefModel(_XrayRefl): """ Reflectivity model See wrxrr._XrayRefl for details regarding the initialization - we need to make sure that the arrays/data are appropriate to pass to the c library. """ def __init__(self, d=[], rho=[], sigma=[], comp=[], elem_z=[], theta=[], params={}): """ Parameters: ----------- All these should be num arrays, dtype = double * d array of layer thicknesses (angstroms) * rho array of corresponding densities (g/cm^3) * sigma array of interface roughnesses (angstroms) * comp is the composition array * elem_z are the Z values of each element in the model * theta array of theta values (degrees) * params is a dictionary of model parameters (see set_params) """ self.iff = Ifeffit(screen_echo=0) self.nlayer = 0 self.nelem = 0 self.nthet = 0 self.fp = [] self.fpp = [] self.amu = [] self.mu_at = [] self._init_params() # some flags self._init_en = True self._init_fy = True self._init_carr = True self._init_ptr = True # init self.init_model(d=d, rho=rho, sigma=sigma, comp=comp, elem_z=elem_z, theta=theta) self.set_params(**params) ########################################################################### def init_model(self, d=None, rho=None, sigma=None, comp=None, elem_z=None, theta=None): """ Initialize/modify model data and arrays. Note that arrays should be passed in as numpy arrays, and will be assigned by reference!! See wrxrr._XrayRefl._init_model for array creation """ if d != None: self.nlayer = len(d) if (d.dtype == DTYPE): self.d = d else: raise exceptions.ValueError self._init_carr = True self._init_ptr = True # if rho != None: if len(rho) != self.nlayer: raise exceptions.ValueError if (rho.dtype == DTYPE): self.rho = rho else: raise exceptions.ValueError self._init_ptr = True # if sigma != None: if len(sigma) != self.nlayer - 1: raise exceptions.ValueError if (sigma.dtype == DTYPE): self.sigma = sigma else: raise exceptions.ValueError self._init_ptr = True # if comp != None: if (comp.dtype != DTYPE): raise exceptions.ValueError nel, nz = comp.shape if nz != self.nlayer: raise exceptions.ValueError self.comp = comp if nel != self.nelem: self.nelem = nel self._init_en = True self._init_fy = True self._init_ptr = True # if elem_z != None: if len(elem_z) != self.nelem: raise exceptions.ValueError if (elem_z.dtype == DTYPE): self.elem_z = elem_z else: raise exceptions.ValueError self._init_en = True self._init_fy = True self._init_ptr = True # if theta != None: self.nthet = len(theta) if (theta.dtype == DTYPE): self.theta = theta else: raise exceptions.ValueError self._init_carr = True self._init_ptr = True ########################################################## def set_params(self, **params): """ Parameters: ----------- * energy (eV) is the incident energy # calc_params[0] * wconv (degrees) is the concolution width # calc_params[1] * slen (mm) is the sample length # calc_params[2] * bvert (mm) is the vertical beam dim # calc_params[3] * bhorz (mm) is the horizontal beam dim # calc_params[4] * aflag is a flag for area calcs # calc_params[6] * fyidx is the index of the element for FY # calc_params[6] * fyenergy (eV) is the energy of FY # calc_params[7] * adet (deg) is the angle of the detector # calc_params[8] * tnorm (deg) is the theta for normalizatio # calc_params[9] * rflag is the roughness flag # calc_params[10] * delz (ang) is the delta z for integration # calc_params[11] * pdepth is the substrate FY clac flag # calc_params[12] * rscale is a scale factor for reflectivity # calc_params[13] """ if len(params) == 0: return if params.has_key('energy'): self.calc_params[0] = params['energy'] self._init_en = True if params.has_key('wconv'): self.calc_params[1] = params['wconv'] if params.has_key('slen'): self.calc_params[2] = params['slen'] if params.has_key('bvert'): self.calc_params[3] = params['bvert'] if params.has_key('bhorz'): self.calc_params[4] = params['bhorz'] if params.has_key('aflag'): self.calc_params[5] = params['aflag'] if params.has_key('fyidx'): self.calc_params[6] = params['fyidx'] if params.has_key('fyenergy'): self.calc_params[7] = params['fyenergy'] self._init_fy = True if params.has_key('adet'): self.calc_params[8] = params['adet'] if params.has_key('tnorm'): self.calc_params[9] = params['tnorm'] if params.has_key('rflag'): self.calc_params[10] = params['rflag'] if params.has_key('delz'): self.calc_params[11] = params['delz'] if params.has_key('pdepth'): self.calc_params[12] = params['pdepth'] if params.has_key('rscale'): self.calc_params[13] = params['rscale'] ########################################################## def get_params(self, **params): """ return params """ params = {} params['energy'] = self.calc_params[0] params['wconv'] = self.calc_params[1] params['slen'] = self.calc_params[2] params['bvert'] = self.calc_params[3] params['bhorz'] = self.calc_params[4] params['aflag'] = self.calc_params[5] params['fyidx'] = self.calc_params[6] params['fyenergy'] = self.calc_params[7] params['adet'] = self.calc_params[8] params['tnorm'] = self.calc_params[9] params['rflag'] = self.calc_params[10] params['delz'] = self.calc_params[11] params['pdepth'] = self.calc_params[12] params['rscale'] = self.calc_params[13] return params ########################################################## def init_energy(self, ): """ Change the incident energy of the calc get fp,fpp from ifeffit for index of refraction calcs """ if len(self.fp) != self.nelem: self.fp = num.zeros(self.nelem, dtype=num.double) self.fpp = num.zeros(self.nelem, dtype=num.double) self.amu = num.zeros(self.nelem, dtype=num.double) self._init_ptr = True energy = self.calc_params[0] for j in range(self.nelem): en = [energy, energy + 1.] self.iff.put_array('calc.en', en) cmd = 'f1f2(energy=calc.en,z=%i)' % self.elem_z[j] self.iff.ifeffit(cmd) fp = self.iff.get_array('calc.f1') fpp = self.iff.get_array('calc.f2') # self.fp[j] = fp[0] self.fpp[j] = fpp[0] self.amu[j] = elements.amu(self.elem_z[j]) self._init_en = False ########################################################## def init_fy(self, ): """ Get fpp from ifeffit and use this to est mu_atomic for fy. This will be a decent estimate for high z and E however, these are approx since we are ignoring coherent and incoherent scattering cross sections to computing total (ie this is photoeffect only) """ if len(self.mu_at) != self.nelem: self.mu_at = num.zeros(self.nelem, dtype=num.double) self._init_ptr = True #below is 2*Na*r_e*hc (in cm^2*eV*mole/atom) con = 4.20792637233e07 fy_energy = self.calc_params[7] if fy_energy == 0.0: self.mu_at = num.zeros(self.nelem, dtype=num.double) else: for j in range(self.nelem): en = [fy_energy, fy_energy + 1.] self.iff.put_array('calc.en', en) cmd = 'f1f2(energy=calc.en,z=%i)' % self.elem_z[j] self.iff.ifeffit(cmd) fp = self.iff.get_array('calc.f1') fpp = self.iff.get_array('calc.f2') fpp = float(fpp[0]) mu = con * fpp / (fy_energy * self.amu[j]) # self.mu_at[j] = mu self._init_fy = False ########################################################## def calc_R(self, ret=False): """ Calc reflectivity """ # save fy_idx to reset tmp = self.calc_params[6] self.calc_params[6] = -1.0 # if self._init_en: self.init_energy() if self._init_fy: self.init_fy() # self._calc(init_ptrs=self._init_ptr, init_arrs=self._init_carr) # if self._init_ptr == True: self._init_ptr = False if self._init_carr == True: self._init_carr = False # self.calc_params[6] = tmp # if ret: return (self.R.copy()) ########################################################## def calc_FY(self, ret=False): """ Calc fluorescent yield """ # check some stuff fy_idx = self.calc_params[6] if (fy_idx < 0.) or (fy_idx > self.nelem - 1): print "Error, fy_idx out of range" return delz = self.calc_params[11] if delz < 1.: print "Error, zint too small, min = 1 ang." return # if self._init_en: self.init_energy() if self._init_fy: self.init_fy() # self._calc(init_ptrs=self._init_ptr, init_arrs=self._init_carr) # if self._init_ptr == True: self._init_ptr = False if self._init_carr == True: self._init_carr = False # if ret: return (self.Y.copy(), self.R.copy()) ########################################################## def make_mole_fractions(self): """ make composition into mole fractions """ self.comp = self.comp / self.comp.sum(0) return
from Ifeffit import Ifeffit from numpy import array,sqrt, exp, power from scipy.special import gamma, gammaln import time iff = Ifeffit() iff.ifeffit("set my.r = range(2,4,0.01)") iff.ifeffit("show @arrays") r = iff.get_array('my.r') iff.ifeffit("set my.rho = my.r * my.r") # iff.ifeffit("plot(my.r, my.rho)") print r def rho(r,r0, sigma2,k3): sigma = sqrt(sigma2) beta = k3 / sigma2*sigma q = 4 / (beta*beta) MAX = 20. if q > MAX: q=MAX if q < 2: q=2 if gammaln(q) > MAX: gammaq = MAX else: gammaq = max(1,min(MAX,gamma(q))) #print r0, sigma, beta, 4/(beta*beta), q, q-1, gammaln(q), gamma(q), gammaq pre = 2/ (sigma*abs(beta)*gammaq)