Changeset 2163
- Timestamp:
- Mar 7, 2016 3:03:10 PM (8 years ago)
- Location:
- trunk
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/GSASIIIO.py
r2161 r2163 2317 2317 print 'read ',DIFFaXfile 2318 2318 Layer = {'Laue':'-1','Cell':[False,1.,1.,1.,90.,90.,90,1.],'Width':[[10.,10.],[False,False]], 2319 'Layers':[],'Stacking':[],'Transitions':[],'Toler':0.01 }2319 'Layers':[],'Stacking':[],'Transitions':[],'Toler':0.01,'AtInfo':{}} 2320 2320 df = open(DIFFaXfile,'r') 2321 2321 lines = df.readlines() … … 2397 2397 while 'layer' not in Struct[N]: 2398 2398 atom = Struct[N][4:].split() 2399 atomType = G2el.FixValence(Struct[N][:4]).strip().capitalize() 2399 atomType = G2el.FixValence(Struct[N][:4].replace(' ','').strip().capitalize()) 2400 if atomType not in Layer['AtInfo']: 2401 Layer['AtInfo'][atomType] = G2el.GetAtomInfo(atomType) 2400 2402 atomName = '%s(%s)'%(atomType,atom[0]) 2401 2403 newVals = [] -
trunk/GSASIIphsGUI.py
r2162 r2163 423 423 if 'Layers' not in data: 424 424 data['Layers'] = {'Laue':'-1','Cell':[False,1.,1.,1.,90.,90.,90,1.], 425 'Width':[[10.,10.],[False,False]],'Toler':0.01, 425 'Width':[[10.,10.],[False,False]],'Toler':0.01,'AtInfo':{}, 426 426 'Layers':[],'Stacking':[],'Transitions':[]} 427 427 G2frame.layerData = wx.ScrolledWindow(G2frame.dataDisplay) … … 2397 2397 transTypes = [wg.GRID_VALUE_FLOAT+':10,3',]+3*[wg.GRID_VALUE_FLOAT+':10,5',]+ \ 2398 2398 [wg.GRID_VALUE_CHOICE+": ,P,PX,PY,PZ,PXY,PXZ,PYZ,PXYZ,X,Y,Z,XY,XZ,YZ,XYZ",wg.GRID_VALUE_BOOL,] 2399 2399 plotDefaults = {'oldxy':[0.,0.],'Quaternion':[0.,0.,0.,1.],'cameraPos':30.,'viewDir':[0,0,1],} 2400 2400 2401 def OnLaue(event): 2401 2402 Obj = event.GetEventObject() … … 2510 2511 widthSizer = wx.BoxSizer(wx.HORIZONTAL) 2511 2512 for i in range(2): 2512 widthSizer.Add(wx.StaticText(layerData,label=' layer width(%s) : '%(Labels[i])),0,WACV)2513 widthSizer.Add(wx.StaticText(layerData,label=' layer width(%s) \xb5m: '%(Labels[i])),0,WACV) 2513 2514 widthVal = wx.TextCtrl(layerData,value='%.3f'%(widths[i]),style=wx.TE_PROCESS_ENTER) 2514 2515 widthVal.Bind(wx.EVT_TEXT_ENTER,OnWidthChange) … … 2525 2526 def OnNewLayer(event): 2526 2527 data['Layers']['Layers'].append({'Name':'Unk','SameAs':'','Symm':'None','Atoms':[]}) 2528 Trans = data['Layers']['Transitions'] 2529 if len(Trans): 2530 Trans.append([[0.,0.,0.,0.,''] for trans in Trans]) 2531 for trans in Trans: 2532 trans.append([0.,0.,0.,0.,'']) 2533 else: 2534 Trans = [[1.,0.,0.,0.,''],] 2527 2535 #modify transition probability matrix as well - add new row/column 2528 2536 UpdateLayerData() … … 2550 2558 PE = G2elemGUI.PickElement(G2frame) 2551 2559 if PE.ShowModal() == wx.ID_OK: 2552 if PE.Elem != 'None': 2553 Layer['Atoms'][r][c] = PE.Elem.strip() 2560 if PE.Elem != 'None': 2561 atType = PE.Elem.strip() 2562 Layer['Atoms'][r][c] = atType 2554 2563 name = Layer['Atoms'][r][c] 2555 2564 if len(name) in [2,4]: … … 2557 2566 else: 2558 2567 Layer['Atoms'][r][c-1] = name[:1]+'%d'%(r+1) 2568 if atType not in data['Layers']['AtInfo']: 2569 data['Layers']['AtInfo'][atType] = G2elem.GetAtomInfo(atType) 2559 2570 PE.Destroy() 2560 2571 UpdateLayerData() … … 2564 2575 def OnDrawLayer(event): 2565 2576 drawLayer.SetValue(False) 2566 pass2577 G2plt.PlotLayers(G2frame,Layers,[il,],plotDefaults) 2567 2578 2568 2579 def OnSameAs(event): … … 2628 2639 if Xi >= 0 and c == 5: #plot column 2629 2640 Obj.SetCellValue(Xi,5,'') 2630 print 'plot %s - %s'%(Names[Yi],Names[Xi])2641 G2plt.PlotLayers(G2frame,Layers,[Yi,Xi,],plotDefaults) 2631 2642 2632 2643 transSizer = wx.BoxSizer(wx.VERTICAL) … … 2659 2670 return transSizer 2660 2671 2672 def PlotSizer(): 2673 2674 def OnPlotSeq(event): 2675 vals = plotSeq.GetValue().split() 2676 try: 2677 vals = [int(val)-1 for val in vals] 2678 except ValueError: 2679 plotSeq.SetValue('Error in string '+vals) 2680 plotSeq.SetValue('') 2681 G2plt.PlotLayers(G2frame,Layers,vals,plotDefaults) 2682 2683 Names = [' %s: %d,'%(layer['Name'],iL+1) for iL,layer in enumerate(Layers['Layers'])] 2684 plotSizer = wx.BoxSizer(wx.VERTICAL) 2685 Str = ' Using sequence nos. from:' 2686 for name in Names: 2687 Str += name 2688 plotSizer.Add(wx.StaticText(layerData,label=Str[:-1]),0,WACV) 2689 lineSizer = wx.BoxSizer(wx.HORIZONTAL) 2690 lineSizer.Add(wx.StaticText(layerData,label=' Enter sequence of layers to plot:'),0,WACV) 2691 plotSeq = wx.TextCtrl(layerData,value = '',style=wx.TE_PROCESS_ENTER) 2692 plotSeq.Bind(wx.EVT_TEXT_ENTER,OnPlotSeq) 2693 plotSeq.Bind(wx.EVT_KILL_FOCUS,OnPlotSeq) 2694 lineSizer.Add(plotSeq,0,WACV) 2695 plotSizer.Add(lineSizer,0,WACV) 2696 return plotSizer 2697 2661 2698 def StackSizer(): 2662 2699 … … 2678 2715 def OnSeqType(event): 2679 2716 Layers['Stacking'][1] = seqType.GetValue() 2717 2718 def OnStackList(event): 2719 stack = stackList.GetValue() 2720 stack = stack.replace('\n',' ').strip().strip('\n') 2721 nstar = stack.count('*') 2722 if nstar: 2723 try: 2724 newstack = '' 2725 Istar = 0 2726 for star in range(nstar): 2727 Istar = stack.index('*',Istar+1) 2728 iB = stack[:Istar].rfind(' ') 2729 if iB == -1: 2730 mult = int(stack[:Istar]) 2731 else: 2732 mult = int(stack[iB:Istar]) 2733 pattern = stack[Istar+2:stack.index(')',Istar)]+' ' 2734 newstack += mult*pattern 2735 stack = newstack 2736 except ValueError: 2737 stack += ' Error in string' 2738 Layers['Stacking'][2] = stack 2739 stackList.SetValue(stack) 2680 2740 2681 2741 stackChoice = ['recursive','explicit',] … … 2708 2768 stackSizer.Add(topLine,0,WACV) 2709 2769 if Layers['Stacking'][1] == 'list': 2710 stackSizer.Add(wx.StaticText(layerData,label=' Explicit layer sequence;'),0,WACV) 2711 2770 Names = [' %s: %d,'%(layer['Name'],iL+1) for iL,layer in enumerate(Layers['Layers'])] 2771 stackSizer.Add(wx.StaticText(layerData,label=' Explicit layer sequence; enter space delimited list of numbers:'),0,WACV) 2772 Str = ' Use sequence nos. from:' 2773 for name in Names: 2774 Str += name 2775 stackSizer.Add(wx.StaticText(layerData,label=Str[:-1]+' Repeat sequences can be used: e.g. 6*(1 2) '),0,WACV) 2776 stackSizer.Add(wx.StaticText(layerData,label=' Zero probability sequences not allowed'),0,WACV) 2777 stackList = wx.TextCtrl(layerData,value=Layers['Stacking'][2],size=(600,-1), 2778 style=wx.TE_MULTILINE|wx.TE_PROCESS_ENTER) 2779 stackList.SetValue(Layers['Stacking'][2]) 2780 stackList.Bind(wx.EVT_TEXT_ENTER,OnStackList) 2781 stackList.Bind(wx.EVT_KILL_FOCUS,OnStackList) 2782 stackSizer.Add(stackList,0,wx.ALL|wx.EXPAND|WACV,8) 2712 2783 return stackSizer 2713 2784 2714 generalData = data['General']2715 2785 Layers = data['Layers'] 2716 2786 layerNames = [] … … 2719 2789 G2frame.dataFrame.SetStatusText('') 2720 2790 layerData = G2frame.layerData 2721 SGData = generalData['SGData']2722 2791 if layerData.GetSizer(): 2723 2792 layerData.GetSizer().Clear(True) … … 2754 2823 for il,layer in enumerate(Layers['Layers']): 2755 2824 topSizer.Add(LayerSizer(il,layer)) 2825 G2G.HorizontalLine(topSizer,layerData) 2756 2826 mainSizer.Add(topSizer) 2827 bottomSizer.Add(TransSizer()) 2757 2828 G2G.HorizontalLine(bottomSizer,layerData) 2758 bottomSizer.Add( TransSizer())2829 bottomSizer.Add(PlotSizer(),0,WACV) 2759 2830 G2G.HorizontalLine(bottomSizer,layerData) 2760 2831 bottomSizer.Add(StackSizer()) … … 6903 6974 # Stacking faults 6904 6975 if data['General']['Type'] == 'faulted': 6905 print 'set bind'6906 6976 FillSelectPageMenu(TabSelectionIdDict, G2frame.dataFrame.LayerData) 6907 6977 G2frame.dataFrame.Bind(wx.EVT_MENU, OnLoadDIFFaX, id=G2gd.wxID_LOADDIFFAX) -
trunk/GSASIIplot.py
r2157 r2163 5762 5762 Page.canvas.SetCurrent() 5763 5763 Draw('main') 5764 5765 ################################################################################ 5766 #### Plot Layers 5767 ################################################################################ 5768 5769 def PlotLayers(G2frame,Layers,laySeq,defaults): 5770 '''Layer plotting package. Can show layer structures as balls & sticks 5771 ''' 5772 5773 def FindBonds(atTypes,XYZ): 5774 Radii = [] 5775 for Atype in atTypes: 5776 Radii.append(AtInfo[Atype]['Drad']) 5777 if Atype == 'H': 5778 Radii[-1] = 0.5 5779 Radii = np.array(Radii) 5780 Bonds = [[] for i in range(len(Radii))] 5781 for i,xyz in enumerate(XYZ): 5782 Dx = np.inner(Amat,(XYZ-xyz)).T 5783 dist = np.sqrt(np.sum(Dx**2,axis=1)) 5784 sumR = Radii[i]+Radii 5785 IndB = ma.nonzero(ma.masked_greater(dist-0.85*sumR,0.)) 5786 for j in IndB[0]: 5787 Bonds[i].append(Dx[j]*Radii[i]/sumR[j]) 5788 Bonds[j].append(-Dx[j]*Radii[j]/sumR[j]) 5789 return Bonds 5790 5791 cell = Layers['Cell'][1:7] 5792 Amat,Bmat = G2lat.cell2AB(cell) #Amat - crystal to cartesian, Bmat - inverse 5793 A4mat = np.concatenate((np.concatenate((Amat,[[0],[0],[0]]),axis=1),[[0,0,0,1],]),axis=0) 5794 B4mat = np.concatenate((np.concatenate((Bmat,[[0],[0],[0]]),axis=1),[[0,0,0,1],]),axis=0) 5795 Trans = Layers['Transitions'] 5796 Wt = np.array([255,255,255]) 5797 Rd = np.array([255,0,0]) 5798 Gr = np.array([0,255,0]) 5799 Bl = np.array([0,0,255]) 5800 uBox = np.array([[0,0,0],[1,0,0],[0,1,0],[0,0,1]]) 5801 uEdges = np.array([[uBox[0],uBox[1]],[uBox[0],uBox[2]],[uBox[0],uBox[3]]]) 5802 uColors = [Rd,Gr,Bl] 5803 AtInfo = Layers['AtInfo'] 5804 Names = [layer['Name'] for layer in Layers['Layers']] 5805 atNames = [] 5806 atTypes = [] 5807 newXYZ = np.zeros((0,3)) 5808 TX = np.zeros(3) 5809 for il,layer in enumerate(laySeq): 5810 if Layers['Layers'][layer]['SameAs']: 5811 layer = Names.index(Layers['Layers'][layer]['SameAs']) 5812 atNames += [atom[0] for atom in Layers['Layers'][layer]['Atoms']] 5813 atTypes += [atom[1] for atom in Layers['Layers'][layer]['Atoms']] 5814 XYZ = np.array([atom[3:6] for atom in Layers['Layers'][layer]['Atoms']])+TX 5815 if '-1' in Layers['Layers'][layer]['Symm']: 5816 atNames += atNames 5817 atTypes += atTypes 5818 XYZ = np.concatenate((XYZ,-XYZ)) 5819 if il: 5820 TX = np.array(Trans[laySeq[il-1]][layer][1:4]) 5821 XYZ += TX 5822 newXYZ = np.concatenate((newXYZ,XYZ)) 5823 XYZ = newXYZ 5824 na = int(8./cell[0]) 5825 nb = int(8./cell[1]) 5826 nunit = [na,nb,0] 5827 indA = range(-na,na) 5828 indB = range(-nb,nb) 5829 Units = np.array([[h,k,0] for h in indA for k in indB]) 5830 newXYZ = np.copy(XYZ) 5831 for unit in Units: 5832 if np.any(unit): 5833 newXYZ = np.concatenate((newXYZ,unit+XYZ)) 5834 if len(Units): 5835 atNames *= len(Units) 5836 atTypes *= len(Units) 5837 XYZ = newXYZ 5838 Bonds = FindBonds(atTypes,XYZ) 5839 5840 def OnMouseDown(event): 5841 xy = event.GetPosition() 5842 defaults['oldxy'] = list(xy) 5843 5844 def OnMouseMove(event): 5845 newxy = event.GetPosition() 5846 5847 if event.Dragging(): 5848 if event.LeftIsDown(): 5849 SetRotation(newxy) 5850 Q = defaults['Quaternion'] 5851 G2frame.G2plotNB.status.SetStatusText('New quaternion: %.2f+, %.2fi+ ,%.2fj+, %.2fk'%(Q[0],Q[1],Q[2],Q[3]),1) 5852 elif event.MiddleIsDown(): 5853 SetRotationZ(newxy) 5854 Q = defaults['Quaternion'] 5855 G2frame.G2plotNB.status.SetStatusText('New quaternion: %.2f+, %.2fi+ ,%.2fj+, %.2fk'%(Q[0],Q[1],Q[2],Q[3]),1) 5856 Draw('move') 5857 5858 def OnMouseWheel(event): 5859 defaults['cameraPos'] += event.GetWheelRotation()/24 5860 defaults['cameraPos'] = max(10,min(500,defaults['cameraPos'])) 5861 G2frame.G2plotNB.status.SetStatusText('New camera distance: %.2f'%(defaults['cameraPos']),1) 5862 Draw('wheel') 5863 5864 def SetBackground(): 5865 R,G,B,A = Page.camera['backColor'] 5866 glClearColor(R,G,B,A) 5867 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) 5868 5869 def SetLights(): 5870 glEnable(GL_DEPTH_TEST) 5871 glShadeModel(GL_FLAT) 5872 glEnable(GL_LIGHTING) 5873 glEnable(GL_LIGHT0) 5874 glLightModeli(GL_LIGHT_MODEL_TWO_SIDE,0) 5875 glLightfv(GL_LIGHT0,GL_AMBIENT,[1,1,1,.8]) 5876 glLightfv(GL_LIGHT0,GL_DIFFUSE,[1,1,1,1]) 5877 5878 def SetRotation(newxy): 5879 #first get rotation vector in screen coords. & angle increment 5880 oldxy = defaults['oldxy'] 5881 if not len(oldxy): oldxy = list(newxy) 5882 dxy = newxy-oldxy 5883 defaults['oldxy'] = list(newxy) 5884 V = np.array([dxy[1],dxy[0],0.]) 5885 A = 0.25*np.sqrt(dxy[0]**2+dxy[1]**2) 5886 # next transform vector back to xtal coordinates via inverse quaternion 5887 # & make new quaternion 5888 Q = defaults['Quaternion'] 5889 V = G2mth.prodQVQ(G2mth.invQ(Q),V) 5890 DQ = G2mth.AVdeg2Q(A,V) 5891 Q = G2mth.prodQQ(Q,DQ) 5892 defaults['Quaternion'] = Q 5893 # finally get new view vector - last row of rotation matrix 5894 VD = G2mth.Q2Mat(Q)[2] 5895 VD /= np.sqrt(np.sum(VD**2)) 5896 defaults['viewDir'] = VD 5897 5898 def SetRotationZ(newxy): 5899 #first get rotation vector (= view vector) in screen coords. & angle increment 5900 View = glGetIntegerv(GL_VIEWPORT) 5901 cent = [View[2]/2,View[3]/2] 5902 oldxy = defaults['oldxy'] 5903 if not len(oldxy): oldxy = list(newxy) 5904 dxy = newxy-oldxy 5905 defaults['oldxy'] = list(newxy) 5906 V = defaults['viewDir'] 5907 A = [0,0] 5908 A[0] = dxy[1]*.25 5909 A[1] = dxy[0]*.25 5910 if newxy[0] > cent[0]: 5911 A[0] *= -1 5912 if newxy[1] < cent[1]: 5913 A[1] *= -1 5914 # next transform vector back to xtal coordinates & make new quaternion 5915 Q = defaults['Quaternion'] 5916 Qx = G2mth.AVdeg2Q(A[0],V) 5917 Qy = G2mth.AVdeg2Q(A[1],V) 5918 Q = G2mth.prodQQ(Q,Qx) 5919 Q = G2mth.prodQQ(Q,Qy) 5920 defaults['Quaternion'] = Q 5921 5922 def RenderUnitVectors(x,y,z): 5923 xyz = np.array([x,y,z]) 5924 glEnable(GL_COLOR_MATERIAL) 5925 glLineWidth(1) 5926 glPushMatrix() 5927 glTranslate(x,y,z) 5928 glBegin(GL_LINES) 5929 for line,color in zip(uEdges,uColors): 5930 glColor3ubv(color) 5931 glVertex3fv(-line[1]) 5932 glVertex3fv(line[1]) 5933 glEnd() 5934 glPopMatrix() 5935 glColor4ubv([0,0,0,0]) 5936 glDisable(GL_COLOR_MATERIAL) 5937 5938 def RenderSphere(x,y,z,radius,color): 5939 glMaterialfv(GL_FRONT_AND_BACK,GL_DIFFUSE,color) 5940 glPushMatrix() 5941 glTranslate(x,y,z) 5942 glMultMatrixf(B4mat.T) 5943 q = gluNewQuadric() 5944 gluSphere(q,radius,20,10) 5945 glPopMatrix() 5946 5947 def RenderBonds(x,y,z,Bonds,radius,color,slice=20): 5948 glMaterialfv(GL_FRONT_AND_BACK,GL_DIFFUSE,color) 5949 glPushMatrix() 5950 glTranslate(x,y,z) 5951 glMultMatrixf(B4mat.T) 5952 for Dx in Bonds: 5953 glPushMatrix() 5954 Z = np.sqrt(np.sum(Dx**2)) 5955 if Z: 5956 azm = atan2d(-Dx[1],-Dx[0]) 5957 phi = acosd(Dx[2]/Z) 5958 glRotate(-azm,0,0,1) 5959 glRotate(phi,1,0,0) 5960 q = gluNewQuadric() 5961 gluCylinder(q,radius,radius,Z,slice,2) 5962 glPopMatrix() 5963 glPopMatrix() 5964 5965 def RenderLabel(x,y,z,label,matRot): 5966 glPushMatrix() 5967 glTranslate(x,y,z) 5968 glMultMatrixf(B4mat.T) 5969 glDisable(GL_LIGHTING) 5970 glRasterPos3f(0,0,0) 5971 glMultMatrixf(matRot) 5972 glRotate(180,1,0,0) #fix to flip about x-axis 5973 text = gltext.TextElement(text=label,font=Font,foreground=wx.WHITE) 5974 text.draw_text(scale=0.025) 5975 glEnable(GL_LIGHTING) 5976 glPopMatrix() 5977 5978 def Draw(caller=''): 5979 #useful debug? 5980 # if caller: 5981 # print caller 5982 # end of useful debug 5983 cPos = defaults['cameraPos'] 5984 VS = np.array(Page.canvas.GetSize()) 5985 aspect = float(VS[0])/float(VS[1]) 5986 Zclip = 500.0 5987 Q = defaults['Quaternion'] 5988 SetBackground() 5989 glInitNames() 5990 glPushName(0) 5991 5992 glMatrixMode(GL_PROJECTION) 5993 glLoadIdentity() 5994 glViewport(0,0,VS[0],VS[1]) 5995 gluPerspective(20.,aspect,1.,500.) 5996 gluLookAt(0,0,cPos,0,0,0,0,1,0) 5997 SetLights() 5998 5999 glMatrixMode(GL_MODELVIEW) 6000 glLoadIdentity() 6001 matRot = G2mth.Q2Mat(Q) 6002 matRot = np.concatenate((np.concatenate((matRot,[[0],[0],[0]]),axis=1),[[0,0,0,1],]),axis=0) 6003 glMultMatrixf(matRot.T) 6004 glMultMatrixf(A4mat.T) 6005 RenderUnitVectors(0.,0.,0.) 6006 radius = 0.2 6007 for iat,atom in enumerate(XYZ): 6008 x,y,z = atom 6009 CL = AtInfo[atTypes[iat]]['Color'] 6010 color = np.array(CL)/255. 6011 RenderSphere(x,y,z,radius,color) 6012 RenderBonds(x,y,z,Bonds[iat],0.05,color) 6013 RenderLabel(x,y,z,' '+atNames[iat],matRot) 6014 if Page.context: Page.canvas.SetCurrent(Page.context) # wx 2.9 fix 6015 Page.canvas.SwapBuffers() 6016 6017 def OnSize(event): 6018 Draw('size') 6019 6020 try: 6021 plotNum = G2frame.G2plotNB.plotList.index('Layer') 6022 Page = G2frame.G2plotNB.nb.GetPage(plotNum) 6023 except ValueError: 6024 Plot = G2frame.G2plotNB.addOgl('Layer') 6025 plotNum = G2frame.G2plotNB.plotList.index('Layer') 6026 Page = G2frame.G2plotNB.nb.GetPage(plotNum) 6027 Page.views = False 6028 view = False 6029 altDown = False 6030 Page.SetFocus() 6031 Font = Page.GetFont() 6032 Page.canvas.Bind(wx.EVT_MOUSEWHEEL, OnMouseWheel) 6033 Page.canvas.Bind(wx.EVT_LEFT_DOWN, OnMouseDown) 6034 Page.canvas.Bind(wx.EVT_RIGHT_DOWN, OnMouseDown) 6035 Page.canvas.Bind(wx.EVT_MIDDLE_DOWN, OnMouseDown) 6036 Page.canvas.Bind(wx.EVT_MOTION, OnMouseMove) 6037 Page.canvas.Bind(wx.EVT_SIZE, OnSize) 6038 Page.camera['position'] = defaults['cameraPos'] 6039 Page.camera['backColor'] = np.array([0,0,0,0]) 6040 Page.canvas.SetCurrent() 6041 Draw('main')
Note: See TracChangeset
for help on using the changeset viewer.