def OnSimulate1(self, event):  # for arbitrary structure
        reload(SimpleParratt)
    # --- Retrive values from panel --------------
        # self.Text1
        text=self.Text1.GetValue()
        eV0=float(text)
        eV0_min=500
        if eV0<=eV0_min:    eV0=eV0_min+10.
        # self.Text2
        film_mat=self.Text2.GetValue()
        # self.Text3
        text=self.Text3.GetValue()
        film_thick=float(text)
        # self.Text4
        text=self.Text4.GetValue()
        film_den=float(text)
        # self.Text5
        text=self.Text5.GetValue()
        film_roughness=float(text)
        # self.Text6
        subs_mat=self.Text6.GetValue()
        # self.Text7
        text=self.Text7.GetValue()
        subs_den=float(text)
        # self.cb2
        text=self.cb2.GetValue()
        use_Cr=0
        if text=='Yes': use_Cr=1
        # self.cb1
        text=self.cb1.GetValue()
        xUnit='m rad'
        xUnit=text
        # self.cb0
        text=self.cb0.GetValue()
        use_Log=False
        if text=='Yes': use_Log=True
        if use_Cr==1:
            NumLayers=2
        else:
            NumLayers=1
        LayerStructure0=self.Text8.GetValue()
        import read_FilmName
        film1=read_FilmName.Film(LayerStructure0)
        film1.get_structure()
        film1.reverse_structure()  # reverse the layer order so that the top is vaccum
        layer_mat=[];	layer_thick=[];	 layer_den=[];	 layer_rough=[]; layer_tag=[]
        layer_thc=[]; layer_la=[]
        print 'energy(eV) \t layer \t th_c(Deg.) \t th_c(m rad) \t absorption_length(micron) \t density (g/cc)\n'
        for (ii, layer1) in enumerate(film1.LayerList):
            layer_mat.append(str(layer1.composition))
            inputfile='NominalDensity.txt'
            f=open(inputfile)
            lines=f.readlines()
            out=1.0
            for line in lines:
                if not line.startswith('#'):
                    words=line.split(',')
                    if layer1.composition==words[0]:
                        temp=words[1].split()
                        out=temp[0]
            layer1.density=float(out)
            f.close()
            layer_den.append(float(layer1.density))
            layer_thick.append(float(layer1.thickness))
            layer_rough.append(float(layer1.rms))
            layer_tag.append(str(layer1.tag))
            out=readf1f2a.get_delta(layer1.composition, layer1.density, eV0)
            la_layer=out[2]*10000.0  # absorption length in cm, convert to microns
            delta_layer=out[0]
            thc_layer=(2.*delta_layer)**(0.5)*180./math.pi  # critical angle in deg
            if ii==1:
                thc_toplayer=thc_layer
            print '%4.1f \t %s \t %4.4f \t %4.4f \t %4.1f \t %s\n' % \
                (eV0, layer1.composition+'-'+layer1.tag, thc_layer, thc_layer*math.pi/180.*1000., la_layer, layer1.density)
        th_step=0.001
        th_range=numpy.arange(0.000, thc_toplayer*12.0, th_step)  # angular range
        depths=[0.0]  # calculate efield intensity at air/film interface
        #print layer_mat
        #print layer_thick
        #print layer_den
        #print layer_rough
        #layer_mat=['He', 'Cr', 'Si']; layer_thick=[0, 10., 10000]; layer_den=[1,1,1]; layer_rough=[1,1,1]
    # --- call reflectivity in SimpleParratt.py	 ------------------
        SimpleParratt.reflectivity(eV0, th_range, layer_mat, layer_thick, layer_den,\
            layer_rough, layer_tag, depths)
    # --- Plot ----------------------------------------------------
        if self.plot_on==1:
            print self.plot_on
            self.plot.Destroy()
            #self.frm.Destroy()
        frm = wx.Frame(self, 1, 'SimpleParratt.txt', size=(600,450))
        self.data=[]; self.data0=[]
        th0=0;	refl_half=1e6
        inputfile='SimpleParratt.txt'
        f=open(inputfile)
        lines=f.readlines()
        self.xMin=1e6; self.xMax=-1e6; self.yMin=1e6; self.yMax=-1e6
        for line in lines:
            if line.startswith('#'):	continue
            words=line.split()
            if xUnit=='m rad':
                xx=float(words[0])*math.pi/180.0*1000.	# convert deg to m rad
            if xUnit=='Deg':
                xx=float(words[0])
            if xUnit=='qz':
                ang=float(words[0])
                qz=4*math.pi*(eV0/1000.0/12.39842)*math.sin(ang*math.pi/180.0)
                xx=qz
            if self.xMin>xx: self.xMin=xx
            if self.xMax<=xx: self.xMax=xx
            yy=float(words[1])
            if self.yMin>yy: self.yMin=yy
            if self.yMax<=yy: self.yMax=yy
            self.data.append((xx, yy))
            self.data0.append((xx, 0.5))
            temp=abs(yy-0.5)
            if temp<=refl_half:
                refl_half=temp
                th0=xx
        self.yMax=1.0
        f.close()
        sample=''
        for (ii,item) in enumerate(layer_mat):
            if ii==0:
                sample='vacuum'
            else:
                sample=sample+'/'+item
        #title=str(eV0)+'eV, '+sample+', Refl.=0.5 at '+str(th0)+' m rad.'
        text0=' m rad.'
        text1='Incident angle (m rad)'
        if xUnit=='Deg':
            text0=' Deg'
            text1='Incident angle (Deg)'
        if xUnit=='qz':
            text0=' qz (1/Angstrom)'
            text1='qz (1/Agnstrom)'
        title='%4.1f, %s, %s %s %3.3f %s' % (eV0, 'eV', sample, 'Refl.=0.5 at', th0, text0)
        #------------------------------------------------
        client = plot.PlotCanvas(frm)
        # 9/1/2010: enable zooming function, double click for default size
        client.SetEnableZoom(True)
        line = plot.PolyLine(self.data, legend='', colour='red', width=1)
        line0 = plot.PolyLine(self.data0, legend='', colour='black', width=0.5)
        gc = plot.PlotGraphics([line, line0], title, text1, 'Reflectivity')
        client.setLogScale((False,False))
        if use_Log==True: client.setLogScale((False,True))
        client.Draw(gc,	 xAxis= (self.xMin,self.xMax), yAxis= (self.yMin,self.yMax))
        frm.Show(True)
        self.plot_on = 1
        self.plot=frm
        #------------------------------------------------
dataset/ETHPy150Open xraypy/xraylarch/plugins/xsw/YongsCode/SimpleParratt_Panel.py/Plot.OnSimulate1/original