Changeset 3209 for Tutorials

Dec 28, 2017 12:50:40 PM (4 years ago)

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

1 added
2 edited


  • Tutorials/PythonScript/Scripting.htm

    r3207 r3209  
    88To demonstrate the use of the
    99<A href="" target="_blank">
    10 GSASIIscriptable module</A>, we create a Python script to duplicate the
    11 refinement in the
    12 <A
    13 href=""
    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="" target="_blank">
    2217by Jackson O'Donnell, as a summer undergraduate visitor under
    2318supervisor Dr. Maria Chan. Other programming contributions are welcome.
     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>
     26The first section duplicates the refinement in the
     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.
    4658The exercise can be performed by placing all of the Python commands
    47 into a script, (which is supplied for
    48 <A href="">
    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.
    54 <h2>Multi-step Script Approach</h2>
     64<a name="multistep">
     65<h2>A. Create a Multi-step Script</h2></a>
     67Note that the script in this section is supplied for
     68<A href="">
     69download here</A>, but some editing will be needed to match where files
     70are found on your computer.
    5672<h4>0: Load the GSASIIscriptable module</H4>
    452 <a name="SingleStep"><h2>Single Step Approach</h2></a>
     468<a name="SingleStep">
     469<h2>B. Single-Step Refinement</h2></a>
    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="">
     479downloaded here</A>.
     480To duplicate the above steps into a
    460481single call, a more complex set of dicts must be created, as shown
    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>
    519540Steps 4 through 10, above then can be performed with these few commands:
    520541<blockquote><textarea rows="4" cols="75" readonly>
['Controls']['data']['max cyc'] = 8 # not in API['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="">
    528 downloaded here</A>).
     548<a name="Simulate">
     549<h2>C. Powder Pattern Simulation</h2></a>
     551Use of the
     552<A href="" target="_blank">
     553GSASIIscriptable module</A> makes it very simple to simulate a powder
     554diffraction pattern using GSAS-II. This is demonstrated in this
     557Note that the Python commands can be
     559href="">downloaded here</A>.
     561As before, the location of the GSASIIscripts Python module must be
     562defined and the module must be loaded:
     564<blockquote><textarea rows="3" cols="60" readonly>
     565import os,sys
     567import GSASIIscriptable as G2sc</textarea></blockquote>
     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
     574are needed.
     576<blockquote><textarea rows="2" cols="70" readonly>
     577workdir = "/Users/toby/Scratch/PythonScript"
     578datadir = "/Users/toby/software/G2/Tutorials/PythonScript/data"</textarea></blockquote>
     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.)
     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>
     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
     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>
     604Finally, to perform the simulation computation, a refinement is
     607<blockquote><textarea rows="3" cols="70" readonly>['Controls']['data']['max cyc'] = 0 # refinement not needed
     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.
    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>
  • Tutorials/PythonScript/data/

    r3207 r3209  
    1111import GSASIIscriptable as G2sc
    13 import GSASIIpath
    14 GSASIIpath.LoadConfigFile('')
    1613workdir = "/Users/toby/Scratch/PythonScript"
Note: See TracChangeset for help on using the changeset viewer.