Ignore:
Timestamp:
Oct 26, 2016 12:24:19 PM (6 years ago)
Author:
vondreele
Message:

some work on automatic mag constraints
move a dlg.Destroy() in OnSeqPeakFit? & OnIndexPeaks? - get rid of orphan wait cursor & progress dialog
more work on mag moment derivs - still wrong! Other derivs now all OK

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/GSASIIstrMath.py

    r2501 r2506  
    753753            FP = np.repeat(FP.T,len(SGT)*len(TwinLaw),axis=0)
    754754            FPP = np.repeat(FPP.T,len(SGT)*len(TwinLaw),axis=0)
    755         Tindx = np.array([refDict['FF']['El'].index(El) for El in Tdata])
    756755        Uniq = np.inner(H,SGMT)
    757756        Phi = np.inner(H,SGT)
     
    764763        Tuij = np.where(HbH<1.,np.exp(HbH),1.0).T
    765764        Tcorr = np.reshape(Tiso,Tuij.shape)*Tuij*Mdata*Fdata/len(SGMT)
     765        Tindx = np.array([refDict['FF']['El'].index(El) for El in Tdata])
    766766        FF = np.repeat(refDict['FF']['FF'][iBeg:iFin].T[Tindx].T,len(SGT)*len(TwinLaw),axis=0)
    767767        if 'N' in calcControls[hfx+'histType'] and parmDict[pfx+'isMag']:
     
    12221222    Mag = np.sqrt(np.sum(Gdata**2,axis=0))      #magnitude of moments for uniq atoms
    12231223    Gdata = np.where(Mag>0.,Gdata/Mag,0.)       #normalze mag. moments
     1224    dGdM = np.copy(Gdata)
    12241225    Gdata = np.inner(Bmat,Gdata.T)              #convert to crystal space
    12251226    Gdata = np.inner(Gdata.T,SGMT).T            #apply sym. ops.
     
    12291230    Gdata = SGData['MagMom'][nxs,:,nxs]*Gdata   #flip vectors according to spin flip
    12301231    Gdata = np.inner(Amat,Gdata.T)              #convert back to cart. space MXYZ, Natoms, NOps*Inv*Ncen
    1231     Gdata = np.swapaxes(Gdata,1,2)              # put Natoms last
     1232    Gdata = np.swapaxes(Gdata,1,2)              # put Natoms last - Mxyz,Nops,Natms
    12321233#    GSASIIpath.IPyBreak()
    1233     Mag = np.tile(Mag[:,nxs],len(SGMT)*Ncen).T  #Mag same length as Gdata
     1234    Mag = np.tile(Mag[:,nxs],len(SGMT)*Ncen).T  #make Mag same length as Gdata
    12341235    if SGData['SGInv']:
    12351236        Mag = np.repeat(Mag,2,axis=0)
     1237    dGdm = (1.-Gdata**2)    #1/Mag removed - canceled out in dqmx=sum(dqdm*dGdm)
    12361238    dFdMx = np.zeros((nRef,mSize,3))
    12371239    Uij = np.array(G2lat.U6toUij(Uijdata))
     
    12821284        cosm = np.cos(mphase)                               #ditto
    12831285        HM = np.inner(Bmat.T,H)                             #put into cartesian space
    1284         HM = HM/np.sqrt(np.sum(HM**2,axis=0))               #Gdata = MAGS & HM = UVEC in magstrfc.for both OK
     1286        HM = HM/np.sqrt(np.sum(HM**2,axis=0))               
    12851287        eDotK = np.sum(HM[:,:,nxs,nxs]*Gdata[:,nxs,:,:],axis=0)
    12861288        Q = HM[:,:,nxs,nxs]*eDotK[nxs,:,:,:]-Gdata[:,nxs,:,:] #Mxyz,Nref,Nop,Natm = BPM in magstrfc.for OK
    1287         dqdm = np.array([np.outer(hm,hm)-np.eye(3) for hm in HM.T]).T   #Mxyz,Mxyz,Nref
     1289        dqdm = np.array([np.outer(hm,hm)-np.eye(3) for hm in HM.T]).T   #Mxyz,Mxyz,Nref (3x3 matrix)
     1290        dqmx = np.sum(dqdm[:,:,:,nxs,nxs]*dGdm[:,nxs,nxs,:,:],axis=0)   #matrix * vector = vector
     1291        dmx = Q*Gdata[:,nxs,:,:]+dqmx      #*Mag canceled out of dqmx term
    12881292        fam = Q*TMcorr[nxs,:,nxs,:]*cosm[nxs,:,:,:]*Mag[nxs,nxs,:,:]    #ditto
    12891293        fbm = Q*TMcorr[nxs,:,nxs,:]*sinm[nxs,:,:,:]*Mag[nxs,nxs,:,:]    #ditto
     
    12921296        famx = Q*TMcorr[nxs,:,nxs,:]*Mag[nxs,nxs,:,:]*sinm[nxs,:,:,:]   #Mxyz,Nref,Nops,Natom
    12931297        fbmx = Q*TMcorr[nxs,:,nxs,:]*Mag[nxs,nxs,:,:]*cosm[nxs,:,:,:]
    1294         #sum below is over Uniq
     1298        #sums below are over Nops - real part
    12951299        dfadfr = np.sum(fam/occ,axis=2)        #array(Mxyz,refBlk,nAtom) Fdata != 0 avoids /0. problem deriv OK
    1296         dfadx = np.sum(twopi*Uniq[nxs,:,:,nxs,:]*famx[:,:,:,:,nxs],axis=2)          #deriv OK
    1297         dmx = dqdm[:,:,:,nxs,nxs]*Mag[nxs,nxs,nxs,:,:]+Q[nxs,:,:,:,:]*Gdata[:,nxs,nxs,:,:]
    1298         dfadmx = np.sum(TMcorr[nxs,nxs,:,nxs,:]*cosm[nxs,nxs,:,:,:]*dmx,axis=-2)
    1299         dfadmx = np.reshape(dfadmx,(3,iFin-iBeg,-1,3))
     1300        dfadx = np.sum(-twopi*Uniq[nxs,:,:,nxs,:]*famx[:,:,:,:,nxs],axis=2)          #deriv OK
     1301        dfadmx = np.sum(TMcorr[nxs,:,nxs,:]*cosm[nxs,:,:,:]*dmx,axis=2)
    13001302        dfadui = np.sum(-SQfactor[:,nxs,nxs]*fam,axis=2) #array(Ops,refBlk,nAtoms)  OK
    13011303        dfadua = np.sum(-Hij[nxs,:,:,nxs,:]*fam[:,:,:,:,nxs],axis=2)    #OK? not U12 & U23 in sarc
    1302         # array(3,refBlk,nAtom,3) & array(3,refBlk,nAtom,6)
     1304        # imaginary part; array(3,refBlk,nAtom,3) & array(3,refBlk,nAtom,6)
    13031305        dfbdfr = np.sum(fbm/occ,axis=2)        #array(mxyz,refBlk,nAtom) Fdata != 0 avoids /0. problem
    1304         dfbdx = np.sum(twopi*Uniq[nxs,:,:,nxs,:]*fbmx[:,:,:,:,nxs],axis=2)
    1305         dfbdmx = np.sum(TMcorr[nxs,nxs,:,nxs,:]*sinm[nxs,nxs,:,:,:]*dmx,axis=-2)
    1306         dfbdmx = np.reshape(dfbdmx,(3,iFin-iBeg,-1,3))
     1306        dfbdx = np.sum(-twopi*Uniq[nxs,:,:,nxs,:]*fbmx[:,:,:,:,nxs],axis=2)
     1307        dfbdmx = np.sum(TMcorr[nxs,:,nxs,:]*sinm[nxs,:,:,:]*dmx,axis=2)
    13071308        dfbdui = np.sum(-SQfactor[:,nxs,nxs]*fbm,axis=2) #array(Ops,refBlk,nAtoms)
    13081309        dfbdua = np.sum(-Hij[nxs,:,:,nxs,:]*fbm[:,:,:,:,nxs],axis=2)
     1310        #accumulate derivatives   
    13091311        dFdfr[iBeg:iFin] = 2.*np.sum((fams[:,:,nxs]*dfadfr+fbms[:,:,nxs]*dfbdfr)*Mdata/(2*Nops*Ncen),axis=0)
    13101312        dFdx[iBeg:iFin] =  2.*np.sum(fams[:,:,nxs,nxs]*dfadx+fbms[:,:,nxs,nxs]*dfbdx,axis=0)
    1311         dFdMx[iBeg:iFin] = 2.*np.sum(fams[:,:,nxs,nxs]*dfadmx+fbms[:,:,nxs,nxs]*dfbdmx,axis=0)
     1313#        GSASIIpath.IPyBreak()
     1314        dFdMx[iBeg:iFin] = np.reshape(2.*fams[:,:,nxs]*dfadmx+fbms[:,:,nxs]*dfbdmx,(iFin-iBeg,-1,3))
    13121315        dFdui[iBeg:iFin] = 2.*np.sum(fams[:,:,nxs]*dfadui+fbms[:,:,nxs]*dfbdui,axis=0)
    13131316        dFdua[iBeg:iFin] = 2.*np.sum(fams[:,:,nxs,nxs]*dfadua+fbms[:,:,nxs,nxs]*dfbdua,axis=0)
     
    37903793                    if Ka2 and iFin2-iBeg2:
    37913794                        dMdv[varylist.index(name)][iBeg2:iFin2] += dpdA*dervDict2['pos']
    3792                 elif name in dependentVars:
     3795                elif name in dependentVars: #need to scale for mixed phase constraints?
    37933796                    depDerivDict[name][iBeg:iFin] += dpdA*dervDict['pos']
    37943797                    if Ka2 and iFin2-iBeg2:
     
    38463849                            depDerivDict[phfx+name][iBeg2:iFin2] += parmDict[phfx+'Scale']*dFdvDict[phfx+name][iref]*dervDict2['int']/refl[9+im]                 
    38473850            if not Phase['General'].get('doPawley'):
    3848                 #do atom derivatives -  for RB,F,X & U so far
     3851                #do atom derivatives -  for RB,F,X & U so far - how do I scale mixed phase constraints?
    38493852                corr = 0.
    38503853                corr2 = 0.
Note: See TracChangeset for help on using the changeset viewer.