Changeset 4499 for trunk/GSASIIplot.py


Ignore:
Timestamp:
Jun 19, 2020 4:19:13 PM (3 years ago)
Author:
toby
Message:

Add sphere of atoms arround view point; show distances to peaks and atoms around view point

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/GSASIIplot.py

    r4495 r4499  
    89118911        GL.glShadeModel(GL.GL_SMOOTH)
    89128912                           
     8913    def distances2Peaks(x,y,z,PeakDistRadius,mapPeaks,peakMax,radius,Amat,matRot):
     8914        ''' show distances to other peaks within PeakDistRadius A
     8915        '''
     8916        XYZ = mapPeaks.T[1:4].T
     8917        Dx = XYZ-(x,y,z)
     8918        dist = np.sqrt(np.sum(np.inner(Dx,Amat)**2,axis=1))
     8919        for i in ma.nonzero(ma.masked_greater(dist,PeakDistRadius))[0]:
     8920            lbl = '{:.2f}'.format(dist[i])
     8921            RenderLines(x,y,z,[Dx[i]],Gr)
     8922            lx,ly,lz = (x,y,z)+(Dx[i]/2)
     8923            RenderLabel(lx,ly,lz,lbl,radius,wxGreen,matRot)
     8924            [mag,x1,y1,z1] = mapPeaks[:,:4][i]
     8925            lbl = '{:.2f}'.format(mag)
     8926            if mag > 0.:
     8927                RenderMapPeak(x1,y1,z1,Wt,mag/peakMax)
     8928                RenderLabel(x1,y1,z1,lbl,radius,wx.Colour(Wt),matRot)
     8929            else:
     8930                RenderMapPeak(x1,y1,z1,Or,-2*mag/peakMax)
     8931                RenderLabel(x1,y1,z1,lbl,radius,wx.Colour(Or),matRot)
     8932
     8933    def distances2Atoms(x,y,z,atomsExpandRadius,atomsdistRadius,Amat,matRot):
     8934        # find and display atoms within atomsExpandRadius A
     8935        vdwScale = drawingData['vdwScale']
     8936        ballScale = drawingData['ballScale']
     8937        xyzA = np.array((x,y,z))
     8938        cx,ct,cs,ci = G2phG.getAtomPtrs(data)     
     8939        cellArray = G2lat.CellBlock(1)
     8940        radDict = dict(zip(*G2phG.getAtomRadii(data)))
     8941        Names = []
     8942        Atoms = []
     8943        Radii = []
     8944        Color = []
     8945        for atomB in data['Atoms']:
     8946            atNum = generalData['AtomTypes'].index(atomB[ct])
     8947            if 'vdW' in atomB[cs]:
     8948                radius = vdwScale*vdWRadii[atNum]
     8949            elif 'H' == atomB[ct]:
     8950                radius = ballScale*drawingData['sizeH']
     8951            else:
     8952                radius = ballScale*BondRadii[atNum]
     8953            xyzB = np.array(atomB[cx:cx+3])
     8954            color = np.array(generalData['Color'][generalData['AtomTypes'].index(atomB[ct])])/255.
     8955            result = G2spc.GenAtom(xyzB,SGData,False,6*[0.],True)
     8956            for item in result:
     8957                for xyz in cellArray+np.array(item[0]):
     8958                    dist = np.sqrt(np.sum(np.inner(Amat,xyz-xyzA)**2))
     8959                    if 0 < dist <= max(atomsdistRadius,atomsExpandRadius):
     8960                        ax,ay,az = xyz
     8961                        RenderSphere(ax,ay,az,radius,color)
     8962                        Atoms.append(xyz)
     8963                        Radii.append(radDict[atomB[ct]])
     8964                        Names.append(atomB[0])
     8965                        Color.append(color)
     8966                    if dist < atomsdistRadius:
     8967                        RenderLines(x,y,z,[xyz-xyzA],Gr)
     8968                        lx,ly,lz = (xyzA+xyz)/2
     8969                        lbl = '{:.2f}'.format(dist)
     8970                        RenderLabel(lx,ly,lz,lbl,radius,wxGreen,matRot)
     8971                        ax,ay,az = xyz
     8972                        RenderLabel(ax,ay,az,'  '+atomB[0],radius,wxGreen,matRot)
     8973        # find bonds
     8974        bondData = [[] for i in range(len(Atoms))]
     8975        Atoms = np.array(Atoms)
     8976        Radii = np.array(Radii)
     8977        for i,atom in enumerate(Atoms):
     8978            Dx = Atoms-atom
     8979            sumR = Radii + Radii[i]
     8980            dist = ma.masked_less(np.sqrt(np.sum(np.inner(Amat,Dx)**2,axis=0)),0.5)
     8981            IndB = ma.nonzero(ma.masked_greater(dist-data['Drawing']['radiusFactor']*sumR,0.))                 #get indices of bonded atoms
     8982            for j in IndB[0]:
     8983                bondData[i].append(Dx[j]*Radii[i]/sumR[j])
     8984                bondData[j].append(-Dx[j]*Radii[j]/sumR[j])
     8985        # draw bonds
     8986        bondR = drawingData['bondRadius']
     8987        for i,xyz in enumerate(Atoms):
     8988            ax,ay,az = xyz
     8989            RenderBonds(ax,ay,az,bondData[i],bondR,Color[i])
     8990               
    89138991    def Draw(caller='',Fade=[]):
    89148992        vdWRadii = generalData['vdWRadii']
     
    91149192        if not FourD and len(rhoXYZ) and drawingData['showMap']:       #no green dot map for 4D - it's wrong!
    91159193            RenderMap(rho,rhoXYZ,indx,Rok)
    9116         if len(Ind) == 1 and pageName == 'Map peaks':
     9194        if (pageName == 'Draw Atoms' or pageName == 'Draw Options') and (
     9195                drawingData['VPPeakDistRad'] + drawingData['VPatomsExpandRad']
     9196                 + drawingData['VPatomsDistRad']
     9197                ) > 0:
     9198            PeakDistRadius = drawingData['VPPeakDistRad']
     9199            atomsExpandRadius = drawingData['VPatomsExpandRad']
     9200            atomsdistRadius = drawingData['VPatomsDistRad']
     9201            x,y,z = drawingData['viewPoint'][0]
     9202            # distances to other peaks within PeakDistRadius A
     9203            if PeakDistRadius > 0:
     9204                distances2Peaks(x,y,z,PeakDistRadius,mapPeaks,radius,peakMax,Amat,matRot)
     9205            # find and display atoms within atomsExpandRadius A
     9206            if atomsExpandRadius > 0:
     9207                distances2Atoms(x,y,z,atomsExpandRadius,atomsdistRadius,Amat,matRot)
     9208        elif len(Ind) == 1 and (pageName == 'Map peaks' or
     9209                                    pageName == 'Draw Options'):
    91179210            # one peak has been selected, show as selected by draw options
    91189211            PeakDistRadius = drawingData['PeakDistRadius']
     
    91229215            mag,x,y,z = mapPeaks[:,:4][ind]
    91239216            RenderMapPeak(x,y,z,Gr,1.0)
    9124             # distances to other peaks within PeakDistRadius A
    91259217            if PeakDistRadius > 0:
    9126                 XYZ = mapPeaks.T[1:4].T
    9127                 Dx = XYZ-(x,y,z)
    9128                 dist = np.sqrt(np.sum(np.inner(Dx,Amat)**2,axis=1))
    9129                 for i in ma.nonzero(ma.masked_greater(dist,PeakDistRadius))[0]:
    9130                     lbl = '{:.2f}'.format(dist[i])
    9131                     RenderLines(x,y,z,[Dx[i]],Gr)
    9132                     lx,ly,lz = (x,y,z)+(Dx[i]/2)
    9133                     RenderLabel(lx,ly,lz,lbl,radius,wxGreen,matRot)
    9134                     [mag,x1,y1,z1] = mapPeaks[:,:4][i]
    9135                     if mag > 0.:
    9136                         RenderMapPeak(x1,y1,z1,Wt,mag/peakMax)
    9137                     else:
    9138                         RenderMapPeak(x1,y1,z1,Or,-2*mag/peakMax)
     9218                distances2Peaks(x,y,z,PeakDistRadius,mapPeaks,radius,peakMax,Amat,matRot)
    91399219            # find and display atoms within atomsExpandRadius A
    91409220            if atomsExpandRadius > 0:
    9141                 xyzA = np.array((x,y,z))
    9142                 cx,ct,cs,ci = G2phG.getAtomPtrs(data)     
    9143                 cellArray = G2lat.CellBlock(1)
    9144                 radDict = dict(zip(*G2phG.getAtomRadii(data)))
    9145                 Names = []
    9146                 Atoms = []
    9147                 Radii = []
    9148                 Color = []
    9149                 for atomB in data['Atoms']:
    9150                     xyzB = np.array(atomB[cx:cx+3])
    9151                     color = np.array(generalData['Color'][generalData['AtomTypes'].index(atomB[ct])])/255.
    9152                     result = G2spc.GenAtom(xyzB,SGData,False,6*[0.],True)
    9153                     for item in result:
    9154                         for xyz in cellArray+np.array(item[0]):
    9155                             dist = np.sqrt(np.sum(np.inner(Amat,xyz-xyzA)**2))
    9156                             if 0 < dist <= max(atomsdistRadius,atomsExpandRadius):
    9157                                 ax,ay,az = xyz
    9158                                 RenderSphere(ax,ay,az,radius,color)
    9159                                 Atoms.append(xyz)
    9160                                 Radii.append(radDict[atomB[ct]])
    9161                                 Names.append(atomB[0])
    9162                                 Color.append(color)
    9163                             if dist < atomsdistRadius:
    9164                                 RenderLines(x,y,z,[xyz-xyzA],Gr)
    9165                                 lx,ly,lz = (xyzA+xyz)/2
    9166                                 lbl = '{:.2f}'.format(dist)
    9167                                 RenderLabel(lx,ly,lz,lbl,radius,wxGreen,matRot)
    9168                                 ax,ay,az = xyz
    9169                                 RenderLabel(ax,ay,az,'  '+atomB[0],radius,wxGreen,matRot)
    9170                 # find bonds
    9171                 bondData = [[] for i in range(len(Atoms))]
    9172                 Atoms = np.array(Atoms)
    9173                 Radii = np.array(Radii)
    9174                 for i,atom in enumerate(Atoms):
    9175                     Dx = Atoms-atom
    9176                     sumR = Radii + Radii[i]
    9177                     dist = ma.masked_less(np.sqrt(np.sum(np.inner(Amat,Dx)**2,axis=0)),0.5)
    9178                     IndB = ma.nonzero(ma.masked_greater(dist-data['Drawing']['radiusFactor']*sumR,0.))                 #get indices of bonded atoms
    9179                     for j in IndB[0]:
    9180                         bondData[i].append(Dx[j]*Radii[i]/sumR[j])
    9181                         bondData[j].append(-Dx[j]*Radii[j]/sumR[j])
    9182                 # draw bonds
    9183                 bondR = drawingData['bondRadius']
    9184                 for i,xyz in enumerate(Atoms):
    9185                     ax,ay,az = xyz
    9186                     RenderBonds(ax,ay,az,bondData[i],bondR,Color[i])
     9221                distances2Atoms(x,y,z,atomsExpandRadius,atomsdistRadius,Amat,matRot)
    91879222        elif len(mapPeaks):
    91889223            XYZ = mapPeaks.T[1:4].T
Note: See TracChangeset for help on using the changeset viewer.