1 | '''Sample script to demonstrate use of GSASIIscriptable to duplicate the |
---|
2 | tutorial found here: |
---|
3 | https://subversion.xray.aps.anl.gov/pyGSAS/Tutorials/CWCombined/Combined%20refinement.htm |
---|
4 | |
---|
5 | This script is described in this tutorial: |
---|
6 | https://subversion.xray.aps.anl.gov/pyGSAS/Tutorials/PythonScript/Scripting.htm |
---|
7 | ''' |
---|
8 | |
---|
9 | import os,sys |
---|
10 | sys.path.insert(0,'/Users/toby/software/G2/GSASII') |
---|
11 | import GSASIIscriptable as G2sc |
---|
12 | |
---|
13 | workdir = "/Users/toby/Scratch/PythonScript" |
---|
14 | datadir = "/Users/toby/software/G2/Tutorials/PythonScript/data" |
---|
15 | |
---|
16 | def 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 |
---|
25 | gpx = G2sc.G2Project(filename='PbSO4.gpx') |
---|
26 | |
---|
27 | # setup step 1: add two histograms to the project |
---|
28 | hist1 = gpx.add_powder_histogram(os.path.join(datadir,"PBSO4.XRA"), |
---|
29 | os.path.join(datadir,"INST_XRY.PRM")) |
---|
30 | hist2 = gpx.add_powder_histogram(os.path.join(datadir,"PBSO4.CWN"), |
---|
31 | os.path.join(datadir,"inst_d1a.prm")) |
---|
32 | # setup step 2: add a phase and link it to the previous histograms |
---|
33 | phase0 = gpx.add_phase(os.path.join(datadir,"PbSO4-Wyckoff.cif"), |
---|
34 | phasename="PbSO4", |
---|
35 | histograms=[hist1,hist2]) |
---|
36 | |
---|
37 | # not in tutorial: increase # of cycles to improve convergence |
---|
38 | gpx.data['Controls']['data']['max cyc'] = 8 # not in API |
---|
39 | |
---|
40 | # tutorial step 4: turn on background refinement (Hist) |
---|
41 | refdict0 = {"set": {"Background": { "no. coeffs": 3, "refine": True }}} |
---|
42 | gpx.save('step4.gpx') |
---|
43 | gpx.do_refinements([refdict0]) |
---|
44 | HistStats(gpx) |
---|
45 | |
---|
46 | # tutorial step 5: add unit cell refinement (Phase) |
---|
47 | gpx.save('step5.gpx') |
---|
48 | refdict1 = {"set": {"Cell": True}} # set the cell flag (for all phases) |
---|
49 | gpx.set_refinement(refdict1) |
---|
50 | gpx.do_refinements([{}]) |
---|
51 | HistStats(gpx) |
---|
52 | |
---|
53 | # tutorial step 6: add Dij terms (HAP) for histogram 1 only |
---|
54 | gpx.save('step6.gpx') |
---|
55 | refdict2 = {"set": {"HStrain": True}} # set HAP parameters |
---|
56 | gpx.set_refinement(refdict2,phase=phase0,histogram=[hist1]) |
---|
57 | gpx.do_refinements([{}]) # refine after setting |
---|
58 | HistStats(gpx) |
---|
59 | |
---|
60 | # tutorial step 7: add size & strain broadening (HAP) for histogram 1 only |
---|
61 | gpx.save('step7.gpx') |
---|
62 | refdict2 = {"set": {"Mustrain": {"type":"isotropic","refine":True}, |
---|
63 | "Size":{"type":"isotropic","refine":True}, |
---|
64 | }} |
---|
65 | gpx.set_refinement(refdict2,phase=phase0,histogram=[hist1]) |
---|
66 | gpx.do_refinements([{}]) # refine after setting |
---|
67 | HistStats(gpx) |
---|
68 | |
---|
69 | # tutorial step 8: add sample parameters & set radius (Hist); refine atom parameters (phase) |
---|
70 | gpx.save('step8.gpx') |
---|
71 | hist1.set_refinements({'Sample Parameters': ['Shift']}) |
---|
72 | hist2.set_refinements({'Sample Parameters': ['DisplaceX', 'DisplaceY']}) |
---|
73 | hist2.data['Sample Parameters']['Gonio. radius'] = 650. # not in API |
---|
74 | phase0.set_refinements({"Atoms":{"all":"XU"}}) |
---|
75 | gpx.do_refinements([{}]) # refine after setting |
---|
76 | HistStats(gpx) |
---|
77 | |
---|
78 | # tutorial step 9: change data limits & inst. parm refinements (Hist) |
---|
79 | gpx.save('step9.gpx') |
---|
80 | hist1.set_refinements({'Limits': [16.,158.4]}) |
---|
81 | hist2.set_refinements({'Limits': [19.,153.]}) |
---|
82 | gpx.do_refinements([{"set": {'Instrument Parameters': ['U', 'V', 'W']}}]) |
---|
83 | HistStats(gpx) |
---|