Skip to content

Commit c56c821

Browse files
committed
finish off refinement self-test
1 parent d9775f0 commit c56c821

File tree

4 files changed

+58
-25
lines changed

4 files changed

+58
-25
lines changed

GSASII/GSASII.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414

1515
if pkginfo is None: # fixup path if GSASII not installed into Python
1616
os.environ["GSASII_YOLO_PATH"] = "True"
17-
#print('GSAS-II not installed in Python: Hacking sys.path')
1817
sys.path.insert(0,os.path.dirname(os.path.dirname(__file__)))
1918

2019
from GSASII.GSASIIGUI import main

GSASII/GSASIIctrlGUI.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@
4949
from . import GSASIImath as G2mth
5050
from . import GSASIIstrMain as G2stMn
5151
from . import GSASIImiscGUI as G2IO
52-
from . import config_example
5352
from .tutorialIndex import tutorialIndex
5453
if sys.version_info[0] >= 3:
5554
unicode = str

docs/source/GSASIIscriptable.rst

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -631,8 +631,9 @@ Sample Parameters Should be provided as a **list** of
631631
Available for powder histograms only.
632632
\ Absorption
633633
\ Contrast
634-
\ DisplaceX Sample displacement along the X direction
635-
\ DisplaceY Sample displacement along the Y direction
634+
\ DisplaceX Sample displacement along the X direction (Debye-Scherrer)
635+
\ DisplaceY Sample displacement along the Y direction (Debye-Scherrer)
636+
\ Shift Bragg-Brentano sample displacement
636637
\ Scale Histogram Scale factor
637638

638639
Background Sample background. Value will be a dict or

tests/test_scripting.py

Lines changed: 55 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,34 +4,68 @@
44
import os
55
import sys
66
import tempfile
7+
import numpy.testing as npt
78
home = os.path.dirname(__file__)
89
work = tempfile.gettempdir()
10+
work='/tmp/'
911

1012
import importlib # fixup path if GSASII not installed into Python
1113
if importlib.util.find_spec('GSASII') is None:
12-
print('Path hacking!')
14+
print('GSAS-II not installed in Python: Hacking sys.path')
1315
os.environ["GSASII_YOLO_PATH"] = "True"
1416
sys.path.append(os.path.dirname(home))
1517

1618
import GSASII.GSASIIscriptable as G2sc
1719

18-
dataloc = lambda fil: os.path.join(home,'testinp',fil)
19-
workloc = lambda fil: os.path.join(work,fil)
20-
gpx = G2sc.G2Project(newgpx=workloc('test_scripting.gpx'))
21-
# setup step 1: add two histograms to the project
22-
hist1 = gpx.add_powder_histogram(dataloc("PBSO4.XRA"),dataloc("INST_XRY.PRM"),
23-
fmthint='GSAS powder')
24-
hist2 = gpx.add_powder_histogram(dataloc("PBSO4.CWN"),dataloc("inst_d1a.prm"),
25-
fmthint='GSAS powder')
26-
# setup step 2: add a phase and link it to the previous histograms
27-
phase0 = gpx.add_phase(dataloc("PbSO4-Wyckoff.cif"),
28-
phasename="PbSO4", histograms=[hist1,hist2])
29-
gpx.set_Controls('cycles', 0)
30-
gpx.refine()
31-
print(hist1.residuals['wR'])
32-
print(hist2.residuals['wR'])
33-
gpx.set_Controls('cycles', 8)
34-
refdict0 = {"set": {"Background": { "no. coeffs": 3, "refine": True }}}
35-
gpx.do_refinements([refdict0])
36-
print(hist1.residuals['wR'])
37-
print(hist2.residuals['wR'])
20+
def test_refine():
21+
def testR(msg,w1,w2):
22+
print(f"*** {msg}: Rwp(h1)={h1.residuals['wR']:.5f}, Rwp(h2)={h2.residuals['wR']:.5f}")
23+
npt.assert_allclose([h1.residuals['wR'],h2.residuals['wR']],
24+
[w1,w2], rtol=0.0001)
25+
26+
print('test_refine(): test a small refinement')
27+
dataloc = lambda fil: os.path.join(home,'testinp',fil)
28+
workloc = lambda fil: os.path.join(work,fil)
29+
gpx = G2sc.G2Project(newgpx=workloc('test_scripting.gpx'))
30+
# setup step 1: add two histograms to the project
31+
h1 = gpx.add_powder_histogram(dataloc("PBSO4.XRA"),dataloc("INST_XRY.PRM"),
32+
fmthint='GSAS powder')
33+
h2 = gpx.add_powder_histogram(dataloc("PBSO4.CWN"),dataloc("inst_d1a.prm"),
34+
fmthint='GSAS powder')
35+
# setup step 2: add a phase and link it to the previous histograms
36+
phase0 = gpx.add_phase(dataloc("PbSO4-Wyckoff.cif"),
37+
phasename="PbSO4", histograms=[h1,h2])
38+
gpx.set_Controls('cycles', 0)
39+
gpx.refine()
40+
testR('Before fitting',96.681098,99.748994)
41+
#
42+
h1.set_refinements({'Limits': [16.,158.4]})
43+
h2.set_refinements({'Limits': [19.,153.]})
44+
gpx.set_Controls('cycles', 8)
45+
h1.set_refinements({"Background": { "no. coeffs": 6, "refine": True }})
46+
h2.set_refinements({"Background": { "no. coeffs": 3, "refine": True }})
47+
gpx.refine()
48+
testR('Fit scale & bkg',40.64193551740201,18.6189841945785)
49+
#
50+
phase0.set_refinements({'Cell':True})
51+
phase0.set_HAP_refinements({'HStrain':True},[h2])
52+
gpx.refine()
53+
testR('Fit cells',30.072804646662338,15.014744642359773)
54+
#
55+
phase0.set_HAP_refinements({'Mustrain':{'refine':True}},[h1])
56+
#phase0.set_HAP_refinements({'Size':{'refine':True}},[h1])
57+
h1.set_refinements({"Sample Parameters": {"Shift": True}})
58+
h2.set_refinements({"Sample Parameters":["DisplaceX","DisplaceY"]})
59+
phase0.set_refinements({"Atoms":{"all":"XU"}})
60+
gpx.refine()
61+
testR('add Mustrain, Shift, Displace[XY], atomic X & Uiso',
62+
12.66845815113383,6.695761603085025)
63+
#
64+
h1.set_refinements({'Instrument Parameters': ['U', 'V', 'W']})
65+
h2.set_refinements({'Instrument Parameters': ['U', 'V', 'W']})
66+
gpx.refine()
67+
testR('add UVW',10.518485346229324,4.495180030877684)
68+
print('OK')
69+
70+
if __name__ == '__main__':
71+
test_refine()

0 commit comments

Comments
 (0)