# Changeset 430

Ignore:
Timestamp:
Nov 30, 2011 5:02:08 PM (10 years ago)
Message:

NB: There are a few stray print statements in this version
Some work on help stuff in GSASIIgrid.py
change default sum for constraints to 1.0
get data plots to include size & preferred orientation
modify plot toolbar - eliminate subplot button & add a Help button; doesn't do anything except recognize what plot it is from
Edited gsasII.html with Word - probably messed up all the bookmarks - but added a lot of text

Location:
trunk
Files:
5 edited

Unmodified
Removed
• ## trunk/GSASIIIO.py

 r428 File = open(filename,'Ur') cons = Bank.split() Nch = cons[2] print cons Nch = int(cons[2]) if DataType[2] == 'C': start = float(cons[5])/100.0               #CW: from centidegrees to degrees yi = max(sfloat(S[i+2:i+8]),0.0) if yi: ei = yi/ni vi = yi/ni else: yi = 0.0 ei = 1.0 vi = 1.0 j += 1 if j < Nch: x.append(xi) y.append(yi) w.append(1.0/ei) w.append(1.0/vi) print '%8.3f %8.0f %d %8g'%(xi,yi,ni,1./vi) S = File.readline() File.close() N = len(x) print N return [np.array(x),np.array(y),np.array(w),np.zeros(N),np.zeros(N),np.zeros(N)]

