Changeset 146


Ignore:
Timestamp:
Aug 5, 2010 2:41:33 PM (13 years ago)
Author:
vondreel
Message:

generalData changed from list to dictionary
add menu items to atoms for atom transformation via symmetry operations & (future) atom parameter modification
improve atom selection tools
implement VERY_LIGHT_GRAY for readonly items in Uij

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/GSASIIphsGUI.py

    r142 r146  
    44import matplotlib as mpl
    55import math
     6import copy
    67import time
    78import cPickle
     
    2324cosd = lambda x: math.cos(x*math.pi/180.)
    2425asind = lambda x: 180.*math.asin(x)/math.pi
    25        
     26            
    2627def UpdatePhaseData(self,item,data,oldPage):
     28   
     29    class SymOpDialog(wx.Dialog):
     30        def __init__(self,parent,SGData):
     31            wx.Dialog.__init__(self,parent,-1,'Select symmetry operator',
     32                pos=wx.DefaultPosition,style=wx.DEFAULT_DIALOG_STYLE)
     33            panel = wx.Panel(self)
     34            self.SGData = SGData
     35            self.OpSelected = [0,0,0,0,0,0]
     36            mainSizer = wx.BoxSizer(wx.VERTICAL)           
     37            mainSizer.Add((5,5),0)
     38            if SGData['SGInv']:
     39                choice = ['No','Yes']
     40                self.inv = wx.RadioBox(panel,-1,'Choose inversion?',choices=choice)
     41                self.inv.Bind(wx.EVT_RADIOBOX, self.OnOpSelect)
     42                mainSizer.Add(self.inv,0,wx.ALIGN_CENTER_VERTICAL)
     43            mainSizer.Add((5,5),0)
     44            if SGData['SGLatt'] != 'P':
     45                LattOp = G2spc.Latt2text(SGData['SGLatt']).split(';')
     46                self.latt = wx.RadioBox(panel,-1,'Choose cell centering?',choices=LattOp)
     47                self.latt.Bind(wx.EVT_RADIOBOX, self.OnOpSelect)
     48                mainSizer.Add(self.latt,0,wx.ALIGN_CENTER_VERTICAL)
     49            mainSizer.Add((5,5),0)
     50            if SGData['SGLaue'] in ['-1','2/m','mmm','4/m','4/mmm']:
     51                Ncol = 2
     52            else:
     53                Ncol = 3
     54            OpList = []
     55            for M,T in SGData['SGOps']:
     56                OpList.append(G2spc.MT2text(M,T))
     57            self.oprs = wx.RadioBox(panel,-1,'Choose space group operator?',choices=OpList,
     58                majorDimension=Ncol)
     59            self.oprs.Bind(wx.EVT_RADIOBOX, self.OnOpSelect)
     60            mainSizer.Add(self.oprs,0,wx.ALIGN_CENTER_VERTICAL)
     61            mainSizer.Add((5,5),0)
     62            mainSizer.Add(wx.StaticText(panel,-1,"   Choose unit cell?"),0,wx.ALIGN_CENTER_VERTICAL)
     63            mainSizer.Add((5,5),0)
     64            cellSizer = wx.BoxSizer(wx.HORIZONTAL)
     65            cellSizer.Add((5,0),0)
     66            cellName = ['X','Y','Z']
     67            self.cell = []
     68            for i in range(3):
     69                self.cell.append(wx.SpinCtrl(panel,-1,cellName[i],size=wx.Size(50,20)))
     70                self.cell[-1].SetRange(-3,3)
     71                self.cell[-1].SetValue(0)
     72                self.cell[-1].Bind(wx.EVT_SPINCTRL, self.OnOpSelect)
     73                cellSizer.Add(self.cell[-1],0,wx.ALIGN_CENTER_VERTICAL)
     74            mainSizer.Add(cellSizer,0,)
     75            choice = ['No','Yes']
     76            self.new = wx.RadioBox(panel,-1,'Generate new positions?',choices=choice)
     77            self.new.Bind(wx.EVT_RADIOBOX, self.OnOpSelect)
     78            mainSizer.Add(self.new,0,wx.ALIGN_CENTER_VERTICAL)
     79            mainSizer.Add((5,5),0)
     80                           
     81            OkBtn = wx.Button(panel,-1,"Ok")
     82            OkBtn.Bind(wx.EVT_BUTTON, self.OnOk)
     83            cancelBtn = wx.Button(panel,-1,"Cancel")
     84            cancelBtn.Bind(wx.EVT_BUTTON, self.OnCancel)
     85            btnSizer = wx.BoxSizer(wx.HORIZONTAL)
     86            btnSizer.Add((20,20),1)
     87            btnSizer.Add(OkBtn)
     88            btnSizer.Add((20,20),1)
     89            btnSizer.Add(cancelBtn)
     90            btnSizer.Add((20,20),1)
     91           
     92            mainSizer.Add(btnSizer,0,wx.EXPAND|wx.BOTTOM|wx.TOP, 10)
     93            panel.SetSizer(mainSizer)
     94            panel.Fit()
     95            self.Fit()
     96           
     97        def OnOpSelect(self,event):
     98            self.OpSelected = [0,0,0,[],0]
     99            if self.SGData['SGInv']:
     100                self.OpSelected[0] = self.inv.GetSelection()
     101            if self.SGData['SGLatt'] != 'P':           
     102                self.OpSelected[1] = self.latt.GetSelection()
     103            self.OpSelected[2] = self.oprs.GetSelection()
     104            for i in range(3):
     105                self.OpSelected[3].append(float(self.cell[i].GetValue()))
     106            self.OpSelected[4] = self.new.GetSelection()
     107               
     108        def GetSelection(self):
     109            return self.OpSelected
     110                           
     111        def OnOk(self,event):
     112            parent = self.GetParent()
     113            parent.Raise()
     114            self.SetReturnCode(wx.ID_OK)
     115            self.MakeModal(False)             
     116            self.Destroy()
     117           
     118        def OnCancel(self,event):
     119            parent = self.GetParent()
     120            parent.Raise()
     121            self.SetReturnCode(wx.ID_CANCEL)
     122            self.MakeModal(False)             
     123            self.Destroy()           
     124       
    27125    Atoms = []
    28126    self.SelectedRow = 0
     
    84182                else:
    85183                    text = G2spc.SGPrint(SGData)
    86                     generalData[SGData] = SGData
     184                    generalData['SGData'] = SGData
    87185                    msg = 'Space Group Information'
    88186                    Style = wx.ICON_INFORMATION
     
    200298               
    201299            r,c =  event.GetRow(),event.GetCol()
    202             if r < 0:                          #on col label!
     300            if r < 0 and c < 0:
     301                Atoms.ClearSelection()
     302            if r < 0:                          #double click on col label! Change all atoms!
    203303                sel = -1
     304                noSkip = True
    204305                if Atoms.GetColLabelValue(c) == 'refine':
    205                     choice = ['F - site fraction','X - coordinates','U - thermal parameters']
     306                    Type = generalData['Type']
     307                    if Type in ['nuclear','macromolecular']:
     308                        choice = ['F - site fraction','X - coordinates','U - thermal parameters']
     309                    elif Type in ['magnetic',]:
     310                        choice = ['F - site fraction','X - coordinates','U - thermal parameters','M - magnetic moment']                       
    206311                    dlg = wx.MultiChoiceDialog(self,'Select','Refinement controls',choice)
    207312                    if dlg.ShowModal() == wx.ID_OK:
     
    209314                        parms = ''
    210315                        for x in sel:
    211                             parms += choice[x][0]                           
     316                            parms += choice[x][0]
     317                    dlg.Destroy()                           
    212318                elif Atoms.GetColLabelValue(c) == 'I/A':
    213319                    choice = ['Isotropic','Anisotropic']
     
    216322                        sel = dlg.GetSelection()
    217323                        parms = choice[sel][0]
    218                 if sel >= 0:
     324                    dlg.Destroy()
     325                elif Atoms.GetColLabelValue(c) == 'Type':
     326                    choice = generalData['AtomTypes']                           
     327                    dlg = wx.SingleChoiceDialog(self,'Select','Atom types',choice)
     328                    if dlg.ShowModal() == wx.ID_OK:
     329                        sel = dlg.GetSelection()
     330                        parms = choice[sel]
     331                        noSkip = False
     332                        Atoms.ClearSelection()
     333                        for row in range(Atoms.GetNumberRows()):
     334                            if parms == atomData[row][c]:
     335                                Atoms.SelectRow(row,True)
     336                elif Atoms.GetColLabelValue(c) == 'residue':
     337                    choice = []
    219338                    for r in range(Atoms.GetNumberRows()):
     339                        if str(atomData[r][c]) not in choice:
     340                            choice.append(str(atomData[r][c]))
     341                    choice.sort()
     342                    dlg = wx.SingleChoiceDialog(self,'Select','Residue',choice)
     343                    if dlg.ShowModal() == wx.ID_OK:
     344                        sel = dlg.GetSelection()
     345                        parms = choice[sel]
     346                        noSkip = False
     347                        Atoms.ClearSelection()
     348                        for row in range(Atoms.GetNumberRows()):
     349                            if parms == atomData[row][c]:
     350                                Atoms.SelectRow(row,True)
     351                elif Atoms.GetColLabelValue(c) == 'res no':
     352                    choice = []
     353                    for r in range(Atoms.GetNumberRows()):
     354                        if str(atomData[r][c]) not in choice:
     355                            choice.append(str(atomData[r][c]))
     356                    dlg = wx.SingleChoiceDialog(self,'Select','Residue no.',choice)
     357                    if dlg.ShowModal() == wx.ID_OK:
     358                        sel = dlg.GetSelection()
     359                        parms = choice[sel]
     360                        noSkip = False
     361                        Atoms.ClearSelection()
     362                        for row in range(Atoms.GetNumberRows()):
     363                            if int(parms) == atomData[row][c]:
     364                                Atoms.SelectRow(row,True)
     365                elif Atoms.GetColLabelValue(c) == 'chain':
     366                    choice = []
     367                    for r in range(Atoms.GetNumberRows()):
     368                        if atomData[r][c] not in choice:
     369                            choice.append(atomData[r][c])
     370                    dlg = wx.SingleChoiceDialog(self,'Select','Chain',choice)
     371                    if dlg.ShowModal() == wx.ID_OK:
     372                        sel = dlg.GetSelection()
     373                        parms = choice[sel]
     374                        noSkip = False
     375                        Atoms.ClearSelection()
     376                        for row in range(Atoms.GetNumberRows()):
     377                            if parms == atomData[row][c]:
     378                                Atoms.SelectRow(row,True)
     379                    dlg.Destroy()
     380                if sel >= 0 and noSkip:
     381                    ui = colLabels.index('U11')
     382                    us = colLabels.index('Uiso')
     383                    ss = colLabels.index('site sym')
     384                    for r in range(Atoms.GetNumberRows()):
     385                        if parms != atomData[r][c] and Atoms.GetColLabelValue(c) == 'I/A':
     386                            if parms == 'A':                #'I' --> 'A'
     387                                Uiso = atomData[r][us]
     388                                sytsym = atomData[r][ss]
     389                                CSI = G2spc.GetCSuinel(sytsym)
     390                                atomData[r][ui:ui+6] = Uiso*np.array(CSI[3])
     391                                atomData[r][us] = ''
     392                                Atoms.SetCellRenderer(r,us,wg.GridCellStringRenderer())
     393                                Atoms.SetCellStyle(r,us,VERY_LIGHT_GREY,True)
     394                                for i in range(6):
     395                                    ci = ui+i
     396                                    Atoms.SetCellRenderer(r,ci,wg.GridCellFloatRenderer(10,4))
     397                                    Atoms.SetCellStyle(r,ci,VERY_LIGHT_GREY,True)
     398                                    if CSI[2][i]:
     399                                        Atoms.SetCellStyle(r,ci,WHITE,False)
     400                            else:                           #'A' --> 'I'
     401                                Uij = atomData[r][ui:ui+6]
     402                                atomData[r][us] = (Uij[0]+Uij[1]+Uij[2])/3.0
     403                                atomData[r][ui:ui+6] = [0,0,0,0,0,0]
     404                                Atoms.SetCellRenderer(r,us,wg.GridCellFloatRenderer(10,4))
     405                                Atoms.SetCellStyle(r,us,WHITE,False)
     406                                for i in range(6):
     407                                    ci = ui+i
     408                                    Atoms.SetCellRenderer(r,ci,wg.GridCellStringRenderer())
     409                                    Atoms.SetCellValue(r,ci,'')
     410                                    Atoms.SetCellStyle(r,ci,VERY_LIGHT_GREY,True)                       
    220411                        Atoms.SetCellValue(r,c,parms)
    221412            elif c < 0:                    #picked atom row
     
    273464                    if iUij == CSI[0][i]:
    274465                        atomData[r][i+colLabels.index('U11')] = value*CSI[1][i]               
     466            Atoms.ForceRefresh()
     467           
     468        def ChangeSelection(event):
     469            r,c =  event.GetRow(),event.GetCol()
     470            if r < 0 and c < 0:
     471                Atoms.ClearSelection()
     472            if c < 0:
     473                if r in Atoms.GetSelectedRows():
     474                    Atoms.DeselectRow(r)
     475                else:
     476                    Atoms.SelectRow(r,True)
     477            if r < 0:
     478                if c in Atoms.GetSelectedCols():
     479                    Atoms.DeselectCol(c)
     480                else:
     481                    Atoms.SelectCol(c,True)           
    275482                   
    276483        def AtomTypeSelect(event):
     
    291498            wg.GRID_VALUE_STRING,wg.GRID_VALUE_NUMBER,wg.GRID_VALUE_CHOICE+":I,A",
    292499            wg.GRID_VALUE_FLOAT+':10,4',                                                            #Uiso
    293             wg.GRID_VALUE_FLOAT+':10,4',wg.GRID_VALUE_FLOAT+':10,4',wg.GRID_VALUE_FLOAT+':10,4',    #Uij
    294             wg.GRID_VALUE_FLOAT+':10,4',wg.GRID_VALUE_FLOAT+':10,4',wg.GRID_VALUE_FLOAT+':10,4']
     500            wg.GRID_VALUE_STRING,wg.GRID_VALUE_STRING,wg.GRID_VALUE_STRING,                         #Uij - placeholders
     501            wg.GRID_VALUE_STRING,wg.GRID_VALUE_STRING,wg.GRID_VALUE_STRING]
    295502        colLabels = ['Name','Type','refine','x','y','z','frac','site sym','mult','I/A','Uiso','U11','U22','U33','U12','U13','U23']
    296503        if generalData['Type'] == 'magnetic':
     
    303510            Types = [wg.GRID_VALUE_NUMBER,
    304511                wg.GRID_VALUE_CHOICE+": ,ALA,ARG,ASN,ASP,CYS,GLN,GLU,GLY,HIS,ILE,LEU,LYS,MET,PHE,PRO,SER,THR,TRP,TYR,VAL,MSE,HOH,UNK",
    305                 wg.GRID_VALUE_STRING] + Types       
     512                wg.GRID_VALUE_STRING] + Types
     513        elif generalData['Type'] == 'modulated':
     514            Types += []
     515            colLabels += []       
    306516        table = []
    307517        rowLabels = []
    308518        for i,atom in enumerate(atomData):
    309             table.append(atom)
     519            if atom[colLabels.index('I/A')] == 'I':
     520                table.append(atom[:colLabels.index('U11')]+['','','','','',''])
     521            else:
     522                table.append(atom)
    310523            rowLabels.append(str(i+1))
    311524        atomTable = G2gd.Table(table,rowLabels=rowLabels,colLabels=colLabels,types=Types)
     
    313526        Atoms.Bind(wg.EVT_GRID_CELL_CHANGE, RefreshAtomGrid)
    314527        Atoms.Bind(wg.EVT_GRID_LABEL_LEFT_DCLICK, RefreshAtomGrid)
     528        Atoms.Bind(wg.EVT_GRID_LABEL_RIGHT_CLICK, ChangeSelection)
    315529        Atoms.Bind(wg.EVT_GRID_SELECT_CELL, AtomTypeSelect)
    316530        Atoms.SetMargins(0,0)
     
    319533        colSS = colLabels.index('site sym')
    320534        colIA = colLabels.index('I/A')
     535        colU11 = colLabels.index('U11')
     536        colUiso = colLabels.index('Uiso')
     537        attr = wg.GridCellAttr()                                #to set Uij defaults
     538        attr.SetBackgroundColour(VERY_LIGHT_GREY)
     539        attr.SetReadOnly(True)
     540        for i in range(colU11,colU11+6):
     541            Atoms.SetColAttr(i,attr)
    321542        for row in range(Atoms.GetNumberRows()):
    322543            Atoms.SetReadOnly(row,colSS,True)                         #site sym
    323544            Atoms.SetReadOnly(row,colSS+1,True)                       #Mult
    324             if Atoms.GetCellValue(row,colIA) == 'I':
    325                 for i in range(2,8):
    326                     Atoms.SetCellRenderer(row,colIA+i,wg.GridCellStringRenderer())
    327                     Atoms.SetCellValue(row,colIA+i,'')
    328                     Atoms.SetCellStyle(row,colIA+i,VERY_LIGHT_GREY,True)
    329             elif Atoms.GetCellValue(row,colIA) == 'A':
     545            if Atoms.GetCellValue(row,colIA) == 'A':
    330546                CSI = G2spc.GetCSuinel(atomData[row][colLabels.index('site sym')])
    331                 Atoms.SetCellRenderer(row,colIA+1,wg.GridCellStringRenderer())
    332                 Atoms.SetCellStyle(row,colIA+1,VERY_LIGHT_GREY,True)
    333                 Atoms.SetCellValue(row,colIA+1,'')
     547                Atoms.SetCellRenderer(row,colUiso,wg.GridCellStringRenderer())
     548                Atoms.SetCellStyle(row,colUiso,VERY_LIGHT_GREY,True)
     549                Atoms.SetCellValue(row,colUiso,'')
    334550                for i in range(6):
    335                     ci = colIA+i+2
    336                     Atoms.SetCellStyle(row,ci,VERY_LIGHT_GREY,True)
     551                    ci = colU11+i
     552                    Atoms.SetCellRenderer(row,ci,wg.GridCellFloatRenderer(10,4))
    337553                    if CSI[2][i]:
    338554                        Atoms.SetCellStyle(row,ci,WHITE,False)
     
    381597        event.StopPropagation()
    382598       
     599    def AtomRefine(event):
     600        indx = Atoms.GetSelectedRows()
     601        if indx:
     602            atomData = data['Atoms']
     603            generalData = data['General']
     604            Type = generalData['Type']
     605            if Type in ['nuclear','macromolecular']:
     606                choice = ['F - site fraction','X - coordinates','U - thermal parameters']
     607            elif Type in ['magnetic',]:
     608                choice = ['F - site fraction','X - coordinates','U - thermal parameters','M - magnetic moment']                       
     609            dlg = wx.MultiChoiceDialog(self,'Select','Refinement controls',choice)
     610            if dlg.ShowModal() == wx.ID_OK:
     611                sel = dlg.GetSelections()
     612                parms = ''
     613                for x in sel:
     614                    parms += choice[x][0]                           
     615            dlg.Destroy()           
     616            colLabels = [Atoms.GetColLabelValue(c) for c in range(Atoms.GetNumberCols())]
     617            c = colLabels.index('refine')
     618            for r in indx:
     619                atomData[r][c] = parms
     620            Atoms.ForceRefresh()                           
     621       
     622    def AtomModify(event):
     623        indx = Atoms.GetSelectedRows()
     624        if indx:
     625            atomData = data['Atoms']
     626            generalData = data['General']
     627       
     628    def AtomTransform(event):       
     629        indx = Atoms.GetSelectedRows()
     630        if indx:
     631            colLabels = [Atoms.GetColLabelValue(c) for c in range(Atoms.GetNumberCols())]
     632            cx = colLabels.index('x')
     633            cuia = colLabels.index('I/A')
     634            cuij = colLabels.index('U11')
     635            css = colLabels.index('site sym')
     636            atomData = data['Atoms']
     637            generalData = data['General']
     638            SGData = generalData['SGData']
     639            dlg = SymOpDialog(self,SGData)
     640            try:
     641                if dlg.ShowModal() == wx.ID_OK:
     642                    Inv,Cent,Opr,Cell,New = dlg.GetSelection()
     643                    Cell = np.array(Cell)
     644                    cent = SGData['SGCen'][Cent]
     645                    M,T = SGData['SGOps'][Opr]
     646                    for ind in indx:
     647                        XYZ = np.array(atomData[ind][cx:cx+3])
     648                        XYZ = np.inner(M,XYZ)+T
     649                        if Inv:
     650                            XYZ = -XYZ
     651                        XYZ = XYZ+cent+Cell
     652                        if New:
     653                            atom = copy.copy(atomData[ind])
     654                        else:
     655                            atom = atomData[ind]
     656                        atom[cx:cx+3] = XYZ
     657                        atom[css:css+2] = G2spc.SytSym(XYZ,SGData)
     658                        if atom[cuia] == 'A':
     659                            Uij = atom[cuij:cuij+6]
     660                            U = G2spc.Uij2U(Uij)
     661                            U = np.inner(np.inner(M.T,U),M)
     662                            Uij = G2spc.U2Uij(U)
     663                            atom[cuij:cuij+6] = Uij
     664                        if New:
     665                            atomData.append(atom)
     666            finally:
     667                dlg.Destroy()
     668            Atoms.ClearSelection()
     669            if New:
     670                FillAtomsGrid()           
     671            else:                       
     672                Atoms.ForceRefresh()
     673       
    383674    def UpdateDrawing():
    384675        print 'Drawing'
     
    397688            self.dataFrame.Bind(wx.EVT_MENU, AtomInsert, id=G2gd.wxID_ATOMSEDITINSERT)
    398689            self.dataFrame.Bind(wx.EVT_MENU, AtomDelete, id=G2gd.wxID_ATOMSEDITDELETE)
     690            self.dataFrame.Bind(wx.EVT_MENU, AtomRefine, id=G2gd.wxID_ATOMSREFINE)
     691            self.dataFrame.Bind(wx.EVT_MENU, AtomModify, id=G2gd.wxID_ATOMSMODIFY)
     692            self.dataFrame.Bind(wx.EVT_MENU, AtomTransform, id=G2gd.wxID_ATOMSTRANSFORM)
    399693            FillAtomsGrid()           
    400694        else:
     
    407701    self.dataFrame.SetMenuBar(self.dataFrame.BlankMenu)
    408702    self.dataFrame.SetLabel('Phase Data for '+PhaseName)
     703    self.dataFrame.CreateStatusBar()
    409704    self.dataDisplay = G2gd.GSNoteBook(parent=self.dataFrame,size=self.dataFrame.GetClientSize())
    410705   
    411     General = G2gd.GSGrid(parent=self.dataDisplay)
     706    General = G2gd.GSGrid(self.dataDisplay)
    412707    FillGeneralGrid()
    413708    self.dataDisplay.AddPage(General,'General')
     
    415710    GeneralData = data['General']
    416711    if GeneralData['Type'] == 'Pawley':
    417         PawleyRefl = G2gd.GSGrid(parent=self.dataDisplay)
     712        PawleyRefl = G2gd.GSGrid(self.dataDisplay)
    418713        self.dataDisplay.AddPage(PawleyRefl,'Pawley reflections')
    419714    else:
    420         Atoms = G2gd.GSGrid(parent=self.dataDisplay)
     715        Atoms = G2gd.GSGrid(self.dataDisplay)
    421716        self.dataDisplay.AddPage(Atoms,'Atoms')
    422         Drawing = wx.Window(parent=self.dataDisplay)
     717        Drawing = wx.Window(self.dataDisplay)
    423718        self.dataDisplay.AddPage(Drawing,'Drawing')
    424719   
Note: See TracChangeset for help on using the changeset viewer.