1 | '''Sample script to demonstrate use of GSASIIscriptable to simulate a powder pattern |
---|
2 | |
---|
3 | This script is described in this tutorial: |
---|
4 | https://subversion.xray.aps.anl.gov/pyGSAS/Tutorials/PythonScript/Scripting.htm |
---|
5 | ''' |
---|
6 | |
---|
7 | import os,sys |
---|
8 | sys.path.insert(0,'/Users/toby/software/G2/GSASII') |
---|
9 | import GSASIIscriptable as G2sc |
---|
10 | |
---|
11 | workdir = "/Users/toby/Scratch/PythonScript" |
---|
12 | datadir = "/Users/toby/software/G2/Tutorials/PythonScript/data" |
---|
13 | |
---|
14 | gpx = G2sc.G2Project(filename='PbSO4sim.gpx') # create a project |
---|
15 | |
---|
16 | # step 1, setup: add a phase to the project |
---|
17 | phase0 = gpx.add_phase(os.path.join(datadir,"PbSO4-Wyckoff.cif"), |
---|
18 | phasename="PbSO4",fmthint='CIF') |
---|
19 | |
---|
20 | # step 2, setup: add a simulated histogram and link it to the previous phase(s) |
---|
21 | hist1 = gpx.add_simulated_powder_histogram("PbSO4 simulation", |
---|
22 | os.path.join(datadir,"inst_d1a.prm"), |
---|
23 | 5.,120.,0.01, |
---|
24 | phases=gpx.phases()) |
---|
25 | |
---|
26 | # Step 3: Set the scale factor to adjust the y scale |
---|
27 | hist1.SampleParameters['Scale'][0] = 1000000. |
---|
28 | |
---|
29 | # step 4, compute: turn off parameter optimization and calculate pattern |
---|
30 | gpx.data['Controls']['data']['max cyc'] = 0 # refinement not needed |
---|
31 | gpx.do_refinements([{}]) |
---|
32 | gpx.save() |
---|
33 | |
---|
34 | # step 5, retrieve results & plot |
---|
35 | x = gpx.histogram(0).getdata('x') |
---|
36 | y = gpx.histogram(0).getdata('ycalc') |
---|
37 | import matplotlib.pyplot as plt |
---|
38 | plt.plot(x,y) |
---|
39 | plt.savefig('PbSO4.png') # to show on screen use: plt.show() |
---|
40 | |
---|
41 | |
---|
42 | |
---|