Changeset 620 for trunk/GSASIIstruct.py


Ignore:
Timestamp:
May 17, 2012 7:52:59 PM (10 years ago)
Author:
vondreele
Message:

remove excessive tabs in source code
fix HKL controls GUI
change HKL reflection record to match the PWDR one
start getting HKLF into fourier & charge flip

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/GSASIIstruct.py

    r612 r620  
    424424        HKLFdata = single crystal data list of reflections: for each reflection:
    425425            HKLF = [np.array([h,k,l]),FoSq,sigFoSq,FcSq,Fcp,Fcpp,phase]
     426            need this [h,k,l,mul,d,pos,0.0,0.0,0.0,0.0,0.0,Uniq,phi,0.0,{}]
    426427    '''
    427428    fl = open(GPXfile,'rb')
     
    495496        refI = int(varyI.split(':')[-1])
    496497        ih,ik,il = PawleyRef[refI][:3]
     498        dspI = PawleyRef[refI][4]
    497499        for varyJ in pawleyVary[i+1:]:
    498500            refJ = int(varyJ.split(':')[-1])
    499501            jh,jk,jl = PawleyRef[refJ][:3]
     502            dspJ = PawleyRef[refJ][4]
    500503            if SGLaue in ['4/m','4/mmm']:
    501504                isum = ih**2+ik**2
     
    519522                jsum = jh**2+jk**2+jl**2
    520523                if isum == jsum:
    521                     eqvDict[varyI].append(varyJ)
     524                    eqvDict[varyI].append(varyJ)
     525#            if abs(dspI-dspJ) < 3.e-4:
     526#                eqvDict[varyI].append(varyJ)
    522527    for item in pawleyVary:
    523528        if eqvDict[item]:
     
    17461751################################################################################
    17471752
    1748 def getPenalties():
    1749     return []
    1750    
    1751 def penaltyFxn(penalties):
    1752     return []
    1753    
    1754 def penaltyDeriv(penalties):
    1755     return []
     1753def penaltyFxn(parmDict,varyList):
     1754    pFxn = np.zeros(len(varyList))
     1755    for i,item in enumerate(varyList):
     1756        if 'PWLref' in item and parmDict[item] < 0.:
     1757            pFxn[i] = -parmDict[item]
     1758    return pFxn
     1759   
     1760def penaltyDeriv(parmDict,varyList):
     1761    pDerv = np.zeros(len(varyList))
     1762    for i,item in enumerate(varyList):
     1763        if 'PWLref' in item and parmDict[item] < 0.:
     1764            pDerv[i] += -1./parmDict[item]
     1765    return pDerv
    17561766
    17571767################################################################################
     
    27422752    return dMdv
    27432753
    2744 def dervRefine(values,HistoPhases,penalties,parmdict,varylist,calcControls,pawleyLookup,dlg):
     2754def dervRefine(values,HistoPhases,parmdict,varylist,calcControls,pawleyLookup,dlg):
    27452755    parmdict.update(zip(varylist,values))
    27462756    G2mv.Dict2Map(parmdict,varylist)
     
    27652775            else:
    27662776                dMdv = dMdvh
    2767     if penalties:
    2768         dmdv = np.concatenate((dmdv.T,penaltyDeriv(penalties).T)).T
     2777#    dpdv = penaltyDeriv(parmdict,varylist)
     2778#    dMdv = np.concatenate((dMdv.T,np.outer(dpdv,dpdv))).T
    27692779    return dMdv
    27702780
    2771 #def ComputePowderHessian(args):
    2772 #    Histogram,parmdict,varylist,Phases,calcControls,pawleyLookup = args
    2773 #    hId = Histogram['hId']
    2774 #    hfx = ':%d:'%(hId)
    2775 #    Limits = calcControls[hfx+'Limits']
    2776 #    x,y,w,yc,yb,yd = Histogram['Data']
    2777 #    dy = y-yc
    2778 #    xB = np.searchsorted(x,Limits[0])
    2779 #    xF = np.searchsorted(x,Limits[1])
    2780 #    dMdvh = np.sqrt(w[xB:xF])*getPowderProfileDerv(
    2781 #        parmdict,x[xB:xF],
    2782 #        varylist,Histogram,Phases,calcControls,pawleyLookup)
    2783 #    Vec = np.sum(dMdvh*np.sqrt(w[xB:xF])*dy[xB:xF],axis=1)
    2784 #    Hess = np.inner(dMdvh,dMdvh)
    2785 #    return Vec,Hess
    2786 #
    2787 def HessRefine(values,HistoPhases,penalties,parmdict,varylist,calcControls,pawleyLookup,dlg):
     2781def HessRefine(values,HistoPhases,parmdict,varylist,calcControls,pawleyLookup,dlg):
    27882782    parmdict.update(zip(varylist,values))
    27892783    G2mv.Dict2Map(parmdict,varylist)
     
    28132807                Vec = np.sum(dMdvh*np.sqrt(w[xB:xF])*dy[xB:xF],axis=1)
    28142808                Hess = np.inner(dMdvh,dMdvh)
     2809#    dpdv = penaltyDeriv(parmdict,varylist)
     2810#    Vec += dpdv*penaltyFxn(parmdict,varylist)
     2811#    Hess += np.outer(dpdv,dpdv)
    28152812    return Vec,Hess
    28162813
    2817 #def ComputePowderProfile(args):
    2818 #    Histogram,parmdict,varylist,Phases,calcControls,pawleyLookup = args
    2819 #    hId = Histogram['hId']
    2820 #    hfx = ':%d:'%(hId)
    2821 #    x,y,w,yc,yb,yd = Histogram['Data']
    2822 #    Limits = calcControls[hfx+'Limits']
    2823 #    xB = np.searchsorted(x,Limits[0])
    2824 #    xF = np.searchsorted(x,Limits[1])
    2825 #    yc,yb = getPowderProfile(parmdict,x[xB:xF],varylist,Histogram,Phases,
    2826 #        calcControls,pawleyLookup)
    2827 #    return xB,xF,yc,yb,Histogram['Reflection Lists']
    2828 #
    2829 def errRefine(values,HistoPhases,penalties,parmdict,varylist,calcControls,pawleyLookup,dlg):       
     2814def errRefine(values,HistoPhases,parmdict,varylist,calcControls,pawleyLookup,dlg):       
    28302815    parmdict.update(zip(varylist,values))
    28312816    Values2Dict(parmdict, varylist, values)
     
    28712856            parmDict['saved values'] = values
    28722857            raise Exception         #Abort!!
    2873     if penalties:
    2874         M = np.concatenate((M,penaltyFxn(penalties)))
     2858#    M = np.concatenate((M,penaltyFxn(parmdict,varylist)))
    28752859    return M
    28762860                       
     
    29352919        begin = time.time()
    29362920        values =  np.array(Dict2Values(parmDict, varyList))
    2937         penalties = getPenalties()
    29382921        Ftol = Controls['min dM/M']
    29392922        Factor = Controls['shift factor']
     
    29422925            result = so.leastsq(errRefine,values,Dfun=dervRefine,full_output=True,
    29432926                ftol=Ftol,col_deriv=True,factor=Factor,
    2944                 args=([Histograms,Phases],penalties,parmDict,varyList,calcControls,pawleyLookup,dlg))
     2927                args=([Histograms,Phases],parmDict,varyList,calcControls,pawleyLookup,dlg))
    29452928            ncyc = int(result[2]['nfev']/2)
    29462929        elif 'Hessian' in Controls['deriv type']:
    29472930            result = G2mth.HessianLSQ(errRefine,values,Hess=HessRefine,ftol=Ftol,maxcyc=maxCyc,
    2948                 args=([Histograms,Phases],penalties,parmDict,varyList,calcControls,pawleyLookup,dlg))
     2931                args=([Histograms,Phases],parmDict,varyList,calcControls,pawleyLookup,dlg))
    29492932            ncyc = result[2]['num cyc']+1
    29502933            Rvals['lamMax'] = result[2]['lamMax']                           
    29512934        else:           #'numeric'
    29522935            result = so.leastsq(errRefine,values,full_output=True,ftol=Ftol,epsfcn=1.e-8,factor=Factor,
    2953                 args=([Histograms,Phases],penalties,parmDict,varyList,calcControls,pawleyLookup,dlg))
     2936                args=([Histograms,Phases],parmDict,varyList,calcControls,pawleyLookup,dlg))
    29542937            ncyc = int(result[2]['nfev']/len(varyList))
    29552938#        table = dict(zip(varyList,zip(values,result[0],(result[0]-values))))
     
    31213104            begin = time.time()
    31223105            values =  np.array(Dict2Values(parmDict,varyList))
    3123             penalties = getPenalties()
    31243106            Ftol = Controls['min dM/M']
    31253107            Factor = Controls['shift factor']
     
    31293111                result = so.leastsq(errRefine,values,Dfun=dervRefine,full_output=True,
    31303112                    ftol=Ftol,col_deriv=True,factor=Factor,
    3131                     args=([Histo,Phases],penalties,parmDict,varyList,calcControls,pawleyLookup,dlg))
     3113                    args=([Histo,Phases],parmDict,varyList,calcControls,pawleyLookup,dlg))
    31323114                ncyc = int(result[2]['nfev']/2)
    31333115            elif 'Hessian' in Controls['deriv type']:
    31343116                result = G2mth.HessianLSQ(errRefine,values,Hess=HessRefine,ftol=Ftol,maxcyc=maxCyc,
    3135                     args=([Histo,Phases],penalties,parmDict,varyList,calcControls,pawleyLookup,dlg))
     3117                    args=([Histo,Phases],parmDict,varyList,calcControls,pawleyLookup,dlg))
    31363118                ncyc = result[2]['num cyc']+1                           
    31373119            else:           #'numeric'
    31383120                result = so.leastsq(errRefine,values,full_output=True,ftol=Ftol,epsfcn=1.e-8,factor=Factor,
    3139                     args=([Histo,Phases],penalties,parmDict,varyList,calcControls,pawleyLookup,dlg))
     3121                    args=([Histo,Phases],parmDict,varyList,calcControls,pawleyLookup,dlg))
    31403122                ncyc = int(result[2]['nfev']/len(varyList))
    31413123
     
    32263208    Factor = DisAglCtls['Factors']
    32273209    Radii = dict(zip(DisAglCtls['AtomTypes'],zip(DisAglCtls['BondRadii'],DisAglCtls['AngleRadii'])))
    3228 #    Units = np.array([                   #is there a nicer way to make this?
    3229 #        [-1,-1,-1],[-1,-1,0],[-1,-1,1],[-1,0,-1],[-1,0,0],[-1,0,1],[-1,1,-1],[-1,1,0],[-1,1,1],
    3230 #        [0,-1,-1],[0,-1,0],[0,-1,1],[0,0,-1],[0,0,0],[0,0,1],[0,1,-1],[0,1,0],[0,1,1],
    3231 #        [1,-1,-1],[1,-1,0],[1,-1,1],[1,0,-1],[1,0,0],[1,0,1],[1,1,-1],[1,1,0],[1,1,1]])
    32323210    indices = (-1,0,1)
    32333211    Units = np.array([[h,k,l] for h in indices for k in indices for l in indices])
Note: See TracChangeset for help on using the changeset viewer.