• ## trunk/GSASIIplot.py

 r428 from OpenGL.GLUT import * from OpenGL.GLE import * from matplotlib.backends.backend_wx import _load_bitmap from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg as Canvas from matplotlib.backends.backend_wxagg import NavigationToolbar2Wx as Toolbar self.figure = mpl.figure.Figure(dpi=dpi,figsize=(5,7)) self.canvas = Canvas(self,-1,self.figure) self.toolbar = Toolbar(self.canvas) self.toolbar = GSASIItoolbar(self.canvas) self.toolbar.Realize() self.figure = mpl.figure.Figure(dpi=dpi,figsize=(6,6)) self.canvas = Canvas(self,-1,self.figure) self.toolbar = Toolbar(self.canvas) self.toolbar = GSASIItoolbar(self.canvas) self.toolbar.Realize() self.status.SetStatusText('Better to select this from GSAS-II data tree',1) self.status.DestroyChildren()                           #get rid of special stuff on status bar class GSASIItoolbar(Toolbar): ON_MPL_HELP = wx.NewId() def __init__(self,plotCanvas): Toolbar.__init__(self,plotCanvas) POSITION_OF_CONFIGURE_SUBPLOTS_BTN = 6 self.DeleteToolByPos(POSITION_OF_CONFIGURE_SUBPLOTS_BTN) help = os.path.join(os.path.split(sys.argv[0])[0],'help.ico') self.AddSimpleTool(self.ON_MPL_HELP,_load_bitmap(help),'Help on','Show help on') wx.EVT_TOOL(self,self.ON_MPL_HELP,self.OnHelp) def OnHelp(self,event): Page = self.GetParent().GetParent() pageNo = Page.GetSelection() print 'Matplotlib help on '+Page.GetPageText(pageNo) def PlotSngl(self,newPlot=False): Page.canvas.draw() def PlotStrain(self,data): '''Plot 3D microstrain figure. In this instance data is for a phase def PlotSizeStrainPO(self,data,Start=False): '''Plot 3D mustrain/size/preferred orientation figure. In this instance data is for a phase ''' PatternId = self.PatternId generalData = data['General'] SGData = generalData['SGData'] SGLaue = SGData['SGLaue'] if Start:                   #initialize the spherical harmonics qlmn arrays ptx.pyqlmninit() Start = False MuStrKeys = G2spc.MustrainNames(SGData) cell = generalData['Cell'][1:] Vol = cell[6] useList = data['Histograms'] phase = generalData['Name'] plotType = generalData['Data plot type'] plotDict = {'Mustrain':'Mustrain','Size':'Size','Preferred orientation':'Pref.Ori.'} for ptype in plotDict: self.G2plotNB.Delete(ptype) for item in useList: if useList[item]['Show']: break else: self.G2plotNB.Delete('Microstrain') return            #nothing to show!! numPlots = len(useList) try: plotNum = self.G2plotNB.plotList.index('Microstrain') Page = self.G2plotNB.nb.GetPage(plotNum) Page.figure.clf() Plot = mp3d.Axes3D(Page.figure) if not Page.IsShown(): Page.Show() except ValueError: Plot = mp3d.Axes3D(self.G2plotNB.add3D('Microstrain')) plotNum = self.G2plotNB.plotList.index('Microstrain') Page = self.G2plotNB.nb.GetPage(plotNum) if plotType in ['Mustrain','Size']: Plot = mp3d.Axes3D(self.G2plotNB.add3D(plotType)) else: Plot = self.G2plotNB.addMpl(plotType).gca() plotNum = self.G2plotNB.plotList.index(plotType) Page = self.G2plotNB.nb.GetPage(plotNum) Page.SetFocus() self.G2plotNB.status.SetStatusText('Adjust frame size to get desired aspect ratio',1) if not Page.IsShown(): Page.Show() for item in useList: if useList[item]['Show']: muStrain = useList[item]['Mustrain'] PHI = np.linspace(0.,360.,30,True) PSI = np.linspace(0.,180.,30,True) Y = np.outer(npcosd(PHI),npsind(PSI)) Z = np.outer(np.ones(np.size(PHI)),npcosd(PSI)) if muStrain[0] == 'isotropic': #                muiso = muStrain[1][0]*math.pi/0.018      #centidegrees to radians! muiso = muStrain[1][0] X *= muiso Y *= muiso Z *= muiso elif muStrain[0] == 'uniaxial': def uniaxMustrain(xyz,muiso,muaniso,axes): Z = np.array(axes) cp = abs(np.dot(xyz,Z)) sp = np.sqrt(1.-cp**2) R = muiso*muaniso/np.sqrt((muiso*cp)**2+(muaniso*sp)**2) #                    S = muiso+muaniso*cp           #old GSAS - wrong math!! #                    return R*xyz*math.pi/0.018      #centidegrees to radians! return R*xyz muiso,muaniso = muStrain[1][:2] axes = np.inner(A,np.array(muStrain[3])) axes /= nl.norm(axes) Shkl = np.array(muStrain[1]) Shape = X.shape[0] XYZ = np.dstack((X,Y,Z)) XYZ = np.nan_to_num(np.apply_along_axis(uniaxMustrain,2,XYZ,muiso,muaniso,axes)) X,Y,Z = np.dsplit(XYZ,3) X = X[:,:,0] Y = Y[:,:,0] Z = Z[:,:,0] elif muStrain[0] == 'generalized': def genMustrain(xyz,SGData,A,Shkl): uvw = np.inner(A.T,xyz) Strm = np.array(G2spc.MustrainCoeff(uvw,SGData)) sum = np.sum(np.multiply(Shkl,Strm)) sum = np.where(sum > 0.01,sum,0.01) sum = np.sqrt(sum)*math.pi/0.018      #centidegrees to radians! return sum*xyz Shkl = np.array(muStrain[4]) if np.any(Shkl): coeff = useList[item][plotDict[plotType]] if plotType in ['Mustrain','Size']: if coeff[0] == 'isotropic': X *= coeff[1][0] Y *= coeff[1][0] Z *= coeff[1][0] elif coeff[0] == 'uniaxial': def uniaxCalc(xyz,iso,aniso,axes): Z = np.array(axes) cp = abs(np.dot(xyz,Z)) sp = np.sqrt(1.-cp**2) R = iso*aniso/np.sqrt((iso*cp)**2+(aniso*sp)**2) return R*xyz iso,aniso = coeff[1][:2] axes = np.inner(A,np.array(coeff[3])) axes /= nl.norm(axes) Shkl = np.array(coeff[1]) Shape = X.shape[0] XYZ = np.dstack((X,Y,Z)) XYZ = np.nan_to_num(np.apply_along_axis(genMustrain,2,XYZ,SGData,A,Shkl)) XYZ = np.nan_to_num(np.apply_along_axis(uniaxCalc,2,XYZ,iso,aniso,axes)) X,Y,Z = np.dsplit(XYZ,3) X = X[:,:,0] Y = Y[:,:,0] Z = Z[:,:,0] elif coeff[0] == 'generalized': if np.any(X) and np.any(Y) and np.any(Z): Plot.plot_surface(X,Y,Z,rstride=1,cstride=1,color='g',linewidth=1) def genMustrain(xyz,SGData,A,Shkl): uvw = np.inner(A.T,xyz) Strm = np.array(G2spc.MustrainCoeff(uvw,SGData)) sum = np.sum(np.multiply(Shkl,Strm)) sum = np.where(sum > 0.01,sum,0.01) sum = np.sqrt(sum)*math.pi/0.018      #centidegrees to radians! return sum*xyz Shkl = np.array(coeff[4]) if np.any(Shkl): Shape = X.shape[0] XYZ = np.dstack((X,Y,Z)) XYZ = np.nan_to_num(np.apply_along_axis(genMustrain,2,XYZ,SGData,A,Shkl)) X,Y,Z = np.dsplit(XYZ,3) X = X[:,:,0] Y = Y[:,:,0] Z = Z[:,:,0] elif coeff[0] == 'ellipsoidal': print 'ellipsoid plot' if np.any(X) and np.any(Y) and np.any(Z): Plot.plot_surface(X,Y,Z,rstride=1,cstride=1,color='g',linewidth=1) if plotType == 'Size': Plot.set_title('Crystallite size for '+phase) Plot.set_xlabel(r'X, $\mu$m') Plot.set_ylabel(r'Y, $\mu$m') Plot.set_zlabel(r'Z, $\mu$m') else: Plot.set_title(r'$\mu$strain for '+phase) Plot.set_xlabel(r'X, $\mu$strain') Plot.set_ylabel(r'Y, $\mu$strain') Plot.set_zlabel(r'Z, $\mu$strain') else: h,k,l = generalData['POhkl'] if coeff[0] == 'MD': print 'March-Dollase preferred orientation plot' Plot.set_xlabel('X') Plot.set_ylabel('Y') Plot.set_zlabel('Z') else: PH = np.array(generalData['POhkl']) phi,beta = G2lat.CrsAng(PH,cell[:6],SGData) SHCoef = {} for item in coeff[5]: L,N = eval(item.strip('C')) SHCoef['C%d,0,%d'%(L,N)] = coeff[5][item] ODFln = G2lat.Flnh(Start,SHCoef,phi,beta,SGData) X = np.linspace(0,90.0,26) Y = G2lat.polfcal(ODFln,'0',X,0.0) Plot.plot(X,Y,color='k',label=str(PH)) Plot.legend(loc='best') Plot.set_title('Axial distribution for HKL='+str(PH)+' in '+phase) Plot.set_xlabel(r'$\psi$',fontsize=16) Plot.set_ylabel('MRD',fontsize=14) Page.canvas.draw() SGData = generalData['SGData'] textureData = generalData['SH Texture'] self.G2plotNB.Delete('Texture') if not textureData['Order']: self.G2plotNB.Delete('Texture') return                  #no plot!! SHData = generalData['SH Texture'] self.G2plotNB.status.SetFields(['', 'psi =%9.3f, beta =%9.3f, MRD =%9.3f xyz=%5.2f,%5.2f,%5.2f'%(r,p,ipf,x,y,z)]) 'psi =%9.3f, beta =%9.3f, MRD =%9.3f hkl=%5.2f,%5.2f,%5.2f'%(r,p,ipf,x,y,z)]) elif 'Axial' in SHData['PlotType']: self.G2plotNB.status.SetFields(['','phi =%9.3f, gam =%9.3f, MRD =%9.3f'%(r,p,pf)]) try: plotNum = self.G2plotNB.plotList.index('Texture') Page = self.G2plotNB.nb.GetPage(plotNum) Page.figure.clf() Plot = Page.figure.gca() if not Page.IsShown(): Page.Show() except ValueError: Plot = self.G2plotNB.addMpl('Texture').gca() plotNum = self.G2plotNB.plotList.index('Texture') Page = self.G2plotNB.nb.GetPage(plotNum) Page.canvas.mpl_connect('motion_notify_event', OnMotion) Plot = self.G2plotNB.addMpl('Texture').gca() plotNum = self.G2plotNB.plotList.index('Texture') Page = self.G2plotNB.nb.GetPage(plotNum) Page.canvas.mpl_connect('motion_notify_event', OnMotion) Page.SetFocus()
