1 | <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN"> |
---|
2 | <html> <head> |
---|
3 | <title>Scripting GSAS-II</title> |
---|
4 | </head> |
---|
5 | |
---|
6 | <body> |
---|
7 | <h1>Running a GSAS-II Refinement From a Python Script</h1> |
---|
8 | In this training example we create a Python script to duplicate the |
---|
9 | refinement in the |
---|
10 | <A |
---|
11 | href="https://subversion.xray.aps.anl.gov/pyGSAS/Tutorials/CWCombined/Combined%20refinement.htm" |
---|
12 | target="_blank">GSAS-II CW Combined Refinement</A> |
---|
13 | tutorial. This uses the |
---|
14 | <A href="http://gsas-ii.readthedocs.io/en/latest/GSASIIscripts.html" target="_blank"> |
---|
15 | GSASIIscriptable module</A> |
---|
16 | to perform the same refinements steps, but without use of the GSAS-II |
---|
17 | graphical user interface. |
---|
18 | |
---|
19 | <h2>Prerequisites</h2> |
---|
20 | This exercise assumes that the reader has reasonable familiarity with |
---|
21 | the Python language. |
---|
22 | Also, the documentation on the |
---|
23 | <A href="http://gsas-ii.readthedocs.io/en/latest/GSASIIscripts.html" |
---|
24 | target="_blank"> |
---|
25 | Scripting Tools in the GSAS-II GSASIIscriptable module</A> should be |
---|
26 | read from here: <A href="http://gsas-ii.readthedocs.io/en/latest/GSASIIscripts.html" |
---|
27 | target="_blank">http://gsas-ii.readthedocs.io/en/latest/GSASIIscripts.html</A>. It |
---|
28 | is also wise to read the <A href="https://subversion.xray.aps.anl.gov/pyGSAS/Tutorials/CWCombined/Combined%20refinement.htm" |
---|
29 | target="_blank">GSAS-II CW Combined Refinement</A> tutorial that this |
---|
30 | exercise is modeled upon, which explains why each refinement step is |
---|
31 | being used. |
---|
32 | <P> |
---|
33 | The exercise can be performed by placing all of the Python commands |
---|
34 | into a script, (which can also be |
---|
35 | <A href="https://subversion.xray.aps.anl.gov/trac/pyGSAS/export/3131/Tutorials/PythonScript/data/example.py"> |
---|
36 | downloaded here</A>), |
---|
37 | but a more pedagogical approach will be to enter the |
---|
38 | commands into a Python interpreter. Use of IPython or Jupyter to run |
---|
39 | Python will make this a more pleasant experience. |
---|
40 | |
---|
41 | <h2>Multi-step Script Approach</h2> |
---|
42 | |
---|
43 | <h4>0: Load the GSASIIscriptable module</H4> |
---|
44 | <blockquote> |
---|
45 | The first step in writing any Python module is to load the modules |
---|
46 | that will be needed. Here we will need the <tt>os</tt> and |
---|
47 | <tt>sys</tt> modules from the Python standard library and the |
---|
48 | GSASIIscriptable from the GSAS-II code. The location where the |
---|
49 | GSAS-II source code is installed must usually be hard-coded into the |
---|
50 | script as is done in the example below. Note that a common location |
---|
51 | for this will be |
---|
52 | <TT>os.path.expanduser("~/g2conda/GSASII/")</TT> or |
---|
53 | <tt>'/Users/toby/software/GSASII'</tt>, etc. |
---|
54 | Thus the script will begin with something like this: |
---|
55 | |
---|
56 | <blockquote><textarea rows="3" cols="60" readonly> |
---|
57 | import os,sys |
---|
58 | sys.path.insert(0,os.path.expanduser("~/g2conda/GSASII/")) |
---|
59 | import GSASIIscriptable as G2sc</textarea></blockquote> |
---|
60 | |
---|
61 | If a <tt>ImportError: No module named GSASIIscriptable</tt> error |
---|
62 | occurs, then the wrong directory location has been supplied for the |
---|
63 | GSAS-II files. |
---|
64 | </blockquote> |
---|
65 | |
---|
66 | <h4>1: Define some other prerequisite code</H4> |
---|
67 | <blockquote> |
---|
68 | To simplify this example, we will define the location where files will |
---|
69 | be written as <tt>workdir</tt> (this directory must exist, but it may |
---|
70 | be empty) and the location where the input files for this exercise may |
---|
71 | be found as <tt>datadir</tt>. (Note that this directory must have the |
---|
72 | the following files: "PBSO4.XRA", "INST_XRY.PRM", "PBSO4.CWN", |
---|
73 | "inst_d1a.prm" and "PbSO4-Wyckoff.cif". These files can be downloaded |
---|
74 | from |
---|
75 | <A href="https://subversion.xray.aps.anl.gov/pyGSAS/Tutorials/PythonScript/data/"> |
---|
76 | https://subversion.xray.aps.anl.gov/pyGSAS/Tutorials/PythonScript/data/</A>) |
---|
77 | <P> |
---|
78 | We also define here a short function to display the weighted profile R |
---|
79 | factor for every histogram in a project, <tt>HistStats</tt>. This will |
---|
80 | be <A href="#HistStats">discussed later</A>. |
---|
81 | |
---|
82 | <blockquote><textarea rows="10" cols="70" readonly> |
---|
83 | workdir = "/Users/toby/Scratch/PythonScript" |
---|
84 | datadir = "/Users/toby/software/G2/Tutorials/PythonScript/data" |
---|
85 | |
---|
86 | def HistStats(gpx): |
---|
87 | '''prints profile rfactors for all histograms''' |
---|
88 | print(u"*** profile Rwp, "+os.path.split(gpx.filename)[1]) |
---|
89 | for hist in gpx.histograms(): |
---|
90 | print("\t{:20s}: {:.2f}".format(hist.name,hist.get_wR())) |
---|
91 | print("") |
---|
92 | gpx.save()</textarea></blockquote> |
---|
93 | |
---|
94 | </blockquote> |
---|
95 | |
---|
96 | <h4>2: Create a GSAS-II project</H4> |
---|
97 | <blockquote> |
---|
98 | The first step in creating a GSASIIscriptable script to to create or |
---|
99 | access a GSAS-II project, which is done with a call to |
---|
100 | <TT>GSASIIscriptable.G2Project()</tt>. This can be done in one of two |
---|
101 | ways: a call with <tt>G2sc.G2Project(filename=</tt><I>file</I><tt>)</tt> creates a new |
---|
102 | (empty) project, while a call with |
---|
103 | <tt>G2sc.G2Project(gpxfile=</tt><I>file</I><tt>)</tt> opens and |
---|
104 | reads an existing project (.gpx) file. Both return a <tt>G2Project</tt> wrapper |
---|
105 | object that is used to access a number of methods and variables. |
---|
106 | Note that <TT>GSASIIscriptable.G2Project()</tt> can read .gpx files |
---|
107 | written by both previous <TT>GSASIIscriptable.G2Project()</tt> runs or |
---|
108 | the GSAS-II GUI. |
---|
109 | <P> |
---|
110 | In this example, we create a new project by using the |
---|
111 | <tt>filename=</tt><I>file</I> argument with this code: |
---|
112 | |
---|
113 | <blockquote><textarea rows="3" cols="70" readonly> |
---|
114 | # create a project with a default project name |
---|
115 | gpx = G2sc.G2Project(filename='PbSO4.gpx')</textarea></blockquote> |
---|
116 | |
---|
117 | Note that the file will not actually be created until an operation |
---|
118 | that saves the project is called. |
---|
119 | </blockquote> |
---|
120 | |
---|
121 | <h4>3: Add Histograms and Phase to the GSAS-II project</H4> |
---|
122 | <blockquote> |
---|
123 | To add two powder diffraction datasets (histograms) and a phase to the |
---|
124 | project using this code: |
---|
125 | |
---|
126 | <blockquote><textarea rows="10" cols="70" readonly> |
---|
127 | # setup step 1: add two histograms to the project |
---|
128 | hist1 = gpx.add_powder_histogram(os.path.join(datadir,"PBSO4.XRA"), |
---|
129 | os.path.join(datadir,"INST_XRY.PRM")) |
---|
130 | hist2 = gpx.add_powder_histogram(os.path.join(datadir,"PBSO4.CWN"), |
---|
131 | os.path.join(datadir,"inst_d1a.prm")) |
---|
132 | # setup step 2: add a phase and link it to the previous histograms |
---|
133 | phase0 = gpx.add_phase(os.path.join(datadir,"PbSO4-Wyckoff.cif"), |
---|
134 | phasename="PbSO4", |
---|
135 | histograms=[hist1,hist2])</textarea></blockquote> |
---|
136 | |
---|
137 | |
---|
138 | We use the <I>project</I><tt>.add_powder_histogram()</tt> method in |
---|
139 | the <TT>GSASIIscriptable</tt> class to read in the powder data. |
---|
140 | The two arguments to |
---|
141 | <tt>.add_powder_histogram()</tt> are the powder dataset and the |
---|
142 | instrument parameter file. Note that these files are both "GSAS |
---|
143 | powder data" files and the importer for this format (and many |
---|
144 | others) allows files with arbitrary extensions to be read. |
---|
145 | All importers that allow for extensions .XRA and .CWN will be |
---|
146 | used to attempt to read the file, producing a number of warning |
---|
147 | messages. To specify that only the GSAS powder data importer be |
---|
148 | used, include a third argument, <tt>fmthint="GSAS powder"</tt> or |
---|
149 | something similar (<tt>fmthint="GSAS"</tt> is also fine, but will |
---|
150 | cause both the "GSAS powder data" and the "GSAS-II .gpx" importer to be considered.) |
---|
151 | <UL><LI> |
---|
152 | Note that <I>project</I><tt>.add_powder_histogram()</tt> returns a |
---|
153 | powder histogram objects, which here are saved for later reference. It is |
---|
154 | also possible to obtain these using <tt>gpx.histograms()</tt>, which |
---|
155 | returns a list of defined histograms. |
---|
156 | </UL> |
---|
157 | <P> |
---|
158 | Then we add a phase to the project using |
---|
159 | <I>project</I><tt>.add_phase()</tt>. This specifies a CIF containing the |
---|
160 | structural information, a name for the phase and specifies that the |
---|
161 | two histograms are "added" (linked) to the phase. The |
---|
162 | <tt>fmthint="CIF"</tt> parameter can also optionally be specified to limit the |
---|
163 | importers that will be tried. |
---|
164 | |
---|
165 | <UL><LI> |
---|
166 | Note that <I>project</I><tt>.add_phase()</tt> |
---|
167 | returns a phase object</li> |
---|
168 | <LI>Also, the previously saved histogram objects are used in the |
---|
169 | <I>project</I><tt>.add_phase()</tt> call. Note that it is |
---|
170 | also possible to reference the two histgrams by their numbers in the |
---|
171 | project (here <tt>histograms=[0,1]</tt>) or by the histogram names |
---|
172 | (here <BR><TT>histograms=['PWDR PBSO4.XRA Bank 1', 'PWDR PBSO4.CWN |
---|
173 | Bank 1']</TT>). |
---|
174 | These three ways to use the <tt>histograms</tt> parameter produce |
---|
175 | the same result. |
---|
176 | </blockquote> |
---|
177 | |
---|
178 | <A name="ChangeCycles"> |
---|
179 | <h4>4: Change the number of refinement cycles</H4> |
---|
180 | </A><blockquote> |
---|
181 | While this is not noted in the original tutorial, this exercise will |
---|
182 | not complete properly if more variables are added to the refinement |
---|
183 | without converging the refinement (or at least coming close to |
---|
184 | convergence) at each refinement step. This is best accomplished by |
---|
185 | increasing the number of least-squares cycles. No supplied method (at |
---|
186 | present) allows this parameter to be set straightforwardly, but this |
---|
187 | code will do this: |
---|
188 | |
---|
189 | <blockquote><textarea rows="3" cols="70" readonly> |
---|
190 | # not in tutorial: increase # of cycles to improve convergence |
---|
191 | gpx.data['Controls']['data']['max cyc'] = 8 # not in API </textarea></blockquote> |
---|
192 | |
---|
193 | <P> |
---|
194 | To find this parameter in the GSAS-II data structure, I followed |
---|
195 | these steps: In the GUI, Controls is the tree item |
---|
196 | corresponding to the section where Least Squares cycles are |
---|
197 | set. Executing the command <tt>gpx.data.keys()</tt> shows the names of the |
---|
198 | entries in the dictionary corresponding to the GSAS-II tree and |
---|
199 | indeed one entry is 'Controls'. |
---|
200 | Command <tt>gpx.data['Controls'].keys()</tt> shows that all |
---|
201 | values are located in an entry labeled 'data' and |
---|
202 | <tt>gpx.data['Controls']['data'].keys()</tt> shows the entries in |
---|
203 | this section. Examination of |
---|
204 | <tt>gpx.data['Controls']['data']['max cyc']</tt> shows the value 3, |
---|
205 | which is default number of cycles. Thus, |
---|
206 | the number of cycles is changed with the Python command above. |
---|
207 | |
---|
208 | </blockquote> |
---|
209 | |
---|
210 | <h4>5: Set initial variables and refine</H4> |
---|
211 | <blockquote> |
---|
212 | |
---|
213 | In Step 4 of the original tutorial, the refinement is performed with |
---|
214 | the variables that are on by default. These variables are the two |
---|
215 | histogram scale factors and three background parameters for each |
---|
216 | histogram (8 in total). With GSASIIscriptable, the background |
---|
217 | refinement flags are not turned on by default, so a dictionary must be |
---|
218 | created to set these histogram variables. This code: |
---|
219 | <blockquote><textarea rows="5" cols="75" readonly> |
---|
220 | # tutorial step 4: turn on background refinement (Hist) |
---|
221 | refdict0 = {"set": {"Background": { "no. coeffs": 3, "refine": True }}} |
---|
222 | gpx.save('step4.gpx') |
---|
223 | gpx.do_refinements([refdict0]) |
---|
224 | HistStats(gpx)</textarea></blockquote> |
---|
225 | <UL> |
---|
226 | <LI>defines a dictionary (refdict0) that will be used to set the number of background coefficients (not really |
---|
227 | needed, since the default is 3) and sets the background refinement |
---|
228 | flag "on".</li> |
---|
229 | <LI>The project is saved under a new name, so that we can later look at |
---|
230 | the results from each step separately.</li> |
---|
231 | <LI>The parameters in refdict0 are set using |
---|
232 | <I>project</i><tt>.do_refinements()</tt> for both histograms in the |
---|
233 | project and the a refinement is run. |
---|
234 | <LI>The weighted profile R-factor values for all histograms in the project |
---|
235 | are printed using the previously defined <tt>HistStats()</tt> function. |
---|
236 | </UL> |
---|
237 | |
---|
238 | <A name="HistStats"> |
---|
239 | Function <tt>HistStats()</tt> works by using <tt>gpx.histograms()</tt> |
---|
240 | to iterate over all histograms in the project, setting <tt>hist</tt> to each histogram |
---|
241 | object. Class member <tt>hist.name</tt> provides the histogram name |
---|
242 | and method <tt>hist.get_wR()</tt> looks up the profile R-factor and |
---|
243 | prints them. The function also writes the final refinement results |
---|
244 | into the current project file. </A> |
---|
245 | |
---|
246 | The output from this will be:<blockquote><pre> |
---|
247 | Hessian Levenburg-Marquardt SVD refinement on 8 variables: |
---|
248 | initial chi^2 9.6912e+06 |
---|
249 | Cycle: 0, Time: 1.88s, Chi**2: 6.7609e+05, Lambda: 0.001, Delta: 0.93 |
---|
250 | initial chi^2 6.7609e+05 |
---|
251 | Cycle: 1, Time: 1.84s, Chi**2: 6.7602e+05, Lambda: 0.001, Delta: 0.000104 |
---|
252 | converged |
---|
253 | Found 0 SVD zeros |
---|
254 | Read from file: /Users/toby/software/G2/Tutorials/PythonScript/step4.bak0.gpx |
---|
255 | Save to file : /Users/toby/software/G2/Tutorials/PythonScript/step4.gpx |
---|
256 | GPX file save successful |
---|
257 | Refinement results are in file: /Users/toby/software/G2/Tutorials/PythonScript/step4.lst |
---|
258 | ***** Refinement successful ***** |
---|
259 | *** profile Rwp, step4.gpx |
---|
260 | PWDR PBSO4.XRA Bank 1: 40.88 |
---|
261 | PWDR PBSO4.CWN Bank 1: 18.65 |
---|
262 | </pre></blockquote>Note that the Rwp values agree with what is |
---|
263 | expected from the original tutorial. |
---|
264 | <P> |
---|
265 | <B>Note:</B> that there are several equivalent ways to set the histogram |
---|
266 | parameters using |
---|
267 | <tt>G2PwdrData.set_refinements()</tt>, |
---|
268 | <tt>G2Project.set_refinement()</tt> or |
---|
269 | <tt>my_project.do_refinements()</tt>, as |
---|
270 | <A href="http://gsas-ii.readthedocs.io/en/latest/GSASIIscripts.html#refinement-parameters"> |
---|
271 | described here</A>. Thus, the <tt>gpx.do_refinements([refdict0])</tt> |
---|
272 | statement above could be replaced with: |
---|
273 | <blockquote><pre> |
---|
274 | gpx.set_refinement({"Background": { "no. coeffs": 3, "refine": True }}) |
---|
275 | gpx.do_refinements([{}]) |
---|
276 | </pre></blockquote> |
---|
277 | or |
---|
278 | <blockquote><pre> |
---|
279 | for hist in gpx.histograms(): |
---|
280 | hist.set_refinements({"Background": { "no. coeffs": 3, "refine": True }}) |
---|
281 | gpx.do_refinements([{}]) |
---|
282 | </pre></blockquote> |
---|
283 | |
---|
284 | </blockquote> |
---|
285 | <h4>6: Add unit cell parameters to refinement</h4> |
---|
286 | <blockquote> |
---|
287 | |
---|
288 | In Step 5 of the original tutorial, the refinement is performed again, |
---|
289 | but the unit cell is refined in the phase. |
---|
290 | |
---|
291 | <blockquote><textarea rows="6" cols="75" readonly> |
---|
292 | # tutorial step 5: add unit cell refinement (Phase) |
---|
293 | gpx.save('step5.gpx') |
---|
294 | refdict1 = {"set": {"Cell": True}} # set the cell flag (for all phases) |
---|
295 | gpx.set_refinement(refdict1) |
---|
296 | gpx.do_refinements([{}]) |
---|
297 | HistStats(gpx)</textarea></blockquote> |
---|
298 | |
---|
299 | In this case the <tt>gpx.set_refinement(refdict1)</tt> statement can |
---|
300 | be replaced with:<blockquote><pre> |
---|
301 | phase0.set_refinements({"Cell": True}) |
---|
302 | </pre></blockquote> |
---|
303 | |
---|
304 | Note that it is also possible to combine the refinement in the current |
---|
305 | and previous section using |
---|
306 | <blockquote><pre> |
---|
307 | gpx.do_refinements([refdict0,refdict1]) |
---|
308 | </pre></blockquote> |
---|
309 | but then the results are not saved in separate project files and it is |
---|
310 | not possible to see the Rwp values after each refinement. |
---|
311 | |
---|
312 | </blockquote> |
---|
313 | <h4>7: Add hydrostatic strain for just one histogram</h4> |
---|
314 | <blockquote> |
---|
315 | |
---|
316 | In Step 6 of the original tutorial, the refinement is performed again |
---|
317 | after adding Histogram/Phase (HAP) parameters so that the lattice |
---|
318 | constants for the first histogram (only) can vary. This is done with |
---|
319 | this code: |
---|
320 | |
---|
321 | <blockquote><textarea rows="6" cols="75" readonly> |
---|
322 | # tutorial step 6: add Dij terms (HAP) for histogram 1 only |
---|
323 | gpx.save('step6.gpx') |
---|
324 | refdict2 = {"set": {"HStrain": True}} # set HAP parameters |
---|
325 | gpx.set_refinement(refdict2,phase=phase0,histogram=[hist1]) |
---|
326 | gpx.do_refinements([{}]) # refine after setting |
---|
327 | HistStats(gpx)</textarea></blockquote> |
---|
328 | |
---|
329 | Here we cannot use <tt>gpx.do_refinements([refdict2])</tt> with |
---|
330 | <tt>refdict2</tt> defined as above because |
---|
331 | that would turn on refinement of the Hstrain terms for all histograms |
---|
332 | and all phases. There are several ways to restrict the parameter |
---|
333 | changes to specified histogram(s) and phase(s). One is to call a |
---|
334 | method in the phase object(s) directly, such as |
---|
335 | replacing the <tt>gpx.set_refinement(...)</tt> |
---|
336 | statement with this: |
---|
337 | <blockquote><pre> |
---|
338 | phase0.set_HAP_refinements({"HStrain": True},histograms=[hist1]) |
---|
339 | </pre></blockquote> |
---|
340 | |
---|
341 | It is also possible to add "histograms" and/or "phases" values into |
---|
342 | the <tt>refdict2</tt> dict, as will be <a href="#SingeStep">described below.</a> |
---|
343 | </blockquote> |
---|
344 | |
---|
345 | <h4>8: Add X-ray Sample broadening terms</h4> |
---|
346 | <blockquote> |
---|
347 | The next step in the original tutorial is to treat sample broadening |
---|
348 | by turning on refinement of the "Mustrain" (microstrain) and |
---|
349 | "Size" (Scherrer broadening) terms using an isotropic (single-term) |
---|
350 | model. As described in the |
---|
351 | <A |
---|
352 | href="http://gsas-ii.readthedocs.io/en/latest/GSASIIscripts.html#histogram-and-phase-parameters"> |
---|
353 | documentation for Histogram/Phase parameters</A>, type must always be |
---|
354 | specfied even as in this case where it is not being changed from the |
---|
355 | existing default. Again, since these parameters are being set only for |
---|
356 | one histogram, either <tt>phase0.set_HAP_refinements()</tt> or |
---|
357 | <tt>gpx.set_refinement()</tt> must be called or to use |
---|
358 | <tt>gpx.do_refinements([refdict3])</tt> the "histograms" element must be |
---|
359 | included inside <tt>refdict3</tt>. |
---|
360 | |
---|
361 | <blockquote><textarea rows="8" cols="75" readonly> |
---|
362 | # tutorial step 7: add size & strain broadening (HAP) for histogram 1 only |
---|
363 | gpx.save('step7.gpx') |
---|
364 | refdict3 = {"set": {"Mustrain": {"type":"isotropic","refine":True}, |
---|
365 | "Size":{"type":"isotropic","refine":True}, |
---|
366 | }} |
---|
367 | gpx.set_refinement(refdict3,phase=phase0,histogram=[hist1]) |
---|
368 | gpx.do_refinements([{}]) # refine after setting |
---|
369 | HistStats(gpx)</textarea></blockquote> |
---|
370 | |
---|
371 | </blockquote> |
---|
372 | <h4>9: Add Structural and Sample Displacement Parameters</h4> |
---|
373 | <blockquote> |
---|
374 | The step 8 in the original tutorial is to treat sample displacement |
---|
375 | for each histogram/phase. These parameters are different because of |
---|
376 | the differing diffractometer geometries. We also add refinement of |
---|
377 | sample parameters using <tt>phase0.set_refinements()</tt> to set the |
---|
378 | "X" (coordinate) and "U" (displacement) refinement flags for all |
---|
379 | atoms. This is done with this code: |
---|
380 | |
---|
381 | <blockquote><textarea rows="9" cols="75" readonly> |
---|
382 | # tutorial step 8: add sample parameters & set radius (Hist); refine atom parameters (phase) |
---|
383 | gpx.save('step8.gpx') |
---|
384 | hist1.set_refinements({'Sample Parameters': ['Shift']}) |
---|
385 | hist2.set_refinements({'Sample Parameters': ['DisplaceX', 'DisplaceY']}) |
---|
386 | hist2.data['Sample Parameters']['Gonio. radius'] = 650. # not in API |
---|
387 | phase0.set_refinements({"Atoms":{"all":"XU"}}) |
---|
388 | gpx.do_refinements([{}]) # refine after setting |
---|
389 | HistStats(gpx)</textarea></blockquote> |
---|
390 | |
---|
391 | Note that the original tutorial |
---|
392 | calls for the diffractometer radius to be changed to the correct value |
---|
393 | so that the displacement value is in the correct units. This parameter |
---|
394 | cannot be set from any GSASIIscriptable routines, but following a |
---|
395 | similar process, |
---|
396 | <A href="#ChangeCycles">as before</A>, the location for this |
---|
397 | setting can be located in the histogram's 'Sample Parameters' section |
---|
398 | (as <tt>hist2.data['Sample Parameters']['Gonio. radius']</tt>). |
---|
399 | |
---|
400 | Also note that the settings provided in the |
---|
401 | <tt>phase0.set_refinements()</tt> and statements |
---|
402 | <tt>gpx.do_refinements()</tt> could have |
---|
403 | been combined into this single statement: |
---|
404 | <blockquote><pre> |
---|
405 | gpx.do_refinements({"set":{"Atoms":{"all":"XU"}}) |
---|
406 | </pre></blockquote> |
---|
407 | |
---|
408 | </blockquote> |
---|
409 | <h4>10: Change Data Limits; Vary Gaussian Profile Terms</h4> |
---|
410 | <blockquote> |
---|
411 | The final step in the original tutorial is to trim the range of data |
---|
412 | used in the refinement to exclude data where no reflections occur and |
---|
413 | where the peaks are cut off at high angle. Also, additional parameters |
---|
414 | are refined here because the supplied instrumental profile parameters |
---|
415 | are not very accurate descriptions for the datasets that are used |
---|
416 | here. It is not possible to refine the Lorentzian x-ray instrumental |
---|
417 | broadening terms, since this broadening is treated as sample |
---|
418 | broadening. The Lorentzian neutron broadening is negligible. |
---|
419 | |
---|
420 | <blockquote><textarea rows="6" cols="75" readonly> |
---|
421 | # tutorial step 9: change data limits & inst. parm refinements (Hist) |
---|
422 | gpx.save('step9.gpx') |
---|
423 | hist1.set_refinements({'Limits': [16.,158.4]}) |
---|
424 | hist2.set_refinements({'Limits': [19.,153.]}) |
---|
425 | gpx.do_refinements([{"set": {'Instrument Parameters': ['U', 'V', 'W']}}]) |
---|
426 | HistStats(gpx)</textarea></blockquote> |
---|
427 | |
---|
428 | Note that the final <tt>gpx.do_refinements()</tt> statement can be |
---|
429 | replaced with calls to |
---|
430 | <tt>hist</tt><I>X</I><tt>.set_refinements()</tt> or |
---|
431 | <tt>gpx.set_refinement()</tt>, such as |
---|
432 | <blockquote><pre> |
---|
433 | hist1.set_refinements({'Instrument Parameters': ['U', 'V', 'W']}) |
---|
434 | hist2.set_refinements({'Instrument Parameters': ['U', 'V', 'W']}) |
---|
435 | gpx.do_refinements([{}]) |
---|
436 | </pre></blockquote> |
---|
437 | |
---|
438 | </blockquote> |
---|
439 | <a name="SingeStep"><h2>Single Step Approach</h2></a> |
---|
440 | <blockquote> |
---|
441 | |
---|
442 | As is noted in the |
---|
443 | <A href="http://gsas-ii.readthedocs.io/en/latest/GSASIIscripts.html" target="_blank"> |
---|
444 | GSASIIscriptable module documentation</A>, |
---|
445 | the <I>project</i><tt>.do_refinements()</tt> method can be used to |
---|
446 | perform multiple refinement steps. To duplicate the above steps into a |
---|
447 | single call a more complex set of dicts must be created, as shown |
---|
448 | below: |
---|
449 | |
---|
450 | <blockquote><textarea rows="39" cols="75" readonly> |
---|
451 | # tutorial step 4: turn on background refinement (Hist) |
---|
452 | refdict0 = {"set": {"Background": { "no. coeffs": 3, "refine": True }}, |
---|
453 | "output":'step4.gpx', |
---|
454 | "call":HistStats,"callargs":[gpx]} # callargs actually unneeded |
---|
455 | # as [gpx] is the default |
---|
456 | # tutorial step 5: add unit cell refinement (Phase) |
---|
457 | refdict1 = {"set": {"Cell": True}, # set the cell flag (for all phases) |
---|
458 | "output":'step5.gpx', "call":HistStats} |
---|
459 | # tutorial step 6: add Dij terms (HAP) for phase 1 only |
---|
460 | refdict2 = {"set": {"HStrain": True}, # set HAP parameters |
---|
461 | "histograms":[hist1], # histogram 1 only |
---|
462 | "phases":[phase0], # unneeded (default is all |
---|
463 | # phases) included as a example |
---|
464 | "output":'step6.gpx', "call":HistStats} |
---|
465 | # tutorial step 7: add size & strain broadening (HAP) for histogram 1 only |
---|
466 | refdict3 = {"set": {"Mustrain": {"type":"isotropic","refine":True}, |
---|
467 | "Size":{"type":"isotropic","refine":True},}, |
---|
468 | "histograms":[hist1], # histogram 1 only |
---|
469 | "output":'step7.gpx', "call":HistStats} |
---|
470 | # tutorial step 8: add sample parameters & set radius (Hist); refine |
---|
471 | # atom parameters (phase) |
---|
472 | refdict4a = {"set": {'Sample Parameters': ['Shift']}, |
---|
473 | "histograms":[hist1], # histogram 1 only |
---|
474 | "skip": True} |
---|
475 | refdict4b = {"set": {"Atoms":{"all":"XU"}, # not affected by histograms |
---|
476 | 'Sample Parameters': ['DisplaceX', 'DisplaceY']}, |
---|
477 | "histograms":[hist2], # histogram 2 only |
---|
478 | "output":'step8.gpx', "call":HistStats} |
---|
479 | # tutorial step 9: change data limits & inst. parm refinements (Hist) |
---|
480 | refdict5a = {"set": {'Limits': [16.,158.4]}, |
---|
481 | "histograms":[hist1], # histogram 1 only |
---|
482 | "skip": True,} |
---|
483 | refdict5b = {"set": {'Limits': [19.,153.]}, |
---|
484 | "histograms":[hist2], # histogram 2 only |
---|
485 | "skip": True} |
---|
486 | refdict5c = {"set": {'Instrument Parameters': ['U', 'V', 'W']}, |
---|
487 | "output":'step9.gpx', "call":HistStats} |
---|
488 | </textarea></blockquote> |
---|
489 | |
---|
490 | Note that above the "call" and "callargs" dict entries are |
---|
491 | defined to run <tt>HistStats</tt> and "output" is used to designate |
---|
492 | the .gpx file that will be needed. When parameters should be changed |
---|
493 | in specific histograms, the entries <tt>"histograms":[hist1]</tt> and |
---|
494 | <tt>"histograms":[hist2]</tt> are used |
---|
495 | (equivalent would be <tt>"histograms":[0]</tt> and |
---|
496 | <tt>"histograms":[1]</tt>). |
---|
497 | Since there is only one phase present, use of <tt>"phase":[0]</tt> is |
---|
498 | superfluous, but in a more complex refinement, this could be needed. |
---|
499 | <p> |
---|
500 | A list of dicts is then prepared here: |
---|
501 | <blockquote><textarea rows="3" cols="75" readonly> |
---|
502 | dictList = [refdict0,refdict1,refdict2,refdict3, |
---|
503 | refdict4a,refdict4b, |
---|
504 | refdict5a,refdict5b,refdict5c] |
---|
505 | </textarea></blockquote> |
---|
506 | Steps 4 through 10, above then can be performed with these few commands: |
---|
507 | <blockquote><textarea rows="4" cols="75" readonly> |
---|
508 | # Change number of cycles and radius |
---|
509 | gpx.data['Controls']['data']['max cyc'] = 8 # not in API |
---|
510 | hist2.data['Sample Parameters']['Gonio. radius'] = 650. # not in API |
---|
511 | gpx.do_refinements(dictList) |
---|
512 | </textarea></blockquote> |
---|
513 | |
---|
514 | </blockquote> |
---|
515 | |
---|
516 | <hr> |
---|
517 | <address></address> |
---|
518 | <!-- hhmts start -->Last modified: Fri Dec 22 16:24:53 CST 2017 <!-- hhmts end --> |
---|
519 | </body> </html> |
---|