Changeset 2172
- Timestamp:
- Mar 15, 2016 3:07:56 PM (8 years ago)
- Location:
- trunk
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/GSASIIgrid.py
r2166 r2172 489 489 parent = self.GetParent() 490 490 parent.Raise() 491 self.EndModal(wx.ID_CANCEL) 491 self.EndModal(wx.ID_CANCEL) 492 493 ################################################################################ 494 class DIFFaXcontrols(wx.Dialog): 495 ''' Solicit items needed to prepare DIFFaX control.dif file 496 ''' 497 def __init__(self,parent,ctrls): 498 wx.Dialog.__init__(self,parent,wx.ID_ANY,'DIFFaX controls', 499 pos=wx.DefaultPosition,style=wx.DEFAULT_DIALOG_STYLE) 500 self.panel = wx.Panel(self) #just a dummy - gets destroyed in Draw! 501 self.ctrls = ctrls 502 self.Draw() 503 504 def Draw(self): 505 506 507 508 self.panel.Destroy() 509 self.panel = wx.Panel(self) 510 mainSizer = wx.BoxSizer(wx.VERTICAL) 511 mainSizer.Add(wx.StaticText(self.panel,label=' Controls for DIFFaX'),0,WACV) 512 513 514 OkBtn = wx.Button(self.panel,-1,"Ok") 515 OkBtn.Bind(wx.EVT_BUTTON, self.OnOk) 516 cancelBtn = wx.Button(self.panel,-1,"Cancel") 517 cancelBtn.Bind(wx.EVT_BUTTON, self.OnCancel) 518 btnSizer = wx.BoxSizer(wx.HORIZONTAL) 519 btnSizer.Add((20,20),1) 520 btnSizer.Add(OkBtn) 521 btnSizer.Add((20,20),1) 522 btnSizer.Add(cancelBtn) 523 btnSizer.Add((20,20),1) 524 525 mainSizer.Add(btnSizer,0,wx.EXPAND|wx.BOTTOM|wx.TOP, 10) 526 self.panel.SetSizer(mainSizer) 527 self.panel.Fit() 528 self.Fit() 529 530 def GetSelection(self): 531 return self.ctrls 532 533 def OnOk(self,event): 534 parent = self.GetParent() 535 parent.Raise() 536 self.EndModal(wx.ID_OK) 537 538 def OnCancel(self,event): 539 parent = self.GetParent() 540 parent.Raise() 541 self.EndModal(wx.ID_CANCEL) 542 492 543 493 544 ################################################################################ -
trunk/GSASIIphsGUI.py
r2170 r2172 67 67 acosd = lambda x: 180.*np.arccos(x)/np.pi 68 68 atan2d = lambda x,y: 180.*np.arctan2(y,x)/np.pi 69 69 70 70 def SetPhaseWindow(mainFrame,phasePage,mainSizer,Scroll=0): 71 71 phasePage.SetSizer(mainSizer) … … 2584 2584 def OnDrawLayer(event): 2585 2585 drawLayer.SetValue(False) 2586 if len(Layers['Layers'][il]['Atoms']) == 0:2587 wx.MessageBox('No atoms in this layer to plot',caption='Data error',style=wx.ICON_EXCLAMATION)2588 return2589 2586 G2plt.PlotLayers(G2frame,Layers,[il,],plotDefaults) 2590 2587 … … 2648 2645 Obj = event.GetEventObject() 2649 2646 Yi = Indx[Obj.GetId()] 2650 if len(Layers['Layers'][Yi]['Atoms']) == 0:2651 wx.MessageBox('No atoms in this layer to plot',caption='Data error',style=wx.ICON_EXCLAMATION)2652 return2653 2647 Xi,c = event.GetRow(),event.GetCol() 2654 2648 if Xi >= 0 and c == 5: #plot column 2655 if len(Layers['Layers'][Xi]['Atoms']) == 0:2656 wx.MessageBox('No atoms in this layer to plot',caption='Data error',style=wx.ICON_EXCLAMATION)2657 return2658 2649 Obj.SetCellValue(Xi,5,'') 2659 2650 G2plt.PlotLayers(G2frame,Layers,[Yi,Xi,],plotDefaults) … … 2664 2655 transArray = Layers['Transitions'] 2665 2656 Indx = {} 2657 layerData.transGrids = [] 2666 2658 if not Names or not transArray: 2667 2659 return transSizer … … 2686 2678 transGrid.AutoSizeColumns(True) 2687 2679 transSizer.Add(transGrid) 2680 layerData.transGrids.append(transGrid) 2688 2681 return transSizer 2689 2682 … … 2904 2897 wx.MessageBox("Can't simulate neutron TOF patterns yet",caption='Data error',style=wx.ICON_EXCLAMATION) 2905 2898 return 2906 profile = G2frame.PatternTree.GetItemPyData(G2frame.PatternId)[1] 2899 profile = G2frame.PatternTree.GetItemPyData(G2frame.PatternId)[1] 2900 ctrls = {} 2901 dlg = G2gd.DIFFaXcontrols(G2frame,ctrls) 2902 if dlg.ShowModal() == wx.ID_OK: 2903 ctrls = dlg.GetSelection() 2904 else: 2905 return 2906 dlg.Destroy() 2907 2907 G2pwd.StackSim(data['Layers'],HistName,scale,background,limits,inst,profile) 2908 2908 G2plt.PlotPatterns(G2frame,plotType='PWDR') -
trunk/GSASIIplot.py
r2167 r2172 582 582 im = Im.new("RGB", (size[0],size[1])) 583 583 im.fromstring(Pix) 584 im = im.transpose(Im.FLIP_TOP_BOTTOM) 584 585 im.save(Fname,mode) 585 586 cb.SetValue(' save as/key:') … … 4523 4524 im = Im.new("RGB", (size[0],size[1])) 4524 4525 im.fromstring(Pix) 4526 im = im.transpose(Im.FLIP_TOP_BOTTOM) 4525 4527 im.save(Fname,mode) 4526 4528 cb.SetValue(' save as/key:') … … 5772 5774 ''' 5773 5775 5776 global AtNames,AtTypes,XYZ,Bonds 5774 5777 def FindBonds(atTypes,XYZ): 5775 5778 Radii = [] … … 5789 5792 Bonds[j].append(-Dx[j]*Radii[j]/sumR[j]) 5790 5793 return Bonds 5794 5795 def getAtoms(): 5796 global AtNames,AtTypes,XYZ,Bonds 5797 AtNames = [] 5798 AtTypes = [] 5799 newXYZ = np.zeros((0,3)) 5800 TX = np.zeros(3) 5801 for il in range(len(laySeq)): 5802 layer = laySeq[il] 5803 if Layers['Layers'][layer]['SameAs']: 5804 layer = Names.index(Layers['Layers'][layer]['SameAs']) 5805 atNames = [atom[0] for atom in Layers['Layers'][layer]['Atoms']] 5806 atTypes = [atom[1] for atom in Layers['Layers'][layer]['Atoms']] 5807 XYZ = np.array([atom[2:5] for atom in Layers['Layers'][layer]['Atoms']]) 5808 if '-1' in Layers['Layers'][layer]['Symm']: 5809 atNames += atNames 5810 atTypes += atTypes 5811 XYZ = np.concatenate((XYZ,-XYZ)) 5812 if il: 5813 TX += np.array(Trans[laySeq[il-1]][layer][1:4]) 5814 XYZ += TX 5815 XYZT = XYZ.T 5816 XYZT[0] = XYZT[0]%1. 5817 XYZT[1] = XYZT[1]%1. 5818 XYZ = XYZT.T 5819 AtNames += atNames 5820 AtTypes += atTypes 5821 newXYZ = np.concatenate((newXYZ,XYZ)) 5822 XYZ = newXYZ 5823 na = int(8./cell[0]) 5824 nb = int(8./cell[1]) 5825 nunit = [na,nb,0] 5826 indA = range(-na,na) 5827 indB = range(-nb,nb) 5828 Units = np.array([[h,k,0] for h in indA for k in indB]) 5829 newXYZ = np.zeros((0,3)) 5830 for unit in Units: 5831 newXYZ = np.concatenate((newXYZ,unit+XYZ)) 5832 if len(Units): 5833 AtNames *= len(Units) 5834 AtTypes *= len(Units) 5835 XYZ = newXYZ 5836 Bonds = FindBonds(AtTypes,XYZ) 5791 5837 5792 5838 cell = Layers['Cell'][1:7] … … 5804 5850 AtInfo = Layers['AtInfo'] 5805 5851 Names = [layer['Name'] for layer in Layers['Layers']] 5806 AtNames = [] 5807 AtTypes = [] 5808 newXYZ = np.zeros((0,3)) 5809 TX = np.zeros(3) 5810 for il in range(len(laySeq)): 5811 layer = laySeq[il] 5812 if Layers['Layers'][layer]['SameAs']: 5813 alayer = Names.index(Layers['Layers'][layer]['SameAs']) 5814 atNames = [atom[0] for atom in Layers['Layers'][layer]['Atoms']] 5815 atTypes = [atom[1] for atom in Layers['Layers'][layer]['Atoms']] 5816 XYZ = np.array([atom[2:5] for atom in Layers['Layers'][layer]['Atoms']]) 5817 if '-1' in Layers['Layers'][layer]['Symm']: 5818 atNames += atNames 5819 atTypes += atTypes 5820 XYZ = np.concatenate((XYZ,-XYZ)) 5821 if il: 5822 TX += np.array(Trans[laySeq[il-1]][layer][1:4]) 5823 XYZ += TX 5824 XYZT = XYZ.T 5825 XYZT[0] = XYZT[0]%1. 5826 XYZT[1] = XYZT[1]%1. 5827 XYZ = XYZT.T 5828 AtNames += atNames 5829 AtTypes += atTypes 5830 newXYZ = np.concatenate((newXYZ,XYZ)) 5831 XYZ = newXYZ 5832 na = int(8./cell[0]) 5833 nb = int(8./cell[1]) 5834 nunit = [na,nb,0] 5835 indA = range(-na,na) 5836 indB = range(-nb,nb) 5837 Units = np.array([[h,k,0] for h in indA for k in indB]) 5838 newXYZ = np.zeros((0,3)) 5839 for unit in Units: 5840 newXYZ = np.concatenate((newXYZ,unit+XYZ)) 5841 if len(Units): 5842 AtNames *= len(Units) 5843 AtTypes *= len(Units) 5844 XYZ = newXYZ 5845 Bonds = FindBonds(AtTypes,XYZ) 5852 getAtoms() 5846 5853 5854 def OnKeyBox(event): 5855 mode = cb.GetValue() 5856 if mode in ['jpeg','bmp','tiff',]: 5857 try: 5858 import Image as Im 5859 except ImportError: 5860 try: 5861 from PIL import Image as Im 5862 except ImportError: 5863 print "PIL/pillow Image module not present. Cannot save images without this" 5864 raise Exception("PIL/pillow Image module not found") 5865 projFile = G2frame.GSASprojectfile 5866 Fname = os.path.splitext(projFile)[0]+'.'+mode 5867 size = Page.canvas.GetSize() 5868 glPixelStorei(GL_UNPACK_ALIGNMENT, 1) 5869 if mode in ['jpeg',]: 5870 Pix = glReadPixels(0,0,size[0],size[1],GL_RGBA, GL_UNSIGNED_BYTE) 5871 im = Im.new("RGBA", (size[0],size[1])) 5872 else: 5873 Pix = glReadPixels(0,0,size[0],size[1],GL_RGB, GL_UNSIGNED_BYTE) 5874 im = Im.new("RGB", (size[0],size[1])) 5875 im.fromstring(Pix) 5876 im = im.transpose(Im.FLIP_TOP_BOTTOM) 5877 im.save(Fname,mode) 5878 cb.SetValue(' save as:') 5879 G2frame.G2plotNB.status.SetStatusText('Drawing saved to: '+Fname,1) 5880 5847 5881 def OnPlotKeyPress(event): 5882 global AtNames,AtTypes,XYZ,Bonds 5848 5883 if event.GetKeyCode() > 255: 5849 5884 return … … 5860 5895 Trans = Layers['Transitions'] 5861 5896 Yi,Xi = laySeq 5897 dxyz = 0.01 5862 5898 if keyCode == 'X': 5863 dx = 0.0015899 dx = dxyz 5864 5900 if event.shiftDown: 5865 5901 dx *= -1. 5902 Trans[Yi][Xi][1] += dx 5903 SetTransText(Yi,Xi,Trans[Yi][Xi],1) 5866 5904 elif keyCode == 'Y': 5867 dy = 0.0015905 dy = dxyz 5868 5906 if event.shiftDown: 5869 5907 dy *= -1. 5908 Trans[Yi][Xi][2] += dy 5909 SetTransText(Yi,Xi,Trans[Yi][Xi],2) 5870 5910 elif keyCode == 'Z': 5871 dz = 0.0015911 dz = dxyz 5872 5912 if event.shiftDown: 5873 5913 dz *= -1. 5874 Trans[Yi][Xi][1] += dx5875 Trans[Yi][Xi][2] += dy5876 Trans[Yi][Xi][3] += dz5914 Trans[Yi][Xi][3] += dz 5915 SetTransText(Yi,Xi,Trans[Yi][Xi],3) 5916 getAtoms() 5877 5917 Draw('shift') 5918 5919 def SetTransText(Yi,Xi,XYZ,id): 5920 page = G2frame.dataDisplay.GetSelection() 5921 if page: 5922 if G2frame.dataDisplay.GetPageText(page) == 'Layers': 5923 G2frame.dataDisplay.GetPage(page).transGrids[Yi].Refresh() 5878 5924 5879 5925 def OnMouseDown(event): … … 6040 6086 # print caller 6041 6087 # end of useful debug 6088 global AtNames,AtTypes,XYZ,Bonds 6042 6089 cPos = defaults['cameraPos'] 6043 6090 VS = np.array(Page.canvas.GetSize()) … … 6091 6138 view = False 6092 6139 altDown = False 6093 Page.Choice = (' key press','l: shift left','r: shift right','d: shift down','u: shift up', 6094 't: toggle labels',) 6140 choice = [' save as:','jpeg','tiff','bmp'] 6095 6141 Page.keyPress = OnPlotKeyPress 6096 6142 Page.SetFocus() 6097 6143 Font = Page.GetFont() 6144 cb = wx.ComboBox(G2frame.G2plotNB.status,style=wx.CB_DROPDOWN|wx.CB_READONLY,choices=choice) 6145 cb.Bind(wx.EVT_COMBOBOX, OnKeyBox) 6146 if len(laySeq) == 2: 6147 G2frame.G2plotNB.status.SetStatusText('Shift layer +/-XYZ key: X/shift-X, Y/shift-Y, Z/shift-Z; key: L - toggle atom labels',1) 6148 else: 6149 G2frame.G2plotNB.status.SetStatusText('L - toggle atom labels',1) 6098 6150 Page.canvas.Bind(wx.EVT_MOUSEWHEEL, OnMouseWheel) 6099 6151 Page.canvas.Bind(wx.EVT_LEFT_DOWN, OnMouseDown) -
trunk/GSASIIpwd.py
r2170 r2172 56 56 npT2stl = lambda tth, wave: 2.0*npsind(tth/2.0)/wave 57 57 npT2q = lambda tth,wave: 2.0*np.pi*npT2stl(tth,wave) 58 forln2 = 4.0*math.log(2.0) 58 59 59 60 #GSASII pdf calculation routines … … 1747 1748 param: background dict: background parameters 1748 1749 param: limits list: min/max 2-theta to be calculated 1749 param: inst dict: instrum net parameters dictionary1750 param: inst dict: instrument parameters dictionary 1750 1751 param: profile list: powder pattern data 1751 1752 … … 1782 1783 iFin = np.searchsorted(x0,limits[1]) 1783 1784 if iFin-iBeg > 20000: 1784 iFin = iBeg+19999 1785 x = x0[iBeg:iFin] 1786 dx = x0[iBeg+1]-x0[iBeg] 1785 iFin = iBeg+20000 1786 Dx = (x0[iFin]-x0[iBeg])/(iFin-iBeg) 1787 1787 cf = open('control.dif','w') 1788 1788 cf.write('GSASII-DIFFaX.dat\n0\n0\n3\n') 1789 cf.write('%. 3f %.3f %.3f\n1\n1\nend\n'%(x0[iBeg],x0[iFin],dx))1789 cf.write('%.6f %.6f %.6f\n1\n1\nend\n'%(x0[iBeg],x0[iFin],Dx)) 1790 1790 cf.close() 1791 1791 #make DIFFaX data file … … 1797 1797 df.write('NEUTRON\n') 1798 1798 df.write('%.4f\n'%(G2mth.getMeanWave(inst))) 1799 # df.write('GAUSSIAN 0.1 TRIM\n') #fast option - might not really matter 1800 df.write('PSEUDO-VOIGT 0.1 -0.036 0.009 0.6 TRIM\n') #slow - make a GUI option? 1799 U = forln2*inst['U'][1]/10000. 1800 V = forln2*inst['V'][1]/10000. 1801 W = forln2*inst['W'][1]/10000. 1802 HWHM = U*nptand(x0[iBeg:iFin]/2.)**2+V*nptand(x0[iBeg:iFin]/2.)+W 1803 HW = np.mean(HWHM) 1804 # df.write('PSEUDO-VOIGT 0.015 -0.0036 0.009 0.605 TRIM\n') 1805 # df.write('GAUSSIAN %.6f TRIM\n'%(HW)) #fast option - might not really matter 1806 df.write('GAUSSIAN %.6f %.6f %.6f TRIM\n'%(U,V,W)) #slow - make a GUI option? 1801 1807 df.write('STRUCTURAL\n') 1802 1808 a,b,c = Layers['Cell'][1:4] … … 1854 1860 subp.call(DIFFaX) 1855 1861 print 'DIFFaX time = %.2fs'%(time.time()-time0) 1856 X = np.loadtxt('GSASII-DIFFaX.spc') 1862 Xpat = np.loadtxt('GSASII-DIFFaX.spc').T 1863 iFin = iBeg+Xpat.shape[1] 1857 1864 bakType,backDict,backVary = SetBackgroundParms(background) 1858 1865 backDict['Lam1'] = G2mth.getWave(inst) 1859 1866 # GSASIIpath.IPyBreak() 1860 iB = np.searchsorted(profile[0],X.T[0])[0] 1861 iF = np.searchsorted(profile[0],X.T[-1])[0] 1862 if not iF: 1863 iF = -1 1864 profile[4][iB:iF] = getBackground('',backDict,bakType,inst['Type'][0],X.T[0])[0] 1865 profile[3][iB:iF] = X.T[1]*scale+profile[4][iB:iF] 1867 profile[4][iBeg:iFin] = getBackground('',backDict,bakType,inst['Type'][0],profile[0][iBeg:iFin])[0] 1868 profile[3][iBeg:iFin] = Xpat[2]*scale+profile[4][iBeg:iFin] 1866 1869 if not np.any(profile[1]): #fill dummy data x,y,w,yc,yb,yd 1867 rv = st.poisson(profile[3][iB :iF])1868 profile[1][iB :iF] = rv.rvs()1869 Z = np.ones_like(profile[3][iB :iF])1870 rv = st.poisson(profile[3][iBeg:iFin]) 1871 profile[1][iBeg:iFin] = rv.rvs() 1872 Z = np.ones_like(profile[3][iBeg:iFin]) 1870 1873 Z[1::2] *= -1 1871 profile[1][iB :iF] = profile[3][iB:iF]+np.abs(profile[1][iB:iF]-profile[3][iB:iF])*Z1872 profile[2][iB :iF] = np.where(profile[1][iB:iF]>0.,1./profile[1][iB:iF],1.0)1873 profile[5][iB :iF] = profile[1][iB:iF]-profile[3][iB:iF]1874 profile[1][iBeg:iFin] = profile[3][iBeg:iFin]+np.abs(profile[1][iBeg:iFin]-profile[3][iBeg:iFin])*Z 1875 profile[2][iBeg:iFin] = np.where(profile[1][iBeg:iFin]>0.,1./profile[1][iBeg:iFin],1.0) 1876 profile[5][iBeg:iFin] = profile[1][iBeg:iFin]-profile[3][iBeg:iFin] 1874 1877 1875 1878
Note: See TracChangeset
for help on using the changeset viewer.