• ## trunk/help/gsasII.html

 r427 Help for GSAS-II

Help for GSAS-II

This is where to find help on various GSAS-II windows.

GSAS-II data tree

This is a hierarchical view of the data items in the current project. Clicking on any item in the window opens a view where information in that item can be viewed or edited. For example, the "Sample Parameters" item contains information about how data were collected, such as the sample temperature (see below).

Atoms Control Window

This window...

Constraints Control Window

This window...

Restraints Control Window

This window...

DiffractionData Control Window

This window...

Draw Atoms Control Window

This window...

Pawley Control Window

This window...

Index Peaks Control Window

This window...

Images Control Window

This window...

Background Control Window

This window...

Limits Control Window

This window...

Instrument Parameters Control Window

This window...

This window...

Sample Parameters Control Window

This window...

Powder Peaks Control Window

This window...

Cell Indexing/Refine Control Window

This window...

Reflection List Control Window

This window...

Texture Control Window

This window...

PDF Controls Control Window

This window...

Help for GSAS-II

This is where to find help on various GSAS-II windows and plots.

GSAS-II data tree

This is a hierarchical view of the data items in your GSAS-II project (name.gpx). Clicking on any item in the window opens a view where information in that item can be viewed or edited. For example, the "Sample Parameters" item contains information about how data were collected, such as the sample temperature (see below).

