Changeset 3340


Ignore:
Timestamp:
Apr 11, 2018 1:32:49 PM (4 years ago)
Author:
vondreele
Message:

make testDeriv py3 compatible
fix problem with Reload draw atoms - mag moments
add |Mag| to lst output of magnetic moments
correct errors in mag moment structure factor & derivatives

Location:
trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/GSASIIdataGUI.py

    r3333 r3340  
    43064306            return
    43074307        dlg = wx.ProgressDialog('Residual','All data Rw =',101.0,
    4308             style = wx.PD_ELAPSED_TIME|wx.PD_AUTO_HIDE|wx.PD_CAN_ABORT|wx.STAY_ON_TOP,
    4309             parent=self)
     4308            style = wx.PD_ELAPSED_TIME|wx.PD_AUTO_HIDE|wx.PD_CAN_ABORT|wx.STAY_ON_TOP,parent=self)
    43104309        Size = dlg.GetSize()
    43114310        if 50 < Size[0] < 500: # sanity check on size, since this fails w/Win & wx3.0
  • trunk/GSASIIspc.py

    r3338 r3340  
    31863186        newMom = -(np.inner(Mom,M).T)*nl.det(M)
    31873187    else:
    3188         newMom = -(np.inner(Mom,M).T)*SGData['SpnFlp'][nA-1]*nl.det(M)
     3188        newMom = -(np.inner(Mom,M).T)*SGData['MagMom'][nA-1]*nl.det(M)
    31893189    return newMom
    31903190       
  • trunk/GSASIIstrIO.py

    r3311 r3340  
    16561656           
    16571657    def PrintMomentsAndSig(General,Atoms,atomsSig):
     1658        cell = General['Cell'][1:7]
     1659        G = G2lat.fillgmat(cell)
     1660        ast = np.sqrt(np.diag(G))
     1661        GS = G/np.outer(ast,ast)
    16581662        pFile.write('\n Magnetic Moments:\n')    #add magnitude & angle, etc.? TBD
    1659         line = '   name      Mx        My        Mz'
     1663        line = '   name       Mx        My        Mz       |Mag|'
    16601664        cx,ct,cs,cia = General['AtomPtrs']
    16611665        cmx = cx+4
     
    16631667        pFile.write(line+'\n')
    16641668        pFile.write(135*'-'+'\n')
    1665         fmt = {0:'%7s',ct:'%7s',cmx:'%10.5f',cmx+1:'%10.5f',cmx+2:'%10.5f'}
     1669        fmt = {0:'%7s',ct:'%7s',cmx:'%10.3f',cmx+1:'%10.3f',cmx+2:'%10.3f'}
    16661670        noFXsig = {cmx:[10*' ','%10s'],cmx+1:[10*' ','%10s'],cmx+2:[10*' ','%10s']}
    16671671        for i,at in enumerate(Atoms):
     
    16771681                    else:
    16781682                        sigstr += noFXsig[ind][1]%(noFXsig[ind][0])
     1683                mag = np.array(at[cmx:cmx+3])
     1684                Mag = np.sqrt(np.inner(mag,np.inner(mag,GS)))
     1685                valstr += '%10.3f'%Mag
     1686                sigstr += 10*' '
    16791687                pFile.write(name+'\n')
    16801688                pFile.write(valstr+'\n')
  • trunk/GSASIIstrMath.py

    r3339 r3340  
    786786
    787787    '''       
    788 #    phfx = pfx.split(':')[0]+hfx
    789788    ast = np.sqrt(np.diag(G))
    790789    GS = G/np.outer(ast,ast)
     790    uAmat = G2lat.Gmat2AB(GS)[0]
    791791    Mast = twopisq*np.multiply.outer(ast,ast)
    792792    SGMT = np.array([ops[0].T for ops in SGData['SGOps']])
     
    797797        Nops *= (1+SGData['SGInv'])
    798798    MFtables = calcControls['MFtables']
    799     Amat,Bmat = G2lat.Gmat2AB(G)
     799    Bmat = G2lat.Gmat2AB(G)[1]
    800800    TwinLaw = np.ones(1)
    801801#    TwinLaw = np.array([[[1,0,0],[0,1,0],[0,0,1]],])
     
    812812        return
    813813    Mag = np.sqrt(np.array([np.inner(mag,np.inner(mag,GS)) for mag in Gdata.T]))
    814     Gdata = np.where(Mag>0.,Gdata/Mag,0.)       #normalze mag. moments
    815814    Gdata = np.inner(Gdata.T,SGMT).T            #apply sym. ops.
    816815    if SGData['SGInv'] and not SGData['SGFixed']:
    817816        Gdata = np.hstack((Gdata,-Gdata))       #inversion if any
    818     Gdata = np.hstack([Gdata for icen in range(Ncen)])        #dup over cell centering
     817    Gdata = np.hstack([Gdata for icen in range(Ncen)])        #dup over cell centering--> [Mxyz,nops,natms]
    819818    Gdata = SGData['MagMom'][nxs,:,nxs]*Gdata   #flip vectors according to spin flip * det(opM)
    820     Mag = np.tile(Mag[:,nxs],len(SGMT)*Ncen).T.reshape((len(SGMT),-1))
    821     if SGData['SGInv'] and not SGData['SGFixed']:
    822         Mag = np.repeat(Mag,2,axis=0)                  #Mag same shape as Gdata
     819    Mag = np.tile(Mag[:,nxs],Nops).T  #make Mag same length as Gdata
     820    Gdata = Gdata/Mag       #normalze mag. moments
     821    Gdata = np.inner(Gdata.T,uAmat).T*np.sqrt(nl.det(GS))
    823822    Uij = np.array(G2lat.U6toUij(Uijdata))
    824823    bij = Mast*Uij.T
     
    10571056   
    10581057def StructureFactorDervMag(refDict,G,hfx,pfx,SGData,calcControls,parmDict):
    1059     '''Compute structure factor derivatives on blocks of reflections - for powders/nontwins only
     1058    '''Compute magnetic structure factor derivatives on blocks of reflections - for powders/nontwins only
    10601059    input:
    10611060   
     
    10751074    ast = np.sqrt(np.diag(G))
    10761075    GS = G/np.outer(ast,ast)
     1076    uAmat = G2lat.Gmat2AB(GS)[0]
    10771077    Mast = twopisq*np.multiply.outer(ast,ast)
    10781078    SGMT = np.array([ops[0].T for ops in SGData['SGOps']])
    10791079    SGT = np.array([ops[1] for ops in SGData['SGOps']])
    10801080    Ncen = len(SGData['SGCen'])
    1081     if SGData['SGFixed']:
    1082         Nops = len(SGMT)*Ncen
    1083     else:
    1084         Nops = len(SGMT)*Ncen*(1+SGData['SGInv'])
    1085     Amat,Bmat = G2lat.Gmat2AB(G)
     1081    Nops = len(SGMT)*Ncen
     1082    if not SGData['SGFixed']:
     1083        Nops *= (1+SGData['SGInv'])
     1084    Bmat = G2lat.Gmat2AB(G)[1]
    10861085    nRef = len(refDict['RefList'])
    10871086    Tdata,Mdata,Fdata,Xdata,dXdata,IAdata,Uisodata,Uijdata,Gdata = \
     
    10981097    Gdata = SGData['MagMom'][nxs,:,nxs]*Gdata   #flip vectors according to spin flip
    10991098    Mag = np.tile(Mag[:,nxs],Nops).T  #make Mag same length as Gdata
     1099    Gdata = Gdata/Mag       #normalze mag. moments
     1100    Gdata = np.inner(Gdata.T,uAmat).T*np.sqrt(nl.det(GS))       #make unit vectors in Cartesian space
    11001101    dGdm = (1.-Gdata**2)                        #1/Mag removed - canceled out in dqmx=sum(dqdm*dGdm)
    11011102    dFdMx = np.zeros((nRef,mSize,3))
     
    11111112#reflection processing begins here - big arrays!
    11121113    iBeg = 0
    1113     blkSize = 32       #no. of reflections in a block - optimized for speed
     1114    blkSize = 40       #no. of reflections in a block - optimized for speed
    11141115    while iBeg < nRef:
    11151116        iFin = min(iBeg+blkSize,nRef)
     
    11311132        MF = refDict['FF']['MF'][iBeg:iFin].T[Tindx].T   #Nref,Natm
    11321133        TMcorr = 0.539*(np.reshape(Tiso,Tuij.shape)*Tuij)[:,0,:]*Fdata*Mdata*MF/(2*Nops)     #Nref,Natm
    1133         if SGData['SGInv'] and not SGData['SGFixed']:
    1134             mphase = np.hstack((phase,-phase))
    1135             Uniq = np.hstack((Uniq,-Uniq))      #Nref,Nops,hkl
    1136             Hij = np.hstack((Hij,Hij))
     1134        if SGData['SGInv']:
     1135            if not SGData['SGFixed']:
     1136                mphase = np.hstack((phase,-phase))  #OK
     1137                Uniq = np.hstack((Uniq,-Uniq))      #Nref,Nops,hkl
     1138                Hij = np.hstack((Hij,Hij))
     1139            else:
     1140                mphase = phase
    11371141        else:
    1138             mphase = phase
     1142            mphase = phase                    #
    11391143        Hij = np.concatenate(np.array([Hij for cen in SGData['SGCen']]),axis=1)
    11401144        Uniq = np.hstack([Uniq for cen in SGData['SGCen']])
     
    11531157        dqmx2 = np.sum(dqmx,axis=1)   #matrix * vector = vector
    11541158#        dqmx1 = np.swapaxes(np.swapaxes(np.inner(dqdm.T,dGdm.T),0,1),2,3)
    1155         dmx = NQ*Q*dGdM[:,nxs,:,:]-Q*dqmx2                                #*Mag canceled out of dqmx term
     1159        dmx = (NQ*Q*dGdM[:,nxs,:,:]-Q*dqmx2)/Mag                                #*Mag canceled out of dqmx term
    11561160       
    11571161        fam = Q*TMcorr[nxs,:,nxs,:]*cosm[nxs,:,:,:]*Mag[nxs,nxs,:,:]    #Mxyz,Nref,Nop,Natm
  • trunk/testDeriv.py

    r3232 r3340  
    2222
    2323import sys
    24 import cPickle
    25 import cProfile,pstats,StringIO
     24import platform
     25if '2' in platform.python_version_tuple()[0]:
     26    import cPickle
     27    import StringIO
     28else:
     29    import _pickle as cPickle
     30    import io as StringIO
     31import cProfile,pstats
    2632import wx
    2733import numpy as np
     
    5359        self.testDerivMenu = wx.MenuBar()
    5460        self.File = wx.Menu(title='')
    55         self.File.Append(help='Open testDeriv.dat', id=wxID_FILEOPEN,
    56              kind=wx.ITEM_NORMAL,text='Open testDeriv.dat file')
    57         self.File.Append(help='Make derivative plots',id=wxID_MAKEPLOTS,
    58             kind=wx.ITEM_NORMAL,text='Make plots')
    59         self.File.Append(help='Exit from testDeriv', id=wxID_FILEEXIT, kind=wx.ITEM_NORMAL,
    60             text='Exit')
     61        self.File.Append(wxID_FILEOPEN,'Open testDeriv.dat file','Open testDeriv.dat')
     62        self.File.Append(wxID_MAKEPLOTS,'Make plots','Make derivative plots')
     63        self.File.Append(wxID_FILEEXIT,'Exit','Exit from testDeriv')
    6164        self.Bind(wx.EVT_MENU, self.OnTestRead, id=wxID_FILEOPEN)
    6265        self.Bind(wx.EVT_MENU,self.OnMakePlots,id=wxID_MAKEPLOTS)
     
    9396                testFile = dlg.GetPath()
    9497                file = open(testFile,'rb')
    95                 self.values = cPickle.load(file)
    96                 self.HistoPhases = cPickle.load(file)
    97                 (self.constrDict,self.fixedList,self.depVarList) = cPickle.load(file)
    98                 self.parmDict = cPickle.load(file)
    99                 self.varylist = cPickle.load(file)
    100                 self.calcControls = cPickle.load(file)
    101                 self.pawleyLookup = cPickle.load(file)
     98                if '2' in platform.python_version_tuple()[0]:
     99                    self.values = cPickle.load(file)
     100                    self.HistoPhases = cPickle.load(file)
     101                    (self.constrDict,self.fixedList,self.depVarList) = cPickle.load(file)
     102                    self.parmDict = cPickle.load(file)
     103                    self.varylist = cPickle.load(file)
     104                    self.calcControls = cPickle.load(file)
     105                    self.pawleyLookup = cPickle.load(file)
     106                else:
     107                    self.values = cPickle.load(file,encoding='Latin-1')
     108                    self.HistoPhases = cPickle.load(file,encoding='Latin-1')
     109                    (self.constrDict,self.fixedList,self.depVarList) = cPickle.load(file,encoding='Latin-1')
     110                    self.parmDict = cPickle.load(file,encoding='Latin-1')
     111                    self.varylist = cPickle.load(file,encoding='Latin-1')
     112                    self.calcControls = cPickle.load(file,encoding='Latin-1')
     113                    self.pawleyLookup = cPickle.load(file,encoding='Latin-1')
    102114                self.use = [False for i in range(len(self.varylist+self.depVarList))]
    103115                self.delt = [max(abs(self.parmDict[name])*0.0001,1e-6) for name in self.varylist+self.depVarList]
Note: See TracChangeset for help on using the changeset viewer.