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/GSASIIlattice.py

    r3103 r3136  
    3030# $Id$
    3131########### SVN repository information ###################
     32from __future__ import division, print_function
    3233import math
    3334import copy
     
    6465   
    6566    """
    66     H = int(sec/3600)
    67     M = int(sec/60-H*60)
     67    H = int(sec//3600)
     68    M = int(sec//60-H*60)
    6869    S = sec-3600*H-60*M
    6970    return '%d:%2d:%.2f'%(H,M,S)
     
    334335            atom[cia+2:cia+8] = TransformU6(atom[cia+2:cia+8],invTrans)
    335336        atom[cs:cs+2] = G2spc.SytSym(atom[cx:cx+3],SGData)[:2]
    336         atom[cia+8] = ran.randint(0,sys.maxint)
     337        atom[cia+8] = ran.randint(0,sys.maxsize)
    337338        if cm:
    338339            mag = np.sqrt(np.sum(np.array(atom[cm:cm+3])**2))
     
    346347    newPhase['Atoms'],atCodes = GetUnique(newPhase,atCodes)
    347348    newPhase['Drawing'] = []
    348     newPhase['ranId'] = ran.randint(0,sys.maxint)
     349    newPhase['ranId'] = ran.randint(0,sys.maxsize)
    349350    return newPhase,atCodes
    350351   
     
    476477    A[1][1] = cell[1]*sind(cell[5])  # b sin(gamma)
    477478    A[1][2] = -cell[2]*cosd(cellstar[3])*sind(cell[4]) # - c cos(alpha*) sin(beta)
    478     A[2][2] = 1/cellstar[2]         # 1/c*
     479    A[2][2] = 1./cellstar[2]         # 1/c*
    479480    B = nl.inv(A)
    480481    return A,B
     
    497498    A[1][1] = cell[1]*sind(cell[5])  # b sin(gamma)
    498499    A[1][2] = -cell[2]*cosd(cellstar[3])*sind(cell[4]) # - c cos(alpha*) sin(beta)
    499     A[2][2] = 1/cellstar[2]         # 1/c*
     500    A[2][2] = 1./cellstar[2]         # 1/c*
    500501    B = nl.inv(A)
    501502    return A,B
     
    630631        cellArray = []
    631632        A = np.array(range(N3))
    632         cellGen = np.array([A/N2-1,A/N%N-1,A%N-1]).T
     633        cellGen = np.array([A//N2-1,A//N%N-1,A%N-1]).T
    633634        for cell in cellGen:
    634635            cellArray.append(cell)
     
    883884        return 0        #error - not rhombohedral reflection
    884885    else:
    885         Rh[1] = itk/3
     886        Rh[1] = itk//3
    886887        Rh[0] = Rh[1]+Hx[0]
    887888        Rh[2] = Rh[1]-Hx[1]
     
    947948    elif center.upper() == 'P' and system.lower() == 'triclinic':
    948949        return 13
    949     raise ValueError,'non-standard Bravais lattice center=%s, cell=%s' % (center,system)
     950    raise ValueError('non-standard Bravais lattice center=%s, cell=%s' % (center,system))
    950951
    951952def GenHBravais(dmin,Bravais,A):
     
    11111112                        rdsq = calc_rDsq(H,A)
    11121113                        if 0 < rdsq <= dminsq:
    1113                             HKL.append([h,k,l,1/math.sqrt(rdsq)])
     1114                            HKL.append([h,k,l,1./math.sqrt(rdsq)])
    11141115    elif SGLaue == '2/m':                #monoclinic
    11151116        axisnum = 1 + ['a','b','c'].index(SGUniq)
     
    11261127                        rdsq = calc_rDsq(H,A)
    11271128                        if 0 < rdsq <= dminsq:
    1128                             HKL.append([h,k,l,1/math.sqrt(rdsq)])
     1129                            HKL.append([h,k,l,1./math.sqrt(rdsq)])
    11291130                    [h,k,l] = SwapIndx(axisnum,[h,k,l])
    11301131    elif SGLaue in ['mmm','4/m','6/m']:            #orthorhombic
     
    11391140                        rdsq = calc_rDsq(H,A)
    11401141                        if 0 < rdsq <= dminsq:
    1141                             HKL.append([h,k,l,1/math.sqrt(rdsq)])
     1142                            HKL.append([h,k,l,1./math.sqrt(rdsq)])
    11421143    elif SGLaue in ['4/mmm','6/mmm']:                  #tetragonal & hexagonal
    11431144        for l in range(Hmax[2]+1):
     
    11491150                        rdsq = calc_rDsq(H,A)
    11501151                        if 0 < rdsq <= dminsq:
    1151                             HKL.append([h,k,l,1/math.sqrt(rdsq)])
     1152                            HKL.append([h,k,l,1./math.sqrt(rdsq)])
    11521153    elif SGLaue in ['3m1','31m','3','3R','3mR']:                  #trigonals
    11531154        for l in range(-Hmax[2],Hmax[2]+1):
     
    11711172                        rdsq = calc_rDsq(H,A)
    11721173                        if 0 < rdsq <= dminsq:
    1173                             HKL.append([H[0],H[1],H[2],1/math.sqrt(rdsq)])
     1174                            HKL.append([H[0],H[1],H[2],1./math.sqrt(rdsq)])
    11741175    else:                                   #cubic
    11751176        for h in range(Hmax[0]+1):
     
    11861187                        rdsq = calc_rDsq(H,A)
    11871188                        if 0 < rdsq <= dminsq:
    1188                             HKL.append([h,k,l,1/math.sqrt(rdsq)])
     1189                            HKL.append([h,k,l,1./math.sqrt(rdsq)])
    11891190    return sortHKLd(HKL,True,True)
    11901191   
     
    12251226                DH = SSdH[dH]
    12261227                H = [h+DH[0],k+DH[1],l+DH[2]]
    1227                 d = 1/np.sqrt(calc_rDsq(H,A))
     1228                d = 1./np.sqrt(calc_rDsq(H,A))
    12281229                if d >= dmin:
    12291230                    HKLM = np.array([h,k,l,dH])
     
    15761577            if M > 0:
    15771578                if L%12 == 2:
    1578                     if M <= L/12: return True
     1579                    if M <= L//12: return True
    15791580                else:
    1580                     if M <= L/12+1: return True
     1581                    if M <= L//12+1: return True
    15811582        elif SGLaue == 'm3m':
    15821583            if M > 0:
    15831584                if L%12 == 2:
    1584                     if M <= L/12: return True
     1585                    if M <= L//12: return True
    15851586                else:
    1586                     if M <= L/12+1: return True
     1587                    if M <= L//12+1: return True
    15871588    return False
    15881589       
     
    15901591    'needs doc string'
    15911592    coeffNames = []
    1592     for iord in [2*i+2 for i in range(L/2)]:
     1593    for iord in [2*i+2 for i in range(L//2)]:
    15931594        for m in [i-iord for i in range(2*iord+1)]:
    15941595            if OdfChk(SamSym,iord,m):
     
    17761777            Kcl = 0.
    17771778        for j in range(0,L+1,4):
    1778             im = j/4
     1779            im = j//4
    17791780            if 'array' in str(type(phi)) and np.any(phi.shape):
    17801781                pcrs = ptx.pyplmpsi(L,j,len(phi),phi)[0]
     
    18371838        Kcl = 0.0
    18381839        for j in range(0,L+1,4):
    1839             im = j/4
     1840            im = j//4
    18401841            pcrs,dum = ptx.pyplmpsi(L,j,1,phi)
    18411842            Kcl += BOH['L=%d'%(L)][N-1][im]*pcrs*cosd(j*beta)       
     
    18921893            Kcl = 0.0
    18931894            for j in range(0,l+1,4):
    1894                 im = j/4
     1895                im = j//4
    18951896                pcrs,dum = ptx.pyplmpsi(l,j,1,phi)
    18961897                Kcl += BOH['L='+str(l)][n-1][im]*pcrs*cosd(j*beta)       
     
    19491950                Kcl = 0.0
    19501951                for j in range(0,l+1,4):
    1951                     im = j/4
     1952                    im = j//4
    19521953                    pcrs,dum = ptx.pyplmpsi(l,j,len(beta),phi)
    19531954                    Kcl += BOH['L=%d'%(l)][n-1][im]*pcrs*cosd(j*beta)       
     
    23202321        for H in hklO:
    23212322            if H not in hklN:
    2322                 print H,' missing from hkl from GSASII'
     2323                print ('%d %s'%(H,' missing from hkl from GSASII'))
    23232324                err = False
    23242325        assert(err)
     
    23332334    for test in selftestlist:
    23342335        test()
    2335     print "OK"
     2336    print ("OK")
Note: See TracChangeset for help on using the changeset viewer.