Changeset 2763 for trunk/GSASIIpwd.py


Ignore:
Timestamp:
Mar 29, 2017 1:57:33 PM (5 years ago)
Author:
vondreele
Message:

add plotting of reflectometry model scattering profiles
add magnetic scatterin component to refl. models (neutrons)
refactor model GUI
allow rescaling of REFD & PWDR profiles via Scale in Sample Parms
cange int element nos. to float ones in Substances

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/GSASIIpwd.py

    r2761 r2763  
    2828import scipy.stats as st
    2929import scipy.optimize as so
     30import scipy.special as sp
    3031
    3132import GSASIIpath
     
    19311932            name = layer['Name']
    19321933            cid = str(ilay)+';'
    1933             for parm in ['Thick','Rough','DenMul']:
     1934            for parm in ['Thick','Rough','DenMul','Mag SLD']:
    19341935                parmDict[cid+parm] = layer.get(parm,[0.,False])[0]
    19351936                if layer.get(parm,[0.,False])[1]:
     
    19591960            line2 = ' Scattering density: Real %.5g'%(Substances[name]['Scatt density']*parmDict[cid+'DenMul'])
    19601961            line2 += ' Imag %.5g'%(Substances[name].get('XImag density',0.)**parmDict[cid+'DenMul'])
    1961             for parm in ['Thick','Rough','DenMul']:
     1962            for parm in ['Thick','Rough','DenMul','Mag SLD']:
    19621963                if parm in layer:
    19631964                    layer[parm][0] = parmDict[cid+parm]
     
    19911992            sigma[ilay] = parmDict[cid+'Rough']
    19921993            rho[ilay] = parmDict[cid+'rho']*parmDict[cid+'DenMul']
     1994            if cid+'Mag SLD' in parmDict:
     1995                rho[ilay] += parmDict[cid+'Mag SLD']
    19931996            irho[ilay] = parmDict[cid+'irho']*parmDict[cid+'DenMul']
    19941997            A,B = abeles(0.5*Q,depth,rho,irho,sigma[1:])     #Q --> k, offset roughness for abeles
     
    20032006    Ifin = np.searchsorted(Q,Qmax)+1    #include last point
    20042007    Ic[:] = 0
    2005     Bounds = {'Scale':[data['Scale'][0]*.85,data['Scale'][0]/.85],'FltBack':[None,None],'DenMul':[0.,None],'Thick':[1.,None],'Rough':[0.,None]}
     2008    Bounds = {'Scale':[data['Scale'][0]*.85,data['Scale'][0]/.85],'FltBack':[None,None],
     2009              'DenMul':[0.,None],'Thick':[1.,None],'Rough':[0.,None],'Mag SLD':[-10.,10.]}
    20062010    parmDict,varyList,values,bounds = GetModelParms()
    20072011    Msg = 'Failed to converge'
     
    20562060            indx = Negs.nonzero()
    20572061            name = varyList[indx[0][0]]
    2058             if name != 'FltBack':
     2062            if name != 'FltBack' and 'Mag SLD' not in name:
    20592063                Msg += ' negative coefficient for '+name+'!'
    20602064                raise ValueError
     
    20742078        print Msg
    20752079        return False,0,0,0,0,0,0,Msg
     2080       
     2081def makeSLDprofile(data,Substances):
     2082   
     2083    sq2 = np.sqrt(2.)
     2084    Nlayers = len(data['Layers'])
     2085    interfaces = np.zeros(Nlayers)
     2086    rho = np.zeros(Nlayers)
     2087    irho = np.zeros(Nlayers)
     2088    sigma = np.zeros(Nlayers)
     2089    thick = 0.
     2090    for ilayer,layer in enumerate(data['Layers']):
     2091        name = layer['Name']
     2092        if 'Thick' in layer:    #skips first & last layers
     2093            thick += layer['Thick'][0]
     2094            interfaces[ilayer] = layer['Thick'][0]+interfaces[ilayer-1]
     2095        if 'Rough' in layer:    #skips first layer
     2096            sigma[ilayer] = max(0.001,layer['Rough'][0])
     2097        rho[ilayer] = Substances[name]['Scatt density']*layer['DenMul'][0]
     2098        if 'Mag SLD' in layer:
     2099            rho[ilayer] += layer['Mag SLD'][0]
     2100        irho[ilayer] = Substances[name].get('XImag density',0.)*layer['DenMul'][0]
     2101    x = np.linspace(-0.15*thick,1.15*thick,1000,endpoint=True)
     2102    xr = np.flipud(x)
     2103    interfaces[-1] = x[-1]
     2104    y = np.ones_like(x)*rho[0]
     2105    iBeg = 0
     2106    for ilayer in range(Nlayers-1):
     2107        delt = rho[ilayer+1]-rho[ilayer]
     2108        iPos = np.searchsorted(x,interfaces[ilayer])
     2109        y[iBeg:] += (delt/2.)*sp.erfc((interfaces[ilayer]-x[iBeg:])/(sq2*sigma[ilayer+1]))
     2110        iBeg = iPos
     2111    return x,xr,y   
    20762112
    20772113def REFDModelFxn(Profile,Inst,Limits,Substances,data):
     
    20972133            sigma[ilayer] = layer['Rough'][0]
    20982134        rho[ilayer] = Substances[name]['Scatt density']*layer['DenMul'][0]
     2135        if 'Mag SLD' in layer:
     2136            rho[ilayer] += layer['Mag SLD'][0]
    20992137        irho[ilayer] = Substances[name].get('XImag density',0.)*layer['DenMul'][0]
    21002138        A,B = abeles(0.5*Q[iBeg:iFin],depth,rho,irho,sigma[1:])     #Q --> k, offset roughness for abeles
Note: See TracChangeset for help on using the changeset viewer.