Skip to content

Commit 53b9ed9

Browse files
committed
debug refinement test
1 parent e9fe3ba commit 53b9ed9

File tree

3 files changed

+80
-61
lines changed

3 files changed

+80
-61
lines changed

.github/workflows/reftest.yml

Lines changed: 0 additions & 56 deletions
This file was deleted.

GSASII.py

Lines changed: 0 additions & 5 deletions
This file was deleted.

tests/debugref.py

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
# perform a GSAS-II refinement using GSASIIscriptable and tutorial
2+
# data
3+
4+
import os
5+
import sys
6+
import tempfile
7+
import numpy.testing as npt
8+
home = os.path.dirname(__file__)
9+
work = tempfile.gettempdir()
10+
11+
import importlib.util
12+
G2loc = None
13+
try:
14+
G2loc = importlib.util.find_spec('GSASII.GSASIIscriptable')
15+
except ModuleNotFoundError:
16+
print('ModuleNotFound for GSASII.GSASIIscriptable')
17+
18+
if G2loc is None: # fixup path if GSASII not installed into Python
19+
print('GSAS-II not installed in Python; Hacking sys.path')
20+
sys.path.append(os.path.dirname(home))
21+
22+
import GSASII
23+
import GSASII.GSASIIscriptable as G2sc
24+
25+
def test_refine():
26+
def testR(msg,w1,w2):
27+
print(f"*** {msg}: Rwp(h1)={h1.residuals['wR']:.5f}, Rwp(h2)={h2.residuals['wR']:.5f}")
28+
npt.assert_allclose([h1.residuals['wR'],h2.residuals['wR']],
29+
[w1,w2], rtol=0.0001)
30+
31+
print('test_refine(): test a small refinement')
32+
dataloc = lambda fil: os.path.join(home,'testinp',fil)
33+
workloc = lambda fil: os.path.join(work,fil)
34+
gpx = G2sc.G2Project(newgpx=workloc('test_scripting.gpx'))
35+
# setup step 1: add two histograms to the project
36+
h1 = gpx.add_powder_histogram(dataloc("PBSO4.XRA"),dataloc("INST_XRY.PRM"),
37+
fmthint='GSAS powder')
38+
h2 = gpx.add_powder_histogram(dataloc("PBSO4.CWN"),dataloc("inst_d1a.prm"),
39+
fmthint='GSAS powder')
40+
# setup step 2: add a phase and link it to the previous histograms
41+
phase0 = gpx.add_phase(dataloc("PbSO4-Wyckoff.cif"),
42+
phasename="PbSO4", histograms=[h1,h2])
43+
gpx.set_Controls('cycles', 0)
44+
gpx.save('test1.gpx')
45+
gpx.save('test2.gpx')
46+
gpx.refine()
47+
testR('Before fitting',96.681098,99.748994)
48+
#
49+
h1.set_refinements({'Limits': [16.,158.4]})
50+
h2.set_refinements({'Limits': [19.,153.]})
51+
gpx.set_Controls('cycles', 8)
52+
gpx.save('test3.gpx')
53+
h1.set_refinements({"Background": { "no. coeffs": 6, "refine": True }})
54+
h2.set_refinements({"Background": { "no. coeffs": 3, "refine": True }})
55+
gpx.save('test4.gpx')
56+
gpx.refine()
57+
testR('Fit scale & bkg',40.64193551740201,18.6189841945785)
58+
#
59+
phase0.set_refinements({'Cell':True})
60+
phase0.set_HAP_refinements({'HStrain':True},[h2])
61+
gpx.refine()
62+
testR('Fit cells',30.072804646662338,15.014744642359773)
63+
#
64+
phase0.set_HAP_refinements({'Mustrain':{'refine':True}},[h1])
65+
#phase0.set_HAP_refinements({'Size':{'refine':True}},[h1])
66+
h1.set_refinements({"Sample Parameters": {"Shift": True}})
67+
h2.set_refinements({"Sample Parameters":["DisplaceX","DisplaceY"]})
68+
phase0.set_refinements({"Atoms":{"all":"XU"}})
69+
gpx.refine()
70+
testR('add Mustrain, Shift, Displace[XY], atomic X & Uiso',
71+
12.66845815113383,6.695761603085025)
72+
#
73+
h1.set_refinements({'Instrument Parameters': ['U', 'V', 'W']})
74+
h2.set_refinements({'Instrument Parameters': ['U', 'V', 'W']})
75+
gpx.refine()
76+
testR('add UVW',10.518485346229324,4.495180030877684)
77+
print('OK')
78+
79+
if __name__ == '__main__':
80+
test_refine()

0 commit comments

Comments
 (0)