<s> import wx <EOL> import wx . lib . plot as plot <EOL> import os . path <EOL> import math <EOL> import numpy <EOL> import readf1f2a <EOL> import SimpleParratt <EOL> class Plot ( wx . Dialog ) : <EOL> def __init__ ( self , parent , id , title ) : <EOL> wx . Dialog . __init__ ( self , parent , id , '<STR_LIT>' , size = ( <NUM_LIT> , <NUM_LIT> ) ) <EOL> self . plot_on = <NUM_LIT:0> <EOL> LogList = [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> xUnitList = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> xcol2 = <NUM_LIT> <EOL> btnSim = wx . Button ( self , <NUM_LIT:1> , '<STR_LIT>' , ( <NUM_LIT:30> , <NUM_LIT:20> ) ) <EOL> wx . StaticText ( self , - <NUM_LIT:1> , '<STR_LIT>' , ( xcol2 , <NUM_LIT:5> ) ) <EOL> self . cb0 = wx . ComboBox ( self , <NUM_LIT:0> , '<STR_LIT>' , ( xcol2 , <NUM_LIT> ) , ( <NUM_LIT> , <NUM_LIT> ) , LogList , wx . CB_DROPDOWN ) <EOL> wx . StaticText ( self , - <NUM_LIT:1> , '<STR_LIT>' , ( xcol2 , <NUM_LIT:50> ) ) <EOL> self . cb1 = wx . ComboBox ( self , <NUM_LIT:0> , '<STR_LIT>' , ( xcol2 , <NUM_LIT> ) , ( <NUM_LIT> , <NUM_LIT> ) , xUnitList , wx . CB_DROPDOWN ) <EOL> wx . StaticText ( self , - <NUM_LIT:1> , "<STR_LIT>" , ( <NUM_LIT:5> , <NUM_LIT:50> ) ) <EOL> self . Text1 = wx . TextCtrl ( self , <NUM_LIT:2> , '<STR_LIT>' , ( <NUM_LIT:10> , <NUM_LIT> ) ) <EOL> wx . StaticText ( self , - <NUM_LIT:1> , "<STR_LIT>" , ( <NUM_LIT:5> , <NUM_LIT:100> ) ) <EOL> self . Text2 = wx . TextCtrl ( self , <NUM_LIT:3> , '<STR_LIT>' , ( <NUM_LIT:10> , <NUM_LIT> ) ) <EOL> wx . StaticText ( self , - <NUM_LIT:1> , "<STR_LIT>" , ( <NUM_LIT:5> , <NUM_LIT> ) ) <EOL> self . Text3 = wx . TextCtrl ( self , <NUM_LIT:4> , '<STR_LIT>' , ( <NUM_LIT:10> , <NUM_LIT> ) ) <EOL> wx . StaticText ( self , - <NUM_LIT:1> , "<STR_LIT>" , ( <NUM_LIT:5> , <NUM_LIT:200> ) ) <EOL> self . Text4 = wx . TextCtrl ( self , <NUM_LIT:5> , '<STR_LIT>' , ( <NUM_LIT:10> , <NUM_LIT> ) ) <EOL> wx . StaticText ( self , - <NUM_LIT:1> , "<STR_LIT>" , ( <NUM_LIT:5> , <NUM_LIT> ) ) <EOL> self . Text5 = wx . TextCtrl ( self , <NUM_LIT:6> , '<STR_LIT:1.0>' , ( <NUM_LIT:10> , <NUM_LIT> ) ) <EOL> wx . StaticText ( self , - <NUM_LIT:1> , "<STR_LIT>" , ( xcol2 - <NUM_LIT:5> , <NUM_LIT:100> ) ) <EOL> self . Text6 = wx . TextCtrl ( self , <NUM_LIT:7> , '<STR_LIT>' , ( xcol2 , <NUM_LIT> ) ) <EOL> wx . StaticText ( self , - <NUM_LIT:1> , "<STR_LIT>" , ( xcol2 - <NUM_LIT:5> , <NUM_LIT> ) ) <EOL> self . Text7 = wx . TextCtrl ( self , <NUM_LIT:8> , '<STR_LIT>' , ( xcol2 , <NUM_LIT> ) ) <EOL> wx . StaticText ( self , - <NUM_LIT:1> , "<STR_LIT>" , ( xcol2 - <NUM_LIT:5> , <NUM_LIT:200> ) ) <EOL> CrList = [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> self . cb2 = wx . ComboBox ( self , <NUM_LIT:10> , '<STR_LIT>' , ( xcol2 , <NUM_LIT> ) , ( <NUM_LIT> , <NUM_LIT> ) , CrList , wx . CB_DROPDOWN ) <EOL> wx . StaticText ( self , - <NUM_LIT:1> , "<STR_LIT>" , ( <NUM_LIT:5> , <NUM_LIT> ) ) <EOL> self . Text8 = wx . TextCtrl ( self , <NUM_LIT:12> , '<STR_LIT>' , ( <NUM_LIT:10> , <NUM_LIT> ) , ( <NUM_LIT> , <NUM_LIT> ) ) <EOL> btnSim = wx . Button ( self , <NUM_LIT:11> , '<STR_LIT>' , ( <NUM_LIT:10> , <NUM_LIT> ) ) <EOL> wx . EVT_BUTTON ( self , <NUM_LIT:1> , self . OnSimulate ) <EOL> wx . EVT_TEXT ( self , <NUM_LIT:3> , self . OnText2 ) <EOL> wx . EVT_TEXT ( self , <NUM_LIT:7> , self . OnText6 ) <EOL> wx . EVT_CLOSE ( self , self . OnQuit ) <EOL> wx . EVT_BUTTON ( self , <NUM_LIT:11> , self . OnSimulate1 ) <EOL> def OnText2 ( self , event ) : <EOL> text = self . Text2 . GetValue ( ) <EOL> inputfile = '<STR_LIT>' <EOL> f = open ( inputfile ) <EOL> lines = f . readlines ( ) <EOL> out = <NUM_LIT:1.0> <EOL> for line in lines : <EOL> if not line . startswith ( '<STR_LIT:#>' ) : <EOL> words = line . split ( '<STR_LIT:U+002C>' ) <EOL> if text == words [ <NUM_LIT:0> ] : <EOL> temp = words [ <NUM_LIT:1> ] . split ( ) <EOL> out = temp [ <NUM_LIT:0> ] <EOL> f . close ( ) <EOL> self . Text4 . SetValue ( str ( out ) ) <EOL> def OnText6 ( self , event ) : <EOL> text = self . Text6 . GetValue ( ) <EOL> inputfile = '<STR_LIT>' <EOL> f = open ( inputfile ) <EOL> lines = f . readlines ( ) <EOL> out = <NUM_LIT:1.0> <EOL> for line in lines : <EOL> if not line . startswith ( '<STR_LIT:#>' ) : <EOL> words = line . split ( '<STR_LIT:U+002C>' ) <EOL> if text == words [ <NUM_LIT:0> ] : <EOL> temp = words [ <NUM_LIT:1> ] . split ( ) <EOL> out = temp [ <NUM_LIT:0> ] <EOL> f . close ( ) <EOL> self . Text7 . SetValue ( str ( out ) ) <EOL> def OnSimulate ( self , event ) : <EOL> reload ( SimpleParratt ) <EOL> text = self . Text1 . GetValue ( ) <EOL> eV0 = float ( text ) <EOL> eV0_min = <NUM_LIT> <EOL> if eV0 <= eV0_min : eV0 = eV0_min + <NUM_LIT> <EOL> film_mat = self . Text2 . GetValue ( ) <EOL> text = self . Text3 . GetValue ( ) <EOL> film_thick = float ( text ) <EOL> text = self . Text4 . GetValue ( ) <EOL> film_den = float ( text ) <EOL> text = self . Text5 . GetValue ( ) <EOL> film_roughness = float ( text ) <EOL> subs_mat = self . Text6 . GetValue ( ) <EOL> text = self . Text7 . GetValue ( ) <EOL> subs_den = float ( text ) <EOL> text = self . cb2 . GetValue ( ) <EOL> use_Cr = <NUM_LIT:0> <EOL> if text == '<STR_LIT>' : use_Cr = <NUM_LIT:1> <EOL> text = self . cb1 . GetValue ( ) <EOL> xUnit = '<STR_LIT>' <EOL> xUnit = text <EOL> text = self . cb0 . GetValue ( ) <EOL> use_Log = False <EOL> if text == '<STR_LIT>' : use_Log = True <EOL> if use_Cr == <NUM_LIT:1> : <EOL> NumLayers = <NUM_LIT:2> <EOL> else : <EOL> NumLayers = <NUM_LIT:1> <EOL> out = readf1f2a . get_delta ( film_mat , film_den , eV0 ) <EOL> delta_film = out [ <NUM_LIT:0> ] <EOL> la_film = out [ <NUM_LIT:2> ] * <NUM_LIT> <EOL> thc_film = ( <NUM_LIT> * delta_film ) ** ( <NUM_LIT:0.5> ) * <NUM_LIT> / math . pi <EOL> print '<STR_LIT>' % ( '<STR_LIT>' , thc_film , thc_film * math . pi / <NUM_LIT> * <NUM_LIT> ) <EOL> th_step = <NUM_LIT> <EOL> th_range = numpy . arange ( <NUM_LIT> , thc_film * <NUM_LIT> , th_step ) <EOL> depths = [ <NUM_LIT:0.0> ] <EOL> layer_mat = [ ] ; layer_thick = [ ] ; layer_den = [ ] ; layer_rough = [ ] ; layer_tag = [ ] <EOL> layer_mat . append ( '<STR_LIT>' ) <EOL> layer_thick . append ( <NUM_LIT:0.0> ) <EOL> layer_den . append ( <NUM_LIT> ) <EOL> layer_rough . append ( film_roughness ) <EOL> layer_tag . append ( '<STR_LIT>' ) <EOL> layer_mat . append ( film_mat ) <EOL> layer_thick . append ( film_thick ) <EOL> layer_den . append ( film_den ) <EOL> layer_rough . append ( film_roughness ) <EOL> layer_tag . append ( film_mat + '<STR_LIT>' ) <EOL> if ( NumLayers == <NUM_LIT:2> ) : <EOL> layer_mat . append ( '<STR_LIT>' ) <EOL> layer_thick . append ( <NUM_LIT> ) <EOL> layer_den . append ( <NUM_LIT> ) <EOL> layer_rough . append ( film_roughness ) <EOL> layer_tag . append ( '<STR_LIT>' ) <EOL> layer_mat . append ( subs_mat ) <EOL> layer_thick . append ( <NUM_LIT> ) <EOL> layer_den . append ( subs_den ) <EOL> layer_rough . append ( film_roughness ) <EOL> layer_tag . append ( subs_mat + '<STR_LIT>' ) <EOL> print '<STR_LIT>' <EOL> print '<STR_LIT>' % ( eV0 , film_mat , thc_film , la_film ) <EOL> out = readf1f2a . get_delta ( subs_mat , subs_den , eV0 ) <EOL> delta_subs = out [ <NUM_LIT:0> ] <EOL> la_subs = out [ <NUM_LIT:2> ] * <NUM_LIT> <EOL> thc_subs = ( <NUM_LIT> * delta_subs ) ** ( <NUM_LIT:0.5> ) * <NUM_LIT> / math . pi <EOL> print '<STR_LIT>' % ( eV0 , subs_mat , thc_subs , la_subs ) <EOL> SimpleParratt . reflectivity ( eV0 , th_range , layer_mat , layer_thick , layer_den , layer_rough , layer_tag , depths ) <EOL> if self . plot_on == <NUM_LIT:1> : <EOL> print self . plot_on <EOL> self . plot . Destroy ( ) <EOL> frm = wx . Frame ( self , <NUM_LIT:1> , '<STR_LIT>' , size = ( <NUM_LIT> , <NUM_LIT> ) ) <EOL> self . data = [ ] ; self . data0 = [ ] <EOL> th0 = <NUM_LIT:0> ; refl_half = <NUM_LIT> <EOL> inputfile = '<STR_LIT>' <EOL> f = open ( inputfile ) <EOL> lines = f . readlines ( ) <EOL> self . xMin = <NUM_LIT> ; self . xMax = - <NUM_LIT> ; self . yMin = <NUM_LIT> ; self . yMax = - <NUM_LIT> <EOL> for line in lines : <EOL> if line . startswith ( '<STR_LIT:#>' ) : continue <EOL> words = line . split ( ) <EOL> if xUnit == '<STR_LIT>' : <EOL> xx = float ( words [ <NUM_LIT:0> ] ) * math . pi / <NUM_LIT> * <NUM_LIT> <EOL> if xUnit == '<STR_LIT>' : <EOL> xx = float ( words [ <NUM_LIT:0> ] ) <EOL> if xUnit == '<STR_LIT>' : <EOL> ang = float ( words [ <NUM_LIT:0> ] ) <EOL> qz = <NUM_LIT:4> * math . pi * ( eV0 / <NUM_LIT> / <NUM_LIT> ) * math . sin ( ang * math . pi / <NUM_LIT> ) <EOL> xx = qz <EOL> if self . xMin > xx : self . xMin = xx <EOL> if self . xMax <= xx : self . xMax = xx <EOL> yy = float ( words [ <NUM_LIT:1> ] ) <EOL> if self . yMin > yy : self . yMin = yy <EOL> if self . yMax <= yy : self . yMax = yy <EOL> self . data . append ( ( xx , yy ) ) <EOL> self . data0 . append ( ( xx , <NUM_LIT:0.5> ) ) <EOL> temp = abs ( yy - <NUM_LIT:0.5> ) <EOL> if temp <= refl_half : <EOL> refl_half = temp <EOL> th0 = xx <EOL> self . yMax = <NUM_LIT:1.0> <EOL> f . close ( ) <EOL> sample = '<STR_LIT>' <EOL> for ( ii , item ) in enumerate ( layer_mat ) : <EOL> if ii == <NUM_LIT:0> : <EOL> sample = '<STR_LIT>' <EOL> else : <EOL> sample = sample + '<STR_LIT:/>' + item <EOL> text0 = '<STR_LIT>' <EOL> text1 = '<STR_LIT>' <EOL> if xUnit == '<STR_LIT>' : <EOL> text0 = '<STR_LIT>' <EOL> text1 = '<STR_LIT>' <EOL> if xUnit == '<STR_LIT>' : <EOL> text0 = '<STR_LIT>' <EOL> text1 = '<STR_LIT>' <EOL> title = '<STR_LIT>' % ( eV0 , '<STR_LIT>' , sample , '<STR_LIT>' , th0 , text0 ) <EOL> client = plot . PlotCanvas ( frm ) <EOL> client . SetEnableZoom ( True ) <EOL> line = plot . PolyLine ( self . data , legend = '<STR_LIT>' , colour = '<STR_LIT>' , width = <NUM_LIT:1> ) <EOL> line0 = plot . PolyLine ( self . data0 , legend = '<STR_LIT>' , colour = '<STR_LIT>' , width = <NUM_LIT:0.5> ) <EOL> gc = plot . PlotGraphics ( [ line , line0 ] , title , text1 , '<STR_LIT>' ) <EOL> client . setLogScale ( ( False , False ) ) <EOL> if use_Log == True : client . setLogScale ( ( False , True ) ) <EOL> client . Draw ( gc , xAxis = ( self . xMin , self . xMax ) , yAxis = ( self . yMin , self . yMax ) ) <EOL> frm . Show ( True ) <EOL> self . plot_on = <NUM_LIT:1> <EOL> self . plot = frm <EOL> def OnSimulate1 ( self , event ) : <EOL> reload ( SimpleParratt ) <EOL> text = self . Text1 . GetValue ( ) <EOL> eV0 = float ( text ) <EOL> eV0_min = <NUM_LIT> <EOL> if eV0 <= eV0_min : eV0 = eV0_min + <NUM_LIT> <EOL> film_mat = self . Text2 . GetValue ( ) <EOL> text = self . Text3 . GetValue ( ) <EOL> film_thick = float ( text ) <EOL> text = self . Text4 . GetValue ( ) <EOL> film_den = float ( text ) <EOL> text = self . Text5 . GetValue ( ) <EOL> film_roughness = float ( text ) <EOL> subs_mat = self . Text6 . GetValue ( ) <EOL> text = self . Text7 . GetValue ( ) <EOL> subs_den = float ( text ) <EOL> text = self . cb2 . GetValue ( ) <EOL> use_Cr = <NUM_LIT:0> <EOL> if text == '<STR_LIT>' : use_Cr = <NUM_LIT:1> <EOL> text = self . cb1 . GetValue ( ) <EOL> xUnit = '<STR_LIT>' <EOL> xUnit = text <EOL> text = self . cb0 . GetValue ( ) <EOL> use_Log = False <EOL> if text == '<STR_LIT>' : use_Log = True <EOL> if use_Cr == <NUM_LIT:1> : <EOL> NumLayers = <NUM_LIT:2> <EOL> else : <EOL> NumLayers = <NUM_LIT:1> <EOL> LayerStructure0 = self . Text8 . GetValue ( ) <EOL> import read_FilmName <EOL> film1 = read_FilmName . Film ( LayerStructure0 ) <EOL> film1 . get_structure ( ) <EOL> film1 . reverse_structure ( ) <EOL> layer_mat = [ ] ; layer_thick = [ ] ; layer_den = [ ] ; layer_rough = [ ] ; layer_tag = [ ] <EOL> layer_thc = [ ] ; layer_la = [ ] <EOL> print '<STR_LIT>' <EOL> for ( ii , layer1 ) in enumerate ( film1 . LayerList ) : <EOL> layer_mat . append ( str ( layer1 . composition ) ) <EOL> inputfile = '<STR_LIT>' <EOL> f = open ( inputfile ) <EOL> lines = f . readlines ( ) <EOL> out = <NUM_LIT:1.0> <EOL> for line in lines : <EOL> if not line . startswith ( '<STR_LIT:#>' ) : <EOL> words = line . split ( '<STR_LIT:U+002C>' ) <EOL> if layer1 . composition == words [ <NUM_LIT:0> ] : <EOL> temp = words [ <NUM_LIT:1> ] . split ( ) <EOL> out = temp [ <NUM_LIT:0> ] <EOL> layer1 . density = float ( out ) <EOL> f . close ( ) <EOL> layer_den . append ( float ( layer1 . density ) ) <EOL> layer_thick . append ( float ( layer1 . thickness ) ) <EOL> layer_rough . append ( float ( layer1 . rms ) ) <EOL> layer_tag . append ( str ( layer1 . tag ) ) <EOL> out = readf1f2a . get_delta ( layer1 . composition , layer1 . density , eV0 ) <EOL> la_layer = out [ <NUM_LIT:2> ] * <NUM_LIT> <EOL> delta_layer = out [ <NUM_LIT:0> ] <EOL> thc_layer = ( <NUM_LIT> * delta_layer ) ** ( <NUM_LIT:0.5> ) * <NUM_LIT> / math . pi <EOL> if ii == <NUM_LIT:1> : <EOL> thc_toplayer = thc_layer <EOL> print '<STR_LIT>' % ( eV0 , layer1 . composition + '<STR_LIT:->' + layer1 . tag , thc_layer , thc_layer * math . pi / <NUM_LIT> * <NUM_LIT> , la_layer , layer1 . density ) <EOL> th_step = <NUM_LIT> <EOL> th_range = numpy . arange ( <NUM_LIT> , thc_toplayer * <NUM_LIT> , th_step ) <EOL> depths = [ <NUM_LIT:0.0> ] <EOL> SimpleParratt . reflectivity ( eV0 , th_range , layer_mat , layer_thick , layer_den , layer_rough , layer_tag , depths ) <EOL> if self . plot_on == <NUM_LIT:1> : <EOL> print self . plot_on <EOL> self . plot . Destroy ( ) <EOL> frm = wx . Frame ( self , <NUM_LIT:1> , '<STR_LIT>' , size = ( <NUM_LIT> , <NUM_LIT> ) ) <EOL> self . data = [ ] ; self . data0 = [ ] <EOL> th0 = <NUM_LIT:0> ; refl_half = <NUM_LIT> <EOL> inputfile = '<STR_LIT>' <EOL> f = open ( inputfile ) <EOL> lines = f . readlines ( ) <EOL> self . xMin = <NUM_LIT> ; self . xMax = - <NUM_LIT> ; self . yMin = <NUM_LIT> ; self . yMax = - <NUM_LIT> <EOL> for line in lines : <EOL> if line . startswith ( '<STR_LIT:#>' ) : continue <EOL> words = line . split ( ) <EOL> if xUnit == '<STR_LIT>' : <EOL> xx = float ( words [ <NUM_LIT:0> ] ) * math . pi / <NUM_LIT> * <NUM_LIT> <EOL> if xUnit == '<STR_LIT>' : <EOL> xx = float ( words [ <NUM_LIT:0> ] ) <EOL> if xUnit == '<STR_LIT>' : <EOL> ang = float ( words [ <NUM_LIT:0> ] ) <EOL> qz = <NUM_LIT:4> * math . pi * ( eV0 / <NUM_LIT> / <NUM_LIT> ) * math . sin ( ang * math . pi / <NUM_LIT> ) <EOL> xx = qz <EOL> if self . xMin > xx : self . xMin = xx <EOL> if self . xMax <= xx : self . xMax = xx <EOL> yy = float ( words [ <NUM_LIT:1> ] ) <EOL> if self . yMin > yy : self . yMin = yy <EOL> if self . yMax <= yy : self . yMax = yy <EOL> self . data . append ( ( xx , yy ) ) <EOL> self . data0 . append ( ( xx , <NUM_LIT:0.5> ) ) <EOL> temp = abs ( yy - <NUM_LIT:0.5> ) <EOL> if temp <= refl_half : <EOL> refl_half = temp <EOL> th0 = xx <EOL> self . yMax = <NUM_LIT:1.0> <EOL> f . close ( ) <EOL> sample = '<STR_LIT>' <EOL> for ( ii , item ) in enumerate ( layer_mat ) : <EOL> if ii == <NUM_LIT:0> : <EOL> sample = '<STR_LIT>' <EOL> else : <EOL> sample = sample + '<STR_LIT:/>' + item <EOL> text0 = '<STR_LIT>' <EOL> text1 = '<STR_LIT>' <EOL> if xUnit == '<STR_LIT>' : <EOL> text0 = '<STR_LIT>' <EOL> text1 = '<STR_LIT>' <EOL> if xUnit == '<STR_LIT>' : <EOL> text0 = '<STR_LIT>' <EOL> text1 = '<STR_LIT>' <EOL> title = '<STR_LIT>' % ( eV0 , '<STR_LIT>' , sample , '<STR_LIT>' , th0 , text0 ) <EOL> client = plot . PlotCanvas ( frm ) <EOL> client . SetEnableZoom ( True ) <EOL> line = plot . PolyLine ( self . data , legend = '<STR_LIT>' , colour = '<STR_LIT>' , width = <NUM_LIT:1> ) <EOL> line0 = plot . PolyLine ( self . data0 , legend = '<STR_LIT>' , colour = '<STR_LIT>' , width = <NUM_LIT:0.5> ) <EOL> gc = plot . PlotGraphics ( [ line , line0 ] , title , text1 , '<STR_LIT>' ) <EOL> client . setLogScale ( ( False , False ) ) <EOL> if use_Log == True : client . setLogScale ( ( False , True ) ) <EOL> client . Draw ( gc , xAxis = ( self . xMin , self . xMax ) , yAxis = ( self . yMin , self . yMax ) ) <EOL> frm . Show ( True ) <EOL> self . plot_on = <NUM_LIT:1> <EOL> self . plot = frm <EOL> def OnQuit ( self , event ) : <EOL> self . plot_on = <NUM_LIT:0> <EOL> self . Destroy ( ) <EOL> class MyApp ( wx . App ) : <EOL> def OnInit ( self ) : <EOL> dlg = Plot ( None , - <NUM_LIT:1> , '<STR_LIT>' ) <EOL> dlg . Show ( True ) <EOL> dlg . Centre ( ) <EOL> return True <EOL> app = MyApp ( <NUM_LIT:0> ) <EOL> app . MainLoop ( ) </s>
