Changeset 5360


Ignore:
Timestamp:
Oct 29, 2022 5:45:12 PM (11 months ago)
Author:
toby
Message:

note use of requests package (now optional); deal w/wx4.2.0 bug; save NIST*LATTICE snapshot

Location:
trunk
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/GSASIIctrlGUI.py

    r5356 r5360  
    573573        else:
    574574            kw['style'] = wx.TE_PROCESS_ENTER
     575        if 'size' not in kw: # wx 4.2.0 needs a size
     576            kw['size'] = (105,-1)
    575577        if typeHint is not None:
    576578            self.type = typeHint
  • trunk/GSASIIpwdGUI.py

    r5354 r5360  
    39463946    def OnIndexPeaks(event):
    39473947        PatternId = G2frame.PatternId   
    3948         print ('Peak Indexing')
     3948        #print ('Peak Indexing')
    39493949        keepcells = []
    39503950        try:
  • trunk/ISODISTORT.py

    r5130 r5360  
    1717import os
    1818import os.path
    19 import requests
     19try:
     20    import requests
     21except:
     22    print('Module requests not installed, access to ISODISTORT not possible')
    2023import copy
    2124import GSASIIscriptable as G2sc
  • trunk/docs/source/packages.rst

    r5317 r5360  
    7373  (`conda create -n <env> package-list...`), it will not be added
    7474  unless you request it specifically. 
    75 
     75* requests: this package simplifies http access
     76  (https://requests.readthedocs.io/). It is used for access to
     77  webpages such as ISODISTORT and for some internal software downloads.
     78 
    7679*Conda command*:
    7780  Here is a typical conda command used to install a GSAS-II compatible
    7881  Python interpreter::
    7982
    80     conda install python=3.9 wxpython numpy scipy matplotlib pyopengl pillow h5py imageio subversion -c conda-forge
     83    conda install python=3.9 wxpython numpy scipy matplotlib pyopengl pillow h5py imageio subversion requests -c conda-forge
    8184   
    8285  or to put a Python configured for GSAS-II into a separate conda
     
    8487  command::
    8588
    86     conda create -n g2python python=3.9 wxpython numpy scipy matplotlib pyopengl  pillow h5py imageio conda subversion -c conda-forge
     89    conda create -n g2python python=3.9 wxpython numpy scipy matplotlib pyopengl  pillow h5py imageio conda subversion requests -c conda-forge
    8790
    8891Note that at present the subversion is only available for Linux, so
  • trunk/fsource/NISTlatsubs/OUTPT1.f

    r5355 r5360  
    194194 2700 FORMAT(//36X,'***** Supercell ',I3,' *****'/)
    195195 2800 FORMAT(//37X,'***** Subcell ',I3,' *****'/)
    196  2900 FORMAT(1X,'T 1=',4X,3F7.2,'/',3F7.2,'/',3F7.2)
    197  3000 FORMAT(1X,'T 2=',4X,3F7.2,'/',3F7.2,'/',3F7.2)
    198  3100 FORMAT(1X,'T 2 INV=',3F7.2,'/',3F7.2,'/',3F7.2)
     196C     Minor formatting change by Brian Toby 10/29/2022: increase sig. digits
     197C       for cell reduction matrix display
     198C 2900 FORMAT(1X,'T 1=',4X,3F7.2,'/',3F7.2,'/',3F7.2)
     199C 3000 FORMAT(1X,'T 2=',4X,3F7.2,'/',3F7.2,'/',3F7.2)
     200C 3100 FORMAT(1X,'T 2 INV=',3F7.2,'/',3F7.2,'/',3F7.2)
     201 2900 FORMAT(1X,'T 1=',4X,3F14.7,'/',3F14.7,'/',3F14.7)
     202 3000 FORMAT(1X,'T 2=',4X,3F14.7,'/',3F14.7,'/',3F14.7)
     203 3100 FORMAT(1X,'T 2 INV=',3F14.7,'/',3F14.7,'/',3F14.7)
    199204 3200 FORMAT(1H+,108X,'** Cell Matrix **'/)
    200205 3300 FORMAT(1X,'CELL  1=',3F10.4,1X,3F10.3,14X,'V1=',F10.2,5X,3F10.3)
  • trunk/fsource/SConstruct

    r5356 r5360  
    382382        installcmd = "copy $TARGET " + InstallLoc
    383383    else:
    384         installcmd = "cp -p $TARGET " + InstallLoc
     384        installcmd = "mv $TARGET " + InstallLoc
    385385    return [cmd, installcmd]
    386386env.Append(BUILDERS = {'nist' : Builder(generator = generate_nist)},)
  • trunk/nistlat.py

    r5357 r5360  
    1414This implements an interface to the NIST*LATTICE code using
    1515the Spring 1991 program version. NIST*LATTICE, "A Program to Analyze
    16 Lattice Relationships" was created by Vicky Lynn Karen and Alan D. Mighell,
    17 National Institute of Standards and Technology, Materials Science and
    18 Engineering Laboratory, Gaithersburg, Maryland 20899.
    19 
    20 [cite: V. L. Karen and A. D. Mighell, NIST Technical Note 1290
    21 (1991), https://nvlpubs.nist.gov/nistpubs/Legacy/TN/nbstechnicalnote1290.pdf;
    22 V. L. Karen & A. D. Mighell, U.S. Patent 5,235,523,
     16Lattice Relationships" was created by Vicky Lynn Karen and Alan D. Mighell
     17(National Institute of Standards and Technology, Materials Science and
     18Engineering Laboratory, Gaithersburg, Maryland 20899.)
     19Minor code modifications made to provide more significant digits for
     20cell reduction matrix terms.
     21
     22[if used cite: V. L. Karen and A. D. Mighell, NIST Technical Note 1290 (1991),
     23https://nvlpubs.nist.gov/nistpubs/Legacy/TN/nbstechnicalnote1290.pdf;
     24and V. L. Karen & A. D. Mighell, U.S. Patent 5,235,523,
    2325https://patents.google.com/patent/US5235523A/en?oq=5235523]
    2426
    2527This is still under development; not yet in use.
    2628
    27 Easy part done: cell reduction and reversion of that. Work to come,
    28 "Search for higher symmetry unit cells" & "Relate two unit cells"
     29Work to come: "Relate two unit cells"
    2930'''
    3031
     
    4041
    4142def showCell(cell,center,setting):
    42     'format cell input or output'
     43    '''show unit cell input or output nicely formatted.
     44    :param list cell: six lattice constants as float values.
     45    :param str center: cell centering code; one of P/A/B/C/F/I/R
     46      Note that 'R' is used for rhombohedral lattices in either
     47      rhombohedral (primitive) or hexagonal cells.
     48    :param str setting: is ' ' except for rhombohedral symmetry where
     49      it will be R or H for the cell type.
     50    :returns: a formatted string
     51    '''
    4352    s = "{:.4f} {:.4f} {:.4f} {:.3f} {:.3f} {:.3f}".format(*cell)
    4453    s += '  ' + centerLbl.get(center,'?')
     
    4756
    4857def uniqCells(cellList):
    49     'remove duplicated cells from an output list'
     58    '''remove duplicated cells from a cell output list
     59    :param list cellList: A list of reduced cells where each entry represents a
     60      reduced cell as (_,cell,_,_,center,...) where cell has six lattice
     61      constants and center is the cell centering code (P/A/B/C/F/I/R).
     62    :returns: a list as above, but where each unique cell is listed only once
     63    '''
    5064    uList = []
    5165    shown = []
     
    5670        uList.append(i)
    5771    return uList
     72
     73def emulateLP(line,fp):
     74    '''Emulate an antique 132 column line printer, where the first column
     75    that is printed is used for printer control. '1' starts a new page
     76    and '0' double-spaces. Not implemented is '+' which overprints.
     77    If the file pointer is not None, the line is copied to the
     78    file, removing the first column but adding a bit of extra formatting
     79    to separate pages or add a blank line where needed.
     80
     81    :param str line: string to be printed
     82    :param file fp: file pointer object
     83    '''
     84    if not fp: return
     85    if line[0] == '1':
     86        fp.write('\n'+130*'='+'\n'+line[1:])           
     87    elif line[0] == '0':
     88        fp.write('\n'+line[1:])           
     89    elif len(line) == 1:
     90        fp.write('\n')           
     91    else:
     92        fp.write(line[1:])           
    5893       
    59 def ReduceCell(center,cellin,mode=0,deltaV=0):
     94def ReduceCell(center, cellin, mode=0, deltaV=0, output=None):
    6095    '''Compute reduced cell(s) with NIST*LATTICE
    6196   
    62     :param str center: cell centering code, one of P/A/B/C/F/I/R
     97    :param str center: cell centering code; one of P/A/B/C/F/I/R
    6398      Note that 'R' is used for rhombohedral lattices in either
    6499      hexagonal or rhombohedral (primitive) cells
     
    71106    :param int deltaV: volume ratios for sub/supercells if mode != 0 as
    72107      ratio of original cell to smallest subcell or largest supercell. Ignored
    73       if mode=0.
     108      if mode=0.
     109    :param str output: name of file to write the NIST*LATTICE output 
    74110    :returns: a dict with item 'input' with input cell as (cell,center,setting)
    75111      and 'output' which is a list of reduced cells of form
     
    89125    (a,b,c,alpha,beta,gamma) = cellin
    90126    celldict = {}
    91     if center == "R":
     127    if center == "R" and alpha == 90 and beta == 90 and gamma == 120:
     128        setting = "H"
     129    elif center == "R" :
    92130        setting = "R"
    93     elif alpha == 90 and beta == 90 and gamma == 120:
    94         setting = "H"
    95131    # prepare input and start program
    96132    cellline = '{:10.4f}{:10.4f}{:10.4f}{:10.3f}{:10.3f}{:10.3f}'.format(*cellin)
     
    110146    line = '?'
    111147    linenum = 0
     148    fp = None
     149    if output: fp = open(output,'w')
    112150    try:
    113151        for b in p.stdout.readlines():
    114152            linenum += 1
    115153            line = b.decode()
     154            emulateLP(line,fp)
    116155            pat = r"T 2= (.*)/ (.*)/ (.*)"  # transform matrix
    117156            s = re.split(pat,line)
     
    137176    finally:
    138177        p.terminate()
    139     if len(celldict['output'] or len(err) > 0) == 0:
     178    if len(celldict['output']) == 0 or len(err) > 0:
    140179        print('Error:' ,err.decode())
    141180    return celldict
     
    190229
    191230
     231def CompareCell(cell1, center1, cell2, center2, tolerance=3*[0.2]+3*[1],
     232                    mode='I', vrange=8, output=None):
     233    '''Search for matrices that relate two unit cells
     234   
     235    :param list cell1: six lattice constants as float values for 1st cell
     236    :param str center1: cell centering code for 1st cell; one of P/A/B/C/F/I/R
     237      Note that 'R' is used for rhombohedral lattices in either
     238      hexagonal or rhombohedral (primitive) cells
     239    :param list cell2: six lattice constants as float values for 2nd cell
     240    :param str center2: cell centering code for 2nd cell (see center1)
     241    :param list tolerance: comparison tolerances for a, b, c, alpha, beta
     242      & gamma (defaults to [0.2,0.2,0.2,1.,1.,1.]
     243    :param str mode: search mode, which should be either 'I' or 'F'
     244      'I' provides searching with integral matrices or
     245      'F' provides searching with integral and fractional matrices
     246    :param int vrange: maximum matrix term range.
     247       Must be 1 <= vrange <= 10 for mode='F' or
     248       Must be 1 <= vrange <= 40 for mode='I'
     249    :param str output: name of file to write the NIST*LATTICE output 
     250
     251    :returns: a list of matrices that match cell1 to cell2 where
     252      each entry contains (det, im, m, tol, one2two, two2one) where
     253      0: det is the determinant, giving the volume ratio between cells
     254      1: im relates the reduced cell for cell1 to the reduced cell for cell2
     255      2: m relates the reduced cell for cell2 to the reduced cell for cell1
     256      3: tol quality of agreement as six differences between the
     257        two reduced cells
     258      4: one2two numpy matrix that transforms cell1 to cell2
     259      5: two2one numpy matrix that transforms cell2 to cell1
     260    '''
     261    # reduce input cells. Save cell, volume and matrix
     262    rcVmat = [[],[]]
     263    rcVmat[0] = ReduceCell(center1,cell1)['output'][0][1:4]
     264    rcVmat[1] = ReduceCell(center2,cell2)['output'][0][1:4]
     265    reverseCells = False
     266    if rcVmat[0][1] < rcVmat[1][1]: # largest volume goes first
     267        reverseCells = True
     268        rcVmat = list(reversed(rcVmat))
     269    # prepare input and start program
     270    inp = "REL      1\n"
     271    inp += "{:.1s}  {:2d}     {:10.5f}{:10.5f}{:10.5f}{:10.5f}{:10.5f}{:10.5f}\n".format(
     272            mode,vrange,*tolerance)
     273    for i in range(2):
     274        inp += "          {:10.5f}{:10.5f}{:10.5f}{:10.4f}{:10.4f}{:10.4f}\n".format(
     275            *rcVmat[i][0])
     276    p = subprocess.Popen([nistlattice],
     277                             stdin=subprocess.PIPE,
     278                             stdout=subprocess.PIPE,
     279                             stderr=subprocess.PIPE)
     280    p.stdin.write(bytearray(inp,'utf8'))
     281    p.stdin.close()
     282    err = p.stderr.read()
     283    line = '?'
     284    fp = None
     285    if output: fp = open(output,'w')
     286    # read output and parse
     287    lines = [b.decode() for b in p.stdout.readlines()]
     288    p.terminate()
     289    if fp:
     290        for line in lines: emulateLP(line,fp)
     291        fp.close()
     292    lnum = 0
     293    while lnum < len(lines):
     294        if ' H Matrix ' in lines[lnum] and ' Determinant' in lines[lnum]:
     295            lnum += 2
     296            break
     297        lnum += 1
     298    else:
     299        print('no header found')
     300        return []
     301
     302    xforms = []
     303    while lnum < len(lines):
     304        try:
     305            sl = lines[lnum].split()
     306            if len(sl) == 10:
     307                sl = [float(i) for i in sl]
     308                m = 3*[3*[0]]  # forward matrix
     309                im = 3*[3*[0]] # inverse matrix
     310                tol = 6*[0]
     311                m[0] = sl[0:3]
     312                im[0] = sl[3:6]
     313                tol[0:3] = sl[6:9]
     314                det = sl[9]
     315           
     316                lnum += 1
     317                sl = [float(i) for i in lines[lnum].split()]
     318                m[1] = sl[0:3]
     319                im[1] = sl[3:6]
     320                tol[3:] = sl[6:9]
     321           
     322                lnum += 1
     323                sl = [float(i) for i in lines[lnum].split()]
     324                m[2] = sl[0:3]
     325                im[2] = sl[3:6]
     326           
     327                xmatI = np.dot(np.dot(np.linalg.inv(rcVmat[0][2]),m),rcVmat[1][2])
     328                xmat  = np.dot(np.dot(np.linalg.inv(rcVmat[1][2]),im),rcVmat[0][2])
     329                if reverseCells:
     330                    one2two, two2one = xmatI, xmat
     331                    xforms.append((det, m, im, tol, one2two, two2one))
     332                else:
     333                    one2two, two2one = xmat, xmatI
     334                    xforms.append((det, im, m, tol, one2two, two2one))
     335        except Exception as msg:
     336            print('error with line',lnum,msg)
     337            print(lines[lnum])
     338
     339        lnum += 1
     340    if len(err) > 0:
     341        print('Execution error:' ,err.decode())
     342    return xforms
     343
    192344if __name__ == '__main__':  # test code
     345
    193346    import GSASIIlattice as G2lat
     347    cell1 = (5.03461,5.03461,13.74753,90,90,120)
     348    center1 = 'R'
     349    cell2 = (7.40242,5.03461,5.42665,90,84.14,90)
     350    center2 = 'P'
     351    #print(ReduceCell(center1,cell1,output='/tmp/reduce.txt'))
     352    tolerance = 3*[0.1]+3*[.5]
     353    print('\ncomparing ',showCell(cell1,center1,' '),showCell(cell2,center2,' '))
     354    out = CompareCell(cell1, center1, cell2, center2, tolerance, output='/tmp/CompCell.txt')
     355    for i in out:
     356        print(70*'=')
     357        print(i[0],i[3],'\n',i[5])
     358    print('testing with 1st entry')
     359    print('cell1 ',showCell(cell1,center1,' '))
     360    print('cell2-->cell1',G2lat.TransformCell(cell2,out[0][5]))
     361    print('cell2 ',showCell(cell2,center2,' '))
     362    print('cell1-->cell2',G2lat.TransformCell(cell1,out[0][4]))
     363
     364    out = CompareCell(cell2, center2, cell1, center1, tolerance)
     365    print('reversed input, testing with 1st entry')
     366    print('cell1 ',showCell(cell2,center2,' '))
     367    print('cell2-->cell1',G2lat.TransformCell(cell1,out[0][5]))
     368    print('cell2 ',showCell(cell1,center1,' '))
     369    print('cell1-->cell2',G2lat.TransformCell(cell2,out[0][4]))
     370
     371   
     372    center2 = 'I'
     373    print('\n\ncomparing ',showCell(cell1,center1,' '),showCell(cell2,center2,' '))
     374    out = CompareCell(cell1, center1, cell2, center2, tolerance)
     375    for i in out:
     376        print(70*'=')
     377        print(i[0],i[3],'\n',i[5])
     378    print('testing with 1st entry')
     379    print('cell1 ',showCell(cell1,center1,' '))
     380    print('cell2-->cell1',G2lat.TransformCell(cell2,out[0][5]))
     381    print('cell2 ',showCell(cell2,center2,' '))
     382    print('cell1-->cell2',G2lat.TransformCell(cell1,out[0][4]))
     383
     384    import sys; sys.exit()
     385
     386   
    194387    cellin = [5.,5.,5.,85.,85.,85.,]
    195388    cellList = ConvCell(cellin)
Note: See TracChangeset for help on using the changeset viewer.