What can I do here?

a.       Open project… - Open a previously saved GSAS-II project file (name.gpx). If you currently have a project file open, you are asked if it is OK to over write it; Cancel will cancel the process.

b.      Save project – Save the current project. If a file name is shown after ‘Loaded Data:’, it will be saved there. Otherwise, you will be prompted for a new name in a file dialog (you may change directory as well). If the file exists, you will be asked if it OK to overwrite.

c.       Save As… - Save the current project to a new file. A file dialog will be shown to enter the name (and change directory if desired). If the file exists, you will be asked if it OK to overwrite.

d.      Close project – Close the current project; you will be asked if you want to save it first.

e.       Exit – Exit the GSAS-II program; if there is a current project you will be asked if you want to save it first. Pressing the red X in the upper right (Windows) also exits (no save option) GSAS-II; useful for escaping from GSAS-II if needed.

a.       Read powder data… - Read in powder diffraction patterns (multiple patterns can be selected). GSAS-II can read most of the old GSAS powder format files with the position in centidegrees 2-theta. It can also read “xye” format files used by topas where the position is in degrees 2-theta. As each file is read, an old GSAS style “instrument parameter file” is searched for; if not found a CuKa laboratory data set is assumed.

c.       Read Powder Pattern Peaks… -

d.      Read single crystal data… -

e.       Sum powder data -

f.       Sum image data -

h.      Delete phase -

i.        Rename data -

j.        Delete data -

a.       Make new PDFs -

b.      View LS parms -

c.       Refine -

d.      Sequential refine -

e.       Solve -

a.       Import GSAS Exp phase… -

b.      Import PDB phase… -

c.       Import CIF phase… -

d.      Import HKLs… -

a.       Export Powder Patterns… -

b.      Export All Peak Lists… -

c.       Export HKLs… -

d.      Export PDF… -

e.       Export Phase… -

f.       Export CIF… -

Notebook

This window provides a place for you to enter whatever text commentary you wish. Each time you enter this window, a date/time entry is provided for you. A possibly useful technique is to select a portion of the console window after a refinement completes (it will contain refinement results with residuals, new values & esds) and paste it into this Notebook window so it becomes a part of your project file.

Controls

This window provides the main controls for the major calculations in GSAS-II. At present only Refinement Controls are presented.

The main refinement tools are the fortran MINPACK lmdif and lmder algorithms wrapped in python as provided in the Scipy package. Their purpose is to minimize the sum of the squares of M nonlinear functions in N variables by a modification of the Levenberg-Marquardt algorithm as written by Burton S. Garbow, Kenneth E. Hillstrom, Jorge J. More (Argonne National Laboratory, 1980).

