Changeset 2776


Ignore:
Timestamp:
Apr 11, 2017 10:39:15 AM (5 years ago)
Author:
vondreele
Message:

add a number of materials to Substances.py
implement multilayer reflectometry models

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/GSASIIpwd.py

    r2774 r2776  
    19461946                values.append(data[parm][0])
    19471947                bounds.append(Bounds[parm])
    1948         parmDict['nLayers'] = len(data['Layers'])
     1948        parmDict['Layer Seq'] = np.array(['0',]+data['Layer Seq'].split()+[str(len(data['Layers'])-1),],dtype=int)
     1949        parmDict['nLayers'] = len(parmDict['Layer Seq'])
    19491950        for ilay,layer in enumerate(data['Layers']):
    19501951            name = layer['Name']
     
    20092010        Nlayers = parmDict['nLayers']
    20102011        Res = parmDict['Res']
    2011         Gaus = np.zeros((9,len(Q)))
    20122012        depth = np.zeros(Nlayers)
    20132013        rho = np.zeros(Nlayers)
    20142014        irho = np.zeros(Nlayers)
    20152015        sigma = np.zeros(Nlayers)
    2016         for ilay in range(Nlayers):
    2017             cid = str(ilay)+';'
     2016        for ilay,lay in enumerate(parmDict['Layer Seq']):
     2017            cid = str(lay)+';'
    20182018            depth[ilay] = parmDict[cid+'Thick']
    20192019            sigma[ilay] = parmDict[cid+'Rough']
     
    20292029        Ic += (A**2+B**2)*Scale     
    20302030        return Ic
     2031       
     2032        def Smear(f,w,z,dq):
     2033            y = f(w,z)
     2034            s = dq/ateln2
     2035            y += 0.1354*(f(w,z+2*s)+f(w,z-2*s))
     2036            y += 0.24935*(f(w,z-1.666667*s)+f(w,z+1.666667*s))
     2037            y += 0.4111*(f(w,z-1.333333*s)+f(w,z+1.333333*s))
     2038            y += 0.60653*(f(w,z-s) +f(w,z+s))
     2039            y += 0.80074*(f(w,z-0.6666667*s)+f(w,z+0.6666667*s))
     2040            y += 0.94596*(f(w,z-0.3333333*s)+f(w,z+0.3333333*s))
     2041            y *= 0.137023
     2042            return y
    20312043       
    20322044    def estimateT0(takestep):
     
    21432155   
    21442156    sq2 = np.sqrt(2.)
    2145     Nlayers = len(data['Layers'])
     2157    laySeq = ['0',]+data['Layer Seq'].split()+[str(len(data['Layers'])-1),]
     2158    Nlayers = len(laySeq)
     2159    laySeq = np.array(laySeq,dtype=int)
    21462160    interfaces = np.zeros(Nlayers)
    21472161    rho = np.zeros(Nlayers)
    2148     irho = np.zeros(Nlayers)
    21492162    sigma = np.zeros(Nlayers)
     2163    name = data['Layers'][0]['Name']
    21502164    thick = 0.
    2151     for ilayer,layer in enumerate(data['Layers']):
     2165    for ilay,lay in enumerate(laySeq):
     2166        layer = data['Layers'][lay]
    21522167        name = layer['Name']
    2153         if 'Thick' in layer:    #skips first & last layers
     2168        if 'Thick' in layer:
    21542169            thick += layer['Thick'][0]
    2155             interfaces[ilayer] = layer['Thick'][0]+interfaces[ilayer-1]
    2156         if 'Rough' in layer:    #skips first layer
    2157             sigma[ilayer] = max(0.001,layer['Rough'][0])
    2158         rho[ilayer] = Substances[name]['Scatt density']*layer['DenMul'][0]
     2170            interfaces[ilay] = layer['Thick'][0]+interfaces[ilay-1]
     2171        if 'Rough' in layer:
     2172            sigma[ilay] = max(0.001,layer['Rough'][0])
     2173        if name != 'vacuum':
     2174            rho[ilay] = Substances[name]['Scatt density']*layer['DenMul'][0]
    21592175        if 'Mag SLD' in layer:
    2160             rho[ilayer] += layer['Mag SLD'][0]
    2161         irho[ilayer] = Substances[name].get('XImag density',0.)*layer['DenMul'][0]
     2176            rho[ilay] += layer['Mag SLD'][0]
     2177    name = data['Layers'][-1]['Name']
    21622178    x = np.linspace(-0.15*thick,1.15*thick,1000,endpoint=True)
    21632179    xr = np.flipud(x)
     
    21822198    Ic[:] = 0
    21832199    Scale = data['Scale'][0]
    2184     Nlayers = len(data['Layers'])
     2200    laySeq = ['0',]+data['Layer Seq'].split()+[str(len(data['Layers'])-1),]
     2201    Nlayers = len(laySeq)
    21852202    depth = np.zeros(Nlayers)
    21862203    rho = np.zeros(Nlayers)
    21872204    irho = np.zeros(Nlayers)
    21882205    sigma = np.zeros(Nlayers)
    2189     for ilayer,layer in enumerate(data['Layers']):
     2206    for ilay,lay in enumerate(np.array(laySeq,dtype=int)):
     2207        layer = data['Layers'][lay]
    21902208        name = layer['Name']
    21912209        if 'Thick' in layer:    #skips first & last layers
    2192             depth[ilayer] = layer['Thick'][0]
     2210            depth[ilay] = layer['Thick'][0]
    21932211        if 'Rough' in layer:    #skips first layer
    2194             sigma[ilayer] = layer['Rough'][0]
     2212            sigma[ilay] = layer['Rough'][0]
    21952213        if 'unit scatter' == name:
    2196             rho[ilayer] = layer['DenMul'][0]
    2197             irho[ilayer] = layer['iDenMul'][0]
     2214            rho[ilay] = layer['DenMul'][0]
     2215            irho[ilay] = layer['iDenMul'][0]
    21982216        else:
    2199             rho[ilayer] = Substances[name]['Scatt density']*layer['DenMul'][0]
    2200             irho[ilayer] = Substances[name].get('XImag density',0.)*layer['DenMul'][0]
     2217            rho[ilay] = Substances[name]['Scatt density']*layer['DenMul'][0]
     2218            irho[ilay] = Substances[name].get('XImag density',0.)*layer['DenMul'][0]
    22012219        if 'Mag SLD' in layer:
    2202             rho[ilayer] += layer['Mag SLD'][0]
     2220            rho[ilay] += layer['Mag SLD'][0]
    22032221    A,B = abeles(0.5*Q[iBeg:iFin],depth,rho,irho,sigma[1:])     #Q --> k, offset roughness for abeles
    22042222    Ic[iBeg:iFin] = (A**2+B**2)*Scale+Ib[iBeg:iFin]
  • trunk/GSASIIpwdGUI.py

    r2774 r2776  
    47814781                disLabel = r'$Distance\ from\ top\ surface,\ \AA$'
    47824782            if od['value_2']:
    4783                 nLines = len(model['Layers'])-1
     4783                laySeq = model['Layer Seq'].split()
     4784                nLines = len(laySeq)+1
    47844785                linePos = np.zeros(nLines)
    4785                 for ilay,layer in enumerate(model['Layers'][1:-1]):
    4786                     linePos[ilay+1:] += layer.get('Thick',[0.,False])[0]
     4786                for ilay,lay in enumerate(np.fromstring(data['Layer Seq'],dtype=int,sep=' ')):
     4787                    linePos[ilay+1:] += model['Layers'][lay].get('Thick',[0.,False])[0]
    47874788                if od['value_1']:
    47884789                    linePos = linePos[-1]-linePos
     
    47964797       
    47974798    def ModelPlot(data,x,xr,y):
    4798         nLines = len(data['Layers'])-1
     4799        laySeq = data['Layer Seq'].split()
     4800        nLines = len(laySeq)+1
    47994801        linePos = np.zeros(nLines)
    4800         for ilay,layer in enumerate(data['Layers'][1:-1]):
    4801             linePos[ilay+1:] += layer.get('Thick',[0.,False])[0]
     4802        for ilay,lay in enumerate(np.fromstring(data['Layer Seq'],dtype=int,sep=' ')):
     4803            linePos[ilay+1:] += data['Layers'][lay].get('Thick',[0.,False])[0]
    48024804        if data['Zero'] == 'Top':
    48034805            XY = [[x,y],]
     
    49224924            Name = Obj.GetValue()
    49234925            data['Layers'][item]['Name'] = Name
    4924             data['Layers'][item]['Rough'] = [0.,False]
    4925             data['Layers'][item]['Thick'] = [1.,False]
     4926            if 'Rough' not in data['Layers'][item]:
     4927                data['Layers'][item]['Rough'] = [0.,False]
     4928            if 'Thick' not in data['Layers'][item]:
     4929                data['Layers'][item]['Thick'] = [10.,False]
    49264930            if 'N' in Inst['Type'][0]:
    49274931                data['Layers'][item]['Mag SLD'] = [0.,False]
     
    49414945            ind = Indx[Obj.GetId()]
    49424946            data['Layers'].insert(ind+1,{'Name':'vacuum','DenMul':[1.0,False],})
     4947            data['Layer Seq'] = ' '.join([str(i+1) for i in range(len(data['Layers'])-2)])
    49434948            G2pwd.REFDModelFxn(Profile,Inst,Limits,Substances,data)
    49444949            G2plt.PlotPatterns(G2frame,plotType='REFD')
     
    49494954            ind = Indx[Obj.GetId()]
    49504955            del data['Layers'][ind]
     4956            data['Layer Seq'] = ' '.join([str(i+1) for i in range(len(data['Layers'])-2)])
    49514957            G2pwd.REFDModelFxn(Profile,Inst,Limits,Substances,data)
    49524958            G2plt.PlotPatterns(G2frame,plotType='REFD')
     
    50695075       
    50705076        return layerSizer
     5077       
     5078    def OnRepSeq(event):
     5079        event.Skip()
     5080        stack = repseq.GetValue()
     5081        nstar = stack.count('*')
     5082        if nstar:
     5083            try:
     5084                newstack = ''
     5085                Istar = 0
     5086                for star in range(nstar):
     5087                    Istar = stack.index('*',Istar+1)
     5088                    iB = stack[:Istar].rfind(' ')
     5089                    if iB == -1:
     5090                        mult = int(stack[:Istar])
     5091                    else:
     5092                        mult = int(stack[iB:Istar])
     5093                    pattern = stack[Istar+2:stack.index(')',Istar)]+' '
     5094                    newstack += mult*pattern
     5095                stack = newstack
     5096            except ValueError:
     5097                stack += ' Error in string'
     5098                wx.MessageBox(stack,'Error',style=wx.ICON_EXCLAMATION)
     5099                repseq.SetValue(data['Layer Seq'])
     5100                return
     5101        try:
     5102            Slist = np.array(stack.split(),dtype=int)
     5103        except ValueError:
     5104            stack += ' Error in string'
     5105            repseq.SetValue(data['Layer Seq'])
     5106            wx.MessageBox(stack,'Error',style=wx.ICON_EXCLAMATION)
     5107            return
     5108        if len(Slist) < 1:
     5109            stack += ' Error in sequence - too short!'
     5110        Stest = np.arange(1,Nlayers-1)
     5111        if not np.all(np.array([item in Stest for item in Slist])):
     5112            stack += ' Error: invalid layer selection'
     5113        elif not np.all(np.ediff1d(Slist)):
     5114            stack += ' Error: Improbable sequence or bad string'
     5115        if 'Error' in stack:
     5116            repseq.SetValue(data['Layer Seq'])
     5117            wx.MessageBox(stack,'Error',style=wx.ICON_EXCLAMATION)
     5118            return
     5119        else:
     5120            data['Layer Seq'] = stack
     5121            repseq.SetValue(stack)
     5122            G2pwd.REFDModelFxn(Profile,Inst,Limits,Substances,data)
     5123            x,xr,y = G2pwd.makeSLDprofile(data,Substances)
     5124            ModelPlot(data,x,xr,y)
     5125            G2plt.PlotPatterns(G2frame,plotType='REFD')
    50715126   
    50725127    Substances = G2frame.PatternTree.GetItemPyData(G2gd.GetPatternTreeItemId(G2frame,G2frame.PatternId, 'Substances'))['Substances']
     
    50945149    mainSizer.Add(wx.StaticText(G2frame.dataDisplay,label=' Global parameters:'),0,WACV)
    50955150    mainSizer.Add(OverallSizer())
    5096     G2G.HorizontalLine(mainSizer,G2frame.dataDisplay)   
     5151    G2G.HorizontalLine(mainSizer,G2frame.dataDisplay)
     5152    Nlayers = len(data['Layers'])
     5153    if Nlayers > 2:
     5154        if 'Layer Seq' not in data:
     5155            data['Layer Seq'] = ' '.join([str(i+1) for i in range(Nlayers-2)])
     5156        lineSizer = wx.BoxSizer(wx.HORIZONTAL)
     5157        lineSizer.Add(wx.StaticText(G2frame.dataDisplay,label=' Layer sequence: '),0,WACV)
     5158        repseq = wx.TextCtrl(G2frame.dataDisplay,value = data['Layer Seq'],style=wx.TE_PROCESS_ENTER,size=(500,25))
     5159        repseq.Bind(wx.EVT_TEXT_ENTER,OnRepSeq)       
     5160        repseq.Bind(wx.EVT_KILL_FOCUS,OnRepSeq)
     5161        lineSizer.Add(repseq,0,WACV)
     5162        mainSizer.Add(lineSizer)
     5163        Str = ' Use sequence nos. from:'
     5164        for ilay,layer in enumerate(data['Layers'][1:-1]):
     5165            Str += ' %d: %s'%(ilay+1,layer['Name'])
     5166        mainSizer.Add(wx.StaticText(G2frame.dataDisplay,label=Str),0,WACV)
     5167        mainSizer.Add(wx.StaticText(G2frame.dataDisplay,label=' NB: Repeat sequence by e.g. 6*(1 2) '),0,WACV)
    50975168    G2G.HorizontalLine(mainSizer,G2frame.dataDisplay)   
    50985169    mainSizer.Add(wx.StaticText(G2frame.dataDisplay,label=' Layers: scatt. densities are 10%scm%s = 10%s%s%s'%(Pwr10,Pwrm2,Pwrm6,Angstr,Pwrm2)),0,WACV)
     
    51045175    Size = mainSizer.Fit(G2frame.dataFrame)
    51055176    Size[0] += 25
     5177    Size[1] = min(700,Size[1])
    51065178    G2frame.dataFrame.setSizePosLeft(Size)
    51075179#    x,xr,y = G2pwd.makeSLDprofile(data,Substances)
  • trunk/Substances.py

    r2763 r2776  
    4040'ZrO2':{'Elements':{'Zr':{'Num':1.},'O':{'Num':3,}},'Density':6.134,},
    4141'Y(0.16)Zr(0.84)O2':{'Elements':{'Y':{'Num':0.16},'Zr':{'Num':0.84},'O':{'Num':2.}},'Density':6.01,},
     42'Ag':{'Elements':{'Ag':{'Num':1}},'Volume':17.066},
     43'Al':{'Elements':{'Al':{'Num':1}},'Volume':16.582},
     44'Au':{'Elements':{'Au':{'Num':1}},'Volume':16.953},
     45'Co':{'Elements':{'Co':{'Num':1}},'Volume':11.0177},
     46'FeF2':{'Elements':{'Fe':{'Num':1},'F':{'Num':2}},'Volume':36.352},
     47'GaAs':{'Elements':{'Ga':{'Num':1},'As':{'Num':1}},'Volume':45.173},
     48'LaAlO3':{'Elements':{'La':{'Num':1},'Al':{'Num':1},'O':{'Num':3}},'Volume':54.503},
     49'LaFeO3':{'Elements':{'La':{'Num':1},'Al':{'Num':1},'O':{'Num':3}},'Volume':50.355},
     50'LaMnO3':{'Elements':{'La':{'Num':1},'Mn':{'Num':1},'o':{'Num':3}},'Volume':58.413},
     51'MgF2':{'Elements':{'Mg':{'Num':1},'F':{'Num':2}},'Volume':32.58},
     52'MgO':{'Elements':{'Mg':{'Num':1},'O':{'Num':1}},'Volume':17.977},
     53'MnF2':{'Elements':{'Mn':{'Num':1},'F':{'Num':2}},'Volume':38.56},
     54'NiO':{'Elements':{'Ni':{'Num':1},'O':{'Num':1}},'Volume':18.22},
     55'Pd':{'Elements':{'Pd':{'Num':1}},'Volume':14.738},
     56'Pt':{'Elements':{'Pt':{'Num':1}},'Volume':15.14},
     57'SrTiO3':{'Elements':{'Sr':{'Num':1},'Ti':{'Num':1},'O':{'Num':1}},'Volume':26.71},
     58'V':{'Elements':{'V':{'Num':1}},'Volume':19.26},
    4259}
    4360# they should not be duplicated in the UserSubstances.py file:
Note: See TracChangeset for help on using the changeset viewer.