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

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

New command-line tutorial

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