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='NotUsed.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 | fmthint="GSAS powder") |
---|
31 | hist2 = 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 |
---|
35 | phase0 = 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 |
---|
40 | gpx.data['Controls']['data']['max cyc'] = 8 # not in API |
---|
41 | hist2.data['Sample Parameters']['Gonio. radius'] = 650. # not in API |
---|
42 | |
---|
43 | # tutorial step 4: turn on background refinement (Hist) |
---|
44 | refdict0 = {"set": {"Background": { "no. coeffs": 3, "refine": True }}, |
---|
45 | "output":'step4.gpx', |
---|
46 | "call":HistStats,} |
---|
47 | # tutorial step 5: add unit cell refinement (Phase) |
---|
48 | refdict1 = {"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 |
---|
52 | refdict2 = {"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 |
---|
58 | refdict3 = {"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) |
---|
64 | refdict4a = {"set": {'Sample Parameters': ['Shift']}, |
---|
65 | "histograms":[hist1], # histogram 1 only |
---|
66 | "skip": True} |
---|
67 | refdict4b = {"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) |
---|
72 | refdict5a = {"set": {'Limits': [16.,158.4]}, |
---|
73 | "histograms":[hist1], # histogram 1 only |
---|
74 | "skip": True,} |
---|
75 | refdict5b = {"set": {'Limits': [19.,153.]}, |
---|
76 | "histograms":[hist2], # histogram 2 only |
---|
77 | "skip": True} |
---|
78 | refdict5c = {"set": {'Instrument Parameters': ['U', 'V', 'W']}, |
---|
79 | "output":'step9.gpx', |
---|
80 | "call":HistStats,} |
---|
81 | |
---|
82 | dictList = [refdict0,refdict1,refdict2,refdict3, |
---|
83 | refdict4a,refdict4b, |
---|
84 | refdict5a,refdict5b,refdict5c] |
---|
85 | |
---|
86 | gpx.do_refinements(dictList) |
---|