Changeset 693 for trunk


Ignore:
Timestamp:
Jul 21, 2012 1:44:56 PM (13 years ago)
Author:
vondreele
Message:

LS refinement results now printed to a separate file "name.lst"; it is overwritten each time refine or sequential refine is run. Console only contains error messages.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • TabularUnified trunk/GSASIImapvars.py

    r668 r693  
    661661    return independentVars
    662662
    663 def PrintIndependentVars(parmDict,varyList,sigDict,PrintAll=False):
     663def PrintIndependentVars(parmDict,varyList,sigDict,PrintAll=False,pFile=None):
    664664    '''Print the values and uncertainties on the independent variables'''
    665665    global dependentParmList,arrayList,invarrayList,indParmList,fixedDict
     
    673673    if len(printlist) == 0: return
    674674    s1 = ''
    675     print 130*'-'
    676     print "Variables generated by constraints"
     675    print >>pFile,130*'-'
     676    print >>pFile,"Variables generated by constraints"
    677677    printlist.append(3*[None])
    678678    for name,val,esd in printlist:
    679679        if len(s1) > 120 or name is None:
    680             print
    681             print s1
    682             print s2
    683             print s3
     680            print >>pFile,''
     681            print >>pFile,s1
     682            print >>pFile,s2
     683            print >>pFile,s3
    684684            s1 = ''
    685685            if name is None: break
  • TabularUnified trunk/GSASIIstruct.py

    r692 r693  
    409409    print 'GPX file save successful'
    410410                       
    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'
     411def 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'
    419419
    420 def ShowControls(Controls):
    421     print ' Least squares controls:'
    422     print ' Refinement type: ',Controls['deriv type']
     420def ShowControls(Controls,pFile=None):
     421    print >>pFile,' Least squares controls:'
     422    print >>pFile,' Refinement type: ',Controls['deriv type']
    423423    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']
    425425    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'])
    428428   
    429429def GetFFtable(General):
     
    527527################################################################################       
    528528                   
    529 def GetPhaseData(PhaseData,RestraintDict=None,Print=True):
     529def GetPhaseData(PhaseData,RestraintDict=None,Print=True,pFile=None):
    530530           
    531531    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*'-'
    535535        for Ename in FFtable:
    536536            ffdata = FFtable[Ename]
    537537            fa = ffdata['fa']
    538538            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' %  \
    540540                (Ename.ljust(8),fa[0],fa[1],fa[2],fa[3],fb[0],fb[1],fb[2],fb[3],ffdata['fc'])
    541541               
    542542    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*'-'
    546546        for Ename in BLtable:
    547547            bldata = BLtable[Ename]
     
    555555            for item in bres:
    556556                line += '%10.5g'%(item)
    557             print line
     557            print >>pFile,line
    558558               
    559559    def PrintAtoms(General,Atoms):
    560         print '\n Atoms:'
     560        print >>pFile,'\n Atoms:'
    561561        line = '   name    type  refine?   x         y         z    '+ \
    562562            '  frac site sym  mult I/A   Uiso     U11     U22     U33     U12     U13     U23'
     
    565565        elif General['Type'] == 'macromolecular':
    566566            line = ' res no  residue  chain '+line
    567         print line
     567        print >>pFile,line
    568568        if General['Type'] == 'nuclear':
    569             print 135*'-'
     569            print >>pFile,135*'-'
    570570            for i,at in enumerate(Atoms):
    571571                line = '%7s'%(at[0])+'%7s'%(at[1])+'%7s'%(at[2])+'%10.5f'%(at[3])+'%10.5f'%(at[4])+ \
     
    577577                    for j in range(6):
    578578                        line += '%8.4f'%(at[11+j])
    579                 print line
     579                print >>pFile,line
    580580       
    581581    def PrintTexture(textureData):
     
    583583            str(textureData['Order'])
    584584        if textureData['Order']:
    585             print topstr+' Refine? '+str(textureData['SH Coeff'][0])
     585            print >>pFile,topstr+' Refine? '+str(textureData['SH Coeff'][0])
    586586        else:
    587             print topstr
     587            print >>pFile,topstr
    588588            return
    589589        names = ['omega','chi','phi']
     
    591591        for name in names:
    592592            line += ' SH '+name+':'+'%12.4f'%(textureData['Sample '+name][1])+' Refine? '+str(textureData['Sample '+name][0])
    593         print line
    594         print '\n Texture coefficients:'
     593        print >>pFile,line
     594        print >>pFile,'\n Texture coefficients:'
    595595        ptlbls = ' names :'
    596596        ptstr =  ' values:'
     
    599599            ptlbls += '%12s'%(item)
    600600            ptstr += '%12.4f'%(SHcoeff[item])
    601         print ptlbls
    602         print ptstr
     601        print >>pFile,ptlbls
     602        print >>pFile,ptstr
    603603       
    604604    def PrintRestraints(phaseRest):
    605605        if phaseRest:
    606             print '\n Restraints:'
     606            print >>pFile,'\n Restraints:'
    607607            names = ['Bonds','Angles','Planes','Volumes']
    608608            for i,name in enumerate(['Bond','Angle','Plane','Chiral']):
    609609                itemRest = phaseRest[name]
    610610                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: '
    613613                    for item in phaseRest[name][names[i]]:
    614614                        text = '   '
     
    617617                            if (a+1)%5 == 0:
    618618                                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])
    620620       
    621     if Print: print ' Phases:'
     621    if Print:print  >>pFile,' Phases:'
    622622    phaseVary = []
    623623    phaseDict = {}
     
    715715               
    716716            if Print:
    717                 print '\n Phase name: ',General['Name']
    718                 print 135*'-'
     717                print >>pFile,'\n Phase name: ',General['Name']
     718                print >>pFile,135*'-'
    719719                PrintFFtable(FFtable)
    720720                PrintBLtable(BLtable)
    721                 print ''
    722                 for line in SGtext: print line
     721                print >>pFile,''
     722                for line in SGtext: print >>pFile,line
    723723                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]), \
    725725                    ' alpha =','%.3f'%(cell[4]),' beta =','%.3f'%(cell[5]),' gamma =', \
    726726                    '%.3f'%(cell[6]),' volume =','%.3f'%(cell[7]),' Refine?',cell[0]
     
    840840    return cellSig           
    841841   
    842 def SetPhaseData(parmDict,sigDict,Phases,covData):
     842def SetPhaseData(parmDict,sigDict,Phases,covData,pFile=None):
    843843   
    844844    def PrintAtomsAndSig(General,Atoms,atomsSig):
    845         print '\n Atoms:'
     845        print >>pFile,'\n Atoms:'
    846846        line = '   name      x         y         z      frac   Uiso     U11     U22     U33     U12     U13     U23'
    847847        if General['Type'] == 'magnetic':
     
    849849        elif General['Type'] == 'macromolecular':
    850850            line = ' res no  residue  chain '+line
    851         print line
     851        print >>pFile,line
    852852        if General['Type'] == 'nuclear':
    853             print 135*'-'
     853            print >>pFile,135*'-'
    854854            fmt = {0:'%7s',1:'%7s',3:'%10.5f',4:'%10.5f',5:'%10.5f',6:'%8.3f',10:'%8.5f',
    855855                11:'%8.5f',12:'%8.5f',13:'%8.5f',14:'%8.5f',15:'%8.5f',16:'%8.5f'}
     
    882882                        else:
    883883                            sigstr += 8*' '
    884                 print name
    885                 print valstr
    886                 print sigstr
     884                print >>pFile,name
     885                print >>pFile,valstr
     886                print >>pFile,sigstr
    887887               
    888888    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'])
    890890        names = ['omega','chi','phi']
    891891        namstr = '  names :'
     
    899899            else:
    900900                sigstr += 12*' '
    901         print namstr
    902         print ptstr
    903         print sigstr
    904         print '\n Texture coefficients:'
     901        print >>pFile,namstr
     902        print >>pFile,ptstr
     903        print >>pFile,sigstr
     904        print >>pFile,'\n Texture coefficients:'
    905905        namstr = '  names :'
    906906        ptstr =  '  values:'
     
    914914            else:
    915915                sigstr += 12*' '
    916         print namstr
    917         print ptstr
    918         print sigstr
     916        print >>pFile,namstr
     917        print >>pFile,ptstr
     918        print >>pFile,sigstr
    919919       
    920920           
    921     print '\n Phases:'
     921    print >>pFile,'\n Phases:'
    922922    for phase in Phases:
    923         print ' Result for phase: ',phase
     923        print >>pFile,' Result for phase: ',phase
    924924        Phase = Phases[phase]
    925925        General = Phase['General']
     
    932932            A,sigA = cellFill(pfx,SGData,parmDict,sigDict)
    933933            cellSig = getCellEsd(pfx,SGData,A,covData)  #includes sigVol
    934             print ' Reciprocal metric tensor: '
     934            print >>pFile,' Reciprocal metric tensor: '
    935935            ptfmt = "%15.9f"
    936936            names = ['A11','A22','A33','A12','A13','A23']
     
    945945                else:
    946946                    sigstr += 15*' '
    947             print namstr
    948             print ptstr
    949             print sigstr
     947            print >>pFile,namstr
     948            print >>pFile,ptstr
     949            print >>pFile,sigstr
    950950            cell[1:7] = G2lat.A2cell(A)
    951951            cell[7] = G2lat.calc_V(A)
    952             print ' New unit cell:'
     952            print >>pFile,' New unit cell:'
    953953            ptfmt = ["%12.6f","%12.6f","%12.6f","%12.4f","%12.4f","%12.4f","%12.3f"]
    954954            names = ['a','b','c','alpha','beta','gamma','Volume']
     
    963963                else:
    964964                    sigstr += 12*' '
    965             print namstr
    966             print ptstr
    967             print sigstr
     965            print >>pFile,namstr
     966            print >>pFile,ptstr
     967            print >>pFile,sigstr
    968968           
    969969        if Phase['General'].get('doPawley'):
     
    10211021################################################################################       
    10221022                   
    1023 def GetHistogramPhaseData(Phases,Histograms,Print=True):
     1023def GetHistogramPhaseData(Phases,Histograms,Print=True,pFile=None):
    10241024   
    10251025    def PrintSize(hapData):
     
    10301030                line += ' axial:'+'%12.3f'%(hapData[1][1])+' Refine? '+str(hapData[2][1])
    10311031            line += '\n\t LG mixing coeff.: %12.4f'%(hapData[1][2])+' Refine? '+str(hapData[2][2])
    1032             print line
     1032            print >>pFile,line
    10331033        else:
    1034             print '\n Size model    : %s'%(hapData[0])+ \
     1034            print >>pFile,'\n Size model    : %s'%(hapData[0])+ \
    10351035                '\n\t LG mixing coeff.:%12.4f'%(hapData[1][2])+' Refine? '+str(hapData[2][2])
    10361036            Snames = ['S11','S22','S33','S12','S13','S23']
     
    10421042                ptstr += '%12.6f' % (hapData[4][i])
    10431043                varstr += '%12s' % (str(hapData[5][i]))
    1044             print ptlbls
    1045             print ptstr
    1046             print varstr
     1044            print >>pFile,ptlbls
     1045            print >>pFile,ptstr
     1046            print >>pFile,varstr
    10471047       
    10481048    def PrintMuStrain(hapData,SGData):
     
    10531053                line += ' axial:'+'%12.1f'%(hapData[1][1])+' Refine? '+str(hapData[2][1])
    10541054            line +='\n\t LG mixing coeff.:%12.4f'%(hapData[1][2])+' Refine? '+str(hapData[2][2])
    1055             print line
     1055            print >>pFile,line
    10561056        else:
    1057             print '\n Mustrain model: %s'%(hapData[0])+ \
     1057            print >>pFile,'\n Mustrain model: %s'%(hapData[0])+ \
    10581058                '\n\t LG mixing coeff.:%12.4f'%(hapData[1][2])+' Refine? '+str(hapData[2][2])
    10591059            Snames = G2spc.MustrainNames(SGData)
     
    10651065                ptstr += '%12.6f' % (hapData[4][i])
    10661066                varstr += '%12s' % (str(hapData[5][i]))
    1067             print ptlbls
    1068             print ptstr
    1069             print varstr
     1067            print >>pFile,ptlbls
     1068            print >>pFile,ptstr
     1069            print >>pFile,varstr
    10701070
    10711071    def PrintHStrain(hapData,SGData):
    1072         print '\n Hydrostatic/elastic strain: '
     1072        print >>pFile,'\n Hydrostatic/elastic strain: '
    10731073        Hsnames = G2spc.HStrainNames(SGData)
    10741074        ptlbls = ' names :'
     
    10791079            ptstr += '%12.6f' % (hapData[0][i])
    10801080            varstr += '%12s' % (str(hapData[1][i]))
    1081         print ptlbls
    1082         print ptstr
    1083         print varstr
     1081        print >>pFile,ptlbls
     1082        print >>pFile,ptstr
     1083        print >>pFile,varstr
    10841084
    10851085    def PrintSHPO(hapData):
    1086         print '\n Spherical harmonics preferred orientation: Order:' + \
     1086        print >>pFile,'\n Spherical harmonics preferred orientation: Order:' + \
    10871087            str(hapData[4])+' Refine? '+str(hapData[2])
    10881088        ptlbls = ' names :'
     
    10911091            ptlbls += '%12s'%(item)
    10921092            ptstr += '%12.3f'%(hapData[5][item])
    1093         print ptlbls
    1094         print ptstr
     1093        print >>pFile,ptlbls
     1094        print >>pFile,ptstr
    10951095   
    10961096    hapDict = {}
     
    11821182                               
    11831183                if Print:
    1184                     print '\n Phase: ',phase,' in histogram: ',histogram
    1185                     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]
    11881188                    if hapData['Pref.Ori.'][0] == 'MD':
    11891189                        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], \
    11911191                            ' Axis: %d %d %d'%(Ax[0],Ax[1],Ax[2])
    11921192                    else: #'SH' for spherical harmonics
     
    12371237                        hapVary.append(pfx+eKey)
    12381238                if Print:
    1239                     print '\n Phase: ',phase,' in histogram: ',histogram
    1240                     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'])
    12431243                    text = ' Parameters       :'
    12441244                    for eKey in Ekey:
    12451245                        text += ' %4s : %10.3g Refine? '%(eKey,extParms[eKey][0])+str(extParms[eKey][1])
    1246                     print text
     1246                    print >>pFile,text
    12471247                Histogram['Reflection Lists'] = phase       
    12481248               
    12491249    return hapVary,hapDict,controlDict
    12501250   
    1251 def SetHistogramPhaseData(parmDict,sigDict,Phases,Histograms,Print=True):
     1251def SetHistogramPhaseData(parmDict,sigDict,Phases,Histograms,Print=True,pFile=None):
    12521252   
    12531253    def PrintSizeAndSig(hapData,sizeSig):
     
    12691269                line += ', sig:%8.3f'%(sizeSig[0][2])
    12701270            if refine:
    1271                 print line
     1271                print >>pFile,line
    12721272        else:
    12731273            line += ' LG mix coeff.:%12.4f'%(hapData[1][2])
     
    12881288                    sigstr += 12*' '
    12891289            if refine:
    1290                 print line
    1291                 print ptlbls
    1292                 print ptstr
    1293                 print sigstr
     1290                print >>pFile,line
     1291                print >>pFile,ptlbls
     1292                print >>pFile,ptstr
     1293                print >>pFile,sigstr
    12941294       
    12951295    def PrintMuStrainAndSig(hapData,mustrainSig,SGData):
     
    13101310                line += ', sig:%8.3f'%(mustrainSig[0][2])
    13111311            if refine:
    1312                 print line
     1312                print >>pFile,line
    13131313        else:
    13141314            line += ' LG mix coeff.:%12.4f'%(hapData[1][2])
     
    13291329                    sigstr += 12*' '
    13301330            if refine:
    1331                 print line
    1332                 print ptlbls
    1333                 print ptstr
    1334                 print sigstr
     1331                print >>pFile,line
     1332                print >>pFile,ptlbls
     1333                print >>pFile,ptstr
     1334                print >>pFile,sigstr
    13351335           
    13361336    def PrintHStrainAndSig(hapData,strainSig,SGData):
     
    13491349                sigstr += 12*' '
    13501350        if refine:
    1351             print '\n Hydrostatic/elastic strain: '
    1352             print ptlbls
    1353             print ptstr
    1354             print sigstr
     1351            print >>pFile,'\n Hydrostatic/elastic strain: '
     1352            print >>pFile,ptlbls
     1353            print >>pFile,ptstr
     1354            print >>pFile,sigstr
    13551355       
    13561356    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])
    13581358        ptlbls = ' names :'
    13591359        ptstr =  ' values:'
     
    13661366            else:
    13671367                sigstr += 12*' '
    1368         print ptlbls
    1369         print ptstr
    1370         print sigstr
     1368        print >>pFile,ptlbls
     1369        print >>pFile,ptstr
     1370        print >>pFile,sigstr
    13711371   
    13721372    for phase in Phases:
     
    13821382                #skip if histogram not included e.g. in a sequential refinement
    13831383                continue
    1384             print '\n Phase: ',phase,' in histogram: ',histogram
    1385             print 130*'-'
     1384            print >>pFile,'\n Phase: ',phase,' in histogram: ',histogram
     1385            print >>pFile,130*'-'
    13861386            hapData = HistoPhase[histogram]
    13871387            hId = Histogram['hId']
    13881388            if 'PWDR' in histogram:
    13891389                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'   \
    13911391                    %(Histogram[pfx+'Rf'],Histogram[pfx+'Rf^2'],Histogram[pfx+'Nref'])
    13921392               
     
    14071407                if Print:
    14081408                    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'])
    14101410                    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'])
    14121412                    if hapData['Pref.Ori.'][0] == 'MD':
    14131413                        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'])
    14151415                    else:
    14161416                        PrintSHPOAndSig(hapData['Pref.Ori.'],PhFrExtPOSig)
     
    14541454            elif 'HKLF' in histogram:
    14551455                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'   \
    14571457                    %(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'])
    14591459                ScalExtSig = {}
    14601460                for item in ['Scale','Ep','Eg','Es']:
     
    14651465                if Print:
    14661466                    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'])
    14681468# fix after it runs!               
    1469 #                    print '\n Phase: ',phase,' in histogram: ',histogram
    1470 #                    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'])
    14731473#                    text = ' Parameters       :'
    14741474#                    for eKey in Ekey:
    14751475#                        text += ' %4s : %10.3g Refine? '%(eKey,extParms[eKey][0])+str(extParms[eKey][1])
    1476 #                    print text
     1476#                    print >>pFile,text
    14771477   
    14781478################################################################################
     
    14801480################################################################################       
    14811481                   
    1482 def GetHistogramData(Histograms,Print=True):
     1482def GetHistogramData(Histograms,Print=True,pFile=None):
    14831483   
    14841484    def GetBackgroundParms(hId,Background):
     
    15581558        Back = Background[0]
    15591559        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])
    15611561        line = ' Coefficients: '
    15621562        for i,back in enumerate(Back[3:]):
     
    15641564            if i and not i%10:
    15651565                line += '\n'+15*' '
    1566         print line
     1566        print >>pFile,line
    15671567        if DebyePeaks['nDebye']:
    1568             print '\n Debye diffuse scattering coefficients'
     1568            print >>pFile,'\n Debye diffuse scattering coefficients'
    15691569            parms = ['DebyeA','DebyeR','DebyeU']
    15701570            line = ' names :  '
    15711571            for parm in parms:
    15721572                line += '%8s refine?'%(parm)
    1573             print line
     1573            print >>pFile,line
    15741574            for j,term in enumerate(DebyePeaks['debyeTerms']):
    15751575                line = ' term'+'%2d'%(j)+':'
    15761576                for i in range(3):
    15771577                    line += '%10.3f %5s'%(term[2*i],bool(term[2*i+1]))                   
    1578                 print line
     1578                print >>pFile,line
    15791579        if DebyePeaks['nPeaks']:
    1580             print '\n Single peak coefficients'
     1580            print >>pFile,'\n Single peak coefficients'
    15811581            parms =    ['BkPkpos','BkPkint','BkPksig','BkPkgam']
    15821582            line = ' names :  '
    15831583            for parm in parms:
    15841584                line += '%8s refine?'%(parm)
    1585             print line
     1585            print >>pFile,line
    15861586            for j,term in enumerate(DebyePeaks['peaksList']):
    15871587                line = ' peak'+'%2d'%(j)+':'
    15881588                for i in range(4):
    15891589                    line += '%10.3f %5s'%(term[2*i],bool(term[2*i+1]))                   
    1590                 print line
     1590                print >>pFile,line
    15911591       
    15921592    def PrintInstParms(Inst):
    1593         print '\n Instrument Parameters:'
     1593        print >>pFile,'\n Instrument Parameters:'
    15941594        ptlbls = ' name  :'
    15951595        ptstr =  ' value :'
     
    16031603            else:
    16041604                varstr += '%12s' % (str(bool(Inst[2][i+1])))
    1605         print ptlbls
    1606         print ptstr
    1607         print varstr
     1605        print >>pFile,ptlbls
     1606        print >>pFile,ptstr
     1607        print >>pFile,varstr
    16081608       
    16091609    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'% \
    16121612            (Sample['Omega'],Sample['Chi'],Sample['Phi'])
    16131613        ptlbls = ' name  :'
     
    16261626                varstr += '%14s'%(str(bool(Sample[item][1])))
    16271627
    1628         print ptlbls
    1629         print ptstr
    1630         print varstr
     1628        print >>pFile,ptlbls
     1629        print >>pFile,ptstr
     1630        print >>pFile,varstr
    16311631       
    16321632
     
    16681668   
    16691669            if Print:
    1670                 print '\n Histogram: ',histogram,' histogram Id: ',hId
    1671                 print 135*'-'
     1670                print >>pFile,'\n Histogram: ',histogram,' histogram Id: ',hId
     1671                print >>pFile,135*'-'
    16721672                Units = {'C':' deg','T':' msec'}
    16731673                units = Units[controlDict[pfx+'histType'][2]]
    16741674                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)     
    16771677                PrintSampleParms(Sample)
    16781678                PrintInstParms(Inst)
     
    16891689    return histVary,histDict,controlDict
    16901690   
    1691 def SetHistogramData(parmDict,sigDict,Histograms,Print=True):
     1691def SetHistogramData(parmDict,sigDict,Histograms,Print=True,pFile=None):
    16921692   
    16931693    def SetBackgroundParms(pfx,Background,parmDict,sigDict):
     
    17571757                sigstr += 10*' '
    17581758        if refine:
    1759             print '\n Background function: ',Back[0]
    1760             print valstr
    1761             print sigstr
     1759            print >>pFile,'\n Background function: ',Back[0]
     1760            print >>pFile,valstr
     1761            print >>pFile,sigstr
    17621762        if DebyePeaks['nDebye']:
    17631763            ifAny = False
     
    17731773                    sigstr += ptfmt%(sigDict[item])
    17741774            if ifAny:
    1775                 print '\n Debye diffuse scattering coefficients'
    1776                 print names
    1777                 print ptstr
    1778                 print sigstr
     1775                print >>pFile,'\n Debye diffuse scattering coefficients'
     1776                print >>pFile,names
     1777                print >>pFile,ptstr
     1778                print >>pFile,sigstr
    17791779        if DebyePeaks['nPeaks']:
    17801780            ifAny = False
     
    17901790                    sigstr += ptfmt%(sigDict[item])
    17911791            if ifAny:
    1792                 print '\n Single peak coefficients'
    1793                 print names
    1794                 print ptstr
    1795                 print sigstr
     1792                print >>pFile,'\n Single peak coefficients'
     1793                print >>pFile,names
     1794                print >>pFile,ptstr
     1795                print >>pFile,sigstr
    17961796       
    17971797    def PrintInstParmsSig(Inst,instSig):
     
    18101810                sigstr += 12*' '
    18111811        if refine:
    1812             print '\n Instrument Parameters:'
    1813             print ptlbls
    1814             print ptstr
    1815             print sigstr
     1812            print >>pFile,'\n Instrument Parameters:'
     1813            print >>pFile,ptlbls
     1814            print >>pFile,ptstr
     1815            print >>pFile,sigstr
    18161816       
    18171817    def PrintSampleParmsSig(Sample,sampleSig):
     
    18411841
    18421842        if refine:
    1843             print '\n Sample Parameters:'
    1844             print ptlbls
    1845             print ptstr
    1846             print sigstr
     1843            print >>pFile,'\n Sample Parameters:'
     1844            print >>pFile,ptlbls
     1845            print >>pFile,ptstr
     1846            print >>pFile,sigstr
    18471847       
    18481848    histoList = Histograms.keys()
     
    18621862            sampSig = SetSampleParms(pfx,Sample,parmDict,sigDict)
    18631863
    1864             print '\n Histogram: ',histogram,' histogram Id: ',hId
    1865             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'])
    18681868            if Print:
    1869                 print ' Instrument type: ',Sample['Type']
     1869                print >>pFile,' Instrument type: ',Sample['Type']
    18701870                PrintSampleParmsSig(Sample,sampSig)
    18711871                PrintInstParmsSig(Inst,instSig)
     
    31763176    ptx.pyqlmninit()            #initialize fortran arrays for spherical harmonics
    31773177   
    3178     ShowBanner()
     3178    printFile = open(ospath.splitext(GPXfile)[0]+'.lst','w')
     3179    ShowBanner(printFile)
    31793180    varyList = []
    31803181    parmDict = {}
    31813182    G2mv.InitVars()   
    31823183    Controls = GetControls(GPXfile)
    3183     ShowControls(Controls)
     3184    ShowControls(Controls,printFile)
    31843185    calcControls = {}
    31853186    calcControls.update(Controls)           
     
    31953196        print ' *** Refine aborted ***'
    31963197        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)
    31983199    calcControls['atomIndx'] = atomIndx
    31993200    calcControls['Natoms'] = Natoms
    32003201    calcControls['FFtables'] = FFtables
    32013202    calcControls['BLtables'] = BLtables
    3202     hapVary,hapDict,controlDict = GetHistogramPhaseData(Phases,Histograms)
     3203    hapVary,hapDict,controlDict = GetHistogramPhaseData(Phases,Histograms,pFile=printFile)
    32033204    calcControls.update(controlDict)
    3204     histVary,histDict,controlDict = GetHistogramData(Histograms)
     3205    histVary,histDict,controlDict = GetHistogramData(Histograms,pFile=printFile)
    32053206    calcControls.update(controlDict)
    32063207    varyList = phaseVary+hapVary+histVary
     
    32613262        Rvals['Rwp'] = np.sqrt(Rvals['chisq']/Histograms['sumwYo'])*100.      #to %
    32623263        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'])
    32683269        try:
    32693270            covMatrix = result[1]*Rvals['GOF']
     
    33053306    # add the uncertainties into the esd dictionary (sigDict)
    33063307    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)
    33113312    SetUsedHistogramsAndPhases(GPXfile,Histograms,Phases,covData)
     3313    printFile.close()
     3314    print ' Refinement results are in file: '+ospath.splitext(GPXfile)[0]+'.lst'
     3315    print ' ***** Refinement successful *****'
    33123316   
    33133317#for testing purposes!!!
     
    33333337    ptx.pyqlmninit()            #initialize fortran arrays for spherical harmonics
    33343338   
    3335     ShowBanner()
     3339    printFile = open(ospath.splitext(GPXfile)[0]+'.lst','w')
    33363340    print ' Sequential Refinement'
     3341    ShowBanner(printFile)
    33373342    G2mv.InitVars()   
    33383343    Controls = GetControls(GPXfile)
    3339     ShowControls(Controls)           
     3344    ShowControls(Controls,printFile)           
    33403345    constrDict,fixedList = GetConstraints(GPXfile)
    33413346    restraintDict = GetRestraints(GPXfile)
     
    33493354        print ' *** Refine aborted ***'
    33503355        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)
    33523357    if 'Seq Data' in Controls:
    33533358        histNames = Controls['Seq Data']
     
    34493454            Rvals['GOF'] = Rvals['Rwp']/(Histo['Nobs']-len(varyList))
    34503455            Rvals['Nobs'] = Histo['Nobs']
    3451             print '\n Refinement results for histogram: v'+histogram
    3452             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'])
    34563461            try:
    34573462                covMatrix = result[1]*Rvals['GOF']
     
    34833488        covData = {'variables':result[0],'varyList':varyList,'sig':sig,'Rvals':Rvals,
    34843489            '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)
    34873492        SeqResult[histogram] = covData
    34883493        SetUsedHistogramsAndPhases(GPXfile,Histo,Phases,covData,makeBack)
    34893494        makeBack = False
    34903495    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 *****'
    34913499
    34923500def DistAngle(DisAglCtls,DisAglData):
Note: See TracChangeset for help on using the changeset viewer.