Ignore:
Timestamp:
Dec 28, 2017 12:50:40 PM (5 years ago)
Author:
toby
Message:

Add simulation to scriptable & add to tutorial; add sphinx index to ctrlsGUI; remove path from RunGSASII.bat

File:
1 edited

Legend:

Unmodified
Added
Removed
  • Tutorials/PythonScript/Scripting.htm

    r3207 r3209  
    88To demonstrate the use of the
    99<A href="http://gsas-ii.readthedocs.io/en/latest/GSASIIscripts.html" target="_blank">
    10 GSASIIscriptable module</A>, we create a Python script to duplicate the
    11 refinement in the
    12 <A
    13 href="https://subversion.xray.aps.anl.gov/pyGSAS/Tutorials/CWCombined/Combined%20refinement.htm"
    14 target="_blank">GSAS-II CW Combined Refinement</A>
    15 tutorial. This uses a Python script
    16 to perform the same refinements steps as in that tutorial, but without use of the GSAS-II
     10GSASIIscriptable module</A>. This uses a Python script
     11to perform a refinement or computation, but without use of the GSAS-II
    1712graphical user interface. Note that the
    1813<A href="http://gsas-ii.readthedocs.io/en/latest/GSASIIscripts.html" target="_blank">
     
    2217by Jackson O'Donnell, as a summer undergraduate visitor under
    2318supervisor Dr. Maria Chan. Other programming contributions are welcome.
     19<P>
     20This tutorial has three sections:
     21<OL type="A">
     22<LI><a href="#multistep"> Create a Multi-step Script</A></LI>
     23<LI><a href="#SingleStep">Single-Step Refinement</a></LI>
     24<LI><a href="#Simulate">Powder Pattern Simulation</a></LI>
     25</OL>
     26The first section duplicates the refinement in the
     27<A
     28href="https://subversion.xray.aps.anl.gov/pyGSAS/Tutorials/CWCombined/Combined%20refinement.htm"
     29target="_blank">GSAS-II CW Combined Refinement</A>
     30tutorial as a multi-step process. The second section repeats the previous
     31refinement, but demonstrates how a complex process can be entered into
     32a single Python dict and the refinement executed with a single
     33function call. The third section shows how a pattern simulation,
     34rather than refinement can be executed from a script.
     35
    2436
    2537<h2>Prerequisites</h2>
     
    4557<P>
    4658The exercise can be performed by placing all of the Python commands
    47 into a script, (which is supplied for
    48 <A href="https://subversion.xray.aps.anl.gov/trac/pyGSAS/browser/Tutorials/PythonScript/data/example.py?format=txt">
    49 download here</A>),
     59into a script,
    5060but a more pedagogical approach will be to enter the
    5161commands into a Python interpreter. Use of IPython or Jupyter to run
    5262Python will make this a more pleasant experience.
    5363
    54 <h2>Multi-step Script Approach</h2>
     64<a name="multistep">
     65<h2>A. Create a Multi-step Script</h2></a>
     66
     67Note that the script in this section is supplied for
     68<A href="https://subversion.xray.aps.anl.gov/trac/pyGSAS/browser/Tutorials/PythonScript/data/example.py?format=txt">
     69download here</A>, but some editing will be needed to match where files
     70are found on your computer.
    5571
    5672<h4>0: Load the GSASIIscriptable module</H4>
     
    450466
    451467</blockquote>
    452 <a name="SingleStep"><h2>Single Step Approach</h2></a>
     468<a name="SingleStep">
     469<h2>B. Single-Step Refinement</h2></a>
    453470<blockquote>
    454471
     
    457474GSASIIscriptable module documentation</A>,
    458475the <I>project</i><tt>.do_refinements()</tt> method can be used to
    459 perform multiple refinement steps. To duplicate the above steps into a
     476perform multiple refinement steps.
     477Note that this version of the exercise can be
     478<A href="https://subversion.xray.aps.anl.gov/trac/pyGSAS/browser/Tutorials/PythonScript/data/SingleStep.py?format=txt">
     479downloaded here</A>.
     480To duplicate the above steps into a
    460481single call, a more complex set of dicts must be created, as shown
    461482below:
    462483
    463 <blockquote><textarea rows="39" cols="75" readonly>
     484<blockquote><textarea rows="38" cols="75" readonly>
    464485# tutorial step 4: turn on background refinement (Hist)
    465486refdict0 = {"set": {"Background": { "no. coeffs": 3, "refine": True }},
     
    515536dictList = [refdict0,refdict1,refdict2,refdict3,
    516537            refdict4a,refdict4b,
    517             refdict5a,refdict5b,refdict5c]
    518 </textarea></blockquote>
     538            refdict5a,refdict5b,refdict5c]</textarea></blockquote>
     539
    519540Steps 4 through 10, above then can be performed with these few commands:
    520541<blockquote><textarea rows="4" cols="75" readonly>
     
    522543gpx.data['Controls']['data']['max cyc'] = 8 # not in API
    523544hist2.data['Sample Parameters']['Gonio. radius'] = 650. # not in API
    524 gpx.do_refinements(dictList)
    525 </textarea></blockquote>
    526 Note that this version of the exercise can be
    527 <A href="https://subversion.xray.aps.anl.gov/trac/pyGSAS/browser/Tutorials/PythonScript/data/SingleStep.py?format=txt">
    528 downloaded here</A>).
     545gpx.do_refinements(dictList)</textarea></blockquote>
     546
     547</blockquote>
     548<a name="Simulate">
     549<h2>C. Powder Pattern Simulation</h2></a>
     550<blockquote>
     551Use of the
     552<A href="http://gsas-ii.readthedocs.io/en/latest/GSASIIscripts.html" target="_blank">
     553GSASIIscriptable module</A> makes it very simple to simulate a powder
     554diffraction pattern using GSAS-II. This is demonstrated in this
     555section.
     556
     557Note that the Python commands can be
     558<A
     559href="https://subversion.xray.aps.anl.gov/trac/pyGSAS/browser/Tutorials/PythonScript/data/sim.py?format=txt">downloaded here</A>.
     560<P>
     561As before, the location of the GSASIIscripts Python module must be
     562defined and the module must be loaded:
     563
     564<blockquote><textarea rows="3" cols="60" readonly>
     565import os,sys
     566sys.path.insert(0,os.path.expanduser("~/g2conda/GSASII/"))
     567import GSASIIscriptable as G2sc</textarea></blockquote>
     568
     569To simplify this example, as before we will define the location where files will
     570be read from and written (as <tt>datadir</tt> and
     571<tt>workdir</tt>). Note that files "inst_d1a.prm" and
     572"PbSO4-Wyckoff.cif" from <A
     573href="https://subversion.xray.aps.anl.gov/pyGSAS/Tutorials/PythonScript/data/">here</A>
     574are needed.
     575
     576<blockquote><textarea rows="2" cols="70" readonly>
     577workdir = "/Users/toby/Scratch/PythonScript"
     578datadir = "/Users/toby/software/G2/Tutorials/PythonScript/data"</textarea></blockquote>
     579
     580We then need to create a project and for this example we choose to
     581define the phase first. (It would work equally well to create the
     582histogram first and then define the phase.)
     583
     584<blockquote><textarea rows="4" cols="70" readonly>
     585gpx = G2sc.G2Project(filename='PbSO4sim.gpx') # create a project
     586# setup step 1: add a phase to the project
     587phase0 = gpx.add_phase(os.path.join(datadir,"PbSO4-Wyckoff.cif"),
     588                      phasename="PbSO4",fmthint='CIF') </textarea></blockquote>
     589
     590We then add a "dummy" histogram to the project. Note that an
     591instrument parameter file is specified, but not a data file. The range
     592of data to be used and the step size must be specified. The phases
     593parameter is specified as ``gpx.phases()`` which creates a list of all
     594the previously read phases, which in this case is equivalent to
     595``[phase0]``.
     596
     597<blockquote><textarea rows="6" cols="70" readonly>
     598# setup step 2: add a simulated histogram and link it to the previous phase(s)
     599hist1 = gpx.add_simulated_powder_histogram("PbSO4 simulation",
     600                          os.path.join(datadir,"inst_d1a.prm"),
     601                          5.,120.,0.01,
     602                          phases=gpx.phases())</textarea></blockquote>
     603
     604Finally, to perform the simulation computation, a refinement is
     605needed:
     606
     607<blockquote><textarea rows="3" cols="70" readonly>
     608gpx.data['Controls']['data']['max cyc'] = 0 # refinement not needed
     609gpx.do_refinements([{}])
     610gpx.save()</textarea></blockquote>
     611
     612However, there is no need to actually optimize any variables,
     613so the number of refinement cycles is set to zero. Refinement is
     614initiated then with <I>proj</i>.<tt>do_refinements</tt>. Finally, the
     615project is saved.
    529616
    530617</blockquote>
     
    532619<hr>
    533620<address></address>
    534 <!-- hhmts start -->Last modified: Tue Dec 26 17:03:22 CST 2017 <!-- hhmts end -->
     621<!-- hhmts start -->Last modified: Thu Dec 28 12:18:27 CST 2017 <!-- hhmts end -->
    535622</body> </html>
Note: See TracChangeset for help on using the changeset viewer.