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

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

more minor G2scriptable changes

  • Property svn:eol-style set to native
File size: 3.2 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='PbSO4.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"))
30hist2 = 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
33phase0 = 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
38gpx.data['Controls']['data']['max cyc'] = 8 # not in API
39
40# tutorial step 4: turn on background refinement (Hist)
41refdict0 = {"set": {"Background": { "no. coeffs": 3, "refine": True }}}
42gpx.save('step4.gpx')
43gpx.do_refinements([refdict0])
44HistStats(gpx)
45
46# tutorial step 5: add unit cell refinement (Phase)
47gpx.save('step5.gpx')
48refdict1 = {"set": {"Cell": True}} # set the cell flag (for all phases)
49gpx.set_refinement(refdict1)
50gpx.do_refinements([{}])
51HistStats(gpx)
52
53# tutorial step 6: add Dij terms (HAP) for histogram 1 only
54gpx.save('step6.gpx')
55refdict2 = {"set": {"HStrain": True}} # set HAP parameters
56gpx.set_refinement(refdict2,phase=phase0,histogram=[hist1])
57gpx.do_refinements([{}]) # refine after setting
58HistStats(gpx)
59
60# tutorial step 7: add size & strain broadening (HAP) for histogram 1 only
61gpx.save('step7.gpx')
62refdict2 = {"set": {"Mustrain": {"type":"isotropic","refine":True},
63                    "Size":{"type":"isotropic","refine":True},
64                    }}
65gpx.set_refinement(refdict2,phase=phase0,histogram=[hist1])
66gpx.do_refinements([{}]) # refine after setting
67HistStats(gpx)
68
69# tutorial step 8: add sample parameters & set radius (Hist); refine atom parameters (phase)
70gpx.save('step8.gpx')
71hist1.set_refinements({'Sample Parameters': ['Shift']})
72hist2.set_refinements({'Sample Parameters': ['DisplaceX', 'DisplaceY']})
73hist2.data['Sample Parameters']['Gonio. radius'] = 650. # not in API
74phase0.set_refinements({"Atoms":{"all":"XU"}})
75gpx.do_refinements([{}]) # refine after setting
76HistStats(gpx)
77
78# tutorial step 9: change data limits & inst. parm refinements (Hist)
79gpx.save('step9.gpx')
80hist1.set_refinements({'Limits': [16.,158.4]})
81hist2.set_refinements({'Limits': [19.,153.]})
82gpx.do_refinements([{"set": {'Instrument Parameters': ['U', 'V', 'W']}}])
83HistStats(gpx)
Note: See TracBrowser for help on using the repository browser.