Ignore:
Timestamp:
Aug 23, 2017 3:05:51 PM (4 years ago)
Author:
odonnell
Message:

remove wx dependency for GSASIIscriptable

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/GSASIIstrMain.py

    r3007 r3023  
    3737acosd = lambda x: 180.*np.arccos(x)/np.pi
    3838atan2d = lambda y,x: 180.*np.arctan2(y,x)/np.pi
    39    
     39
    4040ateln2 = 8.0*math.log(2.0)
    4141DEBUG = True
     
    4343def RefineCore(Controls,Histograms,Phases,restraintDict,rigidbodyDict,parmDict,varyList,
    4444    calcControls,pawleyLookup,ifPrint,printFile,dlg):
    45     'Core optimization routines, shared between SeqRefine and Refine'
     45    '''Core optimization routines, shared between SeqRefine and Refine
     46
     47    :returns: 5-tuple of ifOk (bool), Rvals (dict), result, covMatrix, sig
     48    '''
    4649#    print 'current',varyList
    4750#    for item in parmDict: print item,parmDict[item] ######### show dict just before refinement
     
    5356        # test code to compute GOF and save for external repeat
    5457        #args = ([Histograms,Phases,restraintDict,rigidbodyDict],parmDict,varyList,calcControls,pawleyLookup,dlg)
    55         #print '*** before fit chi**2',np.sum(G2stMth.errRefine(values,*args)**2)           
     58        #print '*** before fit chi**2',np.sum(G2stMth.errRefine(values,*args)**2)
    5659        #fl = open('beforeFit.cpickle','wb')
    5760        #import cPickle
     
    6265        Xtol = Controls['SVDtol']
    6366        Factor = Controls['shift factor']
    64         if 'Jacobian' in Controls['deriv type']:           
     67        if 'Jacobian' in Controls['deriv type']:
    6568            result = so.leastsq(G2stMth.errRefine,values,Dfun=G2stMth.dervRefine,full_output=True,
    6669                ftol=Ftol,col_deriv=True,factor=Factor,
     
    124127                    if val:
    125128                        print 'Removing parameter: ',varyList[num-i]
    126                         del(varyList[num-i])                   
     129                        del(varyList[num-i])
    127130            else:
    128131                Ipvt = result[2]['ipvt']
     
    139142    import pytexture as ptx
    140143    ptx.pyqlmninit()            #initialize fortran arrays for spherical harmonics
    141    
     144
    142145    printFile = open(ospath.splitext(GPXfile)[0]+'.lst','w')
    143146    G2stIO.ShowBanner(printFile)
    144147    varyList = []
    145148    parmDict = {}
    146     G2mv.InitVars()   
     149    G2mv.InitVars()
    147150    Controls = G2stIO.GetControls(GPXfile)
    148151    G2stIO.ShowControls(Controls,printFile)
    149152    calcControls = {}
    150     calcControls.update(Controls)           
     153    calcControls.update(Controls)
    151154    constrDict,fixedList = G2stIO.GetConstraints(GPXfile)
    152155    restraintDict = G2stIO.GetRestraints(GPXfile)
     
    199202        return False,' Constraint error'
    200203#    print G2mv.VarRemapShow(varyList)
    201    
     204
    202205    ifPrint = True
    203206    print >>printFile,'\n Refinement results:'
     
    229232        printFile.close()
    230233        return False,Msg.msg
    231    
     234
    232235#for testing purposes!!!
    233236    if DEBUG:
     
    245248    if dlg:
    246249        return True,Rvals
    247        
     250
    248251def phaseCheck(phaseVary,Phases,histogram):
    249252    '''
    250     Removes unused parameters from phase varylist if phase not in histogram 
     253    Removes unused parameters from phase varylist if phase not in histogram
    251254    '''
    252255    pIds = []
     
    263266    import pytexture as ptx
    264267    ptx.pyqlmninit()            #initialize fortran arrays for spherical harmonics
    265    
     268
    266269    printFile = open(ospath.splitext(GPXfile)[0]+'.lst','w')
    267270    print 'Starting Sequential Refinement'
    268271    G2stIO.ShowBanner(printFile)
    269272    Controls = G2stIO.GetControls(GPXfile)
    270     G2stIO.ShowControls(Controls,printFile,SeqRef=True)           
     273    G2stIO.ShowControls(Controls,printFile,SeqRef=True)
    271274    restraintDict = G2stIO.GetRestraints(GPXfile)
    272275    Histograms,Phases = G2stIO.GetUsedHistogramsAndPhases(GPXfile)
     
    351354        # do constraint processing
    352355        #reload(G2mv) # debug
    353         G2mv.InitVars()   
     356        G2mv.InitVars()
    354357        constrDict,fixedList = G2stIO.GetConstraints(GPXfile)
    355358        varyListStart = tuple(varyList) # save the original varyList before dependent vars are removed
     
    404407                print(line[:-2])
    405408            firstVaryList = newVaryList
    406        
     409
    407410        ifPrint = False
    408411        print >>printFile,'\n Refinement results for histogram: v'+histogram
     
    413416            if PlotFunction:
    414417                PlotFunction(G2frame,Histo[histogram]['Data'],histogram)
    415    
     418
    416419            print '  wR = %7.2f%%, chi**2 = %12.6g, reduced chi**2 = %6.2f, last delta chi = %.4f'%(
    417420                Rvals['Rwp'],Rvals['chisq'],Rvals['GOF']**2,Rvals['DelChi2'])
     
    420423            # the uncertainties for dependent constrained parms into the esd dict
    421424            sigDict.update(G2mv.ComputeDepESD(covMatrix,varyList,parmDict))
    422    
     425
    423426            # a dict with values & esds for dependent (constrained) parameters - avoid extraneous holds
    424427            depParmDict = {i:(parmDict[i],sigDict[i]) for i in varyListStart if i in sigDict and i not in varyList}
     
    441444            NewparmDict = {}
    442445            # make dict of varied parameters in current histogram, renamed to
    443             # next histogram, for use in next refinement. 
     446            # next histogram, for use in next refinement.
    444447            if Controls['Copy2Next'] and ihst < len(histNames)-1:
    445448                hId = Histo[histogram]['hId'] # current histogram
     
    470473    :param dict DisAglCtls: contains distance/angle radii usually defined using
    471474       :func:`GSASIIctrlGUI.DisAglDialog`
    472     :param dict DisAglData: contains phase data: 
     475    :param dict DisAglData: contains phase data:
    473476       Items 'OrigAtoms' and 'TargAtoms' contain the atoms to be used
    474477       for distance/angle origins and atoms to be used as targets.
     
    481484      **DistArray** is a dict keyed by the origin atom number where the value is a list
    482485      of distance entries. The value for each distance is a list containing:
    483      
     486
    484487        0) the target atom number (int);
    485488        1) the unit cell offsets added to x,y & z (tuple of int values)
     
    497500
    498501      The AngArray distance reference items refer directly to the index of the items in the
    499       DistArray item for the list of distances for the central atom. 
     502      DistArray item for the list of distances for the central atom.
    500503    '''
    501504    import numpy.ma as ma
    502    
     505
    503506    SGData = DisAglData['SGData']
    504507    Cell = DisAglData['Cell']
    505    
     508
    506509    Amat,Bmat = G2lat.cell2AB(Cell[:6])
    507510    covData = {}
    508     if 'covData' in DisAglData:   
     511    if 'covData' in DisAglData:
    509512        covData = DisAglData['covData']
    510513        covMatrix = covData['covMatrix']
    511514        varyList = covData['varyList']
    512515        pfx = str(DisAglData['pId'])+'::'
    513        
     516
    514517    Factor = DisAglCtls['Factors']
    515518    Radii = dict(zip(DisAglCtls['AtomTypes'],zip(DisAglCtls['BondRadii'],DisAglCtls['AngleRadii'])))
     
    587590    :param dict DisAglCtls: contains distance/angle radii usually defined using
    588591       :func:`GSASIIctrlGUI.DisAglDialog`
    589     :param dict DisAglData: contains phase data: 
     592    :param dict DisAglData: contains phase data:
    590593       Items 'OrigAtoms' and 'TargAtoms' contain the atoms to be used
    591594       for distance/angle origins and atoms to be used as targets.
    592595       Item 'SGData' has the space group information (see :ref:`Space Group object<SGData_table>`)
    593     :param file out: file object for output. Defaults to sys.stdout.   
     596    :param file out: file object for output. Defaults to sys.stdout.
    594597    '''
    595598    def MyPrint(s):
    596599        out.write(s+'\n')
    597600        # print(s,file=out) # use in Python 3
    598    
     601
    599602    def ShowBanner(name):
    600603        MyPrint(80*'*')
     
    612615            else:
    613616                line = ' %s %s'%(item.ljust(30),SGtable[2*i+1].ljust(30))
    614             MyPrint(line)   
     617            MyPrint(line)
    615618    else:
    616619        MyPrint(' ( 1)    %s'%(SGtable[0])) #triclinic case
    617620    Cell = DisAglData['Cell']
    618    
     621
    619622    Amat,Bmat = G2lat.cell2AB(Cell[:6])
    620623    covData = {}
    621     if 'covData' in DisAglData:   
     624    if 'covData' in DisAglData:
    622625        covData = DisAglData['covData']
    623626        pfx = str(DisAglData['pId'])+'::'
     
    628631        line = '\n Unit cell:'
    629632        for name,vals in zip(names,valEsd):
    630             line += name+vals 
     633            line += name+vals
    631634        MyPrint(line)
    632     else: 
     635    else:
    633636        MyPrint('\n Unit cell: a = '+('%.5f'%Cell[0])+' b = '+('%.5f'%Cell[1])+' c = '+('%.5f'%Cell[2])+
    634637            ' alpha = '+('%.3f'%Cell[3])+' beta = '+('%.3f'%Cell[4])+' gamma = '+
     
    677680    SGData = DATData['SGData']
    678681    Cell = DATData['Cell']
    679    
     682
    680683    Amat,Bmat = G2lat.cell2AB(Cell[:6])
    681684    covData = {}
    682685    pfx = ''
    683     if 'covData' in DATData:   
     686    if 'covData' in DATData:
    684687        covData = DATData['covData']
    685688        pfx = str(DATData['pId'])+'::'
     
    689692        symop = atom[-1].split('+')
    690693        if len(symop) == 1:
    691             symop.append('0,0,0')       
     694            symop.append('0,0,0')
    692695        symop[0] = int(symop[0])
    693696        symop[1] = eval(symop[1])
     
    713716        Dist,sig = G2mth.GetDATSig(Oatoms,Datoms,Amat,SGData,covData)
    714717        print ' Distance in '+DATData['Name']+' for atom sequence: ',atmSeq,'=',G2mth.ValEsd(Dist,sig)
    715                
     718
    716719def BestPlane(PlaneData):
    717720    'Needs a doc string'
     
    724727    ShowBanner(PlaneData['Name'])
    725728
    726     Cell = PlaneData['Cell']   
    727     Amat,Bmat = G2lat.cell2AB(Cell[:6])       
     729    Cell = PlaneData['Cell']
     730    Amat,Bmat = G2lat.cell2AB(Cell[:6])
    728731    Atoms = PlaneData['Atoms']
    729732    sumXYZ = np.zeros(3)
     
    750753    for i,xyz in enumerate(XYZ):
    751754        print ' %6s%10.3f%10.3f%10.3f'%(Atoms[i][1].ljust(6),xyz[0],xyz[1],xyz[2])
    752     print '\n Best plane RMS X =%8.3f, Y =%8.3f, Z =%8.3f'%(Evec[Order[2]],Evec[Order[1]],Evec[Order[0]])   
    753            
     755    print '\n Best plane RMS X =%8.3f, Y =%8.3f, Z =%8.3f'%(Evec[Order[2]],Evec[Order[1]],Evec[Order[0]])
     756
    754757def main():
    755758    'Needs a doc string'
     
    766769        exit()
    767770    print("Done. Execution time {:.2f} sec.".format(time.time()-starttime))
    768          
     771
    769772if __name__ == '__main__':
    770773    main()
Note: See TracChangeset for help on using the changeset viewer.