Changeset 1585 for trunk/GSASIIindex.py


Ignore:
Timestamp:
Nov 25, 2014 2:42:11 PM (8 years ago)
Author:
vondreele
Message:

remove Pwr from FitPeaksZ, SSZ & T - wasn't used
put in derivatives for FitPeaksZ, etc. - works better
reorder arrows & make the expand/shrink symmetric about view point
remove zero & refine? from SS Unit Cells display - not refinable with modulation coeff.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/GSASIIindex.py

    r1582 r1585  
    4747npatand = lambda x: 180.*np.arctan(x)/np.pi
    4848npatan2d = lambda y,x: 180.*np.arctan2(y,x)/np.pi
     49rpd = np.pi/180.
    4950   
    5051def scaleAbyV(A,V):
     
    362363        return [values[0],values[1],values[2],0,values[3],0]
    363364    else:
    364         return list(values)
     365        return list(values[:6])
    365366       
    366367def A2values(ibrav,A):
     
    413414    return True,np.sum(errFit(result[0],ibrav,Peaks[7],Peaks[4:7],Pwr)**2),A,result
    414415           
    415 def errFitZ(values,ibrav,d,H,tth,wave,Z,Zref,Pwr):
     416def errFitZ(values,ibrav,d,H,tth,wave,Z,Zref):
    416417    Zero = Z
    417418    if Zref:   
    418419        Zero = values[-1]
    419     A = Values2A(ibrav,values[:6])
     420    A = Values2A(ibrav,values)
    420421    Qo = 1./d**2
    421422    Qc = G2lat.calc_rDsqZ(H,A,Zero,tth,wave)
    422     return (Qo-Qc)*d**Pwr
    423    
    424 def FitHKLZ(wave,ibrav,peaks,A,Z,Zref,Pwr):
     423    return (Qo-Qc)
     424   
     425def dervFitZ(values,ibrav,d,H,tth,wave,Z,Zref):
     426    if ibrav in [0,1,2]:
     427        derv = [H[0]*H[0]+H[1]*H[1]+H[2]*H[2],]
     428    elif ibrav in [3,4,]:
     429        derv = [H[0]*H[0]+H[1]*H[1]+H[0]*H[1],H[2]*H[2]]
     430    elif ibrav in [5,6]:
     431        derv = [H[0]*H[0]+H[1]*H[1],H[2]*H[2]]
     432    elif ibrav in [7,8,9,10]:
     433        derv = [H[0]*H[0],H[1]*H[1],H[2]*H[2]]
     434    elif ibrav in [11,12]:
     435        derv = [H[0]*H[0],H[1]*H[1],H[2]*H[2],H[0]*H[2]]
     436    else:
     437        derv = [H[0]*H[0],H[1]*H[1],H[2]*H[2],H[0]*H[1],H[0]*H[2],H[1]*H[2]]
     438    if Zref:
     439        derv.append(npsind(tth)*2.0*rpd/wave**2)
     440    derv = -np.array(derv)
     441    return derv.T
     442   
     443def FitHKLZ(wave,ibrav,peaks,A,Z,Zref):
    425444    'needs a doc string'
    426445   
     
    429448    if Zref:
    430449        values.append(Z)
    431     result = so.leastsq(errFitZ,values,full_output=True,ftol=0.0001,factor=10.,
    432         args=(ibrav,Peaks[7],Peaks[4:7],Peaks[0],wave,Z,Zref,Pwr))
     450    result = so.leastsq(errFitZ,values,Dfun=dervFitZ,full_output=True,ftol=0.0001,
     451        args=(ibrav,Peaks[7],Peaks[4:7],Peaks[0],wave,Z,Zref))
    433452    A = Values2A(ibrav,result[0][:6])
    434453    if Zref:
    435454        Z = result[0][-1]
    436     chisq = np.sum(errFitZ(result[0],ibrav,Peaks[7],Peaks[4:7],Peaks[0],wave,Z,Zref,Pwr)**2)
     455    chisq = np.sum(errFitZ(result[0],ibrav,Peaks[7],Peaks[4:7],Peaks[0],wave,Z,Zref)**2)
    437456    return True,chisq,A,Z,result
    438457   
    439 def errFitZSS(values,ibrav,d,H,tth,wave,vec,Vref,Z,Zref,Pwr):
     458def errFitZSS(values,ibrav,d,H,tth,wave,vec,Vref,Z,Zref):
    440459    Zero = Z
    441460    if Zref:   
    442461        Zero = values[-1]
    443     A = Values2A(ibrav,values[:6])
    444     vec = Values2Vec(ibrav,vec,Vref,values)
     462    A = Values2A(ibrav,values)
     463    Vec = Values2Vec(ibrav,vec,Vref,values)
    445464    Qo = 1./d**2
    446     Qc = G2lat.calc_rDsqZSS(H,A,vec,Zero,tth,wave)
    447     return (Qo-Qc)*d**Pwr
    448    
    449 def FitHKLZSS(wave,ibrav,peaks,A,V,Vref,Z,Zref,Pwr):
     465    Qc = G2lat.calc_rDsqZSS(H,A,Vec,Zero,tth,wave)
     466    return (Qo-Qc)
     467   
     468def dervFitZSS(values,ibrav,d,H,tth,wave,vec,Vref,Z,Zref):
     469    A = Values2A(ibrav,values)
     470    Vec = Values2Vec(ibrav,vec,Vref,values)
     471    HM = H[:3]+(H[3][:,np.newaxis]*Vec).T
     472    if ibrav in [3,4,]:
     473        derv = [HM[0]*HM[0]+HM[1]*HM[1]+HM[0]*HM[1],HM[2]*HM[2]]
     474    elif ibrav in [5,6]:
     475        derv = [HM[0]*HM[0]+HM[1]*HM[1],HM[2]*HM[2]]
     476    elif ibrav in [7,8,9,10]:
     477        derv = [HM[0]*HM[0],HM[1]*HM[1],HM[2]*HM[2]]
     478    elif ibrav in [11,12]:
     479        derv = [HM[0]*HM[0],HM[1]*HM[1],HM[2]*HM[2],HM[0]*HM[2]]
     480    else:
     481        derv = [HM[0]*HM[0],HM[1]*HM[1],HM[2]*HM[2],HM[0]*HM[1],HM[0]*HM[2],HM[1]*HM[2]]
     482    if Vref[0]:
     483        derv.append(2.*A[0]*HM[0]*H[3]+A[3]*HM[1]*H[3]+A[4]*HM[2]*H[3])
     484    if Vref[1]:
     485        derv.append(2.*A[1]*HM[1]*H[3]+A[3]*HM[0]*H[3]+A[5]*HM[2]*H[3])
     486    if Vref[2]:
     487        derv.append(2.*A[2]*HM[2]*H[3]+A[4]*HM[1]*H[3]+A[5]*HM[0]*H[3])   
     488    if Zref:
     489        derv.append(npsind(tth)*2.0*rpd/wave**2)
     490    derv = -np.array(derv)
     491    return derv.T
     492   
     493def FitHKLZSS(wave,ibrav,peaks,A,V,Vref,Z,Zref):
    450494    'needs a doc string'
    451495   
     
    457501    if Zref:
    458502        values.append(Z)
    459     result = so.leastsq(errFitZSS,values,full_output=True,ftol=1.e-6,factor=10.,
    460         args=(ibrav,Peaks[8],Peaks[4:8],Peaks[0],wave,V,Vref,Z,Zref,Pwr))
     503    result = so.leastsq(errFitZSS,values,Dfun=dervFitZSS,full_output=True,ftol=1.e-6,
     504        args=(ibrav,Peaks[8],Peaks[4:8],Peaks[0],wave,V,Vref,Z,Zref))
    461505    A = Values2A(ibrav,result[0])
    462506    Vec = Values2Vec(ibrav,V,Vref,result[0])
    463507    if Zref:
    464508        Z = result[0][-1]
    465     chisq = np.sum(errFitZSS(result[0],ibrav,Peaks[8],Peaks[4:8],Peaks[0],wave,Vec,Vref,Z,Zref,Pwr)**2)
     509    chisq = np.sum(errFitZSS(result[0],ibrav,Peaks[8],Peaks[4:8],Peaks[0],wave,Vec,Vref,Z,Zref)**2)
    466510    return True,chisq,A,Vec,Z,result
    467511   
    468 def errFitT(values,ibrav,d,H,tof,difC,Z,Zref,Pwr):
     512def errFitT(values,ibrav,d,H,tof,difC,Z,Zref):
    469513    Zero = Z
    470514    if Zref:   
    471515        Zero = values[-1]
    472     A = Values2A(ibrav,values[:6])
     516    A = Values2A(ibrav,values)
    473517    Qo = 1./d**2
    474518    Qc = G2lat.calc_rDsqT(H,A,Zero,tof,difC)
    475     return (Qo-Qc)*d**Pwr
    476    
    477 def FitHKLT(difC,ibrav,peaks,A,Z,Zref,Pwr):
     519    return (Qo-Qc)
     520   
     521def dervFitT(values,ibrav,d,H,tof,difC,Z,Zref):
     522    if ibrav in [0,1,2]:
     523        derv = [H[0]*H[0]+H[1]*H[1]+H[2]*H[2],]
     524    elif ibrav in [3,4,]:
     525        derv = [H[0]*H[0]+H[1]*H[1]+H[0]*H[1],H[2]*H[2]]
     526    elif ibrav in [5,6]:
     527        derv = [H[0]*H[0]+H[1]*H[1],H[2]*H[2]]
     528    elif ibrav in [7,8,9,10]:
     529        derv = [H[0]*H[0],H[1]*H[1],H[2]*H[2]]
     530    elif ibrav in [11,12]:
     531        derv = [H[0]*H[0],H[1]*H[1],H[2]*H[2],H[0]*H[2]]
     532    else:
     533        derv = [H[0]*H[0],H[1]*H[1],H[2]*H[2],H[0]*H[1],H[0]*H[2],H[1]*H[2]]
     534    if Zref:
     535        derv.append(np.ones_like(d)/difC)
     536    derv = -np.array(derv)
     537    return derv.T
     538   
     539def FitHKLT(difC,ibrav,peaks,A,Z,Zref):
    478540    'needs a doc string'
    479541   
     
    482544    if Zref:
    483545        values.append(Z)
    484     result = so.leastsq(errFitT,values,full_output=True,ftol=0.0001,factor=0.001,
    485         args=(ibrav,Peaks[7],Peaks[4:7],Peaks[0],difC,Z,Zref,Pwr))
    486     A = Values2A(ibrav,result[0][:6])
     546    result = so.leastsq(errFitT,values,Dfun=dervFitT,full_output=True,ftol=0.0001,
     547        args=(ibrav,Peaks[7],Peaks[4:7],Peaks[0],difC,Z,Zref))
     548    A = Values2A(ibrav,result[0])
    487549    if Zref:
    488550        Z = result[0][-1]
    489     chisq = np.sum(errFitT(result[0],ibrav,Peaks[7],Peaks[4:7],Peaks[0],difC,Z,Zref,Pwr)**2)
     551    chisq = np.sum(errFitT(result[0],ibrav,Peaks[7],Peaks[4:7],Peaks[0],difC,Z,Zref)**2)
    490552    return True,chisq,A,Z,result
    491553               
     
    539601    'needs a doc string'
    540602    dmin = getDmin(peaks)
    541     OK,smin,Aref,Z,result = FitHKLZ(wave,ibrav,peaks,A,Zero,ZeroRef,0)
     603    OK,smin,Aref,Z,result = FitHKLZ(wave,ibrav,peaks,A,Zero,ZeroRef)
    542604    Peaks = np.array(peaks).T
    543605    H = Peaks[4:7]
     
    551613    'needs a doc string'
    552614    dmin = getDmin(peaks)
    553     print Zero
    554     OK,smin,Aref,Vref,Z,result = FitHKLZSS(wave,ibrav,peaks,A,vec,vecRef,Zero,ZeroRef,0)
    555     print Z
     615    OK,smin,Aref,Vref,Z,result = FitHKLZSS(wave,ibrav,peaks,A,vec,vecRef,Zero,ZeroRef)
    556616    Peaks = np.array(peaks).T
    557617    H = Peaks[4:8]
     
    565625    'needs a doc string'
    566626    dmin = getDmin(peaks)
    567     OK,smin,Aref,Z,result = FitHKLT(difC,ibrav,peaks,A,Zero,ZeroRef,0)
     627    OK,smin,Aref,Z,result = FitHKLT(difC,ibrav,peaks,A,Zero,ZeroRef)
    568628    Peaks = np.array(peaks).T
    569629    H = Peaks[4:7]
Note: See TracChangeset for help on using the changeset viewer.