Changeset 3646


Ignore:
Timestamp:
Oct 4, 2018 4:55:17 PM (5 years ago)
Author:
vondreele
Message:

modify UseMagAtomDialog? to have ifOK option - only OK button G2phsGUI)
change Unit Cells List mag phase tables to respond to 1)space group - give operator table (no longer row number) & 2)Uniq - give unique mag atom positions (just OK button)
make TestMagAtoms? work over entire mag cell volume to get all unique mag atoms - Uniq in table now correct
G2lat - new routine ExpandCell? - fills mag unit cell (before transformation)

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/GSASIIlattice.py

    r3638 r3646  
    276276    Uij = np.inner(Trans,np.inner(U6toUij(U6),Trans).T)/nl.det(Trans)
    277277    return UijtoU6(Uij)
    278    
    279 def TransformPhase(oldPhase,newPhase,Trans,Uvec,Vvec,ifMag):
    280     '''Transform atoms from oldPhase to newPhase
    281     M' is inv(M)
    282     does X' = M(X-U)+V transformation for coordinates and U' = MUM/det(M)
    283     for anisotropic thermal parameters
    284    
    285     :param oldPhase: dict G2 phase info for old phase
    286     :param newPhase: dict G2 phase info for new phase; with new cell & space group
    287             atoms are from oldPhase & will be transformed
    288     :param Trans: lattice transformation matrix M
    289     :param Uvec: array parent coordinates transformation vector U
    290     :param Vvec: array child coordinate transformation vector V
    291     :param ifMag: bool True if convert to magnetic phase;
    292         if True all nonmagnetic atoms will be removed
    293        
    294     '''
    295    
    296     cx,ct,cs,cia = oldPhase['General']['AtomPtrs']
    297     cm = 0
    298     if oldPhase['General']['Type'] == 'magnetic':
    299         cm = cx+4
    300     oAmat,oBmat = cell2AB(oldPhase['General']['Cell'][1:7])
    301     nAmat,nBmat = cell2AB(newPhase['General']['Cell'][1:7])
    302     SGData = newPhase['General']['SGData']
    303     invTrans = nl.inv(Trans)
    304     newAtoms,atCodes = FillUnitCell(oldPhase)
    305     Unit =[abs(int(max(unit))-1) for unit in Trans.T]
     278
     279def ExpandCell(Atoms,atCodes,cx,Trans):
     280    Unit =[int(max(abs(np.array(unit)))-1) for unit in Trans.T]
    306281    for i,unit in enumerate(Unit):
    307282        if unit > 0:
    308283            for j in range(unit):
    309                 moreAtoms = copy.deepcopy(newAtoms)
     284                moreAtoms = copy.deepcopy(Atoms)
    310285                moreCodes = []
    311286                for atom,code in zip(moreAtoms,atCodes):
     
    319294                    cell[i] += 1
    320295                    moreCodes.append('%s+%d,%d,%d'%(ops,cell[0],cell[1],cell[2]))
    321                 newAtoms += moreAtoms
     296                Atoms += moreAtoms
    322297                atCodes += moreCodes
     298    return Atoms,atCodes
     299   
     300def TransformPhase(oldPhase,newPhase,Trans,Uvec,Vvec,ifMag):
     301    '''Transform atoms from oldPhase to newPhase
     302    M' is inv(M)
     303    does X' = M(X-U)+V transformation for coordinates and U' = MUM/det(M)
     304    for anisotropic thermal parameters
     305   
     306    :param oldPhase: dict G2 phase info for old phase
     307    :param newPhase: dict G2 phase info for new phase; with new cell & space group
     308            atoms are from oldPhase & will be transformed
     309    :param Trans: lattice transformation matrix M
     310    :param Uvec: array parent coordinates transformation vector U
     311    :param Vvec: array child coordinate transformation vector V
     312    :param ifMag: bool True if convert to magnetic phase;
     313        if True all nonmagnetic atoms will be removed
     314       
     315    '''
     316   
     317    cx,ct,cs,cia = oldPhase['General']['AtomPtrs']
     318    cm = 0
     319    if oldPhase['General']['Type'] == 'magnetic':
     320        cm = cx+4
     321    oAmat,oBmat = cell2AB(oldPhase['General']['Cell'][1:7])
     322    nAmat,nBmat = cell2AB(newPhase['General']['Cell'][1:7])
     323    SGData = newPhase['General']['SGData']
     324    invTrans = nl.inv(Trans)
     325    newAtoms,atCodes = FillUnitCell(oldPhase)
     326    newAtoms,atCodes = ExpandCell(newAtoms,atCodes,cx,Trans)
    323327    if ifMag:
    324328        cia += 3
  • trunk/GSASIIphsGUI.py

    r3638 r3646  
    590590    '''Get user selected magnetic atoms after cell transformation
    591591    '''
    592     def __init__(self,parent,Name,Atoms,atCodes,atMxyz,ifDelete=False):
     592    def __init__(self,parent,Name,Atoms,atCodes,atMxyz,ifOK=False,ifDelete=False):
    593593        wx.Dialog.__init__(self,parent,wx.ID_ANY,'Magnetic atom selection',
    594594            pos=wx.DefaultPosition,style=wx.DEFAULT_DIALOG_STYLE)
     
    598598        self.atCodes = atCodes
    599599        self.atMxyz = atMxyz
     600        self.ifOK = ifOK
    600601        self.ifDelete = ifDelete
    601602        self.Use = len(self.Atoms)*[True,]
     
    633634        mainSizer.Add(atmSizer)
    634635       
    635         YesBtn = wx.Button(self.panel,-1,"Yes")
    636         YesBtn.Bind(wx.EVT_BUTTON, self.OnYes)
    637         NoBtn = wx.Button(self.panel,-1,"No")
    638         NoBtn.Bind(wx.EVT_BUTTON, self.OnNo)
    639636        btnSizer = wx.BoxSizer(wx.HORIZONTAL)
    640         btnSizer.Add((20,20),1)
    641         btnSizer.Add(YesBtn)
    642         btnSizer.Add((20,20),1)
    643         btnSizer.Add(NoBtn)
    644         if self.ifDelete:
    645             DeleteBtn = wx.Button(self.panel,-1,"Delete")
    646             DeleteBtn.Bind(wx.EVT_BUTTON, self.OnDelete)
     637        if self.ifOK:
     638            OKBtn = wx.Button(self.panel,-1,"OK")
     639            OKBtn.Bind(wx.EVT_BUTTON, self.OnNo)
     640            btnSizer.Add(OKBtn)           
     641        else:
     642            YesBtn = wx.Button(self.panel,-1,"Yes")
     643            YesBtn.Bind(wx.EVT_BUTTON, self.OnYes)
     644            NoBtn = wx.Button(self.panel,-1,"No")
     645            NoBtn.Bind(wx.EVT_BUTTON, self.OnNo)
    647646            btnSizer.Add((20,20),1)
    648             btnSizer.Add(DeleteBtn)
    649         btnSizer.Add((20,20),1)
     647            btnSizer.Add(YesBtn)
     648            btnSizer.Add((20,20),1)
     649            btnSizer.Add(NoBtn)
     650            if self.ifDelete:
     651                DeleteBtn = wx.Button(self.panel,-1,"Delete")
     652                DeleteBtn.Bind(wx.EVT_BUTTON, self.OnDelete)
     653                btnSizer.Add((20,20),1)
     654                btnSizer.Add(DeleteBtn)
     655            btnSizer.Add((20,20),1)
    650656       
    651657        mainSizer.Add(btnSizer,0,wx.EXPAND|wx.BOTTOM|wx.TOP, 10)
  • trunk/GSASIIpwdGUI.py

    r3638 r3646  
    31613161            controls[15] = testAtoms
    31623162            G2frame.dataWindow.RunSubGroupsMag.Enable(True)
     3163        G2frame.GPXtree.SetItemPyData(UnitCellsId,data)
    31633164        G2frame.dataWindow.RefineCell.Enable(True)
    31643165        OnHklShow(None)
     
    33723373        r,c =  event.GetRow(),event.GetCol()
    33733374        if magcells:
    3374             if c == 1:
     3375            if c == 0:
     3376                r = event.GetRow()
     3377                phase = magcells[r]
     3378                mSGData = phase['SGData']
     3379                msg = 'Magnetic space group information for '+phase['Name']
     3380                text,table = G2spc.SGPrint(mSGData,AddInv=True)
     3381                text[0] = ' Magnetic Space Group: '+mSGData['MagSpGrp']
     3382                text[3] = ' The magnetic lattice point group is '+mSGData['MagPtGp']
     3383                OprNames,SpnFlp = G2spc.GenMagOps(mSGData)
     3384                G2G.SGMagSpinBox(G2frame.dataWindow,msg,text,table,mSGData['SGCen'],OprNames,
     3385                    mSGData['SpnFlp'],False).Show()
     3386            elif c == 1:
    33753387                for i in range(len(magcells)):
    33763388                    magcells[i]['Use'] = False
     
    33793391                magDisplay.ForceRefresh()
    33803392                magcells[r]['Use'] = True
    3381                 SGData = magcells[r]['SGData']
     3393                mSGData = magcells[r]['SGData']
    33823394                A = G2lat.cell2A(magcells[r]['Cell'][:6]) 
    3383                 G2frame.HKL = G2pwd.getHKLpeak(1.0,SGData,A,Inst)
     3395                G2frame.HKL = G2pwd.getHKLpeak(1.0,mSGData,A,Inst)
    33843396                G2plt.PlotPatterns(G2frame)
    33853397            elif c == 2:
     
    33913403                    MagCellsTable.SetValue(r,c,True)
    33923404                magDisplay.ForceRefresh()
     3405            elif c ==3:
     3406                r = event.GetRow()
     3407                allmom = magcells[0].get('allmom',False)
     3408                magAtms = magcells[0].get('magAtms','')
     3409                maxequiv = magcells[0].get('maxequiv',100)
     3410                phase = magcells[r]
     3411                mSGData = magcells[r]['SGData']
     3412                Uvec = phase['Uvec']
     3413                Trans = phase['Trans']
     3414                mAtoms = TestMagAtoms(phase,magAtms,SGData,Uvec,Trans,allmom,maxequiv)
     3415                Atms = []
     3416                AtCods = []
     3417                atMxyz = []
     3418                for ia,atom in enumerate(mAtoms):
     3419                    atom[0] += '_%d'%ia
     3420                    SytSym,Mul,Nop,dupDir = G2spc.SytSym(atom[2:5],mSGData)
     3421                    CSI = G2spc.GetCSpqinel(mSGData['SpnFlp'],dupDir)
     3422                    Atms.append(atom[:2]+['',]+atom[2:5])
     3423                    AtCods.append('1')
     3424                    MagSytSym = G2spc.MagSytSym(SytSym,dupDir,SGData)
     3425                    atMxyz.append([MagSytSym,CSI[0]])
     3426                G2phsG.UseMagAtomDialog(G2frame,magcells[r]['Name'],Atms,AtCods,atMxyz,ifOK=True).ShowModal()
    33933427            data = [controls,bravais,cells,dminx,ssopt,magcells]
    33943428            G2frame.GPXtree.SetItemPyData(UnitCellsId,data)
     
    34023436            allmom = magcells[0].get('allmom',False)
    34033437            magAtms = magcells[0].get('magAtms','')
    3404             maxequiv = magcells[0].get('maxequiv',1000)
     3438            maxequiv = magcells[0].get('maxequiv',100)
    34053439            dlg = G2G.MultiDataDialog(G2frame,title='Keep options',
    3406                 prompts=['test for mag. atoms','all have moment','max unique'],
    3407                 values=['',allmom,maxequiv],limits=[testAtoms,[True,False],[1,100]],
    3408                 formats=['choice','bool','%d',])
     3440                prompts=['max unique','test for mag. atoms','all have moment',],
     3441                values=[maxequiv,'',allmom],limits=[[1,100],testAtoms,[True,False]],
     3442                formats=['%d','choice','bool'])
    34093443            if dlg.ShowModal() == wx.ID_OK:
    3410                 atype,allmom,maxequiv = dlg.GetValues()
     3444                maxequiv,atype,allmom = dlg.GetValues()
    34113445                magAtms = [atom for atom in controls[15] if atom[1] == atype]
    34123446            for phase in magcells:
    34133447                Uvec = phase['Uvec']
    34143448                Trans = phase['Trans']
    3415                 invTrans = nl.inv(Trans)
    3416                 phase['nAtoms'] = TestMagAtoms(phase,magAtms,SGData,Uvec,invTrans,allmom,maxequiv)
     3449                phase['nAtoms'] = len(TestMagAtoms(phase,magAtms,SGData,Uvec,Trans,allmom,maxequiv))
    34173450            data = controls,bravais,cells,dminx,ssopt,magcells
    34183451            G2frame.GPXtree.SetItemPyData(UnitCellsId,data)
    34193452            wx.CallAfter(UpdateUnitCellsGrid,G2frame,data)
    3420         elif c < 0:
    3421             r = event.GetRow()
    3422             phase = magcells[r]
    3423             SGData = phase['SGData']
    3424             msg = 'Magnetic space group information for '+phase['Name']
    3425             text,table = G2spc.SGPrint(SGData,AddInv=True)
    3426             text[0] = ' Magnetic Space Group: '+SGData['MagSpGrp']
    3427             text[3] = ' The magnetic lattice point group is '+SGData['MagPtGp']
    3428             OprNames,SpnFlp = G2spc.GenMagOps(SGData)
    3429             G2G.SGMagSpinBox(G2frame.dataWindow,msg,text,table,SGData['SGCen'],OprNames,
    3430                 SGData['SpnFlp'],False).Show()
    34313453       
    34323454    def MakeNewPhase(event):
     
    35353557        wx.CallAfter(UpdateUnitCellsGrid,G2frame,data)
    35363558       
    3537     def TestMagAtoms(phase,magAtms,SGData,Uvec,invTrans,allmom,maxequiv=1000):
     3559    def TestMagAtoms(phase,magAtms,SGData,Uvec,Trans,allmom,maxequiv=1000):
    35383560        found = False
    35393561        phase['Keep'] = False
     
    35413563            phase['Keep'] = True
    35423564            return
     3565        invTrans = nl.inv(Trans)
     3566        atCodes = []
    35433567        Phase = {'General':{'AtomPtrs':[2,1],'SGData':copy.deepcopy(phase['SGData'])},'Atoms':[]}
    35443568        for matm in magAtms:
    3545             xyzs = G2spc.GenAtom(matm[3:6],SGData,False,Move=True)
     3569            XYZ = G2spc.GenAtom(matm[3:6],SGData,False,Move=True)
     3570            xyzs = [xyz[0] for xyz in XYZ]
     3571            atCodes += len(xyzs)*['1',]
     3572            xyzs,atCodes = G2lat.ExpandCell(xyzs,atCodes,0,Trans)
    35463573            for ix,x in enumerate(xyzs):
    3547                 xyz = G2lat.TransformXYZ(x[0]-Uvec,invTrans.T,np.zeros(3))%1.
     3574                xyz = G2lat.TransformXYZ(x-Uvec,invTrans.T,np.zeros(3))%1.
    35483575                Phase['Atoms'].append(matm[:2]+list(xyz))
    35493576                SytSym,Mul,Nop,dupDir = G2spc.SytSym(xyz,phase['SGData'])
     
    35523579                    phase['Keep'] = True
    35533580                if allmom:
    3554                     if not any(CSI[0]):         #found one - can quit looking
     3581                    if not any(CSI[0]):
    35553582                        phase['Keep'] = False
    35563583                        found = True
    3557         atCodes = len(Phase['Atoms'])*['1',]
    3558         natm = len(G2lat.GetUnique(Phase,atCodes)[0])
     3584        uAtms = G2lat.GetUnique(Phase,atCodes)[0]
     3585        natm = len(uAtms)
    35593586        if natm > maxequiv or found: #too many allowed atoms found
    35603587            phase['Keep'] = False
    3561         return natm
     3588        return uAtms
    35623589       
    35633590    def OnRunSubsMag(event):
    35643591        import kSUBGROUPSMAG as kMAG
    3565         controls,bravais,cells,dminx,ssopt,magcells = G2frame.GPXtree.GetItemPyData(G2gd.GetGPXtreeItemId(G2frame,G2frame.PatternId, 'Unit Cells List'))
     3592        pUCid = G2gd.GetGPXtreeItemId(G2frame,G2frame.PatternId, 'Unit Cells List')
     3593        controls,bravais,cells,dminx,ssopt,magcells = G2frame.GPXtree.GetItemPyData(pUCid)
    35663594        E,SGData = G2spc.SpcGroup(controls[13])
    35673595        testAtoms = ['',]+list(set([atom[1] for atom in controls[15]]))
     
    36213649                if RVT is not None:
    36223650                    result,Uvec,Trans = RVT
    3623                 invTrans = nl.inv(Trans)
    36243651                phase = G2lat.makeBilbaoPhase(result,Uvec,Trans)
    36253652                phase['Cell'] = G2lat.TransformCell(controls[6:12],Trans)   
     
    36283655                phase['magAtms'] = magAtms
    36293656                phase['maxequiv'] = maxequiv
    3630                 phase['nAtoms'] = TestMagAtoms(phase,magAtms,SGData,Uvec,invTrans,allmom,maxequiv)
     3657                phase['nAtoms'] = len(TestMagAtoms(phase,magAtms,SGData,Uvec,Trans,allmom,maxequiv))
    36313658                magcells.append(phase)
    36323659            magcells[0]['Use'] = True
     
    36363663            G2plt.PlotPatterns(G2frame)
    36373664        data = [controls,bravais,cells,dmin,ssopt,magcells]
    3638         G2frame.GPXtree.SetItemPyData(G2gd.GetGPXtreeItemId(G2frame,G2frame.PatternId, 'Unit Cells List'),data)
     3665        G2frame.GPXtree.SetItemPyData(pUCid,data)
    36393666        G2frame.OnFileSave(event)
    36403667        wx.CallAfter(UpdateUnitCellsGrid,G2frame,data)
     
    39193946            G2frame.dataWindow.RunSubGroupsMag.Enable(True)
    39203947        G2frame.dataWindow.CopyCell.Enable(False)
    3921         Label = '\n Magnetic cells from Bilbao k-SUBGROUPSMAG for %s; kvec1: (%s), kvec2: (%s):'%(SGData['SpGrp'],''.join(controls[14][:3]),''.join(controls[14][3:]))
     3948        Label = '\n Magnetic cells from Bilbao k-SUBGROUPSMAG for %s; kvec1: (%s), kvec2: (%s):'%(controls[13],''.join(controls[14][:3]),''.join(controls[14][3:]))
    39223949        mainSizer.Add(wx.StaticText(parent=G2frame.dataWindow,label=Label),0,WACV)
    39233950        rowLabels = []
    39243951        for i in range(len(magcells)): rowLabels.append(str(i+1))
    3925         colLabels = ['Space Gp.','Try','Keep','Uniq','Trans','Vec','a','b','c','alpha','beta','gamma','Volume']
     3952        colLabels = ['Space Gp','Try','Keep','Uniq','Trans','Vec','a','b','c','alpha','beta','gamma','Volume']
    39263953        Types = [wg.GRID_VALUE_STRING,wg.GRID_VALUE_BOOL,wg.GRID_VALUE_BOOL,wg.GRID_VALUE_LONG,wg.GRID_VALUE_STRING,wg.GRID_VALUE_STRING,]+ \
    39273954            3*[wg.GRID_VALUE_FLOAT+':10,5',]+3*[wg.GRID_VALUE_FLOAT+':10,3',]+[wg.GRID_VALUE_FLOAT+':10,2']
     
    39353962            table.append(row)
    39363963        MagCellsTable = G2G.Table(table,rowLabels=rowLabels,colLabels=colLabels,types=Types)
    3937         G2frame.GetStatusBar().SetStatusText('Double click Keep to refresh Keep flags, row no. to see sym. ops.',1)
     3964        G2frame.GetStatusBar().SetStatusText('Double click Keep to refresh Keep flags; click Space Gp to see sym. ops., Uniq to see unique atoms list',1)
    39383965        magDisplay = G2G.GSGrid(G2frame.dataWindow)
    39393966        magDisplay.SetTable(MagCellsTable, True)
Note: See TracChangeset for help on using the changeset viewer.