- Timestamp:
- Jul 21, 2012 1:44:56 PM (13 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
TabularUnified trunk/GSASIImapvars.py ¶
r668 r693 661 661 return independentVars 662 662 663 def PrintIndependentVars(parmDict,varyList,sigDict,PrintAll=False ):663 def PrintIndependentVars(parmDict,varyList,sigDict,PrintAll=False,pFile=None): 664 664 '''Print the values and uncertainties on the independent variables''' 665 665 global dependentParmList,arrayList,invarrayList,indParmList,fixedDict … … 673 673 if len(printlist) == 0: return 674 674 s1 = '' 675 print 130*'-'676 print "Variables generated by constraints"675 print >>pFile,130*'-' 676 print >>pFile,"Variables generated by constraints" 677 677 printlist.append(3*[None]) 678 678 for name,val,esd in printlist: 679 679 if len(s1) > 120 or name is None: 680 print 681 print s1682 print s2683 print s3680 print >>pFile,'' 681 print >>pFile,s1 682 print >>pFile,s2 683 print >>pFile,s3 684 684 s1 = '' 685 685 if name is None: break -
TabularUnified trunk/GSASIIstruct.py ¶
r692 r693 409 409 print 'GPX file save successful' 410 410 411 def ShowBanner( ):412 print 80*'*'413 print ' General Structure Analysis System-II Crystal Structure Refinement'414 print ' by Robert B. Von Dreele & Brian H. Toby'415 print ' Argonne National Laboratory(C), 2010'416 print ' This product includes software developed by the UChicago Argonne, LLC,'417 print ' as Operator of Argonne National Laboratory.'418 print 80*'*','\n'411 def ShowBanner(pFile=None): 412 print >>pFile,80*'*' 413 print >>pFile,' General Structure Analysis System-II Crystal Structure Refinement' 414 print >>pFile,' by Robert B. Von Dreele & Brian H. Toby' 415 print >>pFile,' Argonne National Laboratory(C), 2010' 416 print >>pFile,' This product includes software developed by the UChicago Argonne, LLC,' 417 print >>pFile,' as Operator of Argonne National Laboratory.' 418 print >>pFile,80*'*','\n' 419 419 420 def ShowControls(Controls ):421 print ' Least squares controls:'422 print ' Refinement type: ',Controls['deriv type']420 def ShowControls(Controls,pFile=None): 421 print >>pFile,' Least squares controls:' 422 print >>pFile,' Refinement type: ',Controls['deriv type'] 423 423 if 'Hessian' in Controls['deriv type']: 424 print ' Maximum number of cycles:',Controls['max cyc']424 print >>pFile,' Maximum number of cycles:',Controls['max cyc'] 425 425 else: 426 print ' Minimum delta-M/M for convergence: ','%.2g'%(Controls['min dM/M'])427 print ' Initial shift factor: ','%.3f'%(Controls['shift factor'])426 print >>pFile,' Minimum delta-M/M for convergence: ','%.2g'%(Controls['min dM/M']) 427 print >>pFile,' Initial shift factor: ','%.3f'%(Controls['shift factor']) 428 428 429 429 def GetFFtable(General): … … 527 527 ################################################################################ 528 528 529 def GetPhaseData(PhaseData,RestraintDict=None,Print=True ):529 def GetPhaseData(PhaseData,RestraintDict=None,Print=True,pFile=None): 530 530 531 531 def PrintFFtable(FFtable): 532 print '\n X-ray scattering factors:'533 print ' Symbol fa fb fc'534 print 99*'-'532 print >>pFile,'\n X-ray scattering factors:' 533 print >>pFile,' Symbol fa fb fc' 534 print >>pFile,99*'-' 535 535 for Ename in FFtable: 536 536 ffdata = FFtable[Ename] 537 537 fa = ffdata['fa'] 538 538 fb = ffdata['fb'] 539 print ' %8s %9.5f %9.5f %9.5f %9.5f %9.5f %9.5f %9.5f %9.5f %9.5f' % \539 print >>pFile,' %8s %9.5f %9.5f %9.5f %9.5f %9.5f %9.5f %9.5f %9.5f %9.5f' % \ 540 540 (Ename.ljust(8),fa[0],fa[1],fa[2],fa[3],fb[0],fb[1],fb[2],fb[3],ffdata['fc']) 541 541 542 542 def PrintBLtable(BLtable): 543 print '\n Neutron scattering factors:'544 print ' Symbol isotope mass b resonant terms'545 print 99*'-'543 print >>pFile,'\n Neutron scattering factors:' 544 print >>pFile,' Symbol isotope mass b resonant terms' 545 print >>pFile,99*'-' 546 546 for Ename in BLtable: 547 547 bldata = BLtable[Ename] … … 555 555 for item in bres: 556 556 line += '%10.5g'%(item) 557 print line557 print >>pFile,line 558 558 559 559 def PrintAtoms(General,Atoms): 560 print '\n Atoms:'560 print >>pFile,'\n Atoms:' 561 561 line = ' name type refine? x y z '+ \ 562 562 ' frac site sym mult I/A Uiso U11 U22 U33 U12 U13 U23' … … 565 565 elif General['Type'] == 'macromolecular': 566 566 line = ' res no residue chain '+line 567 print line567 print >>pFile,line 568 568 if General['Type'] == 'nuclear': 569 print 135*'-'569 print >>pFile,135*'-' 570 570 for i,at in enumerate(Atoms): 571 571 line = '%7s'%(at[0])+'%7s'%(at[1])+'%7s'%(at[2])+'%10.5f'%(at[3])+'%10.5f'%(at[4])+ \ … … 577 577 for j in range(6): 578 578 line += '%8.4f'%(at[11+j]) 579 print line579 print >>pFile,line 580 580 581 581 def PrintTexture(textureData): … … 583 583 str(textureData['Order']) 584 584 if textureData['Order']: 585 print topstr+' Refine? '+str(textureData['SH Coeff'][0])585 print >>pFile,topstr+' Refine? '+str(textureData['SH Coeff'][0]) 586 586 else: 587 print topstr587 print >>pFile,topstr 588 588 return 589 589 names = ['omega','chi','phi'] … … 591 591 for name in names: 592 592 line += ' SH '+name+':'+'%12.4f'%(textureData['Sample '+name][1])+' Refine? '+str(textureData['Sample '+name][0]) 593 print line594 print '\n Texture coefficients:'593 print >>pFile,line 594 print >>pFile,'\n Texture coefficients:' 595 595 ptlbls = ' names :' 596 596 ptstr = ' values:' … … 599 599 ptlbls += '%12s'%(item) 600 600 ptstr += '%12.4f'%(SHcoeff[item]) 601 print ptlbls602 print ptstr601 print >>pFile,ptlbls 602 print >>pFile,ptstr 603 603 604 604 def PrintRestraints(phaseRest): 605 605 if phaseRest: 606 print '\n Restraints:'606 print >>pFile,'\n Restraints:' 607 607 names = ['Bonds','Angles','Planes','Volumes'] 608 608 for i,name in enumerate(['Bond','Angle','Plane','Chiral']): 609 609 itemRest = phaseRest[name] 610 610 if itemRest[names[i]]: 611 print '\n %30s %10.3f'%(name+' restraint weight factor',itemRest['wtFactor'])612 print ' atoms(symOp), calc, obs, sig: '611 print >>pFile,'\n %30s %10.3f'%(name+' restraint weight factor',itemRest['wtFactor']) 612 print >>pFile,' atoms(symOp), calc, obs, sig: ' 613 613 for item in phaseRest[name][names[i]]: 614 614 text = ' ' … … 617 617 if (a+1)%5 == 0: 618 618 text += '\n ' 619 print text,' %.3f %.3f %.3f'%(item[3],item[4],item[5])619 print >>pFile,text,' %.3f %.3f %.3f'%(item[3],item[4],item[5]) 620 620 621 if Print: print' Phases:'621 if Print:print >>pFile,' Phases:' 622 622 phaseVary = [] 623 623 phaseDict = {} … … 715 715 716 716 if Print: 717 print '\n Phase name: ',General['Name']718 print 135*'-'717 print >>pFile,'\n Phase name: ',General['Name'] 718 print >>pFile,135*'-' 719 719 PrintFFtable(FFtable) 720 720 PrintBLtable(BLtable) 721 print ''722 for line in SGtext: print line721 print >>pFile,'' 722 for line in SGtext: print >>pFile,line 723 723 PrintAtoms(General,Atoms) 724 print '\n Unit cell: a =','%.5f'%(cell[1]),' b =','%.5f'%(cell[2]),' c =','%.5f'%(cell[3]), \724 print >>pFile,'\n Unit cell: a =','%.5f'%(cell[1]),' b =','%.5f'%(cell[2]),' c =','%.5f'%(cell[3]), \ 725 725 ' alpha =','%.3f'%(cell[4]),' beta =','%.3f'%(cell[5]),' gamma =', \ 726 726 '%.3f'%(cell[6]),' volume =','%.3f'%(cell[7]),' Refine?',cell[0] … … 840 840 return cellSig 841 841 842 def SetPhaseData(parmDict,sigDict,Phases,covData ):842 def SetPhaseData(parmDict,sigDict,Phases,covData,pFile=None): 843 843 844 844 def PrintAtomsAndSig(General,Atoms,atomsSig): 845 print '\n Atoms:'845 print >>pFile,'\n Atoms:' 846 846 line = ' name x y z frac Uiso U11 U22 U33 U12 U13 U23' 847 847 if General['Type'] == 'magnetic': … … 849 849 elif General['Type'] == 'macromolecular': 850 850 line = ' res no residue chain '+line 851 print line851 print >>pFile,line 852 852 if General['Type'] == 'nuclear': 853 print 135*'-'853 print >>pFile,135*'-' 854 854 fmt = {0:'%7s',1:'%7s',3:'%10.5f',4:'%10.5f',5:'%10.5f',6:'%8.3f',10:'%8.5f', 855 855 11:'%8.5f',12:'%8.5f',13:'%8.5f',14:'%8.5f',15:'%8.5f',16:'%8.5f'} … … 882 882 else: 883 883 sigstr += 8*' ' 884 print name885 print valstr886 print sigstr884 print >>pFile,name 885 print >>pFile,valstr 886 print >>pFile,sigstr 887 887 888 888 def PrintSHtextureAndSig(textureData,SHtextureSig): 889 print '\n Spherical harmonics texture: Order:' + str(textureData['Order'])889 print >>pFile,'\n Spherical harmonics texture: Order:' + str(textureData['Order']) 890 890 names = ['omega','chi','phi'] 891 891 namstr = ' names :' … … 899 899 else: 900 900 sigstr += 12*' ' 901 print namstr902 print ptstr903 print sigstr904 print '\n Texture coefficients:'901 print >>pFile,namstr 902 print >>pFile,ptstr 903 print >>pFile,sigstr 904 print >>pFile,'\n Texture coefficients:' 905 905 namstr = ' names :' 906 906 ptstr = ' values:' … … 914 914 else: 915 915 sigstr += 12*' ' 916 print namstr917 print ptstr918 print sigstr916 print >>pFile,namstr 917 print >>pFile,ptstr 918 print >>pFile,sigstr 919 919 920 920 921 print '\n Phases:'921 print >>pFile,'\n Phases:' 922 922 for phase in Phases: 923 print ' Result for phase: ',phase923 print >>pFile,' Result for phase: ',phase 924 924 Phase = Phases[phase] 925 925 General = Phase['General'] … … 932 932 A,sigA = cellFill(pfx,SGData,parmDict,sigDict) 933 933 cellSig = getCellEsd(pfx,SGData,A,covData) #includes sigVol 934 print ' Reciprocal metric tensor: '934 print >>pFile,' Reciprocal metric tensor: ' 935 935 ptfmt = "%15.9f" 936 936 names = ['A11','A22','A33','A12','A13','A23'] … … 945 945 else: 946 946 sigstr += 15*' ' 947 print namstr948 print ptstr949 print sigstr947 print >>pFile,namstr 948 print >>pFile,ptstr 949 print >>pFile,sigstr 950 950 cell[1:7] = G2lat.A2cell(A) 951 951 cell[7] = G2lat.calc_V(A) 952 print ' New unit cell:'952 print >>pFile,' New unit cell:' 953 953 ptfmt = ["%12.6f","%12.6f","%12.6f","%12.4f","%12.4f","%12.4f","%12.3f"] 954 954 names = ['a','b','c','alpha','beta','gamma','Volume'] … … 963 963 else: 964 964 sigstr += 12*' ' 965 print namstr966 print ptstr967 print sigstr965 print >>pFile,namstr 966 print >>pFile,ptstr 967 print >>pFile,sigstr 968 968 969 969 if Phase['General'].get('doPawley'): … … 1021 1021 ################################################################################ 1022 1022 1023 def GetHistogramPhaseData(Phases,Histograms,Print=True ):1023 def GetHistogramPhaseData(Phases,Histograms,Print=True,pFile=None): 1024 1024 1025 1025 def PrintSize(hapData): … … 1030 1030 line += ' axial:'+'%12.3f'%(hapData[1][1])+' Refine? '+str(hapData[2][1]) 1031 1031 line += '\n\t LG mixing coeff.: %12.4f'%(hapData[1][2])+' Refine? '+str(hapData[2][2]) 1032 print line1032 print >>pFile,line 1033 1033 else: 1034 print '\n Size model : %s'%(hapData[0])+ \1034 print >>pFile,'\n Size model : %s'%(hapData[0])+ \ 1035 1035 '\n\t LG mixing coeff.:%12.4f'%(hapData[1][2])+' Refine? '+str(hapData[2][2]) 1036 1036 Snames = ['S11','S22','S33','S12','S13','S23'] … … 1042 1042 ptstr += '%12.6f' % (hapData[4][i]) 1043 1043 varstr += '%12s' % (str(hapData[5][i])) 1044 print ptlbls1045 print ptstr1046 print varstr1044 print >>pFile,ptlbls 1045 print >>pFile,ptstr 1046 print >>pFile,varstr 1047 1047 1048 1048 def PrintMuStrain(hapData,SGData): … … 1053 1053 line += ' axial:'+'%12.1f'%(hapData[1][1])+' Refine? '+str(hapData[2][1]) 1054 1054 line +='\n\t LG mixing coeff.:%12.4f'%(hapData[1][2])+' Refine? '+str(hapData[2][2]) 1055 print line1055 print >>pFile,line 1056 1056 else: 1057 print '\n Mustrain model: %s'%(hapData[0])+ \1057 print >>pFile,'\n Mustrain model: %s'%(hapData[0])+ \ 1058 1058 '\n\t LG mixing coeff.:%12.4f'%(hapData[1][2])+' Refine? '+str(hapData[2][2]) 1059 1059 Snames = G2spc.MustrainNames(SGData) … … 1065 1065 ptstr += '%12.6f' % (hapData[4][i]) 1066 1066 varstr += '%12s' % (str(hapData[5][i])) 1067 print ptlbls1068 print ptstr1069 print varstr1067 print >>pFile,ptlbls 1068 print >>pFile,ptstr 1069 print >>pFile,varstr 1070 1070 1071 1071 def PrintHStrain(hapData,SGData): 1072 print '\n Hydrostatic/elastic strain: '1072 print >>pFile,'\n Hydrostatic/elastic strain: ' 1073 1073 Hsnames = G2spc.HStrainNames(SGData) 1074 1074 ptlbls = ' names :' … … 1079 1079 ptstr += '%12.6f' % (hapData[0][i]) 1080 1080 varstr += '%12s' % (str(hapData[1][i])) 1081 print ptlbls1082 print ptstr1083 print varstr1081 print >>pFile,ptlbls 1082 print >>pFile,ptstr 1083 print >>pFile,varstr 1084 1084 1085 1085 def PrintSHPO(hapData): 1086 print '\n Spherical harmonics preferred orientation: Order:' + \1086 print >>pFile,'\n Spherical harmonics preferred orientation: Order:' + \ 1087 1087 str(hapData[4])+' Refine? '+str(hapData[2]) 1088 1088 ptlbls = ' names :' … … 1091 1091 ptlbls += '%12s'%(item) 1092 1092 ptstr += '%12.3f'%(hapData[5][item]) 1093 print ptlbls1094 print ptstr1093 print >>pFile,ptlbls 1094 print >>pFile,ptstr 1095 1095 1096 1096 hapDict = {} … … 1182 1182 1183 1183 if Print: 1184 print '\n Phase: ',phase,' in histogram: ',histogram1185 print 135*'-'1186 print ' Phase fraction : %10.4f'%(hapData['Scale'][0]),' Refine?',hapData['Scale'][1]1187 print ' Extinction coeff: %10.4f'%(hapData['Extinction'][0]),' Refine?',hapData['Extinction'][1]1184 print >>pFile,'\n Phase: ',phase,' in histogram: ',histogram 1185 print >>pFile,135*'-' 1186 print >>pFile,' Phase fraction : %10.4f'%(hapData['Scale'][0]),' Refine?',hapData['Scale'][1] 1187 print >>pFile,' Extinction coeff: %10.4f'%(hapData['Extinction'][0]),' Refine?',hapData['Extinction'][1] 1188 1188 if hapData['Pref.Ori.'][0] == 'MD': 1189 1189 Ax = hapData['Pref.Ori.'][3] 1190 print ' March-Dollase PO: %10.4f'%(hapData['Pref.Ori.'][1]),' Refine?',hapData['Pref.Ori.'][2], \1190 print >>pFile,' March-Dollase PO: %10.4f'%(hapData['Pref.Ori.'][1]),' Refine?',hapData['Pref.Ori.'][2], \ 1191 1191 ' Axis: %d %d %d'%(Ax[0],Ax[1],Ax[2]) 1192 1192 else: #'SH' for spherical harmonics … … 1237 1237 hapVary.append(pfx+eKey) 1238 1238 if Print: 1239 print '\n Phase: ',phase,' in histogram: ',histogram1240 print 135*'-'1241 print ' Scale factor : %10.4f'%(hapData['Scale'][0]),' Refine?',hapData['Scale'][1]1242 print ' Extinction approx: %10s'%(extApprox),' Type: %15s'%(extType),' tbar: %6.3f'%(extParms['Tbar'])1239 print >>pFile,'\n Phase: ',phase,' in histogram: ',histogram 1240 print >>pFile,135*'-' 1241 print >>pFile,' Scale factor : %10.4f'%(hapData['Scale'][0]),' Refine?',hapData['Scale'][1] 1242 print >>pFile,' Extinction approx: %10s'%(extApprox),' Type: %15s'%(extType),' tbar: %6.3f'%(extParms['Tbar']) 1243 1243 text = ' Parameters :' 1244 1244 for eKey in Ekey: 1245 1245 text += ' %4s : %10.3g Refine? '%(eKey,extParms[eKey][0])+str(extParms[eKey][1]) 1246 print text1246 print >>pFile,text 1247 1247 Histogram['Reflection Lists'] = phase 1248 1248 1249 1249 return hapVary,hapDict,controlDict 1250 1250 1251 def SetHistogramPhaseData(parmDict,sigDict,Phases,Histograms,Print=True ):1251 def SetHistogramPhaseData(parmDict,sigDict,Phases,Histograms,Print=True,pFile=None): 1252 1252 1253 1253 def PrintSizeAndSig(hapData,sizeSig): … … 1269 1269 line += ', sig:%8.3f'%(sizeSig[0][2]) 1270 1270 if refine: 1271 print line1271 print >>pFile,line 1272 1272 else: 1273 1273 line += ' LG mix coeff.:%12.4f'%(hapData[1][2]) … … 1288 1288 sigstr += 12*' ' 1289 1289 if refine: 1290 print line1291 print ptlbls1292 print ptstr1293 print sigstr1290 print >>pFile,line 1291 print >>pFile,ptlbls 1292 print >>pFile,ptstr 1293 print >>pFile,sigstr 1294 1294 1295 1295 def PrintMuStrainAndSig(hapData,mustrainSig,SGData): … … 1310 1310 line += ', sig:%8.3f'%(mustrainSig[0][2]) 1311 1311 if refine: 1312 print line1312 print >>pFile,line 1313 1313 else: 1314 1314 line += ' LG mix coeff.:%12.4f'%(hapData[1][2]) … … 1329 1329 sigstr += 12*' ' 1330 1330 if refine: 1331 print line1332 print ptlbls1333 print ptstr1334 print sigstr1331 print >>pFile,line 1332 print >>pFile,ptlbls 1333 print >>pFile,ptstr 1334 print >>pFile,sigstr 1335 1335 1336 1336 def PrintHStrainAndSig(hapData,strainSig,SGData): … … 1349 1349 sigstr += 12*' ' 1350 1350 if refine: 1351 print '\n Hydrostatic/elastic strain: '1352 print ptlbls1353 print ptstr1354 print sigstr1351 print >>pFile,'\n Hydrostatic/elastic strain: ' 1352 print >>pFile,ptlbls 1353 print >>pFile,ptstr 1354 print >>pFile,sigstr 1355 1355 1356 1356 def PrintSHPOAndSig(hapData,POsig): 1357 print '\n Spherical harmonics preferred orientation: Order:'+str(hapData[4])1357 print >>pFile,'\n Spherical harmonics preferred orientation: Order:'+str(hapData[4]) 1358 1358 ptlbls = ' names :' 1359 1359 ptstr = ' values:' … … 1366 1366 else: 1367 1367 sigstr += 12*' ' 1368 print ptlbls1369 print ptstr1370 print sigstr1368 print >>pFile,ptlbls 1369 print >>pFile,ptstr 1370 print >>pFile,sigstr 1371 1371 1372 1372 for phase in Phases: … … 1382 1382 #skip if histogram not included e.g. in a sequential refinement 1383 1383 continue 1384 print '\n Phase: ',phase,' in histogram: ',histogram1385 print 130*'-'1384 print >>pFile,'\n Phase: ',phase,' in histogram: ',histogram 1385 print >>pFile,130*'-' 1386 1386 hapData = HistoPhase[histogram] 1387 1387 hId = Histogram['hId'] 1388 1388 if 'PWDR' in histogram: 1389 1389 pfx = str(pId)+':'+str(hId)+':' 1390 print ' Final refinement RF, RF^2 = %.2f%%, %.2f%% on %d reflections' \1390 print >>pFile,' Final refinement RF, RF^2 = %.2f%%, %.2f%% on %d reflections' \ 1391 1391 %(Histogram[pfx+'Rf'],Histogram[pfx+'Rf^2'],Histogram[pfx+'Nref']) 1392 1392 … … 1407 1407 if Print: 1408 1408 if 'Scale' in PhFrExtPOSig: 1409 print ' Phase fraction : %10.4f, sig %10.4f'%(hapData['Scale'][0],PhFrExtPOSig['Scale'])1409 print >>pFile,' Phase fraction : %10.4f, sig %10.4f'%(hapData['Scale'][0],PhFrExtPOSig['Scale']) 1410 1410 if 'Extinction' in PhFrExtPOSig: 1411 print ' Extinction coeff: %10.4f, sig %10.4f'%(hapData['Extinction'][0],PhFrExtPOSig['Extinction'])1411 print >>pFile,' Extinction coeff: %10.4f, sig %10.4f'%(hapData['Extinction'][0],PhFrExtPOSig['Extinction']) 1412 1412 if hapData['Pref.Ori.'][0] == 'MD': 1413 1413 if 'MD' in PhFrExtPOSig: 1414 print ' March-Dollase PO: %10.4f, sig %10.4f'%(hapData['Pref.Ori.'][1],PhFrExtPOSig['MD'])1414 print >>pFile,' March-Dollase PO: %10.4f, sig %10.4f'%(hapData['Pref.Ori.'][1],PhFrExtPOSig['MD']) 1415 1415 else: 1416 1416 PrintSHPOAndSig(hapData['Pref.Ori.'],PhFrExtPOSig) … … 1454 1454 elif 'HKLF' in histogram: 1455 1455 pfx = str(pId)+':'+str(hId)+':' 1456 print ' Final refinement RF, RF^2 = %.2f%%, %.2f%% on %d reflections' \1456 print >>pFile,' Final refinement RF, RF^2 = %.2f%%, %.2f%% on %d reflections' \ 1457 1457 %(Histogram[pfx+'Rf'],Histogram[pfx+'Rf^2'],Histogram[pfx+'Nref']) 1458 print ' HKLF histogram weight factor = ','%.3f'%(Histogram['wtFactor'])1458 print >>pFile,' HKLF histogram weight factor = ','%.3f'%(Histogram['wtFactor']) 1459 1459 ScalExtSig = {} 1460 1460 for item in ['Scale','Ep','Eg','Es']: … … 1465 1465 if Print: 1466 1466 if 'Scale' in ScalExtSig: 1467 print ' Scale factor : %10.4f, sig %10.4f'%(hapData['Scale'][0],ScalExtSig['Scale'])1467 print >>pFile,' Scale factor : %10.4f, sig %10.4f'%(hapData['Scale'][0],ScalExtSig['Scale']) 1468 1468 # fix after it runs! 1469 # print '\n Phase: ',phase,' in histogram: ',histogram1470 # print 135*'-'1471 # print ' Scale factor : %10.4f'%(hapData['Scale'][0]),' Refine?',hapData['Scale'][1]1472 # print ' Extinction approx: %10s'%(extApprox),' Type: %15s'%(extType),' tbar: %6.3f'%(extParms['Tbar'])1469 # print >>pFile,'\n Phase: ',phase,' in histogram: ',histogram 1470 # print >>pFile,135*'-' 1471 # print >>pFile,' Scale factor : %10.4f'%(hapData['Scale'][0]),' Refine?',hapData['Scale'][1] 1472 # print >>pFile,' Extinction approx: %10s'%(extApprox),' Type: %15s'%(extType),' tbar: %6.3f'%(extParms['Tbar']) 1473 1473 # text = ' Parameters :' 1474 1474 # for eKey in Ekey: 1475 1475 # text += ' %4s : %10.3g Refine? '%(eKey,extParms[eKey][0])+str(extParms[eKey][1]) 1476 # print text1476 # print >>pFile,text 1477 1477 1478 1478 ################################################################################ … … 1480 1480 ################################################################################ 1481 1481 1482 def GetHistogramData(Histograms,Print=True ):1482 def GetHistogramData(Histograms,Print=True,pFile=None): 1483 1483 1484 1484 def GetBackgroundParms(hId,Background): … … 1558 1558 Back = Background[0] 1559 1559 DebyePeaks = Background[1] 1560 print '\n Background function: ',Back[0],' Refine?',bool(Back[1])1560 print >>pFile,'\n Background function: ',Back[0],' Refine?',bool(Back[1]) 1561 1561 line = ' Coefficients: ' 1562 1562 for i,back in enumerate(Back[3:]): … … 1564 1564 if i and not i%10: 1565 1565 line += '\n'+15*' ' 1566 print line1566 print >>pFile,line 1567 1567 if DebyePeaks['nDebye']: 1568 print '\n Debye diffuse scattering coefficients'1568 print >>pFile,'\n Debye diffuse scattering coefficients' 1569 1569 parms = ['DebyeA','DebyeR','DebyeU'] 1570 1570 line = ' names : ' 1571 1571 for parm in parms: 1572 1572 line += '%8s refine?'%(parm) 1573 print line1573 print >>pFile,line 1574 1574 for j,term in enumerate(DebyePeaks['debyeTerms']): 1575 1575 line = ' term'+'%2d'%(j)+':' 1576 1576 for i in range(3): 1577 1577 line += '%10.3f %5s'%(term[2*i],bool(term[2*i+1])) 1578 print line1578 print >>pFile,line 1579 1579 if DebyePeaks['nPeaks']: 1580 print '\n Single peak coefficients'1580 print >>pFile,'\n Single peak coefficients' 1581 1581 parms = ['BkPkpos','BkPkint','BkPksig','BkPkgam'] 1582 1582 line = ' names : ' 1583 1583 for parm in parms: 1584 1584 line += '%8s refine?'%(parm) 1585 print line1585 print >>pFile,line 1586 1586 for j,term in enumerate(DebyePeaks['peaksList']): 1587 1587 line = ' peak'+'%2d'%(j)+':' 1588 1588 for i in range(4): 1589 1589 line += '%10.3f %5s'%(term[2*i],bool(term[2*i+1])) 1590 print line1590 print >>pFile,line 1591 1591 1592 1592 def PrintInstParms(Inst): 1593 print '\n Instrument Parameters:'1593 print >>pFile,'\n Instrument Parameters:' 1594 1594 ptlbls = ' name :' 1595 1595 ptstr = ' value :' … … 1603 1603 else: 1604 1604 varstr += '%12s' % (str(bool(Inst[2][i+1]))) 1605 print ptlbls1606 print ptstr1607 print varstr1605 print >>pFile,ptlbls 1606 print >>pFile,ptstr 1607 print >>pFile,varstr 1608 1608 1609 1609 def PrintSampleParms(Sample): 1610 print '\n Sample Parameters:'1611 print ' Goniometer omega = %.2f, chi = %.2f, phi = %.2f'% \1610 print >>pFile,'\n Sample Parameters:' 1611 print >>pFile,' Goniometer omega = %.2f, chi = %.2f, phi = %.2f'% \ 1612 1612 (Sample['Omega'],Sample['Chi'],Sample['Phi']) 1613 1613 ptlbls = ' name :' … … 1626 1626 varstr += '%14s'%(str(bool(Sample[item][1]))) 1627 1627 1628 print ptlbls1629 print ptstr1630 print varstr1628 print >>pFile,ptlbls 1629 print >>pFile,ptstr 1630 print >>pFile,varstr 1631 1631 1632 1632 … … 1668 1668 1669 1669 if Print: 1670 print '\n Histogram: ',histogram,' histogram Id: ',hId1671 print 135*'-'1670 print >>pFile,'\n Histogram: ',histogram,' histogram Id: ',hId 1671 print >>pFile,135*'-' 1672 1672 Units = {'C':' deg','T':' msec'} 1673 1673 units = Units[controlDict[pfx+'histType'][2]] 1674 1674 Limits = controlDict[pfx+'Limits'] 1675 print ' Instrument type: ',Sample['Type']1676 print ' Histogram limits: %8.2f%s to %8.2f%s'%(Limits[0],units,Limits[1],units)1675 print >>pFile,' Instrument type: ',Sample['Type'] 1676 print >>pFile,' Histogram limits: %8.2f%s to %8.2f%s'%(Limits[0],units,Limits[1],units) 1677 1677 PrintSampleParms(Sample) 1678 1678 PrintInstParms(Inst) … … 1689 1689 return histVary,histDict,controlDict 1690 1690 1691 def SetHistogramData(parmDict,sigDict,Histograms,Print=True ):1691 def SetHistogramData(parmDict,sigDict,Histograms,Print=True,pFile=None): 1692 1692 1693 1693 def SetBackgroundParms(pfx,Background,parmDict,sigDict): … … 1757 1757 sigstr += 10*' ' 1758 1758 if refine: 1759 print '\n Background function: ',Back[0]1760 print valstr1761 print sigstr1759 print >>pFile,'\n Background function: ',Back[0] 1760 print >>pFile,valstr 1761 print >>pFile,sigstr 1762 1762 if DebyePeaks['nDebye']: 1763 1763 ifAny = False … … 1773 1773 sigstr += ptfmt%(sigDict[item]) 1774 1774 if ifAny: 1775 print '\n Debye diffuse scattering coefficients'1776 print names1777 print ptstr1778 print sigstr1775 print >>pFile,'\n Debye diffuse scattering coefficients' 1776 print >>pFile,names 1777 print >>pFile,ptstr 1778 print >>pFile,sigstr 1779 1779 if DebyePeaks['nPeaks']: 1780 1780 ifAny = False … … 1790 1790 sigstr += ptfmt%(sigDict[item]) 1791 1791 if ifAny: 1792 print '\n Single peak coefficients'1793 print names1794 print ptstr1795 print sigstr1792 print >>pFile,'\n Single peak coefficients' 1793 print >>pFile,names 1794 print >>pFile,ptstr 1795 print >>pFile,sigstr 1796 1796 1797 1797 def PrintInstParmsSig(Inst,instSig): … … 1810 1810 sigstr += 12*' ' 1811 1811 if refine: 1812 print '\n Instrument Parameters:'1813 print ptlbls1814 print ptstr1815 print sigstr1812 print >>pFile,'\n Instrument Parameters:' 1813 print >>pFile,ptlbls 1814 print >>pFile,ptstr 1815 print >>pFile,sigstr 1816 1816 1817 1817 def PrintSampleParmsSig(Sample,sampleSig): … … 1841 1841 1842 1842 if refine: 1843 print '\n Sample Parameters:'1844 print ptlbls1845 print ptstr1846 print sigstr1843 print >>pFile,'\n Sample Parameters:' 1844 print >>pFile,ptlbls 1845 print >>pFile,ptstr 1846 print >>pFile,sigstr 1847 1847 1848 1848 histoList = Histograms.keys() … … 1862 1862 sampSig = SetSampleParms(pfx,Sample,parmDict,sigDict) 1863 1863 1864 print '\n Histogram: ',histogram,' histogram Id: ',hId1865 print 135*'-'1866 print ' Final refinement wR = %.2f%% on %d observations in this histogram'%(Histogram['wR'],Histogram['Nobs'])1867 print ' PWDR histogram weight factor = '+'%.3f'%(Histogram['wtFactor'])1864 print >>pFile,'\n Histogram: ',histogram,' histogram Id: ',hId 1865 print >>pFile,135*'-' 1866 print >>pFile,' Final refinement wR = %.2f%% on %d observations in this histogram'%(Histogram['wR'],Histogram['Nobs']) 1867 print >>pFile,' PWDR histogram weight factor = '+'%.3f'%(Histogram['wtFactor']) 1868 1868 if Print: 1869 print ' Instrument type: ',Sample['Type']1869 print >>pFile,' Instrument type: ',Sample['Type'] 1870 1870 PrintSampleParmsSig(Sample,sampSig) 1871 1871 PrintInstParmsSig(Inst,instSig) … … 3176 3176 ptx.pyqlmninit() #initialize fortran arrays for spherical harmonics 3177 3177 3178 ShowBanner() 3178 printFile = open(ospath.splitext(GPXfile)[0]+'.lst','w') 3179 ShowBanner(printFile) 3179 3180 varyList = [] 3180 3181 parmDict = {} 3181 3182 G2mv.InitVars() 3182 3183 Controls = GetControls(GPXfile) 3183 ShowControls(Controls )3184 ShowControls(Controls,printFile) 3184 3185 calcControls = {} 3185 3186 calcControls.update(Controls) … … 3195 3196 print ' *** Refine aborted ***' 3196 3197 raise Exception 3197 Natoms,atomIndx,phaseVary,phaseDict,pawleyLookup,FFtables,BLtables = GetPhaseData(Phases,restraintDict )3198 Natoms,atomIndx,phaseVary,phaseDict,pawleyLookup,FFtables,BLtables = GetPhaseData(Phases,restraintDict,pFile=printFile) 3198 3199 calcControls['atomIndx'] = atomIndx 3199 3200 calcControls['Natoms'] = Natoms 3200 3201 calcControls['FFtables'] = FFtables 3201 3202 calcControls['BLtables'] = BLtables 3202 hapVary,hapDict,controlDict = GetHistogramPhaseData(Phases,Histograms )3203 hapVary,hapDict,controlDict = GetHistogramPhaseData(Phases,Histograms,pFile=printFile) 3203 3204 calcControls.update(controlDict) 3204 histVary,histDict,controlDict = GetHistogramData(Histograms )3205 histVary,histDict,controlDict = GetHistogramData(Histograms,pFile=printFile) 3205 3206 calcControls.update(controlDict) 3206 3207 varyList = phaseVary+hapVary+histVary … … 3261 3262 Rvals['Rwp'] = np.sqrt(Rvals['chisq']/Histograms['sumwYo'])*100. #to % 3262 3263 Rvals['GOF'] = Rvals['chisq']/(Histograms['Nobs']-len(varyList)) 3263 print '\n Refinement results:'3264 print 135*'-'3265 print ' Number of function calls:',result[2]['nfev'],' Number of observations: ',Histograms['Nobs'],' Number of parameters: ',len(varyList)3266 print ' Refinement time = %8.3fs, %8.3fs/cycle, for %d cycles'%(runtime,runtime/ncyc,ncyc)3267 print ' wR = %7.2f%%, chi**2 = %12.6g, reduced chi**2 = %6.2f'%(Rvals['Rwp'],Rvals['chisq'],Rvals['GOF'])3264 print >>printFile,'\n Refinement results:' 3265 print >>printFile,135*'-' 3266 print >>printFile,' Number of function calls:',result[2]['nfev'],' Number of observations: ',Histograms['Nobs'],' Number of parameters: ',len(varyList) 3267 print >>printFile,' Refinement time = %8.3fs, %8.3fs/cycle, for %d cycles'%(runtime,runtime/ncyc,ncyc) 3268 print >>printFile,' wR = %7.2f%%, chi**2 = %12.6g, reduced chi**2 = %6.2f'%(Rvals['Rwp'],Rvals['chisq'],Rvals['GOF']) 3268 3269 try: 3269 3270 covMatrix = result[1]*Rvals['GOF'] … … 3305 3306 # add the uncertainties into the esd dictionary (sigDict) 3306 3307 sigDict.update(G2mv.ComputeDepESD(covMatrix,varyList,parmDict)) 3307 SetPhaseData(parmDict,sigDict,Phases,covData )3308 SetHistogramPhaseData(parmDict,sigDict,Phases,Histograms )3309 SetHistogramData(parmDict,sigDict,Histograms )3310 G2mv.PrintIndependentVars(parmDict,varyList,sigDict )3308 SetPhaseData(parmDict,sigDict,Phases,covData,printFile) 3309 SetHistogramPhaseData(parmDict,sigDict,Phases,Histograms,pFile=printFile) 3310 SetHistogramData(parmDict,sigDict,Histograms,pFile=printFile) 3311 G2mv.PrintIndependentVars(parmDict,varyList,sigDict,printFile) 3311 3312 SetUsedHistogramsAndPhases(GPXfile,Histograms,Phases,covData) 3313 printFile.close() 3314 print ' Refinement results are in file: '+ospath.splitext(GPXfile)[0]+'.lst' 3315 print ' ***** Refinement successful *****' 3312 3316 3313 3317 #for testing purposes!!! … … 3333 3337 ptx.pyqlmninit() #initialize fortran arrays for spherical harmonics 3334 3338 3335 ShowBanner()3339 printFile = open(ospath.splitext(GPXfile)[0]+'.lst','w') 3336 3340 print ' Sequential Refinement' 3341 ShowBanner(printFile) 3337 3342 G2mv.InitVars() 3338 3343 Controls = GetControls(GPXfile) 3339 ShowControls(Controls )3344 ShowControls(Controls,printFile) 3340 3345 constrDict,fixedList = GetConstraints(GPXfile) 3341 3346 restraintDict = GetRestraints(GPXfile) … … 3349 3354 print ' *** Refine aborted ***' 3350 3355 raise Exception 3351 Natoms,atomIndx,phaseVary,phaseDict,pawleyLookup,FFtables,BLtables = GetPhaseData(Phases,restraintDict,False )3356 Natoms,atomIndx,phaseVary,phaseDict,pawleyLookup,FFtables,BLtables = GetPhaseData(Phases,restraintDict,False,printFile) 3352 3357 if 'Seq Data' in Controls: 3353 3358 histNames = Controls['Seq Data'] … … 3449 3454 Rvals['GOF'] = Rvals['Rwp']/(Histo['Nobs']-len(varyList)) 3450 3455 Rvals['Nobs'] = Histo['Nobs'] 3451 print '\n Refinement results for histogram: v'+histogram3452 print 135*'-'3453 print ' Number of function calls:',result[2]['nfev'],' Number of observations: ',Histo['Nobs'],' Number of parameters: ',len(varyList)3454 print ' Refinement time = %8.3fs, %8.3fs/cycle, for %d cycles'%(runtime,runtime/ncyc,ncyc)3455 print ' wRp = %7.2f%%, chi**2 = %12.6g, reduced chi**2 = %6.2f'%(Rvals['Rwp'],Rvals['chisq'],Rvals['GOF'])3456 print >>printFile,'\n Refinement results for histogram: v'+histogram 3457 print >>printFile,135*'-' 3458 print >>printFile,' Number of function calls:',result[2]['nfev'],' Number of observations: ',Histo['Nobs'],' Number of parameters: ',len(varyList) 3459 print >>printFile,' Refinement time = %8.3fs, %8.3fs/cycle, for %d cycles'%(runtime,runtime/ncyc,ncyc) 3460 print >>printFile,' wRp = %7.2f%%, chi**2 = %12.6g, reduced chi**2 = %6.2f'%(Rvals['Rwp'],Rvals['chisq'],Rvals['GOF']) 3456 3461 try: 3457 3462 covMatrix = result[1]*Rvals['GOF'] … … 3483 3488 covData = {'variables':result[0],'varyList':varyList,'sig':sig,'Rvals':Rvals, 3484 3489 'covMatrix':covMatrix,'title':histogram,'newAtomDict':newAtomDict,'newCellDict':newCellDict} 3485 SetHistogramPhaseData(parmDict,sigDict,Phases,Histo,ifPrint )3486 SetHistogramData(parmDict,sigDict,Histo,ifPrint )3490 SetHistogramPhaseData(parmDict,sigDict,Phases,Histo,ifPrint,printFile) 3491 SetHistogramData(parmDict,sigDict,Histo,ifPrint,printFile) 3487 3492 SeqResult[histogram] = covData 3488 3493 SetUsedHistogramsAndPhases(GPXfile,Histo,Phases,covData,makeBack) 3489 3494 makeBack = False 3490 3495 SetSeqResult(GPXfile,Histograms,SeqResult) 3496 printFile.close() 3497 print ' Sequential refinement results are in file: '+ospath.splitext(GPXfile)[0]+'.lst' 3498 print ' ***** Sequential refinement successful *****' 3491 3499 3492 3500 def DistAngle(DisAglCtls,DisAglData):
Note: See TracChangeset
for help on using the changeset viewer.