What can I do here?

1.      Select whether the refinement uses ‘analytic’ or ‘numeric’ derivatives. The latter is slower and perhaps a bit less accurate, but may be needed if the analytic functions are not fully developed. Generally use ‘analytic’ for routine work.

2.      Select ‘Min delta-M/M’ for convergence; the refinement will stop when the change in the minimization function is less than this value. Set Min delta-M/M = 1.0 to force just a single cycle to be performed. A value less than 10-4 (the default) generally gives no better result. The allowed range is 10-9 to 1.0.

3.      Select ‘Initial shift factor’ for the first cycle of refinement. This value is modified by the least squares routine. The allowed range is 10-5 to 100. Smaller values may be needed if your initial refinement trials immediately diverge, however make sure your starting parameter values are ‘reasonable’. The selected default (=1.0) normally gives good performance.

4.      Select data for sequential refinement; the data sets may be done in ‘reverse order’.

Covariance

This window is blank; the GSASII Plots window ‘Covariance’ shows a graphical representation of the variance-covariance matrix

Constraints

This window shows the constraints to be used in a refinement. It is organized into three tabbed pages. ‘Phase constraints’ contain those involving parameters that describe aspects of the crystalline phases to be used in the refinement (e.g. atom coordinates, thermal motion and site fraction parameters). ‘Histogram/Phase constraints’ are those which describe aspects of the pattern that depend on both the phase and the data set used in the refinement (e.g. mstrain and crystallite size parameters). ‘Histogram constraints’ are those that depend only on the data set (e.g. profile coefficients U,V,W,X and Y).

What can I do here?

1.      Select the tab for the parameter types you wish to constrain. Each will have the same possibilities in the ‘Edit menu.

a.       Add Hold – select a parameter that you wish to remain fixed although other parameters of the same type may be selected as a group for refinement. For example, if the space group for a phase has a polar axis (e.g. the b-axis in P21), then one atom y-parameter is arbitrary and should be selected for a Hold to keep the structure from drifting up or down the y-axis during refinement. If selected, a dialog box will appear showing the list of available parameters; select one and then OK to implement it, Cancel will cancel the operation. The held parameter will be shown in the constraint window with the keyword ‘FIXED’. A Delete button can be used to remove it.

b.      Add equivalence – select a list of parameters that should have the same value (possibly with a non-unitary multiplier for some). Examples are a list of atoms with the same thermal motion Uiso, sets of profile coefficients U,V,W across multiple data sets. If selected, a dialog box will appear with a list of the available parameters. Select one and press OK; a second dialog box will appear with only those parameters that can be made equivalent to the first one. Choose those and press OK. Cancel in either dialog will cancel the operation. The equivalenced parameters will show as an equation of the form M1*P1+M2*P2=0; usually M1=1.0 and M2=-1.0, but can be changed via the ‘Edit’ button. The keyword ‘EQUIV’ marks it as an equivalence. A Delete button can be used to remove it.

c.       Add constraint – select a list of parameters whose sum (with possible non-unitary multipliers) is fixed. For example, the sum of site fractions for atoms on the same site could be fixed to unity. If selected, a dialog box will appear with a list of the available parameters. Select one and press OK; a second dialog box will appear with only those parameters that can be used in a constraint with the first one. Choose those and press OK. Cancel in either dialog will cancel the operation. The equivalenced parameters will show as an equation of the form M1*P1+M2*P2+…=C; the multipliers M1, M2, … and C can be changed via the ‘Edit’ button. The keyword ‘CONSTR’ marks it as a constraint. A Delete button can be used to remove it.

d.      Add function – this is very similar the “Add constraint” type except that the result of the sum can be varied in the refinement. The keyword ‘FUNCT’ marks it as a function; the ‘Refine?’ box indicates your choice to refine the result of the sum. A Delete button can be used to remove it.

Restraints

This window...

Limits

This window shows the limits in position to be used in any fitting for this powder pattern. The ‘original’ values are obtained from the minimum & maximum values in the powder pattern. You can modify ‘changed’ as needed.

What can I do here?

