Ignore:
Timestamp:
Oct 23, 2017 11:39:16 AM (4 years ago)
Author:
vondreele
Message:

make GSAS-II python 3.6 compliant & preserve python 2.7 use;changes:
do from future import division, print_function for all GSAS-II py sources
all menu items revised to be py 2.7/3.6 compliant
all wx.OPEN --> wx.FD_OPEN in file dialogs
all integer divides (typically for image pixel math) made explicit with ; ambiguous ones made floats as appropriate
all print "stuff" --> print (stuff)
all print >> pFile,'stuff' --> pFile.writeCIFtemplate('stuff')
all read file opens made explicit 'r' or 'rb'
all cPickle imports made for py2.7 or 3.6 as cPickle or _pickle; test for '2' platform.version_tuple[0] for py 2.7
define cPickleload to select load(fp) or load(fp,encoding='latin-1') for loading gpx files; provides cross compatibility between py 2.7/3.6 gpx files
make dict.keys() as explicit list(dict.keys()) as needed (NB: possible source of remaining py3.6 bugs)
make zip(a,b) as explicit list(zip(a,b)) as needed (NB: possible source of remaining py3.6 bugs)
select unichr/chr according test for '2' platform.version_tuple[0] for py 2.7 (G2pwdGUI * G2plot) for special characters
select wg.EVT_GRID_CELL_CHANGE (classic) or wg.EVT_GRID_CELL_CHANGED (phoenix) in grid Bind
maxint --> maxsize; used in random number stuff
raise Exception,"stuff" --> raise Exception("stuff")
wx 'classic' sizer.DeleteWindows?() or 'phoenix' sizer.Clear(True)
wx 'classic' SetToolTipString?(text) or 'phoenix' SetToolTip?(wx.ToolTip?(text)); define SetToolTipString?(self,text) to handle the choice in plots
status.SetFields? --> status.SetStatusText?
'classic' AddSimpleTool? or 'phoenix' self.AddTool? for plot toolbar; Bind different as well
define GetItemPydata? as it doesn't exist in wx 'phoenix'
allow python versions 2.7 & 3.6 to run GSAS-II
Bind override commented out - no logging capability (NB: remove all logging code?)
all import ContentsValidator? open filename & test if valid then close; filepointer removed from Reader
binary importers (mostly images) test for 'byte' type & convert as needed to satisfy py 3.6 str/byte rules

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/GSASIImapvars.py

    r3057 r3136  
    217217"""
    218218
     219from __future__ import division, print_function
    219220import numpy as np
    220221import sys
     
    346347        # N.B. No "_" names in holds
    347348        if len(cdict) == 1:
    348             fixVlist.append(cdict.keys()[0])
     349            fixVlist.append(list(cdict.keys())[0])
    349350   
    350351    # process equivalences: make a list of dependent and independent vars
     
    407408        errmsg += '\t'+ s + '\n'
    408409    equivVarList = list(set(indepVarList).union(set(depVarList)))
    409     if debug: print 'equivVarList',equivVarList
     410    if debug: print ('equivVarList',equivVarList)
    410411    inboth = set(fixVlist).intersection(set(equivVarList))
    411412    if len(inboth) > 0:
     
    563564    for cdict in constrDict:
    564565        if len(cdict) == 1:
    565             fixedVarList.append(cdict.keys()[0])
     566            fixedVarList.append(list(cdict.keys())[0])
    566567   
    567568    # process equivalences: make a list of dependent and independent vars
     
    584585                    notvaried += mv
    585586                if parmDict is not None and mv not in parmDict:
    586                     print "Dropping equivalence for variable "+str(mv)+". Not defined in this refinement"
     587                    print ("Dropping equivalence for variable "+str(mv)+". Not defined in this refinement")
    587588                    if mv not in dropVarList: dropVarList.append(mv)
    588589                    #msg += "\nCannot equivalence to variable "+str(mv)+". Not defined in this refinement"
     
    590591            for v,m in zip(varlist,invmultarr):
    591592                if parmDict is not None and v not in parmDict:
    592                     print "Dropping equivalence for dep. variable "+str(v)+". Not defined in this refinement"
     593                    print ("Dropping equivalence for dep. variable "+str(v)+". Not defined in this refinement")
    593594                    if v not in dropVarList: dropVarList.append(v)
    594595                    continue
     
    658659    if shortmsg and SeqHist is not None:
    659660        if msg:
    660             print ' *** ERROR in constraint definitions! ***'
    661             print msg
     661            print (' *** ERROR in constraint definitions! ***')
     662            print (msg)
    662663            raise Exception
    663         print '*** Sequential refinement: ignoring constraint definition(s): ***'
    664         print shortmsg
     664        print ('*** Sequential refinement: ignoring constraint definition(s): ***')
     665        print (shortmsg)
    665666        msg = ''
    666667    elif shortmsg:
    667668        msg += shortmsg
    668669    if msg:
    669         print ' *** ERROR in constraint definitions! ***'
    670         print msg
     670        print (' *** ERROR in constraint definitions! ***')
     671        print (msg)
    671672        raise Exception
    672673               
     
    758759        symGenList.append(False)
    759760    if msg:
    760         print ' *** ERROR in constraint definitions! ***'
    761         print msg
    762         print VarRemapShow(varyList)
     761        print (' *** ERROR in constraint definitions! ***')
     762        print (msg)
     763        print (VarRemapShow(varyList))
    763764        raise Exception
    764765    # setup dictionary containing the fixed values
     
    786787            if mv not in dependentVars: dependentVars.append(mv)
    787788    if debug: # on debug, show what is parsed & generated, semi-readable
    788         print 50*'-'
    789         print VarRemapShow(varyList)
    790         print 'Varied: ',varyList
    791         print 'Not Varied: ',fixedVarList
     789        print (50*'-')
     790        print (VarRemapShow(varyList))
     791        print ('Varied: ',varyList)
     792        print ('Not Varied: ',fixedVarList)
    792793
    793794def StoreEquivalence(independentVar,dependentList,symGen=True):
     
    809810    multlist = []
    810811    for var in dependentList:
    811         if isinstance(var, basestring):
     812        if isinstance(var, str):
    812813            mult = 1.0
    813814        elif len(var) == 2:
     
    859860    s2 = ''
    860861    s3 = ''
    861     print >>pFile,130*'-'
    862     print >>pFile,"Variables generated by constraints"
     862    pFile.write(130*'-'+'\n')
     863    pFile.write("Variables generated by constraints\n")
    863864    printlist.append(3*[None])
    864865    for name,val,esd in printlist:
    865866        if len(s1) > 120 or name is None:
    866             print >>pFile,''
    867             print >>pFile,s1
    868             print >>pFile,s2
    869             print >>pFile,s3
     867            pFile.write(''+'\n')
     868            pFile.write(s1+'\n')
     869            pFile.write(s2+'\n')
     870            pFile.write(s3+'\n')
    870871            s1 = ''
    871872            if name is None: break
     
    957958                j = 0
    958959                for v,m in zip(varlist,invmultarr):
    959                     if debug: print 'v,m[0]: ',v,m[0]
     960                    if debug: print ('v,m[0]: ',v,m[0])
    960961                    if len(s1.split('\n')[-1]) > 75: s1 += '\n        '
    961962                    if j > 0: s1 += ' & '
     
    10101011                j = 0
    10111012                for v,m in zip(varlist,invmultarr):
    1012                     if debug: print 'v,m[0]: ',v,m[0]
     1013                    if debug: print ('v,m[0]: ',v,m[0])
    10131014                    if len(s1.split('\n')[-1]) > 75: s1 += '\n        '
    10141015                    if j > 0: s1 += ' =  '
     
    10271028                    j += 1
    10281029                    s += '(%s * %s)' % (m,v)
    1029                 print 'unexpected sym op=',s
     1030                print ('unexpected sym op='+s)
    10301031    return symout
    10311032
     
    10511052            if multarr is None:
    10521053                for v,m in zip(varlist,invmultarr):
    1053                     if debug: print 'start dMdv',dMdv[varyList.index(name)]
    1054                     if debug: print 'add derv',v,'/',m[0],'to derv',name,'add=',derivDict[v] / m[0]
     1054                    if debug: print ('start dMdv',dMdv[varyList.index(name)])
     1055                    if debug: print ('add derv',v,'/',m[0],'to derv',name,'add=',derivDict[v] / m[0])
    10551056                    if m == 0: continue
    10561057                    dMdv[varyList.index(name)] += derivDict[v] / m[0]
    10571058            else:
    10581059                for v,m in zip(varlist,multarr[i,:]):
    1059                     if debug: print 'start dMdv',dMdv[varyList.index(name)]
    1060                     if debug: print 'add derv',v,'*',m,'to derv',name,'add=',m * derivDict[v]
     1060                    if debug: print ('start dMdv',dMdv[varyList.index(name)])
     1061                    if debug: print ('add derv',v,'*',m,'to derv',name,'add=',m * derivDict[v])
    10611062                    if m == 0: continue
    10621063                    dMdv[varyList.index(name)] += m * derivDict[v]
     
    11611162            a[j] -= proj(a[i],a[j])
    11621163        if np.allclose(np.linalg.norm(a[j]),0.0):
    1163             raise Exception,"Singular input to GramSchmidtOrtho"
     1164            raise Exception("Singular input to GramSchmidtOrtho")
    11641165        a[j] /= np.linalg.norm(a[j])
    11651166    return a
     
    11961197            return
    11971198    else:
    1198         raise Exception,'Singular input'
     1199        raise Exception('Singular input')
    11991200
    12001201def _RowEchelon(m,arr,collist):
     
    12481249    errmsg, warnmsg = CheckConstraints(varylist,constrDict,fixedList)
    12491250    if errmsg:
    1250         print "*** Error ********************"
    1251         print errmsg
     1251        print ("*** Error ********************")
     1252        print (errmsg)
    12521253    if warnmsg:
    1253         print "*** Warning ********************"
    1254         print warnmsg
     1254        print ("*** Warning ********************")
     1255        print (warnmsg)
    12551256    if errmsg or warnmsg:
    12561257        sys.exit()
    12571258    groups,parmlist = GroupConstraints(constrDict)
    12581259    GenerateConstraints(groups,parmlist,varylist,constrDict,fixedList)
    1259     print VarRemapShow(varylist)
     1260    print (VarRemapShow(varylist))
    12601261    parmdict.update( {
    12611262        '0:12:Scale': 1.0, '0:11:Scale': 1.0, '0:14:Scale': 1.0, '0:13:Scale': 1.0, '0:0:Scale': 2.0,
     
    12671268        '2::atomx:3':0.23,'2::atomy:3':-.23, '2::atomz:3':-0.11,
    12681269        })
    1269     print 'parmdict start',parmdict
    1270     print 'varylist start',varylist
     1270    print ('parmdict start',parmdict)
     1271    print ('varylist start',varylist)
    12711272    before = parmdict.copy()
    12721273    Map2Dict(parmdict,varylist)
    1273     print 'parmdict before and after Map2Dict'
    1274     print '  key / before / after'
    1275     for key in sorted(parmdict.keys()):
    1276         print '  '+key,'\t',before.get(key),'\t',parmdict[key]
    1277     print 'varylist after',varylist
     1274    print ('parmdict before and after Map2Dict')
     1275    print ('  key / before / after')
     1276    for key in sorted(list(parmdict.keys())):
     1277        print ('  '+key,'\t',before.get(key),'\t',parmdict[key])
     1278    print ('varylist after',varylist)
    12781279    before = parmdict.copy()
    12791280    Dict2Map(parmdict,varylist)
    1280     print 'after Dict2Map'
    1281     print '  key / before / after'
    1282     for key in sorted(parmdict.keys()):
    1283         print '  '+key,'\t',before.get(key),'\t',parmdict[key]
     1281    print ('after Dict2Map')
     1282    print ('  key / before / after')
     1283    for key in sorted(list(parmdict.keys())):
     1284        print ('  '+key,'\t',before.get(key),'\t',parmdict[key])
    12841285#    dMdv = len(varylist)*[0]
    12851286#    deriv = {}
Note: See TracChangeset for help on using the changeset viewer.