Changeset 4499 for trunk/GSASIIplot.py
- Timestamp:
- Jun 19, 2020 4:19:13 PM (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/GSASIIplot.py
r4495 r4499 8911 8911 GL.glShadeModel(GL.GL_SMOOTH) 8912 8912 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 8913 8991 def Draw(caller='',Fade=[]): 8914 8992 vdWRadii = generalData['vdWRadii'] … … 9114 9192 if not FourD and len(rhoXYZ) and drawingData['showMap']: #no green dot map for 4D - it's wrong! 9115 9193 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'): 9117 9210 # one peak has been selected, show as selected by draw options 9118 9211 PeakDistRadius = drawingData['PeakDistRadius'] … … 9122 9215 mag,x,y,z = mapPeaks[:,:4][ind] 9123 9216 RenderMapPeak(x,y,z,Gr,1.0) 9124 # distances to other peaks within PeakDistRadius A9125 9217 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) 9139 9219 # find and display atoms within atomsExpandRadius A 9140 9220 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) 9187 9222 elif len(mapPeaks): 9188 9223 XYZ = mapPeaks.T[1:4].T
Note: See TracChangeset
for help on using the changeset viewer.