1.      Menu ‘File’ – Copy - this copies the limits shown to other selected powder patterns. If used, a dialog box (Copy Limits) will appear showing the list of available powder patterns, you can copy the limits to any or all of them; select ‘All’ to copy them to all patterns. Then select ‘OK’ to do the copy; ‘Cancel’ to cancel the operation.

2.      You can change Tmin and Tmax in the ‘changed’ row as needed. Use the mouse to select the value to be changed (the background on the box will be blue or have a black border or a vertical bar will appear in the value), then enter the new value and press Enter or click the mouse elsewhere in the Background window. This will set the new value.

Background

This window shows the choice of background function and coefficients to be used in fitting this powder pattern.

What can I do here?

1.      Menu ‘File’ – Copy – this copies the background parameters shown to other selected powder patterns. If used, a dialog box (Copy Parameters) will appear showing the list of available powder patterns, you can copy the background parameters to any or all of them; select ‘All’ to copy them to all patterns. Then select ‘OK’ to do the copy; ‘Cancel’ to cancel the operation.

2.      You can select a different Background function from the pull down tab.

3.      You can choose to refine/not refine the background coefficients.

4.      You can select the number of background coefficients to be used (1-36).

5.      You can change individual background coefficient values. Enter the value then press Enter or click the mouse elsewhere in the Background window. This will set the new value.

Instrument Parameters

This window...

Sample Parameters

This window...

Peak List

This window shows the list of peaks that will be used by the peak fitting refinement. It is filled by picking peaks in the powder pattern displayed in the GSASII Plots window as a sequence of ‘+’ marks. See Powder Patterns below for details for what can be done on this plot.

Index Peak List

This window shows the list of peaks that will be used for indexing (see Unit Cells List). It must be filled before indexing can proceed. When indexing is completed, this display will show the resulting hkl values for every indexed reflection along with the calculated d-spacing (‘d-calc’) for the selected unit cell in Unit Cells List.

What can I do here?

1.      Menu ‘Operations’ – Load/Reload – loads the peak positions & intensities from the Peak List to make them available for the indexing routine. The d-obs is obtained from Bragg’s Law after applying the Zero correction shown on the Instrument Parameters table to the position shown here.

2.      You may deselect individual peaks from indexing by unchecking the corresponding ‘use’ box.

Unit Cells List

This window...

Reflection List

This window...

Texture Control Window

This window...

This window...

Atoms Control Window

This window...

Diffraction Data Control Window

This window...

Draw Atoms Control Window

This window...

Pawley Control Window

This window...

Images Control

This window...

PDF Controls Control Window

This window...

GSASII Plots

This window presents all the graphical material as a multipage tabbed set of plots utilizing the matplotlib python package. Each page has a tool bar (at bottom in Windows) with the controls

These are Home, Back, Forward, Pan, Zoom, Save and Help, respectively. The Pan option allows you to control panning across the plot (press left mouse button) and zooming (press right mouse button), the Zoom option allows you to select a portion of the plot (press right mouse button & drag for zoom box) for the next plot. The Save allows you to save the currently displayed plot in one of several graphical formats suitable for printing or insertion in a document. The Help icon is for access to this GSASII help.

Below the toolbar may be a status bar that on the left may show either an instruction for a keyed input or a pull down selection of keyed input; on the right may be displayed position dependent information that is updated as the mouse is moved over the plot region.

The specific types of plots that are pages in the GSASII Plots windows are next.

Powder Patterns

The powder patterns that are part of your project are shown on this page. They can be displayed as a stack of powder patterns, just a single pattern or as a contour image of the peak intensities. What can be done here will depend on which is displayed and on which item in the GSAS-II data tree you have selected.

Covariance

The variance-covariance matrix as a color coded array is shown on this page. The color bar to the right shows the range of covariances (-1 to 1) and corresponding colors. The parameter names are to the right and the parameter numbers are below the plot.

What can I do here?

1.      Move the mouse cursor across the plot. If on a diagonal cell, the parameter name, value and esd is shown both as a tool tip and in the right hand portion of the status bar. If the cursor is off the diagonal, the two parameter names and their covariance are shown in the tool tip and the status bar.

2.      Type ‘s’ – A color scheme selection dialog is shown. Select a color scheme and press OK, the new color scheme will be plotted. The default is ‘RdYlGn’.