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

Last change on this file since 3130 was 3130, checked in by toby, 4 years ago

updates for G2Scriptable and associated tutorial

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