1 | # -*- coding: utf-8 -*- |
---|
2 | #GSASIIstructure - structure computation routines |
---|
3 | ########### SVN repository information ################### |
---|
4 | # $Date: 2013-03-21 15:54:41 +0000 (Thu, 21 Mar 2013) $ |
---|
5 | # $Author: vondreele $ |
---|
6 | # $Revision: 869 $ |
---|
7 | # $URL: trunk/GSASIIstruct.py $ |
---|
8 | # $Id: GSASIIstruct.py 869 2013-03-21 15:54:41Z vondreele $ |
---|
9 | ########### SVN repository information ################### |
---|
10 | import sys |
---|
11 | import os |
---|
12 | import os.path as ospath |
---|
13 | import time |
---|
14 | import math |
---|
15 | import copy |
---|
16 | import random |
---|
17 | import cPickle |
---|
18 | import numpy as np |
---|
19 | import numpy.ma as ma |
---|
20 | import numpy.linalg as nl |
---|
21 | import scipy.optimize as so |
---|
22 | import GSASIIpath |
---|
23 | GSASIIpath.SetVersionNumber("$Revision: 869 $") |
---|
24 | import GSASIIElem as G2el |
---|
25 | import GSASIIlattice as G2lat |
---|
26 | import GSASIIspc as G2spc |
---|
27 | import GSASIIpwd as G2pwd |
---|
28 | import GSASIImapvars as G2mv |
---|
29 | import GSASIImath as G2mth |
---|
30 | |
---|
31 | sind = lambda x: np.sin(x*np.pi/180.) |
---|
32 | cosd = lambda x: np.cos(x*np.pi/180.) |
---|
33 | tand = lambda x: np.tan(x*np.pi/180.) |
---|
34 | asind = lambda x: 180.*np.arcsin(x)/np.pi |
---|
35 | acosd = lambda x: 180.*np.arccos(x)/np.pi |
---|
36 | atan2d = lambda y,x: 180.*np.arctan2(y,x)/np.pi |
---|
37 | Â Â |
---|
38 | ateln2 =Â 8.0*math.log(2.0) |
---|
39 | DEBUG =Â False |
---|
40 | |
---|
41 | def GetControls(GPXfile): |
---|
42 | Â Â ''' Returns dictionary of control items found in GSASII gpx file |
---|
43 | Â Â input: |
---|
44 | Â Â Â Â GPXfile = .gpx full file name |
---|
45 | Â Â return: |
---|
46 | Â Â Â Â Controls = dictionary of control items |
---|
47 | Â Â ''' |
---|
48 | Â Â Controls =Â {'deriv type':'analytic Hessian','max cyc':3,'max Hprocess':1, |
---|
49 | Â Â Â Â 'max Rprocess':1,'min dM/M':0.0001,'shift factor':1.} |
---|
50 | Â Â fl =Â open(GPXfile,'rb') |
---|
51 |   while True: |
---|
52 | Â Â Â Â try: |
---|
53 | Â Â Â Â Â Â data =Â cPickle.load(fl) |
---|
54 |     except EOFError: |
---|
55 | Â Â Â Â Â Â break |
---|
56 | Â Â Â Â datum =Â data[0] |
---|
57 |     if datum[0] == 'Controls': |
---|
58 | Â Â Â Â Â Â Controls.update(datum[1]) |
---|
59 | Â Â fl.close() |
---|
60 |   return Controls |
---|
61 | Â Â |
---|
62 | def GetConstraints(GPXfile): |
---|
63 | Â Â '''Read the constraints from the GPX file and interpret them |
---|
64 | Â Â ''' |
---|
65 | Â Â constList =Â [] |
---|
66 | Â Â fl =Â open(GPXfile,'rb') |
---|
67 |   while True: |
---|
68 | Â Â Â Â try: |
---|
69 | Â Â Â Â Â Â data =Â cPickle.load(fl) |
---|
70 |     except EOFError: |
---|
71 | Â Â Â Â Â Â break |
---|
72 | Â Â Â Â datum =Â data[0] |
---|
73 |     if datum[0] == 'Constraints': |
---|
74 | Â Â Â Â Â Â constDict =Â datum[1] |
---|
75 |       for item in constDict: |
---|
76 | Â Â Â Â Â Â Â Â constList +=Â constDict[item] |
---|
77 | Â Â fl.close() |
---|
78 | Â Â constDict,fixedList,ignored =Â ProcessConstraints(constList) |
---|
79 |   if ignored: |
---|
80 |     print ignored,'old-style Constraints were rejected' |
---|
81 |   return constDict,fixedList |
---|
82 | Â Â |
---|
83 | def ProcessConstraints(constList): |
---|
84 | Â Â "interpret constraints" |
---|
85 | Â Â constDict =Â [] |
---|
86 | Â Â fixedList =Â [] |
---|
87 | Â Â ignored =Â 0 |
---|
88 |   for item in constList: |
---|
89 |     if item[-1] == 'h': |
---|
90 | Â Â Â Â Â Â # process a hold |
---|
91 | Â Â Â Â Â Â fixedList.append('0') |
---|
92 | Â Â Â Â Â Â constDict.append({item[0][1]:0.0}) |
---|
93 |     elif item[-1] == 'f': |
---|
94 | Â Â Â Â Â Â # process a new variable |
---|
95 | Â Â Â Â Â Â fixedList.append(None) |
---|
96 | Â Â Â Â Â Â constDict.append({}) |
---|
97 |       for term in item[:-3]: |
---|
98 | Â Â Â Â Â Â Â Â constDict[-1][term[1]]Â =Â term[0] |
---|
99 | Â Â Â Â Â Â #constFlag[-1] = ['Vary'] |
---|
100 |     elif item[-1] == 'c': |
---|
101 | Â Â Â Â Â Â # process a contraint relationship |
---|
102 | Â Â Â Â Â Â fixedList.append(str(item[-3])) |
---|
103 | Â Â Â Â Â Â constDict.append({}) |
---|
104 |       for term in item[:-3]: |
---|
105 | Â Â Â Â Â Â Â Â constDict[-1][term[1]]Â =Â term[0] |
---|
106 | Â Â Â Â Â Â #constFlag[-1] = ['VaryFree'] |
---|
107 |     elif item[-1] == 'e': |
---|
108 | Â Â Â Â Â Â # process an equivalence |
---|
109 | Â Â Â Â Â Â firstmult =Â None |
---|
110 | Â Â Â Â Â Â eqlist =Â [] |
---|
111 |       for term in item[:-3]: |
---|
112 |         if term[0] == 0: term[0] = 1.0 |
---|
113 |         if firstmult is None: |
---|
114 | Â Â Â Â Â Â Â Â Â Â firstmult,firstvar =Â term |
---|
115 | Â Â Â Â Â Â Â Â else: |
---|
116 | Â Â Â Â Â Â Â Â Â Â eqlist.append([term[1],firstmult/term[0]]) |
---|
117 | Â Â Â Â Â Â G2mv.StoreEquivalence(firstvar,eqlist) |
---|
118 | Â Â Â Â else: |
---|
119 | Â Â Â Â Â Â ignored +=Â 1 |
---|
120 |   return constDict,fixedList,ignored |
---|
121 | |
---|
122 | def CheckConstraints(GPXfile): |
---|
123 | Â Â '''Load constraints and related info and return any error or warning messages''' |
---|
124 | Â Â # init constraints |
---|
125 | Â Â G2mv.InitVars()Â Â |
---|
126 | Â Â # get variables |
---|
127 | Â Â Histograms,Phases =Â GetUsedHistogramsAndPhases(GPXfile) |
---|
128 |   if not Phases: |
---|
129 |     return 'Error: No Phases!','' |
---|
130 |   if not Histograms: |
---|
131 |     return 'Error: no diffraction data','' |
---|
132 | Â Â Natoms,atomIndx,phaseVary,phaseDict,pawleyLookup,FFtables,BLtables =Â GetPhaseData(Phases,RestraintDict=None,Print=False) |
---|
133 | Â Â hapVary,hapDict,controlDict =Â GetHistogramPhaseData(Phases,Histograms,Print=False) |
---|
134 | Â Â histVary,histDict,controlDict =Â GetHistogramData(Histograms,Print=False) |
---|
135 | Â Â varyList =Â phaseVary+hapVary+histVary |
---|
136 | Â Â constrDict,fixedList =Â GetConstraints(GPXfile) |
---|
137 |   return G2mv.CheckConstraints(varyList,constrDict,fixedList) |
---|
138 | Â Â |
---|
139 | def GetRestraints(GPXfile): |
---|
140 | Â Â '''Read the restraints from the GPX file |
---|
141 | Â Â ''' |
---|
142 | Â Â fl =Â open(GPXfile,'rb') |
---|
143 |   while True: |
---|
144 | Â Â Â Â try: |
---|
145 | Â Â Â Â Â Â data =Â cPickle.load(fl) |
---|
146 |     except EOFError: |
---|
147 | Â Â Â Â Â Â break |
---|
148 | Â Â Â Â datum =Â data[0] |
---|
149 |     if datum[0] == 'Restraints': |
---|
150 | Â Â Â Â Â Â restraintDict =Â datum[1] |
---|
151 | Â Â fl.close() |
---|
152 |   return restraintDict |
---|
153 | Â Â |
---|
154 | def GetRigidBodies(GPXfile): |
---|
155 | Â Â '''Read the rigid body models from the GPX file |
---|
156 | Â Â ''' |
---|
157 | Â Â fl =Â open(GPXfile,'rb') |
---|
158 |   while True: |
---|
159 | Â Â Â Â try: |
---|
160 | Â Â Â Â Â Â data =Â cPickle.load(fl) |
---|
161 |     except EOFError: |
---|
162 | Â Â Â Â Â Â break |
---|
163 | Â Â Â Â datum =Â data[0] |
---|
164 |     if datum[0] == 'Rigid bodies': |
---|
165 | Â Â Â Â Â Â rigidbodyDict =Â datum[1] |
---|
166 | Â Â fl.close() |
---|
167 |   return rigidbodyDict |
---|
168 | Â Â Â Â |
---|
169 | def GetPhaseNames(GPXfile): |
---|
170 | Â Â ''' Returns a list of phase names found under 'Phases' in GSASII gpx file |
---|
171 | Â Â input: |
---|
172 | Â Â Â Â GPXfile = gpx full file name |
---|
173 | Â Â return: |
---|
174 | Â Â Â Â PhaseNames = list of phase names |
---|
175 | Â Â ''' |
---|
176 | Â Â fl =Â open(GPXfile,'rb') |
---|
177 | Â Â PhaseNames =Â [] |
---|
178 |   while True: |
---|
179 | Â Â Â Â try: |
---|
180 | Â Â Â Â Â Â data =Â cPickle.load(fl) |
---|
181 |     except EOFError: |
---|
182 | Â Â Â Â Â Â break |
---|
183 | Â Â Â Â datum =Â data[0] |
---|
184 |     if 'Phases' == datum[0]: |
---|
185 |       for datus in data[1:]: |
---|
186 | Â Â Â Â Â Â Â Â PhaseNames.append(datus[0]) |
---|
187 | Â Â fl.close() |
---|
188 |   return PhaseNames |
---|
189 | |
---|
190 | def GetAllPhaseData(GPXfile,PhaseName): |
---|
191 | Â Â ''' Returns the entire dictionary for PhaseName from GSASII gpx file |
---|
192 | Â Â input: |
---|
193 | Â Â Â Â GPXfile = gpx full file name |
---|
194 | Â Â Â Â PhaseName = phase name |
---|
195 | Â Â return: |
---|
196 | Â Â Â Â phase dictionary |
---|
197 | Â Â '''Â Â Â Â |
---|
198 | Â Â fl =Â open(GPXfile,'rb') |
---|
199 | Â Â General =Â {} |
---|
200 | Â Â Atoms =Â [] |
---|
201 |   while True: |
---|
202 | Â Â Â Â try: |
---|
203 | Â Â Â Â Â Â data =Â cPickle.load(fl) |
---|
204 |     except EOFError: |
---|
205 | Â Â Â Â Â Â break |
---|
206 | Â Â Â Â datum =Â data[0] |
---|
207 |     if 'Phases' == datum[0]: |
---|
208 |       for datus in data[1:]: |
---|
209 |         if datus[0] == PhaseName: |
---|
210 | Â Â Â Â Â Â Â Â Â Â break |
---|
211 | Â Â fl.close() |
---|
212 |   return datus[1] |
---|
213 | Â Â |
---|
214 | def GetHistograms(GPXfile,hNames): |
---|
215 | Â Â """ Returns a dictionary of histograms found in GSASII gpx file |
---|
216 | Â Â input: |
---|
217 | Â Â Â Â GPXfile = .gpx full file name |
---|
218 | Â Â Â Â hNames = list of histogram names |
---|
219 | Â Â return: |
---|
220 | Â Â Â Â Histograms = dictionary of histograms (types = PWDR & HKLF) |
---|
221 | Â Â """ |
---|
222 | Â Â fl =Â open(GPXfile,'rb') |
---|
223 | Â Â Histograms =Â {} |
---|
224 |   while True: |
---|
225 | Â Â Â Â try: |
---|
226 | Â Â Â Â Â Â data =Â cPickle.load(fl) |
---|
227 |     except EOFError: |
---|
228 | Â Â Â Â Â Â break |
---|
229 | Â Â Â Â datum =Â data[0] |
---|
230 | Â Â Â Â hist =Â datum[0] |
---|
231 |     if hist in hNames: |
---|
232 |       if 'PWDR' in hist[:4]: |
---|
233 | Â Â Â Â Â Â Â Â PWDRdata =Â {} |
---|
234 | Â Â Â Â Â Â Â Â try: |
---|
235 | Â Â Â Â Â Â Â Â Â Â PWDRdata.update(datum[1][0])Â Â Â Â #weight factor |
---|
236 |         except ValueError: |
---|
237 | Â Â Â Â Â Â Â Â Â Â PWDRdata['wtFactor']Â =Â 1.0Â Â Â Â Â #patch |
---|
238 | Â Â Â Â Â Â Â Â PWDRdata['Data']Â =Â datum[1][1]Â Â Â Â Â #powder data arrays |
---|
239 | Â Â Â Â Â Â Â Â PWDRdata[data[2][0]]Â =Â data[2][1]Â Â Â Â #Limits |
---|
240 | Â Â Â Â Â Â Â Â PWDRdata[data[3][0]]Â =Â data[3][1]Â Â Â Â #Background |
---|
241 | Â Â Â Â Â Â Â Â PWDRdata[data[4][0]]Â =Â data[4][1]Â Â Â Â #Instrument parameters |
---|
242 | Â Â Â Â Â Â Â Â PWDRdata[data[5][0]]Â =Â data[5][1]Â Â Â Â #Sample parameters |
---|
243 | Â Â Â Â Â Â Â Â try: |
---|
244 | Â Â Â Â Â Â Â Â Â Â PWDRdata[data[9][0]]Â =Â data[9][1]Â Â Â Â #Reflection lists might be missing |
---|
245 |         except IndexError: |
---|
246 | Â Â Â Â Â Â Â Â Â Â PWDRdata['Reflection Lists']Â =Â {} |
---|
247 | Â Â |
---|
248 | Â Â Â Â Â Â Â Â Histograms[hist]Â =Â PWDRdata |
---|
249 |       elif 'HKLF' in hist[:4]: |
---|
250 | Â Â Â Â Â Â Â Â HKLFdata =Â {} |
---|
251 | Â Â Â Â Â Â Â Â try: |
---|
252 | Â Â Â Â Â Â Â Â Â Â HKLFdata.update(datum[1][0])Â Â Â Â #weight factor |
---|
253 |         except ValueError: |
---|
254 | Â Â Â Â Â Â Â Â Â Â HKLFdata['wtFactor']Â =Â 1.0Â Â Â Â Â #patch |
---|
255 | Â Â Â Â Â Â Â Â HKLFdata['Data']Â =Â datum[1][1] |
---|
256 | Â Â Â Â Â Â Â Â HKLFdata[data[1][0]]Â =Â data[1][1]Â Â Â Â #Instrument parameters |
---|
257 | Â Â Â Â Â Â Â Â HKLFdata['Reflection Lists']Â =Â None |
---|
258 |         Histograms[hist] = HKLFdata      |
---|
259 | Â Â fl.close() |
---|
260 |   return Histograms |
---|
261 | Â Â |
---|
262 | def GetHistogramNames(GPXfile,hType): |
---|
263 | Â Â """ Returns a list of histogram names found in GSASII gpx file |
---|
264 | Â Â input: |
---|
265 | Â Â Â Â GPXfile = .gpx full file name |
---|
266 | Â Â Â Â hType = list ['PWDR','HKLF'] |
---|
267 | Â Â return: |
---|
268 | Â Â Â Â HistogramNames = list of histogram names (types = PWDR & HKLF) |
---|
269 | Â Â """ |
---|
270 | Â Â fl =Â open(GPXfile,'rb') |
---|
271 | Â Â HistogramNames =Â [] |
---|
272 |   while True: |
---|
273 | Â Â Â Â try: |
---|
274 | Â Â Â Â Â Â data =Â cPickle.load(fl) |
---|
275 |     except EOFError: |
---|
276 | Â Â Â Â Â Â break |
---|
277 | Â Â Â Â datum =Â data[0] |
---|
278 |     if datum[0][:4] in hType: |
---|
279 | Â Â Â Â Â Â HistogramNames.append(datum[0]) |
---|
280 | Â Â fl.close() |
---|
281 |   return HistogramNames |
---|
282 | Â Â |
---|
283 | def GetUsedHistogramsAndPhases(GPXfile): |
---|
284 | Â Â ''' Returns all histograms that are found in any phase |
---|
285 | Â Â and any phase that uses a histogram |
---|
286 | Â Â input: |
---|
287 | Â Â Â Â GPXfile = .gpx full file name |
---|
288 | Â Â return: |
---|
289 | Â Â Â Â Histograms = dictionary of histograms as {name:data,...} |
---|
290 | Â Â Â Â Phases = dictionary of phases that use histograms |
---|
291 | Â Â ''' |
---|
292 | Â Â phaseNames =Â GetPhaseNames(GPXfile) |
---|
293 | Â Â histoList =Â GetHistogramNames(GPXfile,['PWDR','HKLF']) |
---|
294 | Â Â allHistograms =Â GetHistograms(GPXfile,histoList) |
---|
295 | Â Â phaseData =Â {} |
---|
296 |   for name in phaseNames: |
---|
297 | Â Â Â Â phaseData[name]Â =Â GetAllPhaseData(GPXfile,name) |
---|
298 | Â Â Histograms =Â {} |
---|
299 | Â Â Phases =Â {} |
---|
300 |   for phase in phaseData: |
---|
301 | Â Â Â Â Phase =Â phaseData[phase] |
---|
302 |     if Phase['Histograms']: |
---|
303 |       if phase not in Phases: |
---|
304 | Â Â Â Â Â Â Â Â pId =Â phaseNames.index(phase) |
---|
305 | Â Â Â Â Â Â Â Â Phase['pId']Â =Â pId |
---|
306 | Â Â Â Â Â Â Â Â Phases[phase]Â =Â Phase |
---|
307 |       for hist in Phase['Histograms']: |
---|
308 |         if 'Use' not in Phase['Histograms'][hist]:   #patch |
---|
309 |           Phase['Histograms'][hist]['Use'] = True     |
---|
310 |         if hist not in Histograms and Phase['Histograms'][hist]['Use']: |
---|
311 | Â Â Â Â Â Â Â Â Â Â Histograms[hist]Â =Â allHistograms[hist] |
---|
312 | Â Â Â Â Â Â Â Â Â Â hId =Â histoList.index(hist) |
---|
313 | Â Â Â Â Â Â Â Â Â Â Histograms[hist]['hId']Â =Â hId |
---|
314 |   return Histograms,Phases |
---|
315 | Â Â |
---|
316 | def getBackupName(GPXfile,makeBack): |
---|
317 | Â Â GPXpath,GPXname =Â ospath.split(GPXfile) |
---|
318 |   if GPXpath == '': GPXpath = '.' |
---|
319 | Â Â Name =Â ospath.splitext(GPXname)[0] |
---|
320 | Â Â files =Â os.listdir(GPXpath) |
---|
321 | Â Â last =Â 0 |
---|
322 |   for name in files: |
---|
323 | Â Â Â Â name =Â name.split('.') |
---|
324 |     if len(name) == 3 and name[0] == Name and 'bak' in name[1]: |
---|
325 |       if makeBack: |
---|
326 | Â Â Â Â Â Â Â Â last =Â max(last,int(name[1].strip('bak'))+1) |
---|
327 | Â Â Â Â Â Â else: |
---|
328 | Â Â Â Â Â Â Â Â last =Â max(last,int(name[1].strip('bak'))) |
---|
329 | Â Â GPXback =Â ospath.join(GPXpath,ospath.splitext(GPXname)[0]+'.bak'+str(last)+'.gpx') |
---|
330 |   return GPXback  |
---|
331 | Â Â Â Â |
---|
332 | def GPXBackup(GPXfile,makeBack=True): |
---|
333 |   import distutils.file_util as dfu |
---|
334 | Â Â GPXback =Â getBackupName(GPXfile,makeBack) |
---|
335 | Â Â dfu.copy_file(GPXfile,GPXback) |
---|
336 |   return GPXback |
---|
337 | |
---|
338 | def SetUsedHistogramsAndPhases(GPXfile,Histograms,Phases,CovData,makeBack=True): |
---|
339 | Â Â ''' Updates gpxfile from all histograms that are found in any phase |
---|
340 | Â Â and any phase that used a histogram |
---|
341 | Â Â input: |
---|
342 | Â Â Â Â GPXfile = .gpx full file name |
---|
343 | Â Â Â Â Histograms = dictionary of histograms as {name:data,...} |
---|
344 | Â Â Â Â Phases = dictionary of phases that use histograms |
---|
345 | Â Â Â Â CovData = dictionary of refined variables, varyList, & covariance matrix |
---|
346 | Â Â Â Â makeBack = True if new backup of .gpx file is to be made; else use the last one made |
---|
347 | Â Â ''' |
---|
348 | Â Â Â Â Â Â Â Â Â Â Â Â |
---|
349 | Â Â GPXback =Â GPXBackup(GPXfile,makeBack) |
---|
350 |   print 'Read from file:',GPXback |
---|
351 |   print 'Save to file :',GPXfile |
---|
352 | Â Â infile =Â open(GPXback,'rb') |
---|
353 | Â Â outfile =Â open(GPXfile,'wb') |
---|
354 |   while True: |
---|
355 | Â Â Â Â try: |
---|
356 | Â Â Â Â Â Â data =Â cPickle.load(infile) |
---|
357 |     except EOFError: |
---|
358 | Â Â Â Â Â Â break |
---|
359 | Â Â Â Â datum =Â data[0] |
---|
360 | #Â Â Â Â print 'read: ',datum[0] |
---|
361 |     if datum[0] == 'Phases': |
---|
362 |       for iphase in range(len(data)): |
---|
363 |         if data[iphase][0] in Phases: |
---|
364 | Â Â Â Â Â Â Â Â Â Â phaseName =Â data[iphase][0] |
---|
365 | Â Â Â Â Â Â Â Â Â Â data[iphase][1].update(Phases[phaseName]) |
---|
366 |     elif datum[0] == 'Covariance': |
---|
367 | Â Â Â Â Â Â data[0][1]Â =Â CovData |
---|
368 | Â Â Â Â try: |
---|
369 | Â Â Â Â Â Â histogram =Â Histograms[datum[0]] |
---|
370 | #Â Â Â Â Â Â print 'found ',datum[0] |
---|
371 | Â Â Â Â Â Â data[0][1][1]Â =Â histogram['Data'] |
---|
372 |       for datus in data[1:]: |
---|
373 | #Â Â Â Â Â Â Â Â print 'Â Â read: ',datus[0] |
---|
374 |         if datus[0] in ['Background','Instrument Parameters','Sample Parameters','Reflection Lists']: |
---|
375 | Â Â Â Â Â Â Â Â Â Â datus[1]Â =Â histogram[datus[0]] |
---|
376 |     except KeyError: |
---|
377 | Â Â Â Â Â Â pass |
---|
378 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â |
---|
379 | Â Â Â Â cPickle.dump(data,outfile,1) |
---|
380 | Â Â infile.close() |
---|
381 | Â Â outfile.close() |
---|
382 |   print 'GPX file save successful' |
---|
383 | Â Â |
---|
384 | def SetSeqResult(GPXfile,Histograms,SeqResult): |
---|
385 | Â Â GPXback =Â GPXBackup(GPXfile) |
---|
386 |   print 'Read from file:',GPXback |
---|
387 |   print 'Save to file :',GPXfile |
---|
388 | Â Â infile =Â open(GPXback,'rb') |
---|
389 | Â Â outfile =Â open(GPXfile,'wb') |
---|
390 |   while True: |
---|
391 | Â Â Â Â try: |
---|
392 | Â Â Â Â Â Â data =Â cPickle.load(infile) |
---|
393 |     except EOFError: |
---|
394 | Â Â Â Â Â Â break |
---|
395 | Â Â Â Â datum =Â data[0] |
---|
396 |     if datum[0] == 'Sequental results': |
---|
397 | Â Â Â Â Â Â data[0][1]Â =Â SeqResult |
---|
398 | Â Â Â Â try: |
---|
399 | Â Â Â Â Â Â histogram =Â Histograms[datum[0]] |
---|
400 | Â Â Â Â Â Â data[0][1][1]Â =Â histogram['Data'] |
---|
401 |       for datus in data[1:]: |
---|
402 |         if datus[0] in ['Background','Instrument Parameters','Sample Parameters','Reflection Lists']: |
---|
403 | Â Â Â Â Â Â Â Â Â Â datus[1]Â =Â histogram[datus[0]] |
---|
404 |     except KeyError: |
---|
405 | Â Â Â Â Â Â pass |
---|
406 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â |
---|
407 | Â Â Â Â cPickle.dump(data,outfile,1) |
---|
408 | Â Â infile.close() |
---|
409 | Â Â outfile.close() |
---|
410 |   print 'GPX file save successful' |
---|
411 | Â Â Â Â Â Â Â Â Â Â Â Â |
---|
412 | def ShowBanner(pFile=None): |
---|
413 |   print >>pFile,80*'*' |
---|
414 |   print >>pFile,'  General Structure Analysis System-II Crystal Structure Refinement' |
---|
415 |   print >>pFile,'       by Robert B. Von Dreele & Brian H. Toby' |
---|
416 |   print >>pFile,'        Argonne National Laboratory(C), 2010' |
---|
417 |   print >>pFile,' This product includes software developed by the UChicago Argonne, LLC,' |
---|
418 |   print >>pFile,'      as Operator of Argonne National Laboratory.' |
---|
419 |   print >>pFile,80*'*','\n' |
---|
420 | |
---|
421 | def ShowControls(Controls,pFile=None): |
---|
422 |   print >>pFile,' Least squares controls:' |
---|
423 |   print >>pFile,' Refinement type: ',Controls['deriv type'] |
---|
424 |   if 'Hessian' in Controls['deriv type']: |
---|
425 |     print >>pFile,' Maximum number of cycles:',Controls['max cyc'] |
---|
426 | Â Â else: |
---|
427 |     print >>pFile,' Minimum delta-M/M for convergence: ','%.2g'%(Controls['min dM/M']) |
---|
428 |   print >>pFile,' Initial shift factor: ','%.3f'%(Controls['shift factor']) |
---|
429 | Â Â |
---|
430 | def GetFFtable(General): |
---|
431 | Â Â ''' returns a dictionary of form factor data for atom types found in General |
---|
432 | Â Â input: |
---|
433 | Â Â Â Â General = dictionary of phase info.; includes AtomTypes |
---|
434 | Â Â return: |
---|
435 | Â Â Â Â FFtable = dictionary of form factor data; key is atom type |
---|
436 | Â Â ''' |
---|
437 | Â Â atomTypes =Â General['AtomTypes'] |
---|
438 | Â Â FFtable =Â {} |
---|
439 |   for El in atomTypes: |
---|
440 | Â Â Â Â FFs =Â G2el.GetFormFactorCoeff(El.split('+')[0].split('-')[0]) |
---|
441 |     for item in FFs: |
---|
442 |       if item['Symbol'] == El.upper(): |
---|
443 | Â Â Â Â Â Â Â Â FFtable[El]Â =Â item |
---|
444 |   return FFtable |
---|
445 | Â Â |
---|
446 | def GetBLtable(General): |
---|
447 | Â Â ''' returns a dictionary of neutron scattering length data for atom types & isotopes found in General |
---|
448 | Â Â input: |
---|
449 | Â Â Â Â General = dictionary of phase info.; includes AtomTypes & Isotopes |
---|
450 | Â Â return: |
---|
451 | Â Â Â Â BLtable = dictionary of scattering length data; key is atom type |
---|
452 | Â Â ''' |
---|
453 | Â Â atomTypes =Â General['AtomTypes'] |
---|
454 | Â Â BLtable =Â {} |
---|
455 | Â Â isotopes =Â General['Isotopes'] |
---|
456 | Â Â isotope =Â General['Isotope'] |
---|
457 |   for El in atomTypes: |
---|
458 | Â Â Â Â BLtable[El]Â =Â [isotope[El],isotopes[El][isotope[El]]] |
---|
459 |   return BLtable |
---|
460 | Â Â Â Â |
---|
461 | def GetPawleyConstr(SGLaue,PawleyRef,pawleyVary): |
---|
462 | #Â Â if SGLaue in ['-1','2/m','mmm']: |
---|
463 | #    return           #no Pawley symmetry required constraints |
---|
464 | Â Â eqvDict =Â {} |
---|
465 |   for i,varyI in enumerate(pawleyVary): |
---|
466 | Â Â Â Â eqvDict[varyI]Â =Â [] |
---|
467 | Â Â Â Â refI =Â int(varyI.split(':')[-1]) |
---|
468 | Â Â Â Â ih,ik,il =Â PawleyRef[refI][:3] |
---|
469 | Â Â Â Â dspI =Â PawleyRef[refI][4] |
---|
470 |     for varyJ in pawleyVary[i+1:]: |
---|
471 | Â Â Â Â Â Â refJ =Â int(varyJ.split(':')[-1]) |
---|
472 | Â Â Â Â Â Â jh,jk,jl =Â PawleyRef[refJ][:3] |
---|
473 | Â Â Â Â Â Â dspJ =Â PawleyRef[refJ][4] |
---|
474 |       if SGLaue in ['4/m','4/mmm']: |
---|
475 | Â Â Â Â Â Â Â Â isum =Â ih**2+ik**2 |
---|
476 | Â Â Â Â Â Â Â Â jsum =Â jh**2+jk**2 |
---|
477 |         if abs(il) == abs(jl) and isum == jsum: |
---|
478 | Â Â Â Â Â Â Â Â Â Â eqvDict[varyI].append(varyJ)Â |
---|
479 |       elif SGLaue in ['3R','3mR']: |
---|
480 | Â Â Â Â Â Â Â Â isum =Â ih**2+ik**2+il**2 |
---|
481 | Â Â Â Â Â Â Â Â jsum =Â jh**2+jk**2*jl**2 |
---|
482 | Â Â Â Â Â Â Â Â isum2 =Â ih*ik+ih*il+ik*il |
---|
483 | Â Â Â Â Â Â Â Â jsum2 =Â jh*jk+jh*jl+jk*jl |
---|
484 |         if isum == jsum and isum2 == jsum2: |
---|
485 | Â Â Â Â Â Â Â Â Â Â eqvDict[varyI].append(varyJ)Â |
---|
486 |       elif SGLaue in ['3','3m1','31m','6/m','6/mmm']: |
---|
487 | Â Â Â Â Â Â Â Â isum =Â ih**2+ik**2+ih*ik |
---|
488 | Â Â Â Â Â Â Â Â jsum =Â jh**2+jk**2+jh*jk |
---|
489 |         if abs(il) == abs(jl) and isum == jsum: |
---|
490 | Â Â Â Â Â Â Â Â Â Â eqvDict[varyI].append(varyJ)Â |
---|
491 |       elif SGLaue in ['m3','m3m']: |
---|
492 | Â Â Â Â Â Â Â Â isum =Â ih**2+ik**2+il**2 |
---|
493 | Â Â Â Â Â Â Â Â jsum =Â jh**2+jk**2+jl**2 |
---|
494 |         if isum == jsum: |
---|
495 | Â Â Â Â Â Â Â Â Â Â eqvDict[varyI].append(varyJ) |
---|
496 |       elif abs(dspI-dspJ)/dspI < 1.e-4: |
---|
497 | Â Â Â Â Â Â Â Â eqvDict[varyI].append(varyJ)Â |
---|
498 |   for item in pawleyVary: |
---|
499 |     if eqvDict[item]: |
---|
500 |       for item2 in pawleyVary: |
---|
501 |         if item2 in eqvDict[item]: |
---|
502 | Â Â Â Â Â Â Â Â Â Â eqvDict[item2]Â =Â [] |
---|
503 | Â Â Â Â Â Â G2mv.StoreEquivalence(item,eqvDict[item]) |
---|
504 | Â Â Â Â Â Â Â Â Â Â |
---|
505 | def cellVary(pfx,SGData): |
---|
506 |   if SGData['SGLaue'] in ['-1',]: |
---|
507 |     return [pfx+'A0',pfx+'A1',pfx+'A2',pfx+'A3',pfx+'A4',pfx+'A5'] |
---|
508 |   elif SGData['SGLaue'] in ['2/m',]: |
---|
509 |     if SGData['SGUniq'] == 'a': |
---|
510 |       return [pfx+'A0',pfx+'A1',pfx+'A2',pfx+'A3'] |
---|
511 |     elif SGData['SGUniq'] == 'b': |
---|
512 |       return [pfx+'A0',pfx+'A1',pfx+'A2',pfx+'A4'] |
---|
513 | Â Â Â Â else: |
---|
514 |       return [pfx+'A0',pfx+'A1',pfx+'A2',pfx+'A5'] |
---|
515 |   elif SGData['SGLaue'] in ['mmm',]: |
---|
516 |     return [pfx+'A0',pfx+'A1',pfx+'A2'] |
---|
517 |   elif SGData['SGLaue'] in ['4/m','4/mmm']: |
---|
518 |     return [pfx+'A0',pfx+'A2'] |
---|
519 |   elif SGData['SGLaue'] in ['6/m','6/mmm','3m1', '31m', '3']: |
---|
520 |     return [pfx+'A0',pfx+'A2'] |
---|
521 |   elif SGData['SGLaue'] in ['3R', '3mR']: |
---|
522 |     return [pfx+'A0',pfx+'A3']            |
---|
523 |   elif SGData['SGLaue'] in ['m3m','m3']: |
---|
524 |     return [pfx+'A0',] |
---|
525 | Â Â Â Â |
---|
526 | ################################################################################ |
---|
527 | ##### Phase data |
---|
528 | ################################################################################Â Â Â Â |
---|
529 | Â Â Â Â Â Â Â Â Â Â |
---|
530 | def GetPhaseData(PhaseData,RestraintDict={},Print=True,pFile=None): |
---|
531 | Â Â Â Â Â Â |
---|
532 |   def PrintFFtable(FFtable): |
---|
533 |     print >>pFile,'\n X-ray scattering factors:' |
---|
534 |     print >>pFile,'  Symbol   fa                   fb                   fc' |
---|
535 |     print >>pFile,99*'-' |
---|
536 |     for Ename in FFtable: |
---|
537 | Â Â Â Â Â Â ffdata =Â FFtable[Ename] |
---|
538 | Â Â Â Â Â Â fa =Â ffdata['fa'] |
---|
539 | Â Â Â Â Â Â fb =Â ffdata['fb'] |
---|
540 |       print >>pFile,' %8s %9.5f %9.5f %9.5f %9.5f %9.5f %9.5f %9.5f %9.5f %9.5f' % \ |
---|
541 | Â Â Â Â Â Â Â Â (Ename.ljust(8),fa[0],fa[1],fa[2],fa[3],fb[0],fb[1],fb[2],fb[3],ffdata['fc']) |
---|
542 | Â Â Â Â Â Â Â Â |
---|
543 |   def PrintBLtable(BLtable): |
---|
544 |     print >>pFile,'\n Neutron scattering factors:' |
---|
545 |     print >>pFile,'  Symbol  isotope    mass    b    resonant terms' |
---|
546 |     print >>pFile,99*'-' |
---|
547 |     for Ename in BLtable: |
---|
548 | Â Â Â Â Â Â bldata =Â BLtable[Ename] |
---|
549 | Â Â Â Â Â Â isotope =Â bldata[0] |
---|
550 | Â Â Â Â Â Â mass =Â bldata[1][0] |
---|
551 | Â Â Â Â Â Â blen =Â bldata[1][1] |
---|
552 | Â Â Â Â Â Â bres =Â [] |
---|
553 |       if len(bldata[1]) > 2: |
---|
554 | Â Â Â Â Â Â Â Â bres =Â bldata[1][2:] |
---|
555 |       line = ' %8s%11s %10.3f %8.3f'%(Ename.ljust(8),isotope.center(11),mass,blen) |
---|
556 |       for item in bres: |
---|
557 | Â Â Â Â Â Â Â Â line +=Â '%10.5g'%(item) |
---|
558 |       print >>pFile,line |
---|
559 | Â Â Â Â Â Â |
---|
560 | Â Â #def PrintRBObjects() |
---|
561 | Â Â Â Â Â Â Â Â |
---|
562 |   def PrintAtoms(General,Atoms): |
---|
563 | Â Â Â Â cx,ct,cs,cia =Â General['AtomPtrs'] |
---|
564 |     print >>pFile,'\n Atoms:' |
---|
565 |     line = '  name  type refine?  x     y     z  '+ \ |
---|
566 |       ' frac site sym mult I/A  Uiso   U11   U22   U33   U12   U13   U23' |
---|
567 |     if General['Type'] == 'magnetic': |
---|
568 |       line += '  Mx   My   Mz' |
---|
569 |     elif General['Type'] == 'macromolecular': |
---|
570 | Â Â Â Â Â Â line =Â ' res no residue chain'+line |
---|
571 |     print >>pFile,line |
---|
572 |     if General['Type'] == 'nuclear': |
---|
573 |       print >>pFile,135*'-' |
---|
574 |       for i,at in enumerate(Atoms): |
---|
575 | Â Â Â Â Â Â Â Â line =Â '%7s'%(at[ct-1])+'%7s'%(at[ct])+'%7s'%(at[ct+1])+'%10.5f'%(at[cx])+'%10.5f'%(at[cx+1])+Â \ |
---|
576 | Â Â Â Â Â Â Â Â Â Â '%10.5f'%(at[cx+2])+'%8.3f'%(at[cx+3])+'%7s'%(at[cs])+'%5d'%(at[cs+1])+'%5s'%(at[cia]) |
---|
577 |         if at[cia] == 'I': |
---|
578 | Â Â Â Â Â Â Â Â Â Â line +=Â '%8.4f'%(at[cia+1])+48*' ' |
---|
579 | Â Â Â Â Â Â Â Â else: |
---|
580 | Â Â Â Â Â Â Â Â Â Â line +=Â 8*' ' |
---|
581 |           for j in range(6): |
---|
582 | Â Â Â Â Â Â Â Â Â Â Â Â line +=Â '%8.4f'%(at[cia+1+j]) |
---|
583 |         print >>pFile,line |
---|
584 |     elif General['Type'] == 'macromolecular': |
---|
585 |       print >>pFile,135*'-'      |
---|
586 |       for i,at in enumerate(Atoms): |
---|
587 | Â Â Â Â Â Â Â Â line =Â '%7s'%(at[0])+'%7s'%(at[1])+'%7s'%(at[2])+'%7s'%(at[ct-1])+'%7s'%(at[ct])+'%7s'%(at[ct+1])+'%10.5f'%(at[cx])+'%10.5f'%(at[cx+1])+Â \ |
---|
588 | Â Â Â Â Â Â Â Â Â Â '%10.5f'%(at[cx+2])+'%8.3f'%(at[cx+3])+'%7s'%(at[cs])+'%5d'%(at[cs+1])+'%5s'%(at[cia]) |
---|
589 |         if at[cia] == 'I': |
---|
590 | Â Â Â Â Â Â Â Â Â Â line +=Â '%8.4f'%(at[cia+1])+48*' ' |
---|
591 | Â Â Â Â Â Â Â Â else: |
---|
592 | Â Â Â Â Â Â Â Â Â Â line +=Â 8*' ' |
---|
593 |           for j in range(6): |
---|
594 | Â Â Â Â Â Â Â Â Â Â Â Â line +=Â '%8.4f'%(at[cia+1+j]) |
---|
595 |         print >>pFile,line |
---|
596 | Â Â Â Â |
---|
597 |   def PrintTexture(textureData): |
---|
598 |     topstr = '\n Spherical harmonics texture: Order:' + \ |
---|
599 | Â Â Â Â Â Â str(textureData['Order']) |
---|
600 |     if textureData['Order']: |
---|
601 |       print >>pFile,topstr+' Refine? '+str(textureData['SH Coeff'][0]) |
---|
602 | Â Â Â Â else: |
---|
603 |       print >>pFile,topstr |
---|
604 | Â Â Â Â Â Â return |
---|
605 | Â Â Â Â names =Â ['omega','chi','phi'] |
---|
606 | Â Â Â Â line =Â '\n' |
---|
607 |     for name in names: |
---|
608 | Â Â Â Â Â Â line +=Â ' SH '+name+':'+'%12.4f'%(textureData['Sample '+name][1])+' Refine? '+str(textureData['Sample '+name][0]) |
---|
609 |     print >>pFile,line |
---|
610 |     print >>pFile,'\n Texture coefficients:' |
---|
611 | Â Â Â Â ptlbls =Â ' names :' |
---|
612 | Â Â Â Â ptstr =Â ' values:' |
---|
613 | Â Â Â Â SHcoeff =Â textureData['SH Coeff'][1] |
---|
614 |     for item in SHcoeff: |
---|
615 | Â Â Â Â Â Â ptlbls +=Â '%12s'%(item) |
---|
616 | Â Â Â Â Â Â ptstr +=Â '%12.4f'%(SHcoeff[item])Â |
---|
617 |     print >>pFile,ptlbls |
---|
618 |     print >>pFile,ptstr |
---|
619 | Â Â Â Â |
---|
620 |   if Print:print >>pFile,' Phases:' |
---|
621 | Â Â phaseVary =Â [] |
---|
622 | Â Â phaseDict =Â {} |
---|
623 | Â Â phaseConstr =Â {} |
---|
624 | Â Â pawleyLookup =Â {} |
---|
625 | Â Â FFtables =Â {}Â Â Â Â Â Â Â Â Â Â #scattering factors - xrays |
---|
626 | Â Â BLtables =Â {}Â Â Â Â Â Â Â Â Â Â # neutrons |
---|
627 | Â Â Natoms =Â {} |
---|
628 | Â Â AtMults =Â {} |
---|
629 | Â Â AtIA =Â {} |
---|
630 | Â Â shModels =Â ['cylindrical','none','shear - 2/m','rolling - mmm'] |
---|
631 | Â Â SamSym =Â dict(zip(shModels,['0','-1','2/m','mmm'])) |
---|
632 | Â Â atomIndx =Â {} |
---|
633 |   for name in PhaseData: |
---|
634 | Â Â Â Â General =Â PhaseData[name]['General'] |
---|
635 | Â Â Â Â pId =Â PhaseData[name]['pId'] |
---|
636 | Â Â Â Â pfx =Â str(pId)+'::' |
---|
637 | Â Â Â Â FFtable =Â GetFFtable(General) |
---|
638 | Â Â Â Â BLtable =Â GetBLtable(General) |
---|
639 | Â Â Â Â FFtables.update(FFtable) |
---|
640 | Â Â Â Â BLtables.update(BLtable) |
---|
641 | Â Â Â Â Atoms =Â PhaseData[name]['Atoms'] |
---|
642 | Â Â Â Â AtLookup =Â G2mth.FillAtomLookUp(Atoms) |
---|
643 | Â Â Â Â try: |
---|
644 | Â Â Â Â Â Â PawleyRef =Â PhaseData[name]['Pawley ref'] |
---|
645 |     except KeyError: |
---|
646 | Â Â Â Â Â Â PawleyRef =Â [] |
---|
647 | Â Â Â Â SGData =Â General['SGData'] |
---|
648 | Â Â Â Â SGtext =Â G2spc.SGPrint(SGData) |
---|
649 | Â Â Â Â cell =Â General['Cell'] |
---|
650 | Â Â Â Â A =Â G2lat.cell2A(cell[1:7]) |
---|
651 | Â Â Â Â phaseDict.update({pfx+'A0':A[0],pfx+'A1':A[1],pfx+'A2':A[2], |
---|
652 | Â Â Â Â Â Â pfx+'A3':A[3],pfx+'A4':A[4],pfx+'A5':A[5],pfx+'Vol':G2lat.calc_V(A)}) |
---|
653 |     if cell[0]: |
---|
654 | Â Â Â Â Â Â phaseVary +=Â cellVary(pfx,SGData) |
---|
655 | Â Â Â Â #rigid body model input here |
---|
656 | Â Â Â Â Natoms[pfx]Â =Â 0 |
---|
657 |     if Atoms and not General.get('doPawley'): |
---|
658 | Â Â Â Â Â Â cx,ct,cs,cia =Â General['AtomPtrs'] |
---|
659 |       if General['Type'] in ['nuclear','macromolecular']: |
---|
660 | Â Â Â Â Â Â Â Â Natoms[pfx]Â =Â len(Atoms) |
---|
661 |         for i,at in enumerate(Atoms): |
---|
662 | Â Â Â Â Â Â Â Â Â Â atomIndx[at[-1]]Â =Â [pfx,i]Â Â Â #lookup table for restraints |
---|
663 | Â Â Â Â Â Â Â Â Â Â phaseDict.update({pfx+'Atype:'+str(i):at[ct],pfx+'Afrac:'+str(i):at[cx+3],pfx+'Amul:'+str(i):at[cs+1], |
---|
664 | Â Â Â Â Â Â Â Â Â Â Â Â pfx+'Ax:'+str(i):at[cx],pfx+'Ay:'+str(i):at[cx+1],pfx+'Az:'+str(i):at[cx+2], |
---|
665 |             pfx+'dAx:'+str(i):0.,pfx+'dAy:'+str(i):0.,pfx+'dAz:'+str(i):0.,     #refined shifts for x,y,z |
---|
666 | Â Â Â Â Â Â Â Â Â Â Â Â pfx+'AI/A:'+str(i):at[cia],}) |
---|
667 |           if at[cia] == 'I': |
---|
668 | Â Â Â Â Â Â Â Â Â Â Â Â phaseDict[pfx+'AUiso:'+str(i)]Â =Â at[cia+1] |
---|
669 | Â Â Â Â Â Â Â Â Â Â else: |
---|
670 | Â Â Â Â Â Â Â Â Â Â Â Â phaseDict.update({pfx+'AU11:'+str(i):at[cia+2],pfx+'AU22:'+str(i):at[cia+3],pfx+'AU33:'+str(i):at[cia+4], |
---|
671 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â pfx+'AU12:'+str(i):at[cia+5],pfx+'AU13:'+str(i):at[cia+6],pfx+'AU23:'+str(i):at[cia+7]}) |
---|
672 |           if 'F' in at[ct+1]: |
---|
673 | Â Â Â Â Â Â Â Â Â Â Â Â phaseVary.append(pfx+'Afrac:'+str(i)) |
---|
674 |           if 'X' in at[ct+1]: |
---|
675 | Â Â Â Â Â Â Â Â Â Â Â Â xId,xCoef =Â G2spc.GetCSxinel(at[cs]) |
---|
676 | Â Â Â Â Â Â Â Â Â Â Â Â names =Â [pfx+'dAx:'+str(i),pfx+'dAy:'+str(i),pfx+'dAz:'+str(i)] |
---|
677 | Â Â Â Â Â Â Â Â Â Â Â Â equivs =Â [[],[],[]] |
---|
678 |             for j in range(3): |
---|
679 |               if xId[j] > 0:                |
---|
680 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â phaseVary.append(names[j]) |
---|
681 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â equivs[xId[j]-1].append([names[j],xCoef[j]]) |
---|
682 |             for equiv in equivs: |
---|
683 |               if len(equiv) > 1: |
---|
684 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â name =Â equiv[0][0] |
---|
685 |                 for eqv in equiv[1:]: |
---|
686 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â G2mv.StoreEquivalence(name,(eqv,)) |
---|
687 |           if 'U' in at[ct+1]: |
---|
688 |             if at[9] == 'I': |
---|
689 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â phaseVary.append(pfx+'AUiso:'+str(i)) |
---|
690 | Â Â Â Â Â Â Â Â Â Â Â Â else: |
---|
691 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â uId,uCoef =Â G2spc.GetCSuinel(at[cs])[:2] |
---|
692 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â names =Â [pfx+'AU11:'+str(i),pfx+'AU22:'+str(i),pfx+'AU33:'+str(i), |
---|
693 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â pfx+'AU12:'+str(i),pfx+'AU13:'+str(i),pfx+'AU23:'+str(i)] |
---|
694 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â equivs =Â [[],[],[],[],[],[]] |
---|
695 |               for j in range(6): |
---|
696 |                 if uId[j] > 0:                |
---|
697 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â phaseVary.append(names[j]) |
---|
698 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â equivs[uId[j]-1].append([names[j],uCoef[j]]) |
---|
699 |               for equiv in equivs: |
---|
700 |                 if len(equiv) > 1: |
---|
701 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â name =Â equiv[0][0] |
---|
702 |                   for eqv in equiv[1:]: |
---|
703 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â G2mv.StoreEquivalence(name,(eqv,)) |
---|
704 | #Â Â Â Â Â Â elif General['Type'] == 'magnetic': |
---|
705 | #Â Â Â Â Â Â elif General['Type'] == 'macromolecular': |
---|
706 | Â Â Â Â Â Â textureData =Â General['SH Texture'] |
---|
707 |       if textureData['Order']: |
---|
708 | Â Â Â Â Â Â Â Â phaseDict[pfx+'SHorder']Â =Â textureData['Order'] |
---|
709 | Â Â Â Â Â Â Â Â phaseDict[pfx+'SHmodel']Â =Â SamSym[textureData['Model']] |
---|
710 |         for item in ['omega','chi','phi']: |
---|
711 | Â Â Â Â Â Â Â Â Â Â phaseDict[pfx+'SH '+item]Â =Â textureData['Sample '+item][1] |
---|
712 |           if textureData['Sample '+item][0]: |
---|
713 | Â Â Â Â Â Â Â Â Â Â Â Â phaseVary.append(pfx+'SH '+item) |
---|
714 |         for item in textureData['SH Coeff'][1]: |
---|
715 | Â Â Â Â Â Â Â Â Â Â phaseDict[pfx+item]Â =Â textureData['SH Coeff'][1][item] |
---|
716 |           if textureData['SH Coeff'][0]: |
---|
717 | Â Â Â Â Â Â Â Â Â Â Â Â phaseVary.append(pfx+item) |
---|
718 | Â Â Â Â Â Â Â Â |
---|
719 |       if Print: |
---|
720 |         print >>pFile,'\n Phase name: ',General['Name'] |
---|
721 |         print >>pFile,135*'-' |
---|
722 | Â Â Â Â Â Â Â Â PrintFFtable(FFtable) |
---|
723 | Â Â Â Â Â Â Â Â PrintBLtable(BLtable) |
---|
724 |         print >>pFile,'' |
---|
725 |         for line in SGtext: print >>pFile,line |
---|
726 | Â Â Â Â Â Â Â Â #PrintRBObjects(whatever is needed here) |
---|
727 | Â Â Â Â Â Â Â Â PrintAtoms(General,Atoms) |
---|
728 |         print >>pFile,'\n Unit cell: a =','%.5f'%(cell[1]),' b =','%.5f'%(cell[2]),' c =','%.5f'%(cell[3]), \ |
---|
729 |           ' alpha =','%.3f'%(cell[4]),' beta =','%.3f'%(cell[5]),' gamma =', \ |
---|
730 | Â Â Â Â Â Â Â Â Â Â '%.3f'%(cell[6]),' volume =','%.3f'%(cell[7]),' Refine?',cell[0] |
---|
731 | Â Â Â Â Â Â Â Â PrintTexture(textureData) |
---|
732 |         if name in RestraintDict: |
---|
733 | Â Â Â Â Â Â Â Â Â Â PrintRestraints(cell[1:7],SGData,General['AtomPtrs'],Atoms,AtLookup, |
---|
734 | Â Â Â Â Â Â Â Â Â Â Â Â textureData,RestraintDict[name],pFile) |
---|
735 | Â Â Â Â Â Â Â Â Â Â |
---|
736 |     elif PawleyRef: |
---|
737 | Â Â Â Â Â Â pawleyVary =Â [] |
---|
738 |       for i,refl in enumerate(PawleyRef): |
---|
739 | Â Â Â Â Â Â Â Â phaseDict[pfx+'PWLref:'+str(i)]Â =Â refl[6] |
---|
740 | Â Â Â Â Â Â Â Â pawleyLookup[pfx+'%d,%d,%d'%(refl[0],refl[1],refl[2])]Â =Â i |
---|
741 |         if refl[5]: |
---|
742 | Â Â Â Â Â Â Â Â Â Â pawleyVary.append(pfx+'PWLref:'+str(i)) |
---|
743 | Â Â Â Â Â Â GetPawleyConstr(SGData['SGLaue'],PawleyRef,pawleyVary)Â Â Â #does G2mv.StoreEquivalence |
---|
744 | Â Â Â Â Â Â phaseVary +=Â pawleyVary |
---|
745 | Â Â Â Â Â Â Â Â |
---|
746 |   return Natoms,atomIndx,phaseVary,phaseDict,pawleyLookup,FFtables,BLtables |
---|
747 | Â Â |
---|
748 | def cellFill(pfx,SGData,parmDict,sigDict): |
---|
749 |   if SGData['SGLaue'] in ['-1',]: |
---|
750 | Â Â Â Â A =Â [parmDict[pfx+'A0'],parmDict[pfx+'A1'],parmDict[pfx+'A2'], |
---|
751 | Â Â Â Â Â Â parmDict[pfx+'A3'],parmDict[pfx+'A4'],parmDict[pfx+'A5']] |
---|
752 | Â Â Â Â sigA =Â [sigDict[pfx+'A0'],sigDict[pfx+'A1'],sigDict[pfx+'A2'], |
---|
753 | Â Â Â Â Â Â sigDict[pfx+'A3'],sigDict[pfx+'A4'],sigDict[pfx+'A5']] |
---|
754 |   elif SGData['SGLaue'] in ['2/m',]: |
---|
755 |     if SGData['SGUniq'] == 'a': |
---|
756 | Â Â Â Â Â Â A =Â [parmDict[pfx+'A0'],parmDict[pfx+'A1'],parmDict[pfx+'A2'], |
---|
757 | Â Â Â Â Â Â Â Â parmDict[pfx+'A3'],0,0] |
---|
758 | Â Â Â Â Â Â sigA =Â [sigDict[pfx+'A0'],sigDict[pfx+'A1'],sigDict[pfx+'A2'], |
---|
759 | Â Â Â Â Â Â Â Â sigDict[pfx+'A3'],0,0] |
---|
760 |     elif SGData['SGUniq'] == 'b': |
---|
761 | Â Â Â Â Â Â A =Â [parmDict[pfx+'A0'],parmDict[pfx+'A1'],parmDict[pfx+'A2'], |
---|
762 | Â Â Â Â Â Â Â Â 0,parmDict[pfx+'A4'],0] |
---|
763 | Â Â Â Â Â Â sigA =Â [sigDict[pfx+'A0'],sigDict[pfx+'A1'],sigDict[pfx+'A2'], |
---|
764 | Â Â Â Â Â Â Â Â 0,sigDict[pfx+'A4'],0] |
---|
765 | Â Â Â Â else: |
---|
766 | Â Â Â Â Â Â A =Â [parmDict[pfx+'A0'],parmDict[pfx+'A1'],parmDict[pfx+'A2'], |
---|
767 | Â Â Â Â Â Â Â Â 0,0,parmDict[pfx+'A5']] |
---|
768 | Â Â Â Â Â Â sigA =Â [sigDict[pfx+'A0'],sigDict[pfx+'A1'],sigDict[pfx+'A2'], |
---|
769 | Â Â Â Â Â Â Â Â 0,0,sigDict[pfx+'A5']] |
---|
770 |   elif SGData['SGLaue'] in ['mmm',]: |
---|
771 | Â Â Â Â A =Â [parmDict[pfx+'A0'],parmDict[pfx+'A1'],parmDict[pfx+'A2'],0,0,0] |
---|
772 | Â Â Â Â sigA =Â [sigDict[pfx+'A0'],sigDict[pfx+'A1'],sigDict[pfx+'A2'],0,0,0] |
---|
773 |   elif SGData['SGLaue'] in ['4/m','4/mmm']: |
---|
774 | Â Â Â Â A =Â [parmDict[pfx+'A0'],parmDict[pfx+'A0'],parmDict[pfx+'A2'],0,0,0] |
---|
775 | Â Â Â Â sigA =Â [sigDict[pfx+'A0'],0,sigDict[pfx+'A2'],0,0,0] |
---|
776 |   elif SGData['SGLaue'] in ['6/m','6/mmm','3m1', '31m', '3']: |
---|
777 | Â Â Â Â A =Â [parmDict[pfx+'A0'],parmDict[pfx+'A0'],parmDict[pfx+'A2'], |
---|
778 | Â Â Â Â Â Â parmDict[pfx+'A0'],0,0] |
---|
779 | Â Â Â Â sigA =Â [sigDict[pfx+'A0'],0,sigDict[pfx+'A2'],0,0,0] |
---|
780 |   elif SGData['SGLaue'] in ['3R', '3mR']: |
---|
781 | Â Â Â Â A =Â [parmDict[pfx+'A0'],parmDict[pfx+'A0'],parmDict[pfx+'A0'], |
---|
782 | Â Â Â Â Â Â parmDict[pfx+'A3'],parmDict[pfx+'A3'],parmDict[pfx+'A3']] |
---|
783 | Â Â Â Â sigA =Â [sigDict[pfx+'A0'],0,0,sigDict[pfx+'A3'],0,0] |
---|
784 |   elif SGData['SGLaue'] in ['m3m','m3']: |
---|
785 | Â Â Â Â A =Â [parmDict[pfx+'A0'],parmDict[pfx+'A0'],parmDict[pfx+'A0'],0,0,0] |
---|
786 | Â Â Â Â sigA =Â [sigDict[pfx+'A0'],0,0,0,0,0] |
---|
787 |   return A,sigA |
---|
788 | Â Â Â Â |
---|
789 | def PrintRestraints(cell,SGData,AtPtrs,Atoms,AtLookup,textureData,phaseRest,pFile): |
---|
790 |   if phaseRest: |
---|
791 | Â Â Â Â Amat =Â G2lat.cell2AB(cell)[0] |
---|
792 | Â Â Â Â cx,ct,cs =Â AtPtrs[:3] |
---|
793 | Â Â Â Â names =Â [['Bond','Bonds'],['Angle','Angles'],['Plane','Planes'], |
---|
794 | Â Â Â Â Â Â ['Chiral','Volumes'],['Torsion','Torsions'],['Rama','Ramas'], |
---|
795 | Â Â Â Â Â Â ['ChemComp','Sites'],['Texture','HKLs']] |
---|
796 |     for name,rest in names: |
---|
797 | Â Â Â Â Â Â itemRest =Â phaseRest[name] |
---|
798 |       if itemRest[rest] and itemRest['Use']: |
---|
799 |         print >>pFile,'\n %s %10.3f Use: %s'%(name+' restraint weight factor',itemRest['wtFactor'],str(itemRest['Use'])) |
---|
800 |         if name in ['Bond','Angle','Plane','Chiral']: |
---|
801 |           print >>pFile,'   calc    obs   sig  delt/sig atoms(symOp): ' |
---|
802 |           for indx,ops,obs,esd in itemRest[rest]: |
---|
803 | Â Â Â Â Â Â Â Â Â Â Â Â try: |
---|
804 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â AtNames =Â G2mth.GetAtomItemsById(Atoms,AtLookup,indx,ct-1) |
---|
805 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â AtName =Â '' |
---|
806 |               for i,Aname in enumerate(AtNames): |
---|
807 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â AtName +=Â Aname |
---|
808 |                 if ops[i] == '1': |
---|
809 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â AtName +=Â '-' |
---|
810 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â else: |
---|
811 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â AtName +=Â '+('+ops[i]+')-' |
---|
812 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â XYZ =Â np.array(G2mth.GetAtomItemsById(Atoms,AtLookup,indx,cx,3)) |
---|
813 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â XYZ =Â G2mth.getSyXYZ(XYZ,ops,SGData) |
---|
814 |               if name == 'Bond': |
---|
815 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â calc =Â G2mth.getRestDist(XYZ,Amat) |
---|
816 |               elif name == 'Angle': |
---|
817 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â calc =Â G2mth.getRestAngle(XYZ,Amat) |
---|
818 |               elif name == 'Plane': |
---|
819 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â calc =Â G2mth.getRestPlane(XYZ,Amat) |
---|
820 |               elif name == 'Chiral': |
---|
821 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â calc =Â G2mth.getRestChiral(XYZ,Amat) |
---|
822 |               print >>pFile,' %9.3f %9.3f %8.3f %8.3f  %s'%(calc,obs,esd,(obs-calc)/esd,AtName[:-1]) |
---|
823 |             except KeyError: |
---|
824 |               del itemRest[rest] |
---|
825 |         elif name in ['Torsion','Rama']: |
---|
826 |           print >>pFile,' atoms(symOp) calc obs sig delt/sig torsions: ' |
---|
827 | Â Â Â Â Â Â Â Â Â Â coeffDict =Â itemRest['Coeff'] |
---|
828 |           for indx,ops,cofName,esd in enumerate(itemRest[rest]): |
---|
829 | Â Â Â Â Â Â Â Â Â Â Â Â AtNames =Â G2mth.GetAtomItemsById(Atoms,AtLookup,indx,ct-1) |
---|
830 | Â Â Â Â Â Â Â Â Â Â Â Â AtName =Â '' |
---|
831 |             for i,Aname in enumerate(AtNames): |
---|
832 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â AtName +=Â Aname+'+('+ops[i]+')-' |
---|
833 | Â Â Â Â Â Â Â Â Â Â Â Â XYZ =Â np.array(G2mth.GetAtomItemsById(Atoms,AtLookup,indx,cx,3)) |
---|
834 | Â Â Â Â Â Â Â Â Â Â Â Â XYZ =Â G2mth.getSyXYZ(XYZ,ops,SGData) |
---|
835 |             if name == 'Torsion': |
---|
836 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â tor =Â G2mth.getRestTorsion(XYZ,Amat) |
---|
837 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â restr,calc =Â G2mth.calcTorsionEnergy(tor,coeffDict[cofName]) |
---|
838 |               print >>pFile,' %8.3f %8.3f %.3f %8.3f %8.3f %s'%(AtName[:-1],calc,obs,esd,(obs-calc)/esd,tor) |
---|
839 | Â Â Â Â Â Â Â Â Â Â Â Â else: |
---|
840 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â phi,psi =Â G2mth.getRestRama(XYZ,Amat) |
---|
841 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â restr,calc =Â G2mth.calcRamaEnergy(phi,psi,coeffDict[cofName])Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â |
---|
842 |               print >>pFile,' %8.3f %8.3f %8.3f %8.3f %8.3f %8.3f %s'%(AtName[:-1],calc,obs,esd,(obs-calc)/esd,phi,psi) |
---|
843 |         elif name == 'ChemComp': |
---|
844 |           print >>pFile,'   atoms  mul*frac factor   prod' |
---|
845 |           for indx,factors,obs,esd in itemRest[rest]: |
---|
846 | Â Â Â Â Â Â Â Â Â Â Â Â try: |
---|
847 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â atoms =Â G2mth.GetAtomItemsById(Atoms,AtLookup,indx,ct-1) |
---|
848 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â mul =Â np.array(G2mth.GetAtomItemsById(Atoms,AtLookup,indx,cs+1)) |
---|
849 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â frac =Â np.array(G2mth.GetAtomItemsById(Atoms,AtLookup,indx,cs-1)) |
---|
850 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â mulfrac =Â mul*frac |
---|
851 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â calcs =Â mul*frac*factors |
---|
852 |               for iatm,[atom,mf,fr,clc] in enumerate(zip(atoms,mulfrac,factors,calcs)): |
---|
853 |                 print >>pFile,' %10s %8.3f %8.3f %8.3f'%(atom,mf,fr,clc) |
---|
854 |               print >>pFile,' Sum:          calc: %8.3f obs: %8.3f esd: %8.3f'%(np.sum(calcs),obs,esd) |
---|
855 |             except KeyError: |
---|
856 |               del itemRest[rest] |
---|
857 |         elif name == 'Texture' and textureData['Order']: |
---|
858 | Â Â Â Â Â Â Â Â Â Â Start =Â False |
---|
859 | Â Â Â Â Â Â Â Â Â Â SHCoef =Â textureData['SH Coeff'][1] |
---|
860 | Â Â Â Â Â Â Â Â Â Â shModels =Â ['cylindrical','none','shear - 2/m','rolling - mmm'] |
---|
861 | Â Â Â Â Â Â Â Â Â Â SamSym =Â dict(zip(shModels,['0','-1','2/m','mmm'])) |
---|
862 |           print '  HKL grid neg esd sum neg num neg use unit? unit esd ' |
---|
863 |           for hkl,grid,esd1,ifesd2,esd2 in itemRest[rest]: |
---|
864 | Â Â Â Â Â Â Â Â Â Â Â Â PH =Â np.array(hkl) |
---|
865 | Â Â Â Â Â Â Â Â Â Â Â Â phi,beta =Â G2lat.CrsAng(np.array(hkl),cell,SGData) |
---|
866 | Â Â Â Â Â Â Â Â Â Â Â Â ODFln =Â G2lat.Flnh(Start,SHCoef,phi,beta,SGData) |
---|
867 | Â Â Â Â Â Â Â Â Â Â Â Â R,P,Z =Â G2mth.getRestPolefig(ODFln,SamSym[textureData['Model']],grid) |
---|
868 | Â Â Â Â Â Â Â Â Â Â Â Â Z =Â ma.masked_greater(Z,0.0) |
---|
869 | Â Â Â Â Â Â Â Â Â Â Â Â num =Â ma.count(Z) |
---|
870 |             sum = 0 |
---|
871 |             if num: |
---|
872 |               sum = np.sum(Z) |
---|
873 |             print '  %d %d %d %d %8.3f %8.3f %8d  %s  %8.3f'%(hkl[0],hkl[1],hkl[2],grid,esd1,sum,num,str(ifesd2),esd2) |
---|
874 | Â Â Â Â |
---|
875 | def getCellEsd(pfx,SGData,A,covData): |
---|
876 | Â Â dpr =Â 180./np.pi |
---|
877 | Â Â rVsq =Â G2lat.calc_rVsq(A) |
---|
878 | Â Â G,g =Â G2lat.A2Gmat(A)Â Â Â Â #get recip. & real metric tensors |
---|
879 | Â Â cell =Â np.array(G2lat.Gmat2cell(g))Â Â #real cell |
---|
880 | Â Â cellst =Â np.array(G2lat.Gmat2cell(G))Â #recip. cell |
---|
881 | Â Â scos =Â cosd(cellst[3:6]) |
---|
882 | Â Â ssin =Â sind(cellst[3:6]) |
---|
883 | Â Â scot =Â scos/ssin |
---|
884 | Â Â rcos =Â cosd(cell[3:6]) |
---|
885 | Â Â rsin =Â sind(cell[3:6]) |
---|
886 | Â Â rcot =Â rcos/rsin |
---|
887 | Â Â RMnames =Â [pfx+'A0',pfx+'A1',pfx+'A2',pfx+'A3',pfx+'A4',pfx+'A5'] |
---|
888 | Â Â varyList =Â covData['varyList'] |
---|
889 | Â Â covMatrix =Â covData['covMatrix'] |
---|
890 | Â Â vcov =Â G2mth.getVCov(RMnames,varyList,covMatrix) |
---|
891 | Â Â Ax =Â np.array(A) |
---|
892 | Â Â Ax[3:]Â /=Â 2. |
---|
893 | Â Â drVdA =Â np.array([Ax[1]*Ax[2]-Ax[5]**2,Ax[0]*Ax[2]-Ax[4]**2,Ax[0]*Ax[1]-Ax[3]**2, |
---|
894 | Â Â Â Â Ax[4]*Ax[5]-Ax[2]*Ax[3],Ax[3]*Ax[5]-Ax[1]*Ax[4],Ax[3]*Ax[4]-Ax[0]*Ax[5]]) |
---|
895 | Â Â srcvlsq =Â np.inner(drVdA,np.inner(vcov,drVdA.T)) |
---|
896 | Â Â Vol =Â 1/np.sqrt(rVsq) |
---|
897 | Â Â sigVol =Â Vol**3*np.sqrt(srcvlsq)/2. |
---|
898 | Â Â R123 =Â Ax[0]*Ax[1]*Ax[2] |
---|
899 | Â Â dsasdg =Â np.zeros((3,6)) |
---|
900 | Â Â dadg =Â np.zeros((6,6)) |
---|
901 |   for i0 in range(3):     #0 1  2 |
---|
902 | Â Â Â Â i1 =Â (i0+1)%3Â Â Â Â Â Â #1Â 2Â Â 0 |
---|
903 | Â Â Â Â i2 =Â (i1+1)%3Â Â Â Â Â Â #2Â 0Â Â 1 |
---|
904 | Â Â Â Â i3 =Â 5-i2Â Â Â Â Â Â Â Â #3Â 5Â Â 4 |
---|
905 | Â Â Â Â i4 =Â 5-i1Â Â Â Â Â Â Â Â #4Â 3Â Â 5 |
---|
906 | Â Â Â Â i5 =Â 5-i0Â Â Â Â Â Â Â Â #5Â 4Â Â 3 |
---|
907 | Â Â Â Â dsasdg[i0][i1]Â =Â 0.5*scot[i0]*scos[i0]/Ax[i1] |
---|
908 | Â Â Â Â dsasdg[i0][i2]Â =Â 0.5*scot[i0]*scos[i0]/Ax[i2] |
---|
909 | Â Â Â Â dsasdg[i0][i5]Â =Â -scot[i0]/np.sqrt(Ax[i1]*Ax[i2]) |
---|
910 | Â Â Â Â denmsq =Â Ax[i0]*(R123-Ax[i1]*Ax[i4]**2-Ax[i2]*Ax[i3]**2+(Ax[i4]*Ax[i3])**2) |
---|
911 | Â Â Â Â denom =Â np.sqrt(denmsq) |
---|
912 | Â Â Â Â dadg[i5][i0]Â =Â -Ax[i5]/denom-rcos[i0]/denmsq*(R123-0.5*Ax[i1]*Ax[i4]**2-0.5*Ax[i2]*Ax[i3]**2) |
---|
913 | Â Â Â Â dadg[i5][i1]Â =Â -0.5*rcos[i0]/denmsq*(Ax[i0]**2*Ax[i2]-Ax[i0]*Ax[i4]**2) |
---|
914 | Â Â Â Â dadg[i5][i2]Â =Â -0.5*rcos[i0]/denmsq*(Ax[i0]**2*Ax[i1]-Ax[i0]*Ax[i3]**2) |
---|
915 | Â Â Â Â dadg[i5][i3]Â =Â Ax[i4]/denom+rcos[i0]/denmsq*(Ax[i0]*Ax[i2]*Ax[i3]-Ax[i3]*Ax[i4]**2) |
---|
916 | Â Â Â Â dadg[i5][i4]Â =Â Ax[i3]/denom+rcos[i0]/denmsq*(Ax[i0]*Ax[i1]*Ax[i4]-Ax[i3]**2*Ax[i4]) |
---|
917 | Â Â Â Â dadg[i5][i5]Â =Â -Ax[i0]/denom |
---|
918 |   for i0 in range(3): |
---|
919 | Â Â Â Â i1 =Â (i0+1)%3 |
---|
920 | Â Â Â Â i2 =Â (i1+1)%3 |
---|
921 | Â Â Â Â i3 =Â 5-i2 |
---|
922 |     for ij in range(6): |
---|
923 | Â Â Â Â Â Â dadg[i0][ij]Â =Â cell[i0]*(rcot[i2]*dadg[i3][ij]/rsin[i2]-dsasdg[i1][ij]/ssin[i1]) |
---|
924 |       if ij == i0: |
---|
925 | Â Â Â Â Â Â Â Â dadg[i0][ij]Â =Â dadg[i0][ij]-0.5*cell[i0]/Ax[i0] |
---|
926 | Â Â Â Â Â Â dadg[i3][ij]Â =Â -dadg[i3][ij]*rsin[2-i0]*dpr |
---|
927 | Â Â sigMat =Â np.inner(dadg,np.inner(vcov,dadg.T)) |
---|
928 | Â Â var =Â np.diag(sigMat) |
---|
929 | Â Â CS =Â np.where(var>0.,np.sqrt(var),0.) |
---|
930 | Â Â cellSig =Â [CS[0],CS[1],CS[2],CS[5],CS[4],CS[3],sigVol]Â #exchange sig(alp) & sig(gam) to get in right order |
---|
931 |   return cellSig      |
---|
932 | Â Â |
---|
933 | def SetPhaseData(parmDict,sigDict,Phases,covData,RestraintDict=None,pFile=None): |
---|
934 | Â Â |
---|
935 |   def PrintAtomsAndSig(General,Atoms,atomsSig): |
---|
936 |     print >>pFile,'\n Atoms:' |
---|
937 |     line = '  name   x     y     z   frac  Uiso   U11   U22   U33   U12   U13   U23' |
---|
938 |     if General['Type'] == 'magnetic': |
---|
939 |       line += '  Mx   My   Mz' |
---|
940 |     elif General['Type'] == 'macromolecular': |
---|
941 |       line = ' res no residue chain '+line |
---|
942 |     print >>pFile,line |
---|
943 |     if General['Type'] == 'nuclear': |
---|
944 |       print >>pFile,135*'-' |
---|
945 | Â Â Â Â Â Â fmt =Â {0:'%7s',1:'%7s',3:'%10.5f',4:'%10.5f',5:'%10.5f',6:'%8.3f',10:'%8.5f', |
---|
946 | Â Â Â Â Â Â Â Â 11:'%8.5f',12:'%8.5f',13:'%8.5f',14:'%8.5f',15:'%8.5f',16:'%8.5f'} |
---|
947 | Â Â Â Â Â Â noFXsig =Â {3:[10*' ','%10s'],4:[10*' ','%10s'],5:[10*' ','%10s'],6:[8*' ','%8s']} |
---|
948 |       for atyp in General['AtomTypes']:    #zero composition |
---|
949 | Â Â Â Â Â Â Â Â General['NoAtoms'][atyp]Â =Â 0. |
---|
950 |       for i,at in enumerate(Atoms): |
---|
951 | Â Â Â Â Â Â Â Â General['NoAtoms'][at[1]]Â +=Â at[6]*float(at[8])Â Â Â #new composition |
---|
952 | Â Â Â Â Â Â Â Â name =Â fmt[0]%(at[0])+fmt[1]%(at[1])+':' |
---|
953 | Â Â Â Â Â Â Â Â valstr =Â ' values:' |
---|
954 |         sigstr = ' sig  :' |
---|
955 |         for ind in [3,4,5,6]: |
---|
956 | Â Â Â Â Â Â Â Â Â Â sigind =Â str(i)+':'+str(ind) |
---|
957 | Â Â Â Â Â Â Â Â Â Â valstr +=Â fmt[ind]%(at[ind])Â Â Â Â Â Â Â Â Â Â |
---|
958 |           if sigind in atomsSig: |
---|
959 | Â Â Â Â Â Â Â Â Â Â Â Â sigstr +=Â fmt[ind]%(atomsSig[sigind]) |
---|
960 | Â Â Â Â Â Â Â Â Â Â else: |
---|
961 | Â Â Â Â Â Â Â Â Â Â Â Â sigstr +=Â noFXsig[ind][1]%(noFXsig[ind][0]) |
---|
962 |         if at[9] == 'I': |
---|
963 | Â Â Â Â Â Â Â Â Â Â valstr +=Â fmt[10]%(at[10]) |
---|
964 |           if str(i)+':10' in atomsSig: |
---|
965 | Â Â Â Â Â Â Â Â Â Â Â Â sigstr +=Â fmt[10]%(atomsSig[str(i)+':10']) |
---|
966 | Â Â Â Â Â Â Â Â Â Â else: |
---|
967 | Â Â Â Â Â Â Â Â Â Â Â Â sigstr +=Â 8*' ' |
---|
968 | Â Â Â Â Â Â Â Â else: |
---|
969 | Â Â Â Â Â Â Â Â Â Â valstr +=Â 8*' ' |
---|
970 | Â Â Â Â Â Â Â Â Â Â sigstr +=Â 8*' ' |
---|
971 |           for ind in [11,12,13,14,15,16]: |
---|
972 | Â Â Â Â Â Â Â Â Â Â Â Â sigind =Â str(i)+':'+str(ind) |
---|
973 | Â Â Â Â Â Â Â Â Â Â Â Â valstr +=Â fmt[ind]%(at[ind]) |
---|
974 |             if sigind in atomsSig:            |
---|
975 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â sigstr +=Â fmt[ind]%(atomsSig[sigind]) |
---|
976 | Â Â Â Â Â Â Â Â Â Â Â Â else: |
---|
977 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â sigstr +=Â 8*' ' |
---|
978 |         print >>pFile,name |
---|
979 |         print >>pFile,valstr |
---|
980 |         print >>pFile,sigstr |
---|
981 | Â Â Â Â Â Â Â Â |
---|
982 | Â Â #def PrintRBObjectsAndSig() |
---|
983 | Â Â Â Â Â Â Â Â |
---|
984 |   def PrintSHtextureAndSig(textureData,SHtextureSig): |
---|
985 |     print >>pFile,'\n Spherical harmonics texture: Order:' + str(textureData['Order']) |
---|
986 | Â Â Â Â names =Â ['omega','chi','phi'] |
---|
987 | Â Â Â Â namstr =Â 'Â names :' |
---|
988 | Â Â Â Â ptstr =Â 'Â values:' |
---|
989 |     sigstr = ' esds :' |
---|
990 |     for name in names: |
---|
991 | Â Â Â Â Â Â namstr +=Â '%12s'%(name) |
---|
992 | Â Â Â Â Â Â ptstr +=Â '%12.3f'%(textureData['Sample '+name][1]) |
---|
993 |       if 'Sample '+name in SHtextureSig: |
---|
994 | Â Â Â Â Â Â Â Â sigstr +=Â '%12.3f'%(SHtextureSig['Sample '+name]) |
---|
995 | Â Â Â Â Â Â else: |
---|
996 | Â Â Â Â Â Â Â Â sigstr +=Â 12*' ' |
---|
997 |     print >>pFile,namstr |
---|
998 |     print >>pFile,ptstr |
---|
999 |     print >>pFile,sigstr |
---|
1000 |     print >>pFile,'\n Texture coefficients:' |
---|
1001 | Â Â Â Â namstr =Â 'Â names :' |
---|
1002 | Â Â Â Â ptstr =Â 'Â values:' |
---|
1003 |     sigstr = ' esds :' |
---|
1004 | Â Â Â Â SHcoeff =Â textureData['SH Coeff'][1] |
---|
1005 |     for name in SHcoeff: |
---|
1006 | Â Â Â Â Â Â namstr +=Â '%12s'%(name) |
---|
1007 | Â Â Â Â Â Â ptstr +=Â '%12.3f'%(SHcoeff[name]) |
---|
1008 |       if name in SHtextureSig: |
---|
1009 | Â Â Â Â Â Â Â Â sigstr +=Â '%12.3f'%(SHtextureSig[name]) |
---|
1010 | Â Â Â Â Â Â else: |
---|
1011 | Â Â Â Â Â Â Â Â sigstr +=Â 12*' ' |
---|
1012 |     print >>pFile,namstr |
---|
1013 |     print >>pFile,ptstr |
---|
1014 |     print >>pFile,sigstr |
---|
1015 | Â Â Â Â |
---|
1016 | Â Â Â Â Â Â |
---|
1017 |   print >>pFile,'\n Phases:' |
---|
1018 |   for phase in Phases: |
---|
1019 |     print >>pFile,' Result for phase: ',phase |
---|
1020 | Â Â Â Â Phase =Â Phases[phase] |
---|
1021 | Â Â Â Â General =Â Phase['General'] |
---|
1022 | Â Â Â Â SGData =Â General['SGData'] |
---|
1023 | Â Â Â Â Atoms =Â Phase['Atoms'] |
---|
1024 | Â Â Â Â AtLookup =Â G2mth.FillAtomLookUp(Atoms) |
---|
1025 | Â Â Â Â cell =Â General['Cell'] |
---|
1026 | Â Â Â Â pId =Â Phase['pId'] |
---|
1027 | Â Â Â Â pfx =Â str(pId)+'::' |
---|
1028 |     if cell[0]: |
---|
1029 | Â Â Â Â Â Â A,sigA =Â cellFill(pfx,SGData,parmDict,sigDict) |
---|
1030 | Â Â Â Â Â Â cellSig =Â getCellEsd(pfx,SGData,A,covData)Â #includes sigVol |
---|
1031 |       print >>pFile,' Reciprocal metric tensor: ' |
---|
1032 | Â Â Â Â Â Â ptfmt =Â "%15.9f" |
---|
1033 | Â Â Â Â Â Â names =Â ['A11','A22','A33','A12','A13','A23'] |
---|
1034 | Â Â Â Â Â Â namstr =Â 'Â names :' |
---|
1035 | Â Â Â Â Â Â ptstr =Â 'Â values:' |
---|
1036 |       sigstr = ' esds :' |
---|
1037 |       for name,a,siga in zip(names,A,sigA): |
---|
1038 | Â Â Â Â Â Â Â Â namstr +=Â '%15s'%(name) |
---|
1039 | Â Â Â Â Â Â Â Â ptstr +=Â ptfmt%(a) |
---|
1040 |         if siga: |
---|
1041 | Â Â Â Â Â Â Â Â Â Â sigstr +=Â ptfmt%(siga) |
---|
1042 | Â Â Â Â Â Â Â Â else: |
---|
1043 | Â Â Â Â Â Â Â Â Â Â sigstr +=Â 15*' ' |
---|
1044 |       print >>pFile,namstr |
---|
1045 |       print >>pFile,ptstr |
---|
1046 |       print >>pFile,sigstr |
---|
1047 | Â Â Â Â Â Â cell[1:7]Â =Â G2lat.A2cell(A) |
---|
1048 | Â Â Â Â Â Â cell[7]Â =Â G2lat.calc_V(A) |
---|
1049 |       print >>pFile,' New unit cell:' |
---|
1050 | Â Â Â Â Â Â ptfmt =Â ["%12.6f","%12.6f","%12.6f","%12.4f","%12.4f","%12.4f","%12.3f"] |
---|
1051 | Â Â Â Â Â Â names =Â ['a','b','c','alpha','beta','gamma','Volume'] |
---|
1052 | Â Â Â Â Â Â namstr =Â 'Â names :' |
---|
1053 | Â Â Â Â Â Â ptstr =Â 'Â values:' |
---|
1054 |       sigstr = ' esds :' |
---|
1055 |       for name,fmt,a,siga in zip(names,ptfmt,cell[1:8],cellSig): |
---|
1056 | Â Â Â Â Â Â Â Â namstr +=Â '%12s'%(name) |
---|
1057 | Â Â Â Â Â Â Â Â ptstr +=Â fmt%(a) |
---|
1058 |         if siga: |
---|
1059 | Â Â Â Â Â Â Â Â Â Â sigstr +=Â fmt%(siga) |
---|
1060 | Â Â Â Â Â Â Â Â else: |
---|
1061 | Â Â Â Â Â Â Â Â Â Â sigstr +=Â 12*' ' |
---|
1062 |       print >>pFile,namstr |
---|
1063 |       print >>pFile,ptstr |
---|
1064 |       print >>pFile,sigstr |
---|
1065 | Â Â Â Â Â Â |
---|
1066 | Â Â Â Â General['Mass']Â =Â 0. |
---|
1067 |     if Phase['General'].get('doPawley'): |
---|
1068 | Â Â Â Â Â Â pawleyRef =Â Phase['Pawley ref'] |
---|
1069 |       for i,refl in enumerate(pawleyRef): |
---|
1070 | Â Â Â Â Â Â Â Â key =Â pfx+'PWLref:'+str(i) |
---|
1071 | Â Â Â Â Â Â Â Â refl[6]Â =Â parmDict[key] |
---|
1072 |         if key in sigDict: |
---|
1073 | Â Â Â Â Â Â Â Â Â Â refl[7]Â =Â sigDict[key] |
---|
1074 | Â Â Â Â Â Â Â Â else: |
---|
1075 | Â Â Â Â Â Â Â Â Â Â refl[7]Â =Â 0 |
---|
1076 | Â Â Â Â else: |
---|
1077 | Â Â Â Â Â Â #new RBObj parms here, mod atoms, & PrintRBObjectsAndSig |
---|
1078 | Â Â Â Â Â Â atomsSig =Â {} |
---|
1079 |       if General['Type'] == 'nuclear':    #this needs macromolecular variant! |
---|
1080 |         for i,at in enumerate(Atoms): |
---|
1081 | Â Â Â Â Â Â Â Â Â Â names =Â {3:pfx+'Ax:'+str(i),4:pfx+'Ay:'+str(i),5:pfx+'Az:'+str(i),6:pfx+'Afrac:'+str(i), |
---|
1082 | Â Â Â Â Â Â Â Â Â Â Â Â 10:pfx+'AUiso:'+str(i),11:pfx+'AU11:'+str(i),12:pfx+'AU22:'+str(i),13:pfx+'AU33:'+str(i), |
---|
1083 | Â Â Â Â Â Â Â Â Â Â Â Â 14:pfx+'AU12:'+str(i),15:pfx+'AU13:'+str(i),16:pfx+'AU23:'+str(i)} |
---|
1084 |           for ind in [3,4,5,6]: |
---|
1085 | Â Â Â Â Â Â Â Â Â Â Â Â at[ind]Â =Â parmDict[names[ind]] |
---|
1086 |             if ind in [3,4,5]: |
---|
1087 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â name =Â names[ind].replace('A','dA') |
---|
1088 | Â Â Â Â Â Â Â Â Â Â Â Â else: |
---|
1089 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â name =Â names[ind] |
---|
1090 |             if name in sigDict: |
---|
1091 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â atomsSig[str(i)+':'+str(ind)]Â =Â sigDict[name] |
---|
1092 |           if at[9] == 'I': |
---|
1093 | Â Â Â Â Â Â Â Â Â Â Â Â at[10]Â =Â parmDict[names[10]] |
---|
1094 |             if names[10] in sigDict: |
---|
1095 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â atomsSig[str(i)+':10']Â =Â sigDict[names[10]] |
---|
1096 | Â Â Â Â Â Â Â Â Â Â else: |
---|
1097 |             for ind in [11,12,13,14,15,16]: |
---|
1098 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â at[ind]Â =Â parmDict[names[ind]] |
---|
1099 |               if names[ind] in sigDict: |
---|
1100 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â atomsSig[str(i)+':'+str(ind)]Â =Â sigDict[names[ind]] |
---|
1101 | Â Â Â Â Â Â Â Â Â Â ind =Â General['AtomTypes'].index(at[1]) |
---|
1102 | Â Â Â Â Â Â Â Â Â Â General['Mass']Â +=Â General['AtomMass'][ind]*at[6]*at[8] |
---|
1103 | Â Â Â Â Â Â PrintAtomsAndSig(General,Atoms,atomsSig) |
---|
1104 | Â Â Â Â |
---|
1105 | Â Â Â Â textureData =Â General['SH Texture']Â Â |
---|
1106 |     if textureData['Order']: |
---|
1107 | Â Â Â Â Â Â SHtextureSig =Â {} |
---|
1108 |       for name in ['omega','chi','phi']: |
---|
1109 | Â Â Â Â Â Â Â Â aname =Â pfx+'SH '+name |
---|
1110 | Â Â Â Â Â Â Â Â textureData['Sample '+name][1]Â =Â parmDict[aname] |
---|
1111 |         if aname in sigDict: |
---|
1112 | Â Â Â Â Â Â Â Â Â Â SHtextureSig['Sample '+name]Â =Â sigDict[aname] |
---|
1113 |       for name in textureData['SH Coeff'][1]: |
---|
1114 | Â Â Â Â Â Â Â Â aname =Â pfx+name |
---|
1115 | Â Â Â Â Â Â Â Â textureData['SH Coeff'][1][name]Â =Â parmDict[aname] |
---|
1116 |         if aname in sigDict: |
---|
1117 | Â Â Â Â Â Â Â Â Â Â SHtextureSig[name]Â =Â sigDict[aname] |
---|
1118 | Â Â Â Â Â Â PrintSHtextureAndSig(textureData,SHtextureSig) |
---|
1119 |     if phase in RestraintDict: |
---|
1120 | Â Â Â Â Â Â PrintRestraints(cell[1:7],SGData,General['AtomPtrs'],Atoms,AtLookup, |
---|
1121 | Â Â Â Â Â Â Â Â textureData,RestraintDict[phase],pFile) |
---|
1122 | Â Â Â Â Â Â Â Â Â Â |
---|
1123 | ################################################################################ |
---|
1124 | ##### Histogram & Phase data |
---|
1125 | ################################################################################Â Â Â Â |
---|
1126 | Â Â Â Â Â Â Â Â Â Â |
---|
1127 | def GetHistogramPhaseData(Phases,Histograms,Print=True,pFile=None): |
---|
1128 | Â Â |
---|
1129 |   def PrintSize(hapData): |
---|
1130 |     if hapData[0] in ['isotropic','uniaxial']: |
---|
1131 |       line = '\n Size model  : %9s'%(hapData[0]) |
---|
1132 | Â Â Â Â Â Â line +=Â ' equatorial:'+'%12.3f'%(hapData[1][0])+' Refine? '+str(hapData[2][0]) |
---|
1133 |       if hapData[0] == 'uniaxial': |
---|
1134 | Â Â Â Â Â Â Â Â line +=Â ' axial:'+'%12.3f'%(hapData[1][1])+' Refine? '+str(hapData[2][1]) |
---|
1135 |       line += '\n\t LG mixing coeff.: %12.4f'%(hapData[1][2])+' Refine? '+str(hapData[2][2]) |
---|
1136 |       print >>pFile,line |
---|
1137 | Â Â Â Â else: |
---|
1138 |       print >>pFile,'\n Size model  : %s'%(hapData[0])+ \ |
---|
1139 |         '\n\t LG mixing coeff.:%12.4f'%(hapData[1][2])+' Refine? '+str(hapData[2][2]) |
---|
1140 | Â Â Â Â Â Â Snames =Â ['S11','S22','S33','S12','S13','S23'] |
---|
1141 | Â Â Â Â Â Â ptlbls =Â ' names :' |
---|
1142 | Â Â Â Â Â Â ptstr =Â ' values:' |
---|
1143 | Â Â Â Â Â Â varstr =Â ' refine:' |
---|
1144 |       for i,name in enumerate(Snames): |
---|
1145 | Â Â Â Â Â Â Â Â ptlbls +=Â '%12s'Â %Â (name) |
---|
1146 | Â Â Â Â Â Â Â Â ptstr +=Â '%12.6f'Â %Â (hapData[4][i]) |
---|
1147 | Â Â Â Â Â Â Â Â varstr +=Â '%12s'Â %Â (str(hapData[5][i])) |
---|
1148 |       print >>pFile,ptlbls |
---|
1149 |       print >>pFile,ptstr |
---|
1150 |       print >>pFile,varstr |
---|
1151 | Â Â Â Â |
---|
1152 |   def PrintMuStrain(hapData,SGData): |
---|
1153 |     if hapData[0] in ['isotropic','uniaxial']: |
---|
1154 |       line = '\n Mustrain model: %9s'%(hapData[0]) |
---|
1155 | Â Â Â Â Â Â line +=Â ' equatorial:'+'%12.1f'%(hapData[1][0])+' Refine? '+str(hapData[2][0]) |
---|
1156 |       if hapData[0] == 'uniaxial': |
---|
1157 | Â Â Â Â Â Â Â Â line +=Â ' axial:'+'%12.1f'%(hapData[1][1])+' Refine? '+str(hapData[2][1]) |
---|
1158 |       line +='\n\t LG mixing coeff.:%12.4f'%(hapData[1][2])+' Refine? '+str(hapData[2][2]) |
---|
1159 |       print >>pFile,line |
---|
1160 | Â Â Â Â else: |
---|
1161 |       print >>pFile,'\n Mustrain model: %s'%(hapData[0])+ \ |
---|
1162 |         '\n\t LG mixing coeff.:%12.4f'%(hapData[1][2])+' Refine? '+str(hapData[2][2]) |
---|
1163 | Â Â Â Â Â Â Snames =Â G2spc.MustrainNames(SGData) |
---|
1164 | Â Â Â Â Â Â ptlbls =Â ' names :' |
---|
1165 | Â Â Â Â Â Â ptstr =Â ' values:' |
---|
1166 | Â Â Â Â Â Â varstr =Â ' refine:' |
---|
1167 |       for i,name in enumerate(Snames): |
---|
1168 | Â Â Â Â Â Â Â Â ptlbls +=Â '%12s'Â %Â (name) |
---|
1169 | Â Â Â Â Â Â Â Â ptstr +=Â '%12.6f'Â %Â (hapData[4][i]) |
---|
1170 | Â Â Â Â Â Â Â Â varstr +=Â '%12s'Â %Â (str(hapData[5][i])) |
---|
1171 |       print >>pFile,ptlbls |
---|
1172 |       print >>pFile,ptstr |
---|
1173 |       print >>pFile,varstr |
---|
1174 | |
---|
1175 |   def PrintHStrain(hapData,SGData): |
---|
1176 |     print >>pFile,'\n Hydrostatic/elastic strain: ' |
---|
1177 | Â Â Â Â Hsnames =Â G2spc.HStrainNames(SGData) |
---|
1178 | Â Â Â Â ptlbls =Â ' names :' |
---|
1179 | Â Â Â Â ptstr =Â ' values:' |
---|
1180 | Â Â Â Â varstr =Â ' refine:' |
---|
1181 |     for i,name in enumerate(Hsnames): |
---|
1182 | Â Â Â Â Â Â ptlbls +=Â '%12s'Â %Â (name) |
---|
1183 | Â Â Â Â Â Â ptstr +=Â '%12.6f'Â %Â (hapData[0][i]) |
---|
1184 | Â Â Â Â Â Â varstr +=Â '%12s'Â %Â (str(hapData[1][i])) |
---|
1185 |     print >>pFile,ptlbls |
---|
1186 |     print >>pFile,ptstr |
---|
1187 |     print >>pFile,varstr |
---|
1188 | |
---|
1189 |   def PrintSHPO(hapData): |
---|
1190 |     print >>pFile,'\n Spherical harmonics preferred orientation: Order:' + \ |
---|
1191 | Â Â Â Â Â Â str(hapData[4])+' Refine? '+str(hapData[2]) |
---|
1192 | Â Â Â Â ptlbls =Â ' names :' |
---|
1193 | Â Â Â Â ptstr =Â ' values:' |
---|
1194 |     for item in hapData[5]: |
---|
1195 | Â Â Â Â Â Â ptlbls +=Â '%12s'%(item) |
---|
1196 | Â Â Â Â Â Â ptstr +=Â '%12.3f'%(hapData[5][item])Â |
---|
1197 |     print >>pFile,ptlbls |
---|
1198 |     print >>pFile,ptstr |
---|
1199 | Â Â |
---|
1200 |   def PrintBabinet(hapData): |
---|
1201 |     print >>pFile,'\n Babinet form factor modification: ' |
---|
1202 | Â Â Â Â ptlbls =Â ' names :' |
---|
1203 | Â Â Â Â ptstr =Â ' values:' |
---|
1204 | Â Â Â Â varstr =Â ' refine:' |
---|
1205 |     for name in ['BabA','BabU']: |
---|
1206 | Â Â Â Â Â Â ptlbls +=Â '%12s'Â %Â (name) |
---|
1207 | Â Â Â Â Â Â ptstr +=Â '%12.6f'Â %Â (hapData[name][0]) |
---|
1208 | Â Â Â Â Â Â varstr +=Â '%12s'Â %Â (str(hapData[name][1])) |
---|
1209 |     print >>pFile,ptlbls |
---|
1210 |     print >>pFile,ptstr |
---|
1211 |     print >>pFile,varstr |
---|
1212 | Â Â Â Â |
---|
1213 | Â Â |
---|
1214 | Â Â hapDict =Â {} |
---|
1215 | Â Â hapVary =Â [] |
---|
1216 | Â Â controlDict =Â {} |
---|
1217 | Â Â poType =Â {} |
---|
1218 | Â Â poAxes =Â {} |
---|
1219 | Â Â spAxes =Â {} |
---|
1220 | Â Â spType =Â {} |
---|
1221 | Â Â |
---|
1222 |   for phase in Phases: |
---|
1223 | Â Â Â Â HistoPhase =Â Phases[phase]['Histograms'] |
---|
1224 | Â Â Â Â SGData =Â Phases[phase]['General']['SGData'] |
---|
1225 | Â Â Â Â cell =Â Phases[phase]['General']['Cell'][1:7] |
---|
1226 | Â Â Â Â A =Â G2lat.cell2A(cell) |
---|
1227 | Â Â Â Â pId =Â Phases[phase]['pId'] |
---|
1228 | Â Â Â Â histoList =Â HistoPhase.keys() |
---|
1229 | Â Â Â Â histoList.sort() |
---|
1230 |     for histogram in histoList: |
---|
1231 | Â Â Â Â Â Â try: |
---|
1232 | Â Â Â Â Â Â Â Â Histogram =Â Histograms[histogram] |
---|
1233 |       except KeyError:            |
---|
1234 | Â Â Â Â Â Â Â Â #skip if histogram not included e.g. in a sequential refinement |
---|
1235 | Â Â Â Â Â Â Â Â continue |
---|
1236 | Â Â Â Â Â Â hapData =Â HistoPhase[histogram] |
---|
1237 | Â Â Â Â Â Â hId =Â Histogram['hId'] |
---|
1238 |       if 'PWDR' in histogram: |
---|
1239 | Â Â Â Â Â Â Â Â limits =Â Histogram['Limits'][1] |
---|
1240 | Â Â Â Â Â Â Â Â inst =Â Histogram['Instrument Parameters'][0] |
---|
1241 | Â Â Â Â Â Â Â Â Zero =Â inst['Zero'][1] |
---|
1242 |         if 'C' in inst['Type'][1]: |
---|
1243 | Â Â Â Â Â Â Â Â Â Â try: |
---|
1244 | Â Â Â Â Â Â Â Â Â Â Â Â wave =Â inst['Lam'][1] |
---|
1245 |           except KeyError: |
---|
1246 | Â Â Â Â Â Â Â Â Â Â Â Â wave =Â inst['Lam1'][1] |
---|
1247 | Â Â Â Â Â Â Â Â Â Â dmin =Â wave/(2.0*sind(limits[1]/2.0)) |
---|
1248 | Â Â Â Â Â Â Â Â pfx =Â str(pId)+':'+str(hId)+':' |
---|
1249 |         for item in ['Scale','Extinction']: |
---|
1250 | Â Â Â Â Â Â Â Â Â Â hapDict[pfx+item]Â =Â hapData[item][0] |
---|
1251 |           if hapData[item][1]: |
---|
1252 | Â Â Â Â Â Â Â Â Â Â Â Â hapVary.append(pfx+item) |
---|
1253 | Â Â Â Â Â Â Â Â names =Â G2spc.HStrainNames(SGData) |
---|
1254 |         for i,name in enumerate(names): |
---|
1255 | Â Â Â Â Â Â Â Â Â Â hapDict[pfx+name]Â =Â hapData['HStrain'][0][i] |
---|
1256 |           if hapData['HStrain'][1][i]: |
---|
1257 | Â Â Â Â Â Â Â Â Â Â Â Â hapVary.append(pfx+name) |
---|
1258 | Â Â Â Â Â Â Â Â controlDict[pfx+'poType']Â =Â hapData['Pref.Ori.'][0] |
---|
1259 |         if hapData['Pref.Ori.'][0] == 'MD': |
---|
1260 | Â Â Â Â Â Â Â Â Â Â hapDict[pfx+'MD']Â =Â hapData['Pref.Ori.'][1] |
---|
1261 | Â Â Â Â Â Â Â Â Â Â controlDict[pfx+'MDAxis']Â =Â hapData['Pref.Ori.'][3] |
---|
1262 |           if hapData['Pref.Ori.'][2]: |
---|
1263 | Â Â Â Â Â Â Â Â Â Â Â Â hapVary.append(pfx+'MD') |
---|
1264 | Â Â Â Â Â Â Â Â else:Â Â Â Â Â Â Â Â Â Â Â Â Â Â #'SH' spherical harmonics |
---|
1265 | Â Â Â Â Â Â Â Â Â Â controlDict[pfx+'SHord']Â =Â hapData['Pref.Ori.'][4] |
---|
1266 | Â Â Â Â Â Â Â Â Â Â controlDict[pfx+'SHncof']Â =Â len(hapData['Pref.Ori.'][5]) |
---|
1267 |           for item in hapData['Pref.Ori.'][5]: |
---|
1268 | Â Â Â Â Â Â Â Â Â Â Â Â hapDict[pfx+item]Â =Â hapData['Pref.Ori.'][5][item] |
---|
1269 |             if hapData['Pref.Ori.'][2]: |
---|
1270 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â hapVary.append(pfx+item) |
---|
1271 |         for item in ['Mustrain','Size']: |
---|
1272 | Â Â Â Â Â Â Â Â Â Â controlDict[pfx+item+'Type']Â =Â hapData[item][0] |
---|
1273 | Â Â Â Â Â Â Â Â Â Â hapDict[pfx+item+';mx']Â =Â hapData[item][1][2] |
---|
1274 |           if hapData[item][2][2]: |
---|
1275 | Â Â Â Â Â Â Â Â Â Â Â Â hapVary.append(pfx+item+';mx') |
---|
1276 |           if hapData[item][0] in ['isotropic','uniaxial']: |
---|
1277 | Â Â Â Â Â Â Â Â Â Â Â Â hapDict[pfx+item+';i']Â =Â hapData[item][1][0] |
---|
1278 |             if hapData[item][2][0]: |
---|
1279 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â hapVary.append(pfx+item+';i') |
---|
1280 |             if hapData[item][0] == 'uniaxial': |
---|
1281 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â controlDict[pfx+item+'Axis']Â =Â hapData[item][3] |
---|
1282 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â hapDict[pfx+item+';a']Â =Â hapData[item][1][1] |
---|
1283 |               if hapData[item][2][1]: |
---|
1284 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â hapVary.append(pfx+item+';a') |
---|
1285 | Â Â Â Â Â Â Â Â Â Â else:Â Â Â Â #generalized for mustrain or ellipsoidal for size |
---|
1286 | Â Â Â Â Â Â Â Â Â Â Â Â Nterms =Â len(hapData[item][4]) |
---|
1287 |             if item == 'Mustrain': |
---|
1288 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â names =Â G2spc.MustrainNames(SGData) |
---|
1289 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â pwrs =Â [] |
---|
1290 |               for name in names: |
---|
1291 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â h,k,l =Â name[1:] |
---|
1292 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â pwrs.append([int(h),int(k),int(l)]) |
---|
1293 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â controlDict[pfx+'MuPwrs']Â =Â pwrs |
---|
1294 |             for i in range(Nterms): |
---|
1295 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â sfx =Â ':'+str(i) |
---|
1296 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â hapDict[pfx+item+sfx]Â =Â hapData[item][4][i] |
---|
1297 |               if hapData[item][5][i]: |
---|
1298 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â hapVary.append(pfx+item+sfx) |
---|
1299 |         for bab in ['BabA','BabU']: |
---|
1300 | Â Â Â Â Â Â Â Â Â Â hapDict[pfx+bab]Â =Â hapData['Babinet'][bab][0] |
---|
1301 |           if hapData['Babinet'][bab][1]: |
---|
1302 | Â Â Â Â Â Â Â Â Â Â Â Â hapVary.append(pfx+bab) |
---|
1303 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â |
---|
1304 |         if Print: |
---|
1305 |           print >>pFile,'\n Phase: ',phase,' in histogram: ',histogram |
---|
1306 |           print >>pFile,135*'-' |
---|
1307 |           print >>pFile,' Phase fraction : %10.4f'%(hapData['Scale'][0]),' Refine?',hapData['Scale'][1] |
---|
1308 |           print >>pFile,' Extinction coeff: %10.4f'%(hapData['Extinction'][0]),' Refine?',hapData['Extinction'][1] |
---|
1309 |           if hapData['Pref.Ori.'][0] == 'MD': |
---|
1310 | Â Â Â Â Â Â Â Â Â Â Â Â Ax =Â hapData['Pref.Ori.'][3] |
---|
1311 |             print >>pFile,' March-Dollase PO: %10.4f'%(hapData['Pref.Ori.'][1]),' Refine?',hapData['Pref.Ori.'][2], \ |
---|
1312 |               ' Axis: %d %d %d'%(Ax[0],Ax[1],Ax[2]) |
---|
1313 | Â Â Â Â Â Â Â Â Â Â else:Â #'SH' for spherical harmonics |
---|
1314 | Â Â Â Â Â Â Â Â Â Â Â Â PrintSHPO(hapData['Pref.Ori.']) |
---|
1315 | Â Â Â Â Â Â Â Â Â Â PrintSize(hapData['Size']) |
---|
1316 | Â Â Â Â Â Â Â Â Â Â PrintMuStrain(hapData['Mustrain'],SGData) |
---|
1317 | Â Â Â Â Â Â Â Â Â Â PrintHStrain(hapData['HStrain'],SGData) |
---|
1318 |           if hapData['Babinet']['BabA'][0]: |
---|
1319 | Â Â Â Â Â Â Â Â Â Â Â Â PrintBabinet(hapData['Babinet']) |
---|
1320 | Â Â Â Â Â Â Â Â HKLd =Â np.array(G2lat.GenHLaue(dmin,SGData,A)) |
---|
1321 | Â Â Â Â Â Â Â Â refList =Â [] |
---|
1322 |         for h,k,l,d in HKLd: |
---|
1323 | Â Â Â Â Â Â Â Â Â Â ext,mul,Uniq,phi =Â G2spc.GenHKLf([h,k,l],SGData) |
---|
1324 | Â Â Â Â Â Â Â Â Â Â mul *=Â 2Â Â Â # for powder overlap of Friedel pairs |
---|
1325 |           if ext: |
---|
1326 | Â Â Â Â Â Â Â Â Â Â Â Â continue |
---|
1327 |           if 'C' in inst['Type'][0]: |
---|
1328 | Â Â Â Â Â Â Â Â Â Â Â Â pos =Â 2.0*asind(wave/(2.0*d))+Zero |
---|
1329 |             if limits[0] < pos < limits[1]: |
---|
1330 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â refList.append([h,k,l,mul,d,pos,0.0,0.0,0.0,0.0,0.0,Uniq,phi,0.0,{}]) |
---|
1331 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â #last item should contain form factor values by atom type |
---|
1332 | Â Â Â Â Â Â Â Â Â Â else: |
---|
1333 |             raise ValueError |
---|
1334 | Â Â Â Â Â Â Â Â Histogram['Reflection Lists'][phase]Â =Â refList |
---|
1335 |       elif 'HKLF' in histogram: |
---|
1336 | Â Â Â Â Â Â Â Â inst =Â Histogram['Instrument Parameters'][0] |
---|
1337 | Â Â Â Â Â Â Â Â hId =Â Histogram['hId'] |
---|
1338 | Â Â Â Â Â Â Â Â hfx =Â ':%d:'%(hId) |
---|
1339 |         for item in inst: |
---|
1340 | Â Â Â Â Â Â Â Â Â Â hapDict[hfx+item]Â =Â inst[item][1] |
---|
1341 | Â Â Â Â Â Â Â Â pfx =Â str(pId)+':'+str(hId)+':' |
---|
1342 | Â Â Â Â Â Â Â Â hapDict[pfx+'Scale']Â =Â hapData['Scale'][0] |
---|
1343 |         if hapData['Scale'][1]: |
---|
1344 | Â Â Â Â Â Â Â Â Â Â hapVary.append(pfx+'Scale') |
---|
1345 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â |
---|
1346 | Â Â Â Â Â Â Â Â extApprox,extType,extParms =Â hapData['Extinction'] |
---|
1347 | Â Â Â Â Â Â Â Â controlDict[pfx+'EType']Â =Â extType |
---|
1348 | Â Â Â Â Â Â Â Â controlDict[pfx+'EApprox']Â =Â extApprox |
---|
1349 | Â Â Â Â Â Â Â Â controlDict[pfx+'Tbar']Â =Â extParms['Tbar'] |
---|
1350 | Â Â Â Â Â Â Â Â controlDict[pfx+'Cos2TM']Â =Â extParms['Cos2TM'] |
---|
1351 |         if 'Primary' in extType: |
---|
1352 | Â Â Â Â Â Â Â Â Â Â Ekey =Â ['Ep',] |
---|
1353 |         elif 'I & II' in extType: |
---|
1354 | Â Â Â Â Â Â Â Â Â Â Ekey =Â ['Eg','Es'] |
---|
1355 |         elif 'Secondary Type II' == extType: |
---|
1356 | Â Â Â Â Â Â Â Â Â Â Ekey =Â ['Es',] |
---|
1357 |         elif 'Secondary Type I' == extType: |
---|
1358 | Â Â Â Â Â Â Â Â Â Â Ekey =Â ['Eg',] |
---|
1359 | Â Â Â Â Â Â Â Â else:Â Â #'None' |
---|
1360 | Â Â Â Â Â Â Â Â Â Â Ekey =Â [] |
---|
1361 |         for eKey in Ekey: |
---|
1362 | Â Â Â Â Â Â Â Â Â Â hapDict[pfx+eKey]Â =Â extParms[eKey][0] |
---|
1363 |           if extParms[eKey][1]: |
---|
1364 | Â Â Â Â Â Â Â Â Â Â Â Â hapVary.append(pfx+eKey) |
---|
1365 |         for bab in ['BabA','BabU']: |
---|
1366 | Â Â Â Â Â Â Â Â Â Â hapDict[pfx+bab]Â =Â hapData['Babinet'][bab][0] |
---|
1367 |           if hapData['Babinet'][bab][1]: |
---|
1368 | Â Â Â Â Â Â Â Â Â Â Â Â hapVary.append(pfx+bab) |
---|
1369 |         if Print: |
---|
1370 |           print >>pFile,'\n Phase: ',phase,' in histogram: ',histogram |
---|
1371 |           print >>pFile,135*'-' |
---|
1372 |           print >>pFile,' Scale factor   : %10.4f'%(hapData['Scale'][0]),' Refine?',hapData['Scale'][1] |
---|
1373 |           if extType != 'None': |
---|
1374 |             print >>pFile,' Extinction Type: %15s'%(extType),' approx: %10s'%(extApprox),' tbar: %6.3f'%(extParms['Tbar']) |
---|
1375 |             text = ' Parameters    :' |
---|
1376 |             for eKey in Ekey: |
---|
1377 |               text += ' %4s : %10.3e Refine? '%(eKey,extParms[eKey][0])+str(extParms[eKey][1]) |
---|
1378 |             print >>pFile,text |
---|
1379 |           if hapData['Babinet']['BabA'][0]: |
---|
1380 | Â Â Â Â Â Â Â Â Â Â Â Â PrintBabinet(hapData['Babinet']) |
---|
1381 |         Histogram['Reflection Lists'] = phase    |
---|
1382 | Â Â Â Â Â Â Â Â |
---|
1383 |   return hapVary,hapDict,controlDict |
---|
1384 | Â Â |
---|
1385 | def SetHistogramPhaseData(parmDict,sigDict,Phases,Histograms,Print=True,pFile=None): |
---|
1386 | Â Â |
---|
1387 |   def PrintSizeAndSig(hapData,sizeSig): |
---|
1388 |     line = '\n Size model:   %9s'%(hapData[0]) |
---|
1389 | Â Â Â Â refine =Â False |
---|
1390 |     if hapData[0] in ['isotropic','uniaxial']: |
---|
1391 | Â Â Â Â Â Â line +=Â ' equatorial:%12.4f'%(hapData[1][0]) |
---|
1392 |       if sizeSig[0][0]: |
---|
1393 | Â Â Â Â Â Â Â Â line +=Â ', sig:%8.4f'%(sizeSig[0][0]) |
---|
1394 | Â Â Â Â Â Â Â Â refine =Â True |
---|
1395 |       if hapData[0] == 'uniaxial': |
---|
1396 | Â Â Â Â Â Â Â Â line +=Â ' axial:%12.4f'%(hapData[1][1]) |
---|
1397 |         if sizeSig[0][1]: |
---|
1398 | Â Â Â Â Â Â Â Â Â Â refine =Â True |
---|
1399 | Â Â Â Â Â Â Â Â Â Â line +=Â ', sig:%8.4f'%(sizeSig[0][1]) |
---|
1400 | Â Â Â Â Â Â line +=Â ' LG mix coeff.:%12.4f'%(hapData[1][2]) |
---|
1401 |       if sizeSig[0][2]: |
---|
1402 | Â Â Â Â Â Â Â Â refine =Â True |
---|
1403 | Â Â Â Â Â Â Â Â line +=Â ', sig:%8.4f'%(sizeSig[0][2]) |
---|
1404 |       if refine: |
---|
1405 |         print >>pFile,line |
---|
1406 | Â Â Â Â else: |
---|
1407 | Â Â Â Â Â Â line +=Â ' LG mix coeff.:%12.4f'%(hapData[1][2]) |
---|
1408 |       if sizeSig[0][2]: |
---|
1409 | Â Â Â Â Â Â Â Â refine =Â True |
---|
1410 | Â Â Â Â Â Â Â Â line +=Â ', sig:%8.4f'%(sizeSig[0][2]) |
---|
1411 | Â Â Â Â Â Â Snames =Â ['S11','S22','S33','S12','S13','S23'] |
---|
1412 |       ptlbls = ' name :' |
---|
1413 | Â Â Â Â Â Â ptstr =Â ' value :' |
---|
1414 |       sigstr = ' sig  :' |
---|
1415 |       for i,name in enumerate(Snames): |
---|
1416 | Â Â Â Â Â Â Â Â ptlbls +=Â '%12s'Â %Â (name) |
---|
1417 | Â Â Â Â Â Â Â Â ptstr +=Â '%12.6f'Â %Â (hapData[4][i]) |
---|
1418 |         if sizeSig[1][i]: |
---|
1419 | Â Â Â Â Â Â Â Â Â Â refine =Â True |
---|
1420 | Â Â Â Â Â Â Â Â Â Â sigstr +=Â '%12.6f'Â %Â (sizeSig[1][i]) |
---|
1421 | Â Â Â Â Â Â Â Â else: |
---|
1422 | Â Â Â Â Â Â Â Â Â Â sigstr +=Â 12*' ' |
---|
1423 |       if refine: |
---|
1424 |         print >>pFile,line |
---|
1425 |         print >>pFile,ptlbls |
---|
1426 |         print >>pFile,ptstr |
---|
1427 |         print >>pFile,sigstr |
---|
1428 | Â Â Â Â |
---|
1429 |   def PrintMuStrainAndSig(hapData,mustrainSig,SGData): |
---|
1430 |     line = '\n Mustrain model: %9s'%(hapData[0]) |
---|
1431 | Â Â Â Â refine =Â False |
---|
1432 |     if hapData[0] in ['isotropic','uniaxial']: |
---|
1433 | Â Â Â Â Â Â line +=Â ' equatorial:%12.1f'%(hapData[1][0]) |
---|
1434 |       if mustrainSig[0][0]: |
---|
1435 | Â Â Â Â Â Â Â Â line +=Â ', sig:%8.1f'%(mustrainSig[0][0]) |
---|
1436 | Â Â Â Â Â Â Â Â refine =Â True |
---|
1437 |       if hapData[0] == 'uniaxial': |
---|
1438 | Â Â Â Â Â Â Â Â line +=Â ' axial:%12.1f'%(hapData[1][1]) |
---|
1439 |         if mustrainSig[0][1]: |
---|
1440 | Â Â Â Â Â Â Â Â Â Â Â line +=Â ', sig:%8.1f'%(mustrainSig[0][1]) |
---|
1441 | Â Â Â Â Â Â line +=Â ' LG mix coeff.:%12.4f'%(hapData[1][2]) |
---|
1442 |       if mustrainSig[0][2]: |
---|
1443 | Â Â Â Â Â Â Â Â refine =Â True |
---|
1444 | Â Â Â Â Â Â Â Â line +=Â ', sig:%8.3f'%(mustrainSig[0][2]) |
---|
1445 |       if refine: |
---|
1446 |         print >>pFile,line |
---|
1447 | Â Â Â Â else: |
---|
1448 | Â Â Â Â Â Â line +=Â ' LG mix coeff.:%12.4f'%(hapData[1][2]) |
---|
1449 |       if mustrainSig[0][2]: |
---|
1450 | Â Â Â Â Â Â Â Â refine =Â True |
---|
1451 | Â Â Â Â Â Â Â Â line +=Â ', sig:%8.3f'%(mustrainSig[0][2]) |
---|
1452 | Â Â Â Â Â Â Snames =Â G2spc.MustrainNames(SGData) |
---|
1453 |       ptlbls = ' name :' |
---|
1454 | Â Â Â Â Â Â ptstr =Â ' value :' |
---|
1455 |       sigstr = ' sig  :' |
---|
1456 |       for i,name in enumerate(Snames): |
---|
1457 | Â Â Â Â Â Â Â Â ptlbls +=Â '%12s'Â %Â (name) |
---|
1458 | Â Â Â Â Â Â Â Â ptstr +=Â '%12.6f'Â %Â (hapData[4][i]) |
---|
1459 |         if mustrainSig[1][i]: |
---|
1460 | Â Â Â Â Â Â Â Â Â Â refine =Â True |
---|
1461 | Â Â Â Â Â Â Â Â Â Â sigstr +=Â '%12.6f'Â %Â (mustrainSig[1][i]) |
---|
1462 | Â Â Â Â Â Â Â Â else: |
---|
1463 | Â Â Â Â Â Â Â Â Â Â sigstr +=Â 12*' ' |
---|
1464 |       if refine: |
---|
1465 |         print >>pFile,line |
---|
1466 |         print >>pFile,ptlbls |
---|
1467 |         print >>pFile,ptstr |
---|
1468 |         print >>pFile,sigstr |
---|
1469 | Â Â Â Â Â Â |
---|
1470 |   def PrintHStrainAndSig(hapData,strainSig,SGData): |
---|
1471 | Â Â Â Â Hsnames =Â G2spc.HStrainNames(SGData) |
---|
1472 |     ptlbls = ' name :' |
---|
1473 | Â Â Â Â ptstr =Â ' value :' |
---|
1474 |     sigstr = ' sig  :' |
---|
1475 | Â Â Â Â refine =Â False |
---|
1476 |     for i,name in enumerate(Hsnames): |
---|
1477 | Â Â Â Â Â Â ptlbls +=Â '%12s'Â %Â (name) |
---|
1478 | Â Â Â Â Â Â ptstr +=Â '%12.6g'Â %Â (hapData[0][i]) |
---|
1479 |       if name in strainSig: |
---|
1480 | Â Â Â Â Â Â Â Â refine =Â True |
---|
1481 | Â Â Â Â Â Â Â Â sigstr +=Â '%12.6g'Â %Â (strainSig[name]) |
---|
1482 | Â Â Â Â Â Â else: |
---|
1483 | Â Â Â Â Â Â Â Â sigstr +=Â 12*' ' |
---|
1484 |     if refine: |
---|
1485 |       print >>pFile,'\n Hydrostatic/elastic strain: ' |
---|
1486 |       print >>pFile,ptlbls |
---|
1487 |       print >>pFile,ptstr |
---|
1488 |       print >>pFile,sigstr |
---|
1489 | Â Â Â Â |
---|
1490 |   def PrintSHPOAndSig(pfx,hapData,POsig): |
---|
1491 |     print >>pFile,'\n Spherical harmonics preferred orientation: Order:'+str(hapData[4]) |
---|
1492 | Â Â Â Â ptlbls =Â ' names :' |
---|
1493 | Â Â Â Â ptstr =Â ' values:' |
---|
1494 |     sigstr = ' sig  :' |
---|
1495 |     for item in hapData[5]: |
---|
1496 | Â Â Â Â Â Â ptlbls +=Â '%12s'%(item) |
---|
1497 | Â Â Â Â Â Â ptstr +=Â '%12.3f'%(hapData[5][item]) |
---|
1498 |       if pfx+item in POsig: |
---|
1499 | Â Â Â Â Â Â Â Â sigstr +=Â '%12.3f'%(POsig[pfx+item]) |
---|
1500 | Â Â Â Â Â Â else: |
---|
1501 | Â Â Â Â Â Â Â Â sigstr +=Â 12*' 'Â |
---|
1502 |     print >>pFile,ptlbls |
---|
1503 |     print >>pFile,ptstr |
---|
1504 |     print >>pFile,sigstr |
---|
1505 | Â Â Â Â |
---|
1506 |   def PrintExtAndSig(pfx,hapData,ScalExtSig): |
---|
1507 |     print >>pFile,'\n Single crystal extinction: Type: ',hapData[0],' Approx: ',hapData[1] |
---|
1508 | Â Â Â Â text =Â '' |
---|
1509 |     for item in hapData[2]: |
---|
1510 |       if pfx+item in ScalExtSig: |
---|
1511 | Â Â Â Â Â Â Â Â text +=Â 'Â Â Â Â %s: '%(item) |
---|
1512 | Â Â Â Â Â Â Â Â text +=Â '%12.2e'%(hapData[2][item][0]) |
---|
1513 |         if pfx+item in ScalExtSig: |
---|
1514 | Â Â Â Â Â Â Â Â Â Â text +=Â ' sig: %12.2e'%(ScalExtSig[pfx+item]) |
---|
1515 |     print >>pFile,text    |
---|
1516 | Â Â Â Â |
---|
1517 |   def PrintBabinetAndSig(pfx,hapData,BabSig): |
---|
1518 |     print >>pFile,'\n Babinet form factor modification: ' |
---|
1519 | Â Â Â Â ptlbls =Â ' names :' |
---|
1520 | Â Â Â Â ptstr =Â ' values:' |
---|
1521 |     sigstr = ' sig  :' |
---|
1522 |     for item in hapData: |
---|
1523 | Â Â Â Â Â Â ptlbls +=Â '%12s'%(item) |
---|
1524 | Â Â Â Â Â Â ptstr +=Â '%12.3f'%(hapData[item][0]) |
---|
1525 |       if pfx+item in BabSig: |
---|
1526 | Â Â Â Â Â Â Â Â sigstr +=Â '%12.3f'%(BabSig[pfx+item]) |
---|
1527 | Â Â Â Â Â Â else: |
---|
1528 | Â Â Â Â Â Â Â Â sigstr +=Â 12*' 'Â |
---|
1529 |     print >>pFile,ptlbls |
---|
1530 |     print >>pFile,ptstr |
---|
1531 |     print >>pFile,sigstr |
---|
1532 | Â Â |
---|
1533 | Â Â PhFrExtPOSig =Â {} |
---|
1534 | Â Â SizeMuStrSig =Â {} |
---|
1535 | Â Â ScalExtSig =Â {} |
---|
1536 | Â Â BabSig =Â {} |
---|
1537 | Â Â wtFrSum =Â {} |
---|
1538 |   for phase in Phases: |
---|
1539 | Â Â Â Â HistoPhase =Â Phases[phase]['Histograms'] |
---|
1540 | Â Â Â Â General =Â Phases[phase]['General'] |
---|
1541 | Â Â Â Â SGData =Â General['SGData'] |
---|
1542 | Â Â Â Â pId =Â Phases[phase]['pId'] |
---|
1543 | Â Â Â Â histoList =Â HistoPhase.keys() |
---|
1544 | Â Â Â Â histoList.sort() |
---|
1545 |     for histogram in histoList: |
---|
1546 | Â Â Â Â Â Â try: |
---|
1547 | Â Â Â Â Â Â Â Â Histogram =Â Histograms[histogram] |
---|
1548 |       except KeyError:            |
---|
1549 | Â Â Â Â Â Â Â Â #skip if histogram not included e.g. in a sequential refinement |
---|
1550 | Â Â Â Â Â Â Â Â continue |
---|
1551 | Â Â Â Â Â Â hapData =Â HistoPhase[histogram] |
---|
1552 | Â Â Â Â Â Â hId =Â Histogram['hId'] |
---|
1553 | Â Â Â Â Â Â pfx =Â str(pId)+':'+str(hId)+':' |
---|
1554 |       if hId not in wtFrSum: |
---|
1555 | Â Â Â Â Â Â Â Â wtFrSum[hId]Â =Â 0. |
---|
1556 |       if 'PWDR' in histogram: |
---|
1557 |         for item in ['Scale','Extinction']: |
---|
1558 | Â Â Â Â Â Â Â Â Â Â hapData[item][0]Â =Â parmDict[pfx+item] |
---|
1559 |           if pfx+item in sigDict: |
---|
1560 | Â Â Â Â Â Â Â Â Â Â Â Â PhFrExtPOSig.update({pfx+item:sigDict[pfx+item],}) |
---|
1561 | Â Â Â Â Â Â Â Â wtFrSum[hId]Â +=Â hapData['Scale'][0]*General['Mass'] |
---|
1562 |         if hapData['Pref.Ori.'][0] == 'MD': |
---|
1563 | Â Â Â Â Â Â Â Â Â Â hapData['Pref.Ori.'][1]Â =Â parmDict[pfx+'MD'] |
---|
1564 |           if pfx+'MD' in sigDict: |
---|
1565 | Â Â Â Â Â Â Â Â Â Â Â Â PhFrExtPOSig.update({pfx+'MD':sigDict[pfx+'MD'],}) |
---|
1566 | Â Â Â Â Â Â Â Â else:Â Â Â Â Â Â Â Â Â Â Â Â Â Â #'SH' spherical harmonics |
---|
1567 |           for item in hapData['Pref.Ori.'][5]: |
---|
1568 | Â Â Â Â Â Â Â Â Â Â Â Â hapData['Pref.Ori.'][5][item]Â =Â parmDict[pfx+item] |
---|
1569 |             if pfx+item in sigDict: |
---|
1570 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â PhFrExtPOSig.update({pfx+item:sigDict[pfx+item],}) |
---|
1571 |         SizeMuStrSig.update({pfx+'Mustrain':[[0,0,0],[0 for i in range(len(hapData['Mustrain'][4]))]], |
---|
1572 |           pfx+'Size':[[0,0,0],[0 for i in range(len(hapData['Size'][4]))]], |
---|
1573 | Â Â Â Â Â Â Â Â Â Â pfx+'HStrain':{}})Â Â Â Â Â Â Â Â Â |
---|
1574 |         for item in ['Mustrain','Size']: |
---|
1575 | Â Â Â Â Â Â Â Â Â Â hapData[item][1][2]Â =Â parmDict[pfx+item+';mx'] |
---|
1576 | Â Â Â Â Â Â Â Â Â Â hapData[item][1][2]Â =Â min(1.,max(0.1,hapData[item][1][2])) |
---|
1577 |           if pfx+item+';mx' in sigDict: |
---|
1578 | Â Â Â Â Â Â Â Â Â Â Â Â SizeMuStrSig[pfx+item][0][2]Â =Â sigDict[pfx+item+';mx'] |
---|
1579 |           if hapData[item][0] in ['isotropic','uniaxial']:          |
---|
1580 | Â Â Â Â Â Â Â Â Â Â Â Â hapData[item][1][0]Â =Â parmDict[pfx+item+';i'] |
---|
1581 |             if item == 'Size': |
---|
1582 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â hapData[item][1][0]Â =Â min(10.,max(0.001,hapData[item][1][0])) |
---|
1583 |             if pfx+item+';i' in sigDict: |
---|
1584 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â SizeMuStrSig[pfx+item][0][0]Â =Â sigDict[pfx+item+';i'] |
---|
1585 |             if hapData[item][0] == 'uniaxial': |
---|
1586 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â hapData[item][1][1]Â =Â parmDict[pfx+item+';a'] |
---|
1587 |               if item == 'Size': |
---|
1588 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â hapData[item][1][1]Â =Â min(10.,max(0.001,hapData[item][1][1]))Â Â Â Â Â Â Â Â Â Â Â Â |
---|
1589 |               if pfx+item+';a' in sigDict: |
---|
1590 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â SizeMuStrSig[pfx+item][0][1]Â =Â sigDict[pfx+item+';a'] |
---|
1591 | Â Â Â Â Â Â Â Â Â Â else:Â Â Â Â #generalized for mustrain or ellipsoidal for size |
---|
1592 | Â Â Â Â Â Â Â Â Â Â Â Â Nterms =Â len(hapData[item][4]) |
---|
1593 |             for i in range(Nterms): |
---|
1594 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â sfx =Â ':'+str(i) |
---|
1595 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â hapData[item][4][i]Â =Â parmDict[pfx+item+sfx] |
---|
1596 |               if pfx+item+sfx in sigDict: |
---|
1597 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â SizeMuStrSig[pfx+item][1][i]Â =Â sigDict[pfx+item+sfx] |
---|
1598 | Â Â Â Â Â Â Â Â names =Â G2spc.HStrainNames(SGData) |
---|
1599 |         for i,name in enumerate(names): |
---|
1600 | Â Â Â Â Â Â Â Â Â Â hapData['HStrain'][0][i]Â =Â parmDict[pfx+name] |
---|
1601 |           if pfx+name in sigDict: |
---|
1602 | Â Â Â Â Â Â Â Â Â Â Â Â SizeMuStrSig[pfx+'HStrain'][name]Â =Â sigDict[pfx+name] |
---|
1603 |         for name in ['BabA','BabU']: |
---|
1604 | Â Â Â Â Â Â Â Â Â Â hapData['Babinet'][name][0]Â =Â parmDict[pfx+name] |
---|
1605 |           if pfx+name in sigDict: |
---|
1606 | Â Â Â Â Â Â Â Â Â Â Â Â BabSig[pfx+name]Â =Â sigDict[pfx+name]Â Â Â Â Â Â Â Â |
---|
1607 | Â Â Â Â Â Â Â Â |
---|
1608 |       elif 'HKLF' in histogram: |
---|
1609 |         for item in ['Scale',]: |
---|
1610 |           if parmDict.get(pfx+item): |
---|
1611 | Â Â Â Â Â Â Â Â Â Â Â Â hapData[item][0]Â =Â parmDict[pfx+item] |
---|
1612 |             if pfx+item in sigDict: |
---|
1613 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â ScalExtSig[pfx+item]Â =Â sigDict[pfx+item] |
---|
1614 |         for item in ['Ep','Eg','Es']: |
---|
1615 |           if parmDict.get(pfx+item): |
---|
1616 | Â Â Â Â Â Â Â Â Â Â Â Â hapData['Extinction'][2][item][0]Â =Â parmDict[pfx+item] |
---|
1617 |             if pfx+item in sigDict: |
---|
1618 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â ScalExtSig[pfx+item]Â =Â sigDict[pfx+item] |
---|
1619 |         for name in ['BabA','BabU']: |
---|
1620 | Â Â Â Â Â Â Â Â Â Â hapData['Babinet'][name][0]Â =Â parmDict[pfx+name] |
---|
1621 |           if pfx+name in sigDict: |
---|
1622 | Â Â Â Â Â Â Â Â Â Â Â Â BabSig[pfx+name]Â =Â sigDict[pfx+name]Â Â Â Â Â Â Â Â |
---|
1623 | |
---|
1624 |   if Print: |
---|
1625 |     for phase in Phases: |
---|
1626 | Â Â Â Â Â Â HistoPhase =Â Phases[phase]['Histograms'] |
---|
1627 | Â Â Â Â Â Â General =Â Phases[phase]['General'] |
---|
1628 | Â Â Â Â Â Â SGData =Â General['SGData'] |
---|
1629 | Â Â Â Â Â Â pId =Â Phases[phase]['pId'] |
---|
1630 | Â Â Â Â Â Â histoList =Â HistoPhase.keys() |
---|
1631 | Â Â Â Â Â Â histoList.sort() |
---|
1632 |       for histogram in histoList: |
---|
1633 | Â Â Â Â Â Â Â Â try: |
---|
1634 | Â Â Â Â Â Â Â Â Â Â Histogram =Â Histograms[histogram] |
---|
1635 |         except KeyError:            |
---|
1636 | Â Â Â Â Â Â Â Â Â Â #skip if histogram not included e.g. in a sequential refinement |
---|
1637 | Â Â Â Â Â Â Â Â Â Â continue |
---|
1638 |         print >>pFile,'\n Phase: ',phase,' in histogram: ',histogram |
---|
1639 |         print >>pFile,130*'-' |
---|
1640 | Â Â Â Â Â Â Â Â hapData =Â HistoPhase[histogram] |
---|
1641 | Â Â Â Â Â Â Â Â hId =Â Histogram['hId'] |
---|
1642 | Â Â Â Â Â Â Â Â pfx =Â str(pId)+':'+str(hId)+':' |
---|
1643 |         if 'PWDR' in histogram: |
---|
1644 |           print >>pFile,' Final refinement RF, RF^2 = %.2f%%, %.2f%% on %d reflections'  \ |
---|
1645 | Â Â Â Â Â Â Â Â Â Â Â Â %(Histogram[pfx+'Rf'],Histogram[pfx+'Rf^2'],Histogram[pfx+'Nref']) |
---|
1646 | Â Â Â Â Â Â Â Â |
---|
1647 |           if pfx+'Scale' in PhFrExtPOSig: |
---|
1648 | Â Â Â Â Â Â Â Â Â Â Â Â wtFr =Â hapData['Scale'][0]*General['Mass']/wtFrSum[hId] |
---|
1649 | Â Â Â Â Â Â Â Â Â Â Â Â sigwtFr =Â PhFrExtPOSig[pfx+'Scale']*wtFr/hapData['Scale'][0] |
---|
1650 |             print >>pFile,' Phase fraction : %10.5f, sig %10.5f Weight fraction : %8.5f, sig %10.5f' \ |
---|
1651 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â %(hapData['Scale'][0],PhFrExtPOSig[pfx+'Scale'],wtFr,sigwtFr) |
---|
1652 |           if pfx+'Extinction' in PhFrExtPOSig: |
---|
1653 |             print >>pFile,' Extinction coeff: %10.4f, sig %10.4f'%(hapData['Extinction'][0],PhFrExtPOSig[pfx+'Extinction']) |
---|
1654 |           if hapData['Pref.Ori.'][0] == 'MD': |
---|
1655 |             if pfx+'MD' in PhFrExtPOSig: |
---|
1656 |               print >>pFile,' March-Dollase PO: %10.4f, sig %10.4f'%(hapData['Pref.Ori.'][1],PhFrExtPOSig[pfx+'MD']) |
---|
1657 | Â Â Â Â Â Â Â Â Â Â else: |
---|
1658 | Â Â Â Â Â Â Â Â Â Â Â Â PrintSHPOAndSig(pfx,hapData['Pref.Ori.'],PhFrExtPOSig) |
---|
1659 | Â Â Â Â Â Â Â Â Â Â PrintSizeAndSig(hapData['Size'],SizeMuStrSig[pfx+'Size']) |
---|
1660 | Â Â Â Â Â Â Â Â Â Â PrintMuStrainAndSig(hapData['Mustrain'],SizeMuStrSig[pfx+'Mustrain'],SGData) |
---|
1661 | Â Â Â Â Â Â Â Â Â Â PrintHStrainAndSig(hapData['HStrain'],SizeMuStrSig[pfx+'HStrain'],SGData) |
---|
1662 | Â Â Â Â Â Â Â Â Â Â PrintBabinetAndSig(pfx,hapData['Babinet'],BabSig) |
---|
1663 | Â Â Â Â Â Â Â Â Â Â |
---|
1664 |         elif 'HKLF' in histogram: |
---|
1665 |           print >>pFile,' Final refinement RF, RF^2 = %.2f%%, %.2f%% on %d reflections'  \ |
---|
1666 | Â Â Â Â Â Â Â Â Â Â Â Â %(Histogram[pfx+'Rf'],Histogram[pfx+'Rf^2'],Histogram[pfx+'Nref']) |
---|
1667 |           print >>pFile,' HKLF histogram weight factor = ','%.3f'%(Histogram['wtFactor']) |
---|
1668 |           if pfx+'Scale' in ScalExtSig: |
---|
1669 |             print >>pFile,' Scale factor : %10.4f, sig %10.4f'%(hapData['Scale'][0],ScalExtSig[pfx+'Scale']) |
---|
1670 |           if hapData['Extinction'][0] != 'None': |
---|
1671 | Â Â Â Â Â Â Â Â Â Â Â Â PrintExtAndSig(pfx,hapData['Extinction'],ScalExtSig) |
---|
1672 |           if len(BabSig): |
---|
1673 | Â Â Â Â Â Â Â Â Â Â Â Â PrintBabinetAndSig(pfx,hapData['Babinet'],BabSig) |
---|
1674 | |
---|
1675 | ################################################################################ |
---|
1676 | ##### Histogram data |
---|
1677 | ################################################################################Â Â Â Â |
---|
1678 | Â Â Â Â Â Â Â Â Â Â |
---|
1679 | def GetHistogramData(Histograms,Print=True,pFile=None): |
---|
1680 | Â Â |
---|
1681 |   def GetBackgroundParms(hId,Background): |
---|
1682 | Â Â Â Â Back =Â Background[0] |
---|
1683 | Â Â Â Â DebyePeaks =Â Background[1] |
---|
1684 | Â Â Â Â bakType,bakFlag =Â Back[:2] |
---|
1685 | Â Â Â Â backVals =Â Back[3:] |
---|
1686 |     backNames = [':'+str(hId)+':Back:'+str(i) for i in range(len(backVals))] |
---|
1687 | Â Â Â Â backDict =Â dict(zip(backNames,backVals)) |
---|
1688 | Â Â Â Â backVary =Â [] |
---|
1689 |     if bakFlag: |
---|
1690 | Â Â Â Â Â Â backVary =Â backNames |
---|
1691 | Â Â Â Â backDict[':'+str(hId)+':nDebye']Â =Â DebyePeaks['nDebye'] |
---|
1692 | Â Â Â Â backDict[':'+str(hId)+':nPeaks']Â =Â DebyePeaks['nPeaks'] |
---|
1693 | Â Â Â Â debyeDict =Â {} |
---|
1694 | Â Â Â Â debyeList =Â [] |
---|
1695 |     for i in range(DebyePeaks['nDebye']): |
---|
1696 | Â Â Â Â Â Â debyeNames =Â [':'+str(hId)+':DebyeA:'+str(i),':'+str(hId)+':DebyeR:'+str(i),':'+str(hId)+':DebyeU:'+str(i)] |
---|
1697 | Â Â Â Â Â Â debyeDict.update(dict(zip(debyeNames,DebyePeaks['debyeTerms'][i][::2]))) |
---|
1698 | Â Â Â Â Â Â debyeList +=Â zip(debyeNames,DebyePeaks['debyeTerms'][i][1::2]) |
---|
1699 | Â Â Â Â debyeVary =Â [] |
---|
1700 |     for item in debyeList: |
---|
1701 |       if item[1]: |
---|
1702 | Â Â Â Â Â Â Â Â debyeVary.append(item[0]) |
---|
1703 | Â Â Â Â backDict.update(debyeDict) |
---|
1704 | Â Â Â Â backVary +=Â debyeVary |
---|
1705 | Â Â Â Â peakDict =Â {} |
---|
1706 | Â Â Â Â peakList =Â [] |
---|
1707 |     for i in range(DebyePeaks['nPeaks']): |
---|
1708 | Â Â Â Â Â Â peakNames =Â [':'+str(hId)+':BkPkpos:'+str(i),':'+str(hId)+Â \ |
---|
1709 | Â Â Â Â Â Â Â Â ':BkPkint:'+str(i),':'+str(hId)+':BkPksig:'+str(i),':'+str(hId)+':BkPkgam:'+str(i)] |
---|
1710 | Â Â Â Â Â Â peakDict.update(dict(zip(peakNames,DebyePeaks['peaksList'][i][::2]))) |
---|
1711 | Â Â Â Â Â Â peakList +=Â zip(peakNames,DebyePeaks['peaksList'][i][1::2]) |
---|
1712 | Â Â Â Â peakVary =Â [] |
---|
1713 |     for item in peakList: |
---|
1714 |       if item[1]: |
---|
1715 | Â Â Â Â Â Â Â Â peakVary.append(item[0]) |
---|
1716 | Â Â Â Â backDict.update(peakDict) |
---|
1717 | Â Â Â Â backVary +=Â peakVary |
---|
1718 |     return bakType,backDict,backVary      |
---|
1719 | Â Â Â Â |
---|
1720 |   def GetInstParms(hId,Inst):   |
---|
1721 | Â Â Â Â dataType =Â Inst['Type'][0] |
---|
1722 | Â Â Â Â instDict =Â {} |
---|
1723 | Â Â Â Â insVary =Â [] |
---|
1724 | Â Â Â Â pfx =Â ':'+str(hId)+':' |
---|
1725 | Â Â Â Â insKeys =Â Inst.keys() |
---|
1726 | Â Â Â Â insKeys.sort() |
---|
1727 |     for item in insKeys: |
---|
1728 | Â Â Â Â Â Â insName =Â pfx+item |
---|
1729 | Â Â Â Â Â Â instDict[insName]Â =Â Inst[item][1] |
---|
1730 |       if Inst[item][2]: |
---|
1731 | Â Â Â Â Â Â Â Â insVary.append(insName) |
---|
1732 | #Â Â Â Â instDict[pfx+'X'] = max(instDict[pfx+'X'],0.001) |
---|
1733 | #Â Â Â Â instDict[pfx+'Y'] = max(instDict[pfx+'Y'],0.001) |
---|
1734 | Â Â Â Â instDict[pfx+'SH/L']Â =Â max(instDict[pfx+'SH/L'],0.0005) |
---|
1735 |     return dataType,instDict,insVary |
---|
1736 | Â Â Â Â |
---|
1737 |   def GetSampleParms(hId,Sample): |
---|
1738 | Â Â Â Â sampVary =Â [] |
---|
1739 | Â Â Â Â hfx =Â ':'+str(hId)+':'Â Â Â Â |
---|
1740 | Â Â Â Â sampDict =Â {hfx+'Gonio. radius':Sample['Gonio. radius'],hfx+'Omega':Sample['Omega'], |
---|
1741 | Â Â Â Â Â Â hfx+'Chi':Sample['Chi'],hfx+'Phi':Sample['Phi']} |
---|
1742 | Â Â Â Â Type =Â Sample['Type'] |
---|
1743 |     if 'Bragg' in Type:       #Bragg-Brentano |
---|
1744 |       for item in ['Scale','Shift','Transparency']:    #surface roughness?, diffuse scattering? |
---|
1745 | Â Â Â Â Â Â Â Â sampDict[hfx+item]Â =Â Sample[item][0] |
---|
1746 |         if Sample[item][1]: |
---|
1747 | Â Â Â Â Â Â Â Â Â Â sampVary.append(hfx+item) |
---|
1748 |     elif 'Debye' in Type:    #Debye-Scherrer |
---|
1749 |       for item in ['Scale','Absorption','DisplaceX','DisplaceY']: |
---|
1750 | Â Â Â Â Â Â Â Â sampDict[hfx+item]Â =Â Sample[item][0] |
---|
1751 |         if Sample[item][1]: |
---|
1752 | Â Â Â Â Â Â Â Â Â Â sampVary.append(hfx+item) |
---|
1753 |     return Type,sampDict,sampVary |
---|
1754 | Â Â Â Â |
---|
1755 |   def PrintBackground(Background): |
---|
1756 | Â Â Â Â Back =Â Background[0] |
---|
1757 | Â Â Â Â DebyePeaks =Â Background[1] |
---|
1758 |     print >>pFile,'\n Background function: ',Back[0],' Refine?',bool(Back[1]) |
---|
1759 | Â Â Â Â line =Â ' Coefficients: ' |
---|
1760 |     for i,back in enumerate(Back[3:]): |
---|
1761 | Â Â Â Â Â Â line +=Â '%10.3f'%(back) |
---|
1762 |       if i and not i%10: |
---|
1763 | Â Â Â Â Â Â Â Â line +=Â '\n'+15*' ' |
---|
1764 |     print >>pFile,line |
---|
1765 |     if DebyePeaks['nDebye']: |
---|
1766 |       print >>pFile,'\n Debye diffuse scattering coefficients' |
---|
1767 | Â Â Â Â Â Â parms =Â ['DebyeA','DebyeR','DebyeU'] |
---|
1768 | Â Â Â Â Â Â line =Â ' names :Â ' |
---|
1769 |       for parm in parms: |
---|
1770 |         line += '%8s refine?'%(parm) |
---|
1771 |       print >>pFile,line |
---|
1772 |       for j,term in enumerate(DebyePeaks['debyeTerms']): |
---|
1773 | Â Â Â Â Â Â Â Â line =Â ' term'+'%2d'%(j)+':' |
---|
1774 |         for i in range(3): |
---|
1775 |           line += '%10.3f %5s'%(term[2*i],bool(term[2*i+1]))          |
---|
1776 |         print >>pFile,line |
---|
1777 |     if DebyePeaks['nPeaks']: |
---|
1778 |       print >>pFile,'\n Single peak coefficients' |
---|
1779 | Â Â Â Â Â Â parms =Â Â ['BkPkpos','BkPkint','BkPksig','BkPkgam'] |
---|
1780 | Â Â Â Â Â Â line =Â ' names :Â ' |
---|
1781 |       for parm in parms: |
---|
1782 |         line += '%8s refine?'%(parm) |
---|
1783 |       print >>pFile,line |
---|
1784 |       for j,term in enumerate(DebyePeaks['peaksList']): |
---|
1785 | Â Â Â Â Â Â Â Â line =Â ' peak'+'%2d'%(j)+':' |
---|
1786 |         for i in range(4): |
---|
1787 |           line += '%10.3f %5s'%(term[2*i],bool(term[2*i+1]))          |
---|
1788 |         print >>pFile,line |
---|
1789 | Â Â Â Â |
---|
1790 |   def PrintInstParms(Inst): |
---|
1791 |     print >>pFile,'\n Instrument Parameters:' |
---|
1792 |     ptlbls = ' name :' |
---|
1793 | Â Â Â Â ptstr =Â ' value :' |
---|
1794 | Â Â Â Â varstr =Â ' refine:' |
---|
1795 | Â Â Â Â insKeys =Â Inst.keys() |
---|
1796 | Â Â Â Â insKeys.sort() |
---|
1797 |     for item in insKeys: |
---|
1798 |       if item != 'Type': |
---|
1799 | Â Â Â Â Â Â Â Â ptlbls +=Â '%12s'Â %Â (item) |
---|
1800 | Â Â Â Â Â Â Â Â ptstr +=Â '%12.6f'Â %Â (Inst[item][1]) |
---|
1801 |         if item in ['Lam1','Lam2','Azimuth']: |
---|
1802 | Â Â Â Â Â Â Â Â Â Â varstr +=Â 12*' ' |
---|
1803 | Â Â Â Â Â Â Â Â else: |
---|
1804 | Â Â Â Â Â Â Â Â Â Â varstr +=Â '%12s'Â %Â (str(bool(Inst[item][2]))) |
---|
1805 |     print >>pFile,ptlbls |
---|
1806 |     print >>pFile,ptstr |
---|
1807 |     print >>pFile,varstr |
---|
1808 | Â Â Â Â |
---|
1809 |   def PrintSampleParms(Sample): |
---|
1810 |     print >>pFile,'\n Sample Parameters:' |
---|
1811 |     print >>pFile,' Goniometer omega = %.2f, chi = %.2f, phi = %.2f'% \ |
---|
1812 | Â Â Â Â Â Â (Sample['Omega'],Sample['Chi'],Sample['Phi']) |
---|
1813 |     ptlbls = ' name :' |
---|
1814 | Â Â Â Â ptstr =Â ' value :' |
---|
1815 | Â Â Â Â varstr =Â ' refine:' |
---|
1816 |     if 'Bragg' in Sample['Type']: |
---|
1817 |       for item in ['Scale','Shift','Transparency']: |
---|
1818 | Â Â Â Â Â Â Â Â ptlbls +=Â '%14s'%(item) |
---|
1819 | Â Â Â Â Â Â Â Â ptstr +=Â '%14.4f'%(Sample[item][0]) |
---|
1820 | Â Â Â Â Â Â Â Â varstr +=Â '%14s'%(str(bool(Sample[item][1]))) |
---|
1821 | Â Â Â Â Â Â |
---|
1822 |     elif 'Debye' in Type:    #Debye-Scherrer |
---|
1823 |       for item in ['Scale','Absorption','DisplaceX','DisplaceY']: |
---|
1824 | Â Â Â Â Â Â Â Â ptlbls +=Â '%14s'%(item) |
---|
1825 | Â Â Â Â Â Â Â Â ptstr +=Â '%14.4f'%(Sample[item][0]) |
---|
1826 | Â Â Â Â Â Â Â Â varstr +=Â '%14s'%(str(bool(Sample[item][1]))) |
---|
1827 | |
---|
1828 |     print >>pFile,ptlbls |
---|
1829 |     print >>pFile,ptstr |
---|
1830 |     print >>pFile,varstr |
---|
1831 | Â Â Â Â |
---|
1832 | Â Â histDict =Â {} |
---|
1833 | Â Â histVary =Â [] |
---|
1834 | Â Â controlDict =Â {} |
---|
1835 | Â Â histoList =Â Histograms.keys() |
---|
1836 | Â Â histoList.sort() |
---|
1837 |   for histogram in histoList: |
---|
1838 |     if 'PWDR' in histogram: |
---|
1839 | Â Â Â Â Â Â Histogram =Â Histograms[histogram] |
---|
1840 | Â Â Â Â Â Â hId =Â Histogram['hId'] |
---|
1841 | Â Â Â Â Â Â pfx =Â ':'+str(hId)+':' |
---|
1842 | Â Â Â Â Â Â controlDict[pfx+'wtFactor']Â =Â Histogram['wtFactor'] |
---|
1843 | Â Â Â Â Â Â controlDict[pfx+'Limits']Â =Â Histogram['Limits'][1] |
---|
1844 | Â Â Â Â Â Â |
---|
1845 | Â Â Â Â Â Â Background =Â Histogram['Background'] |
---|
1846 | Â Â Â Â Â Â Type,bakDict,bakVary =Â GetBackgroundParms(hId,Background) |
---|
1847 | Â Â Â Â Â Â controlDict[pfx+'bakType']Â =Â Type |
---|
1848 | Â Â Â Â Â Â histDict.update(bakDict) |
---|
1849 | Â Â Â Â Â Â histVary +=Â bakVary |
---|
1850 | Â Â Â Â Â Â |
---|
1851 | Â Â Â Â Â Â Inst =Â Histogram['Instrument Parameters'][0] |
---|
1852 | Â Â Â Â Â Â Type,instDict,insVary =Â GetInstParms(hId,Inst) |
---|
1853 | Â Â Â Â Â Â controlDict[pfx+'histType']Â =Â Type |
---|
1854 |       if pfx+'Lam1' in instDict: |
---|
1855 | Â Â Â Â Â Â Â Â controlDict[pfx+'keV']Â =Â 12.397639/instDict[pfx+'Lam1'] |
---|
1856 | Â Â Â Â Â Â else: |
---|
1857 | Â Â Â Â Â Â Â Â controlDict[pfx+'keV']Â =Â 12.397639/instDict[pfx+'Lam']Â Â Â Â Â Â |
---|
1858 | Â Â Â Â Â Â histDict.update(instDict) |
---|
1859 | Â Â Â Â Â Â histVary +=Â insVary |
---|
1860 | Â Â Â Â Â Â |
---|
1861 | Â Â Â Â Â Â Sample =Â Histogram['Sample Parameters'] |
---|
1862 | Â Â Â Â Â Â Type,sampDict,sampVary =Â GetSampleParms(hId,Sample) |
---|
1863 | Â Â Â Â Â Â controlDict[pfx+'instType']Â =Â Type |
---|
1864 | Â Â Â Â Â Â histDict.update(sampDict) |
---|
1865 | Â Â Â Â Â Â histVary +=Â sampVary |
---|
1866 | Â Â Â Â Â Â |
---|
1867 | Â Â |
---|
1868 |       if Print: |
---|
1869 |         print >>pFile,'\n Histogram: ',histogram,' histogram Id: ',hId |
---|
1870 |         print >>pFile,135*'-' |
---|
1871 | Â Â Â Â Â Â Â Â Units =Â {'C':' deg','T':' msec'} |
---|
1872 | Â Â Â Â Â Â Â Â units =Â Units[controlDict[pfx+'histType'][2]] |
---|
1873 | Â Â Â Â Â Â Â Â Limits =Â controlDict[pfx+'Limits'] |
---|
1874 |         print >>pFile,' Instrument type: ',Sample['Type'] |
---|
1875 |         print >>pFile,' Histogram limits: %8.2f%s to %8.2f%s'%(Limits[0],units,Limits[1],units)   |
---|
1876 | Â Â Â Â Â Â Â Â PrintSampleParms(Sample) |
---|
1877 | Â Â Â Â Â Â Â Â PrintInstParms(Inst) |
---|
1878 | Â Â Â Â Â Â Â Â PrintBackground(Background) |
---|
1879 |     elif 'HKLF' in histogram: |
---|
1880 | Â Â Â Â Â Â Histogram =Â Histograms[histogram] |
---|
1881 | Â Â Â Â Â Â hId =Â Histogram['hId'] |
---|
1882 | Â Â Â Â Â Â pfx =Â ':'+str(hId)+':' |
---|
1883 | Â Â Â Â Â Â controlDict[pfx+'wtFactor']Â =Histogram['wtFactor'] |
---|
1884 | Â Â Â Â Â Â Inst =Â Histogram['Instrument Parameters'][0] |
---|
1885 | Â Â Â Â Â Â controlDict[pfx+'histType']Â =Â Inst['Type'][0] |
---|
1886 | Â Â Â Â Â Â histDict[pfx+'Lam']Â =Â Inst['Lam'][1] |
---|
1887 | Â Â Â Â Â Â controlDict[pfx+'keV']Â =Â 12.397639/histDict[pfx+'Lam']Â Â Â Â Â Â Â Â Â Â |
---|
1888 |   return histVary,histDict,controlDict |
---|
1889 | Â Â |
---|
1890 | def SetHistogramData(parmDict,sigDict,Histograms,Print=True,pFile=None): |
---|
1891 | Â Â |
---|
1892 |   def SetBackgroundParms(pfx,Background,parmDict,sigDict): |
---|
1893 | Â Â Â Â Back =Â Background[0] |
---|
1894 | Â Â Â Â DebyePeaks =Â Background[1] |
---|
1895 | Â Â Â Â lenBack =Â len(Back[3:]) |
---|
1896 |     backSig = [0 for i in range(lenBack+3*DebyePeaks['nDebye']+4*DebyePeaks['nPeaks'])] |
---|
1897 |     for i in range(lenBack): |
---|
1898 | Â Â Â Â Â Â Back[3+i]Â =Â parmDict[pfx+'Back:'+str(i)] |
---|
1899 |       if pfx+'Back:'+str(i) in sigDict: |
---|
1900 | Â Â Â Â Â Â Â Â backSig[i]Â =Â sigDict[pfx+'Back:'+str(i)] |
---|
1901 |     if DebyePeaks['nDebye']: |
---|
1902 |       for i in range(DebyePeaks['nDebye']): |
---|
1903 | Â Â Â Â Â Â Â Â names =Â [pfx+'DebyeA:'+str(i),pfx+'DebyeR:'+str(i),pfx+'DebyeU:'+str(i)] |
---|
1904 |         for j,name in enumerate(names): |
---|
1905 | Â Â Â Â Â Â Â Â Â Â DebyePeaks['debyeTerms'][i][2*j]Â =Â parmDict[name] |
---|
1906 |           if name in sigDict: |
---|
1907 | Â Â Â Â Â Â Â Â Â Â Â Â backSig[lenBack+3*i+j]Â =Â sigDict[name]Â Â Â Â Â Â |
---|
1908 |     if DebyePeaks['nPeaks']: |
---|
1909 |       for i in range(DebyePeaks['nPeaks']): |
---|
1910 | Â Â Â Â Â Â Â Â names =Â [pfx+'BkPkpos:'+str(i),pfx+'BkPkint:'+str(i), |
---|
1911 | Â Â Â Â Â Â Â Â Â Â pfx+'BkPksig:'+str(i),pfx+'BkPkgam:'+str(i)] |
---|
1912 |         for j,name in enumerate(names): |
---|
1913 | Â Â Â Â Â Â Â Â Â Â DebyePeaks['peaksList'][i][2*j]Â =Â parmDict[name] |
---|
1914 |           if name in sigDict: |
---|
1915 | Â Â Â Â Â Â Â Â Â Â Â Â backSig[lenBack+3*DebyePeaks['nDebye']+4*i+j]Â =Â sigDict[name] |
---|
1916 |     return backSig |
---|
1917 | Â Â Â Â |
---|
1918 |   def SetInstParms(pfx,Inst,parmDict,sigDict): |
---|
1919 | Â Â Â Â instSig =Â {} |
---|
1920 | Â Â Â Â insKeys =Â Inst.keys() |
---|
1921 | Â Â Â Â insKeys.sort() |
---|
1922 |     for item in insKeys: |
---|
1923 | Â Â Â Â Â Â insName =Â pfx+item |
---|
1924 | Â Â Â Â Â Â Inst[item][1]Â =Â parmDict[insName] |
---|
1925 |       if insName in sigDict: |
---|
1926 | Â Â Â Â Â Â Â Â instSig[item]Â =Â sigDict[insName] |
---|
1927 | Â Â Â Â Â Â else: |
---|
1928 | Â Â Â Â Â Â Â Â instSig[item]Â =Â 0 |
---|
1929 |     return instSig |
---|
1930 | Â Â Â Â |
---|
1931 |   def SetSampleParms(pfx,Sample,parmDict,sigDict): |
---|
1932 |     if 'Bragg' in Sample['Type']:       #Bragg-Brentano |
---|
1933 |       sampSig = [0 for i in range(3)] |
---|
1934 |       for i,item in enumerate(['Scale','Shift','Transparency']):    #surface roughness?, diffuse scattering? |
---|
1935 | Â Â Â Â Â Â Â Â Sample[item][0]Â =Â parmDict[pfx+item] |
---|
1936 |         if pfx+item in sigDict: |
---|
1937 | Â Â Â Â Â Â Â Â Â Â sampSig[i]Â =Â sigDict[pfx+item] |
---|
1938 |     elif 'Debye' in Sample['Type']:    #Debye-Scherrer |
---|
1939 |       sampSig = [0 for i in range(4)] |
---|
1940 |       for i,item in enumerate(['Scale','Absorption','DisplaceX','DisplaceY']): |
---|
1941 | Â Â Â Â Â Â Â Â Sample[item][0]Â =Â parmDict[pfx+item] |
---|
1942 |         if pfx+item in sigDict: |
---|
1943 | Â Â Â Â Â Â Â Â Â Â sampSig[i]Â =Â sigDict[pfx+item] |
---|
1944 |     return sampSig |
---|
1945 | Â Â Â Â |
---|
1946 |   def PrintBackgroundSig(Background,backSig): |
---|
1947 | Â Â Â Â Back =Â Background[0] |
---|
1948 | Â Â Â Â DebyePeaks =Â Background[1] |
---|
1949 | Â Â Â Â lenBack =Â len(Back[3:]) |
---|
1950 | Â Â Â Â valstr =Â ' value : ' |
---|
1951 |     sigstr = ' sig  : ' |
---|
1952 | Â Â Â Â refine =Â False |
---|
1953 |     for i,back in enumerate(Back[3:]): |
---|
1954 | Â Â Â Â Â Â valstr +=Â '%10.4g'%(back) |
---|
1955 |       if Back[1]: |
---|
1956 | Â Â Â Â Â Â Â Â refine =Â True |
---|
1957 | Â Â Â Â Â Â Â Â sigstr +=Â '%10.4g'%(backSig[i]) |
---|
1958 | Â Â Â Â Â Â else: |
---|
1959 | Â Â Â Â Â Â Â Â sigstr +=Â 10*' ' |
---|
1960 |     if refine: |
---|
1961 |       print >>pFile,'\n Background function: ',Back[0] |
---|
1962 |       print >>pFile,valstr |
---|
1963 |       print >>pFile,sigstr |
---|
1964 |     if DebyePeaks['nDebye']: |
---|
1965 | Â Â Â Â Â Â ifAny =Â False |
---|
1966 | Â Â Â Â Â Â ptfmt =Â "%12.3f" |
---|
1967 | Â Â Â Â Â Â names =Â ' names :' |
---|
1968 | Â Â Â Â Â Â ptstr =Â ' values:' |
---|
1969 |       sigstr = ' esds :' |
---|
1970 |       for item in sigDict: |
---|
1971 |         if 'Debye' in item: |
---|
1972 | Â Â Â Â Â Â Â Â Â Â ifAny =Â True |
---|
1973 | Â Â Â Â Â Â Â Â Â Â names +=Â '%12s'%(item) |
---|
1974 | Â Â Â Â Â Â Â Â Â Â ptstr +=Â ptfmt%(parmDict[item]) |
---|
1975 | Â Â Â Â Â Â Â Â Â Â sigstr +=Â ptfmt%(sigDict[item]) |
---|
1976 |       if ifAny: |
---|
1977 |         print >>pFile,'\n Debye diffuse scattering coefficients' |
---|
1978 |         print >>pFile,names |
---|
1979 |         print >>pFile,ptstr |
---|
1980 |         print >>pFile,sigstr |
---|
1981 |     if DebyePeaks['nPeaks']: |
---|
1982 | Â Â Â Â Â Â ifAny =Â False |
---|
1983 | Â Â Â Â Â Â ptfmt =Â "%14.3f" |
---|
1984 | Â Â Â Â Â Â names =Â ' names :' |
---|
1985 | Â Â Â Â Â Â ptstr =Â ' values:' |
---|
1986 |       sigstr = ' esds :' |
---|
1987 |       for item in sigDict: |
---|
1988 |         if 'BkPk' in item: |
---|
1989 | Â Â Â Â Â Â Â Â Â Â ifAny =Â True |
---|
1990 | Â Â Â Â Â Â Â Â Â Â names +=Â '%14s'%(item) |
---|
1991 | Â Â Â Â Â Â Â Â Â Â ptstr +=Â ptfmt%(parmDict[item]) |
---|
1992 | Â Â Â Â Â Â Â Â Â Â sigstr +=Â ptfmt%(sigDict[item]) |
---|
1993 |       if ifAny: |
---|
1994 |         print >>pFile,'\n Single peak coefficients' |
---|
1995 |         print >>pFile,names |
---|
1996 |         print >>pFile,ptstr |
---|
1997 |         print >>pFile,sigstr |
---|
1998 | Â Â Â Â |
---|
1999 |   def PrintInstParmsSig(Inst,instSig): |
---|
2000 | Â Â Â Â ptlbls =Â ' names :' |
---|
2001 | Â Â Â Â ptstr =Â ' value :' |
---|
2002 |     sigstr = ' sig  :' |
---|
2003 | Â Â Â Â refine =Â False |
---|
2004 | Â Â Â Â insKeys =Â instSig.keys() |
---|
2005 | Â Â Â Â insKeys.sort() |
---|
2006 |     for name in insKeys: |
---|
2007 |       if name not in ['Type','Lam1','Lam2','Azimuth']: |
---|
2008 | Â Â Â Â Â Â Â Â ptlbls +=Â '%12s'Â %Â (name) |
---|
2009 | Â Â Â Â Â Â Â Â ptstr +=Â '%12.6f'Â %Â (Inst[name][1]) |
---|
2010 |         if instSig[name]: |
---|
2011 | Â Â Â Â Â Â Â Â Â Â refine =Â True |
---|
2012 | Â Â Â Â Â Â Â Â Â Â sigstr +=Â '%12.6f'Â %Â (instSig[name]) |
---|
2013 | Â Â Â Â Â Â Â Â else: |
---|
2014 | Â Â Â Â Â Â Â Â Â Â sigstr +=Â 12*' ' |
---|
2015 |     if refine: |
---|
2016 |       print >>pFile,'\n Instrument Parameters:' |
---|
2017 |       print >>pFile,ptlbls |
---|
2018 |       print >>pFile,ptstr |
---|
2019 |       print >>pFile,sigstr |
---|
2020 | Â Â Â Â |
---|
2021 |   def PrintSampleParmsSig(Sample,sampleSig): |
---|
2022 | Â Â Â Â ptlbls =Â ' names :' |
---|
2023 | Â Â Â Â ptstr =Â ' values:' |
---|
2024 |     sigstr = ' sig  :' |
---|
2025 | Â Â Â Â refine =Â False |
---|
2026 |     if 'Bragg' in Sample['Type']: |
---|
2027 |       for i,item in enumerate(['Scale','Shift','Transparency']): |
---|
2028 | Â Â Â Â Â Â Â Â ptlbls +=Â '%14s'%(item) |
---|
2029 | Â Â Â Â Â Â Â Â ptstr +=Â '%14.4f'%(Sample[item][0]) |
---|
2030 |         if sampleSig[i]: |
---|
2031 | Â Â Â Â Â Â Â Â Â Â refine =Â True |
---|
2032 | Â Â Â Â Â Â Â Â Â Â sigstr +=Â '%14.4f'%(sampleSig[i]) |
---|
2033 | Â Â Â Â Â Â Â Â else: |
---|
2034 | Â Â Â Â Â Â Â Â Â Â sigstr +=Â 14*' ' |
---|
2035 | Â Â Â Â Â Â |
---|
2036 |     elif 'Debye' in Sample['Type']:    #Debye-Scherrer |
---|
2037 |       for i,item in enumerate(['Scale','Absorption','DisplaceX','DisplaceY']): |
---|
2038 | Â Â Â Â Â Â Â Â ptlbls +=Â '%14s'%(item) |
---|
2039 | Â Â Â Â Â Â Â Â ptstr +=Â '%14.4f'%(Sample[item][0]) |
---|
2040 |         if sampleSig[i]: |
---|
2041 | Â Â Â Â Â Â Â Â Â Â refine =Â True |
---|
2042 | Â Â Â Â Â Â Â Â Â Â sigstr +=Â '%14.4f'%(sampleSig[i]) |
---|
2043 | Â Â Â Â Â Â Â Â else: |
---|
2044 | Â Â Â Â Â Â Â Â Â Â sigstr +=Â 14*' ' |
---|
2045 | |
---|
2046 |     if refine: |
---|
2047 |       print >>pFile,'\n Sample Parameters:' |
---|
2048 |       print >>pFile,ptlbls |
---|
2049 |       print >>pFile,ptstr |
---|
2050 |       print >>pFile,sigstr |
---|
2051 | Â Â Â Â |
---|
2052 | Â Â histoList =Â Histograms.keys() |
---|
2053 | Â Â histoList.sort() |
---|
2054 |   for histogram in histoList: |
---|
2055 |     if 'PWDR' in histogram: |
---|
2056 | Â Â Â Â Â Â Histogram =Â Histograms[histogram] |
---|
2057 | Â Â Â Â Â Â hId =Â Histogram['hId'] |
---|
2058 | Â Â Â Â Â Â pfx =Â ':'+str(hId)+':' |
---|
2059 | Â Â Â Â Â Â Background =Â Histogram['Background'] |
---|
2060 | Â Â Â Â Â Â backSig =Â SetBackgroundParms(pfx,Background,parmDict,sigDict) |
---|
2061 | Â Â Â Â Â Â |
---|
2062 | Â Â Â Â Â Â Inst =Â Histogram['Instrument Parameters'][0] |
---|
2063 | Â Â Â Â Â Â instSig =Â SetInstParms(pfx,Inst,parmDict,sigDict) |
---|
2064 | Â Â Â Â |
---|
2065 | Â Â Â Â Â Â Sample =Â Histogram['Sample Parameters'] |
---|
2066 | Â Â Â Â Â Â sampSig =Â SetSampleParms(pfx,Sample,parmDict,sigDict) |
---|
2067 | |
---|
2068 |       print >>pFile,'\n Histogram: ',histogram,' histogram Id: ',hId |
---|
2069 |       print >>pFile,135*'-' |
---|
2070 |       print >>pFile,' Final refinement wR = %.2f%% on %d observations in this histogram'%(Histogram['wR'],Histogram['Nobs']) |
---|
2071 |       print >>pFile,' PWDR histogram weight factor = '+'%.3f'%(Histogram['wtFactor']) |
---|
2072 |       if Print: |
---|
2073 |         print >>pFile,' Instrument type: ',Sample['Type'] |
---|
2074 | Â Â Â Â Â Â Â Â PrintSampleParmsSig(Sample,sampSig) |
---|
2075 | Â Â Â Â Â Â Â Â PrintInstParmsSig(Inst,instSig) |
---|
2076 | Â Â Â Â Â Â Â Â PrintBackgroundSig(Background,backSig) |
---|
2077 | Â Â Â Â Â Â Â Â |
---|
2078 | ################################################################################ |
---|
2079 | ##### Penalty & restraint functions |
---|
2080 | ################################################################################ |
---|
2081 | |
---|
2082 | def penaltyFxn(HistoPhases,parmDict,varyList): |
---|
2083 | Â Â Histograms,Phases,restraintDict =Â HistoPhases |
---|
2084 | Â Â pNames =Â [] |
---|
2085 | Â Â pVals =Â [] |
---|
2086 | Â Â pWt =Â [] |
---|
2087 | Â Â negWt =Â {} |
---|
2088 |   for phase in Phases: |
---|
2089 | Â Â Â Â pId =Â Phases[phase]['pId'] |
---|
2090 | Â Â Â Â negWt[pId]Â =Â Phases[phase]['General']['Pawley neg wt'] |
---|
2091 | Â Â Â Â General =Â Phases[phase]['General'] |
---|
2092 | Â Â Â Â textureData =Â General['SH Texture'] |
---|
2093 | Â Â Â Â SGData =Â General['SGData'] |
---|
2094 | Â Â Â Â AtLookup =Â G2mth.FillAtomLookUp(Phases[phase]['Atoms']) |
---|
2095 | Â Â Â Â cell =Â General['Cell'][1:7] |
---|
2096 | Â Â Â Â Amat,Bmat =Â G2lat.cell2AB(cell) |
---|
2097 |     if phase not in restraintDict: |
---|
2098 | Â Â Â Â Â Â continue |
---|
2099 | Â Â Â Â phaseRest =Â restraintDict[phase] |
---|
2100 | Â Â Â Â names =Â [['Bond','Bonds'],['Angle','Angles'],['Plane','Planes'], |
---|
2101 | Â Â Â Â Â Â ['Chiral','Volumes'],['Torsion','Torsions'],['Rama','Ramas'], |
---|
2102 | Â Â Â Â Â Â ['ChemComp','Sites'],['Texture','HKLs']] |
---|
2103 |     for name,rest in names: |
---|
2104 | Â Â Â Â Â Â itemRest =Â phaseRest[name] |
---|
2105 |       if itemRest[rest] and itemRest['Use']: |
---|
2106 | Â Â Â Â Â Â Â Â wt =Â itemRest['wtFactor'] |
---|
2107 |         if name in ['Bond','Angle','Plane','Chiral']: |
---|
2108 |           for i,[indx,ops,obs,esd] in enumerate(itemRest[rest]): |
---|
2109 | Â Â Â Â Â Â Â Â Â Â Â Â pNames.append(str(pId)+':'+name+':'+str(i)) |
---|
2110 | Â Â Â Â Â Â Â Â Â Â Â Â XYZ =Â np.array(G2mth.GetAtomCoordsByID(pId,parmDict,AtLookup,indx)) |
---|
2111 | Â Â Â Â Â Â Â Â Â Â Â Â XYZ =Â G2mth.getSyXYZ(XYZ,ops,SGData) |
---|
2112 |             if name == 'Bond': |
---|
2113 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â calc =Â G2mth.getRestDist(XYZ,Amat) |
---|
2114 |             elif name == 'Angle': |
---|
2115 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â calc =Â G2mth.getRestAngle(XYZ,Amat) |
---|
2116 |             elif name == 'Plane': |
---|
2117 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â calc =Â G2mth.getRestPlane(XYZ,Amat) |
---|
2118 |             elif name == 'Chiral': |
---|
2119 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â calc =Â G2mth.getRestChiral(XYZ,Amat) |
---|
2120 | Â Â Â Â Â Â Â Â Â Â Â Â pVals.append(obs-calc) |
---|
2121 | Â Â Â Â Â Â Â Â Â Â Â Â pWt.append(wt/esd**2) |
---|
2122 |         elif name in ['Torsion','Rama']: |
---|
2123 | Â Â Â Â Â Â Â Â Â Â coeffDict =Â itemRest['Coeff'] |
---|
2124 |           for i,[indx,ops,cofName,esd] in enumerate(torsionList): |
---|
2125 | Â Â Â Â Â Â Â Â Â Â Â Â pNames.append(str(pId)+':'+name+':'+str(i)) |
---|
2126 | Â Â Â Â Â Â Â Â Â Â Â Â XYZ =Â np.array(G2mth.GetAtomCoordsByID(pId,parmDict,AtLookup,indx)) |
---|
2127 | Â Â Â Â Â Â Â Â Â Â Â Â XYZ =Â G2mth.getSyXYZ(XYZ,ops,SGData) |
---|
2128 |             if name == 'Torsion': |
---|
2129 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â tor =Â G2mth.getRestTorsion(XYZ,Amat) |
---|
2130 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â restr,calc =Â G2mth.calcTorsionEnergy(tor,coeffDict[cofName]) |
---|
2131 | Â Â Â Â Â Â Â Â Â Â Â Â else: |
---|
2132 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â phi,psi =Â G2mth.getRestRama(XYZ,Amat) |
---|
2133 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â restr,calc =Â G2mth.calcRamaEnergy(phi,psi,coeffDict[cofName])Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â |
---|
2134 | Â Â Â Â Â Â Â Â Â Â Â Â pVals.append(obs-calc) |
---|
2135 | Â Â Â Â Â Â Â Â Â Â Â Â pWt.append(wt/esd**2) |
---|
2136 |         elif name == 'ChemComp': |
---|
2137 |           for i,[indx,factors,obs,esd] in enumerate(itemRest[rest]): |
---|
2138 | Â Â Â Â Â Â Â Â Â Â Â Â pNames.append(str(pId)+':'+name+':'+str(i)) |
---|
2139 | Â Â Â Â Â Â Â Â Â Â Â Â mul =Â np.array(G2mth.GetAtomItemsById(Atoms,AtLookUp,indx,cs+1)) |
---|
2140 | Â Â Â Â Â Â Â Â Â Â Â Â frac =Â np.array(G2mth.GetAtomItemsById(Atoms,AtLookUp,indx,cs-1)) |
---|
2141 | Â Â Â Â Â Â Â Â Â Â Â Â calc =Â np.sum(mul*frac*factors) |
---|
2142 | Â Â Â Â Â Â Â Â Â Â Â Â pVals.append(obs-calc) |
---|
2143 | Â Â Â Â Â Â Â Â Â Â Â Â pWt.append(wt/esd**2)Â Â Â Â Â Â Â Â Â Â |
---|
2144 |         elif name == 'Texture': |
---|
2145 | Â Â Â Â Â Â Â Â Â Â SHkeys =Â textureData['SH Coeff'][1].keys() |
---|
2146 | Â Â Â Â Â Â Â Â Â Â SHCoef =Â G2mth.GetSHCoeff(pId,parmDict,SHkeys) |
---|
2147 | Â Â Â Â Â Â Â Â Â Â shModels =Â ['cylindrical','none','shear - 2/m','rolling - mmm'] |
---|
2148 | Â Â Â Â Â Â Â Â Â Â SamSym =Â dict(zip(shModels,['0','-1','2/m','mmm'])) |
---|
2149 |           for i,[hkl,grid,esd1,ifesd2,esd2] in enumerate(itemRest[rest]): |
---|
2150 | Â Â Â Â Â Â Â Â Â Â Â Â PH =Â np.array(hkl) |
---|
2151 | Â Â Â Â Â Â Â Â Â Â Â Â phi,beta =Â G2lat.CrsAng(np.array(hkl),cell,SGData) |
---|
2152 | Â Â Â Â Â Â Â Â Â Â Â Â ODFln =Â G2lat.Flnh(False,SHCoef,phi,beta,SGData) |
---|
2153 | Â Â Â Â Â Â Â Â Â Â Â Â R,P,Z =Â G2mth.getRestPolefig(ODFln,SamSym[textureData['Model']],grid) |
---|
2154 | Â Â Â Â Â Â Â Â Â Â Â Â Z1 =Â -ma.masked_greater(Z,0.0) |
---|
2155 | Â Â Â Â Â Â Â Â Â Â Â Â IndZ1 =Â np.array(ma.nonzero(Z1)) |
---|
2156 |             for ind in IndZ1.T: |
---|
2157 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â pNames.append('%d:%s:%d:%.2f:%.2f'%(pId,name,i,R[ind[0],ind[1]],P[ind[0],ind[1]])) |
---|
2158 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â pVals.append(Z1[ind[0]][ind[1]]) |
---|
2159 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â pWt.append(wt/esd1**2) |
---|
2160 |             if ifesd2: |
---|
2161 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Z2 =Â 1.-Z |
---|
2162 |               for ind in np.ndindex(grid,grid): |
---|
2163 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â pNames.append('%d:%s:%d:%.2f:%.2f'%(pId,name+'-unit',i,R[ind[0],ind[1]],P[ind[0],ind[1]])) |
---|
2164 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â pVals.append(Z1[ind[0]][ind[1]]) |
---|
2165 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â pWt.append(wt/esd2**2) |
---|
2166 | Â Â Â Â Â |
---|
2167 |   for item in varyList: |
---|
2168 |     if 'PWLref' in item and parmDict[item] < 0.: |
---|
2169 | Â Â Â Â Â Â pId =Â int(item.split(':')[0]) |
---|
2170 |       if negWt[pId]: |
---|
2171 | Â Â Â Â Â Â Â Â pNames.append(item) |
---|
2172 | Â Â Â Â Â Â Â Â pVals.append(-parmDict[item]) |
---|
2173 | Â Â Â Â Â Â Â Â pWt.append(negWt[pId]) |
---|
2174 | Â Â pVals =Â np.array(pVals) |
---|
2175 | Â Â pWt =Â np.array(pWt)Â Â Â Â Â #should this be np.sqrt? |
---|
2176 |   return pNames,pVals,pWt |
---|
2177 | Â Â |
---|
2178 | def penaltyDeriv(pNames,pVal,HistoPhases,parmDict,varyList): |
---|
2179 | Â Â Histograms,Phases,restraintDict =Â HistoPhases |
---|
2180 | Â Â pDerv =Â np.zeros((len(varyList),len(pVal))) |
---|
2181 |   for phase in Phases: |
---|
2182 |     if phase not in restraintDict: |
---|
2183 | Â Â Â Â Â Â continue |
---|
2184 | Â Â Â Â pId =Â Phases[phase]['pId'] |
---|
2185 | Â Â Â Â General =Â Phases[phase]['General'] |
---|
2186 | Â Â Â Â SGData =Â General['SGData'] |
---|
2187 | Â Â Â Â AtLookup =Â G2mth.FillAtomLookUp(Phases[phase]['Atoms']) |
---|
2188 | Â Â Â Â cell =Â General['Cell'][1:7] |
---|
2189 | Â Â Â Â Amat,Bmat =Â G2lat.cell2AB(cell) |
---|
2190 | Â Â Â Â textureData =Â General['SH Texture'] |
---|
2191 | |
---|
2192 | Â Â Â Â SHkeys =Â textureData['SH Coeff'][1].keys() |
---|
2193 | Â Â Â Â SHCoef =Â G2mth.GetSHCoeff(pId,parmDict,SHkeys) |
---|
2194 | Â Â Â Â shModels =Â ['cylindrical','none','shear - 2/m','rolling - mmm'] |
---|
2195 | Â Â Â Â SamSym =Â dict(zip(shModels,['0','-1','2/m','mmm'])) |
---|
2196 | Â Â Â Â sam =Â SamSym[textureData['Model']] |
---|
2197 | Â Â Â Â phaseRest =Â restraintDict[phase] |
---|
2198 | Â Â Â Â names =Â {'Bond':'Bonds','Angle':'Angles','Plane':'Planes', |
---|
2199 | Â Â Â Â Â Â 'Chiral':'Volumes','Torsion':'Torsions','Rama':'Ramas', |
---|
2200 | Â Â Â Â Â Â 'ChemComp':'Sites','Texture':'HKLs'} |
---|
2201 | Â Â Â Â lasthkl =Â np.array([0,0,0]) |
---|
2202 |     for ip,pName in enumerate(pNames): |
---|
2203 | Â Â Â Â Â Â pnames =Â pName.split(':') |
---|
2204 |       if pId == int(pnames[0]): |
---|
2205 | Â Â Â Â Â Â Â Â name =Â pnames[1] |
---|
2206 |         if not name:    #empty for Pawley restraints; pName has '::' in it |
---|
2207 | Â Â Â Â Â Â Â Â Â Â pDerv[varyList.index(pName)][ip]Â +=Â 1. |
---|
2208 | Â Â Â Â Â Â Â Â Â Â continue |
---|
2209 |         id = int(pnames[2]) |
---|
2210 | Â Â Â Â Â Â Â Â itemRest =Â phaseRest[name] |
---|
2211 |         if name in ['Bond','Angle','Plane','Chiral']: |
---|
2212 | Â Â Â Â Â Â Â Â Â Â indx,ops,obs,esd =Â itemRest[names[name]][id] |
---|
2213 | Â Â Â Â Â Â Â Â Â Â dNames =Â [] |
---|
2214 |           for ind in indx: |
---|
2215 |             dNames += [str(pId)+'::dA'+Xname+':'+str(AtLookup[ind]) for Xname in ['x','y','z']] |
---|
2216 | Â Â Â Â Â Â Â Â Â Â XYZ =Â np.array(G2mth.GetAtomCoordsByID(pId,parmDict,AtLookup,indx)) |
---|
2217 |           if name == 'Bond': |
---|
2218 | Â Â Â Â Â Â Â Â Â Â Â Â deriv =Â G2mth.getRestDeriv(G2mth.getRestDist,XYZ,Amat,ops,SGData) |
---|
2219 |           elif name == 'Angle': |
---|
2220 | Â Â Â Â Â Â Â Â Â Â Â Â deriv =Â G2mth.getRestDeriv(G2mth.getRestAngle,XYZ,Amat,ops,SGData) |
---|
2221 |           elif name == 'Plane': |
---|
2222 | Â Â Â Â Â Â Â Â Â Â Â Â deriv =Â G2mth.getRestDeriv(G2mth.getRestPlane,XYZ,Amat,ops,SGData) |
---|
2223 |           elif name == 'Chiral': |
---|
2224 | Â Â Â Â Â Â Â Â Â Â Â Â deriv =Â G2mth.getRestDeriv(G2mth.getRestChiral,XYZ,Amat,ops,SGData) |
---|
2225 |         elif name in ['Torsion','Rama']: |
---|
2226 | Â Â Â Â Â Â Â Â Â Â coffDict =Â itemRest['Coeff'] |
---|
2227 | Â Â Â Â Â Â Â Â Â Â indx,ops,cofName,esd =Â itemRest[names[name]][id] |
---|
2228 | Â Â Â Â Â Â Â Â Â Â dNames =Â [] |
---|
2229 |           for ind in indx: |
---|
2230 |             dNames += [str(pId)+'::dA'+Xname+':'+str(AtLookup[ind]) for Xname in ['x','y','z']] |
---|
2231 | Â Â Â Â Â Â Â Â Â Â XYZ =Â np.array(G2mth.GetAtomCoordsByID(pId,parmDict,AtLookup,indx)) |
---|
2232 |           if name == 'Torsion': |
---|
2233 | Â Â Â Â Â Â Â Â Â Â Â Â deriv =Â G2mth.getTorsionDeriv(XYZ,Amat,coffDict[cofName]) |
---|
2234 | Â Â Â Â Â Â Â Â Â Â else: |
---|
2235 | Â Â Â Â Â Â Â Â Â Â Â Â deriv =Â G2mth.getRamaDeriv(XYZ,Amat,coffDict[cofName]) |
---|
2236 |         elif name == 'ChemComp': |
---|
2237 | Â Â Â Â Â Â Â Â Â Â indx,factors,obs,esd =Â itemRest[names[name]][id] |
---|
2238 | Â Â Â Â Â Â Â Â Â Â dNames =Â [] |
---|
2239 |           for ind in indx: |
---|
2240 | Â Â Â Â Â Â Â Â Â Â Â Â dNames +=Â [str(pId)+'::Afrac:'+str(AtLookup[ind])] |
---|
2241 | Â Â Â Â Â Â Â Â Â Â Â Â mul =Â np.array(G2mth.GetAtomItemsById(Atoms,AtLookUp,indx,cs+1)) |
---|
2242 | Â Â Â Â Â Â Â Â Â Â Â Â deriv =Â mul*factors |
---|
2243 |         elif 'Texture' in name: |
---|
2244 | Â Â Â Â Â Â Â Â Â Â deriv =Â [] |
---|
2245 | Â Â Â Â Â Â Â Â Â Â dNames =Â [] |
---|
2246 | Â Â Â Â Â Â Â Â Â Â hkl,grid,esd1,ifesd2,esd2 =Â itemRest[names[name]][id] |
---|
2247 | Â Â Â Â Â Â Â Â Â Â hkl =Â np.array(hkl) |
---|
2248 |           if np.any(lasthkl-hkl): |
---|
2249 | Â Â Â Â Â Â Â Â Â Â Â Â PH =Â np.array(hkl) |
---|
2250 | Â Â Â Â Â Â Â Â Â Â Â Â phi,beta =Â G2lat.CrsAng(np.array(hkl),cell,SGData) |
---|
2251 | Â Â Â Â Â Â Â Â Â Â Â Â ODFln =Â G2lat.Flnh(False,SHCoef,phi,beta,SGData) |
---|
2252 | Â Â Â Â Â Â Â Â Â Â Â Â lasthkl =Â copy.copy(hkl)Â Â Â Â Â Â Â Â Â Â Â Â |
---|
2253 |           if 'unit' in name: |
---|
2254 | Â Â Â Â Â Â Â Â Â Â Â Â pass |
---|
2255 | Â Â Â Â Â Â Â Â Â Â else: |
---|
2256 | Â Â Â Â Â Â Â Â Â Â Â Â gam =Â float(pnames[3]) |
---|
2257 | Â Â Â Â Â Â Â Â Â Â Â Â psi =Â float(pnames[4]) |
---|
2258 |             for SHname in ODFln: |
---|
2259 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â l,m,n =Â eval(SHname[1:]) |
---|
2260 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Ksl =Â G2lat.GetKsl(l,m,sam,psi,gam)[0] |
---|
2261 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â dNames +=Â [str(pId)+'::'+SHname] |
---|
2262 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â deriv.append(-ODFln[SHname][0]*Ksl/SHCoef[SHname]) |
---|
2263 |         for dName,drv in zip(dNames,deriv): |
---|
2264 | Â Â Â Â Â Â Â Â Â Â try: |
---|
2265 | Â Â Â Â Â Â Â Â Â Â Â Â ind =Â varyList.index(dName) |
---|
2266 | Â Â Â Â Â Â Â Â Â Â Â Â pDerv[ind][ip]Â +=Â drv |
---|
2267 |           except ValueError: |
---|
2268 | Â Â Â Â Â Â Â Â Â Â Â Â pass |
---|
2269 |   return pDerv |
---|
2270 | |
---|
2271 | ################################################################################ |
---|
2272 | ##### Function & derivative calculations |
---|
2273 | ################################################################################Â Â Â Â |
---|
2274 | Â Â Â Â Â Â Â Â Â Â |
---|
2275 | def GetAtomFXU(pfx,calcControls,parmDict): |
---|
2276 | Â Â Natoms =Â calcControls['Natoms'][pfx] |
---|
2277 | Â Â Tdata =Â Natoms*[' ',] |
---|
2278 | Â Â Mdata =Â np.zeros(Natoms) |
---|
2279 | Â Â IAdata =Â Natoms*[' ',] |
---|
2280 | Â Â Fdata =Â np.zeros(Natoms) |
---|
2281 | Â Â FFdata =Â [] |
---|
2282 | Â Â BLdata =Â [] |
---|
2283 | Â Â Xdata =Â np.zeros((3,Natoms)) |
---|
2284 | Â Â dXdata =Â np.zeros((3,Natoms)) |
---|
2285 | Â Â Uisodata =Â np.zeros(Natoms) |
---|
2286 | Â Â Uijdata =Â np.zeros((6,Natoms)) |
---|
2287 | Â Â keys =Â {'Atype:':Tdata,'Amul:':Mdata,'Afrac:':Fdata,'AI/A:':IAdata, |
---|
2288 | Â Â Â Â 'dAx:':dXdata[0],'dAy:':dXdata[1],'dAz:':dXdata[2], |
---|
2289 | Â Â Â Â 'Ax:':Xdata[0],'Ay:':Xdata[1],'Az:':Xdata[2],'AUiso:':Uisodata, |
---|
2290 | Â Â Â Â 'AU11:':Uijdata[0],'AU22:':Uijdata[1],'AU33:':Uijdata[2], |
---|
2291 | Â Â Â Â 'AU12:':Uijdata[3],'AU13:':Uijdata[4],'AU23:':Uijdata[5]} |
---|
2292 |   for iatm in range(Natoms): |
---|
2293 |     for key in keys: |
---|
2294 | Â Â Â Â Â Â parm =Â pfx+key+str(iatm) |
---|
2295 |       if parm in parmDict: |
---|
2296 | Â Â Â Â Â Â Â Â keys[key][iatm]Â =Â parmDict[parm] |
---|
2297 |   return Tdata,Mdata,Fdata,Xdata,dXdata,IAdata,Uisodata,Uijdata |
---|
2298 | Â Â |
---|
2299 | def getFFvalues(FFtables,SQ): |
---|
2300 | Â Â FFvals =Â {} |
---|
2301 |   for El in FFtables: |
---|
2302 | Â Â Â Â FFvals[El]Â =Â G2el.ScatFac(FFtables[El],SQ)[0] |
---|
2303 |   return FFvals |
---|
2304 | Â Â |
---|
2305 | def getBLvalues(BLtables): |
---|
2306 | Â Â BLvals =Â {} |
---|
2307 |   for El in BLtables: |
---|
2308 | Â Â Â Â BLvals[El]Â =Â BLtables[El][1][1] |
---|
2309 |   return BLvals |
---|
2310 | Â Â Â Â |
---|
2311 | def StructureFactor(refList,G,hfx,pfx,SGData,calcControls,parmDict): |
---|
2312 | Â Â ''' Compute structure factors for all h,k,l for phase |
---|
2313 | Â Â input: |
---|
2314 | Â Â Â Â refList: [ref] where each ref = h,k,l,m,d,...,[equiv h,k,l],phase[equiv] |
---|
2315 | Â Â Â Â G:Â Â Â reciprocal metric tensor |
---|
2316 | Â Â Â Â pfx:Â Â phase id string |
---|
2317 | Â Â Â Â SGData: space group info. dictionary output from SpcGroup |
---|
2318 | Â Â Â Â calcControls: |
---|
2319 | Â Â Â Â ParmDict: |
---|
2320 | Â Â puts result F^2 in each ref[8] in refList |
---|
2321 | Â Â '''Â Â Â Â |
---|
2322 | Â Â twopi =Â 2.0*np.pi |
---|
2323 | Â Â twopisq =Â 2.0*np.pi**2 |
---|
2324 | Â Â phfx =Â pfx.split(':')[0]+hfx |
---|
2325 | Â Â ast =Â np.sqrt(np.diag(G)) |
---|
2326 | Â Â Mast =Â twopisq*np.multiply.outer(ast,ast) |
---|
2327 | Â Â FFtables =Â calcControls['FFtables'] |
---|
2328 | Â Â BLtables =Â calcControls['BLtables'] |
---|
2329 | Â Â Tdata,Mdata,Fdata,Xdata,dXdata,IAdata,Uisodata,Uijdata =Â GetAtomFXU(pfx,calcControls,parmDict) |
---|
2330 | Â Â FF =Â np.zeros(len(Tdata)) |
---|
2331 |   if 'N' in parmDict[hfx+'Type']: |
---|
2332 | Â Â Â Â FP,FPP =Â G2el.BlenRes(Tdata,BLtables,parmDict[hfx+'Lam']) |
---|
2333 | Â Â else: |
---|
2334 |     FP = np.array([FFtables[El][hfx+'FP'] for El in Tdata]) |
---|
2335 |     FPP = np.array([FFtables[El][hfx+'FPP'] for El in Tdata]) |
---|
2336 | Â Â maxPos =Â len(SGData['SGOps']) |
---|
2337 | Â Â Uij =Â np.array(G2lat.U6toUij(Uijdata)) |
---|
2338 | Â Â bij =Â Mast*Uij.T |
---|
2339 |   for refl in refList: |
---|
2340 | Â Â Â Â fbs =Â np.array([0,0]) |
---|
2341 | Â Â Â Â H =Â refl[:3] |
---|
2342 | Â Â Â Â SQ =Â 1./(2.*refl[4])**2 |
---|
2343 | Â Â Â Â SQfactor =Â 4.0*SQ*twopisq |
---|
2344 | Â Â Â Â Bab =Â parmDict[phfx+'BabA']*np.exp(-parmDict[phfx+'BabU']*SQfactor) |
---|
2345 |     if not len(refl[-1]):        #no form factors |
---|
2346 |       if 'N' in parmDict[hfx+'Type']: |
---|
2347 | Â Â Â Â Â Â Â Â refl[-1]Â =Â getBLvalues(BLtables) |
---|
2348 | Â Â Â Â Â Â else:Â Â Â Â #'X' |
---|
2349 | Â Â Â Â Â Â Â Â refl[-1]Â =Â getFFvalues(FFtables,SQ) |
---|
2350 |     for i,El in enumerate(Tdata): |
---|
2351 | Â Â Â Â Â Â FF[i]Â =Â refl[-1][El]Â Â Â Â Â Â |
---|
2352 | Â Â Â Â Uniq =Â refl[11] |
---|
2353 | Â Â Â Â phi =Â refl[12] |
---|
2354 | Â Â Â Â phase =Â twopi*(np.inner(Uniq,(dXdata.T+Xdata.T))+phi[:,np.newaxis]) |
---|
2355 | Â Â Â Â sinp =Â np.sin(phase) |
---|
2356 | Â Â Â Â cosp =Â np.cos(phase) |
---|
2357 | Â Â Â Â occ =Â Mdata*Fdata/len(Uniq) |
---|
2358 | Â Â Â Â biso =Â -SQfactor*Uisodata |
---|
2359 | Â Â Â Â Tiso =Â np.where(biso<1.,np.exp(biso),1.0) |
---|
2360 |     HbH = np.array([-np.inner(h,np.inner(bij,h)) for h in Uniq]) |
---|
2361 | Â Â Â Â Tuij =Â np.where(HbH<1.,np.exp(HbH),1.0) |
---|
2362 | Â Â Â Â Tcorr =Â Tiso*Tuij |
---|
2363 | Â Â Â Â fa =Â np.array([(FF+FP-Bab)*occ*cosp*Tcorr,-FPP*occ*sinp*Tcorr]) |
---|
2364 | Â Â Â Â fas =Â np.sum(np.sum(fa,axis=1),axis=1)Â Â Â Â #real |
---|
2365 |     if not SGData['SGInv']: |
---|
2366 | Â Â Â Â Â Â fb =Â np.array([(FF+FP-Bab)*occ*sinp*Tcorr,FPP*occ*cosp*Tcorr]) |
---|
2367 | Â Â Â Â Â Â fbs =Â np.sum(np.sum(fb,axis=1),axis=1) |
---|
2368 | Â Â Â Â fasq =Â fas**2 |
---|
2369 | Â Â Â Â fbsq =Â fbs**2Â Â Â Â #imaginary |
---|
2370 | Â Â Â Â refl[9]Â =Â np.sum(fasq)+np.sum(fbsq) |
---|
2371 | Â Â Â Â refl[10]Â =Â atan2d(fbs[0],fas[0]) |
---|
2372 |   return refList |
---|
2373 | Â Â |
---|
2374 | def StructureFactorDerv(refList,G,hfx,pfx,SGData,calcControls,parmDict): |
---|
2375 | Â Â twopi =Â 2.0*np.pi |
---|
2376 | Â Â twopisq =Â 2.0*np.pi**2 |
---|
2377 | Â Â phfx =Â pfx.split(':')[0]+hfx |
---|
2378 | Â Â ast =Â np.sqrt(np.diag(G)) |
---|
2379 | Â Â Mast =Â twopisq*np.multiply.outer(ast,ast) |
---|
2380 | Â Â FFtables =Â calcControls['FFtables'] |
---|
2381 | Â Â BLtables =Â calcControls['BLtables'] |
---|
2382 | Â Â Tdata,Mdata,Fdata,Xdata,dXdata,IAdata,Uisodata,Uijdata =Â GetAtomFXU(pfx,calcControls,parmDict) |
---|
2383 | Â Â FF =Â np.zeros(len(Tdata)) |
---|
2384 |   if 'N' in parmDict[hfx+'Type']: |
---|
2385 | Â Â Â Â FP =Â 0. |
---|
2386 | Â Â Â Â FPP =Â 0. |
---|
2387 | Â Â else: |
---|
2388 |     FP = np.array([FFtables[El][hfx+'FP'] for El in Tdata]) |
---|
2389 |     FPP = np.array([FFtables[El][hfx+'FPP'] for El in Tdata]) |
---|
2390 | Â Â maxPos =Â len(SGData['SGOps'])Â Â Â Â |
---|
2391 | Â Â Uij =Â np.array(G2lat.U6toUij(Uijdata)) |
---|
2392 | Â Â bij =Â Mast*Uij.T |
---|
2393 | Â Â dFdvDict =Â {} |
---|
2394 | Â Â dFdfr =Â np.zeros((len(refList),len(Mdata))) |
---|
2395 | Â Â dFdx =Â np.zeros((len(refList),len(Mdata),3)) |
---|
2396 | Â Â dFdui =Â np.zeros((len(refList),len(Mdata))) |
---|
2397 | Â Â dFdua =Â np.zeros((len(refList),len(Mdata),6)) |
---|
2398 | Â Â dFdbab =Â np.zeros((len(refList),2)) |
---|
2399 |   for iref,refl in enumerate(refList): |
---|
2400 | Â Â Â Â H =Â np.array(refl[:3]) |
---|
2401 | Â Â Â Â SQ =Â 1./(2.*refl[4])**2Â Â Â Â Â Â Â # or (sin(theta)/lambda)**2 |
---|
2402 | Â Â Â Â SQfactor =Â 8.0*SQ*np.pi**2 |
---|
2403 | Â Â Â Â dBabdA =Â np.exp(-parmDict[phfx+'BabU']*SQfactor) |
---|
2404 | Â Â Â Â Bab =Â parmDict[phfx+'BabA']*dBabdA |
---|
2405 |     for i,El in enumerate(Tdata):      |
---|
2406 | Â Â Â Â Â Â FF[i]Â =Â refl[-1][El]Â Â Â Â Â Â |
---|
2407 | Â Â Â Â Uniq =Â refl[11] |
---|
2408 | Â Â Â Â phi =Â refl[12] |
---|
2409 | Â Â Â Â phase =Â twopi*(np.inner((dXdata.T+Xdata.T),Uniq)+phi[np.newaxis,:]) |
---|
2410 | Â Â Â Â sinp =Â np.sin(phase) |
---|
2411 | Â Â Â Â cosp =Â np.cos(phase) |
---|
2412 | Â Â Â Â occ =Â Mdata*Fdata/len(Uniq) |
---|
2413 | Â Â Â Â biso =Â -SQfactor*Uisodata |
---|
2414 | Â Â Â Â Tiso =Â np.where(biso<1.,np.exp(biso),1.0) |
---|
2415 | Â Â Â Â HbH =Â -np.inner(H,np.inner(bij,H)) |
---|
2416 |     Hij = np.array([Mast*np.multiply.outer(U,U) for U in Uniq]) |
---|
2417 |     Hij = np.array([G2lat.UijtoU6(Uij) for Uij in Hij]) |
---|
2418 | Â Â Â Â Tuij =Â np.where(HbH<1.,np.exp(HbH),1.0) |
---|
2419 | Â Â Â Â Tcorr =Â Tiso*Tuij |
---|
2420 | Â Â Â Â fot =Â (FF+FP-Bab)*occ*Tcorr |
---|
2421 | Â Â Â Â fotp =Â FPP*occ*Tcorr |
---|
2422 | Â Â Â Â fa =Â np.array([fot[:,np.newaxis]*cosp,fotp[:,np.newaxis]*cosp])Â Â Â Â #non positions |
---|
2423 | Â Â Â Â fb =Â np.array([fot[:,np.newaxis]*sinp,-fotp[:,np.newaxis]*sinp]) |
---|
2424 | Â Â Â Â |
---|
2425 | Â Â Â Â fas =Â np.sum(np.sum(fa,axis=1),axis=1) |
---|
2426 | Â Â Â Â fbs =Â np.sum(np.sum(fb,axis=1),axis=1) |
---|
2427 | Â Â Â Â fax =Â np.array([-fot[:,np.newaxis]*sinp,-fotp[:,np.newaxis]*sinp])Â Â #positions |
---|
2428 | Â Â Â Â fbx =Â np.array([fot[:,np.newaxis]*cosp,-fot[:,np.newaxis]*cosp]) |
---|
2429 | Â Â Â Â #sum below is over Uniq |
---|
2430 | Â Â Â Â dfadfr =Â np.sum(fa/occ[:,np.newaxis],axis=2) |
---|
2431 | Â Â Â Â dfadx =Â np.sum(twopi*Uniq*fax[:,:,:,np.newaxis],axis=2) |
---|
2432 | Â Â Â Â dfadui =Â np.sum(-SQfactor*fa,axis=2) |
---|
2433 | Â Â Â Â dfadua =Â np.sum(-Hij*fa[:,:,:,np.newaxis],axis=2) |
---|
2434 | Â Â Â Â dfadba =Â np.sum(-cosp*(occ*Tcorr)[:,np.newaxis],axis=1) |
---|
2435 |     #NB: the above have been checked against PA(1:10,1:2) in strfctr.for   |
---|
2436 | Â Â Â Â dFdfr[iref]Â =Â 2.*(fas[0]*dfadfr[0]+fas[1]*dfadfr[1])*Mdata/len(Uniq) |
---|
2437 | Â Â Â Â dFdx[iref]Â =Â 2.*(fas[0]*dfadx[0]+fas[1]*dfadx[1]) |
---|
2438 | Â Â Â Â dFdui[iref]Â =Â 2.*(fas[0]*dfadui[0]+fas[1]*dfadui[1]) |
---|
2439 | Â Â Â Â dFdua[iref]Â =Â 2.*(fas[0]*dfadua[0]+fas[1]*dfadua[1]) |
---|
2440 | Â Â Â Â dFdbab[iref]Â =Â np.array([np.sum(dfadba*dBabdA),np.sum(-dfadba*parmDict[phfx+'BabA']*SQfactor*dBabdA)]).T |
---|
2441 |     if not SGData['SGInv']: |
---|
2442 | Â Â Â Â Â Â dfbdfr =Â np.sum(fb/occ[:,np.newaxis],axis=2)Â Â Â Â #problem here if occ=0 for some atom |
---|
2443 | Â Â Â Â Â Â dfbdx =Â np.sum(twopi*Uniq*fbx[:,:,:,np.newaxis],axis=2)Â Â Â Â Â |
---|
2444 | Â Â Â Â Â Â dfbdui =Â np.sum(-SQfactor*fb,axis=2) |
---|
2445 | Â Â Â Â Â Â dfbdua =Â np.sum(-Hij*fb[:,:,:,np.newaxis],axis=2) |
---|
2446 | Â Â Â Â Â Â dfbdba =Â np.sum(-sinp*(occ*Tcorr)[:,np.newaxis],axis=1) |
---|
2447 | Â Â Â Â Â Â dFdfr[iref]Â +=Â 2.*(fbs[0]*dfbdfr[0]-fbs[1]*dfbdfr[1])*Mdata/len(Uniq) |
---|
2448 | Â Â Â Â Â Â dFdx[iref]Â +=Â 2.*(fbs[0]*dfbdx[0]+fbs[1]*dfbdx[1]) |
---|
2449 | Â Â Â Â Â Â dFdui[iref]Â +=Â 2.*(fbs[0]*dfbdui[0]-fbs[1]*dfbdui[1]) |
---|
2450 | Â Â Â Â Â Â dFdua[iref]Â +=Â 2.*(fbs[0]*dfbdua[0]+fbs[1]*dfbdua[1]) |
---|
2451 | Â Â Â Â Â Â dFdbab[iref]Â +=Â np.array([np.sum(dfbdba*dBabdA),np.sum(-dfbdba*parmDict[phfx+'BabA']*SQfactor*dBabdA)]).T |
---|
2452 | Â Â Â Â #loop over atoms - each dict entry is list of derivatives for all the reflections |
---|
2453 |   for i in range(len(Mdata)):   |
---|
2454 | Â Â Â Â dFdvDict[pfx+'Afrac:'+str(i)]Â =Â dFdfr.T[i] |
---|
2455 | Â Â Â Â dFdvDict[pfx+'dAx:'+str(i)]Â =Â dFdx.T[0][i] |
---|
2456 | Â Â Â Â dFdvDict[pfx+'dAy:'+str(i)]Â =Â dFdx.T[1][i] |
---|
2457 | Â Â Â Â dFdvDict[pfx+'dAz:'+str(i)]Â =Â dFdx.T[2][i] |
---|
2458 | Â Â Â Â dFdvDict[pfx+'AUiso:'+str(i)]Â =Â dFdui.T[i] |
---|
2459 | Â Â Â Â dFdvDict[pfx+'AU11:'+str(i)]Â =Â dFdua.T[0][i] |
---|
2460 | Â Â Â Â dFdvDict[pfx+'AU22:'+str(i)]Â =Â dFdua.T[1][i] |
---|
2461 | Â Â Â Â dFdvDict[pfx+'AU33:'+str(i)]Â =Â dFdua.T[2][i] |
---|
2462 | Â Â Â Â dFdvDict[pfx+'AU12:'+str(i)]Â =Â 2.*dFdua.T[3][i] |
---|
2463 | Â Â Â Â dFdvDict[pfx+'AU13:'+str(i)]Â =Â 2.*dFdua.T[4][i] |
---|
2464 | Â Â Â Â dFdvDict[pfx+'AU23:'+str(i)]Â =Â 2.*dFdua.T[5][i] |
---|
2465 | Â Â Â Â dFdvDict[pfx+'BabA']Â =Â dFdbab.T[0] |
---|
2466 | Â Â Â Â dFdvDict[pfx+'BabU']Â =Â dFdbab.T[1] |
---|
2467 |   return dFdvDict |
---|
2468 | Â Â |
---|
2469 | def SCExtinction(ref,phfx,hfx,pfx,calcControls,parmDict,varyList): |
---|
2470 | Â Â ''' Single crystal extinction function; puts correction in ref[13] and returns |
---|
2471 | Â Â corrections needed for derivatives |
---|
2472 | Â Â ''' |
---|
2473 | Â Â ref[13]Â =Â 1.0 |
---|
2474 | Â Â dervCor =Â 1.0 |
---|
2475 | Â Â dervDict =Â {} |
---|
2476 |   if calcControls[phfx+'EType'] != 'None': |
---|
2477 | Â Â Â Â cos2T =Â 1.0-0.5*(parmDict[hfx+'Lam']/ref[4])**2Â Â Â Â Â #cos(2theta) |
---|
2478 |     if 'SXC' in parmDict[hfx+'Type']: |
---|
2479 | Â Â Â Â Â Â AV =Â 7.9406e5/parmDict[pfx+'Vol']**2 |
---|
2480 | Â Â Â Â Â Â PL =Â np.sqrt(1.0-cos2T**2)/parmDict[hfx+'Lam'] |
---|
2481 | Â Â Â Â Â Â P12 =Â (calcControls[phfx+'Cos2TM']+cos2T**4)/(calcControls[phfx+'Cos2TM']+cos2T**2) |
---|
2482 |     elif 'SNT' in parmDict[hfx+'Type']: |
---|
2483 | Â Â Â Â Â Â AV =Â 1.e7/parmDict[pfx+'Vol']**2 |
---|
2484 | Â Â Â Â Â Â PL =Â 1./(4.*refl[4]**2) |
---|
2485 | Â Â Â Â Â Â P12 =Â 1.0 |
---|
2486 |     elif 'SNC' in parmDict[hfx+'Type']: |
---|
2487 | Â Â Â Â Â Â AV =Â 1.e7/parmDict[pfx+'Vol']**2 |
---|
2488 | Â Â Â Â Â Â PL =Â np.sqrt(1.0-cos2T**2)/parmDict[hfx+'Lam'] |
---|
2489 | Â Â Â Â Â Â P12 =Â 1.0 |
---|
2490 | Â Â Â Â Â Â |
---|
2491 | Â Â Â Â PLZ =Â AV*P12*parmDict[hfx+'Lam']**2*ref[7] |
---|
2492 |     if 'Primary' in calcControls[phfx+'EType']: |
---|
2493 | Â Â Â Â Â Â PLZ *=Â 1.5 |
---|
2494 | Â Â Â Â else: |
---|
2495 | Â Â Â Â Â Â PLZ *=Â calcControls[phfx+'Tbar'] |
---|
2496 | Â Â Â Â Â Â Â Â Â Â Â Â |
---|
2497 |     if 'Primary' in calcControls[phfx+'EType']: |
---|
2498 | Â Â Â Â Â Â PSIG =Â parmDict[phfx+'Ep'] |
---|
2499 |     elif 'I & II' in calcControls[phfx+'EType']: |
---|
2500 | Â Â Â Â Â Â PSIG =Â parmDict[phfx+'Eg']/np.sqrt(1.+(parmDict[phfx+'Es']*PL/parmDict[phfx+'Eg'])**2) |
---|
2501 |     elif 'Type II' in calcControls[phfx+'EType']: |
---|
2502 | Â Â Â Â Â Â PSIG =Â parmDict[phfx+'Es'] |
---|
2503 | Â Â Â Â else:Â Â Â Â # 'Secondary Type I' |
---|
2504 | Â Â Â Â Â Â PSIG =Â parmDict[phfx+'Eg']/PL |
---|
2505 | Â Â Â Â Â Â |
---|
2506 | Â Â Â Â AG =Â 0.58+0.48*cos2T+0.24*cos2T**2 |
---|
2507 | Â Â Â Â AL =Â 0.025+0.285*cos2T |
---|
2508 | Â Â Â Â BG =Â 0.02-0.025*cos2T |
---|
2509 | Â Â Â Â BL =Â 0.15-0.2*(0.75-cos2T)**2 |
---|
2510 |     if cos2T < 0.: |
---|
2511 | Â Â Â Â Â Â BL =Â -0.45*cos2T |
---|
2512 | Â Â Â Â CG =Â 2. |
---|
2513 | Â Â Â Â CL =Â 2. |
---|
2514 | Â Â Â Â PF =Â PLZ*PSIG |
---|
2515 | Â Â Â Â |
---|
2516 |     if 'Gaussian' in calcControls[phfx+'EApprox']: |
---|
2517 | Â Â Â Â Â Â PF4 =Â 1.+CG*PF+AG*PF**2/(1.+BG*PF) |
---|
2518 | Â Â Â Â Â Â extCor =Â np.sqrt(PF4) |
---|
2519 | Â Â Â Â Â Â PF3 =Â 0.5*(CG+2.*AG*PF/(1.+BG*PF)-AG*PF**2*BG/(1.+BG*PF)**2)/(PF4*extCor) |
---|
2520 | Â Â Â Â else: |
---|
2521 | Â Â Â Â Â Â PF4 =Â 1.+CL*PF+AL*PF**2/(1.+BL*PF) |
---|
2522 | Â Â Â Â Â Â extCor =Â np.sqrt(PF4) |
---|
2523 | Â Â Â Â Â Â PF3 =Â 0.5*(CL+2.*AL*PF/(1.+BL*PF)-AL*PF**2*BL/(1.+BL*PF)**2)/(PF4*extCor) |
---|
2524 | |
---|
2525 | Â Â Â Â dervCor =Â (1.+PF)*PF3 |
---|
2526 |     if 'Primary' in calcControls[phfx+'EType'] and phfx+'Ep' in varyList: |
---|
2527 | Â Â Â Â Â Â dervDict[phfx+'Ep']Â =Â -ref[7]*PLZ*PF3 |
---|
2528 |     if 'II' in calcControls[phfx+'EType'] and phfx+'Es' in varyList: |
---|
2529 | Â Â Â Â Â Â dervDict[phfx+'Es']Â =Â -ref[7]*PLZ*PF3*(PSIG/parmDict[phfx+'Es'])**3 |
---|
2530 |     if 'I' in calcControls[phfx+'EType'] and phfx+'Eg' in varyList: |
---|
2531 | Â Â Â Â Â Â dervDict[phfx+'Eg']Â =Â -ref[7]*PLZ*PF3*(PSIG/parmDict[phfx+'Eg'])**3*PL**2 |
---|
2532 | Â Â Â Â Â Â Â Â |
---|
2533 | Â Â Â Â ref[13]Â =Â 1./extCor |
---|
2534 |   return dervCor,dervDict |
---|
2535 | Â Â Â Â |
---|
2536 | Â Â |
---|
2537 | def Dict2Values(parmdict, varylist): |
---|
2538 | Â Â '''Use before call to leastsq to setup list of values for the parameters |
---|
2539 | Â Â in parmdict, as selected by key in varylist''' |
---|
2540 |   return [parmdict[key] for key in varylist] |
---|
2541 | Â Â |
---|
2542 | def Values2Dict(parmdict, varylist, values): |
---|
2543 | Â Â ''' Use after call to leastsq to update the parameter dictionary with |
---|
2544 | Â Â values corresponding to keys in varylist''' |
---|
2545 | Â Â parmdict.update(zip(varylist,values)) |
---|
2546 | Â Â |
---|
2547 | def GetNewCellParms(parmDict,varyList): |
---|
2548 | Â Â newCellDict =Â {} |
---|
2549 |   Anames = ['A'+str(i) for i in range(6)] |
---|
2550 | Â Â Ddict =Â dict(zip(['D11','D22','D33','D12','D13','D23'],Anames)) |
---|
2551 |   for item in varyList: |
---|
2552 | Â Â Â Â keys =Â item.split(':') |
---|
2553 |     if keys[2] in Ddict: |
---|
2554 | Â Â Â Â Â Â key =Â keys[0]+'::'+Ddict[keys[2]]Â Â Â Â #key is e.g. '0::A0' |
---|
2555 | Â Â Â Â Â Â parm =Â keys[0]+'::'+keys[2]Â Â Â Â Â Â Â #parm is e.g. '0::D11' |
---|
2556 | Â Â Â Â Â Â newCellDict[parm]Â =Â [key,parmDict[key]+parmDict[item]] |
---|
2557 |   return newCellDict     # is e.g. {'0::D11':A0+D11} |
---|
2558 | Â Â |
---|
2559 | def ApplyXYZshifts(parmDict,varyList): |
---|
2560 | Â Â ''' takes atom x,y,z shift and applies it to corresponding atom x,y,z value |
---|
2561 | Â Â Â Â input: |
---|
2562 | Â Â Â Â Â Â parmDict - parameter dictionary |
---|
2563 | Â Â Â Â Â Â varyList - list of variables |
---|
2564 | Â Â Â Â returns: |
---|
2565 | Â Â Â Â Â Â newAtomDict - dictionary of new atomic coordinate names & values; |
---|
2566 | Â Â Â Â Â Â Â Â key is parameter shift name |
---|
2567 | Â Â ''' |
---|
2568 | Â Â newAtomDict =Â {} |
---|
2569 |   for item in parmDict: |
---|
2570 |     if 'dA' in item: |
---|
2571 | Â Â Â Â Â Â parm =Â ''.join(item.split('d')) |
---|
2572 | Â Â Â Â Â Â parmDict[parm]Â +=Â parmDict[item] |
---|
2573 | Â Â Â Â Â Â newAtomDict[item]Â =Â [parm,parmDict[parm]] |
---|
2574 |   return newAtomDict |
---|
2575 | Â Â |
---|
2576 | def SHTXcal(refl,g,pfx,hfx,SGData,calcControls,parmDict): |
---|
2577 | Â Â #Spherical harmonics texture |
---|
2578 |   IFCoup = 'Bragg' in calcControls[hfx+'instType'] |
---|
2579 | Â Â odfCor =Â 1.0 |
---|
2580 | Â Â H =Â refl[:3] |
---|
2581 | Â Â cell =Â G2lat.Gmat2cell(g) |
---|
2582 | Â Â Sangls =Â [parmDict[pfx+'SH omega'],parmDict[pfx+'SH chi'],parmDict[pfx+'SH phi']] |
---|
2583 | Â Â Gangls =Â [parmDict[hfx+'Omega'],parmDict[hfx+'Chi'],parmDict[hfx+'Phi'],parmDict[hfx+'Azimuth']] |
---|
2584 | Â Â phi,beta =Â G2lat.CrsAng(H,cell,SGData) |
---|
2585 | Â Â psi,gam,x,x =Â G2lat.SamAng(refl[5]/2.,Gangls,Sangls,IFCoup)Â #ignore 2 sets of angle derivs. |
---|
2586 | Â Â SHnames =Â G2lat.GenSHCoeff(SGData['SGLaue'],parmDict[pfx+'SHmodel'],parmDict[pfx+'SHorder']) |
---|
2587 |   for item in SHnames: |
---|
2588 | Â Â Â Â L,M,N =Â eval(item.strip('C')) |
---|
2589 | Â Â Â Â Kcl =Â G2lat.GetKcl(L,N,SGData['SGLaue'],phi,beta) |
---|
2590 | Â Â Â Â Ksl,x,x =Â G2lat.GetKsl(L,M,parmDict[pfx+'SHmodel'],psi,gam) |
---|
2591 | Â Â Â Â Lnorm =Â G2lat.Lnorm(L) |
---|
2592 | Â Â Â Â odfCor +=Â parmDict[pfx+item]*Lnorm*Kcl*Ksl |
---|
2593 |   return odfCor |
---|
2594 | Â Â |
---|
2595 | def SHTXcalDerv(refl,g,pfx,hfx,SGData,calcControls,parmDict): |
---|
2596 | Â Â #Spherical harmonics texture derivatives |
---|
2597 | Â Â FORPI =Â 4.0*np.pi |
---|
2598 |   IFCoup = 'Bragg' in calcControls[hfx+'instType'] |
---|
2599 | Â Â odfCor =Â 1.0 |
---|
2600 | Â Â dFdODF =Â {} |
---|
2601 | Â Â dFdSA =Â [0,0,0] |
---|
2602 | Â Â H =Â refl[:3] |
---|
2603 | Â Â cell =Â G2lat.Gmat2cell(g) |
---|
2604 | Â Â Sangls =Â [parmDict[pfx+'SH omega'],parmDict[pfx+'SH chi'],parmDict[pfx+'SH phi']] |
---|
2605 | Â Â Gangls =Â [parmDict[hfx+'Omega'],parmDict[hfx+'Chi'],parmDict[hfx+'Phi'],parmDict[hfx+'Azimuth']] |
---|
2606 | Â Â phi,beta =Â G2lat.CrsAng(H,cell,SGData) |
---|
2607 | Â Â psi,gam,dPSdA,dGMdA =Â G2lat.SamAng(refl[5]/2.,Gangls,Sangls,IFCoup) |
---|
2608 | Â Â SHnames =Â G2lat.GenSHCoeff(SGData['SGLaue'],parmDict[pfx+'SHmodel'],parmDict[pfx+'SHorder']) |
---|
2609 |   for item in SHnames: |
---|
2610 | Â Â Â Â L,M,N =Â eval(item.strip('C')) |
---|
2611 | Â Â Â Â Kcl =Â G2lat.GetKcl(L,N,SGData['SGLaue'],phi,beta) |
---|
2612 | Â Â Â Â Ksl,dKsdp,dKsdg =Â G2lat.GetKsl(L,M,parmDict[pfx+'SHmodel'],psi,gam) |
---|
2613 | Â Â Â Â Lnorm =Â G2lat.Lnorm(L) |
---|
2614 | Â Â Â Â odfCor +=Â parmDict[pfx+item]*Lnorm*Kcl*Ksl |
---|
2615 | Â Â Â Â dFdODF[pfx+item]Â =Â Lnorm*Kcl*Ksl |
---|
2616 |     for i in range(3): |
---|
2617 | Â Â Â Â Â Â dFdSA[i]Â +=Â parmDict[pfx+item]*Lnorm*Kcl*(dKsdp*dPSdA[i]+dKsdg*dGMdA[i]) |
---|
2618 |   return odfCor,dFdODF,dFdSA |
---|
2619 | Â Â |
---|
2620 | def SHPOcal(refl,g,phfx,hfx,SGData,calcControls,parmDict): |
---|
2621 | Â Â #sphericaql harmonics preferred orientation (cylindrical symmetry only) |
---|
2622 | Â Â odfCor =Â 1.0 |
---|
2623 | Â Â H =Â refl[:3] |
---|
2624 | Â Â cell =Â G2lat.Gmat2cell(g) |
---|
2625 | Â Â Sangl =Â [0.,0.,0.] |
---|
2626 |   if 'Bragg' in calcControls[hfx+'instType']: |
---|
2627 | Â Â Â Â Gangls =Â [0.,90.,0.,parmDict[hfx+'Azimuth']] |
---|
2628 | Â Â Â Â IFCoup =Â True |
---|
2629 | Â Â else: |
---|
2630 | Â Â Â Â Gangls =Â [0.,0.,0.,parmDict[hfx+'Azimuth']] |
---|
2631 | Â Â Â Â IFCoup =Â False |
---|
2632 | Â Â phi,beta =Â G2lat.CrsAng(H,cell,SGData) |
---|
2633 | Â Â psi,gam,x,x =Â G2lat.SamAng(refl[5]/2.,Gangls,Sangl,IFCoup)Â #ignore 2 sets of angle derivs. |
---|
2634 | Â Â SHnames =Â G2lat.GenSHCoeff(SGData['SGLaue'],'0',calcControls[phfx+'SHord'],False) |
---|
2635 |   for item in SHnames: |
---|
2636 | Â Â Â Â L,N =Â eval(item.strip('C')) |
---|
2637 | Â Â Â Â Kcsl,Lnorm =Â G2lat.GetKclKsl(L,N,SGData['SGLaue'],psi,phi,beta)Â |
---|
2638 | Â Â Â Â odfCor +=Â parmDict[phfx+item]*Lnorm*Kcsl |
---|
2639 |   return odfCor |
---|
2640 | Â Â |
---|
2641 | def SHPOcalDerv(refl,g,phfx,hfx,SGData,calcControls,parmDict): |
---|
2642 | Â Â #spherical harmonics preferred orientation derivatives (cylindrical symmetry only) |
---|
2643 | Â Â FORPI =Â 12.5663706143592 |
---|
2644 | Â Â odfCor =Â 1.0 |
---|
2645 | Â Â dFdODF =Â {} |
---|
2646 | Â Â H =Â refl[:3] |
---|
2647 | Â Â cell =Â G2lat.Gmat2cell(g) |
---|
2648 | Â Â Sangl =Â [0.,0.,0.] |
---|
2649 |   if 'Bragg' in calcControls[hfx+'instType']: |
---|
2650 | Â Â Â Â Gangls =Â [0.,90.,0.,parmDict[hfx+'Azimuth']] |
---|
2651 | Â Â Â Â IFCoup =Â True |
---|
2652 | Â Â else: |
---|
2653 | Â Â Â Â Gangls =Â [0.,0.,0.,parmDict[hfx+'Azimuth']] |
---|
2654 | Â Â Â Â IFCoup =Â False |
---|
2655 | Â Â phi,beta =Â G2lat.CrsAng(H,cell,SGData) |
---|
2656 | Â Â psi,gam,x,x =Â G2lat.SamAng(refl[5]/2.,Gangls,Sangl,IFCoup)Â #ignore 2 sets of angle derivs. |
---|
2657 | Â Â SHnames =Â G2lat.GenSHCoeff(SGData['SGLaue'],'0',calcControls[phfx+'SHord'],False) |
---|
2658 |   for item in SHnames: |
---|
2659 | Â Â Â Â L,N =Â eval(item.strip('C')) |
---|
2660 | Â Â Â Â Kcsl,Lnorm =Â G2lat.GetKclKsl(L,N,SGData['SGLaue'],psi,phi,beta)Â |
---|
2661 | Â Â Â Â odfCor +=Â parmDict[phfx+item]*Lnorm*Kcsl |
---|
2662 | Â Â Â Â dFdODF[phfx+item]Â =Â Kcsl*Lnorm |
---|
2663 |   return odfCor,dFdODF |
---|
2664 | Â Â |
---|
2665 | def GetPrefOri(refl,G,g,phfx,hfx,SGData,calcControls,parmDict): |
---|
2666 | Â Â POcorr =Â 1.0 |
---|
2667 |   if calcControls[phfx+'poType'] == 'MD': |
---|
2668 | Â Â Â Â MD =Â parmDict[phfx+'MD'] |
---|
2669 |     if MD != 1.0: |
---|
2670 | Â Â Â Â Â Â MDAxis =Â calcControls[phfx+'MDAxis'] |
---|
2671 | Â Â Â Â Â Â sumMD =Â 0 |
---|
2672 |       for H in refl[11]:      |
---|
2673 | Â Â Â Â Â Â Â Â cosP,sinP =Â G2lat.CosSinAngle(H,MDAxis,G) |
---|
2674 | Â Â Â Â Â Â Â Â A =Â 1.0/np.sqrt((MD*cosP)**2+sinP**2/MD) |
---|
2675 | Â Â Â Â Â Â Â Â sumMD +=Â A**3 |
---|
2676 | Â Â Â Â Â Â POcorr =Â sumMD/len(refl[11]) |
---|
2677 | Â Â else:Â Â #spherical harmonics |
---|
2678 |     if calcControls[phfx+'SHord']: |
---|
2679 | Â Â Â Â Â Â POcorr =Â SHPOcal(refl,g,phfx,hfx,SGData,calcControls,parmDict) |
---|
2680 |   return POcorr |
---|
2681 | Â Â |
---|
2682 | def GetPrefOriDerv(refl,G,g,phfx,hfx,SGData,calcControls,parmDict): |
---|
2683 | Â Â POcorr =Â 1.0 |
---|
2684 | Â Â POderv =Â {} |
---|
2685 |   if calcControls[phfx+'poType'] == 'MD': |
---|
2686 | Â Â Â Â MD =Â parmDict[phfx+'MD'] |
---|
2687 | Â Â Â Â MDAxis =Â calcControls[phfx+'MDAxis'] |
---|
2688 | Â Â Â Â sumMD =Â 0 |
---|
2689 | Â Â Â Â sumdMD =Â 0 |
---|
2690 |     for H in refl[11]:      |
---|
2691 | Â Â Â Â Â Â cosP,sinP =Â G2lat.CosSinAngle(H,MDAxis,G) |
---|
2692 | Â Â Â Â Â Â A =Â 1.0/np.sqrt((MD*cosP)**2+sinP**2/MD) |
---|
2693 | Â Â Â Â Â Â sumMD +=Â A**3 |
---|
2694 | Â Â Â Â Â Â sumdMD -=Â (1.5*A**5)*(2.0*MD*cosP**2-(sinP/MD)**2) |
---|
2695 | Â Â Â Â POcorr =Â sumMD/len(refl[11]) |
---|
2696 | Â Â Â Â POderv[phfx+'MD']Â =Â sumdMD/len(refl[11]) |
---|
2697 | Â Â else:Â Â #spherical harmonics |
---|
2698 |     if calcControls[phfx+'SHord']: |
---|
2699 | Â Â Â Â Â Â POcorr,POderv =Â SHPOcalDerv(refl,g,phfx,hfx,SGData,calcControls,parmDict) |
---|
2700 |   return POcorr,POderv |
---|
2701 | Â Â |
---|
2702 | def GetAbsorb(refl,hfx,calcControls,parmDict): |
---|
2703 |   if 'Debye' in calcControls[hfx+'instType']: |
---|
2704 |     return G2pwd.Absorb('Cylinder',parmDict[hfx+'Absorption'],refl[5],0,0) |
---|
2705 | Â Â else: |
---|
2706 |     return 1.0 |
---|
2707 | Â Â |
---|
2708 | def GetAbsorbDerv(refl,hfx,calcControls,parmDict): |
---|
2709 |   if 'Debye' in calcControls[hfx+'instType']: |
---|
2710 |     return G2pwd.AbsorbDerv('Cylinder',parmDict[hfx+'Absorption'],refl[5],0,0) |
---|
2711 | Â Â else: |
---|
2712 |     return 0.0 |
---|
2713 | Â Â |
---|
2714 | def GetIntensityCorr(refl,G,g,pfx,phfx,hfx,SGData,calcControls,parmDict): |
---|
2715 | Â Â Icorr =Â parmDict[phfx+'Scale']*parmDict[hfx+'Scale']*refl[3]Â Â Â Â Â Â Â Â #scale*multiplicity |
---|
2716 |   if 'X' in parmDict[hfx+'Type']: |
---|
2717 | Â Â Â Â Icorr *=Â G2pwd.Polarization(parmDict[hfx+'Polariz.'],refl[5],parmDict[hfx+'Azimuth'])[0] |
---|
2718 | Â Â Icorr *=Â GetPrefOri(refl,G,g,phfx,hfx,SGData,calcControls,parmDict) |
---|
2719 |   if pfx+'SHorder' in parmDict: |
---|
2720 | Â Â Â Â Icorr *=Â SHTXcal(refl,g,pfx,hfx,SGData,calcControls,parmDict) |
---|
2721 | Â Â Icorr *=Â GetAbsorb(refl,hfx,calcControls,parmDict) |
---|
2722 |   refl[13] = Icorr    |
---|
2723 | Â Â |
---|
2724 | def GetIntensityDerv(refl,G,g,pfx,phfx,hfx,SGData,calcControls,parmDict): |
---|
2725 | Â Â dIdsh =Â 1./parmDict[hfx+'Scale'] |
---|
2726 | Â Â dIdsp =Â 1./parmDict[phfx+'Scale'] |
---|
2727 |   if 'X' in parmDict[hfx+'Type']: |
---|
2728 | Â Â Â Â pola,dIdPola =Â G2pwd.Polarization(parmDict[hfx+'Polariz.'],refl[5],parmDict[hfx+'Azimuth']) |
---|
2729 | Â Â Â Â dIdPola /=Â pola |
---|
2730 | Â Â else:Â Â Â Â #'N' |
---|
2731 | Â Â Â Â dIdPola =Â 0.0 |
---|
2732 | Â Â POcorr,dIdPO =Â GetPrefOriDerv(refl,G,g,phfx,hfx,SGData,calcControls,parmDict) |
---|
2733 |   for iPO in dIdPO: |
---|
2734 | Â Â Â Â dIdPO[iPO]Â /=Â POcorr |
---|
2735 | Â Â dFdODF =Â {} |
---|
2736 | Â Â dFdSA =Â [0,0,0] |
---|
2737 |   if pfx+'SHorder' in parmDict: |
---|
2738 | Â Â Â Â odfCor,dFdODF,dFdSA =Â SHTXcalDerv(refl,g,pfx,hfx,SGData,calcControls,parmDict) |
---|
2739 |     for iSH in dFdODF: |
---|
2740 | Â Â Â Â Â Â dFdODF[iSH]Â /=Â odfCor |
---|
2741 |     for i in range(3): |
---|
2742 | Â Â Â Â Â Â dFdSA[i]Â /=Â odfCor |
---|
2743 | Â Â dFdAb =Â GetAbsorbDerv(refl,hfx,calcControls,parmDict) |
---|
2744 |   return dIdsh,dIdsp,dIdPola,dIdPO,dFdODF,dFdSA,dFdAb |
---|
2745 | Â Â Â Â |
---|
2746 | def GetSampleSigGam(refl,wave,G,GB,phfx,calcControls,parmDict): |
---|
2747 | Â Â costh =Â cosd(refl[5]/2.) |
---|
2748 | Â Â #crystallite size |
---|
2749 |   if calcControls[phfx+'SizeType'] == 'isotropic': |
---|
2750 | Â Â Â Â Sgam =Â 1.8*wave/(np.pi*parmDict[phfx+'Size;i']*costh) |
---|
2751 |   elif calcControls[phfx+'SizeType'] == 'uniaxial': |
---|
2752 | Â Â Â Â H =Â np.array(refl[:3]) |
---|
2753 | Â Â Â Â P =Â np.array(calcControls[phfx+'SizeAxis']) |
---|
2754 | Â Â Â Â cosP,sinP =Â G2lat.CosSinAngle(H,P,G) |
---|
2755 | Â Â Â Â Sgam =Â (1.8*wave/np.pi)/(parmDict[phfx+'Size;i']*parmDict[phfx+'Size;a']*costh) |
---|
2756 | Â Â Â Â Sgam *=Â np.sqrt((sinP*parmDict[phfx+'Size;a'])**2+(cosP*parmDict[phfx+'Size;i'])**2) |
---|
2757 | Â Â else:Â Â Â Â Â Â #ellipsoidal crystallites |
---|
2758 |     Sij =[parmDict[phfx+'Size:%d'%(i)] for i in range(6)] |
---|
2759 | Â Â Â Â H =Â np.array(refl[:3]) |
---|
2760 | Â Â Â Â lenR =Â G2pwd.ellipseSize(H,Sij,GB) |
---|
2761 | Â Â Â Â Sgam =Â 1.8*wave/(np.pi*costh*lenR) |
---|
2762 |   #microstrain        |
---|
2763 |   if calcControls[phfx+'MustrainType'] == 'isotropic': |
---|
2764 | Â Â Â Â Mgam =Â 0.018*parmDict[phfx+'Mustrain;i']*tand(refl[5]/2.)/np.pi |
---|
2765 |   elif calcControls[phfx+'MustrainType'] == 'uniaxial': |
---|
2766 | Â Â Â Â H =Â np.array(refl[:3]) |
---|
2767 | Â Â Â Â P =Â np.array(calcControls[phfx+'MustrainAxis']) |
---|
2768 | Â Â Â Â cosP,sinP =Â G2lat.CosSinAngle(H,P,G) |
---|
2769 | Â Â Â Â Si =Â parmDict[phfx+'Mustrain;i'] |
---|
2770 | Â Â Â Â Sa =Â parmDict[phfx+'Mustrain;a'] |
---|
2771 | Â Â Â Â Mgam =Â 0.018*Si*Sa*tand(refl[5]/2.)/(np.pi*np.sqrt((Si*cosP)**2+(Sa*sinP)**2)) |
---|
2772 | Â Â else:Â Â Â Â #generalized - P.W. Stephens model |
---|
2773 | Â Â Â Â pwrs =Â calcControls[phfx+'MuPwrs'] |
---|
2774 |     sum = 0 |
---|
2775 |     for i,pwr in enumerate(pwrs): |
---|
2776 |       sum += parmDict[phfx+'Mustrain:'+str(i)]*refl[0]**pwr[0]*refl[1]**pwr[1]*refl[2]**pwr[2] |
---|
2777 | Â Â Â Â Mgam =Â 0.018*refl[4]**2*tand(refl[5]/2.)*sum |
---|
2778 | Â Â gam =Â Sgam*parmDict[phfx+'Size;mx']+Mgam*parmDict[phfx+'Mustrain;mx'] |
---|
2779 | Â Â sig =Â (Sgam*(1.-parmDict[phfx+'Size;mx']))**2+(Mgam*(1.-parmDict[phfx+'Mustrain;mx']))**2 |
---|
2780 | Â Â sig /=Â ateln2 |
---|
2781 |   return sig,gam |
---|
2782 | Â Â Â Â |
---|
2783 | def GetSampleSigGamDerv(refl,wave,G,GB,phfx,calcControls,parmDict): |
---|
2784 | Â Â gamDict =Â {} |
---|
2785 | Â Â sigDict =Â {} |
---|
2786 | Â Â costh =Â cosd(refl[5]/2.) |
---|
2787 | Â Â tanth =Â tand(refl[5]/2.) |
---|
2788 | Â Â #crystallite size derivatives |
---|
2789 |   if calcControls[phfx+'SizeType'] == 'isotropic': |
---|
2790 | Â Â Â Â Sgam =Â 1.8*wave/(np.pi*parmDict[phfx+'Size;i']*costh) |
---|
2791 | Â Â Â Â gamDict[phfx+'Size;i']Â =Â -1.8*wave*parmDict[phfx+'Size;mx']/(np.pi*costh) |
---|
2792 | Â Â Â Â sigDict[phfx+'Size;i']Â =Â -3.6*Sgam*wave*(1.-parmDict[phfx+'Size;mx'])**2/(np.pi*costh*ateln2) |
---|
2793 |   elif calcControls[phfx+'SizeType'] == 'uniaxial': |
---|
2794 | Â Â Â Â H =Â np.array(refl[:3]) |
---|
2795 | Â Â Â Â P =Â np.array(calcControls[phfx+'SizeAxis']) |
---|
2796 | Â Â Â Â cosP,sinP =Â G2lat.CosSinAngle(H,P,G) |
---|
2797 | Â Â Â Â Si =Â parmDict[phfx+'Size;i'] |
---|
2798 | Â Â Â Â Sa =Â parmDict[phfx+'Size;a'] |
---|
2799 | Â Â Â Â gami =Â (1.8*wave/np.pi)/(Si*Sa) |
---|
2800 | Â Â Â Â sqtrm =Â np.sqrt((sinP*Sa)**2+(cosP*Si)**2) |
---|
2801 | Â Â Â Â Sgam =Â gami*sqtrm |
---|
2802 | Â Â Â Â gam =Â Sgam/costh |
---|
2803 | Â Â Â Â dsi =Â (gami*Si*cosP**2/(sqtrm*costh)-gam/Si) |
---|
2804 | Â Â Â Â dsa =Â (gami*Sa*sinP**2/(sqtrm*costh)-gam/Sa) |
---|
2805 | Â Â Â Â gamDict[phfx+'Size;i']Â =Â dsi*parmDict[phfx+'Size;mx'] |
---|
2806 | Â Â Â Â gamDict[phfx+'Size;a']Â =Â dsa*parmDict[phfx+'Size;mx'] |
---|
2807 | Â Â Â Â sigDict[phfx+'Size;i']Â =Â 2.*dsi*Sgam*(1.-parmDict[phfx+'Size;mx'])**2/ateln2 |
---|
2808 | Â Â Â Â sigDict[phfx+'Size;a']Â =Â 2.*dsa*Sgam*(1.-parmDict[phfx+'Size;mx'])**2/ateln2 |
---|
2809 | Â Â else:Â Â Â Â Â Â #ellipsoidal crystallites |
---|
2810 | Â Â Â Â const =Â 1.8*wave/(np.pi*costh) |
---|
2811 |     Sij =[parmDict[phfx+'Size:%d'%(i)] for i in range(6)] |
---|
2812 | Â Â Â Â H =Â np.array(refl[:3]) |
---|
2813 | Â Â Â Â lenR,dRdS =Â G2pwd.ellipseSizeDerv(H,Sij,GB) |
---|
2814 | Â Â Â Â Sgam =Â 1.8*wave/(np.pi*costh*lenR) |
---|
2815 |     for i,item in enumerate([phfx+'Size:%d'%(j) for j in range(6)]): |
---|
2816 | Â Â Â Â Â Â gamDict[item]Â =Â -(const/lenR**2)*dRdS[i]*parmDict[phfx+'Size;mx'] |
---|
2817 | Â Â Â Â Â Â sigDict[item]Â =Â -2.*Sgam*(const/lenR**2)*dRdS[i]*(1.-parmDict[phfx+'Size;mx'])**2/ateln2 |
---|
2818 | Â Â gamDict[phfx+'Size;mx']Â =Â Sgam |
---|
2819 | Â Â sigDict[phfx+'Size;mx']Â =Â -2.*Sgam**2*(1.-parmDict[phfx+'Size;mx'])/ateln2 |
---|
2820 | Â Â Â Â Â Â |
---|
2821 |   #microstrain derivatives        |
---|
2822 |   if calcControls[phfx+'MustrainType'] == 'isotropic': |
---|
2823 | Â Â Â Â Mgam =Â 0.018*parmDict[phfx+'Mustrain;i']*tand(refl[5]/2.)/np.pi |
---|
2824 | Â Â Â Â gamDict[phfx+'Mustrain;i']Â =Â 0.018*tanth*parmDict[phfx+'Mustrain;mx']/np.pi |
---|
2825 | Â Â Â Â sigDict[phfx+'Mustrain;i']Â =Â 0.036*Mgam*tanth*(1.-parmDict[phfx+'Mustrain;mx'])**2/(np.pi*ateln2)Â Â Â Â |
---|
2826 |   elif calcControls[phfx+'MustrainType'] == 'uniaxial': |
---|
2827 | Â Â Â Â H =Â np.array(refl[:3]) |
---|
2828 | Â Â Â Â P =Â np.array(calcControls[phfx+'MustrainAxis']) |
---|
2829 | Â Â Â Â cosP,sinP =Â G2lat.CosSinAngle(H,P,G) |
---|
2830 | Â Â Â Â Si =Â parmDict[phfx+'Mustrain;i'] |
---|
2831 | Â Â Â Â Sa =Â parmDict[phfx+'Mustrain;a'] |
---|
2832 | Â Â Â Â gami =Â 0.018*Si*Sa*tanth/np.pi |
---|
2833 | Â Â Â Â sqtrm =Â np.sqrt((Si*cosP)**2+(Sa*sinP)**2) |
---|
2834 | Â Â Â Â Mgam =Â gami/sqtrm |
---|
2835 | Â Â Â Â dsi =Â -gami*Si*cosP**2/sqtrm**3 |
---|
2836 | Â Â Â Â dsa =Â -gami*Sa*sinP**2/sqtrm**3 |
---|
2837 | Â Â Â Â gamDict[phfx+'Mustrain;i']Â =Â (Mgam/Si+dsi)*parmDict[phfx+'Mustrain;mx'] |
---|
2838 | Â Â Â Â gamDict[phfx+'Mustrain;a']Â =Â (Mgam/Sa+dsa)*parmDict[phfx+'Mustrain;mx'] |
---|
2839 | Â Â Â Â sigDict[phfx+'Mustrain;i']Â =Â 2*(Mgam/Si+dsi)*Mgam*(1.-parmDict[phfx+'Mustrain;mx'])**2/ateln2 |
---|
2840 | Â Â Â Â sigDict[phfx+'Mustrain;a']Â =Â 2*(Mgam/Sa+dsa)*Mgam*(1.-parmDict[phfx+'Mustrain;mx'])**2/ateln2Â Â Â Â |
---|
2841 | Â Â else:Â Â Â Â #generalized - P.W. Stephens model |
---|
2842 | Â Â Â Â pwrs =Â calcControls[phfx+'MuPwrs'] |
---|
2843 | Â Â Â Â const =Â 0.018*refl[4]**2*tanth |
---|
2844 |     sum = 0 |
---|
2845 |     for i,pwr in enumerate(pwrs): |
---|
2846 | Â Â Â Â Â Â term =Â refl[0]**pwr[0]*refl[1]**pwr[1]*refl[2]**pwr[2] |
---|
2847 |       sum += parmDict[phfx+'Mustrain:'+str(i)]*term |
---|
2848 | Â Â Â Â Â Â gamDict[phfx+'Mustrain:'+str(i)]Â =Â const*term*parmDict[phfx+'Mustrain;mx'] |
---|
2849 | Â Â Â Â Â Â sigDict[phfx+'Mustrain:'+str(i)]Â =Â \ |
---|
2850 | Â Â Â Â Â Â Â Â 2.*const*term*(1.-parmDict[phfx+'Mustrain;mx'])**2/ateln2 |
---|
2851 | Â Â Â Â Mgam =Â 0.018*refl[4]**2*tand(refl[5]/2.)*sum |
---|
2852 |     for i in range(len(pwrs)): |
---|
2853 | Â Â Â Â Â Â sigDict[phfx+'Mustrain:'+str(i)]Â *=Â Mgam |
---|
2854 | Â Â gamDict[phfx+'Mustrain;mx']Â =Â Mgam |
---|
2855 | Â Â sigDict[phfx+'Mustrain;mx']Â =Â -2.*Mgam**2*(1.-parmDict[phfx+'Mustrain;mx'])/ateln2 |
---|
2856 |   return sigDict,gamDict |
---|
2857 | Â Â Â Â |
---|
2858 | def GetReflPos(refl,wave,G,hfx,calcControls,parmDict): |
---|
2859 | Â Â h,k,l =Â refl[:3] |
---|
2860 | Â Â dsq =Â 1./G2lat.calc_rDsq2(np.array([h,k,l]),G) |
---|
2861 | Â Â d =Â np.sqrt(dsq) |
---|
2862 | |
---|
2863 | Â Â refl[4]Â =Â d |
---|
2864 | Â Â pos =Â 2.0*asind(wave/(2.0*d))+parmDict[hfx+'Zero'] |
---|
2865 | Â Â const =Â 9.e-2/(np.pi*parmDict[hfx+'Gonio. radius'])Â Â Â Â Â Â Â Â Â #shifts in microns |
---|
2866 |   if 'Bragg' in calcControls[hfx+'instType']: |
---|
2867 | Â Â Â Â pos -=Â const*(4.*parmDict[hfx+'Shift']*cosd(pos/2.0)+Â \ |
---|
2868 | Â Â Â Â Â Â parmDict[hfx+'Transparency']*sind(pos)*100.0)Â Â Â Â Â Â #trans(=1/mueff) in cm |
---|
2869 | Â Â else:Â Â Â Â Â Â Â Â #Debye-Scherrer - simple but maybe not right |
---|
2870 | Â Â Â Â pos -=Â const*(parmDict[hfx+'DisplaceX']*cosd(pos)+parmDict[hfx+'DisplaceY']*sind(pos)) |
---|
2871 |   return pos |
---|
2872 | |
---|
2873 | def GetReflPosDerv(refl,wave,A,hfx,calcControls,parmDict): |
---|
2874 | Â Â dpr =Â 180./np.pi |
---|
2875 | Â Â h,k,l =Â refl[:3] |
---|
2876 | Â Â dstsq =Â G2lat.calc_rDsq(np.array([h,k,l]),A) |
---|
2877 | Â Â dst =Â np.sqrt(dstsq) |
---|
2878 | Â Â pos =Â refl[5]-parmDict[hfx+'Zero'] |
---|
2879 | Â Â const =Â dpr/np.sqrt(1.0-wave**2*dstsq/4.0) |
---|
2880 | Â Â dpdw =Â const*dst |
---|
2881 | Â Â dpdA =Â np.array([h**2,k**2,l**2,h*k,h*l,k*l]) |
---|
2882 | Â Â dpdA *=Â const*wave/(2.0*dst) |
---|
2883 | Â Â dpdZ =Â 1.0 |
---|
2884 | Â Â const =Â 9.e-2/(np.pi*parmDict[hfx+'Gonio. radius'])Â Â Â Â Â Â Â Â Â #shifts in microns |
---|
2885 |   if 'Bragg' in calcControls[hfx+'instType']: |
---|
2886 | Â Â Â Â dpdSh =Â -4.*const*cosd(pos/2.0) |
---|
2887 | Â Â Â Â dpdTr =Â -const*sind(pos)*100.0 |
---|
2888 |     return dpdA,dpdw,dpdZ,dpdSh,dpdTr,0.,0. |
---|
2889 | Â Â else:Â Â Â Â Â Â Â Â #Debye-Scherrer - simple but maybe not right |
---|
2890 | Â Â Â Â dpdXd =Â -const*cosd(pos) |
---|
2891 | Â Â Â Â dpdYd =Â -const*sind(pos) |
---|
2892 |     return dpdA,dpdw,dpdZ,0.,0.,dpdXd,dpdYd |
---|
2893 | Â Â Â Â Â Â |
---|
2894 | def GetHStrainShift(refl,SGData,phfx,parmDict): |
---|
2895 | Â Â laue =Â SGData['SGLaue'] |
---|
2896 | Â Â uniq =Â SGData['SGUniq'] |
---|
2897 | Â Â h,k,l =Â refl[:3] |
---|
2898 |   if laue in ['m3','m3m']: |
---|
2899 | Â Â Â Â Dij =Â parmDict[phfx+'D11']*(h**2+k**2+l**2)+Â \ |
---|
2900 | Â Â Â Â Â Â refl[4]**2*parmDict[phfx+'eA']*((h*k)**2+(h*l)**2+(k*l)**2)/(h**2+k**2+l**2)**2 |
---|
2901 |   elif laue in ['6/m','6/mmm','3m1','31m','3']: |
---|
2902 | Â Â Â Â Dij =Â parmDict[phfx+'D11']*(h**2+k**2+h*k)+parmDict[phfx+'D33']*l**2 |
---|
2903 |   elif laue in ['3R','3mR']: |
---|
2904 | Â Â Â Â Dij =Â parmDict[phfx+'D11']*(h**2+k**2+l**2)+parmDict[phfx+'D12']*(h*k+h*l+k*l) |
---|
2905 |   elif laue in ['4/m','4/mmm']: |
---|
2906 | Â Â Â Â Dij =Â parmDict[phfx+'D11']*(h**2+k**2)+parmDict[phfx+'D33']*l**2 |
---|
2907 |   elif laue in ['mmm']: |
---|
2908 | Â Â Â Â Dij =Â parmDict[phfx+'D11']*h**2+parmDict[phfx+'D22']*k**2+parmDict[phfx+'D33']*l**2 |
---|
2909 |   elif laue in ['2/m']: |
---|
2910 | Â Â Â Â Dij =Â parmDict[phfx+'D11']*h**2+parmDict[phfx+'D22']*k**2+parmDict[phfx+'D33']*l**2 |
---|
2911 |     if uniq == 'a': |
---|
2912 | Â Â Â Â Â Â Dij +=Â parmDict[phfx+'D23']*k*l |
---|
2913 |     elif uniq == 'b': |
---|
2914 | Â Â Â Â Â Â Dij +=Â parmDict[phfx+'D13']*h*l |
---|
2915 |     elif uniq == 'c': |
---|
2916 | Â Â Â Â Â Â Dij +=Â parmDict[phfx+'D12']*h*k |
---|
2917 | Â Â else: |
---|
2918 | Â Â Â Â Dij =Â parmDict[phfx+'D11']*h**2+parmDict[phfx+'D22']*k**2+parmDict[phfx+'D33']*l**2+Â \ |
---|
2919 | Â Â Â Â Â Â parmDict[phfx+'D12']*h*k+parmDict[phfx+'D13']*h*l+parmDict[phfx+'D23']*k*l |
---|
2920 |   return -Dij*refl[4]**2*tand(refl[5]/2.0) |
---|
2921 | Â Â Â Â Â Â |
---|
2922 | def GetHStrainShiftDerv(refl,SGData,phfx): |
---|
2923 | Â Â laue =Â SGData['SGLaue'] |
---|
2924 | Â Â uniq =Â SGData['SGUniq'] |
---|
2925 | Â Â h,k,l =Â refl[:3] |
---|
2926 |   if laue in ['m3','m3m']: |
---|
2927 | Â Â Â Â dDijDict =Â {phfx+'D11':h**2+k**2+l**2, |
---|
2928 | Â Â Â Â Â Â phfx+'eA':refl[4]**2*((h*k)**2+(h*l)**2+(k*l)**2)/(h**2+k**2+l**2)**2} |
---|
2929 |   elif laue in ['6/m','6/mmm','3m1','31m','3']: |
---|
2930 | Â Â Â Â dDijDict =Â {phfx+'D11':h**2+k**2+h*k,phfx+'D33':l**2} |
---|
2931 |   elif laue in ['3R','3mR']: |
---|
2932 | Â Â Â Â dDijDict =Â {phfx+'D11':h**2+k**2+l**2,phfx+'D12':h*k+h*l+k*l} |
---|
2933 |   elif laue in ['4/m','4/mmm']: |
---|
2934 | Â Â Â Â dDijDict =Â {phfx+'D11':h**2+k**2,phfx+'D33':l**2} |
---|
2935 |   elif laue in ['mmm']: |
---|
2936 | Â Â Â Â dDijDict =Â {phfx+'D11':h**2,phfx+'D22':k**2,phfx+'D33':l**2} |
---|
2937 |   elif laue in ['2/m']: |
---|
2938 | Â Â Â Â dDijDict =Â {phfx+'D11':h**2,phfx+'D22':k**2,phfx+'D33':l**2} |
---|
2939 |     if uniq == 'a': |
---|
2940 | Â Â Â Â Â Â dDijDict[phfx+'D23']Â =Â k*l |
---|
2941 |     elif uniq == 'b': |
---|
2942 | Â Â Â Â Â Â dDijDict[phfx+'D13']Â =Â h*l |
---|
2943 |     elif uniq == 'c': |
---|
2944 | Â Â Â Â Â Â dDijDict[phfx+'D12']Â =Â h*k |
---|
2945 | Â Â Â Â Â Â names.append() |
---|
2946 | Â Â else: |
---|
2947 | Â Â Â Â dDijDict =Â {phfx+'D11':h**2,phfx+'D22':k**2,phfx+'D33':l**2, |
---|
2948 | Â Â Â Â Â Â phfx+'D12':h*k,phfx+'D13':h*l,phfx+'D23':k*l} |
---|
2949 |   for item in dDijDict: |
---|
2950 | Â Â Â Â dDijDict[item]Â *=Â -refl[4]**2*tand(refl[5]/2.0) |
---|
2951 |   return dDijDict |
---|
2952 | Â Â |
---|
2953 | def GetFprime(controlDict,Histograms): |
---|
2954 | Â Â FFtables =Â controlDict['FFtables'] |
---|
2955 |   if not FFtables: |
---|
2956 | Â Â Â Â return |
---|
2957 | Â Â histoList =Â Histograms.keys() |
---|
2958 | Â Â histoList.sort() |
---|
2959 |   for histogram in histoList: |
---|
2960 |     if histogram[:4] in ['PWDR','HKLF']: |
---|
2961 | Â Â Â Â Â Â Histogram =Â Histograms[histogram] |
---|
2962 | Â Â Â Â Â Â hId =Â Histogram['hId'] |
---|
2963 | Â Â Â Â Â Â hfx =Â ':%d:'%(hId) |
---|
2964 | Â Â Â Â Â Â keV =Â controlDict[hfx+'keV'] |
---|
2965 |       for El in FFtables: |
---|
2966 | Â Â Â Â Â Â Â Â Orbs =Â G2el.GetXsectionCoeff(El.split('+')[0].split('-')[0]) |
---|
2967 |         FP,FPP,Mu = G2el.FPcalc(Orbs, keV) |
---|
2968 | Â Â Â Â Â Â Â Â FFtables[El][hfx+'FP']Â =Â FP |
---|
2969 | Â Â Â Â Â Â Â Â FFtables[El][hfx+'FPP']Â =Â FPPÂ Â Â Â Â Â Â Â |
---|
2970 | Â Â Â Â Â Â |
---|
2971 | def GetFobsSq(Histograms,Phases,parmDict,calcControls): |
---|
2972 | Â Â histoList =Â Histograms.keys() |
---|
2973 | Â Â histoList.sort() |
---|
2974 |   for histogram in histoList: |
---|
2975 |     if 'PWDR' in histogram[:4]: |
---|
2976 | Â Â Â Â Â Â Histogram =Â Histograms[histogram] |
---|
2977 | Â Â Â Â Â Â hId =Â Histogram['hId'] |
---|
2978 | Â Â Â Â Â Â hfx =Â ':%d:'%(hId) |
---|
2979 | Â Â Â Â Â Â Limits =Â calcControls[hfx+'Limits'] |
---|
2980 | Â Â Â Â Â Â shl =Â max(parmDict[hfx+'SH/L'],0.0005) |
---|
2981 | Â Â Â Â Â Â Ka2 =Â False |
---|
2982 | Â Â Â Â Â Â kRatio =Â 0.0 |
---|
2983 |       if hfx+'Lam1' in parmDict.keys(): |
---|
2984 | Â Â Â Â Â Â Â Â Ka2 =Â True |
---|
2985 | Â Â Â Â Â Â Â Â lamRatio =Â 360*(parmDict[hfx+'Lam2']-parmDict[hfx+'Lam1'])/(np.pi*parmDict[hfx+'Lam1']) |
---|
2986 | Â Â Â Â Â Â Â Â kRatio =Â parmDict[hfx+'I(L2)/I(L1)'] |
---|
2987 | Â Â Â Â Â Â x,y,w,yc,yb,yd =Â Histogram['Data'] |
---|
2988 | Â Â Â Â Â Â xB =Â np.searchsorted(x,Limits[0]) |
---|
2989 | Â Â Â Â Â Â xF =Â np.searchsorted(x,Limits[1]) |
---|
2990 | Â Â Â Â Â Â ymb =Â np.array(y-yb) |
---|
2991 | Â Â Â Â Â Â ymb =Â np.where(ymb,ymb,1.0) |
---|
2992 | Â Â Â Â Â Â ycmb =Â np.array(yc-yb) |
---|
2993 | Â Â Â Â Â Â ratio =Â 1./np.where(ycmb,ycmb/ymb,1.e10)Â Â Â Â Â |
---|
2994 | Â Â Â Â Â Â refLists =Â Histogram['Reflection Lists'] |
---|
2995 |       for phase in refLists: |
---|
2996 | Â Â Â Â Â Â Â Â Phase =Â Phases[phase] |
---|
2997 | Â Â Â Â Â Â Â Â pId =Â Phase['pId'] |
---|
2998 | Â Â Â Â Â Â Â Â phfx =Â '%d:%d:'%(pId,hId) |
---|
2999 | Â Â Â Â Â Â Â Â refList =Â refLists[phase] |
---|
3000 | Â Â Â Â Â Â Â Â sumFo =Â 0.0 |
---|
3001 | Â Â Â Â Â Â Â Â sumdF =Â 0.0 |
---|
3002 | Â Â Â Â Â Â Â Â sumFosq =Â 0.0 |
---|
3003 | Â Â Â Â Â Â Â Â sumdFsq =Â 0.0 |
---|
3004 |         for refl in refList: |
---|
3005 |           if 'C' in calcControls[hfx+'histType']: |
---|
3006 | Â Â Â Â Â Â Â Â Â Â Â Â yp =Â np.zeros_like(yb) |
---|
3007 | Â Â Â Â Â Â Â Â Â Â Â Â Wd,fmin,fmax =Â G2pwd.getWidthsCW(refl[5],refl[6],refl[7],shl) |
---|
3008 | Â Â Â Â Â Â Â Â Â Â Â Â iBeg =Â max(xB,np.searchsorted(x,refl[5]-fmin)) |
---|
3009 | Â Â Â Â Â Â Â Â Â Â Â Â iFin =Â max(xB,min(np.searchsorted(x,refl[5]+fmax),xF)) |
---|
3010 | Â Â Â Â Â Â Â Â Â Â Â Â iFin2 =Â iFin |
---|
3011 | Â Â Â Â Â Â Â Â Â Â Â Â yp[iBeg:iFin]Â =Â refl[13]*refl[9]*G2pwd.getFCJVoigt3(refl[5],refl[6],refl[7],shl,x[iBeg:iFin])Â Â #>90% of time spent here |
---|
3012 |             if Ka2: |
---|
3013 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â pos2 =Â refl[5]+lamRatio*tand(refl[5]/2.0)Â Â Â Â # + 360/pi * Dlam/lam * tan(th) |
---|
3014 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Wd,fmin,fmax =Â G2pwd.getWidthsCW(pos2,refl[6],refl[7],shl) |
---|
3015 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â iBeg2 =Â max(xB,np.searchsorted(x,pos2-fmin)) |
---|
3016 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â iFin2 =Â min(np.searchsorted(x,pos2+fmax),xF) |
---|
3017 |               if not iBeg2+iFin2:    #peak below low limit - skip peak |
---|
3018 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â continue |
---|
3019 |               elif not iBeg2-iFin2:   #peak above high limit - done |
---|
3020 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â break |
---|
3021 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â yp[iBeg2:iFin2]Â +=Â refl[13]*refl[9]*kRatio*G2pwd.getFCJVoigt3(pos2,refl[6],refl[7],shl,x[iBeg2:iFin2])Â Â Â Â #and here |
---|
3022 | Â Â Â Â Â Â Â Â Â Â Â Â refl[8]Â =Â np.sum(np.where(ratio[iBeg:iFin2]>0.,yp[iBeg:iFin2]*ratio[iBeg:iFin2]/(refl[13]*(1.+kRatio)),0.0)) |
---|
3023 |           elif 'T' in calcControls[hfx+'histType']: |
---|
3024 |             print 'TOF Undefined at present' |
---|
3025 |             raise Exception  #no TOF yet |
---|
3026 | Â Â Â Â Â Â Â Â Â Â Fo =Â np.sqrt(np.abs(refl[8])) |
---|
3027 | Â Â Â Â Â Â Â Â Â Â Fc =Â np.sqrt(np.abs(refl[9])) |
---|
3028 | Â Â Â Â Â Â Â Â Â Â sumFo +=Â Fo |
---|
3029 | Â Â Â Â Â Â Â Â Â Â sumFosq +=Â refl[8]**2 |
---|
3030 | Â Â Â Â Â Â Â Â Â Â sumdF +=Â np.abs(Fo-Fc) |
---|
3031 | Â Â Â Â Â Â Â Â Â Â sumdFsq +=Â (refl[8]-refl[9])**2 |
---|
3032 | Â Â Â Â Â Â Â Â Histogram[phfx+'Rf']Â =Â min(100.,(sumdF/sumFo)*100.) |
---|
3033 | Â Â Â Â Â Â Â Â Histogram[phfx+'Rf^2']Â =Â min(100.,np.sqrt(sumdFsq/sumFosq)*100.) |
---|
3034 | Â Â Â Â Â Â Â Â Histogram[phfx+'Nref']Â =Â len(refList) |
---|
3035 | Â Â Â Â Â Â Â Â |
---|
3036 | def getPowderProfile(parmDict,x,varylist,Histogram,Phases,calcControls,pawleyLookup): |
---|
3037 | Â Â |
---|
3038 |   def GetReflSigGam(refl,wave,G,GB,hfx,phfx,calcControls,parmDict): |
---|
3039 | Â Â Â Â U =Â parmDict[hfx+'U'] |
---|
3040 | Â Â Â Â V =Â parmDict[hfx+'V'] |
---|
3041 | Â Â Â Â W =Â parmDict[hfx+'W'] |
---|
3042 | Â Â Â Â X =Â parmDict[hfx+'X'] |
---|
3043 | Â Â Â Â Y =Â parmDict[hfx+'Y'] |
---|
3044 | Â Â Â Â tanPos =Â tand(refl[5]/2.0) |
---|
3045 | Â Â Â Â Ssig,Sgam =Â GetSampleSigGam(refl,wave,G,GB,phfx,calcControls,parmDict) |
---|
3046 |     sig = U*tanPos**2+V*tanPos+W+Ssig   #save peak sigma |
---|
3047 | Â Â Â Â sig =Â max(0.001,sig) |
---|
3048 |     gam = X/cosd(refl[5]/2.0)+Y*tanPos+Sgam   #save peak gamma |
---|
3049 | Â Â Â Â gam =Â max(0.001,gam) |
---|
3050 |     return sig,gam |
---|
3051 | Â Â Â Â Â Â Â Â |
---|
3052 | Â Â hId =Â Histogram['hId'] |
---|
3053 | Â Â hfx =Â ':%d:'%(hId) |
---|
3054 | Â Â bakType =Â calcControls[hfx+'bakType'] |
---|
3055 | Â Â yb =Â G2pwd.getBackground(hfx,parmDict,bakType,x) |
---|
3056 | Â Â yc =Â np.zeros_like(yb) |
---|
3057 | Â Â Â Â |
---|
3058 |   if 'C' in calcControls[hfx+'histType']:  |
---|
3059 | Â Â Â Â shl =Â max(parmDict[hfx+'SH/L'],0.002) |
---|
3060 | Â Â Â Â Ka2 =Â False |
---|
3061 |     if hfx+'Lam1' in parmDict.keys(): |
---|
3062 | Â Â Â Â Â Â wave =Â parmDict[hfx+'Lam1'] |
---|
3063 | Â Â Â Â Â Â Ka2 =Â True |
---|
3064 | Â Â Â Â Â Â lamRatio =Â 360*(parmDict[hfx+'Lam2']-parmDict[hfx+'Lam1'])/(np.pi*parmDict[hfx+'Lam1']) |
---|
3065 | Â Â Â Â Â Â kRatio =Â parmDict[hfx+'I(L2)/I(L1)'] |
---|
3066 | Â Â Â Â else: |
---|
3067 | Â Â Â Â Â Â wave =Â parmDict[hfx+'Lam'] |
---|
3068 | Â Â else: |
---|
3069 |     print 'TOF Undefined at present' |
---|
3070 |     raise ValueError |
---|
3071 |   for phase in Histogram['Reflection Lists']: |
---|
3072 | Â Â Â Â refList =Â Histogram['Reflection Lists'][phase] |
---|
3073 | Â Â Â Â Phase =Â Phases[phase] |
---|
3074 | Â Â Â Â pId =Â Phase['pId'] |
---|
3075 | Â Â Â Â pfx =Â '%d::'%(pId) |
---|
3076 | Â Â Â Â phfx =Â '%d:%d:'%(pId,hId) |
---|
3077 | Â Â Â Â hfx =Â ':%d:'%(hId) |
---|
3078 | Â Â Â Â SGData =Â Phase['General']['SGData'] |
---|
3079 |     A = [parmDict[pfx+'A%d'%(i)] for i in range(6)] |
---|
3080 | Â Â Â Â G,g =Â G2lat.A2Gmat(A)Â Â Â Â #recip & real metric tensors |
---|
3081 | Â Â Â Â GA,GB =Â G2lat.Gmat2AB(G)Â Â #Orthogonalization matricies |
---|
3082 | Â Â Â Â Vst =Â np.sqrt(nl.det(G))Â Â #V* |
---|
3083 |     if not Phase['General'].get('doPawley'): |
---|
3084 | Â Â Â Â Â Â refList =Â StructureFactor(refList,G,hfx,pfx,SGData,calcControls,parmDict) |
---|
3085 |     for refl in refList: |
---|
3086 |       if 'C' in calcControls[hfx+'histType']: |
---|
3087 | Â Â Â Â Â Â Â Â h,k,l =Â refl[:3] |
---|
3088 | Â Â Â Â Â Â Â Â refl[5]Â =Â GetReflPos(refl,wave,G,hfx,calcControls,parmDict)Â Â Â Â Â #corrected reflection position |
---|
3089 | Â Â Â Â Â Â Â Â Lorenz =Â 1./(2.*sind(refl[5]/2.)**2*cosd(refl[5]/2.))Â Â Â Â Â Â #Lorentz correction |
---|
3090 | Â Â Â Â Â Â Â Â refl[5]Â +=Â GetHStrainShift(refl,SGData,phfx,parmDict)Â Â Â Â Â Â Â Â #apply hydrostatic strain shift |
---|
3091 | Â Â Â Â Â Â Â Â refl[6:8]Â =Â GetReflSigGam(refl,wave,G,GB,hfx,phfx,calcControls,parmDict)Â Â #peak sig & gam |
---|
3092 | Â Â Â Â Â Â Â Â GetIntensityCorr(refl,G,g,pfx,phfx,hfx,SGData,calcControls,parmDict)Â Â #puts corrections in refl[13] |
---|
3093 | Â Â Â Â Â Â Â Â refl[13]Â *=Â Vst*Lorenz |
---|
3094 |         if Phase['General'].get('doPawley'): |
---|
3095 | Â Â Â Â Â Â Â Â Â Â try: |
---|
3096 | Â Â Â Â Â Â Â Â Â Â Â Â pInd =pfx+'PWLref:%d'%(pawleyLookup[pfx+'%d,%d,%d'%(h,k,l)]) |
---|
3097 | Â Â Â Â Â Â Â Â Â Â Â Â refl[9]Â =Â parmDict[pInd] |
---|
3098 |           except KeyError: |
---|
3099 | #Â Â Â Â Â Â Â Â Â Â Â Â print ' ***Error %d,%d,%d missing from Pawley reflection list ***'%(h,k,l) |
---|
3100 | Â Â Â Â Â Â Â Â Â Â Â Â continue |
---|
3101 | Â Â Â Â Â Â Â Â Wd,fmin,fmax =Â G2pwd.getWidthsCW(refl[5],refl[6],refl[7],shl) |
---|
3102 | Â Â Â Â Â Â Â Â iBeg =Â np.searchsorted(x,refl[5]-fmin) |
---|
3103 | Â Â Â Â Â Â Â Â iFin =Â np.searchsorted(x,refl[5]+fmax) |
---|
3104 |         if not iBeg+iFin:    #peak below low limit - skip peak |
---|
3105 | Â Â Â Â Â Â Â Â Â Â continue |
---|
3106 |         elif not iBeg-iFin:   #peak above high limit - done |
---|
3107 | Â Â Â Â Â Â Â Â Â Â break |
---|
3108 | Â Â Â Â Â Â Â Â yc[iBeg:iFin]Â +=Â refl[13]*refl[9]*G2pwd.getFCJVoigt3(refl[5],refl[6],refl[7],shl,x[iBeg:iFin])Â Â #>90% of time spent here |
---|
3109 |         if Ka2: |
---|
3110 | Â Â Â Â Â Â Â Â Â Â pos2 =Â refl[5]+lamRatio*tand(refl[5]/2.0)Â Â Â Â # + 360/pi * Dlam/lam * tan(th) |
---|
3111 | Â Â Â Â Â Â Â Â Â Â Wd,fmin,fmax =Â G2pwd.getWidthsCW(pos2,refl[6],refl[7],shl) |
---|
3112 | Â Â Â Â Â Â Â Â Â Â iBeg =Â np.searchsorted(x,pos2-fmin) |
---|
3113 | Â Â Â Â Â Â Â Â Â Â iFin =Â np.searchsorted(x,pos2+fmax) |
---|
3114 |           if not iBeg+iFin:    #peak below low limit - skip peak |
---|
3115 | Â Â Â Â Â Â Â Â Â Â Â Â continue |
---|
3116 |           elif not iBeg-iFin:   #peak above high limit - done |
---|
3117 |             return yc,yb |
---|
3118 | Â Â Â Â Â Â Â Â Â Â yc[iBeg:iFin]Â +=Â refl[13]*refl[9]*kRatio*G2pwd.getFCJVoigt3(pos2,refl[6],refl[7],shl,x[iBeg:iFin])Â Â Â Â #and here |
---|
3119 |       elif 'T' in calcControls[hfx+'histType']: |
---|
3120 |         print 'TOF Undefined at present' |
---|
3121 |         raise Exception  #no TOF yet |
---|
3122 |   return yc,yb |
---|
3123 | Â Â |
---|
3124 | def getPowderProfileDerv(parmDict,x,varylist,Histogram,Phases,calcControls,pawleyLookup): |
---|
3125 | Â Â |
---|
3126 |   def cellVaryDerv(pfx,SGData,dpdA): |
---|
3127 |     if SGData['SGLaue'] in ['-1',]: |
---|
3128 |       return [[pfx+'A0',dpdA[0]],[pfx+'A1',dpdA[1]],[pfx+'A2',dpdA[2]], |
---|
3129 | Â Â Â Â Â Â Â Â [pfx+'A3',dpdA[3]],[pfx+'A4',dpdA[4]],[pfx+'A5',dpdA[5]]] |
---|
3130 |     elif SGData['SGLaue'] in ['2/m',]: |
---|
3131 |       if SGData['SGUniq'] == 'a': |
---|
3132 |         return [[pfx+'A0',dpdA[0]],[pfx+'A1',dpdA[1]],[pfx+'A2',dpdA[2]],[pfx+'A3',dpdA[3]]] |
---|
3133 |       elif SGData['SGUniq'] == 'b': |
---|
3134 |         return [[pfx+'A0',dpdA[0]],[pfx+'A1',dpdA[1]],[pfx+'A2',dpdA[2]],[pfx+'A4',dpdA[4]]] |
---|
3135 | Â Â Â Â Â Â else: |
---|
3136 |         return [[pfx+'A0',dpdA[0]],[pfx+'A1',dpdA[1]],[pfx+'A2',dpdA[2]],[pfx+'A5',dpdA[5]]] |
---|
3137 |     elif SGData['SGLaue'] in ['mmm',]: |
---|
3138 |       return [[pfx+'A0',dpdA[0]],[pfx+'A1',dpdA[1]],[pfx+'A2',dpdA[2]]] |
---|
3139 |     elif SGData['SGLaue'] in ['4/m','4/mmm']: |
---|
3140 |       return [[pfx+'A0',dpdA[0]],[pfx+'A2',dpdA[2]]] |
---|
3141 |     elif SGData['SGLaue'] in ['6/m','6/mmm','3m1', '31m', '3']: |
---|
3142 |       return [[pfx+'A0',dpdA[0]],[pfx+'A2',dpdA[2]]] |
---|
3143 |     elif SGData['SGLaue'] in ['3R', '3mR']: |
---|
3144 |       return [[pfx+'A0',dpdA[0]+dpdA[1]+dpdA[2]],[pfx+'A3',dpdA[3]+dpdA[4]+dpdA[5]]]            |
---|
3145 |     elif SGData['SGLaue'] in ['m3m','m3']: |
---|
3146 |       return [[pfx+'A0',dpdA[0]]] |
---|
3147 | Â Â # create a list of dependent variables and set up a dictionary to hold their derivatives |
---|
3148 | Â Â dependentVars =Â G2mv.GetDependentVars() |
---|
3149 | Â Â depDerivDict =Â {} |
---|
3150 |   for j in dependentVars: |
---|
3151 | Â Â Â Â depDerivDict[j]Â =Â np.zeros(shape=(len(x))) |
---|
3152 | Â Â #print 'dependent vars',dependentVars |
---|
3153 | Â Â lenX =Â len(x)Â Â Â Â Â Â Â Â |
---|
3154 | Â Â hId =Â Histogram['hId'] |
---|
3155 | Â Â hfx =Â ':%d:'%(hId) |
---|
3156 | Â Â bakType =Â calcControls[hfx+'bakType'] |
---|
3157 | Â Â dMdv =Â np.zeros(shape=(len(varylist),len(x))) |
---|
3158 | Â Â dMdb,dMddb,dMdpk =Â G2pwd.getBackgroundDerv(hfx,parmDict,bakType,x) |
---|
3159 |   if hfx+'Back:0' in varylist: # for now assume that Back:x vars to not appear in constraints |
---|
3160 | Â Â Â Â bBpos =varylist.index(hfx+'Back:0') |
---|
3161 | Â Â Â Â dMdv[bBpos:bBpos+len(dMdb)]Â =Â dMdb |
---|
3162 | Â Â names =Â [hfx+'DebyeA',hfx+'DebyeR',hfx+'DebyeU'] |
---|
3163 |   for name in varylist: |
---|
3164 |     if 'Debye' in name: |
---|
3165 |       id = int(name.split(':')[-1]) |
---|
3166 | Â Â Â Â Â Â parm =Â name[:int(name.rindex(':'))] |
---|
3167 | Â Â Â Â Â Â ip =Â names.index(parm) |
---|
3168 | Â Â Â Â Â Â dMdv[varylist.index(name)]Â =Â dMddb[3*id+ip] |
---|
3169 | Â Â names =Â [hfx+'BkPkpos',hfx+'BkPkint',hfx+'BkPksig',hfx+'BkPkgam'] |
---|
3170 |   for name in varylist: |
---|
3171 |     if 'BkPk' in name: |
---|
3172 |       id = int(name.split(':')[-1]) |
---|
3173 | Â Â Â Â Â Â parm =Â name[:int(name.rindex(':'))] |
---|
3174 | Â Â Â Â Â Â ip =Â names.index(parm) |
---|
3175 | Â Â Â Â Â Â dMdv[varylist.index(name)]Â =Â dMdpk[4*id+ip] |
---|
3176 | Â Â cw =Â np.diff(x) |
---|
3177 | Â Â cw =Â np.append(cw,cw[-1]) |
---|
3178 |   if 'C' in calcControls[hfx+'histType']:  |
---|
3179 | Â Â Â Â shl =Â max(parmDict[hfx+'SH/L'],0.002) |
---|
3180 | Â Â Â Â Ka2 =Â False |
---|
3181 |     if hfx+'Lam1' in parmDict.keys(): |
---|
3182 | Â Â Â Â Â Â wave =Â parmDict[hfx+'Lam1'] |
---|
3183 | Â Â Â Â Â Â Ka2 =Â True |
---|
3184 | Â Â Â Â Â Â lamRatio =Â 360*(parmDict[hfx+'Lam2']-parmDict[hfx+'Lam1'])/(np.pi*parmDict[hfx+'Lam1']) |
---|
3185 | Â Â Â Â Â Â kRatio =Â parmDict[hfx+'I(L2)/I(L1)'] |
---|
3186 | Â Â Â Â else: |
---|
3187 | Â Â Â Â Â Â wave =Â parmDict[hfx+'Lam'] |
---|
3188 | Â Â else: |
---|
3189 |     print 'TOF Undefined at present' |
---|
3190 |     raise ValueError |
---|
3191 |   for phase in Histogram['Reflection Lists']: |
---|
3192 | Â Â Â Â refList =Â Histogram['Reflection Lists'][phase] |
---|
3193 | Â Â Â Â Phase =Â Phases[phase] |
---|
3194 | Â Â Â Â SGData =Â Phase['General']['SGData'] |
---|
3195 | Â Â Â Â pId =Â Phase['pId'] |
---|
3196 | Â Â Â Â pfx =Â '%d::'%(pId) |
---|
3197 | Â Â Â Â phfx =Â '%d:%d:'%(pId,hId) |
---|
3198 |     A = [parmDict[pfx+'A%d'%(i)] for i in range(6)] |
---|
3199 | Â Â Â Â G,g =Â G2lat.A2Gmat(A)Â Â Â Â #recip & real metric tensors |
---|
3200 | Â Â Â Â GA,GB =Â G2lat.Gmat2AB(G)Â Â #Orthogonalization matricies |
---|
3201 |     if not Phase['General'].get('doPawley'): |
---|
3202 | Â Â Â Â Â Â dFdvDict =Â StructureFactorDerv(refList,G,hfx,pfx,SGData,calcControls,parmDict) |
---|
3203 |     for iref,refl in enumerate(refList): |
---|
3204 |       if 'C' in calcControls[hfx+'histType']:    #CW powder |
---|
3205 | Â Â Â Â Â Â Â Â h,k,l =Â refl[:3] |
---|
3206 | Â Â Â Â Â Â Â Â dIdsh,dIdsp,dIdpola,dIdPO,dFdODF,dFdSA,dFdAb =Â GetIntensityDerv(refl,G,g,pfx,phfx,hfx,SGData,calcControls,parmDict) |
---|
3207 | Â Â Â Â Â Â Â Â Wd,fmin,fmax =Â G2pwd.getWidthsCW(refl[5],refl[6],refl[7],shl) |
---|
3208 | Â Â Â Â Â Â Â Â iBeg =Â np.searchsorted(x,refl[5]-fmin) |
---|
3209 | Â Â Â Â Â Â Â Â iFin =Â np.searchsorted(x,refl[5]+fmax) |
---|
3210 |         if not iBeg+iFin:    #peak below low limit - skip peak |
---|
3211 | Â Â Â Â Â Â Â Â Â Â continue |
---|
3212 |         elif not iBeg-iFin:   #peak above high limit - done |
---|
3213 | Â Â Â Â Â Â Â Â Â Â break |
---|
3214 | Â Â Â Â Â Â Â Â pos =Â refl[5] |
---|
3215 | Â Â Â Â Â Â Â Â tanth =Â tand(pos/2.0) |
---|
3216 | Â Â Â Â Â Â Â Â costh =Â cosd(pos/2.0) |
---|
3217 | Â Â Â Â Â Â Â Â lenBF =Â iFin-iBeg |
---|
3218 | Â Â Â Â Â Â Â Â dMdpk =Â np.zeros(shape=(6,lenBF)) |
---|
3219 | Â Â Â Â Â Â Â Â dMdipk =Â G2pwd.getdFCJVoigt3(refl[5],refl[6],refl[7],shl,x[iBeg:iFin]) |
---|
3220 |         for i in range(5): |
---|
3221 | Â Â Â Â Â Â Â Â Â Â dMdpk[i]Â +=Â 100.*cw[iBeg:iFin]*refl[13]*refl[9]*dMdipk[i] |
---|
3222 | Â Â Â Â Â Â Â Â dervDict =Â {'int':dMdpk[0],'pos':dMdpk[1],'sig':dMdpk[2],'gam':dMdpk[3],'shl':dMdpk[4],'L1/L2':np.zeros_like(dMdpk[0])} |
---|
3223 |         if Ka2: |
---|
3224 |           pos2 = refl[5]+lamRatio*tanth    # + 360/pi * Dlam/lam * tan(th) |
---|
3225 | Â Â Â Â Â Â Â Â Â Â iBeg2 =Â np.searchsorted(x,pos2-fmin) |
---|
3226 | Â Â Â Â Â Â Â Â Â Â iFin2 =Â np.searchsorted(x,pos2+fmax) |
---|
3227 |           if iBeg2-iFin2: |
---|
3228 | Â Â Â Â Â Â Â Â Â Â Â Â lenBF2 =Â iFin2-iBeg2 |
---|
3229 | Â Â Â Â Â Â Â Â Â Â Â Â dMdpk2 =Â np.zeros(shape=(6,lenBF2)) |
---|
3230 | Â Â Â Â Â Â Â Â Â Â Â Â dMdipk2 =Â G2pwd.getdFCJVoigt3(pos2,refl[6],refl[7],shl,x[iBeg2:iFin2]) |
---|
3231 |             for i in range(5): |
---|
3232 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â dMdpk2[i]Â =Â 100.*cw[iBeg2:iFin2]*refl[13]*refl[9]*kRatio*dMdipk2[i] |
---|
3233 | Â Â Â Â Â Â Â Â Â Â Â Â dMdpk2[5]Â =Â 100.*cw[iBeg2:iFin2]*refl[13]*dMdipk2[0] |
---|
3234 | Â Â Â Â Â Â Â Â Â Â Â Â dervDict2 =Â {'int':dMdpk2[0],'pos':dMdpk2[1],'sig':dMdpk2[2],'gam':dMdpk2[3],'shl':dMdpk2[4],'L1/L2':dMdpk2[5]*refl[9]} |
---|
3235 |         if Phase['General'].get('doPawley'): |
---|
3236 | Â Â Â Â Â Â Â Â Â Â dMdpw =Â np.zeros(len(x)) |
---|
3237 | Â Â Â Â Â Â Â Â Â Â try: |
---|
3238 | Â Â Â Â Â Â Â Â Â Â Â Â pIdx =Â pfx+'PWLref:'+str(pawleyLookup[pfx+'%d,%d,%d'%(h,k,l)]) |
---|
3239 | Â Â Â Â Â Â Â Â Â Â Â Â idx =Â varylist.index(pIdx) |
---|
3240 | Â Â Â Â Â Â Â Â Â Â Â Â dMdpw[iBeg:iFin]Â =Â dervDict['int']/refl[9] |
---|
3241 |             if Ka2: |
---|
3242 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â dMdpw[iBeg2:iFin2]Â +=Â dervDict2['int']/refl[9] |
---|
3243 | Â Â Â Â Â Â Â Â Â Â Â Â dMdv[idx]Â =Â dMdpw |
---|
3244 | Â Â Â Â Â Â Â Â Â Â except:Â # ValueError: |
---|
3245 | Â Â Â Â Â Â Â Â Â Â Â Â pass |
---|
3246 | Â Â Â Â Â Â Â Â dpdA,dpdw,dpdZ,dpdSh,dpdTr,dpdX,dpdY =Â GetReflPosDerv(refl,wave,A,hfx,calcControls,parmDict) |
---|
3247 | Â Â Â Â Â Â Â Â names =Â {hfx+'Scale':[dIdsh,'int'],hfx+'Polariz.':[dIdpola,'int'],phfx+'Scale':[dIdsp,'int'], |
---|
3248 | Â Â Â Â Â Â Â Â Â Â hfx+'U':[tanth**2,'sig'],hfx+'V':[tanth,'sig'],hfx+'W':[1.0,'sig'], |
---|
3249 | Â Â Â Â Â Â Â Â Â Â hfx+'X':[1.0/costh,'gam'],hfx+'Y':[tanth,'gam'],hfx+'SH/L':[1.0,'shl'], |
---|
3250 | Â Â Â Â Â Â Â Â Â Â hfx+'I(L2)/I(L1)':[1.0,'L1/L2'],hfx+'Zero':[dpdZ,'pos'],hfx+'Lam':[dpdw,'pos'], |
---|
3251 | Â Â Â Â Â Â Â Â Â Â hfx+'Shift':[dpdSh,'pos'],hfx+'Transparency':[dpdTr,'pos'],hfx+'DisplaceX':[dpdX,'pos'], |
---|
3252 | Â Â Â Â Â Â Â Â Â Â hfx+'DisplaceY':[dpdY,'pos'],hfx+'Absorption':[dFdAb,'int'],} |
---|
3253 |         for name in names: |
---|
3254 | Â Â Â Â Â Â Â Â Â Â item =Â names[name] |
---|
3255 |           if name in varylist: |
---|
3256 | Â Â Â Â Â Â Â Â Â Â Â Â dMdv[varylist.index(name)][iBeg:iFin]Â +=Â item[0]*dervDict[item[1]] |
---|
3257 |             if Ka2: |
---|
3258 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â dMdv[varylist.index(name)][iBeg2:iFin2]Â +=Â item[0]*dervDict2[item[1]] |
---|
3259 |           elif name in dependentVars: |
---|
3260 |             if Ka2: |
---|
3261 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â depDerivDict[name][iBeg2:iFin2]Â +=Â item[0]*dervDict2[item[1]] |
---|
3262 | Â Â Â Â Â Â Â Â Â Â Â Â depDerivDict[name][iBeg:iFin]Â +=Â item[0]*dervDict[item[1]] |
---|
3263 |         for iPO in dIdPO: |
---|
3264 |           if iPO in varylist: |
---|
3265 | Â Â Â Â Â Â Â Â Â Â Â Â dMdv[varylist.index(iPO)][iBeg:iFin]Â +=Â dIdPO[iPO]*dervDict['int'] |
---|
3266 |             if Ka2: |
---|
3267 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â dMdv[varylist.index(iPO)][iBeg2:iFin2]Â +=Â dIdPO[iPO]*dervDict2['int'] |
---|
3268 |           elif iPO in dependentVars: |
---|
3269 | Â Â Â Â Â Â Â Â Â Â Â Â depDerivDict[iPO][iBeg:iFin]Â +=Â dIdPO[iPO]*dervDict['int'] |
---|
3270 |             if Ka2: |
---|
3271 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â depDerivDict[iPO][iBeg2:iFin2]Â +=Â dIdPO[iPO]*dervDict2['int'] |
---|
3272 |         for i,name in enumerate(['omega','chi','phi']): |
---|
3273 | Â Â Â Â Â Â Â Â Â Â aname =Â pfx+'SH '+name |
---|
3274 |           if aname in varylist: |
---|
3275 | Â Â Â Â Â Â Â Â Â Â Â Â dMdv[varylist.index(aname)][iBeg:iFin]Â +=Â dFdSA[i]*dervDict['int'] |
---|
3276 |             if Ka2: |
---|
3277 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â dMdv[varylist.index(aname)][iBeg2:iFin2]Â +=Â dFdSA[i]*dervDict2['int'] |
---|
3278 |           elif aname in dependentVars: |
---|
3279 | Â Â Â Â Â Â Â Â Â Â Â Â depDerivDict[aname][iBeg:iFin]Â +=Â dFdSA[i]*dervDict['int'] |
---|
3280 |             if Ka2: |
---|
3281 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â depDerivDict[aname][iBeg2:iFin2]Â +=Â dFdSA[i]*dervDict2['int'] |
---|
3282 |         for iSH in dFdODF: |
---|
3283 |           if iSH in varylist: |
---|
3284 | Â Â Â Â Â Â Â Â Â Â Â Â dMdv[varylist.index(iSH)][iBeg:iFin]Â +=Â dFdODF[iSH]*dervDict['int'] |
---|
3285 |             if Ka2: |
---|
3286 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â dMdv[varylist.index(iSH)][iBeg2:iFin2]Â +=Â dFdODF[iSH]*dervDict2['int'] |
---|
3287 |           elif iSH in dependentVars: |
---|
3288 | Â Â Â Â Â Â Â Â Â Â Â Â depDerivDict[iSH][iBeg:iFin]Â +=Â dFdODF[iSH]*dervDict['int'] |
---|
3289 |             if Ka2: |
---|
3290 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â depDerivDict[iSH][iBeg2:iFin2]Â +=Â dFdODF[iSH]*dervDict2['int'] |
---|
3291 | Â Â Â Â Â Â Â Â cellDervNames =Â cellVaryDerv(pfx,SGData,dpdA) |
---|
3292 |         for name,dpdA in cellDervNames: |
---|
3293 |           if name in varylist: |
---|
3294 | Â Â Â Â Â Â Â Â Â Â Â Â dMdv[varylist.index(name)][iBeg:iFin]Â +=Â dpdA*dervDict['pos'] |
---|
3295 |             if Ka2: |
---|
3296 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â dMdv[varylist.index(name)][iBeg2:iFin2]Â +=Â dpdA*dervDict2['pos'] |
---|
3297 |           elif name in dependentVars: |
---|
3298 | Â Â Â Â Â Â Â Â Â Â Â Â depDerivDict[name][iBeg:iFin]Â +=Â dpdA*dervDict['pos'] |
---|
3299 |             if Ka2: |
---|
3300 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â depDerivDict[name][iBeg2:iFin2]Â +=Â dpdA*dervDict2['pos'] |
---|
3301 | Â Â Â Â Â Â Â Â dDijDict =Â GetHStrainShiftDerv(refl,SGData,phfx) |
---|
3302 |         for name in dDijDict: |
---|
3303 |           if name in varylist: |
---|
3304 | Â Â Â Â Â Â Â Â Â Â Â Â dMdv[varylist.index(name)][iBeg:iFin]Â +=Â dDijDict[name]*dervDict['pos'] |
---|
3305 |             if Ka2: |
---|
3306 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â dMdv[varylist.index(name)][iBeg2:iFin2]Â +=Â dDijDict[name]*dervDict2['pos'] |
---|
3307 |           elif name in dependentVars: |
---|
3308 | Â Â Â Â Â Â Â Â Â Â Â Â depDerivDict[name][iBeg:iFin]Â +=Â dDijDict[name]*dervDict['pos'] |
---|
3309 |             if Ka2: |
---|
3310 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â depDerivDict[name][iBeg2:iFin2]Â +=Â dDijDict[name]*dervDict2['pos'] |
---|
3311 | Â Â Â Â Â Â Â Â sigDict,gamDict =Â GetSampleSigGamDerv(refl,wave,G,GB,phfx,calcControls,parmDict) |
---|
3312 |         for name in gamDict: |
---|
3313 |           if name in varylist: |
---|
3314 | Â Â Â Â Â Â Â Â Â Â Â Â dMdv[varylist.index(name)][iBeg:iFin]Â +=Â gamDict[name]*dervDict['gam'] |
---|
3315 |             if Ka2: |
---|
3316 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â dMdv[varylist.index(name)][iBeg2:iFin2]Â +=Â gamDict[name]*dervDict2['gam'] |
---|
3317 |           elif name in dependentVars: |
---|
3318 | Â Â Â Â Â Â Â Â Â Â Â Â depDerivDict[name][iBeg:iFin]Â +=Â gamDict[name]*dervDict['gam'] |
---|
3319 |             if Ka2: |
---|
3320 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â depDerivDict[name][iBeg2:iFin2]Â +=Â gamDict[name]*dervDict2['gam'] |
---|
3321 |         for name in sigDict: |
---|
3322 |           if name in varylist: |
---|
3323 | Â Â Â Â Â Â Â Â Â Â Â Â dMdv[varylist.index(name)][iBeg:iFin]Â +=Â sigDict[name]*dervDict['sig'] |
---|
3324 |             if Ka2: |
---|
3325 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â dMdv[varylist.index(name)][iBeg2:iFin2]Â +=Â sigDict[name]*dervDict2['sig'] |
---|
3326 |           elif name in dependentVars: |
---|
3327 | Â Â Â Â Â Â Â Â Â Â Â Â depDerivDict[name][iBeg:iFin]Â +=Â sigDict[name]*dervDict['sig'] |
---|
3328 |             if Ka2: |
---|
3329 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â depDerivDict[name][iBeg2:iFin2]Â +=Â sigDict[name]*dervDict2['sig'] |
---|
3330 |         for name in ['BabA','BabU']: |
---|
3331 |           if phfx+name in varylist: |
---|
3332 | Â Â Â Â Â Â Â Â Â Â Â Â dMdv[varylist.index(phfx+name)][iBeg:iFin]Â +=Â dFdvDict[pfx+name][iref]*dervDict['int']*cw[iBeg:iFin] |
---|
3333 |             if Ka2: |
---|
3334 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â dMdv[varylist.index(phfx+name)][iBeg2:iFin2]Â +=Â dFdvDict[pfx+name][iref]*dervDict2['int']*cw[iBeg2:iFin2] |
---|
3335 |           elif phfx+name in dependentVars:          |
---|
3336 | Â Â Â Â Â Â Â Â Â Â Â Â depDerivDict[phfx+name][iBeg:iFin]Â +=Â dFdvDict[pfx+name][iref]*dervDict['int']*cw[iBeg:iFin] |
---|
3337 |             if Ka2: |
---|
3338 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â depDerivDict[phfx+name][iBeg2:iFin2]Â +=Â dFdvDict[pfx+name][iref]*dervDict2['int']*cw[iBeg2:iFin2]Â Â Â Â Â Â Â Â Â |
---|
3339 |       elif 'T' in calcControls[hfx+'histType']: |
---|
3340 |         print 'TOF Undefined at present' |
---|
3341 |         raise Exception  #no TOF yet |
---|
3342 |       #do atom derivatives - for F,X & U so far       |
---|
3343 | Â Â Â Â Â Â corr =Â dervDict['int']/refl[9] |
---|
3344 |       if Ka2: |
---|
3345 | Â Â Â Â Â Â Â Â corr2 =Â dervDict2['int']/refl[9] |
---|
3346 |       for name in varylist+dependentVars: |
---|
3347 | Â Â Â Â Â Â Â Â try: |
---|
3348 | Â Â Â Â Â Â Â Â Â Â aname =Â name.split(pfx)[1][:2] |
---|
3349 |           if aname not in ['Af','dA','AU']: continue # skip anything not an atom param |
---|
3350 |         except IndexError: |
---|
3351 | Â Â Â Â Â Â Â Â Â Â continue |
---|
3352 |         if name in varylist: |
---|
3353 | Â Â Â Â Â Â Â Â Â Â dMdv[varylist.index(name)][iBeg:iFin]Â +=Â dFdvDict[name][iref]*corr |
---|
3354 |           if Ka2: |
---|
3355 | Â Â Â Â Â Â Â Â Â Â Â Â dMdv[varylist.index(name)][iBeg2:iFin2]Â +=Â dFdvDict[name][iref]*corr2 |
---|
3356 |         elif name in dependentVars: |
---|
3357 | Â Â Â Â Â Â Â Â Â Â depDerivDict[name][iBeg:iFin]Â +=Â dFdvDict[name][iref]*corr |
---|
3358 |           if Ka2: |
---|
3359 | Â Â Â Â Â Â Â Â Â Â Â Â depDerivDict[name][iBeg2:iFin2]Â +=Â dFdvDict[name][iref]*corr2 |
---|
3360 | Â Â # now process derivatives in constraints |
---|
3361 | Â Â G2mv.Dict2Deriv(varylist,depDerivDict,dMdv) |
---|
3362 |   return dMdv |
---|
3363 | |
---|
3364 | def dervRefine(values,HistoPhases,parmdict,varylist,calcControls,pawleyLookup,dlg): |
---|
3365 | Â Â parmdict.update(zip(varylist,values)) |
---|
3366 | Â Â G2mv.Dict2Map(parmdict,varylist) |
---|
3367 | Â Â Histograms,Phases,restraintDict =Â HistoPhases |
---|
3368 | Â Â nvar =Â len(varylist) |
---|
3369 | Â Â dMdv =Â np.empty(0) |
---|
3370 | Â Â histoList =Â Histograms.keys() |
---|
3371 | Â Â histoList.sort() |
---|
3372 |   for histogram in histoList: |
---|
3373 |     if 'PWDR' in histogram[:4]: |
---|
3374 | Â Â Â Â Â Â Histogram =Â Histograms[histogram] |
---|
3375 | Â Â Â Â Â Â hId =Â Histogram['hId'] |
---|
3376 | Â Â Â Â Â Â hfx =Â ':%d:'%(hId) |
---|
3377 | Â Â Â Â Â Â wtFactor =Â calcControls[hfx+'wtFactor'] |
---|
3378 | Â Â Â Â Â Â Limits =Â calcControls[hfx+'Limits'] |
---|
3379 | Â Â Â Â Â Â x,y,w,yc,yb,yd =Â Histogram['Data'] |
---|
3380 | Â Â Â Â Â Â W =Â wtFactor*w |
---|
3381 | Â Â Â Â Â Â xB =Â np.searchsorted(x,Limits[0]) |
---|
3382 | Â Â Â Â Â Â xF =Â np.searchsorted(x,Limits[1]) |
---|
3383 | Â Â Â Â Â Â dMdvh =Â np.sqrt(W[xB:xF])*getPowderProfileDerv(parmdict,x[xB:xF], |
---|
3384 | Â Â Â Â Â Â Â Â varylist,Histogram,Phases,calcControls,pawleyLookup) |
---|
3385 |     elif 'HKLF' in histogram[:4]: |
---|
3386 | Â Â Â Â Â Â Histogram =Â Histograms[histogram] |
---|
3387 | Â Â Â Â Â Â nobs =Â Histogram['Nobs'] |
---|
3388 | Â Â Â Â Â Â phase =Â Histogram['Reflection Lists'] |
---|
3389 | Â Â Â Â Â Â Phase =Â Phases[phase] |
---|
3390 | Â Â Â Â Â Â hId =Â Histogram['hId'] |
---|
3391 | Â Â Â Â Â Â hfx =Â ':%d:'%(hId) |
---|
3392 | Â Â Â Â Â Â wtFactor =Â calcControls[hfx+'wtFactor'] |
---|
3393 | Â Â Â Â Â Â pfx =Â '%d::'%(Phase['pId']) |
---|
3394 | Â Â Â Â Â Â phfx =Â '%d:%d:'%(Phase['pId'],hId) |
---|
3395 | Â Â Â Â Â Â SGData =Â Phase['General']['SGData'] |
---|
3396 |       A = [parmdict[pfx+'A%d'%(i)] for i in range(6)] |
---|
3397 | Â Â Â Â Â Â G,g =Â G2lat.A2Gmat(A)Â Â Â Â #recip & real metric tensors |
---|
3398 | Â Â Â Â Â Â refList =Â Histogram['Data'] |
---|
3399 | Â Â Â Â Â Â dFdvDict =Â StructureFactorDerv(refList,G,hfx,pfx,SGData,calcControls,parmdict) |
---|
3400 | Â Â Â Â Â Â dMdvh =Â np.zeros((len(varylist),len(refList))) |
---|
3401 |       for iref,ref in enumerate(refList): |
---|
3402 |         if ref[6] > 0: |
---|
3403 | Â Â Â Â Â Â Â Â Â Â dervCor,dervDict =Â SCExtinction(ref,phfx,hfx,pfx,calcControls,parmdict,varylist)Â #puts correction in refl[13] |
---|
3404 |           if calcControls['F**2']: |
---|
3405 |             if ref[5]/ref[6] >= calcControls['minF/sig']: |
---|
3406 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â w =Â wtFactor/ref[6] |
---|
3407 |               for j,var in enumerate(varylist): |
---|
3408 |                 if var in dFdvDict: |
---|
3409 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â dMdvh[j][iref]Â =Â w*dFdvDict[var][iref]*dervCor |
---|
3410 |               if phfx+'Scale' in varylist: |
---|
3411 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â dMdvh[varylist.index(phfx+'Scale')][iref]Â =Â w*ref[9]*dervCor |
---|
3412 | Â Â Â Â Â Â Â Â Â Â else: |
---|
3413 | Â Â Â Â Â Â Â Â Â Â Â Â Fo =Â np.sqrt(ref[5]) |
---|
3414 | Â Â Â Â Â Â Â Â Â Â Â Â Fc =Â np.sqrt(ref[7]) |
---|
3415 | Â Â Â Â Â Â Â Â Â Â Â Â sig =Â ref[6]/(2.0*Fo) |
---|
3416 |             if Fo/sig >= calcControls['minF/sig']: |
---|
3417 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â w =Â wtFactor/sig |
---|
3418 |               for j,var in enumerate(varylist): |
---|
3419 |                 if var in dFdvDict: |
---|
3420 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â dMdvh[j][iref]Â =Â w*dFdvDict[var][iref]*np.sqrt(dervCor) |
---|
3421 |               if phfx+'Scale' in varylist: |
---|
3422 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â dMdvh[varylist.index(phfx+'Scale')][iref]Â =Â w*ref[9]*np.sqrt(dervCor)Â Â Â Â Â Â Â Â Â Â Â Â Â Â |
---|
3423 |           for item in ['Ep','Es','Eg']: |
---|
3424 |             if phfx+item in varylist: |
---|
3425 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â dMdvh[varylist.index(phfx+item)][iref]Â =Â w*dervDict[phfx+item] |
---|
3426 | Â Â Â Â else: |
---|
3427 |       continue    #skip non-histogram entries |
---|
3428 |     if len(dMdv): |
---|
3429 | Â Â Â Â Â Â dMdv =Â np.concatenate((dMdv.T,dMdvh.T)).T |
---|
3430 | Â Â Â Â else: |
---|
3431 | Â Â Â Â Â Â dMdv =Â dMdvh |
---|
3432 | Â Â Â Â Â Â |
---|
3433 | Â Â pNames,pVals,pWt =Â penaltyFxn(HistoPhases,parmdict,varylist) |
---|
3434 |   if np.any(pVals): |
---|
3435 | Â Â Â Â dpdv =Â penaltyDeriv(pNames,pVals,HistoPhases,parmdict,varylist) |
---|
3436 | Â Â Â Â dMdv =Â np.concatenate((dMdv.T,dpdv.T)).T |
---|
3437 | Â Â Â Â |
---|
3438 |   return dMdv |
---|
3439 | |
---|
3440 | def HessRefine(values,HistoPhases,parmdict,varylist,calcControls,pawleyLookup,dlg): |
---|
3441 | Â Â parmdict.update(zip(varylist,values)) |
---|
3442 | Â Â G2mv.Dict2Map(parmdict,varylist) |
---|
3443 | Â Â Histograms,Phases,restraintDict =Â HistoPhases |
---|
3444 | Â Â nvar =Â len(varylist) |
---|
3445 | Â Â Hess =Â np.empty(0) |
---|
3446 | Â Â histoList =Â Histograms.keys() |
---|
3447 | Â Â histoList.sort() |
---|
3448 |   for histogram in histoList: |
---|
3449 |     if 'PWDR' in histogram[:4]: |
---|
3450 | Â Â Â Â Â Â Histogram =Â Histograms[histogram] |
---|
3451 | Â Â Â Â Â Â hId =Â Histogram['hId'] |
---|
3452 | Â Â Â Â Â Â hfx =Â ':%d:'%(hId) |
---|
3453 | Â Â Â Â Â Â wtFactor =Â calcControls[hfx+'wtFactor'] |
---|
3454 | Â Â Â Â Â Â Limits =Â calcControls[hfx+'Limits'] |
---|
3455 | Â Â Â Â Â Â x,y,w,yc,yb,yd =Â Histogram['Data'] |
---|
3456 | Â Â Â Â Â Â W =Â wtFactor*w |
---|
3457 | Â Â Â Â Â Â dy =Â y-yc |
---|
3458 | Â Â Â Â Â Â xB =Â np.searchsorted(x,Limits[0]) |
---|
3459 | Â Â Â Â Â Â xF =Â np.searchsorted(x,Limits[1]) |
---|
3460 | Â Â Â Â Â Â dMdvh =Â getPowderProfileDerv(parmdict,x[xB:xF], |
---|
3461 | Â Â Â Â Â Â Â Â varylist,Histogram,Phases,calcControls,pawleyLookup) |
---|
3462 | Â Â Â Â Â Â Wt =Â np.sqrt(W[xB:xF])[np.newaxis,:] |
---|
3463 | Â Â Â Â Â Â Dy =Â dy[xB:xF][np.newaxis,:] |
---|
3464 | Â Â Â Â Â Â dMdvh *=Â Wt |
---|
3465 |       if dlg: |
---|
3466 | Â Â Â Â Â Â Â Â dlg.Update(Histogram['wR'],newmsg='Hessian for histogram %d\nAll data Rw=%8.3f%s'%(hId,Histogram['wR'],'%'))[0] |
---|
3467 |       if len(Hess): |
---|
3468 | Â Â Â Â Â Â Â Â Hess +=Â np.inner(dMdvh,dMdvh) |
---|
3469 | Â Â Â Â Â Â Â Â dMdvh *=Â Wt*Dy |
---|
3470 | Â Â Â Â Â Â Â Â Vec +=Â np.sum(dMdvh,axis=1) |
---|
3471 | Â Â Â Â Â Â else: |
---|
3472 | Â Â Â Â Â Â Â Â Hess =Â np.inner(dMdvh,dMdvh) |
---|
3473 | Â Â Â Â Â Â Â Â dMdvh *=Â Wt*Dy |
---|
3474 | Â Â Â Â Â Â Â Â Vec =Â np.sum(dMdvh,axis=1) |
---|
3475 |     elif 'HKLF' in histogram[:4]: |
---|
3476 | Â Â Â Â Â Â Histogram =Â Histograms[histogram] |
---|
3477 | Â Â Â Â Â Â nobs =Â Histogram['Nobs'] |
---|
3478 | Â Â Â Â Â Â phase =Â Histogram['Reflection Lists'] |
---|
3479 | Â Â Â Â Â Â Phase =Â Phases[phase] |
---|
3480 | Â Â Â Â Â Â hId =Â Histogram['hId'] |
---|
3481 | Â Â Â Â Â Â hfx =Â ':%d:'%(hId) |
---|
3482 | Â Â Â Â Â Â wtFactor =Â calcControls[hfx+'wtFactor'] |
---|
3483 | Â Â Â Â Â Â pfx =Â '%d::'%(Phase['pId']) |
---|
3484 | Â Â Â Â Â Â phfx =Â '%d:%d:'%(Phase['pId'],hId) |
---|
3485 | Â Â Â Â Â Â SGData =Â Phase['General']['SGData'] |
---|
3486 |       A = [parmdict[pfx+'A%d'%(i)] for i in range(6)] |
---|
3487 | Â Â Â Â Â Â G,g =Â G2lat.A2Gmat(A)Â Â Â Â #recip & real metric tensors |
---|
3488 | Â Â Â Â Â Â refList =Â Histogram['Data'] |
---|
3489 | Â Â Â Â Â Â dFdvDict =Â StructureFactorDerv(refList,G,hfx,pfx,SGData,calcControls,parmdict) |
---|
3490 | Â Â Â Â Â Â dMdvh =Â np.zeros((len(varylist),len(refList))) |
---|
3491 | Â Â Â Â Â Â wdf =Â np.zeros(len(refList)) |
---|
3492 |       for iref,ref in enumerate(refList): |
---|
3493 |         if ref[6] > 0: |
---|
3494 | Â Â Â Â Â Â Â Â Â Â dervCor,dervDict =Â SCExtinction(ref,phfx,hfx,pfx,calcControls,parmdict,varylist)Â #puts correction in refl[13] |
---|
3495 |           if calcControls['F**2']: |
---|
3496 |             if ref[5]/ref[6] >= calcControls['minF/sig']: |
---|
3497 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â w =Â wtFactor/ref[6] |
---|
3498 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â wdf[iref]Â =Â w*(ref[5]-ref[7]) |
---|
3499 |               for j,var in enumerate(varylist): |
---|
3500 |                 if var in dFdvDict: |
---|
3501 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â dMdvh[j][iref]Â =Â w*dFdvDict[var][iref]*dervCor |
---|
3502 |               if phfx+'Scale' in varylist: |
---|
3503 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â dMdvh[varylist.index(phfx+'Scale')][iref]Â =Â w*ref[9]*dervCor |
---|
3504 | Â Â Â Â Â Â Â Â Â Â else: |
---|
3505 |             if ref[5] > 0.: |
---|
3506 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Fo =Â np.sqrt(ref[5]) |
---|
3507 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Fc =Â np.sqrt(ref[7]) |
---|
3508 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â sig =Â ref[6]/(2.0*Fo) |
---|
3509 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â w =Â wtFactor/sig |
---|
3510 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â wdf[iref]Â =Â w*(Fo-Fc) |
---|
3511 |               if Fo/sig >= calcControls['minF/sig']: |
---|
3512 |                 for j,var in enumerate(varylist): |
---|
3513 |                   if var in dFdvDict: |
---|
3514 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â dMdvh[j][iref]Â =Â w*dFdvDict[var][iref]*np.sqrt(dervCor) |
---|
3515 |                 if phfx+'Scale' in varylist: |
---|
3516 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â dMdvh[varylist.index(phfx+'Scale')][iref]Â =Â w*ref[9]*np.sqrt(dervCor)Â Â Â Â Â Â Â Â Â Â Â Â Â Â |
---|
3517 |           for item in ['Ep','Es','Eg']: |
---|
3518 |             if phfx+item in varylist: |
---|
3519 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â dMdvh[varylist.index(phfx+item)][iref]Â =Â w*dervDict[phfx+item] |
---|
3520 |       if dlg: |
---|
3521 |         dlg.Update(Histogram['wR'],newmsg='Hessian for histogram %d Rw=%8.3f%s'%(hId,Histogram['wR'],'%'))[0] |
---|
3522 |       if len(Hess): |
---|
3523 | Â Â Â Â Â Â Â Â Vec +=Â np.sum(dMdvh*wdf,axis=1) |
---|
3524 | Â Â Â Â Â Â Â Â Hess +=Â np.inner(dMdvh,dMdvh) |
---|
3525 | Â Â Â Â Â Â else: |
---|
3526 | Â Â Â Â Â Â Â Â Vec =Â np.sum(dMdvh*wdf,axis=1) |
---|
3527 | Â Â Â Â Â Â Â Â Hess =Â np.inner(dMdvh,dMdvh) |
---|
3528 | Â Â Â Â else: |
---|
3529 |       continue    #skip non-histogram entries |
---|
3530 | Â Â pNames,pVals,pWt =Â penaltyFxn(HistoPhases,parmdict,varylist) |
---|
3531 |   if np.any(pVals): |
---|
3532 | Â Â Â Â dpdv =Â penaltyDeriv(pNames,pVals,HistoPhases,parmdict,varylist) |
---|
3533 | Â Â Â Â Vec +=Â np.sum(dpdv*pWt*pVals,axis=1) |
---|
3534 | Â Â Â Â Hess +=Â np.inner(dpdv*pWt,dpdv) |
---|
3535 |   return Vec,Hess |
---|
3536 | |
---|
3537 | def errRefine(values,HistoPhases,parmdict,varylist,calcControls,pawleyLookup,dlg):    |
---|
3538 | Â Â parmdict.update(zip(varylist,values)) |
---|
3539 |   Values2Dict(parmdict, varylist, values) |
---|
3540 | Â Â G2mv.Dict2Map(parmdict,varylist) |
---|
3541 | Â Â Histograms,Phases,restraintDict =Â HistoPhases |
---|
3542 | Â Â M =Â np.empty(0) |
---|
3543 | Â Â SumwYo =Â 0 |
---|
3544 | Â Â Nobs =Â 0 |
---|
3545 | Â Â histoList =Â Histograms.keys() |
---|
3546 | Â Â histoList.sort() |
---|
3547 |   for histogram in histoList: |
---|
3548 |     if 'PWDR' in histogram[:4]: |
---|
3549 | Â Â Â Â Â Â Histogram =Â Histograms[histogram] |
---|
3550 | Â Â Â Â Â Â hId =Â Histogram['hId'] |
---|
3551 | Â Â Â Â Â Â hfx =Â ':%d:'%(hId) |
---|
3552 | Â Â Â Â Â Â wtFactor =Â calcControls[hfx+'wtFactor'] |
---|
3553 | Â Â Â Â Â Â Limits =Â calcControls[hfx+'Limits'] |
---|
3554 | Â Â Â Â Â Â x,y,w,yc,yb,yd =Â Histogram['Data'] |
---|
3555 | Â Â Â Â Â Â W =Â wtFactor*w |
---|
3556 | Â Â Â Â Â Â yc *=Â 0.0Â Â Â Â Â Â Â Â Â Â Â Â Â Â #zero full calcd profiles |
---|
3557 | Â Â Â Â Â Â yb *=Â 0.0 |
---|
3558 | Â Â Â Â Â Â yd *=Â 0.0 |
---|
3559 | Â Â Â Â Â Â xB =Â np.searchsorted(x,Limits[0]) |
---|
3560 | Â Â Â Â Â Â xF =Â np.searchsorted(x,Limits[1]) |
---|
3561 | Â Â Â Â Â Â Histogram['Nobs']Â =Â xF-xB |
---|
3562 | Â Â Â Â Â Â Nobs +=Â Histogram['Nobs'] |
---|
3563 | Â Â Â Â Â Â Histogram['sumwYo']Â =Â np.sum(W[xB:xF]*y[xB:xF]**2) |
---|
3564 | Â Â Â Â Â Â SumwYo +=Â Histogram['sumwYo'] |
---|
3565 | Â Â Â Â Â Â yc[xB:xF],yb[xB:xF]Â =Â getPowderProfile(parmdict,x[xB:xF], |
---|
3566 | Â Â Â Â Â Â Â Â varylist,Histogram,Phases,calcControls,pawleyLookup) |
---|
3567 | Â Â Â Â Â Â yc[xB:xF]Â +=Â yb[xB:xF] |
---|
3568 | Â Â Â Â Â Â yd[xB:xF]Â =Â y[xB:xF]-yc[xB:xF] |
---|
3569 | Â Â Â Â Â Â Histogram['sumwYd']Â =Â np.sum(np.sqrt(W[xB:xF])*(yd[xB:xF])) |
---|
3570 | Â Â Â Â Â Â wdy =Â -np.sqrt(W[xB:xF])*(yd[xB:xF]) |
---|
3571 | Â Â Â Â Â Â Histogram['wR']Â =Â min(100.,np.sqrt(np.sum(wdy**2)/Histogram['sumwYo'])*100.) |
---|
3572 |       if dlg: |
---|
3573 |         dlg.Update(Histogram['wR'],newmsg='For histogram %d Rw=%8.3f%s'%(hId,Histogram['wR'],'%'))[0] |
---|
3574 | Â Â Â Â Â Â M =Â np.concatenate((M,wdy)) |
---|
3575 | #end of PWDR processing |
---|
3576 |     elif 'HKLF' in histogram[:4]: |
---|
3577 | Â Â Â Â Â Â Histogram =Â Histograms[histogram] |
---|
3578 | Â Â Â Â Â Â phase =Â Histogram['Reflection Lists'] |
---|
3579 | Â Â Â Â Â Â Phase =Â Phases[phase] |
---|
3580 | Â Â Â Â Â Â hId =Â Histogram['hId'] |
---|
3581 | Â Â Â Â Â Â hfx =Â ':%d:'%(hId) |
---|
3582 | Â Â Â Â Â Â wtFactor =Â calcControls[hfx+'wtFactor'] |
---|
3583 | Â Â Â Â Â Â pfx =Â '%d::'%(Phase['pId']) |
---|
3584 | Â Â Â Â Â Â phfx =Â '%d:%d:'%(Phase['pId'],hId) |
---|
3585 | Â Â Â Â Â Â SGData =Â Phase['General']['SGData'] |
---|
3586 |       A = [parmdict[pfx+'A%d'%(i)] for i in range(6)] |
---|
3587 | Â Â Â Â Â Â G,g =Â G2lat.A2Gmat(A)Â Â Â Â #recip & real metric tensors |
---|
3588 | Â Â Â Â Â Â refList =Â Histogram['Data'] |
---|
3589 | Â Â Â Â Â Â refList =Â StructureFactor(refList,G,hfx,pfx,SGData,calcControls,parmdict) |
---|
3590 | Â Â Â Â Â Â df =Â np.zeros(len(refList)) |
---|
3591 | Â Â Â Â Â Â sumwYo =Â 0 |
---|
3592 | Â Â Â Â Â Â sumFo =Â 0 |
---|
3593 | Â Â Â Â Â Â sumFo2 =Â 0 |
---|
3594 | Â Â Â Â Â Â sumdF =Â 0 |
---|
3595 | Â Â Â Â Â Â sumdF2 =Â 0 |
---|
3596 | Â Â Â Â Â Â nobs =Â 0 |
---|
3597 |       for i,ref in enumerate(refList): |
---|
3598 |         if ref[6] > 0: |
---|
3599 | Â Â Â Â Â Â Â Â Â Â SCExtinction(ref,phfx,hfx,pfx,calcControls,parmdict,varylist)Â #puts correction in refl[13] |
---|
3600 | Â Â Â Â Â Â Â Â Â Â ref[7]Â =Â parmdict[phfx+'Scale']*ref[9] |
---|
3601 | Â Â Â Â Â Â Â Â Â Â ref[7]Â *=Â ref[13] |
---|
3602 | Â Â Â Â Â Â Â Â Â Â ref[8]Â =Â ref[5]/parmdict[phfx+'Scale'] |
---|
3603 |           if calcControls['F**2']: |
---|
3604 |             if ref[5]/ref[6] >= calcControls['minF/sig']: |
---|
3605 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â sumFo2 +=Â ref[5] |
---|
3606 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Fo =Â np.sqrt(ref[5]) |
---|
3607 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â sumFo +=Â Fo |
---|
3608 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â sumFo2 +=Â ref[5] |
---|
3609 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â sumdF +=Â abs(Fo-np.sqrt(ref[7])) |
---|
3610 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â sumdF2 +=Â abs(ref[5]-ref[7]) |
---|
3611 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â nobs +=Â 1 |
---|
3612 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â df[i]Â =Â -np.sqrt(wtFactor)*(ref[5]-ref[7])/ref[6] |
---|
3613 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â sumwYo +=Â wtFactor*(ref[5]/ref[6])**2 |
---|
3614 | Â Â Â Â Â Â Â Â Â Â else: |
---|
3615 | Â Â Â Â Â Â Â Â Â Â Â Â Fo =Â np.sqrt(ref[5]) |
---|
3616 | Â Â Â Â Â Â Â Â Â Â Â Â Fc =Â np.sqrt(ref[7]) |
---|
3617 | Â Â Â Â Â Â Â Â Â Â Â Â sig =Â ref[6]/(2.0*Fo) |
---|
3618 |             if Fo/sig >= calcControls['minF/sig']: |
---|
3619 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â sumFo +=Â Fo |
---|
3620 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â sumFo2 +=Â ref[5] |
---|
3621 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â sumdF +=Â abs(Fo-Fc) |
---|
3622 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â sumdF2 +=Â abs(ref[5]-ref[7]) |
---|
3623 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â nobs +=Â 1 |
---|
3624 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â df[i]Â =Â -np.sqrt(wtFactor)*(Fo-Fc)/sig |
---|
3625 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â sumwYo +=Â wtFactor*(Fo/sig)**2 |
---|
3626 | Â Â Â Â Â Â Histogram['Nobs']Â =Â nobs |
---|
3627 | Â Â Â Â Â Â Histogram['sumwYo']Â =Â sumwYo |
---|
3628 | Â Â Â Â Â Â SumwYo +=Â sumwYo |
---|
3629 | Â Â Â Â Â Â Histogram['wR']Â =Â min(100.,np.sqrt(np.sum(df**2)/Histogram['sumwYo'])*100.) |
---|
3630 | Â Â Â Â Â Â Histogram[phfx+'Rf']Â =Â 100.*sumdF/sumFo |
---|
3631 | Â Â Â Â Â Â Histogram[phfx+'Rf^2']Â =Â 100.*sumdF2/sumFo2 |
---|
3632 | Â Â Â Â Â Â Histogram[phfx+'Nref']Â =Â nobs |
---|
3633 | Â Â Â Â Â Â Nobs +=Â nobs |
---|
3634 |       if dlg: |
---|
3635 |         dlg.Update(Histogram['wR'],newmsg='For histogram %d Rw=%8.3f%s'%(hId,Histogram['wR'],'%'))[0] |
---|
3636 | Â Â Â Â Â Â M =Â np.concatenate((M,df)) |
---|
3637 | # end of HKLF processing |
---|
3638 | Â Â Histograms['sumwYo']Â =Â SumwYo |
---|
3639 | Â Â Histograms['Nobs']Â =Â Nobs |
---|
3640 | Â Â Rw =Â min(100.,np.sqrt(np.sum(M**2)/SumwYo)*100.) |
---|
3641 |   if dlg: |
---|
3642 | Â Â Â Â GoOn =Â dlg.Update(Rw,newmsg='%s%8.3f%s'%('All data Rw =',Rw,'%'))[0] |
---|
3643 |     if not GoOn: |
---|
3644 | Â Â Â Â Â Â parmdict['saved values']Â =Â values |
---|
3645 | Â Â Â Â Â Â dlg.Destroy() |
---|
3646 |       raise Exception     #Abort!! |
---|
3647 | Â Â pDict,pVals,pWt =Â penaltyFxn(HistoPhases,parmdict,varylist) |
---|
3648 |   if np.any(pVals): |
---|
3649 | Â Â Â Â pSum =Â np.sum(pWt*pVals**2) |
---|
3650 |     print 'Penalty function: %.3f on %d terms'%(pSum,len(pVals)) |
---|
3651 | Â Â Â Â Nobs +=Â len(pVals) |
---|
3652 | Â Â Â Â M =Â np.concatenate((M,np.sqrt(pWt)*pVals)) |
---|
3653 |   return M |
---|
3654 | Â Â Â Â Â Â Â Â Â Â Â Â |
---|
3655 | def Refine(GPXfile,dlg): |
---|
3656 |   import pytexture as ptx |
---|
3657 | Â Â ptx.pyqlmninit()Â Â Â Â Â Â #initialize fortran arrays for spherical harmonics |
---|
3658 | Â Â |
---|
3659 | Â Â printFile =Â open(ospath.splitext(GPXfile)[0]+'.lst','w') |
---|
3660 | Â Â ShowBanner(printFile) |
---|
3661 | Â Â varyList =Â [] |
---|
3662 | Â Â parmDict =Â {} |
---|
3663 | Â Â G2mv.InitVars()Â Â |
---|
3664 | Â Â Controls =Â GetControls(GPXfile) |
---|
3665 | Â Â ShowControls(Controls,printFile) |
---|
3666 | Â Â calcControls =Â {} |
---|
3667 | Â Â calcControls.update(Controls)Â Â Â Â Â Â |
---|
3668 | Â Â constrDict,fixedList =Â GetConstraints(GPXfile) |
---|
3669 | Â Â restraintDict =Â GetRestraints(GPXfile) |
---|
3670 | Â Â rigidbodyDict =Â GetRigidBodies(GPXfile) |
---|
3671 | Â Â Histograms,Phases =Â GetUsedHistogramsAndPhases(GPXfile) |
---|
3672 |   if not Phases: |
---|
3673 |     print ' *** ERROR - you have no phases! ***' |
---|
3674 |     print ' *** Refine aborted ***' |
---|
3675 |     raise Exception |
---|
3676 |   if not Histograms: |
---|
3677 |     print ' *** ERROR - you have no data to refine with! ***' |
---|
3678 |     print ' *** Refine aborted ***' |
---|
3679 |     raise Exception    |
---|
3680 | Â Â Natoms,atomIndx,phaseVary,phaseDict,pawleyLookup,FFtables,BLtables =Â GetPhaseData(Phases,restraintDict,pFile=printFile) |
---|
3681 | Â Â calcControls['atomIndx']Â =Â atomIndx |
---|
3682 | Â Â calcControls['Natoms']Â =Â Natoms |
---|
3683 | Â Â calcControls['FFtables']Â =Â FFtables |
---|
3684 | Â Â calcControls['BLtables']Â =Â BLtables |
---|
3685 | Â Â hapVary,hapDict,controlDict =Â GetHistogramPhaseData(Phases,Histograms,pFile=printFile) |
---|
3686 | Â Â calcControls.update(controlDict) |
---|
3687 | Â Â histVary,histDict,controlDict =Â GetHistogramData(Histograms,pFile=printFile) |
---|
3688 | Â Â calcControls.update(controlDict) |
---|
3689 | Â Â varyList =Â phaseVary+hapVary+histVary |
---|
3690 | Â Â parmDict.update(phaseDict) |
---|
3691 | Â Â parmDict.update(hapDict) |
---|
3692 | Â Â parmDict.update(histDict) |
---|
3693 | Â Â GetFprime(calcControls,Histograms) |
---|
3694 | Â Â # do constraint processing |
---|
3695 | Â Â try: |
---|
3696 | Â Â Â Â groups,parmlist =Â G2mv.GroupConstraints(constrDict) |
---|
3697 | Â Â Â Â G2mv.GenerateConstraints(groups,parmlist,varyList,constrDict,fixedList) |
---|
3698 | Â Â except: |
---|
3699 |     print ' *** ERROR - your constraints are internally inconsistent ***' |
---|
3700 | Â Â Â Â # traceback for debug |
---|
3701 | Â Â Â Â #print 'varyList',varyList |
---|
3702 | Â Â Â Â #print 'constrDict',constrDict |
---|
3703 | Â Â Â Â #print 'fixedList',fixedList |
---|
3704 | Â Â Â Â #import traceback |
---|
3705 | Â Â Â Â #print traceback.format_exc() |
---|
3706 |     raise Exception(' *** Refine aborted ***') |
---|
3707 | Â Â # # check to see which generated parameters are fully varied |
---|
3708 | Â Â # msg = G2mv.SetVaryFlags(varyList) |
---|
3709 | Â Â # if msg: |
---|
3710 | Â Â #Â Â Â print ' *** ERROR - you have not set the refine flags for constraints consistently! ***' |
---|
3711 | Â Â #Â Â Â print msg |
---|
3712 | Â Â #Â Â Â raise Exception(' *** Refine aborted ***') |
---|
3713 | Â Â #print G2mv.VarRemapShow(varyList) |
---|
3714 | Â Â G2mv.Map2Dict(parmDict,varyList) |
---|
3715 | Â Â Rvals =Â {} |
---|
3716 |   while True: |
---|
3717 | Â Â Â Â begin =Â time.time() |
---|
3718 |     values = np.array(Dict2Values(parmDict, varyList)) |
---|
3719 | Â Â Â Â Ftol =Â Controls['min dM/M'] |
---|
3720 | Â Â Â Â Factor =Â Controls['shift factor'] |
---|
3721 | Â Â Â Â maxCyc =Â Controls['max cyc'] |
---|
3722 |     if 'Jacobian' in Controls['deriv type']:      |
---|
3723 | Â Â Â Â Â Â result =Â so.leastsq(errRefine,values,Dfun=dervRefine,full_output=True, |
---|
3724 | Â Â Â Â Â Â Â Â ftol=Ftol,col_deriv=True,factor=Factor, |
---|
3725 | Â Â Â Â Â Â Â Â args=([Histograms,Phases,restraintDict],parmDict,varyList,calcControls,pawleyLookup,dlg)) |
---|
3726 | Â Â Â Â Â Â ncyc =Â int(result[2]['nfev']/2) |
---|
3727 |     elif 'Hessian' in Controls['deriv type']: |
---|
3728 | Â Â Â Â Â Â result =Â G2mth.HessianLSQ(errRefine,values,Hess=HessRefine,ftol=Ftol,maxcyc=maxCyc, |
---|
3729 | Â Â Â Â Â Â Â Â args=([Histograms,Phases,restraintDict],parmDict,varyList,calcControls,pawleyLookup,dlg)) |
---|
3730 | Â Â Â Â Â Â ncyc =Â result[2]['num cyc']+1 |
---|
3731 | Â Â Â Â Â Â Rvals['lamMax']Â =Â result[2]['lamMax'] |
---|
3732 | Â Â Â Â else:Â Â Â Â Â Â #'numeric' |
---|
3733 | Â Â Â Â Â Â result =Â so.leastsq(errRefine,values,full_output=True,ftol=Ftol,epsfcn=1.e-8,factor=Factor, |
---|
3734 | Â Â Â Â Â Â Â Â args=([Histograms,Phases,restraintDict],parmDict,varyList,calcControls,pawleyLookup,dlg)) |
---|
3735 | Â Â Â Â Â Â ncyc =Â int(result[2]['nfev']/len(varyList)) |
---|
3736 | #Â Â Â Â table = dict(zip(varyList,zip(values,result[0],(result[0]-values)))) |
---|
3737 | #Â Â Â Â for item in table: print item,table[item]Â Â Â Â Â Â Â Â #useful debug - are things shifting? |
---|
3738 | Â Â Â Â runtime =Â time.time()-begin |
---|
3739 | Â Â Â Â Rvals['chisq']Â =Â np.sum(result[2]['fvec']**2) |
---|
3740 |     Values2Dict(parmDict, varyList, result[0]) |
---|
3741 | Â Â Â Â G2mv.Dict2Map(parmDict,varyList) |
---|
3742 | Â Â Â Â |
---|
3743 | Â Â Â Â Rvals['Nobs']Â =Â Histograms['Nobs'] |
---|
3744 |     Rvals['Rwp'] = np.sqrt(Rvals['chisq']/Histograms['sumwYo'])*100.   #to % |
---|
3745 | Â Â Â Â Rvals['GOF']Â =Â Rvals['chisq']/(Histograms['Nobs']-len(varyList)) |
---|
3746 |     print >>printFile,'\n Refinement results:' |
---|
3747 |     print >>printFile,135*'-' |
---|
3748 |     print >>printFile,' Number of function calls:',result[2]['nfev'],' Number of observations: ',Histograms['Nobs'],' Number of parameters: ',len(varyList) |
---|
3749 |     print >>printFile,' Refinement time = %8.3fs, %8.3fs/cycle, for %d cycles'%(runtime,runtime/ncyc,ncyc) |
---|
3750 |     print >>printFile,' wR = %7.2f%%, chi**2 = %12.6g, reduced chi**2 = %6.2f'%(Rvals['Rwp'],Rvals['chisq'],Rvals['GOF']) |
---|
3751 | Â Â Â Â try: |
---|
3752 | Â Â Â Â Â Â covMatrix =Â result[1]*Rvals['GOF'] |
---|
3753 | Â Â Â Â Â Â sig =Â np.sqrt(np.diag(covMatrix)) |
---|
3754 |       if np.any(np.isnan(sig)): |
---|
3755 |         print '*** Least squares aborted - some invalid esds possible ***' |
---|
3756 | #Â Â Â Â Â Â table = dict(zip(varyList,zip(values,result[0],(result[0]-values)/sig))) |
---|
3757 | #Â Â Â Â Â Â for item in table: print item,table[item]Â Â Â Â Â Â Â Â #useful debug - are things shifting? |
---|
3758 |       break          #refinement succeeded - finish up! |
---|
3759 |     except TypeError:     #result[1] is None on singular matrix |
---|
3760 |       print '**** Refinement failed - singular matrix ****' |
---|
3761 |       if 'Hessian' in Controls['deriv type']: |
---|
3762 | Â Â Â Â Â Â Â Â num =Â len(varyList)-1 |
---|
3763 |         for i,val in enumerate(np.flipud(result[2]['psing'])): |
---|
3764 |           if val: |
---|
3765 |             print 'Removing parameter: ',varyList[num-i] |
---|
3766 | Â Â Â Â Â Â Â Â Â Â Â Â del(varyList[num-i])Â Â Â Â Â Â Â Â Â Â |
---|
3767 | Â Â Â Â Â Â else: |
---|
3768 | Â Â Â Â Â Â Â Â Ipvt =Â result[2]['ipvt'] |
---|
3769 |         for i,ipvt in enumerate(Ipvt): |
---|
3770 |           if not np.sum(result[2]['fjac'],axis=1)[i]: |
---|
3771 |             print 'Removing parameter: ',varyList[ipvt-1] |
---|
3772 | Â Â Â Â Â Â Â Â Â Â Â Â del(varyList[ipvt-1]) |
---|
3773 | Â Â Â Â Â Â Â Â Â Â Â Â break |
---|
3774 | |
---|
3775 | #Â Â print 'dependentParmList: ',G2mv.dependentParmList |
---|
3776 | #Â Â print 'arrayList: ',G2mv.arrayList |
---|
3777 | #Â Â print 'invarrayList: ',G2mv.invarrayList |
---|
3778 | #Â Â print 'indParmList: ',G2mv.indParmList |
---|
3779 | #Â Â print 'fixedDict: ',G2mv.fixedDict |
---|
3780 | #Â Â print 'test1' |
---|
3781 | Â Â GetFobsSq(Histograms,Phases,parmDict,calcControls) |
---|
3782 | #Â Â print 'test2' |
---|
3783 | Â Â sigDict =Â dict(zip(varyList,sig)) |
---|
3784 | Â Â newCellDict =Â GetNewCellParms(parmDict,varyList) |
---|
3785 | Â Â newAtomDict =Â ApplyXYZshifts(parmDict,varyList) |
---|
3786 | Â Â covData =Â {'variables':result[0],'varyList':varyList,'sig':sig,'Rvals':Rvals, |
---|
3787 | Â Â Â Â 'covMatrix':covMatrix,'title':GPXfile,'newAtomDict':newAtomDict,'newCellDict':newCellDict} |
---|
3788 | Â Â # add the uncertainties into the esd dictionary (sigDict) |
---|
3789 | Â Â sigDict.update(G2mv.ComputeDepESD(covMatrix,varyList,parmDict)) |
---|
3790 | Â Â G2mv.PrintIndependentVars(parmDict,varyList,sigDict,pFile=printFile) |
---|
3791 | Â Â SetPhaseData(parmDict,sigDict,Phases,covData,restraintDict,printFile) |
---|
3792 | Â Â SetHistogramPhaseData(parmDict,sigDict,Phases,Histograms,pFile=printFile) |
---|
3793 | Â Â SetHistogramData(parmDict,sigDict,Histograms,pFile=printFile) |
---|
3794 | Â Â SetUsedHistogramsAndPhases(GPXfile,Histograms,Phases,covData) |
---|
3795 | Â Â printFile.close() |
---|
3796 |   print ' Refinement results are in file: '+ospath.splitext(GPXfile)[0]+'.lst' |
---|
3797 |   print ' ***** Refinement successful *****' |
---|
3798 | Â Â |
---|
3799 | #for testing purposes!!! |
---|
3800 |   if DEBUG: |
---|
3801 |     import cPickle |
---|
3802 | Â Â Â Â fl =Â open('structTestdata.dat','wb') |
---|
3803 | Â Â Â Â cPickle.dump(parmDict,fl,1) |
---|
3804 | Â Â Â Â cPickle.dump(varyList,fl,1) |
---|
3805 |     for histogram in Histograms: |
---|
3806 |       if 'PWDR' in histogram[:4]: |
---|
3807 | Â Â Â Â Â Â Â Â Histogram =Â Histograms[histogram] |
---|
3808 | Â Â Â Â cPickle.dump(Histogram,fl,1) |
---|
3809 | Â Â Â Â cPickle.dump(Phases,fl,1) |
---|
3810 | Â Â Â Â cPickle.dump(calcControls,fl,1) |
---|
3811 | Â Â Â Â cPickle.dump(pawleyLookup,fl,1) |
---|
3812 | Â Â Â Â fl.close() |
---|
3813 | |
---|
3814 |   if dlg: |
---|
3815 |     return Rvals['Rwp'] |
---|
3816 | |
---|
3817 | def SeqRefine(GPXfile,dlg): |
---|
3818 |   import pytexture as ptx |
---|
3819 | Â Â ptx.pyqlmninit()Â Â Â Â Â Â #initialize fortran arrays for spherical harmonics |
---|
3820 | Â Â |
---|
3821 | Â Â printFile =Â open(ospath.splitext(GPXfile)[0]+'.lst','w') |
---|
3822 |   print ' Sequential Refinement' |
---|
3823 | Â Â ShowBanner(printFile) |
---|
3824 | Â Â G2mv.InitVars()Â Â |
---|
3825 | Â Â Controls =Â GetControls(GPXfile) |
---|
3826 | Â Â ShowControls(Controls,printFile)Â Â Â Â Â Â |
---|
3827 | Â Â constrDict,fixedList =Â GetConstraints(GPXfile) |
---|
3828 | Â Â restraintDict =Â GetRestraints(GPXfile) |
---|
3829 | Â Â Histograms,Phases =Â GetUsedHistogramsAndPhases(GPXfile) |
---|
3830 |   if not Phases: |
---|
3831 |     print ' *** ERROR - you have no histograms to refine! ***' |
---|
3832 |     print ' *** Refine aborted ***' |
---|
3833 |     raise Exception |
---|
3834 |   if not Histograms: |
---|
3835 |     print ' *** ERROR - you have no data to refine with! ***' |
---|
3836 |     print ' *** Refine aborted ***' |
---|
3837 |     raise Exception |
---|
3838 | Â Â Natoms,atomIndx,phaseVary,phaseDict,pawleyLookup,FFtables,BLtables =Â GetPhaseData(Phases,restraintDict,False,printFile) |
---|
3839 |   for item in phaseVary: |
---|
3840 |     if '::A0' in item: |
---|
3841 |       print '**** WARNING - lattice parameters should not be refined in a sequential refinement ****' |
---|
3842 |       print '****      instead use the Dij parameters for each powder histogram      ****' |
---|
3843 |   if 'Seq Data' in Controls: |
---|
3844 | Â Â Â Â histNames =Â Controls['Seq Data'] |
---|
3845 | Â Â else: |
---|
3846 | Â Â Â Â histNames =Â GetHistogramNames(GPXfile,['PWDR',]) |
---|
3847 |   if 'Reverse Seq' in Controls: |
---|
3848 |     if Controls['Reverse Seq']: |
---|
3849 | Â Â Â Â Â Â histNames.reverse() |
---|
3850 | Â Â SeqResult =Â {'histNames':histNames} |
---|
3851 | Â Â makeBack =Â True |
---|
3852 |   for ihst,histogram in enumerate(histNames): |
---|
3853 | Â Â Â Â ifPrint =Â False |
---|
3854 |     if dlg: |
---|
3855 | Â Â Â Â Â Â dlg.SetTitle('Residual for histogram '+str(ihst)) |
---|
3856 | Â Â Â Â calcControls =Â {} |
---|
3857 | Â Â Â Â calcControls['atomIndx']Â =Â atomIndx |
---|
3858 | Â Â Â Â calcControls['Natoms']Â =Â Natoms |
---|
3859 | Â Â Â Â calcControls['FFtables']Â =Â FFtables |
---|
3860 | Â Â Â Â calcControls['BLtables']Â =Â BLtables |
---|
3861 | Â Â Â Â varyList =Â [] |
---|
3862 | Â Â Â Â parmDict =Â {} |
---|
3863 | Â Â Â Â Histo =Â {histogram:Histograms[histogram],} |
---|
3864 | Â Â Â Â hapVary,hapDict,controlDict =Â GetHistogramPhaseData(Phases,Histo,False) |
---|
3865 | Â Â Â Â calcControls.update(controlDict) |
---|
3866 | Â Â Â Â histVary,histDict,controlDict =Â GetHistogramData(Histo,False) |
---|
3867 | Â Â Â Â calcControls.update(controlDict) |
---|
3868 | Â Â Â Â varyList =Â phaseVary+hapVary+histVary |
---|
3869 |     if not ihst: |
---|
3870 | Â Â Â Â Â Â saveVaryList =Â varyList[:] |
---|
3871 |       for i,item in enumerate(saveVaryList): |
---|
3872 | Â Â Â Â Â Â Â Â items =Â item.split(':') |
---|
3873 |         if items[1]: |
---|
3874 | Â Â Â Â Â Â Â Â Â Â items[1]Â =Â '' |
---|
3875 | Â Â Â Â Â Â Â Â item =Â ':'.join(items) |
---|
3876 | Â Â Â Â Â Â Â Â saveVaryList[i]Â =Â item |
---|
3877 | Â Â Â Â Â Â SeqResult['varyList']Â =Â saveVaryList |
---|
3878 | Â Â Â Â else: |
---|
3879 | Â Â Â Â Â Â newVaryList =Â varyList[:] |
---|
3880 |       for i,item in enumerate(newVaryList): |
---|
3881 | Â Â Â Â Â Â Â Â items =Â item.split(':') |
---|
3882 |         if items[1]: |
---|
3883 | Â Â Â Â Â Â Â Â Â Â items[1]Â =Â '' |
---|
3884 | Â Â Â Â Â Â Â Â item =Â ':'.join(items) |
---|
3885 | Â Â Â Â Â Â Â Â newVaryList[i]Â =Â item |
---|
3886 |       if newVaryList != SeqResult['varyList']: |
---|
3887 |         print newVaryList |
---|
3888 |         print SeqResult['varyList'] |
---|
3889 |         print '**** ERROR - variable list for this histogram does not match previous' |
---|
3890 |         raise Exception |
---|
3891 | Â Â Â Â parmDict.update(phaseDict) |
---|
3892 | Â Â Â Â parmDict.update(hapDict) |
---|
3893 | Â Â Â Â parmDict.update(histDict) |
---|
3894 | Â Â Â Â GetFprime(calcControls,Histo) |
---|
3895 | Â Â Â Â # do constraint processing |
---|
3896 | Â Â Â Â try: |
---|
3897 | Â Â Â Â Â Â groups,parmlist =Â G2mv.GroupConstraints(constrDict) |
---|
3898 | Â Â Â Â Â Â G2mv.GenerateConstraints(groups,parmlist,varyList,constrDict,fixedList) |
---|
3899 | Â Â Â Â except: |
---|
3900 |       print ' *** ERROR - your constraints are internally inconsistent ***' |
---|
3901 |       raise Exception(' *** Refine aborted ***') |
---|
3902 | Â Â Â Â # check to see which generated parameters are fully varied |
---|
3903 | Â Â Â Â # msg = G2mv.SetVaryFlags(varyList) |
---|
3904 | Â Â Â Â # if msg: |
---|
3905 | Â Â Â Â #Â Â Â print ' *** ERROR - you have not set the refine flags for constraints consistently! ***' |
---|
3906 | Â Â Â Â #Â Â Â print msg |
---|
3907 | Â Â Â Â #Â Â Â raise Exception(' *** Refine aborted ***') |
---|
3908 | Â Â Â Â #print G2mv.VarRemapShow(varyList) |
---|
3909 | Â Â Â Â G2mv.Map2Dict(parmDict,varyList) |
---|
3910 | Â Â Â Â Rvals =Â {} |
---|
3911 |     while True: |
---|
3912 | Â Â Â Â Â Â begin =Â time.time() |
---|
3913 | Â Â Â Â Â Â values =Â np.array(Dict2Values(parmDict,varyList)) |
---|
3914 | Â Â Â Â Â Â Ftol =Â Controls['min dM/M'] |
---|
3915 | Â Â Â Â Â Â Factor =Â Controls['shift factor'] |
---|
3916 | Â Â Â Â Â Â maxCyc =Â Controls['max cyc'] |
---|
3917 | |
---|
3918 |       if 'Jacobian' in Controls['deriv type']:      |
---|
3919 | Â Â Â Â Â Â Â Â result =Â so.leastsq(errRefine,values,Dfun=dervRefine,full_output=True, |
---|
3920 | Â Â Â Â Â Â Â Â Â Â ftol=Ftol,col_deriv=True,factor=Factor, |
---|
3921 | Â Â Â Â Â Â Â Â Â Â args=([Histo,Phases,restraintDict],parmDict,varyList,calcControls,pawleyLookup,dlg)) |
---|
3922 | Â Â Â Â Â Â Â Â ncyc =Â int(result[2]['nfev']/2) |
---|
3923 |       elif 'Hessian' in Controls['deriv type']: |
---|
3924 | Â Â Â Â Â Â Â Â result =Â G2mth.HessianLSQ(errRefine,values,Hess=HessRefine,ftol=Ftol,maxcyc=maxCyc, |
---|
3925 | Â Â Â Â Â Â Â Â Â Â args=([Histo,Phases,restraintDict],parmDict,varyList,calcControls,pawleyLookup,dlg)) |
---|
3926 | Â Â Â Â Â Â Â Â ncyc =Â result[2]['num cyc']+1Â Â Â Â Â Â Â Â Â Â Â Â Â Â |
---|
3927 | Â Â Â Â Â Â else:Â Â Â Â Â Â #'numeric' |
---|
3928 | Â Â Â Â Â Â Â Â result =Â so.leastsq(errRefine,values,full_output=True,ftol=Ftol,epsfcn=1.e-8,factor=Factor, |
---|
3929 | Â Â Â Â Â Â Â Â Â Â args=([Histo,Phases,restraintDict],parmDict,varyList,calcControls,pawleyLookup,dlg)) |
---|
3930 | Â Â Â Â Â Â Â Â ncyc =Â int(result[2]['nfev']/len(varyList)) |
---|
3931 | |
---|
3932 | Â Â Â Â Â Â runtime =Â time.time()-begin |
---|
3933 | Â Â Â Â Â Â Rvals['chisq']Â =Â np.sum(result[2]['fvec']**2) |
---|
3934 |       Values2Dict(parmDict, varyList, result[0]) |
---|
3935 | Â Â Â Â Â Â G2mv.Dict2Map(parmDict,varyList) |
---|
3936 | Â Â Â Â Â Â |
---|
3937 |       Rvals['Rwp'] = np.sqrt(Rvals['chisq']/Histo['sumwYo'])*100.   #to % |
---|
3938 | Â Â Â Â Â Â Rvals['GOF']Â =Â Rvals['Rwp']/(Histo['Nobs']-len(varyList)) |
---|
3939 | Â Â Â Â Â Â Rvals['Nobs']Â =Â Histo['Nobs'] |
---|
3940 |       print >>printFile,'\n Refinement results for histogram: v'+histogram |
---|
3941 |       print >>printFile,135*'-' |
---|
3942 |       print >>printFile,' Number of function calls:',result[2]['nfev'],' Number of observations: ',Histo['Nobs'],' Number of parameters: ',len(varyList) |
---|
3943 |       print >>printFile,' Refinement time = %8.3fs, %8.3fs/cycle, for %d cycles'%(runtime,runtime/ncyc,ncyc) |
---|
3944 |       print >>printFile,' wRp = %7.2f%%, chi**2 = %12.6g, reduced chi**2 = %6.2f'%(Rvals['Rwp'],Rvals['chisq'],Rvals['GOF']) |
---|
3945 | Â Â Â Â Â Â try: |
---|
3946 | Â Â Â Â Â Â Â Â covMatrix =Â result[1]*Rvals['GOF'] |
---|
3947 | Â Â Â Â Â Â Â Â sig =Â np.sqrt(np.diag(covMatrix)) |
---|
3948 |         if np.any(np.isnan(sig)): |
---|
3949 |           print '*** Least squares aborted - some invalid esds possible ***' |
---|
3950 | Â Â Â Â Â Â Â Â Â Â ifPrint =Â True |
---|
3951 |         break          #refinement succeeded - finish up! |
---|
3952 |       except TypeError:     #result[1] is None on singular matrix |
---|
3953 |         print '**** Refinement failed - singular matrix ****' |
---|
3954 |         if 'Hessian' in Controls['deriv type']: |
---|
3955 | Â Â Â Â Â Â Â Â Â Â num =Â len(varyList)-1 |
---|
3956 |           for i,val in enumerate(np.flipud(result[2]['psing'])): |
---|
3957 |             if val: |
---|
3958 | Â Â Â Â Â Â |
---|