@@ -10,8 +10,26 @@ def runfit(fit):
1010 import difscript
1111
1212 # Do the rietveld refinement first (it's more tempermental)
13- difscript .runfit (fit )
13+ difscript .initialize (fit )
1414 difcomp = fit .getComponent (0 )
15+ # Let's see where we're starting
16+ if 1 :
17+ calc = difcomp .getCalculator ()
18+ calc ._prepareSrRietUI ()
19+ calc .calculate ()
20+ from pylab import plot , show , title , xlabel , ylabel , legend
21+ x0 ,y0 ,u0 = difcomp .getFitDataArrays ()
22+ x1 ,y1 = difcomp .getFitArrays ()
23+ dy = y0 - y1
24+ dy -= 1.5 * ( abs (min (dy )) + abs (min (y0 )))
25+ plot (x1 , y0 , 'bo' , x1 , y1 , 'r-' , x1 , dy , 'g--' )
26+ title ("Initial Rietveld configuration" )
27+ xlabel ("Q (A^-1)" )
28+ ylabel ("I (arb.)" )
29+ legend (("data" , "fit (R = %f)" % difcomp .getR (), "difference" ))
30+ show ()
31+ print "Rietveld fit"
32+ difscript .runfit (fit )
1533
1634 ###############################################################################
1735 # PDF #
@@ -65,15 +83,66 @@ def runfit(fit):
6583 pdfpha .getAtom (2 ).x = pdfpha .getAtom (2 ).z = 0.5
6684 pdfpha .getAtom (3 ).x = pdfpha .getAtom (3 ).y = 0.5
6785
86+ # Check where we're at
87+ if 1 :
88+ calc = pdfcomp .getCalculator ()
89+ calc .calculate ()
90+ from pylab import plot , show , title , xlabel , ylabel , legend
91+ x0 ,y0 ,u0 = pdfcomp .getFitDataArrays ()
92+ x1 ,y1 = pdfcomp .getFitArrays ()
93+ dy = y0 - y1
94+ dy -= 1.5 * ( abs (min (dy )) + abs (min (y0 )))
95+ plot (x1 , y0 , 'bo' , x1 , y1 , 'r-' , x1 , dy , 'g--' )
96+ title ("Initial PDF configuration" )
97+ xlabel ("r (A)" )
98+ ylabel ("G (A^-2)" )
99+ legend (("data" , "fit (R = %f)" % pdfcomp .getR (), "difference" ))
100+ show ()
101+ raw_input ("Press any key to continue ... " )
102+
68103 # Fitting
69104 fit .setWeight (pdfcomp , 0.5 )
70105 fit .setWeight (difcomp , 0.5 )
106+ print "Rietveld+PDF fit"
71107 fit .refine ()
72108 fit .printResults ()
73109 fit .saveResults ("ni.co.res" )
74110 pdfcomp .saveFitArrays ("ni.co.pdf.fit" )
75111 difcomp .saveFitArrays ("ni.co.dif.fit" )
76112
113+ # Show final Rietveld fit
114+ if 1 :
115+ from pylab import plot , show , title , xlabel , ylabel , legend
116+ x0 ,y0 ,u0 = difcomp .getFitDataArrays ()
117+ x1 ,y1 = difcomp .getFitArrays ()
118+ dy = y0 - y1
119+ dy -= 1.5 * ( abs (min (dy )) + abs (min (y0 )))
120+ plot (x1 , y0 , 'bo' , x1 , y1 , 'r-' , x1 , dy , 'g--' )
121+ title ("Rietveld fit from co-refinement" )
122+ xlabel ("Q (A^-1)" )
123+ ylabel ("I (arb.)" )
124+ legend (("data" , "fit (R = %f)" % difcomp .getR (), "difference" ))
125+ show ()
126+ raw_input ("Press any key to continue ... " )
127+
128+
129+ # Show final PDF fit
130+ if 1 :
131+ calc = pdfcomp .getCalculator ()
132+ calc .calculate ()
133+ from pylab import plot , show , title , xlabel , ylabel , legend
134+ x0 ,y0 ,u0 = pdfcomp .getFitDataArrays ()
135+ x1 ,y1 = pdfcomp .getFitArrays ()
136+ dy = y0 - y1
137+ dy -= 1.5 * ( abs (min (dy )) + abs (min (y0 )))
138+ plot (x1 , y0 , 'bo' , x1 , y1 , 'r-' , x1 , dy , 'g--' )
139+ title ("PDF fit from co-refinement" )
140+ xlabel ("r (A)" )
141+ ylabel ("G (A^-2)" )
142+ legend (("data" , "fit (R = %f)" % pdfcomp .getR (), "difference" ))
143+ show ()
144+ raw_input ("Press any key to continue ... " )
145+
77146if __name__ == "__main__" :
78147 from SrRietveld import Fit
79148 fit = Fit ()
0 commit comments