Changeset 4433


Ignore:
Timestamp:
May 25, 2020 3:08:15 PM (4 years ago)
Author:
toby
Message:

fix problem where histogram has reflections, but is not in phase; alternate atom selection -- in progress

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/GSASIIphsGUI.py

    r4432 r4433  
    37193719        event.StopPropagation()
    37203720
    3721     def GetSelectedAtoms():
    3722         '''Get all atoms that are selected by row or by having any cell selected.
    3723         produce an error message if no atoms are selected.
     3721    def GetSelectedAtoms(action='action'):
     3722        '''Get all atoms that are selected by row or by having any cell
     3723        selected. If no atoms are selected ask user.
    37243724        '''
    37253725        indx = list(set([row for row,col in Atoms.GetSelectedCells()]+Atoms.GetSelectedRows()))
    3726         if indx:
    3727             return indx
    3728         else:
    3729             G2G.G2MessageBox(G2frame,'Warning: no atoms were selected','Nothing selected')
     3726        # if indx:
     3727        #     return indx
     3728        # else:
     3729        #     G2G.G2MessageBox(G2frame,'Warning: no atoms were selected','Nothing selected')
     3730        if indx: return indx
     3731        choices = []
     3732        for i in range(Atoms.GetNumberRows()):
     3733            val = Atoms.GetCellValue(i,0)
     3734            if val in choices:
     3735                val += '_' + Atoms.GetCellValue(i,5)
     3736            choices.append(val)
     3737        if not choices: return
     3738        dlg = G2G.G2MultiChoiceDialog(Atoms.GetTopLevelParent(),
     3739            'Select atoms','Select atoms for '+action,choices)
     3740        if dlg.ShowModal() == wx.ID_OK:
     3741            indx = dlg.GetSelections()
     3742        dlg.Destroy()
     3743        return indx
    37303744       
    37313745    def AtomRefine(event):
     
    70567070#### Structure drawing GUI stuff               
    70577071################################################################################
     7072    def getAtomSelections(drawAtoms,action='action'):
     7073        '''get selected atoms from table or ask user if none selected'''
     7074        #indx = drawAtoms.GetSelectedRows()
     7075        indx = list(set([row for row,col in drawAtoms.GetSelectedCells()]+
     7076                            drawAtoms.GetSelectedRows()))
     7077        if indx: return indx
     7078        choices = []
     7079        for i in range(drawAtoms.GetNumberRows()):
     7080            val = drawAtoms.GetCellValue(i,0)
     7081            if val in choices:
     7082                val += '_' + drawAtoms.GetCellValue(i,5)
     7083            choices.append(val)
     7084        if not choices: return
     7085        dlg = G2G.G2MultiChoiceDialog(drawAtoms.GetTopLevelParent(),
     7086            'Select atoms','Select atoms for '+action,choices)
     7087        if dlg.ShowModal() == wx.ID_OK:
     7088            indx = dlg.GetSelections()
     7089        dlg.Destroy()
     7090        return indx
    70587091
    70597092    def SetupDrawingData():
     
    71177150       
    71187151    def OnRestraint(event):       
     7152        indx = getAtomSelections(drawAtoms)
     7153        if not indx: return
    71197154        indx = drawAtoms.GetSelectedRows()
    71207155        restData = G2frame.GPXtree.GetItemPyData(   
     
    71717206
    71727207    def OnDefineRB(event):
    7173         indx = drawAtoms.GetSelectedRows()
     7208        indx = getAtomSelections(drawAtoms)
     7209        if not indx: return
    71747210        indx.sort()
    71757211        RBData = G2frame.GPXtree.GetItemPyData(   
     
    72097245##### Draw Atom routines
    72107246################################################################################
    7211            
    72127247    def UpdateDrawAtoms(atomStyle=''):
    72137248        def RefreshDrawAtomGrid(event):
     
    74167451
    74177452    def DrawAtomStyle(event):
    7418         indx = drawAtoms.GetSelectedRows()
    7419         if indx:
    7420             generalData = data['General']
    7421             atomData = data['Drawing']['Atoms']
    7422             cx,ct,cs,ci = data['Drawing']['atomPtrs']
    7423             styleChoice = [' ','lines','vdW balls','sticks','balls & sticks','ellipsoids','polyhedra']
    7424             if generalData['Type'] == 'macromolecular':
    7425                 styleChoice = [' ','lines','vdW balls','sticks','balls & sticks','ellipsoids',
    7426                 'backbone','ribbons','schematic']
    7427             dlg = wx.SingleChoiceDialog(G2frame,'Select','Atom drawing style',styleChoice)
    7428             if dlg.ShowModal() == wx.ID_OK:
    7429                 sel = dlg.GetSelection()
    7430                 parms = styleChoice[sel]
    7431                 for r in indx:
    7432                     atomData[r][cs] = parms
    7433                     drawAtoms.SetCellValue(r,cs,parms)
    7434             dlg.Destroy()
    7435             FindBondsDraw(data)
    7436             drawAtoms.ClearSelection()
    7437             G2plt.PlotStructure(G2frame,data)
     7453        indx = getAtomSelections(drawAtoms)
     7454        if not indx: return
     7455        generalData = data['General']
     7456        atomData = data['Drawing']['Atoms']
     7457        cx,ct,cs,ci = data['Drawing']['atomPtrs']
     7458        styleChoice = [' ','lines','vdW balls','sticks','balls & sticks','ellipsoids','polyhedra']
     7459        if generalData['Type'] == 'macromolecular':
     7460            styleChoice = [' ','lines','vdW balls','sticks','balls & sticks','ellipsoids',
     7461            'backbone','ribbons','schematic']
     7462        dlg = wx.SingleChoiceDialog(G2frame,'Select','Atom drawing style',styleChoice)
     7463        if dlg.ShowModal() == wx.ID_OK:
     7464            sel = dlg.GetSelection()
     7465            parms = styleChoice[sel]
     7466            for r in indx:
     7467                atomData[r][cs] = parms
     7468                drawAtoms.SetCellValue(r,cs,parms)
     7469        dlg.Destroy()
     7470        FindBondsDraw(data)
     7471        drawAtoms.ClearSelection()
     7472        G2plt.PlotStructure(G2frame,data)
     7473
     7474    def DrawAtomLabel(event):
     7475        indx = getAtomSelections(drawAtoms)
     7476        if not indx: return
     7477        generalData = data['General']
     7478        atomData = data['Drawing']['Atoms']
     7479        cx,ct,cs,ci = data['Drawing']['atomPtrs']
     7480        styleChoice = [' ','type','name','number']
     7481        if generalData['Type'] == 'macromolecular':
     7482            styleChoice = [' ','type','name','number','residue','1-letter','chain']
     7483        dlg = wx.SingleChoiceDialog(G2frame,'Select','Atom label style',styleChoice)
     7484        if dlg.ShowModal() == wx.ID_OK:
     7485            sel = dlg.GetSelection()
     7486            parms = styleChoice[sel]
     7487            for r in indx:
     7488                atomData[r][cs+1] = parms
     7489                drawAtoms.SetCellValue(r,cs+1,parms)
     7490        dlg.Destroy()
     7491        drawAtoms.ClearSelection()
     7492        G2plt.PlotStructure(G2frame,data)
     7493           
     7494    def DrawAtomColor(event):
     7495        indx = getAtomSelections(drawAtoms)
     7496        if not indx: return
     7497        if len(indx) > 1:
     7498            G2frame.GetStatusBar().SetStatusText('Select Custom Color, change color, Add to Custom Colors, then OK',1)
    74387499        else:
    7439             G2G.G2MessageBox(G2frame,'Select atoms first')
    7440 
    7441     def DrawAtomLabel(event):
    7442         indx = drawAtoms.GetSelectedRows()
    7443         if indx:
    7444             generalData = data['General']
    7445             atomData = data['Drawing']['Atoms']
    7446             cx,ct,cs,ci = data['Drawing']['atomPtrs']
    7447             styleChoice = [' ','type','name','number']
    7448             if generalData['Type'] == 'macromolecular':
    7449                 styleChoice = [' ','type','name','number','residue','1-letter','chain']
    7450             dlg = wx.SingleChoiceDialog(G2frame,'Select','Atom label style',styleChoice)
    7451             if dlg.ShowModal() == wx.ID_OK:
    7452                 sel = dlg.GetSelection()
    7453                 parms = styleChoice[sel]
    7454                 for r in indx:
    7455                     atomData[r][cs+1] = parms
    7456                     drawAtoms.SetCellValue(r,cs+1,parms)
    7457             dlg.Destroy()
    7458             drawAtoms.ClearSelection()
    7459             G2plt.PlotStructure(G2frame,data)
    7460         else:
    7461             G2G.G2MessageBox(G2frame,'Select atoms first')
    7462            
    7463     def DrawAtomColor(event):
    7464 
    7465         indx = drawAtoms.GetSelectedRows()
    7466         if indx:
    7467             if len(indx) > 1:
    7468                 G2frame.GetStatusBar().SetStatusText('Select Custom Color, change color, Add to Custom Colors, then OK',1)
    7469             else:
    7470                 G2frame.GetStatusBar().SetStatusText('Change color, Add to Custom Colors, then OK',1)
    7471             atomData = data['Drawing']['Atoms']
    7472             cx,ct,cs,ci = data['Drawing']['atomPtrs']
    7473             atmColors = []
    7474             atmTypes = []
     7500            G2frame.GetStatusBar().SetStatusText('Change color, Add to Custom Colors, then OK',1)
     7501        atomData = data['Drawing']['Atoms']
     7502        cx,ct,cs,ci = data['Drawing']['atomPtrs']
     7503        atmColors = []
     7504        atmTypes = []
     7505        for r in indx:
     7506            if atomData[r][cs+2] not in atmColors:
     7507                atmColors.append(atomData[r][cs+2])
     7508                atmTypes.append(atomData[r][ct])
     7509                if len(atmColors) > 16:
     7510                    break
     7511        colors = wx.ColourData()
     7512        colors.SetChooseFull(True)
     7513        dlg = wx.ColourDialog(None,colors)
     7514        if dlg.ShowModal() == wx.ID_OK:
     7515            for i in range(len(atmColors)):                   
     7516                atmColors[i] = dlg.GetColourData().GetColour()[:3]
     7517            colorDict = dict(zip(atmTypes,atmColors))
    74757518            for r in indx:
    7476                 if atomData[r][cs+2] not in atmColors:
    7477                     atmColors.append(atomData[r][cs+2])
    7478                     atmTypes.append(atomData[r][ct])
    7479                     if len(atmColors) > 16:
    7480                         break
    7481             colors = wx.ColourData()
    7482             colors.SetChooseFull(True)
    7483             dlg = wx.ColourDialog(None,colors)
    7484             if dlg.ShowModal() == wx.ID_OK:
    7485                 for i in range(len(atmColors)):                   
    7486                     atmColors[i] = dlg.GetColourData().GetColour()[:3]
    7487                 colorDict = dict(zip(atmTypes,atmColors))
    7488                 for r in indx:
    7489                     color = colorDict[atomData[r][ct]]
    7490                     atomData[r][cs+2] = color
    7491                     attr = wg.GridCellAttr()                #needs to be here - gets lost if outside loop!
    7492                     attr.SetBackgroundColour(color)
    7493                     drawAtoms.SetAttr(r,cs+2,attr)
    7494                     data['Drawing']['Atoms'][r][cs+2] = color
    7495             drawAtoms.ClearSelection()
    7496             dlg.Destroy()
    7497             G2frame.GetStatusBar().SetStatusText('',1)
    7498             G2plt.PlotStructure(G2frame,data)
    7499         else:
    7500             G2G.G2MessageBox(G2frame,'Select atoms first')
     7519                color = colorDict[atomData[r][ct]]
     7520                atomData[r][cs+2] = color
     7521                attr = wg.GridCellAttr()                #needs to be here - gets lost if outside loop!
     7522                attr.SetBackgroundColour(color)
     7523                drawAtoms.SetAttr(r,cs+2,attr)
     7524                data['Drawing']['Atoms'][r][cs+2] = color
     7525        drawAtoms.ClearSelection()
     7526        dlg.Destroy()
     7527        G2frame.GetStatusBar().SetStatusText('',1)
     7528        G2plt.PlotStructure(G2frame,data)
    75017529           
    75027530    def ResetAtomColors(event):
     
    75257553       
    75267554    def SetViewPoint(event):
    7527         indx = drawAtoms.GetSelectedRows()
    7528         if indx:
    7529             atomData = data['Drawing']['Atoms']
    7530             cx = data['Drawing']['atomPtrs'][0]
    7531             data['Drawing']['viewPoint'] = [atomData[indx[0]][cx:cx+3],[indx[0],0]]
     7555        indx = getAtomSelections(drawAtoms)
     7556        if not indx: return
     7557        atomData = data['Drawing']['Atoms']
     7558        cx = data['Drawing']['atomPtrs'][0]
     7559        data['Drawing']['viewPoint'] = [atomData[indx[0]][cx:cx+3],[indx[0],0]]
    75327560#            drawAtoms.ClearSelection()                                  #do I really want to do this?
    7533             G2plt.PlotStructure(G2frame,data)
    7534         else:
    7535             G2G.G2MessageBox(G2frame,'Select atoms first')
     7561        G2plt.PlotStructure(G2frame,data)
    75367562           
    75377563    def noDuplicate(xyz,atomData):                  #be careful where this is used - it's slow
     
    75437569               
    75447570    def AddSymEquiv(event):
    7545         indx = drawAtoms.GetSelectedRows()
     7571        indx = getAtomSelections(drawAtoms)
     7572        if not indx: return
    75467573        indx.sort()
    7547         if indx:
    7548             colLabels = [drawAtoms.GetColLabelValue(c) for c in range(drawAtoms.GetNumberCols())]
    7549             cx,ct,cs,cui = data['Drawing']['atomPtrs']
    7550             cuij = cui+2
    7551             cmx = 0
    7552             if 'Mx' in colLabels:
    7553                 cmx = colLabels.index('Mx')
    7554             atomData = data['Drawing']['Atoms']
    7555             generalData = data['General']
    7556             SGData = generalData['SGData']
    7557             SpnFlp = SGData.get('SpnFlp',[])
    7558             dlg = SymOpDialog(G2frame,SGData,False,True)
    7559             try:
    7560                 if dlg.ShowModal() == wx.ID_OK:
    7561                     Inv,Cent,Opr,Cell,New,Force = dlg.GetSelection()
    7562                     Cell = np.array(Cell)
    7563                     cent = SGData['SGCen'][Cent]
    7564                     M,T = SGData['SGOps'][Opr]
    7565                     for ind in indx:
    7566                         XYZ = np.array(atomData[ind][cx:cx+3])
    7567                         XYZ = np.inner(M,XYZ)+T
    7568                         if Inv and not SGData['SGFixed']:
    7569                             XYZ = -XYZ
    7570                         XYZ = XYZ+cent+Cell
    7571                         if Force:
    7572                             XYZ %= 1.       #G2spc.MoveToUnitCell(XYZ)
    7573                         if noDuplicate(XYZ,atomData):
    7574                             atom = copy.copy(atomData[ind])
    7575                             atom[cx:cx+3] = XYZ
    7576                             atomOp = atom[cs-1]
    7577                             OprNum = ((Opr+1)+100*Cent)*(1-2*Inv)
    7578                             newOp = str(OprNum)+'+'+ \
    7579                                 str(int(Cell[0]))+','+str(int(Cell[1]))+','+str(int(Cell[2]))                           
    7580                             atom[cs-1] = G2spc.StringOpsProd(atomOp,newOp,SGData)
    7581                             if cmx:         #magnetic moment
    7582                                 opNum = G2spc.GetOpNum(OprNum,SGData)
    7583                                 mom = np.array(atom[cmx:cmx+3])
    7584                                 if SGData['SGGray']:
    7585                                     atom[cmx:cmx+3] = np.inner(mom,M)*nl.det(M)
    7586                                 else:   
    7587                                     atom[cmx:cmx+3] = np.inner(mom,M)*nl.det(M)*SpnFlp[opNum-1]
    7588                             if atom[cui] == 'A':
    7589                                 Uij = atom[cuij:cuij+6]
    7590                                 Uij = G2spc.U2Uij(np.inner(np.inner(M,G2spc.Uij2U(Uij)),M))
    7591                                 atom[cuij:cuij+6] = Uij
    7592                             atomData.append(atom[:cuij+9])  #not SS stuff
    7593             finally:
    7594                 dlg.Destroy()
    7595             UpdateDrawAtoms()
    7596             drawAtoms.ClearSelection()
    7597             G2plt.PlotStructure(G2frame,data)
    7598         else:
    7599             G2G.G2MessageBox(G2frame,'Select atoms first')
     7574        colLabels = [drawAtoms.GetColLabelValue(c) for c in range(drawAtoms.GetNumberCols())]
     7575        cx,ct,cs,cui = data['Drawing']['atomPtrs']
     7576        cuij = cui+2
     7577        cmx = 0
     7578        if 'Mx' in colLabels:
     7579            cmx = colLabels.index('Mx')
     7580        atomData = data['Drawing']['Atoms']
     7581        generalData = data['General']
     7582        SGData = generalData['SGData']
     7583        SpnFlp = SGData.get('SpnFlp',[])
     7584        dlg = SymOpDialog(G2frame,SGData,False,True)
     7585        try:
     7586            if dlg.ShowModal() == wx.ID_OK:
     7587                Inv,Cent,Opr,Cell,New,Force = dlg.GetSelection()
     7588                Cell = np.array(Cell)
     7589                cent = SGData['SGCen'][Cent]
     7590                M,T = SGData['SGOps'][Opr]
     7591                for ind in indx:
     7592                    XYZ = np.array(atomData[ind][cx:cx+3])
     7593                    XYZ = np.inner(M,XYZ)+T
     7594                    if Inv and not SGData['SGFixed']:
     7595                        XYZ = -XYZ
     7596                    XYZ = XYZ+cent+Cell
     7597                    if Force:
     7598                        XYZ %= 1.       #G2spc.MoveToUnitCell(XYZ)
     7599                    if noDuplicate(XYZ,atomData):
     7600                        atom = copy.copy(atomData[ind])
     7601                        atom[cx:cx+3] = XYZ
     7602                        atomOp = atom[cs-1]
     7603                        OprNum = ((Opr+1)+100*Cent)*(1-2*Inv)
     7604                        newOp = str(OprNum)+'+'+ \
     7605                            str(int(Cell[0]))+','+str(int(Cell[1]))+','+str(int(Cell[2]))                           
     7606                        atom[cs-1] = G2spc.StringOpsProd(atomOp,newOp,SGData)
     7607                        if cmx:         #magnetic moment
     7608                            opNum = G2spc.GetOpNum(OprNum,SGData)
     7609                            mom = np.array(atom[cmx:cmx+3])
     7610                            if SGData['SGGray']:
     7611                                atom[cmx:cmx+3] = np.inner(mom,M)*nl.det(M)
     7612                            else:   
     7613                                atom[cmx:cmx+3] = np.inner(mom,M)*nl.det(M)*SpnFlp[opNum-1]
     7614                        if atom[cui] == 'A':
     7615                            Uij = atom[cuij:cuij+6]
     7616                            Uij = G2spc.U2Uij(np.inner(np.inner(M,G2spc.Uij2U(Uij)),M))
     7617                            atom[cuij:cuij+6] = Uij
     7618                        atomData.append(atom[:cuij+9])  #not SS stuff
     7619        finally:
     7620            dlg.Destroy()
     7621        UpdateDrawAtoms()
     7622        drawAtoms.ClearSelection()
     7623        G2plt.PlotStructure(G2frame,data)
    76007624           
    76017625    def AddSphere(event):
     7626        indx = getAtomSelections(drawAtoms)
     7627        if not indx: return
    76027628        generalData = data['General']
    76037629        Amat,Bmat = G2lat.cell2AB(generalData['Cell'][1:7])
     
    76147640        SpnFlp = SGData.get('SpnFlp',[])
    76157641        cellArray = G2lat.CellBlock(1)
    7616         indx = drawAtoms.GetSelectedRows()
    76177642        indx.sort()
    76187643        dlg = SphereEnclosure(G2frame,data['General'],data['Drawing'],indx)
     
    76707695           
    76717696    def TransformSymEquiv(event):
    7672         indx = drawAtoms.GetSelectedRows()
     7697        indx = getAtomSelections(drawAtoms)
     7698        if not indx: return
    76737699        indx.sort()
    7674         if indx:
    7675             atomData = data['Drawing']['Atoms']
    7676             colLabels = [drawAtoms.GetColLabelValue(c) for c in range(drawAtoms.GetNumberCols())]
    7677             cx,ct,cs,ci = data['Drawing']['atomPtrs']
    7678             cuij = ci+2
    7679             cmx = 0
    7680             if 'Mx' in colLabels:
    7681                 cmx = colLabels.index('Mx')
    7682             atomData = data['Drawing']['Atoms']
    7683             generalData = data['General']
    7684             SGData = generalData['SGData']
    7685             SpnFlp = SGData.get('SpnFlp',[])
    7686             dlg = SymOpDialog(G2frame,SGData,False,True)
    7687             try:
    7688                 if dlg.ShowModal() == wx.ID_OK:
    7689                     Inv,Cent,Opr,Cell,New,Force = dlg.GetSelection()
    7690                     Cell = np.array(Cell)
    7691                     cent = SGData['SGCen'][Cent]
    7692                     M,T = SGData['SGOps'][Opr]
    7693                     for ind in indx:
    7694                         XYZ = np.array(atomData[ind][cx:cx+3])
    7695                         XYZ = np.inner(M,XYZ)+T
    7696                         if Inv and not SGData['SGFixed']:
    7697                             XYZ = -XYZ
    7698                         XYZ = XYZ+cent+Cell
    7699                         if Force:
    7700                             XYZ,cell = G2spc.MoveToUnitCell(XYZ)
    7701                             Cell += cell
    7702                         atom = atomData[ind]
    7703                         atom[cx:cx+3] = XYZ
    7704                         OprNum = ((Opr+1)+100*Cent)*(1-2*Inv)
    7705                         if cmx:
    7706                             opNum = G2spc.GetOpNum(OprNum,SGData)
    7707                             mom = np.array(atom[cmx:cmx+3])
    7708                             atom[cmx:cmx+3] = np.inner(mom,M)*nl.det(M)*SpnFlp[opNum-1]
    7709                         atomOp = atom[cs-1]
    7710                         newOp = str(((Opr+1)+100*Cent)*(1-2*Inv))+'+'+ \
    7711                             str(int(Cell[0]))+','+str(int(Cell[1]))+','+str(int(Cell[2]))
    7712                         atom[cs-1] = G2spc.StringOpsProd(atomOp,newOp,SGData)
    7713                         if atom[ci] == 'A':
    7714                             Uij = atom[cuij:cuij+6]
    7715                             U = G2spc.Uij2U(Uij)
    7716                             U = np.inner(np.inner(M,U),M)
    7717                             Uij = G2spc.U2Uij(U)
    7718                             atom[cuij:cuij+6] = Uij
    7719                     data['Drawing']['Atoms'] = atomData
    7720             finally:
    7721                 dlg.Destroy()
    7722             UpdateDrawAtoms()
    7723             drawAtoms.ClearSelection()
    7724             G2plt.PlotStructure(G2frame,data)
    7725         else:
    7726             G2G.G2MessageBox(G2frame,'Select atoms first')
     7700        atomData = data['Drawing']['Atoms']
     7701        colLabels = [drawAtoms.GetColLabelValue(c) for c in range(drawAtoms.GetNumberCols())]
     7702        cx,ct,cs,ci = data['Drawing']['atomPtrs']
     7703        cuij = ci+2
     7704        cmx = 0
     7705        if 'Mx' in colLabels:
     7706            cmx = colLabels.index('Mx')
     7707        atomData = data['Drawing']['Atoms']
     7708        generalData = data['General']
     7709        SGData = generalData['SGData']
     7710        SpnFlp = SGData.get('SpnFlp',[])
     7711        dlg = SymOpDialog(G2frame,SGData,False,True)
     7712        try:
     7713            if dlg.ShowModal() == wx.ID_OK:
     7714                Inv,Cent,Opr,Cell,New,Force = dlg.GetSelection()
     7715                Cell = np.array(Cell)
     7716                cent = SGData['SGCen'][Cent]
     7717                M,T = SGData['SGOps'][Opr]
     7718                for ind in indx:
     7719                    XYZ = np.array(atomData[ind][cx:cx+3])
     7720                    XYZ = np.inner(M,XYZ)+T
     7721                    if Inv and not SGData['SGFixed']:
     7722                        XYZ = -XYZ
     7723                    XYZ = XYZ+cent+Cell
     7724                    if Force:
     7725                        XYZ,cell = G2spc.MoveToUnitCell(XYZ)
     7726                        Cell += cell
     7727                    atom = atomData[ind]
     7728                    atom[cx:cx+3] = XYZ
     7729                    OprNum = ((Opr+1)+100*Cent)*(1-2*Inv)
     7730                    if cmx:
     7731                        opNum = G2spc.GetOpNum(OprNum,SGData)
     7732                        mom = np.array(atom[cmx:cmx+3])
     7733                        atom[cmx:cmx+3] = np.inner(mom,M)*nl.det(M)*SpnFlp[opNum-1]
     7734                    atomOp = atom[cs-1]
     7735                    newOp = str(((Opr+1)+100*Cent)*(1-2*Inv))+'+'+ \
     7736                        str(int(Cell[0]))+','+str(int(Cell[1]))+','+str(int(Cell[2]))
     7737                    atom[cs-1] = G2spc.StringOpsProd(atomOp,newOp,SGData)
     7738                    if atom[ci] == 'A':
     7739                        Uij = atom[cuij:cuij+6]
     7740                        U = G2spc.Uij2U(Uij)
     7741                        U = np.inner(np.inner(M,U),M)
     7742                        Uij = G2spc.U2Uij(U)
     7743                        atom[cuij:cuij+6] = Uij
     7744                data['Drawing']['Atoms'] = atomData
     7745        finally:
     7746            dlg.Destroy()
     7747        UpdateDrawAtoms()
     7748        drawAtoms.ClearSelection()
     7749        G2plt.PlotStructure(G2frame,data)
    77277750           
    77287751    def FillCoordSphere(event):
     7752        indx = getAtomSelections(drawAtoms)
     7753        if not indx: return
    77297754        generalData = data['General']
    77307755        Amat,Bmat = G2lat.cell2AB(generalData['Cell'][1:7])
     
    77367761        except:
    77377762            pass           
    7738         indx = drawAtoms.GetSelectedRows()
    7739         if indx:
    7740             indx.sort()
    7741             atomData = data['Drawing']['Atoms']
    7742             numAtoms = len(atomData)
    7743             cx,ct,cs,ci = data['Drawing']['atomPtrs']
    7744             cij = ci+2
    7745             SGData = generalData['SGData']
    7746             cellArray = G2lat.CellBlock(1)
    7747             nind = len(indx)
    7748             pgbar = wx.ProgressDialog('Fill CN sphere for %d atoms'%nind,'Atoms done=',nind+1,
    7749                 style = wx.PD_ELAPSED_TIME|wx.PD_AUTO_HIDE|wx.PD_CAN_ABORT)
    7750             screenSize = wx.ClientDisplayRect()
    7751             Size = pgbar.GetSize()
    7752             if 50 < Size[0] < 500: # sanity check on size, since this fails w/Win & wx3.0
    7753                 pgbar.SetSize((int(Size[0]*1.2),Size[1])) # increase size a bit along x
    7754                 pgbar.SetPosition(wx.Point(screenSize[2]-Size[0]-305,screenSize[1]+5))
    7755             for Ind,ind in enumerate(indx):
    7756                 atomA = atomData[ind]
    7757                 xyzA = np.array(atomA[cx:cx+3])
    7758                 indA = atomTypes.index(atomA[ct])
    7759                 for atomB in atomData[:numAtoms]:
    7760                     indB = atomTypes.index(atomB[ct])
    7761                     sumR = radii[indA]+radii[indB]
    7762                     xyzB = np.array(atomB[cx:cx+3])
    7763                     for xyz in cellArray+xyzB:
    7764                         dist = np.sqrt(np.sum(np.inner(Amat,xyz-xyzA)**2))
    7765                         if 0 < dist <= data['Drawing']['radiusFactor']*sumR:
    7766                             if noDuplicate(xyz,atomData):
    7767                                 oprB = atomB[cs-1]
    7768                                 C = xyz-xyzB
    7769                                 newOp = '1+'+str(int(round(C[0])))+','+str(int(round(C[1])))+','+str(int(round(C[2])))
    7770                                 newAtom = atomB[:]
    7771                                 newAtom[cx:cx+3] = xyz
    7772                                 newAtom[cs-1] = G2spc.StringOpsProd(oprB,newOp,SGData)
    7773                                 atomData.append(newAtom[:cij+9])  #not SS stuff
    7774                 GoOn = pgbar.Update(Ind,newmsg='Atoms done=%d'%(Ind))
    7775                 if not GoOn[0]:
    7776                     break
    7777             pgbar.Destroy()   
     7763        indx.sort()
     7764        atomData = data['Drawing']['Atoms']
     7765        numAtoms = len(atomData)
     7766        cx,ct,cs,ci = data['Drawing']['atomPtrs']
     7767        cij = ci+2
     7768        SGData = generalData['SGData']
     7769        cellArray = G2lat.CellBlock(1)
     7770        nind = len(indx)
     7771        pgbar = wx.ProgressDialog('Fill CN sphere for %d atoms'%nind,'Atoms done=',nind+1,
     7772            style = wx.PD_ELAPSED_TIME|wx.PD_AUTO_HIDE|wx.PD_CAN_ABORT)
     7773        screenSize = wx.ClientDisplayRect()
     7774        Size = pgbar.GetSize()
     7775        if 50 < Size[0] < 500: # sanity check on size, since this fails w/Win & wx3.0
     7776            pgbar.SetSize((int(Size[0]*1.2),Size[1])) # increase size a bit along x
     7777            pgbar.SetPosition(wx.Point(screenSize[2]-Size[0]-305,screenSize[1]+5))
     7778        for Ind,ind in enumerate(indx):
     7779            atomA = atomData[ind]
     7780            xyzA = np.array(atomA[cx:cx+3])
     7781            indA = atomTypes.index(atomA[ct])
     7782            for atomB in atomData[:numAtoms]:
     7783                indB = atomTypes.index(atomB[ct])
     7784                sumR = radii[indA]+radii[indB]
     7785                xyzB = np.array(atomB[cx:cx+3])
     7786                for xyz in cellArray+xyzB:
     7787                    dist = np.sqrt(np.sum(np.inner(Amat,xyz-xyzA)**2))
     7788                    if 0 < dist <= data['Drawing']['radiusFactor']*sumR:
     7789                        if noDuplicate(xyz,atomData):
     7790                            oprB = atomB[cs-1]
     7791                            C = xyz-xyzB
     7792                            newOp = '1+'+str(int(round(C[0])))+','+str(int(round(C[1])))+','+str(int(round(C[2])))
     7793                            newAtom = atomB[:]
     7794                            newAtom[cx:cx+3] = xyz
     7795                            newAtom[cs-1] = G2spc.StringOpsProd(oprB,newOp,SGData)
     7796                            atomData.append(newAtom[:cij+9])  #not SS stuff
     7797            GoOn = pgbar.Update(Ind,newmsg='Atoms done=%d'%(Ind))
     7798            if not GoOn[0]:
     7799                break
     7800        pgbar.Destroy()   
     7801        data['Drawing']['Atoms'] = atomData
     7802        UpdateDrawAtoms()
     7803        drawAtoms.ClearSelection()
     7804        G2plt.PlotStructure(G2frame,data)
     7805           
     7806    def FillUnitCell(event):
     7807        indx = getAtomSelections(drawAtoms)
     7808        if not indx: return
     7809        indx.sort()
     7810        atomData = data['Drawing']['Atoms']
     7811        colLabels = [drawAtoms.GetColLabelValue(c) for c in range(drawAtoms.GetNumberCols())]
     7812        cx,ct,cs,ci = data['Drawing']['atomPtrs']
     7813        cmx = 0
     7814        if 'Mx' in colLabels:
     7815            cmx = colLabels.index('Mx')
     7816        cuij = cs+5
     7817        generalData = data['General']
     7818        SGData = generalData['SGData']
     7819        SpnFlp = SGData.get('SpnFlp',[])
     7820        nind = len(indx)
     7821        pgbar = wx.ProgressDialog('Fill unit cell for %d atoms'%nind,'Atoms done=',nind+1,
     7822            style = wx.PD_ELAPSED_TIME|wx.PD_AUTO_HIDE|wx.PD_CAN_ABORT)
     7823        screenSize = wx.ClientDisplayRect()
     7824        Size = pgbar.GetSize()
     7825        if 50 < Size[0] < 500: # sanity check on size, since this fails w/Win & wx3.0
     7826            pgbar.SetSize((int(Size[0]*1.2),Size[1])) # increase size a bit along x
     7827            pgbar.SetPosition(wx.Point(screenSize[2]-Size[0]-305,screenSize[1]+5))
     7828        for Ind,ind in enumerate(indx):
     7829            atom = atomData[ind]
     7830            XYZ = np.array(atom[cx:cx+3])
     7831            Uij = atom[cuij:cuij+6]
     7832            result = G2spc.GenAtom(XYZ,SGData,False,Uij,True)
     7833            for item in result:
     7834                atom = copy.copy(atomData[ind])
     7835                atom[cx:cx+3] = item[0]
     7836                if cmx:
     7837                    Opr = abs(item[2])%100
     7838                    M = SGData['SGOps'][Opr-1][0]
     7839                    opNum = G2spc.GetOpNum(item[2],SGData)
     7840                    mom = np.array(atom[cmx:cmx+3])
     7841                    if SGData['SGGray']:
     7842                        atom[cmx:cmx+3] = np.inner(mom,M)*nl.det(M)
     7843                    else:   
     7844                        atom[cmx:cmx+3] = np.inner(mom,M)*nl.det(M)*SpnFlp[opNum-1]
     7845                atom[cs-1] = str(item[2])+'+' \
     7846                    +str(item[3][0])+','+str(item[3][1])+','+str(item[3][2])
     7847                atom[cuij:cuij+6] = item[1]
     7848                Opp = G2spc.Opposite(item[0])
     7849                for key in Opp:
     7850                    if noDuplicate(Opp[key],atomData):
     7851                        unit = item[3]+np.array(eval(key))*1.
     7852                        cell = '%d+%d,%d,%d'%(item[2],unit[0],unit[1],unit[2])
     7853                        atom[cx:cx+3] = Opp[key]
     7854                        atom[cs-1] = cell
     7855                        atomData.append(atom[:cuij+9])  #not SS stuff
    77787856            data['Drawing']['Atoms'] = atomData
    7779             UpdateDrawAtoms()
    7780             drawAtoms.ClearSelection()
    7781             G2plt.PlotStructure(G2frame,data)
    7782         else:
    7783             G2G.G2MessageBox(G2frame,'Select atoms first')
    7784            
    7785     def FillUnitCell(event):
    7786         indx = drawAtoms.GetSelectedRows()
     7857            GoOn = pgbar.Update(Ind,newmsg='Atoms done=%d'%(Ind))
     7858            if not GoOn[0]:
     7859                break
     7860        pgbar.Destroy()   
     7861        UpdateDrawAtoms()
     7862        drawAtoms.ClearSelection()
     7863        G2plt.PlotStructure(G2frame,data)
     7864           
     7865    def DrawAtomsDelete(event):   
     7866        indx = getAtomSelections(drawAtoms)
     7867        if not indx: return
    77877868        indx.sort()
    7788         if indx:
    7789             atomData = data['Drawing']['Atoms']
    7790             colLabels = [drawAtoms.GetColLabelValue(c) for c in range(drawAtoms.GetNumberCols())]
    7791             cx,ct,cs,ci = data['Drawing']['atomPtrs']
    7792             cmx = 0
    7793             if 'Mx' in colLabels:
    7794                 cmx = colLabels.index('Mx')
    7795             cuij = cs+5
    7796             generalData = data['General']
    7797             SGData = generalData['SGData']
    7798             SpnFlp = SGData.get('SpnFlp',[])
    7799             nind = len(indx)
    7800             pgbar = wx.ProgressDialog('Fill unit cell for %d atoms'%nind,'Atoms done=',nind+1,
    7801                 style = wx.PD_ELAPSED_TIME|wx.PD_AUTO_HIDE|wx.PD_CAN_ABORT)
    7802             screenSize = wx.ClientDisplayRect()
    7803             Size = pgbar.GetSize()
    7804             if 50 < Size[0] < 500: # sanity check on size, since this fails w/Win & wx3.0
    7805                 pgbar.SetSize((int(Size[0]*1.2),Size[1])) # increase size a bit along x
    7806                 pgbar.SetPosition(wx.Point(screenSize[2]-Size[0]-305,screenSize[1]+5))
    7807             for Ind,ind in enumerate(indx):
    7808                 atom = atomData[ind]
    7809                 XYZ = np.array(atom[cx:cx+3])
    7810                 Uij = atom[cuij:cuij+6]
    7811                 result = G2spc.GenAtom(XYZ,SGData,False,Uij,True)
    7812                 for item in result:
    7813                     atom = copy.copy(atomData[ind])
    7814                     atom[cx:cx+3] = item[0]
    7815                     if cmx:
    7816                         Opr = abs(item[2])%100
    7817                         M = SGData['SGOps'][Opr-1][0]
    7818                         opNum = G2spc.GetOpNum(item[2],SGData)
    7819                         mom = np.array(atom[cmx:cmx+3])
    7820                         if SGData['SGGray']:
    7821                             atom[cmx:cmx+3] = np.inner(mom,M)*nl.det(M)
    7822                         else:   
    7823                             atom[cmx:cmx+3] = np.inner(mom,M)*nl.det(M)*SpnFlp[opNum-1]
    7824                     atom[cs-1] = str(item[2])+'+' \
    7825                         +str(item[3][0])+','+str(item[3][1])+','+str(item[3][2])
    7826                     atom[cuij:cuij+6] = item[1]
    7827                     Opp = G2spc.Opposite(item[0])
    7828                     for key in Opp:
    7829                         if noDuplicate(Opp[key],atomData):
    7830                             unit = item[3]+np.array(eval(key))*1.
    7831                             cell = '%d+%d,%d,%d'%(item[2],unit[0],unit[1],unit[2])
    7832                             atom[cx:cx+3] = Opp[key]
    7833                             atom[cs-1] = cell
    7834                             atomData.append(atom[:cuij+9])  #not SS stuff
    7835                 data['Drawing']['Atoms'] = atomData
    7836                 GoOn = pgbar.Update(Ind,newmsg='Atoms done=%d'%(Ind))
    7837                 if not GoOn[0]:
    7838                     break
    7839             pgbar.Destroy()   
    7840             UpdateDrawAtoms()
    7841             drawAtoms.ClearSelection()
    7842             G2plt.PlotStructure(G2frame,data)
    7843         else:
    7844             G2G.G2MessageBox(G2frame,'Select atoms first')
    7845            
    7846     def DrawAtomsDelete(event):   
    7847         indx = drawAtoms.GetSelectedRows()
    7848         indx.sort()
    7849         if indx:
    7850             atomData = data['Drawing']['Atoms']
    7851             indx.reverse()
    7852             for ind in indx:
    7853                 del atomData[ind]
    7854             UpdateDrawAtoms()
    7855             drawAtoms.ClearSelection()
    7856             G2plt.PlotStructure(G2frame,data)
    7857         else:
    7858             G2G.G2MessageBox(G2frame,'Select atoms first')
     7869        atomData = data['Drawing']['Atoms']
     7870        indx.reverse()
     7871        for ind in indx:
     7872            del atomData[ind]
     7873        UpdateDrawAtoms()
     7874        drawAtoms.ClearSelection()
     7875        G2plt.PlotStructure(G2frame,data)
    78597876        event.StopPropagation()
    78607877       
     
    78937910               
    78947911    def OnDrawPlane(event):
    7895         indx = drawAtoms.GetSelectedRows()
     7912        indx = getAtomSelections(drawAtoms)
    78967913        if len(indx) < 4:
    78977914            G2G.G2MessageBox(G2frame,'Select four or more atoms first')
     
    79167933    def OnDrawDistVP(event):
    79177934        # distance to view point
    7918         indx = drawAtoms.GetSelectedRows()
    7919         if not indx:
    7920             G2G.G2MessageBox(G2frame,'Select atoms first')
    7921             print ('***** ERROR - no atoms selected')
    7922             return
     7935        indx = getAtomSelections(drawAtoms,'distance calc')
     7936        if not indx: return
    79237937        generalData = data['General']
    79247938        Amat,Bmat = G2lat.cell2AB(generalData['Cell'][1:7])           
     
    79387952   
    79397953    def OnDrawDAT(event):
    7940         #distance, angle, torsion
    7941         indx = drawAtoms.GetSelectedRows()
     7954        #compute distance, angle, or torsion depending on number of selections
     7955        indx = getAtomSelections(drawAtoms)
    79427956        if len(indx) not in [2,3,4]:
    79437957            G2G.G2MessageBox(G2frame,'Select 2, 3 or 4 atoms first')
  • trunk/GSASIIpwdGUI.py

    r4416 r4433  
    47324732                    if General.get('Modulated',False):
    47334733                        Super = 1
    4734                     Histograms = G2frame.GPXtree.GetItemPyData(phaseId)['Histograms']
    4735                     histName = G2frame.GPXtree.GetItemText(G2frame.PatternId)
    4736                     histData = Histograms[histName]
    4737                     muStrData = histData['Mustrain']
    4738                     sizeData = histData['Size']
     4734                    try:
     4735                        Histograms = G2frame.GPXtree.GetItemPyData(phaseId)['Histograms']
     4736                        histName = G2frame.GPXtree.GetItemText(G2frame.PatternId)
     4737                        histData = Histograms[histName]
     4738                        muStrData = histData['Mustrain']
     4739                        sizeData = histData['Size']
     4740                    except:
     4741                        return
    47394742        rowLabels = []
    47404743        if HKLF:
     
    48274830        if G2frame.refTable[phaseName].GetTable() is None:
    48284831            PeakTable = MakeReflectionTable(phaseName)
     4832            if not PeakTable: return
    48294833            G2frame.refTable[phaseName].SetTable(PeakTable, True)
    48304834            G2frame.refTable[phaseName].EnableEditing(False)
  • trunk/exports/G2export_CIF.py

    r4411 r4433  
    13381338            # compute maximum intensity reflection
    13391339            Imax = 0
     1340            phaselist = []
    13401341            for phasenam in histblk['Reflection Lists']:
    1341                 scale = self.Phases[phasenam]['Histograms'][histlbl]['Scale'][0]
     1342                try:
     1343                    scale = self.Phases[phasenam]['Histograms'][histlbl]['Scale'][0]
     1344                except KeyError: # reflection table from removed phase?
     1345                    continue
     1346                phaselist.append(phasenam)
    13421347                refList = np.asarray(histblk['Reflection Lists'][phasenam]['RefList'])
    13431348                I100 = scale*refList.T[8]*refList.T[11]
     
    13481353
    13491354            WriteCIFitem(self.fp, 'loop_')
    1350             if len(histblk['Reflection Lists'].keys()) > 1:
     1355            if len(phaselist) > 1:
    13511356                WriteCIFitem(self.fp, '   _pd_refln_phase_id')
    13521357            WriteCIFitem(self.fp, '   ' + refprx + 'index_h' +
     
    13651370            dmax = None
    13661371            dmin = None
    1367             for phasenam in histblk['Reflection Lists']:
     1372            for phasenam in phaselist:
    13681373                scale = self.Phases[phasenam]['Histograms'][histlbl]['Scale'][0]
    13691374                phaseid = self.Phases[phasenam]['pId']
     
    13801385                    if dmin is None:
    13811386                         dmax = dmin = ref[4]
    1382                     if len(histblk['Reflection Lists'].keys()) > 1:
     1387                    if len(phaselist) > 1:
    13831388                        s = PutInCol(phaseid,2)
    13841389                    else:
     
    13981403                    WriteCIFitem(self.fp, "  "+s)
    13991404
    1400             WriteReflStat(refcount,hklmin,hklmax,dmin,dmax,len(histblk['Reflection Lists']))
     1405            WriteReflStat(refcount,hklmin,hklmax,dmin,dmax,len(phaselist))
    14011406            WriteCIFitem(self.fp, '\n# POWDER DATA TABLE')
    14021407            # is data fixed step? If the step varies by <0.01% treat as fixed step
Note: See TracChangeset for help on using the changeset viewer.