Changeset 4479


Ignore:
Timestamp:
Jun 10, 2020 9:10:31 PM (3 years ago)
Author:
toby
Message:

changes to unique map peaks & plotting after selection

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/GSASIImath.py

    r4431 r4479  
    39343934               
    39353935def PeaksUnique(data,Ind):
    3936     '''Finds the symmetry unique set of peaks from those selected. Works on the
    3937     contents of data['Map Peaks'].
     3936    '''Finds the symmetry unique set of peaks from those selected. Selects
     3937    the one closest to the center of the unit cell.
     3938    Works on the contents of data['Map Peaks']. Called from OnPeaksUnique in
     3939    GSASIIphsGUI.py,
    39383940
    39393941    :param data: the phase data structure
    39403942    :param list Ind: list of selected peak indices
     3943
    39413944    :returns: the list of symmetry unique peaks from among those given in Ind
    3942 
    39433945    '''       
    39443946#    XYZE = np.array([[equiv[0] for equiv in G2spc.GenAtom(xyz[1:4],SGData,Move=True)] for xyz in mapPeaks]) #keep this!!
     
    39533955    SGData = generalData['SGData']
    39543956    mapPeaks = data['Map Peaks']
    3955     Indx = {}
    3956     XYZ = {}
    3957     for ind in Ind:
    3958         XYZ[ind] = np.array(mapPeaks[ind][1:4])
    3959         Indx[ind] = True
     3957    XYZ = {ind:np.array(mapPeaks[ind][1:4]) for ind in Ind}
     3958    Indx = [True for ind in Ind]
     3959    Unique = []
     3960    # scan through peaks, finding all peaks equivalent to peak ind
    39603961    for ind in Ind:
    39613962        if Indx[ind]:
    39623963            xyz = XYZ[ind]
     3964            dups = []
    39633965            for jnd in Ind:
    3964                 if ind != jnd and Indx[jnd]:                       
     3966                # only consider peaks we have not looked at before
     3967                # and were not already found to be equivalent
     3968                if jnd > ind and Indx[jnd]:                       
    39653969                    Equiv = G2spc.GenAtom(XYZ[jnd],SGData,Move=True)
    39663970                    xyzs = np.array([equiv[0] for equiv in Equiv])
    3967                     Indx[jnd] = noDuplicate(xyz,xyzs,Amat)
    3968     Ind = []
    3969     for ind in Indx:
    3970         if Indx[ind]:
    3971             Ind.append(ind)
    3972     return Ind
     3971                    if not noDuplicate(xyz,xyzs,Amat):
     3972                        Indx[jnd] = False
     3973                        dups.append(jnd)
     3974            # select the unique peak closest to cell center
     3975            cntr = mapPeaks[ind][-1]
     3976            icntr = ind
     3977            for jnd in dups:
     3978                if mapPeaks[jnd][-1] < cntr:
     3979                    cntr = mapPeaks[jnd][-1]
     3980                    icntr = jnd
     3981            Unique.append(icntr)
     3982    return Unique
    39733983
    39743984################################################################################
  • trunk/GSASIIphsGUI.py

    r4476 r4479  
    14031403            'vdwScale':0.67,'ellipseProb':50,'sizeH':0.50,'unitCellBox':True,
    14041404            'showABC':True,'selectedAtoms':[],'Atoms':[],'oldxy':[],'magMult':1.0,
    1405             'bondList':{},'viewDir':[1,0,0],'Plane':[[0,0,1],False,False,0.0,[255,255,0]]}
     1405            'bondList':{},'viewDir':[1,0,0],'Plane':[[0,0,1],False,False,0.0,[255,255,0]],
     1406            'peakMoveView':True,'PeakDistRadius':0.0,
     1407            'atomsExpandRadius':5.,'atomsDistRadius':2.5,
     1408        }
    14061409    for key in defaultDrawing:
    14071410        if key not in drawingData: drawingData[key] = defaultDrawing[key]
     
    87278730            drawOptions.GetSizer().Clear(True)
    87288731        mainSizer = wx.BoxSizer(wx.VERTICAL)
    8729         mainSizer.Add((5,5),0)
    8730         mainSizer.Add(wx.StaticText(drawOptions,-1,' Drawing controls:'),0,WACV)
    8731         mainSizer.Add((5,5),0)       
     8732        #mainSizer.Add(wx.StaticText(drawOptions,-1,' Drawing controls'),0,
     8733        #                  wx.ALL|wx.CENTER)
     8734        #G2G.HorizontalLine(mainSizer,drawOptions)
    87328735        mainSizer.Add(SlopSizer(),0)
    8733         mainSizer.Add((5,5),0)
     8736        G2G.HorizontalLine(mainSizer,drawOptions)
    87348737        mainSizer.Add(ShowSizer(),0,)
    8735         mainSizer.Add((5,5),0)
     8738        G2G.HorizontalLine(mainSizer,drawOptions)
    87368739        mainSizer.Add(RadSizer(),0,)
    8737         mainSizer.Add((5,5),0)
     8740        G2G.HorizontalLine(mainSizer,drawOptions)
    87388741        mainSizer.Add(PlaneSizer(),0,)
     8742        G2G.HorizontalLine(mainSizer,drawOptions)
     8743        mainSizer.Add(wx.StaticText(drawOptions,wx.ID_ANY,
     8744                                        'On map peak selection:'),0,WACV)
     8745        mainSizer.Add(G2G.G2CheckBox(drawOptions,'Move view point',
     8746                                         drawingData,'peakMoveView'))
     8747        mapSizer = wx.FlexGridSizer(0,3,5,5)
     8748        mapSizer.Add(wx.StaticText(drawOptions,wx.ID_ANY,'Show Map points within:'),0,WACV)
     8749        mapSizer.Add(G2G.ValidatedTxtCtrl(drawOptions,drawingData,'PeakDistRadius',
     8750                            min=0.0,max=5.0,nDig=(10,1),size=(50,-1)))
     8751        mapSizer.Add(wx.StaticText(drawOptions,wx.ID_ANY,u"\u212B"),0,WACV)
     8752        mapSizer.Add(wx.StaticText(drawOptions,wx.ID_ANY,'Show atoms within:'),0,WACV)
     8753        mapSizer.Add(G2G.ValidatedTxtCtrl(drawOptions,drawingData,'atomsExpandRadius',
     8754                            min=0.0,max=15.0,nDig=(10,1),size=(50,-1)))
     8755        mapSizer.Add(wx.StaticText(drawOptions,wx.ID_ANY,u"\u212B"),0,WACV)
     8756        mapSizer.Add(wx.StaticText(drawOptions,wx.ID_ANY,'Label distance to atoms within:'),0,WACV)
     8757        mapSizer.Add(G2G.ValidatedTxtCtrl(drawOptions,drawingData,'atomsDistRadius',
     8758                            min=0.0,max=15.0,nDig=(10,1),size=(50,-1)))
     8759        mapSizer.Add(wx.StaticText(drawOptions,wx.ID_ANY,u"\u212B"),0,WACV)
     8760        mainSizer.Add(mapSizer)
    87398761        SetPhaseWindow(drawOptions,mainSizer)
    87408762
     
    1147011492            elif c < 0:                   #only row clicks
    1147111493                if event.ControlDown():                   
    11472                     if r in MapPeaks.GetSelectedRows():
     11494                    if r in getAtomSelections(MapPeaks):
    1147311495                        MapPeaks.DeselectRow(r)
    1147411496                    else:
    1147511497                        MapPeaks.SelectRow(r,True)
    1147611498                elif event.ShiftDown():
    11477                     indxs = MapPeaks.GetSelectedRows()
     11499                    indxs = getAtomSelections(MapPeaks)
    1147811500                    MapPeaks.ClearSelection()
    1147911501                    ibeg = 0
     
    1149811520            G2plt.PlotStructure(G2frame,data)                   
    1149911521           
     11522        # beginning of FillMapPeaksGrid()
     11523        #import imp   # debug code
     11524        #imp.reload(G2plt) # debug code
    1150011525        G2frame.GetStatusBar().SetStatusText('',1)
    1150111526        if 'Map Peaks' in data:
     
    1152011545            mapPeaks = np.array(data['Map Peaks'])
    1152111546            peakMax = np.amax(mapPeaks.T[0])
    11522             Ind = MapPeaks.GetSelectedRows()
     11547            Ind = getAtomSelections(MapPeaks)
    1152311548            for ind in Ind:
    1152411549                mag,x,y,z = mapPeaks[ind][:4]
     
    1155611581        if 'Map Peaks' in data:
    1155711582            mapPeaks = data['Map Peaks']
    11558             Ind = MapPeaks.GetSelectedRows()
     11583            Ind = getAtomSelections(MapPeaks)
    1155911584            Ind.sort()
    1156011585            Ind.reverse()
     
    1158111606    def OnPeaksEquiv(event):
    1158211607        if 'Map Peaks' in data:
    11583             Ind = MapPeaks.GetSelectedRows()
     11608            Ind = getAtomSelections(MapPeaks)
    1158411609            if Ind:
    1158511610                wx.BeginBusyCursor()
     
    1160911634        if 'Map Peaks' in data:
    1161011635            mapPeaks = data['Map Peaks']
    11611             Ind = MapPeaks.GetSelectedRows()
     11636            Ind = getAtomSelections(MapPeaks)
    1161211637            if Ind:
    1161311638                wx.BeginBusyCursor()
     
    1161511640                    Ind = G2mth.PeaksUnique(data,Ind)
    1161611641                    print (' No. unique peaks: %d Unique peak fraction: %.3f'%(len(Ind),float(len(Ind))/len(mapPeaks)))
     11642                    tbl = MapPeaks.GetTable().data
     11643                    tbl[:] = [t for i,t in enumerate(tbl) if i in Ind] + [
     11644                        t for i,t in enumerate(tbl) if i not in Ind]         
    1161711645                    for r in range(MapPeaks.GetNumberRows()):
    11618                         if r in Ind:
     11646                        if r < len(Ind):
    1161911647                            MapPeaks.SelectRow(r,addToSelected=True)
    1162011648                        else:
     
    1162211650                finally:
    1162311651                    wx.EndBusyCursor()
     11652                MapPeaks.ForceRefresh()
    1162411653                G2plt.PlotStructure(G2frame,data)
    1162511654               
    1162611655    def OnPeaksViewPoint(event):
    1162711656        # set view point
    11628         indx = MapPeaks.GetSelectedRows()
     11657        indx = getAtomSelections(MapPeaks)
    1162911658        if not indx:
    1163011659            G2frame.ErrorDialog('Set viewpoint','No peaks selected')
     
    1163711666    def OnPeaksDistVP(event):
    1163811667        # distance to view point
    11639         indx = MapPeaks.GetSelectedRows()
     11668        indx = getAtomSelections(MapPeaks)
    1164011669        if not indx:
    1164111670            G2frame.ErrorDialog('Peak distance','No peaks selected')
     
    1165811687    def OnPeaksDA(event):
    1165911688        #distance, angle
    11660         indx = MapPeaks.GetSelectedRows()
     11689        indx = getAtomSelections(MapPeaks)
    1166111690        if len(indx) not in [2,3]:
    1166211691            G2frame.ErrorDialog('Peak distance/angle','Wrong number of atoms for distance or angle calculation')
  • trunk/GSASIIplot.py

    r4470 r4479  
    89288928        Zclip = drawingData['Zclip']*cPos/200.
    89298929        Q = drawingData['Quaternion']
     8930        # Move view point on selection of a single peak, if enabled
     8931        if pageName == 'Map peaks' and len(Ind) == 1 and drawingData['peakMoveView']:
     8932            ind = Ind[0]
     8933            mag,x,y,z = mapPeaks[:,:4][ind]
     8934            drawingData['viewPoint'][0][:] = [x,y,z]
    89308935        Tx,Ty,Tz = drawingData['viewPoint'][0]
    89318936        cx,ct,cs,ci = drawingData['atomPtrs']
     
    90789083        if not FourD and len(rhoXYZ):       #no green dot map for 4D - it's wrong!
    90799084            RenderMap(rho,rhoXYZ,indx,Rok)
    9080         if len(mapPeaks):
     9085        if len(Ind) == 1 and pageName == 'Map peaks':
     9086            # one peak has been selected, show as selected by draw options
     9087            PeakDistRadius = drawingData['PeakDistRadius']
     9088            atomsExpandRadius = drawingData['atomsExpandRadius']
     9089            atomsdistRadius = drawingData['atomsDistRadius']
     9090            ind = Ind[0]
     9091            mag,x,y,z = mapPeaks[:,:4][ind]
     9092            RenderMapPeak(x,y,z,Gr,1.0)
     9093            # distances to other peaks within PeakDistRadius A
     9094            if PeakDistRadius > 0:
     9095                XYZ = mapPeaks.T[1:4].T
     9096                Dx = XYZ-(x,y,z)
     9097                dist = np.sqrt(np.sum(np.inner(Dx,Amat)**2,axis=1))
     9098                for i in ma.nonzero(ma.masked_greater(dist,PeakDistRadius))[0]:
     9099                    lbl = '{:.2f}'.format(dist[i])
     9100                    RenderLines(x,y,z,[Dx[i]],Gr)
     9101                    lx,ly,lz = (x,y,z)+(Dx[i]/2)
     9102                    RenderLabel(lx,ly,lz,lbl,radius,wxGreen,matRot)
     9103                    [mag,x1,y1,z1] = mapPeaks[:,:4][i]
     9104                    if mag > 0.:
     9105                        RenderMapPeak(x1,y1,z1,Wt,mag/peakMax)
     9106                    else:
     9107                        RenderMapPeak(x1,y1,z1,Or,-2*mag/peakMax)
     9108            # find and display atoms within atomsExpandRadius A
     9109            if atomsExpandRadius > 0:
     9110                xyzA = np.array((x,y,z))
     9111                cx,ct,cs,ci = G2phG.getAtomPtrs(data)     
     9112                cellArray = G2lat.CellBlock(1)
     9113                radDict = dict(zip(*G2phG.getAtomRadii(data)))
     9114                Names = []
     9115                Atoms = []
     9116                Radii = []
     9117                Color = []
     9118                for atomB in data['Atoms']:
     9119                    xyzB = np.array(atomB[cx:cx+3])
     9120                    color = np.array(generalData['Color'][generalData['AtomTypes'].index(atomB[ct])])/255.
     9121                    result = G2spc.GenAtom(xyzB,SGData,False,6*[0.],True)
     9122                    for item in result:
     9123                        for xyz in cellArray+np.array(item[0]):
     9124                            dist = np.sqrt(np.sum(np.inner(Amat,xyz-xyzA)**2))
     9125                            if 0 < dist <= max(atomsdistRadius,atomsExpandRadius):
     9126                                ax,ay,az = xyz
     9127                                RenderSphere(ax,ay,az,radius,color)
     9128                                Atoms.append(xyz)
     9129                                Radii.append(radDict[atomB[ct]])
     9130                                Names.append(atomB[0])
     9131                                Color.append(color)
     9132                            if dist < atomsdistRadius:
     9133                                RenderLines(x,y,z,[xyz-xyzA],Gr)
     9134                                lx,ly,lz = (xyzA+xyz)/2
     9135                                lbl = '{:.2f}'.format(dist)
     9136                                RenderLabel(lx,ly,lz,lbl,radius,wxGreen,matRot)
     9137                                ax,ay,az = xyz
     9138                                RenderLabel(ax,ay,az,'  '+atomB[0],radius,wxGreen,matRot)
     9139                # find bonds
     9140                bondData = [[] for i in range(len(Atoms))]
     9141                Atoms = np.array(Atoms)
     9142                Radii = np.array(Radii)
     9143                for i,atom in enumerate(Atoms):
     9144                    Dx = Atoms-atom
     9145                    sumR = Radii + Radii[i]
     9146                    dist = ma.masked_less(np.sqrt(np.sum(np.inner(Amat,Dx)**2,axis=0)),0.5)
     9147                    IndB = ma.nonzero(ma.masked_greater(dist-data['Drawing']['radiusFactor']*sumR,0.))                 #get indices of bonded atoms
     9148                    for j in IndB[0]:
     9149                        bondData[i].append(Dx[j]*Radii[i]/sumR[j])
     9150                        bondData[j].append(-Dx[j]*Radii[j]/sumR[j])
     9151                # draw bonds
     9152                bondR = drawingData['bondRadius']
     9153                for i,xyz in enumerate(Atoms):
     9154                    ax,ay,az = xyz
     9155                    RenderBonds(ax,ay,az,bondData[i],bondR,Color[i])
     9156        elif len(mapPeaks):
    90819157            XYZ = mapPeaks.T[1:4].T
    90829158            mapBonds = FindPeaksBonds(XYZ)
Note: See TracChangeset for help on using the changeset viewer.