Changeset 312


Ignore:
Timestamp:
Jun 27, 2011 12:11:26 PM (10 years ago)
Author:
vondreele
Message:

implement refinement of zero point as part of cell refinement

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/GSASIIindex.py

    r311 r312  
    230230    else:
    231231        return False
     232       
     233def Values2A(ibrav,values):
     234    if ibrav in [0,1,2]:
     235        return [values[0],values[0],values[0],0,0,0]
     236    elif ibrav in [3,4]:
     237        return [values[0],values[0],values[1],values[0],0,0]
     238    elif ibrav in [5,6]:
     239        return [values[0],values[0],values[1],0,0,0]
     240    elif ibrav in [7,8,9,10]:
     241        return [values[0],values[1],values[2],0,0,0]
     242    elif ibrav in [11,12]:
     243        return [values[0],values[1],values[2],0,values[3],0]
     244    else:
     245        return list(values)
     246       
     247def A2values(ibrav,A):
     248    if ibrav in [0,1,2]:
     249        return [A[0],]
     250    elif ibrav in [3,4,5,6]:
     251        return [A[0],A[2]]
     252    elif ibrav in [7,8,9,10]:
     253        return [A[0],A[1],A[2]]
     254    elif ibrav in [11,12]:
     255        return [A[0],A[1],A[2],A[4]]
     256    else:
     257        return A
    232258
    233259def FitHKL(ibrav,peaks,A,Pwr):
    234    
    235     def Values2A(ibrav,values):
    236         if ibrav in [0,1,2]:
    237             return [values[0],values[0],values[0],0,0,0]
    238         elif ibrav in [3,4]:
    239             return [values[0],values[0],values[1],values[0],0,0]
    240         elif ibrav in [5,6]:
    241             return [values[0],values[0],values[1],0,0,0]
    242         elif ibrav in [7,8,9,10]:
    243             return [values[0],values[1],values[2],0,0,0]
    244         elif ibrav in [11,12]:
    245             return [values[0],values[1],values[2],0,values[3],0]
    246         else:
    247             return list(values)
    248            
    249     def A2values(ibrav,A):
    250         if ibrav in [0,1,2]:
    251             return [A[0],]
    252         elif ibrav in [3,4,5,6]:
    253             return [A[0],A[2]]
    254         elif ibrav in [7,8,9,10]:
    255             return [A[0],A[1],A[2]]
    256         elif ibrav in [11,12]:
    257             return [A[0],A[1],A[2],A[4]]
    258         else:
    259             return A
    260            
    261     def Jacobian(values,ibrav,d,H,Pwr):
    262 # derivatives of rdsq = H[0]*H[0]*A[0]+H[1]*H[1]*A[1]+H[2]*H[2]*A[2]+H[0]*H[1]*A[3]+H[0]*H[2]*A[4]+H[1]*H[2]*A[5]
    263         if ibrav in [0,1,2]:            #m3m
    264             return [H[0]*H[0]+H[1]*H[1]+H[2]*H[2],]*d**Pwr
    265         elif ibrav in [3,4]:            #R3H, P3/m & P6/mmm
    266             return [H[0]*H[0]+H[1]*H[0]+H[1]*H[1],H[2]*H[2]]*d**Pwr
    267         elif ibrav in [5,6]:            #4/mmm
    268             return [H[0]*H[0]+H[1]*H[1],H[2]*H[2]]*d**Pwr
    269         elif ibrav in [7,8,9,10]:       #mmm
    270             return [H[0]*H[0],H[1]*H[1],H[2]*H[2]]*d**Pwr
    271         elif ibrav in [11,12]:          #2/m
    272             return [H[0]*H[0],H[1]*H[1],H[2]*H[2],H[0]*H[2]]*d**Pwr
    273         else:                           #-1
    274             return [H[0]*H[0],H[1]*H[1],H[2]*H[2],H[1]*H[0],H[0]*H[2],H[1]*H[2]]*d**Pwr
    275    
     260               
    276261    def errFit(values,ibrav,d,H,Pwr):
    277262        A = Values2A(ibrav,values)
     
    283268   
    284269    values = A2values(ibrav,A)
    285 #    result = so.leastsq(errFit,values,args=(ibrav,Peaks[7],Peaks[4:7],Pwr),
    286 #        Dfun=Jacobian,col_deriv=True,full_output=True)
    287270    result = so.leastsq(errFit,values,args=(ibrav,Peaks[7],Peaks[4:7],Pwr),
    288271        full_output=True,factor=0.1)
     
    290273    return True,np.sum(errFit(result[0],ibrav,Peaks[7],Peaks[4:7],Pwr)**2),A,result
    291274           
    292 def FitHKLZ(ibrav,peaks,Z,A):
    293     return A,Z
    294    
     275def FitHKLZ(wave,ibrav,peaks,A,Z,Pwr):
     276   
     277    def errFit(values,ibrav,d,H,tth,wave,Pwr):
     278        A = Values2A(ibrav,values[:-1])
     279        Z = values[-1]
     280        Qo = 1./d**2
     281        Qc = G2lat.calc_rDsqZ(H,A,Z,tth,wave)
     282        return (Qo-Qc)*d**Pwr
     283   
     284    Peaks = np.array(peaks).T
     285   
     286    values = A2values(ibrav,A)
     287    values.append(Z)
     288    result = so.leastsq(errFit,values,args=(ibrav,Peaks[7],Peaks[4:7],Peaks[0],wave,Pwr),
     289        full_output=True)
     290    A = Values2A(ibrav,result[0][:-1])
     291    Z = result[0][-1]
     292   
     293    return True,np.sum(errFit(result[0],ibrav,Peaks[7],Peaks[4:7],Peaks[0],wave,Pwr)**2),A,Z,result
     294               
    295295def rotOrthoA(A):
    296296    return [A[1],A[2],A[0],0,0,0]
     
    333333    return peaks[0][7]
    334334   
    335 def refinePeaks(peaks,ibrav,A,Zero):
    336     #Zero is list(zero value, flag)
     335def refinePeaksZ(peaks,wave,ibrav,A,Zero):
     336    dmin = getDmin(peaks)
     337    OK,smin,Aref,Z,result = FitHKLZ(wave,ibrav,peaks,A,Zero,2)
     338    Peaks = np.array(peaks).T
     339    H = Peaks[4:7]
     340    Peaks[8] = 1./np.sqrt(G2lat.calc_rDsqZ(H,Aref,Z,Peaks[0],wave))
     341    peaks = Peaks.T
     342   
     343    HKL = G2lat.GenHBravais(dmin,ibrav,Aref)
     344    M20,X20 = calc_M20(peaks,HKL)
     345    return len(HKL),M20,X20,Aref,Z
     346   
     347def refinePeaks(peaks,ibrav,A):
    337348    dmin = getDmin(peaks)
    338349    smin = 1.0e10
    339350    pwr = 4
    340351    maxTries = 10
    341     if ibrav == 13: #-1 - triclinic
    342         pwr = 4
    343         maxTries = 10
    344352    OK = False
    345353    tries = 0
     
    376384       
    377385    M20,X20 = calc_M20(peaks,HKL)
    378     return len(HKL),M20,X20,A,Zero
     386    return len(HKL),M20,X20,A
    379387       
    380388def findBestCell(dlg,ncMax,A,Ntries,ibrav,peaks,V1):
     
    405413       
    406414        if IndexPeaks(peaks,HKL) and len(HKL) > mHKL[ibrav]:
    407             Lhkl,M20,X20,Aref,Zero = refinePeaks(peaks,ibrav,Abeg,[0,False])
     415            Lhkl,M20,X20,Aref = refinePeaks(peaks,ibrav,Abeg)
    408416            Asave.append([calc_M20(peaks,HKL),Aref[:]])
    409417            if ibrav == 9:                          #C-centered orthorhombic
    410418                for i in range(2):
    411419                    Abeg = rotOrthoA(Abeg[:])
    412                     Lhkl,M20,X20,Aref,Zero = refinePeaks(peaks,ibrav,Abeg,[0,False])
     420                    Lhkl,M20,X20,Aref = refinePeaks(peaks,ibrav,Abeg)
    413421                    HKL = G2lat.GenHBravais(dmin,ibrav,Aref)
    414422                    IndexPeaks(peaks,HKL)
     
    416424            elif ibrav == 11:                      #C-centered monoclinic
    417425                Abeg = swapMonoA(Abeg[:])
    418                 Lhkl,M20,X20,Aref,Zero = refinePeaks(peaks,ibrav,Abeg,[0,False])
     426                Lhkl,M20,X20,Aref = refinePeaks(peaks,ibrav,Abeg)
    419427                HKL = G2lat.GenHBravais(dmin,ibrav,Aref)
    420428                IndexPeaks(peaks,HKL)
     
    432440    X = sortM20(Asave)
    433441    if X:
    434         Lhkl,M20,X20,A,Zero = refinePeaks(peaks,ibrav,X[0][1],[0,False])
     442        Lhkl,M20,X20,A = refinePeaks(peaks,ibrav,X[0][1])
    435443        return GoOn,Lhkl,M20,X20,A
    436444       
     
    652660    print 'msg:',result[3]
    653661    print 'ier:',result[4]
    654     result = refinePeaks(peaks,ibrav,A,[0,False])
    655     N,M20,X20,A,Zero = result
     662    result = refinePeaks(peaks,ibrav,A)
     663    N,M20,X20,A = result
    656664    print 'refinePeaks:',N,M20,X20,G2lat.A2cell(A)
    657665    print 'compare bestcell:',bestcell
     
    664672    print 'FitHKL'
    665673    OK,smin,A,result = FitHKL(ibrav,peaks,A,Pwr)
    666     result = refinePeaks(peaks,ibrav,A,[0,False])
    667     N,M20,X20,A,Zero = result
     674    result = refinePeaks(peaks,ibrav,A)
     675    N,M20,X20,A = result
    668676    print 'refinePeaks:',N,M20,X20,A
    669677#    Peaks = np.array(peaks)
  • trunk/GSASIIlattice.py

    r311 r312  
    254254   
    255255def calc_rDsqZ(H,A,Z,tth,lam):
    256     rpd = math.pi/180.
    257     rdsq = calc_rDsq(H,A)+Z*math.sin(tth*rpd)*2.0*rpd/(lam*lam)
     256    rpd = np.pi/180.
     257    rdsq = calc_rDsq(H,A)+Z*sind(tth)*2.0*rpd/lam**2
    258258    return rdsq
    259259       
  • trunk/GSASIIpwdGUI.py

    r311 r312  
    792792        ibrav = bravaisSymb.index(controls[5])
    793793        dmin = G2indx.getDmin(peaks)-0.005
    794         Lhkl,M20,X20,Aref,Zero = G2indx.refinePeaks(peaks,ibrav,A,controls[:2])
    795         controls[:2] = Zero
     794        if controls[0]:
     795            Lhkl,M20,X20,Aref,Zero = G2indx.refinePeaksZ(peaks,inst[1],ibrav,A,controls[1])           
     796            controls[1] = Zero
     797        else:
     798            Lhkl,M20,X20,Aref = G2indx.refinePeaks(peaks,ibrav,A)
    796799        controls[6:12] = G2lat.A2cell(Aref)
    797800        controls[12] = G2lat.calc_V(Aref)
     
    9971000    zero.Bind(wx.EVT_KILL_FOCUS,OnZero)
    9981001    littleSizer.Add(zero,0,wx.ALIGN_CENTER_VERTICAL)
    999     zeroVar = wx.CheckBox(self.dataDisplay,label="Refine? (not implemented)")
     1002    zeroVar = wx.CheckBox(self.dataDisplay,label="Refine?")
     1003    zeroVar.SetValue(controls[0])
    10001004    zeroVar.Bind(wx.EVT_CHECKBOX,OnZeroVar)
    10011005    littleSizer.Add(zeroVar,0,wx.ALIGN_CENTER_VERTICAL)
Note: See TracChangeset for help on using the changeset viewer.