Changeset 159


Ignore:
Timestamp:
Oct 4, 2010 1:00:32 PM (12 years ago)
Author:
vondreele
Message:

added new genHKL to G2spc

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/GSASIIspc.py

    r155 r159  
    22
    33import numpy as np
     4import numpy.ma as ma
    45import math
    56import sys
     
    1112def SpcGroup(SGSymbol):
    1213    '''
    13    Determines cell and symmetry information from a short H-M space group name
    14    input: space group symbol (string) with spaces between axial fields
    15    returns [SGError,SGData]
    16        SGError = 0 for no errors; >0 for errors (see SGErrors below for details)
    17        returns dictionary SGData with entries:
    18          'SpGrp': space group symbol slightly cleaned up
    19          'Laue':  one of '-1','2/m','mmm','4/m','4/mmm','3R','3mR','3',
    20                   '3m1','31m','6/m','6/mmm','m3','m3m'
    21          'SGInv': boolean; True if centrosymmetric, False if not
    22          'SGLatt': one of 'P','A','B','C','I','F','R'
    23          'SGUniq': one of 'a','b','c' if monoclinic, '' otherwise
    24          'SGCen': cell centering vectors [0,0,0] at least
    25          'SGOps': symmetry operations as [M,T] so that M*x+T = x'
    26          'SGSys': one of 'triclinic','monoclinic','orthorhombic','tetragonal','rhombohedral','trigonal','hexagonal','cubic'
     14    Determines cell and symmetry information from a short H-M space group name
     15    input:
     16        SGSymbol - space group symbol (string) with spaces between axial fields
     17    returns:
     18        SGError = 0 for no errors; >0 for errors (see SGErrors below for details)
     19        SGData - dictionary with entries:
     20             'SpGrp': space group symbol slightly cleaned up
     21             'Laue':  one of '-1','2/m','mmm','4/m','4/mmm','3R','3mR','3',
     22                      '3m1','31m','6/m','6/mmm','m3','m3m'
     23             'SGInv': boolean; True if centrosymmetric, False if not
     24             'SGLatt': one of 'P','A','B','C','I','F','R'
     25             'SGUniq': one of 'a','b','c' if monoclinic, '' otherwise
     26             'SGCen': cell centering vectors [0,0,0] at least
     27             'SGOps': symmetry operations as [M,T] so that M*x+T = x'
     28             'SGSys': one of 'triclinic','monoclinic','orthorhombic','tetragonal','rhombohedral','trigonal','hexagonal','cubic'
    2729       '''
    2830    LaueSym = ('-1','2/m','mmm','4/m','4/mmm','3R','3mR','3','3m1','31m','6/m','6/mmm','m3','m3m')
     
    7577
    7678def SGErrors(IErr):
    77     '''Interprets the error message code from SpcGroup. Used in SpaceGroup.
    78     input:  SGError, from SpcGroup
    79     returns a string with the error message or "Unknown error"
     79    '''
     80    Interprets the error message code from SpcGroup. Used in SpaceGroup.
     81    input:
     82        SGError - from SpcGroup
     83    returns:
     84        ErrString - a string with the error message or "Unknown error"
    8085    '''
    8186
     
    115120    '''
    116121    Print the output of SpcGroup in a nicely formatted way. Used in SpaceGroup
    117     input:  SGData, from SpcGroup
    118     returns a list of strings with the space group details
     122    input:
     123        SGData - from SpcGroup
     124    returns:
     125        SGText - list of strings with the space group details
    119126    '''
    120127    POL = (' ','x','y','x y','z','x z','y z','xyz','111')
     
    183190    return lattTxt[Latt]   
    184191       
    185 def SpaceGroup(SgSym):
     192def SpaceGroup(SGSymbol):
    186193    '''
    187194    Print the output of SpcGroup in a nicely formatted way.
    188       input: space group symbol (string) with spaces between axial fields
    189       returns nothing
    190     '''
    191     E,A = SpcGroup(SgSym)
     195    input:
     196        SGSymbol - space group symbol (string) with spaces between axial fields
     197    returns:
     198        nothing
     199    '''
     200    E,A = SpcGroup(SGSymbol)
    192201    if E > 0:
    193202        print SGErrors(E)
     
    199208    '''
    200209    Translates a set of coordinates so that all values are >=0 and < 1
    201       input: a list or numpy array of any length.
    202       output: none; the object is modified in place.
     210    input:
     211        XYZ - a list or numpy array of fractional coordinates
     212    output:
     213        none; the object is modified in place.
    203214    '''
    204215    for i,x in enumerate(XYZ):
     
    248259        C = np.array(cen)
    249260        for invers in range(int(SGData['SGInv']+1)):
    250             for io,ops in enumerate(SGData['SGOps']):
     261            for io,M,T in enumerate(SGData['SGOps']):
    251262                idup = ((io+1)+100*ic)*(1-2*invers)
    252                 T = np.array(ops[1])
    253                 M =  np.array(ops[0])
    254263                newX = np.inner(M,X)+T
    255264                if len(Uij):
     
    276285    else:
    277286        return zip(XYZEquiv,Idup)
     287       
     288def GenHKL(HKL,SGData,Friedel=False):
     289    '''
     290    Generate set of equivalent reflections
     291    input:
     292        HKL - [h,k,l]
     293        SGData - space group data obtained from SpcGroup
     294        Friedel = True to retain Friedel pairs for centrosymmetric case
     295    returns:
     296        iabsnt = True is reflection is forbidden by symmetry
     297        mulp = reflection multiplicity including Fridel pairs
     298        Uniq = numpy array of equivalent hkl in descending order of h,k,l
     299        Phs = numpy array of corresponding phase factors (multiples of 2pi)
     300    '''
     301    iabsnt = False
     302    H = np.array(HKL)
     303    Inv = SGData['SGInv']
     304    Cen = SGData['SGCen'][1:]           #skip P
     305    # do cell centering extinction check
     306    for cen in Cen:
     307        iabsnt |= bool(int(round(np.sum(cen*H*12)))%12)
     308    # get operators & expand if centrosymmetric
     309    Ops = SGData['SGOps']
     310    opM = np.array([op[0].T for op in Ops])
     311    opT = np.array([op[1] for op in Ops])
     312    if Inv:
     313        opM = np.concatenate((opM,-opM))
     314        opT = np.concatenate((opT,-opT))
     315    # generate full hkl table and phase factors; find duplicates for multiplicity
     316    eqH = np.inner(opM,H)
     317    HT = np.dot(opT,H)%1.
     318    dup = len(ma.nonzero([ma.allclose(HKL,hkl,atol=0.001) for hkl in eqH])[0])
     319    mulp = len(eqH)/dup
     320    # generate unique reflection set (with or without Friedel pairs)
     321    HPT = [tuple(hp) for hp in np.column_stack((eqH,HT))]
     322    HPT.sort()
     323    UPT = HPT[::dup]
     324    UPT.reverse()
     325    if Inv and not Friedel:
     326        UPT = UPT[:len(UPT)/2]           
     327    Uniq = np.split(UPT,[3,4],axis=1)
     328    Phs = Uniq[1].T[0]
     329    Uniq = Uniq[0]
     330    # determine if extinct
     331    HPT = np.split(HPT,[3,4],axis=1)[1].T[0]
     332    HPT = np.reshape(HPT,(mulp,-1)).T
     333    HPT = np.around(HPT-HPT[0],4)%1.
     334    iabsnt |= np.any(HPT)
     335    return iabsnt,mulp,Uniq,Phs
    278336                                   
    279337def GetOprPtrName(key):           
Note: See TracChangeset for help on using the changeset viewer.