Changeset 2848 for trunk/GSASIIplot.py
- Timestamp:
- May 31, 2017 2:48:06 PM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/GSASIIplot.py
r2835 r2848 6862 6862 ''' 6863 6863 6864 global AtNames,AtTypes,XYZ,Bonds 6864 global AtNames,AtTypes,XYZ,Bonds,Faces 6865 6865 6866 def FindBonds(atTypes,XYZ): 6866 6867 Radii = [] … … 6880 6881 Bonds[j].append(-Dx[j]*Radii[j]/sumR[j]) 6881 6882 return Bonds 6883 6884 def FindFaces(Bonds): 6885 Faces = [] 6886 for bonds in Bonds: 6887 faces = [] 6888 if len(bonds) > 2: 6889 FaceGen = G2lat.uniqueCombinations(bonds,3) #N.B. this is a generator 6890 for face in FaceGen: 6891 vol = nl.det(face) 6892 if abs(vol) > .5 or len(bonds) == 3: 6893 if vol < 0.: 6894 face = [face[0],face[2],face[1]] 6895 face = 1.8*np.array(face) 6896 if not np.array([np.array(nl.det(face-bond))+0.0001 < 0 for bond in bonds]).any(): 6897 norm = np.cross(face[1]-face[0],face[2]-face[0]) 6898 norm /= np.sqrt(np.sum(norm**2)) 6899 faces.append([face,norm]) 6900 Faces.append(faces) 6901 return Faces 6882 6902 6883 6903 def getAtoms(): 6884 global AtNames,AtTypes,XYZ,Bonds 6904 global AtNames,AtTypes,XYZ,Bonds,Faces 6885 6905 AtNames = [] 6886 6906 AtTypes = [] … … 6922 6942 6923 6943 Bonds = FindBonds(AtTypes,XYZ) 6944 Faces = FindFaces(Bonds) 6924 6945 6925 6946 def OnKeyBox(event): … … 6951 6972 im.save(Fname,mode) 6952 6973 print ' Drawing saved to: '+Fname 6953 elif mode[0] in ['L','F' ]:6974 elif mode[0] in ['L','F','P']: 6954 6975 event.key = cb.GetValue()[0] 6955 6976 wx.CallAfter(OnPlotKeyPress,event) … … 6974 6995 elif keyCode =='F' and len(laySeq) == 2: 6975 6996 Page.fade = not Page.fade 6997 elif keyCode == 'P': 6998 Page.poly = not Page.poly 6976 6999 if len(laySeq) != 2: 6977 7000 return … … 7145 7168 GL.glPopMatrix() 7146 7169 7170 def RenderPolyhedra(x,y,z,Faces,color): 7171 GL.glShadeModel(GL.GL_FLAT) 7172 GL.glPushMatrix() 7173 GL.glTranslate(x,y,z) 7174 GL.glMaterialfv(GL.GL_FRONT_AND_BACK,GL.GL_DIFFUSE,color) 7175 GL.glShadeModel(GL.GL_SMOOTH) 7176 GL.glMultMatrixf(B4mat.T) 7177 for face,norm in Faces: 7178 GL.glPolygonMode(GL.GL_FRONT_AND_BACK,GL.GL_FILL) 7179 GL.glFrontFace(GL.GL_CW) 7180 GL.glNormal3fv(norm) 7181 GL.glBegin(GL.GL_TRIANGLES) 7182 for vert in face: 7183 GL.glVertex3fv(vert) 7184 GL.glEnd() 7185 GL.glPopMatrix() 7186 GL.glShadeModel(GL.GL_SMOOTH) 7187 7147 7188 def RenderLabel(x,y,z,label,matRot): 7148 7189 GL.glPushMatrix() … … 7163 7204 # print caller 7164 7205 # end of useful debug 7165 global AtNames,AtTypes,XYZ,Bonds 7206 global AtNames,AtTypes,XYZ,Bonds,Faces 7166 7207 cPos = defaults['cameraPos'] 7167 7208 VS = np.array(Page.canvas.GetSize()) … … 7200 7241 if len(laySeq) == 2 and AtTypes[iat][1] and Page.fade: 7201 7242 color *= .5 7202 RenderSphere(x,y,z,atomRad,color) 7203 RenderBonds(x,y,z,Bonds[iat],bondRad,color) 7243 if Page.poly: 7244 if len(Faces[iat])>16: 7245 RenderPolyhedra(x,y,z,Faces[iat],color) 7246 else: 7247 RenderSphere(x,y,z,atomRad,color) 7248 RenderBonds(x,y,z,Bonds[iat],bondRad,color) 7204 7249 if Page.labels: 7205 7250 RenderLabel(x,y,z,' '+AtNames[iat],matRot) … … 7240 7285 Page.labels = False 7241 7286 Page.fade = False 7242 choice = [' save as:','jpeg','tiff','bmp','use keys for:','L - toggle labels'] 7287 Page.poly = False 7288 choice = [' save as:','jpeg','tiff','bmp','use keys for:','L - toggle labels', 7289 'F - fade 2nd layer','P - polyhedra'] 7243 7290 if len(laySeq) == 2: 7244 7291 choice += ['F - toggle fade','X/shift-X move Dx','Y/shift-Y move Dy','Z/shift-Z move Dz']
Note: See TracChangeset
for help on using the changeset viewer.