Changeset 30


Ignore:
Timestamp:
Feb 18, 2010 9:34:17 PM (12 years ago)
Author:
toby
Message:

document GSASIIspc for independent use and develop unit tests

Location:
trunk
Files:
6 added
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/GSASIIspc.py

    r13 r30  
    1 #GSASII - Space group intrepretion routines
    2 #
    3 #   input string - space group symbol with spaces between axial fields
    4 #   returns [SGError,SGData]
    5 #       SGError = 0 for no errors; >0 for errors, see SGErrors below for details
    6 #       SGData dictionary entries are:
    7 #       'SpGrp': space group symbol slightly cleaned up
    8 #       'Laue':  one of '-1','2/m','mmm','4/m','4/mmm','3R','3mR','3','3m1','31m','6/m','6/mmm','m3','m3m'
    9 #       'SGInv': boolean; True if centrosymmetric, False if not
    10 #       'SGLatt': one of 'P','A','B','C','I','F','R'
    11 #       'SGUniq': one of 'a','b','c' if monoclinic, '' otherwise
    12 #       'SGCen': cell centering vectors [0,0,0] at least
    13 #       'SGOps': symmetry operations as [M,T] so that M*x+T = x'
    14 #
     1"GSASII - Space group interpretion routines"
     2
     3
    154import numpy as np
     5import sys
     6import os.path
     7# determine a binary path pased on the host OS and the python version, path is relative to
     8# location of this file
     9if sys.platform == "win32":
     10    bindir = '../binwin%d.%d' % sys.version_info[0:2]
     11elif sys.platform == "darwin":
     12    bindir = '../binmac%d.%d' % sys.version_info[0:2]
     13else:
     14    bindir = '../bin'
     15if os.path.exists(os.path.join(sys.path[0],bindir)): sys.path.insert(0,os.path.join(sys.path[0],bindir))
     16
     17import pypowder as pyd
    1618
    1719def SpcGroup(SGSymbol):
    18     import pypowder as pyd
     20    '''
     21   input: space group symbol (string) with spaces between axial fields
     22   returns [SGError,SGData]
     23       SGError = 0 for no errors; >0 for errors (see SGErrors below for details)
     24       returns dictionary SGData with entries:
     25         'SpGrp': space group symbol slightly cleaned up
     26         'Laue':  one of '-1','2/m','mmm','4/m','4/mmm','3R','3mR','3',
     27                  '3m1','31m','6/m','6/mmm','m3','m3m'
     28         'SGInv': boolean; True if centrosymmetric, False if not
     29         'SGLatt': one of 'P','A','B','C','I','F','R'
     30         'SGUniq': one of 'a','b','c' if monoclinic, '' otherwise
     31         'SGCen': cell centering vectors [0,0,0] at least
     32         'SGOps': symmetry operations as [M,T] so that M*x+T = x'
     33         'SGSys': one of 'triclinic','monoclinic','orthorhombic','tetragonal','rhombohedral','trigonal','hexagonal','cubic'
     34       '''
    1935    LaueSym = ('-1','2/m','mmm','4/m','4/mmm','3R','3mR','3','3m1','31m','6/m','6/mmm','m3','m3m')
    2036    LattSym = ('P','A','B','C','I','F','R')
     
    6682
    6783def SGErrors(IErr):
     84    '''Interprets the error message code from SpcGroup. Used in SpaceGroup.
     85    input:  SGError, from SpcGroup
     86    returns a string with the error message or "Unknown error"
     87    '''
     88
    6889    ErrString = [' ',
    6990        'Less than 2 operator fields were found',
     
    93114        'Illegal character in the space group symbol',
    94115        ]
    95     return ErrString[IErr]
     116    try:
     117        return ErrString[IErr]
     118    except:
     119        return "Unknown error"
    96120   
    97121def SGPrint(SGData):
     122    '''
     123    Print the output of SpcGroup in a nicely formatted way. Used in SpaceGroup
     124    input:  SGData, from SpcGroup
     125    returns a list of strings with the space group details
     126    '''
    98127    XYZ = ('-Z ','-Y ','-X ','X-Y','ERR','Y-X',' X ',' Y ',' Z ','+X ','+Y ','+Z ')
    99128    TRA = ('   ','ERR','1/6','1/4','1/3','ERR','1/2','ERR','2/3','3/4','5/6','ERR')
     
    159188   
    160189def SpaceGroup(SgSym):
     190    '''
     191    Print the output of SpcGroup in a nicely formatted way.
     192      input: space group symbol (string) with spaces between axial fields
     193      returns nothing
     194    '''
    161195    E,A = SpcGroup(SgSym)
    162196    if E > 0:
    163197        print SGErrors(E)
    164198        return
    165     L = SGPrint(A)
    166     for l in L:
     199    for l in SGPrint(A):
    167200        print l
    168201
    169202def MoveToUnitCell(XYZ):
     203    '''
     204    Translates a set of coordinates so that all values are >=0 and < 1
     205      input: a list or numpy array of any length. Note that the object is modified  in place.
     206      output: none
     207    '''
    170208    for i,x in enumerate(XYZ):
    171209        x = ((x % 1.0)+1.0) % 1.0
     
    174212       
    175213def GenAtom(XYZ,SGData,ifAll=False):
     214    '''
     215    Generates the equivalent positions for a specified coordinate and space group
     216    input: 
     217       XYZ an array, tuple or list containing 3 elements: x, y & z
     218       SGData, from SpcGroup
     219       ifAll=True causes the return to provide the unique set of
     220                  equivalent positions
     221            =False causes the input position to be repeated. This is the default,
     222                   but why someone would want this, I am not sure.
     223    Returns a list of two element tuples:
     224       The first element is the coordinate as a three-element array and
     225       the second describes the symmetry used to generate the site, of form [-][C]SS
     226          C indicates a centering operation was used (omitted if the 1st, [0,0,0])
     227          SS is the symmetry operator number (1-24)
     228          - indicates the center of symmetry was used (omitted otherwise)     
     229    '''
    176230    XYZEquiv = []
    177231    Idup = []
     
    398452       
    399453def SytSym(XYZ,SGData):
     454    '''
     455    Generates the number of equivalent positions and a site symmetry code for a specified coordinate and space group
     456    input: 
     457       XYZ: an array, tuple or list containing 3 elements: x, y & z
     458       SGData: from SpcGroup
     459    Returns a two element tuple:
     460       The 1st element is a code for the site symmetry (see GetOprPtrName)
     461       The 2nd element is the site multiplicity
     462    '''
    400463    def PackRot(SGOps):
    401464        IRT = []
Note: See TracChangeset for help on using the changeset viewer.