Changeset 1110


Ignore:
Timestamp:
Oct 16, 2013 11:52:06 AM (10 years ago)
Author:
vondreele
Message:

removed Uniq % Phi from reflection data structure - make locally (faster by 16%)

Location:
trunk
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/GSASIIIO.py

    r1106 r1110  
    15821582        self.InitParameters()
    15831583        self.InitControls()
    1584         self.RefDict = {'RefList':[],'Uniq':[],'Phi':[],'FF':[]}
     1584        self.RefDict = {'RefList':[],'FF':[]}
    15851585       
    15861586    def InitControls(self):
  • trunk/GSASIIgrid.py

    r1106 r1110  
    30933093        data[0] = {'wtFactor':1.0}
    30943094    if isinstance(data[1],list) and kind == 'HKLF':
    3095         RefData = {'RefList':[],'Uniq':[],'Phi':[],'FF':[]}
     3095        RefData = {'RefList':[],'FF':[]}
    30963096        for ref in data[1]:
    30973097            RefData['RefList'].append(ref[:11]+[ref[13],])
    3098             RefData['Uniq'].append(ref[11])
    3099             RefData['Phi'].append(ref[12])
    31003098            RefData['FF'].append(ref[14])
    31013099        data[1] = RefData
  • trunk/GSASIImath.py

    r1106 r1110  
    13571357    dmin = mapData['Resolution']
    13581358    SGData = generalData['SGData']
     1359    SGMT = np.array([ops[0].T for ops in SGData['SGOps']])
     1360    SGT = np.array([ops[1] for ops in SGData['SGOps']])
    13591361    cell = generalData['Cell'][1:8]       
    13601362    A = G2lat.cell2A(cell[:6])
     
    13661368        if ref[4] >= dmin:
    13671369            Fosq,Fcsq,ph = ref[8:11]
    1368             for i,hkl in enumerate(reflDict['Uniq']):        #uses uniq
     1370            Uniq = np.inner(ref[:3],SGMT)
     1371            Phi = np.inner(ref[:3],SGT)
     1372            for i,hkl in enumerate(Uniq):        #uses uniq
    13691373                hkl = np.asarray(hkl,dtype='i')
    1370                 dp = 360.*reflDict['Phi'][i]                #and phi
     1374                dp = 360.*Phi[i]                #and phi
    13711375                a = cosd(ph+dp)
    13721376                b = sind(ph+dp)
     
    14011405    dmin = mapData['Resolution']
    14021406    SGData = generalData['SGData']
     1407    SGMT = np.array([ops[0].T for ops in SGData['SGOps']])
     1408    SGT = np.array([ops[1] for ops in SGData['SGOps']])
    14031409    cell = generalData['Cell'][1:8]       
    14041410    A = G2lat.cell2A(cell[:6])
     
    14111417        if ref[4] >= dmin:
    14121418            Fosq,Fcsq,ph = ref[8:11]
    1413             for i,hkl in enumerate(reflDict['Uniq'][iref]):        #uses uniq
     1419            Uniq = np.inner(ref[:3],SGMT)
     1420            Phi = np.inner(ref[:3],SGT)
     1421            for i,hkl in enumerate(Uniq):        #uses uniq
    14141422                hkl = np.asarray(hkl,dtype='i')
    1415                 dp = 360.*reflDict['Phi'][iref][i]                #and phi
     1423                dp = 360.*Phi[i]                #and phi
    14161424                a = cosd(ph+dp)
    14171425                b = sind(ph+dp)
     
    15701578    dmin = flipData['Resolution']
    15711579    SGData = generalData['SGData']
     1580    SGMT = np.array([ops[0].T for ops in SGData['SGOps']])
     1581    SGT = np.array([ops[1] for ops in SGData['SGOps']])
    15721582    cell = generalData['Cell'][1:8]       
    15731583    A = G2lat.cell2A(cell[:6])
     
    15901600            ph = ref[10]
    15911601            ph = rn.uniform(0.,360.)
    1592             for i,hkl in enumerate(reflDict['Uniq'][iref]):        #uses uniq
     1602            Uniq = np.inner(ref[:3],SGMT)
     1603            Phi = np.inner(ref[:3],SGT)
     1604            for i,hkl in enumerate(Uniq):        #uses uniq
    15931605                hkl = np.asarray(hkl,dtype='i')
    1594                 dp = 360.*reflDict['Phi'][iref][i]                #and phi
     1606                dp = 360.*Phi[i]                #and phi
    15951607                a = cosd(ph+dp)
    15961608                b = sind(ph+dp)
     
    17971809        xyz = np.array(mapPeaks[ind][1:4])
    17981810        xyzs = np.array([equiv[0] for equiv in G2spc.GenAtom(xyz,SGData,Move=True)])
    1799 #        for x in xyzs: print x
    18001811        for jnd,xyz in enumerate(XYZ):       
    18011812            Indx[jnd] = Duplicate(xyz,xyzs,Amat)
  • trunk/GSASIIphsGUI.py

    r1107 r1110  
    31173117            ref[4] = np.sqrt(1./G2lat.calc_rDsq2(H,G))
    31183118            iabsnt,ref[3],Uniq,phi = G2spc.GenHKLf(H,SGData)
    3119             reflData['Uniq'][iref] = Uniq
    3120             reflData['Phi'][iref] = phi
    31213119        G2frame.PatternTree.SetItemPyData(Id,[refDict,reflData])
    31223120       
     
    48924890            reflData = reflSets[phaseName]
    48934891            if isinstance(reflData,list):       #patch for old reflection data
    4894                 RefData = {'RefList':[],'Uniq':[],'Phi':[],'FF':[]}
     4892                RefData = {'RefList':[],'FF':[]}
    48954893                for ref in reflData:
    48964894                    RefData['RefList'].append(ref[:11]+[ref[13],])
    4897                     RefData['Uniq'].append(ref[11])
    4898                     RefData['Phi'].append(ref[12])
    48994895                    RefData['FF'].append(ref[14])
    49004896                RefData['RefList'] = np.array(RefData['RefList'])
     
    49864982            reflDict = reflSets[phaseName]
    49874983            if isinstance(reflDict,list):       #patch for old reflection data
    4988                 RefData = {'RefList':[],'Uniq':[],'Phi':[],'FF':[]}
     4984                RefData = {'RefList':[],'FF':[]}
    49894985                for ref in reflDict:
    49904986                    RefData['RefList'].append(ref[:11]+[ref[13],])
    4991                     RefData['Uniq'].append(ref[11])
    4992                     RefData['Phi'].append(ref[12])
    49934987                    RefData['FF'].append(ref[14])
    49944988                RefData['RefList'] = np.array(RefData['RefList'])
  • trunk/GSASIIstrIO.py

    r1107 r1110  
    297297#patch
    298298                if isinstance(datum[1][1],list):
    299                     RefData = {'RefList':[],'Uniq':[],'Phi':[],'FF':[]}
     299                    RefData = {'RefList':[],'FF':[]}
    300300                    for ref in datum[1][1]:
    301301                        RefData['RefList'].append(ref[:11]+[ref[13],])
    302                         RefData['Uniq'].append(ref[11])
    303                         RefData['Phi'].append(ref[12])
    304302                        RefData['FF'].append(ref[14])
    305303                    RefData['RefList'] = np.array(RefData['RefList'])
     
    17731771                        else:
    17741772                            raise ValueError
    1775                     Histogram['Reflection Lists'][phase] = {'RefList':np.array(refList),
    1776                         'Uniq':Uniq,'Phi':Phi,'FF':FF}
     1773                    Histogram['Reflection Lists'][phase] = {'RefList':np.array(refList),'FF':FF}
    17771774            elif 'HKLF' in histogram:
    17781775                inst = Histogram['Instrument Parameters'][0]
  • trunk/GSASIIstrMath.py

    r1107 r1110  
    535535    :param dict refDict: where
    536536        'RefList' list where each ref = h,k,l,m,d,...
    537         'Uniq' list of [equiv h,k,l]
    538         'Phi' list of phase[equiv]
    539537        'FF' dict of form factors - filed in below
    540538    :param np.array G:      reciprocal metric tensor
     
    550548    ast = np.sqrt(np.diag(G))
    551549    Mast = twopisq*np.multiply.outer(ast,ast)
     550    SGMT = np.array([ops[0].T for ops in SGData['SGOps']])
     551    SGT = np.array([ops[1] for ops in SGData['SGOps']])
    552552    FFtables = calcControls['FFtables']
    553553    BLtables = calcControls['BLtables']
     
    574574        for i,El in enumerate(Tdata):
    575575            FF[i] = refDict['FF'][iref][El]           
    576         phase = twopi*(np.inner(refDict['Uniq'][iref],(dXdata.T+Xdata.T))+refDict['Phi'][iref][:,np.newaxis])
     576        Uniq = np.inner(H,SGMT)
     577        Phi = np.inner(H,SGT)
     578        phase = twopi*(np.inner(Uniq,(dXdata.T+Xdata.T))+Phi[:,np.newaxis])
    577579        sinp = np.sin(phase)
    578580        cosp = np.cos(phase)
    579         occ = Mdata*Fdata/len(refDict['Uniq'][iref])
     581        occ = Mdata*Fdata/len(Uniq)
    580582        biso = -SQfactor*Uisodata
    581583        Tiso = np.where(biso<1.,np.exp(biso),1.0)
    582         HbH = np.array([-np.inner(h,np.inner(bij,h)) for h in refDict['Uniq'][iref]])
     584        HbH = np.array([-np.inner(h,np.inner(bij,h)) for h in Uniq])
    583585        Tuij = np.where(HbH<1.,np.exp(HbH),1.0)
    584586        Tcorr = Tiso*Tuij
     
    593595        refl[10] = atan2d(fbs[0],fas[0])
    594596   
    595 def StructureFactor2(refDict,G,hfx,pfx,SGData,calcControls,parmDict):
    596     ''' Compute structure factors for all h,k,l for phase
    597     puts the result, F^2, in each ref[8] in refList
    598     input:
    599    
    600     :param dict refDict: where
    601         'RefList' list where each ref = h,k,l,m,d,...
    602         'Uniq' list of [equiv h,k,l]
    603         'Phi' list of phase[equiv]
    604         'FF' dict of form factors - filed in below
    605     :param np.array G:      reciprocal metric tensor
    606     :param str pfx:    phase id string
    607     :param dict SGData: space group info. dictionary output from SpcGroup
    608     :param dict calcControls:
    609     :param dict ParmDict:
    610 
    611     '''       
     597def StructureFactorDerv(refDict,G,hfx,pfx,SGData,calcControls,parmDict):
     598    'Needs a doc string'
    612599    twopi = 2.0*np.pi
    613600    twopisq = 2.0*np.pi**2
     
    615602    ast = np.sqrt(np.diag(G))
    616603    Mast = twopisq*np.multiply.outer(ast,ast)
    617     FFtables = calcControls['FFtables']
    618     BLtables = calcControls['BLtables']
    619     Tdata,Mdata,Fdata,Xdata,dXdata,IAdata,Uisodata,Uijdata = GetAtomFXU(pfx,calcControls,parmDict)
    620     FF = np.zeros(len(Tdata))
    621     if 'N' in calcControls[hfx+'histType']:
    622         FP,FPP = G2el.BlenRes(Tdata,BLtables,parmDict[hfx+'Lam'])
    623     else:
    624         FP = np.array([FFtables[El][hfx+'FP'] for El in Tdata])
    625         FPP = np.array([FFtables[El][hfx+'FPP'] for El in Tdata])
    626     Uij = np.array(G2lat.U6toUij(Uijdata))
    627     bij = Mast*Uij.T
    628     for iref,refl in enumerate(refDict['RefList']):
    629         fbs = np.array([0,0])
    630         H = refl[:3]
    631         SQ = 1./(2.*refl[4])**2
    632         SQfactor = 4.0*SQ*twopisq
    633         Bab = parmDict[phfx+'BabA']*np.exp(-parmDict[phfx+'BabU']*SQfactor)
    634         if not len(refDict['FF'][iref]):                #no form factors
    635             if 'N' in calcControls[hfx+'histType']:
    636                 refDict['FF'][iref] = G2el.getBLvalues(BLtables)
    637             else:       #'X'
    638                 refDict['FF'][iref] = G2el.getFFvalues(FFtables,SQ)
    639         for i,El in enumerate(Tdata):
    640             FF[i] = refDict['FF'][iref][El]           
    641         phase = twopi*(np.inner(refDict['Uniq'][iref],(dXdata.T+Xdata.T))+refDict['Phi'][iref][:,np.newaxis])
    642         sinp = np.sin(phase)
    643         cosp = np.cos(phase)
    644         occ = Mdata*Fdata/len(refDict['Uniq'][iref])
    645         biso = -SQfactor*Uisodata
    646         Tiso = np.where(biso<1.,np.exp(biso),1.0)
    647         HbH = np.array([-np.inner(h,np.inner(bij,h)) for h in refDict['Uniq'][iref]])
    648         Tuij = np.where(HbH<1.,np.exp(HbH),1.0)
    649         Tcorr = Tiso*Tuij
    650         fa = np.array([(FF+FP-Bab)*occ*cosp*Tcorr,-FPP*occ*sinp*Tcorr])
    651         fas = np.sum(np.sum(fa,axis=1),axis=1)        #real
    652         if not SGData['SGInv']:
    653             fb = np.array([(FF+FP-Bab)*occ*sinp*Tcorr,FPP*occ*cosp*Tcorr])
    654             fbs = np.sum(np.sum(fb,axis=1),axis=1)
    655         fasq = fas**2
    656         fbsq = fbs**2        #imaginary
    657         refl[9] = np.sum(fasq)+np.sum(fbsq)
    658         refl[10] = atan2d(fbs[0],fas[0])
    659    
    660 def StructureFactorDerv(refDict,G,hfx,pfx,SGData,calcControls,parmDict):
    661     'Needs a doc string'
    662     twopi = 2.0*np.pi
    663     twopisq = 2.0*np.pi**2
    664     phfx = pfx.split(':')[0]+hfx
    665     ast = np.sqrt(np.diag(G))
    666     Mast = twopisq*np.multiply.outer(ast,ast)
     604    SGMT = np.array([ops[0].T for ops in SGData['SGOps']])
     605    SGT = np.array([ops[1] for ops in SGData['SGOps']])
    667606    FFtables = calcControls['FFtables']
    668607    BLtables = calcControls['BLtables']
     
    691630        for i,El in enumerate(Tdata):           
    692631            FF[i] = refDict['FF'][iref][El]           
    693         phase = twopi*(np.inner((dXdata.T+Xdata.T),refDict['Uniq'][iref])+refDict['Phi'][iref][np.newaxis,:])
     632        Uniq = np.inner(H,SGMT)
     633        Phi = np.inner(H,SGT)
     634        phase = twopi*(np.inner((dXdata.T+Xdata.T),Uniq)+Phi[np.newaxis,:])
    694635        sinp = np.sin(phase)
    695636        cosp = np.cos(phase)
    696         occ = Mdata*Fdata/len(refDict['Uniq'][iref])
     637        occ = Mdata*Fdata/len(Uniq)
    697638        biso = -SQfactor*Uisodata
    698639        Tiso = np.where(biso<1.,np.exp(biso),1.0)
    699640        HbH = -np.inner(H,np.inner(bij,H))
    700         Hij = np.array([Mast*np.multiply.outer(U,U) for U in refDict['Uniq'][iref]])
     641        Hij = np.array([Mast*np.multiply.outer(U,U) for U in Uniq])
    701642        Hij = np.array([G2lat.UijtoU6(Uij) for Uij in Hij])
    702643        Tuij = np.where(HbH<1.,np.exp(HbH),1.0)
     
    713654        #sum below is over Uniq
    714655        dfadfr = np.sum(fa/occ[:,np.newaxis],axis=2)
    715         dfadx = np.sum(twopi*refDict['Uniq'][iref]*fax[:,:,:,np.newaxis],axis=2)
     656        dfadx = np.sum(twopi*Uniq*fax[:,:,:,np.newaxis],axis=2)
    716657        dfadui = np.sum(-SQfactor*fa,axis=2)
    717658        dfadua = np.sum(-Hij*fa[:,:,:,np.newaxis],axis=2)
    718659        dfadba = np.sum(-cosp*(occ*Tcorr)[:,np.newaxis],axis=1)
    719660        #NB: the above have been checked against PA(1:10,1:2) in strfctr.for     
    720         dFdfr[iref] = 2.*(fas[0]*dfadfr[0]+fas[1]*dfadfr[1])*Mdata/len(refDict['Uniq'][iref])
     661        dFdfr[iref] = 2.*(fas[0]*dfadfr[0]+fas[1]*dfadfr[1])*Mdata/len(Uniq)
    721662        dFdx[iref] = 2.*(fas[0]*dfadx[0]+fas[1]*dfadx[1])
    722663        dFdui[iref] = 2.*(fas[0]*dfadui[0]+fas[1]*dfadui[1])
     
    725666        if not SGData['SGInv']:
    726667            dfbdfr = np.sum(fb/occ[:,np.newaxis],axis=2)        #problem here if occ=0 for some atom
    727             dfbdx = np.sum(twopi*refDict['Uniq'][iref]*fbx[:,:,:,np.newaxis],axis=2)         
     668            dfbdx = np.sum(twopi*Uniq*fbx[:,:,:,np.newaxis],axis=2)         
    728669            dfbdui = np.sum(-SQfactor*fb,axis=2)
    729670            dfbdua = np.sum(-Hij*fb[:,:,:,np.newaxis],axis=2)
    730671            dfbdba = np.sum(-sinp*(occ*Tcorr)[:,np.newaxis],axis=1)
    731             dFdfr[iref] += 2.*(fbs[0]*dfbdfr[0]-fbs[1]*dfbdfr[1])*Mdata/len(refDict['Uniq'][iref])
     672            dFdfr[iref] += 2.*(fbs[0]*dfbdfr[0]-fbs[1]*dfbdfr[1])*Mdata/len(Uniq)
    732673            dFdx[iref] += 2.*(fbs[0]*dfbdx[0]+fbs[1]*dfbdx[1])
    733674            dFdui[iref] += 2.*(fbs[0]*dfbdui[0]-fbs[1]*dfbdui[1])
     
    13611302        hfx = ':%d:'%(hId)
    13621303        SGData = Phase['General']['SGData']
     1304        SGMT = np.array([ops[0].T for ops in SGData['SGOps']])
    13631305        A = [parmDict[pfx+'A%d'%(i)] for i in range(6)]
    13641306        G,g = G2lat.A2Gmat(A)       #recip & real metric tensors
     
    13701312            print 'sf calc time: %.3fs'%(time.time()-time0)
    13711313        time0 = time.time()
    1372         Uniq = refDict['Uniq']
    13731314        for iref,refl in enumerate(refDict['RefList']):
    13741315            if 'C' in calcControls[hfx+'histType']:
    13751316                h,k,l = refl[:3]
     1317                Uniq = np.inner(refl[:3],SGMT)
    13761318                refl[5] = GetReflPos(refl,wave,G,hfx,calcControls,parmDict)         #corrected reflection position
    13771319                Lorenz = 1./(2.*sind(refl[5]/2.)**2*cosd(refl[5]/2.))           #Lorentz correction
    13781320                refl[5] += GetHStrainShift(refl,SGData,phfx,parmDict)               #apply hydrostatic strain shift
    13791321                refl[6:8] = GetReflSigGam(refl,wave,G,GB,hfx,phfx,calcControls,parmDict)    #peak sig & gam
    1380                 GetIntensityCorr(refl,Uniq[iref],G,g,pfx,phfx,hfx,SGData,calcControls,parmDict)    #puts corrections in refl[11]
     1322                GetIntensityCorr(refl,Uniq,G,g,pfx,phfx,hfx,SGData,calcControls,parmDict)    #puts corrections in refl[11]
    13811323                refl[11] *= Vst*Lorenz
    13821324                if Phase['General'].get('doPawley'):
     
    14841426        Phase = Phases[phase]
    14851427        SGData = Phase['General']['SGData']
     1428        SGMT = np.array([ops[0].T for ops in SGData['SGOps']])
    14861429        pId = Phase['pId']
    14871430        pfx = '%d::'%(pId)
     
    14961439            ApplyRBModelDervs(dFdvDict,parmDict,rigidbodyDict,Phase)
    14971440        time0 = time.time()
    1498         Uniq = refDict['Uniq']
    14991441        for iref,refl in enumerate(refDict['RefList']):
    15001442            if 'C' in calcControls[hfx+'histType']:        #CW powder
    15011443                h,k,l = refl[:3]
    1502                 dIdsh,dIdsp,dIdpola,dIdPO,dFdODF,dFdSA,dFdAb = GetIntensityDerv(refl,Uniq[iref],G,g,pfx,phfx,hfx,SGData,calcControls,parmDict)
     1444                Uniq = np.inner(refl[:3],SGMT)
     1445                dIdsh,dIdsp,dIdpola,dIdPO,dFdODF,dFdSA,dFdAb = GetIntensityDerv(refl,Uniq,G,g,pfx,phfx,hfx,SGData,calcControls,parmDict)
    15031446                Wd,fmin,fmax = G2pwd.getWidthsCW(refl[5],refl[6],refl[7],shl)
    15041447                iBeg = np.searchsorted(x,refl[5]-fmin)
  • trunk/imports/G2sfact.py

    r1107 r1110  
    5252                # h,k,l,m,dsp,Fo2,sig,Fc2,Fot2,Fct2,phase,...
    5353                self.RefDict['RefList'].append([h,k,l,0,0,Fo**2,2.*Fo*sigFo,0,Fo**2,0,0,0])
    54                 self.RefDict['Uniq'].append([])
    55                 self.RefDict['Phi'].append([])
    5654                self.RefDict['FF'].append({})
    5755            self.RefDict['RefList'] = np.array(self.RefDict['RefList'])
     
    102100                # h,k,l,m,dsp,Fo2,sig,Fc2,Fot2,Fct2,phase,...
    103101                self.RefDict['RefList'].append([h,k,l,0,0,Fo,sigFo,0,Fo,0,0,0])
    104                 self.RefDict['Uniq'].append([])
    105                 self.RefDict['Phi'].append([])
    106102                self.RefDict['FF'].append({})
    107103            self.RefDict['RefList'] = np.array(self.RefDict['RefList'])
  • trunk/imports/G2sfact_CIF.py

    r1107 r1110  
    213213                        pass                               
    214214                self.RefDict['RefList'].append(ref)
    215                 self.RefDict['Uniq'].append([])
    216                 self.RefDict['Phi'].append([])
    217215                self.RefDict['FF'].append({})
    218216            self.RefDict['RefList'] = np.array(self.RefDict['RefList'])
Note: See TracChangeset for help on using the changeset viewer.