source: Tutorials/PythonScript/data/SingleStep.py @ 4575

Last change on this file since 4575 was 3209, checked in by toby, 5 years ago

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

  • Property svn:eol-style set to native
File size: 3.8 KB
Line 
1'''Sample script to demonstrate use of GSASIIscriptable to duplicate the
2tutorial found here:
3https://subversion.xray.aps.anl.gov/pyGSAS/Tutorials/CWCombined/Combined%20refinement.htm
4
5This script is described in this tutorial:
6https://subversion.xray.aps.anl.gov/pyGSAS/Tutorials/PythonScript/Scripting.htm
7'''
8
9import os,sys
10sys.path.insert(0,'/Users/toby/software/G2/GSASII')
11import GSASIIscriptable as G2sc
12
13workdir = "/Users/toby/Scratch/PythonScript"
14datadir = "/Users/toby/software/G2/Tutorials/PythonScript/data"
15
16def HistStats(gpx):
17    '''prints profile rfactors for all histograms'''
18    print(u"*** profile Rwp, "+os.path.split(gpx.filename)[1])
19    for hist in gpx.histograms():
20        print("\t{:20s}: {:.2f}".format(hist.name,hist.get_wR()))
21    print("")
22    gpx.save()
23
24# create a project with a default project name
25gpx = G2sc.G2Project(filename='NotUsed.gpx')
26
27# setup step 1: add two histograms to the project
28hist1 = gpx.add_powder_histogram(os.path.join(datadir,"PBSO4.XRA"),
29                          os.path.join(datadir,"INST_XRY.PRM"),
30                          fmthint="GSAS powder")
31hist2 = gpx.add_powder_histogram(os.path.join(datadir,"PBSO4.CWN"),
32                          os.path.join(datadir,"inst_d1a.prm"),
33                          fmthint="GSAS powder")
34# setup step 2: add a phase and link it to the previous histograms
35phase0 = gpx.add_phase(os.path.join(datadir,"PbSO4-Wyckoff.cif"),
36                      phasename="PbSO4",
37                      histograms=[hist1,hist2],fmthint='CIF')
38
39# not in tutorial: increase # of cycles to improve convergence
40gpx.data['Controls']['data']['max cyc'] = 8 # not in API
41hist2.data['Sample Parameters']['Gonio. radius'] = 650. # not in API
42
43# tutorial step 4: turn on background refinement (Hist)
44refdict0 = {"set": {"Background": { "no. coeffs": 3, "refine": True }},
45            "output":'step4.gpx',
46            "call":HistStats,}
47# tutorial step 5: add unit cell refinement (Phase)
48refdict1 = {"set": {"Cell": True},    # set the cell flag (for all phases)
49            "output":'step5.gpx',
50            "call":HistStats,}
51# tutorial step 6: add Dij terms (HAP) for phase 1 only
52refdict2 = {"set": {"HStrain": True},  # set HAP parameters
53            "histograms":[hist1],      # histogram 1 only
54            "phases":[phase0],         # unneeded (default is all phases)
55            "output":'step6.gpx',
56            "call":HistStats,}
57# tutorial step 7: add size & strain broadening (HAP) for histogram 1 only
58refdict3 = {"set": {"Mustrain": {"type":"isotropic","refine":True},
59                    "Size":{"type":"isotropic","refine":True},},
60            "histograms":[hist1],      # histogram 1 only
61            "output":'step7.gpx',
62            "call":HistStats,}
63# tutorial step 8: add sample parameters & set radius (Hist); refine atom parameters (phase)
64refdict4a = {"set": {'Sample Parameters': ['Shift']},
65            "histograms":[hist1],      # histogram 1 only
66             "skip": True}
67refdict4b = {"set": {"Atoms":{"all":"XU"}, 'Sample Parameters': ['DisplaceX', 'DisplaceY']},
68            "histograms":[hist2],      # histogram 2 only (does not affect atom parms)
69            "output":'step8.gpx',
70            "call":HistStats,}
71# tutorial step 9: change data limits & inst. parm refinements (Hist)
72refdict5a = {"set": {'Limits': [16.,158.4]},
73            "histograms":[hist1],      # histogram 1 only
74             "skip": True,}
75refdict5b = {"set": {'Limits': [19.,153.]},
76            "histograms":[hist2],      # histogram 2 only
77             "skip": True}
78refdict5c = {"set": {'Instrument Parameters': ['U', 'V', 'W']},
79            "output":'step9.gpx',
80            "call":HistStats,}
81
82dictList = [refdict0,refdict1,refdict2,refdict3,
83            refdict4a,refdict4b,
84            refdict5a,refdict5b,refdict5c]
85               
86gpx.do_refinements(dictList)
Note: See TracBrowser for help on using the repository browser.