source: trunk/GSASIIspc.py @ 2061

Last change on this file since 2061 was 2061, checked in by vondreele, 7 years ago

modify export app peak lists to include d-spacing as a column
fix 2x error in U2Uij & Uij2U in G2spc - now same as one in G2lat
fix math errors for Uij modulation derivatives - all ok now

  • Property svn:eol-style set to native
  • Property svn:keywords set to Date Author Revision URL Id
File size: 143.1 KB
Line 
1# -*- coding: utf-8 -*-
2"""
3*GSASIIspc: Space group module*
4-------------------------------
5
6Space group interpretation routines. Note that space group information is
7stored in a :ref:`Space Group (SGData)<SGData_table>` object.
8
9"""
10########### SVN repository information ###################
11# $Date: 2015-11-19 15:15:05 +0000 (Thu, 19 Nov 2015) $
12# $Author: vondreele $
13# $Revision: 2061 $
14# $URL: trunk/GSASIIspc.py $
15# $Id: GSASIIspc.py 2061 2015-11-19 15:15:05Z vondreele $
16########### SVN repository information ###################
17import numpy as np
18import numpy.ma as ma
19import numpy.linalg as nl
20import scipy.optimize as so
21import math
22import sys
23import copy
24import os.path as ospath
25
26import GSASIIpath
27GSASIIpath.SetVersionNumber("$Revision: 2061 $")
28import pyspg
29
30npsind = lambda x: np.sin(x*np.pi/180.)
31npcosd = lambda x: np.cos(x*np.pi/180.)
32DEBUG = False
33   
34################################################################################
35#### Space group codes
36################################################################################
37
38def SpcGroup(SGSymbol):
39    """
40    Determines cell and symmetry information from a short H-M space group name
41
42    :param SGSymbol: space group symbol (string) with spaces between axial fields
43    :returns: (SGError,SGData)
44   
45       * SGError = 0 for no errors; >0 for errors (see SGErrors below for details)
46       * SGData - is a dict (see :ref:`Space Group object<SGData_table>`) with entries:
47       
48             * 'SpGrp': space group symbol, slightly cleaned up
49             * 'SGLaue':  one of '-1', '2/m', 'mmm', '4/m', '4/mmm', '3R',
50               '3mR', '3', '3m1', '31m', '6/m', '6/mmm', 'm3', 'm3m'
51             * 'SGInv': boolean; True if centrosymmetric, False if not
52             * 'SGLatt': one of 'P', 'A', 'B', 'C', 'I', 'F', 'R'
53             * 'SGUniq': one of 'a', 'b', 'c' if monoclinic, '' otherwise
54             * 'SGCen': cell centering vectors [0,0,0] at least
55             * 'SGOps': symmetry operations as [M,T] so that M*x+T = x'
56             * 'SGSys': one of 'triclinic', 'monoclinic', 'orthorhombic',
57               'tetragonal', 'rhombohedral', 'trigonal', 'hexagonal', 'cubic'
58             * 'SGPolax': one of ' ', 'x', 'y', 'x y', 'z', 'x z', 'y z',
59               'xyz', '111' for arbitrary axes
60             * 'SGPtGrp': one of 32 point group symbols (with some permutations), which
61                is filled by SGPtGroup, is external (KE) part of supersymmetry point group
62             * 'SSGKl': default internal (Kl) part of supersymmetry point group; modified
63                in supersymmetry stuff depending on chosen modulation vector for Mono & Ortho
64
65    """
66    LaueSym = ('-1','2/m','mmm','4/m','4/mmm','3R','3mR','3','3m1','31m','6/m','6/mmm','m3','m3m')
67    LattSym = ('P','A','B','C','I','F','R')
68    UniqSym = ('','','a','b','c','',)
69    SysSym = ('triclinic','monoclinic','orthorhombic','tetragonal','rhombohedral','trigonal','hexagonal','cubic')
70    SGData = {}
71    SGSymbol = SGSymbol.replace(':',' ')    #get rid of ':' in R space group symbols from some cif files
72    SGInfo = pyspg.sgforpy(SGSymbol)
73    SGData['SpGrp'] = SGSymbol.strip().lower().capitalize()
74    SGData['SGLaue'] = LaueSym[SGInfo[0]-1]
75    SGData['SGInv'] = bool(SGInfo[1])
76    SGData['SGLatt'] = LattSym[SGInfo[2]-1]
77    SGData['SGUniq'] = UniqSym[SGInfo[3]+1]
78    if SGData['SGLatt'] == 'P':
79        SGData['SGCen'] = np.array(([0,0,0],))
80    elif SGData['SGLatt'] == 'A':
81        SGData['SGCen'] = np.array(([0,0,0],[0,.5,.5]))
82    elif SGData['SGLatt'] == 'B':
83        SGData['SGCen'] = np.array(([0,0,0],[.5,0,.5]))
84    elif SGData['SGLatt'] == 'C':
85        SGData['SGCen'] = np.array(([0,0,0],[.5,.5,0,]))
86    elif SGData['SGLatt'] == 'I':
87        SGData['SGCen'] = np.array(([0,0,0],[.5,.5,.5]))
88    elif SGData['SGLatt'] == 'F':
89        SGData['SGCen'] = np.array(([0,0,0],[0,.5,.5],[.5,0,.5],[.5,.5,0,]))
90    elif SGData['SGLatt'] == 'R':
91        SGData['SGCen'] = np.array(([0,0,0],[1./3.,2./3.,2./3.],[2./3.,1./3.,1./3.]))
92    SGData['SGOps'] = []
93    for i in range(SGInfo[5]):
94        Mat = np.array(SGInfo[6][i])
95        Trns = np.array(SGInfo[7][i])
96        SGData['SGOps'].append([Mat,Trns])
97    if SGData['SGLaue'] in '-1':
98        SGData['SGSys'] = SysSym[0]
99    elif SGData['SGLaue'] in '2/m':
100        SGData['SGSys'] = SysSym[1]
101    elif SGData['SGLaue'] in 'mmm':
102        SGData['SGSys'] = SysSym[2]
103    elif SGData['SGLaue'] in ['4/m','4/mmm']:
104        SGData['SGSys'] = SysSym[3]
105    elif SGData['SGLaue'] in ['3R','3mR']:
106        SGData['SGSys'] = SysSym[4]
107    elif SGData['SGLaue'] in ['3','3m1','31m']:
108        SGData['SGSys'] = SysSym[5]
109    elif SGData['SGLaue'] in ['6/m','6/mmm']:
110        SGData['SGSys'] = SysSym[6]
111    elif SGData['SGLaue'] in ['m3','m3m']:
112        SGData['SGSys'] = SysSym[7]
113    SGData['SGPolax'] = SGpolar(SGData)
114    SGData['SGPtGrp'],SGData['SSGKl'] = SGPtGroup(SGData)
115    return SGInfo[8],SGData
116
117def SGErrors(IErr):
118    '''
119    Interprets the error message code from SpcGroup. Used in SpaceGroup.
120   
121    :param IErr: see SGError in :func:`SpcGroup`
122    :returns:
123        ErrString - a string with the error message or "Unknown error"
124    '''
125
126    ErrString = [' ',
127        'Less than 2 operator fields were found',
128        'Illegal Lattice type, not P, A, B, C, I, F or R',
129        'Rhombohedral lattice requires a 3-axis',
130        'Minus sign does not preceed 1, 2, 3, 4 or 6',
131        'Either a 5-axis anywhere or a 3-axis in field not allowed',
132        ' ',
133        'I for COMPUTED GO TO out of range.',
134        'An a-glide mirror normal to A not allowed',
135        'A b-glide mirror normal to B not allowed',
136        'A c-glide mirror normal to C not allowed',
137        'D-glide in a primitive lattice not allowed',
138        'A 4-axis not allowed in the 2nd operator field',
139        'A 6-axis not allowed in the 2nd operator field',
140        'More than 24 matrices needed to define group',
141        ' ',
142        'Improper construction of a rotation operator',
143        'Mirror following a / not allowed',
144        'A translation conflict between operators',
145        'The 2bar operator is not allowed',
146        '3 fields are legal only in R & m3 cubic groups',
147        'Syntax error. Expected I -4 3 d at this point',
148        ' ',
149        'A or B centered tetragonal not allowed',
150        ' ','unknown error in sgroup',' ',' ',' ',
151        'Illegal character in the space group symbol',
152        ]
153    try:
154        return ErrString[IErr]
155    except:
156        return "Unknown error"
157
158def SGpolar(SGData):
159    '''
160    Determine identity of polar axes if any
161    '''
162    POL = ('','x','y','x y','z','x z','y z','xyz','111')
163    NP = [1,2,4]
164    NPZ = [0,1]
165    for M,T in SGData['SGOps']:
166        for i in range(3):
167            if M[i][i] <= 0.: NP[i] = 0
168        if M[0][2] > 0: NPZ[0] = 8
169        if M[1][2] > 0: NPZ[1] = 0
170    NPol = (NP[0]+NP[1]+NP[2]+NPZ[0]*NPZ[1])*(1-int(SGData['SGInv']))
171    return POL[NPol]
172   
173def SGPtGroup(SGData):
174    '''
175    Determine point group of the space group - done after space group symbol has
176    been evaluated by SpcGroup. Only short symbols are allowed
177   
178    :param SGData: from :func SpcGroup
179    :returns: SSGPtGrp & SSGKl (only defaults for Mono & Ortho)
180    '''
181    Flds = SGData['SpGrp'].split()
182    if len(Flds) < 2:
183        return '',[]
184    if SGData['SGLaue'] == '-1':    #triclinic
185        if '-' in Flds[1]:
186            return '-1',[-1,]
187        else:
188            return '1',[1,]
189    elif SGData['SGLaue'] == '2/m': #monoclinic - default for 2D modulation vector
190        if '/' in SGData['SpGrp']:
191            return '2/m',[-1,1]
192        elif '2' in SGData['SpGrp']:
193            return '2',[-1,]
194        else:
195            return 'm',[1,]
196    elif SGData['SGLaue'] == 'mmm': #orthorhombic
197        if SGData['SpGrp'].count('2') == 3:
198            return '222',[-1,-1,-1]
199        elif SGData['SpGrp'].count('2') == 1:
200            if SGData['SGPolax'] == 'x':
201                return '2mm',[-1,1,1]
202            elif SGData['SGPolax'] == 'y':
203                return 'm2m',[1,-1,1]
204            elif SGData['SGPolax'] == 'z':
205                return 'mm2',[1,1,-1]
206        else:
207            return 'mmm',[1,1,1]
208    elif SGData['SGLaue'] == '4/m': #tetragonal
209        if '/' in SGData['SpGrp']:
210            return '4/m',[1,-1]
211        elif '-' in Flds[1]:
212            return '-4',[-1,]
213        else:
214            return '4',[1,]
215    elif SGData['SGLaue'] == '4/mmm':
216        if '/' in SGData['SpGrp']:
217            return '4/mmm',[1,-1,1,1]
218        elif '-' in Flds[1]:
219            if '2' in Flds[2]:
220                return '-42m',[-1,-1,1]
221            else:
222                return '-4m2',[-1,1,-1]             
223        elif '2' in Flds[2:]:
224            return '422',[1,-1,-1]
225        else:
226            return '4mm',[1,1,1]
227    elif SGData['SGLaue'] in ['3','3R']:  #trigonal/rhombohedral
228        if '-' in Flds[1]:
229            return '-3',[-1,]
230        else:
231            return '3',[1,]
232    elif SGData['SGLaue'] == '3mR' or 'R' in Flds[0]:
233        if '2' in Flds[2]:
234            return '32',[1,-1]
235        elif '-' in Flds[1]:
236            return '-3m',[-1,1]
237        else:
238            return '3m',[1,1]
239    elif SGData['SGLaue'] == '3m1':
240        if '2' in Flds[2]:
241            return '321',[1,-1,1]
242        elif '-' in Flds[1]:
243            return '-3m1',[-1,1,1]
244        else:
245            return '3m1',[1,1,1]
246    elif SGData['SGLaue'] == '31m':
247        if '2' in Flds[3]:
248            return '312',[1,1,-1]
249        elif '-' in Flds[1]:
250            return '-31m',[-1,1,1]
251        else:
252            return '31m',[1,1,1]
253    elif SGData['SGLaue'] == '6/m': #hexagonal
254        if '/' in SGData['SpGrp']:
255            return '6/m',[1,-1]
256        elif '-' in SGData['SpGrp']:
257            return '-6',[-1,]
258        else:
259            return '6',[1,]
260    elif SGData['SGLaue'] == '6/mmm':
261        if '/' in SGData['SpGrp']:
262            return '6/mmm',[1,-1,1,1]
263        elif '-' in Flds[1]:
264            if '2' in Flds[2]:
265                return '-62m',[-1,-1,1]
266            else:
267                return '-6m2',[-1,1,-1]                 
268        elif '2' in Flds[2:]:
269            return '622',[1,-1,-1]
270        else:
271            return '6mm',[1,1,1]   
272    elif SGData['SGLaue'] == 'm3':      #cubic - no (3+1) supersymmetry
273        if '2' in Flds[1]:
274            return '23',[]
275        else: 
276            return 'm3',[]
277    elif SGData['SGLaue'] == 'm3m':
278        if '4' in Flds[1]:
279            if '-' in Flds[1]:
280                return '-43m',[]
281            else:
282                return '432',[]
283        else:
284            return 'm-3m',[]
285   
286def SGPrint(SGData):
287    '''
288    Print the output of SpcGroup in a nicely formatted way. Used in SpaceGroup
289
290    :param SGData: from :func:`SpcGroup`
291    :returns:
292        SGText - list of strings with the space group details
293        SGTable - list of strings for each of the operations
294    '''
295    Mult = len(SGData['SGCen'])*len(SGData['SGOps'])*(int(SGData['SGInv'])+1)
296    SGText = []
297    SGText.append(' Space Group: '+SGData['SpGrp'])
298    CentStr = 'centrosymmetric'
299    if not SGData['SGInv']:
300        CentStr = 'non'+CentStr
301    if SGData['SGLatt'] in 'ABCIFR':
302        SGText.append(' The lattice is '+CentStr+' '+SGData['SGLatt']+'-centered '+SGData['SGSys'].lower())
303    else:
304        SGText.append(' The lattice is '+CentStr+' '+'primitive '+SGData['SGSys'].lower()) 
305    SGText.append(' The Laue symmetry is '+SGData['SGLaue'])
306    if 'SGPtGrp' in SGData:         #patch
307        SGText.append(' The lattice point group is '+SGData['SGPtGrp'])
308    SGText.append(' Multiplicity of a general site is '+str(Mult))
309    if SGData['SGUniq'] in ['a','b','c']:
310        SGText.append(' The unique monoclinic axis is '+SGData['SGUniq'])
311    if SGData['SGInv']:
312        SGText.append(' The inversion center is located at 0,0,0')
313    if SGData['SGPolax']:
314        SGText.append(' The location of the origin is arbitrary in '+SGData['SGPolax'])
315    SGText.append(' ')
316    if SGData['SGLatt'] == 'P':
317        SGText.append(' The equivalent positions are:\n')
318    else:   
319        SGText.append(' The equivalent positions are:')
320        SGText.append(' ('+Latt2text(SGData['SGLatt'])+')+\n')
321    SGTable = []
322    for i,Opr in enumerate(SGData['SGOps']):
323        SGTable.append('(%2d) %s'%(i+1,MT2text(Opr)))
324    return SGText,SGTable
325
326def AllOps(SGData):
327    '''
328    Returns a list of all operators for a space group, including those for
329    centering and a center of symmetry
330   
331    :param SGData: from :func:`SpcGroup`
332    :returns: (SGTextList,offsetList,symOpList,G2oprList) where
333
334      * SGTextList: a list of strings with formatted and normalized
335        symmetry operators.
336      * offsetList: a tuple of (dx,dy,dz) offsets that relate the GSAS-II
337        symmetry operation to the operator in SGTextList and symOpList.
338        these dx (etc.) values are added to the GSAS-II generated
339        positions to provide the positions that are generated
340        by the normalized symmetry operators.       
341      * symOpList: a list of tuples with the normalized symmetry
342        operations as (M,T) values
343        (see ``SGOps`` in the :ref:`Space Group object<SGData_table>`)
344      * G2oprList: The GSAS-II operations for each symmetry operation as
345        a tuple with (center,mult,opnum), where center is (0,0,0), (0.5,0,0),
346        (0.5,0.5,0.5),...; where mult is 1 or -1 for the center of symmetry
347        and opnum is the number for the symmetry operation, in ``SGOps``
348        (starting with 0).
349    '''
350    SGTextList = []
351    offsetList = []
352    symOpList = []
353    G2oprList = []
354    onebar = (1,)
355    if SGData['SGInv']:
356        onebar += (-1,)
357    for cen in SGData['SGCen']:
358        for mult in onebar:
359            for j,(M,T) in enumerate(SGData['SGOps']):
360                offset = [0,0,0]
361                Tprime = (mult*T)+cen
362                for i in range(3):
363                    while Tprime[i] < 0:
364                        Tprime[i] += 1
365                        offset[i] += 1
366                    while Tprime[i] >= 1:
367                        Tprime[i] += -1
368                        offset[i] += -1
369                Opr = [mult*M,Tprime]
370                OPtxt = MT2text(Opr)
371                SGTextList.append(OPtxt.replace(' ',''))
372                offsetList.append(tuple(offset))
373                symOpList.append((mult*M,Tprime))
374                G2oprList.append((cen,mult,j))
375    return SGTextList,offsetList,symOpList,G2oprList
376   
377def MT2text(Opr):
378    "From space group matrix/translation operator returns text version"
379    XYZ = ('-Z','-Y','-X','X-Y','ERR','Y-X','X','Y','Z')
380    TRA = ('   ','ERR','1/6','1/4','1/3','ERR','1/2','ERR','2/3','3/4','5/6','ERR')
381    Fld = ''
382    M,T = Opr
383    for j in range(3):
384        IJ = int(round(2*M[j][0]+3*M[j][1]+4*M[j][2]+4))%12
385        IK = int(round(T[j]*12))%12
386        if IK:
387            if IJ < 3:
388                Fld += (TRA[IK]+XYZ[IJ]).rjust(5)
389            else:
390                Fld += (TRA[IK]+'+'+XYZ[IJ]).rjust(5)
391        else:
392            Fld += XYZ[IJ].rjust(5)
393        if j != 2: Fld += ', '
394    return Fld
395   
396def Latt2text(Latt):
397    "From lattice type ('P',A', etc.) returns ';' delimited cell centering vectors"
398    lattTxt = {'A':'0,0,0; 0,1/2,1/2','B':'0,0,0; 1/2,0,1/2',
399        'C':'0,0,0; 1/2,1/2,0','I':'0,0,0; 1/2,1/2,1/2',
400        'F':'0,0,0; 0,1/2,1/2; 1/2,0,1/2; 1/2,1/2,0',
401        'R':'0,0,0; 1/3,2/3,2/3; 2/3,1/3,1/3','P':'0,0,0'}
402    return lattTxt[Latt]   
403       
404def SpaceGroup(SGSymbol):
405    '''
406    Print the output of SpcGroup in a nicely formatted way.
407
408    :param SGSymbol: space group symbol (string) with spaces between axial fields
409    :returns: nothing
410    '''
411    E,A = SpcGroup(SGSymbol)
412    if E > 0:
413        print SGErrors(E)
414        return
415    for l in SGPrint(A):
416        print l
417       
418################################################################################
419#### Superspace group codes
420################################################################################
421       
422def SSpcGroup(SGData,SSymbol):
423    """
424    Determines supersymmetry information from superspace group name; currently only for (3+1) superlattices
425
426    :param SGData: space group data structure as defined in SpcGroup above (see :ref:`SGData<SGData_table>`).
427    :param SSymbol: superspace group symbol extension (string) defining modulation direction & generator info.
428    :returns: (SSGError,SSGData)
429   
430       * SGError = 0 for no errors; >0 for errors (see SGErrors below for details)
431       * SSGData - is a dict (see :ref:`Superspace Group object<SSGData_table>`) with entries:
432       
433             * 'SSpGrp': superspace group symbol extension to space group symbol, accidental spaces removed
434             * 'SSGCen': 4D cell centering vectors [0,0,0,0] at least
435             * 'SSGOps': 4D symmetry operations as [M,T] so that M*x+T = x'
436
437    """
438   
439    def checkModSym():
440        '''
441        Checks to see if proposed modulation form is allowed for Laue group
442        '''
443        if LaueId in [0,] and LaueModId in [0,]:
444            return True
445        elif LaueId in [1,]:
446            try:
447                if modsym.index('1/2') != ['A','B','C'].index(SGData['SGLatt']):
448                    return False
449                if 'I'.index(SGData['SGLatt']) and modsym.count('1/2') not in [0,2]:
450                    return False
451            except ValueError:
452                pass
453            if SGData['SGUniq'] == 'a' and LaueModId in [5,6,7,8,9,10,]:
454                return True
455            elif SGData['SGUniq'] == 'b' and LaueModId in [3,4,13,14,15,16,]:
456                return True
457            elif SGData['SGUniq'] == 'c' and LaueModId in [1,2,19,20,21,22,]:
458                return True
459        elif LaueId in [2,] and LaueModId in [i+7 for i in range(18)]:
460            try:
461                if modsym.index('1/2') != ['A','B','C'].index(SGData['SGLatt']):
462                    return False
463                if SGData['SGLatt'] in ['I','F',] and modsym.index('1/2'):
464                    return False
465            except ValueError:
466                pass
467            return True
468        elif LaueId in [3,4,] and LaueModId in [19,22,]:
469            try:
470                if SGData['SGLatt'] == 'I' and modsym.count('1/2'):
471                    return False
472            except ValueError:
473                pass
474            return True
475        elif LaueId in [7,8,9,] and LaueModId in [19,25,]:
476            if (SGData['SGLatt'] == 'R' or SGData['SGPtGrp'] in ['3m1','-3m1']) and modsym.count('1/3'):
477                return False
478            return True
479        elif LaueId in [10,11,] and LaueModId in [19,]:
480            return True
481        return False
482       
483    def fixMonoOrtho():
484        mod = ''.join(modsym).replace('1/2','0').replace('1','0')
485        if SGData['SGPtGrp'] in ['2','m']:  #OK
486            if mod in ['a00','0b0','00g']:
487                result = [i*-1 for i in SGData['SSGKl']]
488            else:
489                result = SGData['SSGKl'][:]
490            if '/' in mod:
491                return [i*-1 for i in result]
492            else:
493                return result
494        elif SGData['SGPtGrp'] == '2/m':    #OK
495            if mod in ['a00','0b0','00g']:
496                result =  SGData['SSGKl'][:]
497            else:
498                result = [i*-1 for i in SGData['SSGKl']]
499            if '/' in mod:
500                return [i*-1 for i in result]
501            else:
502                return result
503        else:   #orthorhombic
504            return [-SSGKl[i] if mod[i] in ['a','b','g'] else SSGKl[i] for i in range(3)]
505               
506    def extendSSGOps(SSGOps):
507        nOps = len(SSGOps)
508        for OpA in SSGOps:
509            OpAtxt = SSMT2text(OpA)
510            if 't' not in OpAtxt:
511                continue
512            for OpB in SSGOps:
513                OpBtxt = SSMT2text(OpB)
514                if 't' not in OpBtxt:
515                    continue
516                OpC = list(SGProd(OpB,OpA))
517                OpC[1] %= 1.
518                OpCtxt = SSMT2text(OpC)
519#                print OpAtxt.replace(' ','')+' * '+OpBtxt.replace(' ','')+' = '+OpCtxt.replace(' ','')
520                for k,OpD in enumerate(SSGOps):
521                    OpDtxt = SSMT2text(OpD)
522                    if 't' in OpDtxt:
523                        continue
524#                    print '    ('+OpCtxt.replace(' ','')+' = ? '+OpDtxt.replace(' ','')+')'
525                    if OpCtxt == OpDtxt:
526                        continue
527                    elif OpCtxt.split(',')[:3] == OpDtxt.split(',')[:3]:
528                        if 't' not in OpDtxt:
529                            SSGOps[k] = OpC
530#                            print k,'   new:',OpCtxt.replace(' ','')
531                            break
532                        else:
533                            OpCtxt = OpCtxt.replace(' ','')
534                            OpDtxt = OpDtxt.replace(' ','')
535                            Txt = OpCtxt+' conflict with '+OpDtxt
536                            print Txt
537                            return False,Txt
538        return True,SSGOps
539       
540    def findMod(modSym):
541        for a in ['a','b','g']:
542            if a in modSym:
543                return a
544               
545    def genSSGOps():
546        SSGOps = SSGData['SSGOps'][:]
547        iFrac = {}
548        for i,frac in enumerate(SSGData['modSymb']):
549            if frac in ['1/2','1/3','1/4','1/6','1']:
550                iFrac[i] = frac+'.'
551#        print SGData['SpGrp']+SSymbol
552#        print 'SSGKl',SSGKl,'genQ',genQ,'iFrac',iFrac,'modSymb',SSGData['modSymb']
553# set identity & 1,-1; triclinic
554        SSGOps[0][0][3,3] = 1.
555## expand if centrosymmetric
556#        if SGData['SGInv']:
557#            SSGOps += [[-1*M,V] for M,V in SSGOps[:]]
558# monoclinic - all done & all checked
559        if SGData['SGPtGrp'] in ['2','m']:  #OK
560            SSGOps[1][0][3,3] = SSGKl[0]
561            SSGOps[1][1][3] = genQ[0]
562            for i in iFrac:
563                SSGOps[1][0][3,i] = -SSGKl[0]
564        elif SGData['SGPtGrp'] == '2/m':    #OK
565            SSGOps[1][0][3,3] = SSGKl[1]
566            if gensym:
567                SSGOps[1][1][3] = 0.5
568            for i in iFrac:
569                SSGOps[1][0][3,i] = SSGKl[0]
570           
571# orthorhombic - all OK not fully checked
572        elif SGData['SGPtGrp'] in ['222','mm2','m2m','2mm']:    #OK
573            if SGData['SGPtGrp'] == '222':
574                OrOps = {'g':{0:[1,3],1:[2,3]},'a':{1:[1,2],2:[1,3]},'b':{2:[3,2],0:[1,2]}} #OK
575            elif SGData['SGPtGrp'] == 'mm2':
576                OrOps = {'g':{0:[1,3],1:[2,3]},'a':{1:[2,1],2:[3,1]},'b':{0:[1,2],2:[3,2]}} #OK
577            elif SGData['SGPtGrp'] == 'm2m':
578                OrOps = {'b':{0:[1,2],2:[3,2]},'g':{0:[1,3],1:[2,3]},'a':{1:[2,1],2:[3,1]}} #OK
579            elif SGData['SGPtGrp'] == '2mm':
580                OrOps = {'a':{1:[2,1],2:[3,1]},'b':{0:[1,2],2:[3,2]},'g':{0:[1,3],1:[2,3]}} #OK
581            a = findMod(SSGData['modSymb'])
582            OrFrac = OrOps[a]
583            for j in iFrac:
584                for i in OrFrac[j]:
585                    SSGOps[i][0][3,j] = -2.*eval(iFrac[j])*SSGKl[i-1]
586            for i in [0,1,2]:
587                SSGOps[i+1][0][3,3] = SSGKl[i]
588                SSGOps[i+1][1][3] = genQ[i]
589                E,SSGOps = extendSSGOps(SSGOps)
590                if not E:
591                    return E,SSGOps
592        elif SGData['SGPtGrp'] == 'mmm':    #OK
593            OrOps = {'g':{0:[1,3],1:[2,3]},'a':{1:[2,1],2:[3,1]},'b':{0:[1,2],2:[3,2]}} 
594            a = findMod(SSGData['modSymb'])
595            if a == 'g':
596                SSkl = [1,1,1]
597            elif a == 'a':
598                SSkl = [-1,1,-1]
599            else:
600                SSkl = [1,-1,-1]
601            OrFrac = OrOps[a]
602            for j in iFrac:
603                for i in OrFrac[j]:
604                    SSGOps[i][0][3,j] = -2.*eval(iFrac[j])*SSkl[i-1]
605            for i in [0,1,2]:
606                SSGOps[i+1][0][3,3] = SSkl[i]
607                SSGOps[i+1][1][3] = genQ[i]
608                E,SSGOps = extendSSGOps(SSGOps)
609                if not E:
610                    return E,SSGOps               
611# tetragonal - all done & checked
612        elif SGData['SGPtGrp'] == '4':  #OK
613            SSGOps[1][0][3,3] = SSGKl[0]
614            SSGOps[1][1][3] = genQ[0]
615            if '1/2' in SSGData['modSymb']:
616                SSGOps[1][0][3,1] = -1
617        elif SGData['SGPtGrp'] == '-4': #OK
618            SSGOps[1][0][3,3] = SSGKl[0]
619            if '1/2' in SSGData['modSymb']:
620                SSGOps[1][0][3,1] = 1
621        elif SGData['SGPtGrp'] in ['4/m',]: #OK
622            if '1/2' in SSGData['modSymb']:
623                SSGOps[1][0][3,1] = -SSGKl[0]
624            for i,j in enumerate([1,3]):
625                SSGOps[j][0][3,3] = 1
626                if genQ[i]:
627                    SSGOps[j][1][3] = genQ[i]
628                E,SSGOps = extendSSGOps(SSGOps)
629                if not E:
630                    return E,SSGOps
631        elif SGData['SGPtGrp'] in ['422','4mm','-42m','-4m2',]: #OK
632            iGens = [1,4,5]
633            if SGData['SGPtGrp'] in ['4mm','-4m2',]:
634                iGens = [1,6,7]
635            for i,j in enumerate(iGens):
636                if '1/2' in SSGData['modSymb'] and i < 2:
637                    SSGOps[j][0][3,1] = SSGKl[i]
638                SSGOps[j][0][3,3] = SSGKl[i]
639                if genQ[i]:
640                    if 's' in gensym and j == 6:
641                        SSGOps[j][1][3] = -genQ[i]
642                    else:
643                        SSGOps[j][1][3] = genQ[i]
644                E,SSGOps = extendSSGOps(SSGOps)
645                if not E:
646                    return E,SSGOps
647        elif SGData['SGPtGrp'] in ['4/mmm',]:#OK
648            if '1/2' in SSGData['modSymb']:
649                SSGOps[1][0][3,1] = -SSGKl[0]
650                SSGOps[6][0][3,1] = SSGKl[1]
651                if modsym:
652                   SSGOps[1][1][3]  = -genQ[3]
653            for i,j in enumerate([1,2,6,7]):
654                SSGOps[j][0][3,3] = 1
655                SSGOps[j][1][3] = genQ[i]
656                E,Result = extendSSGOps(SSGOps)
657                if not E:
658                    return E,Result
659                else:
660                    SSGOps = Result
661               
662# trigonal - all done & checked
663        elif SGData['SGPtGrp'] == '3':  #OK
664            SSGOps[1][0][3,3] = SSGKl[0]
665            if '1/3' in SSGData['modSymb']:
666                SSGOps[1][0][3,1] = -1
667            SSGOps[1][1][3] = genQ[0]
668        elif SGData['SGPtGrp'] == '-3': #OK
669            SSGOps[1][0][3,3] = -SSGKl[0]
670            if '1/3' in SSGData['modSymb']:
671                SSGOps[1][0][3,1] = -1
672            SSGOps[1][1][3] = genQ[0]
673        elif SGData['SGPtGrp'] in ['312','3m','-3m','-3m1','3m1']:   #OK
674            if '1/3' in SSGData['modSymb']:
675                SSGOps[1][0][3,1] = -1
676            for i,j in enumerate([1,5]):
677                if SGData['SGPtGrp'] in ['3m','-3m']:
678                    SSGOps[j][0][3,3] = 1
679                else:                   
680                    SSGOps[j][0][3,3] = SSGKl[i+1]
681                if genQ[i]:
682                    SSGOps[j][1][3] = genQ[i]
683        elif SGData['SGPtGrp'] in ['321','32']:   #OK
684            for i,j in enumerate([1,4]):
685                SSGOps[j][0][3,3] = SSGKl[i]
686                if genQ[i]:
687                    SSGOps[j][1][3] = genQ[i]
688        elif SGData['SGPtGrp'] in ['31m','-31m']:   #OK
689            ids = [1,3]
690            if SGData['SGPtGrp'] == '-31m':
691                ids = [1,3]
692            if '1/3' in SSGData['modSymb']:
693                SSGOps[ids[0]][0][3,1] = -SSGKl[0]
694            for i,j in enumerate(ids):
695                SSGOps[j][0][3,3] = 1
696                if genQ[i+1]:
697                    SSGOps[j][1][3] = genQ[i+1]
698                     
699# hexagonal all done & checked
700        elif SGData['SGPtGrp'] == '6':  #OK
701            SSGOps[1][0][3,3] = SSGKl[0]
702            SSGOps[1][1][3] = genQ[0]
703        elif SGData['SGPtGrp'] == '-6': #OK
704            SSGOps[1][0][3,3] = SSGKl[0]
705        elif SGData['SGPtGrp'] in ['6/m',]: #OK
706            SSGOps[1][0][3,3] = -SSGKl[1]
707            SSGOps[1][1][3] = genQ[0]
708            SSGOps[2][1][3] = genQ[1]
709        elif SGData['SGPtGrp'] in ['622',]: #OK
710            for i,j in enumerate([1,8,9]):
711                SSGOps[j][0][3,3] = SSGKl[i]
712                if genQ[i]:
713                    SSGOps[j][1][3] = genQ[i]
714                E,SSGOps = extendSSGOps(SSGOps)
715           
716        elif SGData['SGPtGrp'] in ['6mm','-62m','-6m2',]: #OK
717            for i,j in enumerate([1,6,7]):
718                SSGOps[j][0][3,3] = SSGKl[i]
719                if genQ[i]:
720                    SSGOps[j][1][3] = genQ[i]
721                E,SSGOps = extendSSGOps(SSGOps)
722        elif SGData['SGPtGrp'] in ['6/mmm',]: # OK
723            for i,j in enumerate([1,2,10,11]):
724                SSGOps[j][0][3,3] = 1
725                if genQ[i]:
726                    SSGOps[j][1][3] = genQ[i]
727                E,SSGOps = extendSSGOps(SSGOps)
728        elif SGData['SGPtGrp'] in ['1','-1']: #triclinic - done
729            return True,SSGOps
730        E,SSGOps = extendSSGOps(SSGOps)
731        return E,SSGOps
732       
733    def specialGen(gensym,modsym):
734        sym = ''.join(gensym)
735        if SGData['SGPtGrp'] in ['2/m',] and 'n' in SGData['SpGrp']:
736            if 's' in sym:
737                gensym = 'ss'
738        if SGData['SGPtGrp'] in ['-62m',] and sym == '00s':
739            gensym = '0ss'
740        elif SGData['SGPtGrp'] in ['222',]:
741            if sym == '00s':
742                gensym = '0ss'
743            elif sym == '0s0':
744                gensym = 'ss0'
745            elif sym == 's00':
746                gensym = 's0s'
747        elif SGData['SGPtGrp'] in ['mmm',]:
748            if 'g' in modsym:
749                if sym == 's00':
750                    gensym = 's0s'
751                elif sym == '0s0':
752                    gensym = '0ss'
753            elif 'a' in modsym:
754                if sym == '0s0':
755                    gensym = 'ss0'
756                elif sym == '00s':
757                    gensym = 's0s'
758            elif 'b' in modsym:
759                if sym == '00s':
760                    gensym = '0ss'
761                elif sym == 's00':
762                    gensym = 'ss0'
763        return gensym
764                   
765    def checkGen(gensym):
766        '''
767    GenSymList = ['','s','0s','s0', '00s','0s0','s00','s0s','ss0','0ss','q00','0q0','00q','qq0','q0q', '0qq',
768        'q','qqs','s0s0','00ss','s00s','t','t00','t0','h','h00','000s']
769        '''
770        sym = ''.join(gensym)
771# monoclinic - all done
772        if str(SSGKl) == '[-1]' and sym == 's':
773            return False
774        elif SGData['SGPtGrp'] in ['2/m',]:
775            if str(SSGKl) == '[-1, 1]' and sym == '0s':
776                return False
777            elif str(SSGKl) == '[1, -1]' and sym == 's0':
778                return False
779#orthorhombic - all
780        elif SGData['SGPtGrp'] in ['222',] and sym not in ['','s00','0s0','00s']:
781            return False 
782        elif SGData['SGPtGrp'] in ['2mm','m2m','mm2','mmm'] and sym not in ['',]+GenSymList[4:16]:
783            return False 
784#tetragonal - all done
785        elif SGData['SGPtGrp'] in ['4',] and sym not in ['','s','q']:
786            return False 
787        elif SGData['SGPtGrp'] in ['-4',] and sym not in ['',]:
788            return False             
789        elif SGData['SGPtGrp'] in ['4/m',] and sym not in ['','s0','q0']:
790            return False
791        elif SGData['SGPtGrp'] in ['422',] and sym not in ['','q00','s00']:
792            return False         
793        elif SGData['SGPtGrp'] in ['4mm',] and sym not in ['','ss0','s0s','0ss','00s','qq0','qqs']:
794            return False
795        elif SGData['SGPtGrp'] in ['-4m2',] and sym not in ['','0s0','0q0']:
796            return False
797        elif SGData['SGPtGrp'] in ['-42m',] and sym not in ['','0ss','00q',]:
798            return False
799        elif SGData['SGPtGrp'] in ['4/mmm',] and sym not in ['','s00s','s0s0','00ss','000s',]:
800            return False
801#trigonal/rhombohedral - all done
802        elif SGData['SGPtGrp'] in ['3',] and sym not in ['','t']:
803            return False 
804        elif SGData['SGPtGrp'] in ['-3',] and sym not in ['',]:
805            return False 
806        elif SGData['SGPtGrp'] in ['32',] and sym not in ['','t0']:
807            return False 
808        elif SGData['SGPtGrp'] in ['321','312'] and sym not in ['','t00']:
809            return False 
810        elif SGData['SGPtGrp'] in ['3m','-3m'] and sym not in ['','0s']:
811            return False 
812        elif SGData['SGPtGrp'] in ['3m1','-3m1'] and sym not in ['','0s0']:
813            return False 
814        elif SGData['SGPtGrp'] in ['31m','-31m'] and sym not in ['','00s']:
815            return False 
816#hexagonal - all done
817        elif SGData['SGPtGrp'] in ['6',] and sym not in ['','s','h','t']:
818            return False 
819        elif SGData['SGPtGrp'] in ['-6',] and sym not in ['',]:
820            return False
821        elif SGData['SGPtGrp'] in ['6/m',] and sym not in ['','s0']:
822            return False
823        elif SGData['SGPtGrp'] in ['622',] and sym not in ['','h00','t00','s00']:
824            return False         
825        elif SGData['SGPtGrp'] in ['6mm',] and sym not in ['','ss0','s0s','0ss']:
826            return False
827        elif SGData['SGPtGrp'] in ['-6m2',] and sym not in ['','0s0']:
828            return False
829        elif SGData['SGPtGrp'] in ['-62m',] and sym not in ['','00s']:
830            return False
831        elif SGData['SGPtGrp'] in ['6/mmm',] and sym not in ['','s00s','s0s0','00ss']:
832            return False
833        return True
834       
835    LaueModList = [
836        'abg','ab0','ab1/2','a0g','a1/2g',  '0bg','1/2bg','a00','a01/2','a1/20',
837        'a1/21/2','a01','a10','0b0','0b1/2', '1/2b0','1/2b1/2','0b1','1b0','00g',
838        '01/2g','1/20g','1/21/2g','01g','10g', '1/31/3g']
839    LaueList = ['-1','2/m','mmm','4/m','4/mmm','3R','3mR','3','3m1','31m','6/m','6/mmm','m3','m3m']
840    GenSymList = ['','s','0s','s0', '00s','0s0','s00','s0s','ss0','0ss','q00','0q0','00q','qq0','q0q', '0qq',
841        'q','qqs','s0s0','00ss','s00s','t','t00','t0','h','h00','000s']
842    Fracs = {'1/2':0.5,'1/3':1./3,'1':1.0,'0':0.,'s':.5,'t':1./3,'q':.25,'h':1./6,'a':0.,'b':0.,'g':0.}
843    LaueId = LaueList.index(SGData['SGLaue'])
844    if SGData['SGLaue'] in ['m3','m3m']:
845        return '(3+1) superlattices not defined for cubic space groups',None
846    elif SGData['SGLaue'] in ['3R','3mR']:
847        return '(3+1) superlattices not defined for rhombohedral settings - use hexagonal setting',None
848    try:
849        modsym,gensym = splitSSsym(SSymbol)
850    except ValueError:
851        return 'Error in superspace symbol '+SSymbol,None
852    if ''.join(gensym) not in GenSymList:
853        return 'unknown generator symbol '+''.join(gensym),None
854    try:
855        LaueModId = LaueModList.index(''.join(modsym))
856    except ValueError:
857        return 'Unknown modulation symbol '+''.join(modsym),None
858    if not checkModSym():
859        return 'Modulation '+''.join(modsym)+' not consistent with space group '+SGData['SpGrp'],None
860    modQ = [Fracs[mod] for mod in modsym]
861    SSGKl = SGData['SSGKl'][:]
862    if SGData['SGLaue'] in ['2/m','mmm']:
863        SSGKl = fixMonoOrtho()
864    if len(gensym) and len(gensym) != len(SSGKl):
865        return 'Wrong number of items in generator symbol '+''.join(gensym),None
866    if not checkGen(gensym):
867        return 'Generator '+''.join(gensym)+' not consistent with space group '+SGData['SpGrp'],None
868    gensym = specialGen(gensym,modsym)
869    genQ = [Fracs[mod] for mod in gensym]
870    if not genQ:
871        genQ = [0,0,0,0]
872    SSGData = {'SSpGrp':SGData['SpGrp']+SSymbol,'modQ':modQ,'modSymb':modsym,'SSGKl':SSGKl}
873    SSCen = np.zeros((len(SGData['SGCen']),4))
874    for icen,cen in enumerate(SGData['SGCen']):
875        SSCen[icen,0:3] = cen
876    SSCen[0] = np.zeros(4)
877    SSGData['SSGCen'] = SSCen
878    SSGData['SSGOps'] = []
879    for iop,op in enumerate(SGData['SGOps']):
880        T = np.zeros(4)
881        ssop = np.zeros((4,4))
882        ssop[:3,:3] = op[0]
883        T[:3] = op[1]
884        SSGData['SSGOps'].append([ssop,T])
885    E,Result = genSSGOps()
886    if E:
887        SSGData['SSGOps'] = Result
888        if DEBUG:
889            print 'Super spacegroup operators for '+SSGData['SSpGrp']
890            for Op in Result:
891                print SSMT2text(Op).replace(' ','')
892            if SGData['SGInv']:                                 
893                for Op in Result:
894                    Op = [-Op[0],-Op[1]%1.]
895                    print SSMT2text(Op).replace(' ','')                                 
896        return None,SSGData
897    else:
898        return Result+'\nOperator conflict - incorrect superspace symbol',None
899
900def splitSSsym(SSymbol):
901    '''
902    Splits supersymmetry symbol into two lists of strings
903    '''
904    modsym,gensym = SSymbol.replace(' ','').split(')')
905    if gensym in ['0','00','000','0000']:       #get rid of extraneous symbols
906        gensym = ''
907    nfrac = modsym.count('/')
908    modsym = modsym.lstrip('(')
909    if nfrac == 0:
910        modsym = list(modsym)
911    elif nfrac == 1:
912        pos = modsym.find('/')
913        if pos == 1:
914            modsym = [modsym[:3],modsym[3],modsym[4]]
915        elif pos == 2:
916            modsym = [modsym[0],modsym[1:4],modsym[4]]
917        else:
918            modsym = [modsym[0],modsym[1],modsym[2:]]
919    else:
920        lpos = modsym.find('/')
921        rpos = modsym.rfind('/')
922        if lpos == 1 and rpos == 4:
923            modsym = [modsym[:3],modsym[3:6],modsym[6]]
924        elif lpos == 1 and rpos == 5:
925            modsym = [modsym[:3],modsym[3],modsym[4:]]
926        else:
927            modsym = [modsym[0],modsym[1:4],modsym[4:]]
928    gensym = list(gensym)
929    return modsym,gensym
930       
931def SSGPrint(SGData,SSGData):
932    '''
933    Print the output of SSpcGroup in a nicely formatted way. Used in SSpaceGroup
934
935    :param SGData: space group data structure as defined in SpcGroup above.
936    :param SSGData: from :func:`SSpcGroup`
937    :returns:
938        SSGText - list of strings with the superspace group details
939        SGTable - list of strings for each of the operations
940    '''
941    Mult = len(SSGData['SSGCen'])*len(SSGData['SSGOps'])*(int(SGData['SGInv'])+1)
942    SSGText = []
943    SSGText.append(' Superspace Group: '+SSGData['SSpGrp'])
944    CentStr = 'centrosymmetric'
945    if not SGData['SGInv']:
946        CentStr = 'non'+CentStr
947    if SGData['SGLatt'] in 'ABCIFR':
948        SSGText.append(' The lattice is '+CentStr+' '+SGData['SGLatt']+'-centered '+SGData['SGSys'].lower())
949    else:
950        SSGText.append(' The superlattice is '+CentStr+' '+'primitive '+SGData['SGSys'].lower())       
951    SSGText.append(' The Laue symmetry is '+SGData['SGLaue'])
952    SSGText.append(' The superlattice point group is '+SGData['SGPtGrp']+', '+''.join([str(i) for i in SSGData['SSGKl']]))
953    SSGText.append(' The number of superspace group generators is '+str(len(SGData['SSGKl'])))
954    SSGText.append(' Multiplicity of a general site is '+str(Mult))
955    if SGData['SGUniq'] in ['a','b','c']:
956        SSGText.append(' The unique monoclinic axis is '+SGData['SGUniq'])
957    if SGData['SGInv']:
958        SSGText.append(' The inversion center is located at 0,0,0')
959    if SGData['SGPolax']:
960        SSGText.append(' The location of the origin is arbitrary in '+SGData['SGPolax'])
961    SSGText.append(' ')
962    if len(SSGData['SSGCen']) > 1:
963        SSGText.append(' The equivalent positions are:')
964        SSGText.append(' ('+SSLatt2text(SSGData['SSGCen'])+')+\n')
965    else:
966        SSGText.append(' The equivalent positions are:\n')
967    SSGTable = []
968    for i,Opr in enumerate(SSGData['SSGOps']):
969        SSGTable.append('(%2d) %s'%(i+1,SSMT2text(Opr)))
970    return SSGText,SSGTable
971   
972def SSGModCheck(Vec,modSymb):
973    ''' Checks modulation vector compatibility with supersymmetry space group symbol.
974    Superspace group symbol takes precidence & the vector will be modified accordingly
975    '''
976    Fracs = {'1/2':0.5,'1/3':1./3,'1':1.0,'0':0.,'a':0.,'b':0.,'g':0.}
977    modQ = [Fracs[mod] for mod in modSymb]
978    Vec = [0.1 if (vec == 0.0 and mod in ['a','b','g']) else vec for [vec,mod] in zip(Vec,modSymb)]
979    return [Q if mod not in ['a','b','g'] and vec != Q else vec for [vec,mod,Q] in zip(Vec,modSymb,modQ)],  \
980        [True if mod in ['a','b','g'] else False for mod in modSymb]
981
982def SSMT2text(Opr):
983    "From superspace group matrix/translation operator returns text version"
984    XYZS = ('x','y','z','t')    #Stokes, Campbell & van Smaalen notation
985    TRA = ('   ','ERR','1/6','1/4','1/3','ERR','1/2','ERR','2/3','3/4','5/6','ERR')
986    Fld = ''
987    M,T = Opr
988    for j in range(4):
989        IJ = ''
990        for k in range(4):
991            txt = str(int(round(M[j][k])))
992            txt = txt.replace('1',XYZS[k]).replace('0','')
993            if '2' in txt:
994                txt += XYZS[k]
995            if IJ and M[j][k] > 0:
996                IJ += '+'+txt
997            else:
998                IJ += txt
999        IK = int(round(T[j]*12))%12
1000        if IK:
1001            if not IJ:
1002                break
1003            if IJ[0] == '-':
1004                Fld += (TRA[IK]+IJ).rjust(8)
1005            else:
1006                Fld += (TRA[IK]+'+'+IJ).rjust(8)
1007        else:
1008            Fld += IJ.rjust(8)
1009        if j != 3: Fld += ', '
1010    return Fld
1011   
1012def SSLatt2text(SSGCen):
1013    "Lattice centering vectors to text"
1014    lattTxt = ''
1015    lattDir = {4:'1/3',6:'1/2',8:'2/3',0:'0'}
1016    for vec in SSGCen:
1017        lattTxt += ' '
1018        for item in vec:
1019            lattTxt += '%s,'%(lattDir[int(item*12)])
1020        lattTxt = lattTxt.rstrip(',')
1021        lattTxt += ';'
1022    lattTxt = lattTxt.rstrip(';').lstrip(' ')
1023    return lattTxt
1024       
1025def SSpaceGroup(SGSymbol,SSymbol):
1026    '''
1027    Print the output of SSpcGroup in a nicely formatted way.
1028
1029    :param SGSymbol: space group symbol with spaces between axial fields.
1030    :param SSymbol: superspace group symbol extension (string).
1031    :returns: nothing
1032    '''
1033
1034    E,A = SpcGroup(SGSymbol)
1035    if E > 0:
1036        print SGErrors(E)
1037        return
1038    E,B = SSpcGroup(A,SSymbol)   
1039    if E > 0:
1040        print E
1041        return
1042    for l in SSGPrint(B):
1043        print l
1044       
1045def SGProd(OpA,OpB):
1046    '''
1047    Form space group operator product. OpA & OpB are [M,V] pairs;
1048        both must be of same dimension (3 or 4). Returns [M,V] pair
1049    '''
1050    A,U = OpA
1051    B,V = OpB
1052    M = np.inner(B,A.T)
1053    W = np.inner(B,U)+V
1054    return M,W
1055       
1056def MoveToUnitCell(xyz):
1057    '''
1058    Translates a set of coordinates so that all values are >=0 and < 1
1059
1060    :param xyz: a list or numpy array of fractional coordinates
1061    :returns: XYZ - numpy array of new coordinates now 0 or greater and less than 1
1062    '''
1063    XYZ = (np.array(xyz)+10.)%1.
1064    cell = np.asarray(np.rint(xyz-XYZ),dtype=np.int32)
1065    return XYZ,cell
1066       
1067def Opposite(XYZ,toler=0.0002):
1068    '''
1069    Gives opposite corner, edge or face of unit cell for position within tolerance.
1070        Result may be just outside the cell within tolerance
1071
1072    :param XYZ: 0 >= np.array[x,y,z] > 1 as by MoveToUnitCell
1073    :param toler: unit cell fraction tolerance making opposite
1074    :returns:
1075        XYZ: dict of opposite positions; key=unit cell & always contains XYZ
1076    '''
1077    perm3 = [[1,1,1],[0,1,1],[1,0,1],[1,1,0],[1,0,0],[0,1,0],[0,0,1],[0,0,0]]
1078    TB = np.where(abs(XYZ-1)<toler,-1,0)+np.where(abs(XYZ)<toler,1,0)
1079    perm = TB*perm3
1080    cperm = ['%d,%d,%d'%(i,j,k) for i,j,k in perm]
1081    D = dict(zip(cperm,perm))
1082    new = {}
1083    for key in D:
1084        new[key] = np.array(D[key])+np.array(XYZ)
1085    return new
1086       
1087def GenAtom(XYZ,SGData,All=False,Uij=[],Move=True):
1088    '''
1089    Generates the equivalent positions for a specified coordinate and space group
1090
1091    :param XYZ: an array, tuple or list containing 3 elements: x, y & z
1092    :param SGData: from :func:`SpcGroup`
1093    :param All: True return all equivalent positions including duplicates;
1094      False return only unique positions
1095    :param Uij: [U11,U22,U33,U12,U13,U23] or [] if no Uij
1096    :param Move: True move generated atom positions to be inside cell
1097      False do not move atoms       
1098    :return: [[XYZEquiv],Idup,[UijEquiv]]
1099
1100      *  [XYZEquiv] is list of equivalent positions (XYZ is first entry)
1101      *  Idup = [-][C]SS where SS is the symmetry operator number (1-24), C (if not 0,0,0)
1102      * is centering operator number (1-4) and - is for inversion
1103        Cell = unit cell translations needed to put new positions inside cell
1104        [UijEquiv] - equivalent Uij; absent if no Uij given
1105       
1106    '''
1107    XYZEquiv = []
1108    UijEquiv = []
1109    Idup = []
1110    Cell = []
1111    X = np.array(XYZ)
1112    if Move:
1113        X = MoveToUnitCell(X)[0]
1114    for ic,cen in enumerate(SGData['SGCen']):
1115        C = np.array(cen)
1116        for invers in range(int(SGData['SGInv']+1)):
1117            for io,[M,T] in enumerate(SGData['SGOps']):
1118                idup = ((io+1)+100*ic)*(1-2*invers)
1119                XT = np.inner(M,X)+T
1120                if len(Uij):
1121                    U = Uij2U(Uij)
1122                    U = np.inner(M,np.inner(U,M).T)
1123                    newUij = U2Uij(U)
1124                if invers:
1125                    XT = -XT
1126                XT += C
1127                cell = np.zeros(3,dtype=np.int32)
1128                cellj = np.zeros(3,dtype=np.int32)
1129                if Move:
1130                    newX,cellj = MoveToUnitCell(XT)
1131                else:
1132                    newX = XT
1133                cell += cellj
1134                if All:
1135                    if np.allclose(newX,X,atol=0.0002):
1136                        idup = False
1137                else:
1138                    if True in [np.allclose(newX,oldX,atol=0.0002) for oldX in XYZEquiv]:
1139                        idup = False
1140                if All or idup:
1141                    XYZEquiv.append(newX)
1142                    Idup.append(idup)
1143                    Cell.append(cell)
1144                    if len(Uij):
1145                        UijEquiv.append(newUij)                   
1146    if len(Uij):
1147        return zip(XYZEquiv,UijEquiv,Idup,Cell)
1148    else:
1149        return zip(XYZEquiv,Idup,Cell)
1150
1151def GenHKLf(HKL,SGData):
1152    '''
1153    Uses old GSAS Fortran routine genhkl.for
1154
1155    :param HKL:  [h,k,l] must be integral values for genhkl.for to work
1156    :param SGData: space group data obtained from SpcGroup
1157    :returns: iabsnt,mulp,Uniq,phi
1158
1159     *   iabsnt = True if reflection is forbidden by symmetry
1160     *   mulp = reflection multiplicity including Friedel pairs
1161     *   Uniq = numpy array of equivalent hkl in descending order of h,k,l
1162     *   phi = phase offset for each equivalent h,k,l
1163
1164    '''
1165    hklf = list(HKL)+[0,]       #could be numpy array!
1166    Ops = SGData['SGOps']
1167    OpM = np.array([op[0] for op in Ops])
1168    OpT = np.array([op[1] for op in Ops])
1169    Inv = SGData['SGInv']
1170    Cen = np.array([cen for cen in SGData['SGCen']])
1171   
1172    Nuniq,Uniq,iabsnt,mulp = pyspg.genhklpy(hklf,len(Ops),OpM,OpT,SGData['SGInv'],len(Cen),Cen)
1173    h,k,l,f = Uniq
1174    Uniq=np.array(zip(h[:Nuniq],k[:Nuniq],l[:Nuniq]))
1175    phi = f[:Nuniq]
1176   
1177    return iabsnt,mulp,Uniq,phi
1178   
1179def checkSSLaue(HKL,SGData,SSGData):
1180    #Laue check here - Toss HKL if outside unique Laue part
1181    h,k,l,m = HKL
1182    if SGData['SGLaue'] == '2/m':
1183        if SGData['SGUniq'] == 'a':
1184            if 'a' in SSGData['modSymb'] and h == 0 and m < 0:
1185                return False
1186            elif 'b' in SSGData['modSymb'] and k == 0 and l ==0 and m < 0:
1187                return False
1188            else:
1189                return True
1190        elif SGData['SGUniq'] == 'b':
1191            if 'b' in SSGData['modSymb'] and k == 0 and m < 0:
1192                return False
1193            elif 'a' in SSGData['modSymb'] and h == 0 and l ==0 and m < 0:
1194                return False
1195            else:
1196                return True
1197        elif SGData['SGUniq'] == 'c':
1198            if 'g' in SSGData['modSymb'] and l == 0 and m < 0:
1199                return False
1200            elif 'a' in SSGData['modSymb'] and h == 0 and k ==0 and m < 0:
1201                return False
1202            else:
1203                return True
1204    elif SGData['SGLaue'] == 'mmm':
1205        if 'a' in SSGData['modSymb']:
1206            if h == 0 and m < 0:
1207                return False
1208            else:
1209                return True
1210        elif 'b' in SSGData['modSymb']:
1211            if k == 0 and m < 0:
1212                return False
1213            else:
1214                return True
1215        elif 'g' in SSGData['modSymb']:
1216            if l == 0 and m < 0:
1217                return False
1218            else:
1219                return True
1220    else:   #tetragonal, trigonal, hexagonal (& triclinic?)
1221        if l == 0 and m < 0:
1222            return False
1223        else:
1224            return True
1225       
1226   
1227def checkSSextc(HKL,SSGData):
1228    Ops = SSGData['SSGOps']
1229    OpM = np.array([op[0] for op in Ops])
1230    OpT = np.array([op[1] for op in Ops])
1231    HKLS = np.array([HKL,-HKL])     #Freidel's Law
1232    DHKL = np.reshape(np.inner(HKLS,OpM)-HKL,(-1,4))
1233    PHKL = np.reshape(np.inner(HKLS,OpT),(-1,))
1234    for dhkl,phkl in zip(DHKL,PHKL)[1:]:    #skip identity
1235        if dhkl.any():
1236            continue
1237        else:
1238            if phkl%1.:
1239                return False
1240    return True
1241                                 
1242def GetOprPtrName(key):
1243    'Needs a doc string'
1244    OprPtrName = {
1245        '-6643':[   2,' 1bar ', 1],'6479' :[  10,'  2z  ', 2],'-6479':[   9,'  mz  ', 3],
1246        '6481' :[   7,'  my  ', 4],'-6481':[   6,'  2y  ', 5],'6641' :[   4,'  mx  ', 6],
1247        '-6641':[   3,'  2x  ', 7],'6591' :[  28,' m+-0 ', 8],'-6591':[  27,' 2+-0 ', 9],
1248        '6531' :[  25,' m110 ',10],'-6531':[  24,' 2110 ',11],'6537' :[  61,'  4z  ',12],
1249        '-6537':[  62,' -4z  ',13],'975'  :[  68,' 3+++1',14],'6456' :[ 114,'  3z1 ',15],
1250        '-489' :[  73,' 3+-- ',16],'483'  :[  78,' 3-+- ',17],'-969' :[  83,' 3--+ ',18],
1251        '819'  :[  22,' m+0- ',19],'-819' :[  21,' 2+0- ',20],'2431' :[  16,' m0+- ',21],
1252        '-2431':[  15,' 20+- ',22],'-657' :[  19,' m101 ',23],'657'  :[  18,' 2101 ',24],
1253        '1943' :[  48,' -4x  ',25],'-1943':[  47,'  4x  ',26],'-2429':[  13,' m011 ',27],
1254        '2429' :[  12,' 2011 ',28],'639'  :[  55,' -4y  ',29],'-639' :[  54,'  4y  ',30],
1255        '-6484':[ 146,' 2010 ', 4],'6484' :[ 139,' m010 ', 5],'-6668':[ 145,' 2100 ', 6],
1256        '6668' :[ 138,' m100 ', 7],'-6454':[ 148,' 2120 ',18],'6454' :[ 141,' m120 ',19],
1257        '-6638':[ 149,' 2210 ',20],'6638' :[ 142,' m210 ',21],              #search ends here
1258        '2223' :[  68,' 3+++2',39],
1259        '6538' :[ 106,'  6z1 ',40],'-2169':[  83,' 3--+2',41],'2151' :[  73,' 3+--2',42],
1260        '2205' :[  79,'-3-+-2',43],'-2205':[  78,' 3-+-2',44],'489'  :[  74,'-3+--1',45],
1261        '801'  :[  53,'  4y1 ',46],'1945' :[  47,'  4x3 ',47],'-6585':[  62,' -4z3 ',48],
1262        '6585' :[  61,'  4z3 ',49],'6584' :[ 114,'  3z2 ',50],'6666' :[ 106,'  6z5 ',51],
1263        '6643' :[   1,' Iden ',52],'-801' :[  55,' -4y1 ',53],'-1945':[  48,' -4x3 ',54],
1264        '-6666':[ 105,' -6z5 ',55],'-6538':[ 105,' -6z1 ',56],'-2223':[  69,'-3+++2',57],
1265        '-975' :[  69,'-3+++1',58],'-6456':[ 113,' -3z1 ',59],'-483' :[  79,'-3-+-1',60],
1266        '969'  :[  84,'-3--+1',61],'-6584':[ 113,' -3z2 ',62],'2169' :[  84,'-3--+2',63],
1267        '-2151':[  74,'-3+--2',64],'0':[0,' ????',0]
1268        }
1269    return OprPtrName[key]
1270
1271def GetKNsym(key):
1272    'Needs a doc string'
1273    KNsym = {
1274        '0'         :'    1   ','1'         :'   -1   ','64'        :'    2(x)','32'        :'    m(x)',
1275        '97'        :'  2/m(x)','16'        :'    2(y)','8'         :'    m(y)','25'        :'  2/m(y)',
1276        '2'         :'    2(z)','4'         :'    m(z)','7'         :'  2/m(z)','134217728' :'   2(yz)',
1277        '67108864'  :'   m(yz)','201326593' :' 2/m(yz)','2097152'   :'  2(0+-)','1048576'   :'  m(0+-)',
1278        '3145729'   :'2/m(0+-)','8388608'   :'   2(xz)','4194304'   :'   m(xz)','12582913'  :' 2/m(xz)',
1279        '524288'    :'  2(+0-)','262144'    :'  m(+0-)','796433'    :'2/m(+0-)','1024'      :'   2(xy)',
1280        '512'       :'   m(xy)','1537'      :' 2/m(xy)','256'       :'  2(+-0)','128'       :'  m(+-0)',
1281        '385'       :'2/m(+-0)','76'        :'  mm2(x)','52'        :'  mm2(y)','42'        :'  mm2(z)',
1282        '135266336' :' mm2(yz)','69206048'  :'mm2(0+-)','8650760'   :' mm2(xz)','4718600'   :'mm2(+0-)',
1283        '1156'      :' mm2(xy)','772'       :'mm2(+-0)','82'        :'  222   ','136314944' :'  222(x)',
1284        '8912912'   :'  222(y)','1282'      :'  222(z)','127'       :'  mmm   ','204472417' :'  mmm(x)',
1285        '13369369'  :'  mmm(y)','1927'      :'  mmm(z)','33554496'  :'  4(100)','16777280'  :' -4(100)',
1286        '50331745'  :'4/m(100)','169869394' :'422(100)','84934738'  :'-42m 100','101711948' :'4mm(100)',
1287        '254804095' :'4/mmm100','536870928 ':'  4(010)','268435472' :' -4(010)','805306393' :'4/m (10)',
1288        '545783890' :'422(010)','272891986' :'-42m 010','541327412' :'4mm(010)','818675839' :'4/mmm010',
1289        '2050'      :'  4(001)','4098'      :' -4(001)','6151'      :'4/m(001)','3410'      :'422(001)',
1290        '4818'      :'-42m 001','2730'      :'4mm(001)','8191'      :'4/mmm001','8192'      :'  3(111)',
1291        '8193'      :' -3(111)','2629888'   :' 32(111)','1319040'   :' 3m(111)','3940737'   :'-3m(111)',
1292        '32768'     :'  3(+--)','32769'     :' -3(+--)','10519552'  :' 32(+--)','5276160'   :' 3m(+--)',
1293        '15762945'  :'-3m(+--)','65536'     :'  3(-+-)','65537'     :' -3(-+-)','134808576' :' 32(-+-)',
1294        '67437056'  :' 3m(-+-)','202180097' :'-3m(-+-)','131072'    :'  3(--+)','131073'    :' -3(--+)',
1295        '142737664' :' 32(--+)','71434368'  :' 3m(--+)','214040961' :'-3m(--+)','237650'    :'   23   ',
1296        '237695'    :'   m3   ','715894098' :'   432  ','358068946' :'  -43m  ','1073725439':'   m3m  ',
1297        '68157504'  :' mm2d100','4456464'   :' mm2d010','642'       :' mm2d001','153092172' :'-4m2 100',
1298        '277348404' :'-4m2 010','5418'      :'-4m2 001','1075726335':'  6/mmm ','1074414420':'-6m2 100',
1299        '1075070124':'-6m2 120','1075069650':'   6mm  ','1074414890':'   622  ','1073758215':'   6/m  ',
1300        '1073758212':'   -6   ','1073758210':'    6   ','1073759865':'-3m(100)','1075724673':'-3m(120)',
1301        '1073758800':' 3m(100)','1075069056':' 3m(120)','1073759272':' 32(100)','1074413824':' 32(120)',
1302        '1073758209':'   -3   ','1073758208':'    3   ','1074135143':'mmm(100)','1075314719':'mmm(010)',
1303        '1073743751':'mmm(110)','1074004034':' mm2z100','1074790418':' mm2z010','1073742466':' mm2z110',
1304        '1074004004':'mm2(100)','1074790412':'mm2(010)','1073742980':'mm2(110)','1073872964':'mm2(120)',
1305        '1074266132':'mm2(210)','1073742596':'mm2(+-0)','1073872930':'222(100)','1074266122':'222(010)',
1306        '1073743106':'222(110)','1073741831':'2/m(001)','1073741921':'2/m(100)','1073741849':'2/m(010)',
1307        '1073743361':'2/m(110)','1074135041':'2/m(120)','1075314689':'2/m(210)','1073742209':'2/m(+-0)',
1308        '1073741828':' m(001) ','1073741888':' m(100) ','1073741840':' m(010) ','1073742336':' m(110) ',
1309        '1074003968':' m(120) ','1074790400':' m(210) ','1073741952':' m(+-0) ','1073741826':' 2(001) ',
1310        '1073741856':' 2(100) ','1073741832':' 2(010) ','1073742848':' 2(110) ','1073872896':' 2(120) ',
1311        '1074266112':' 2(210) ','1073742080':' 2(+-0) ','1073741825':'   -1   '
1312        }
1313    return KNsym[key]       
1314
1315def GetNXUPQsym(siteSym):
1316    '''       
1317    The codes XUPQ are for lookup of symmetry constraints for position(X), thermal parm(U) & magnetic moments
1318    (P&Q-not used in GSAS-II)
1319    '''
1320    NXUPQsym = {
1321        '    1   ':(28,29,28,28),'   -1   ':( 1,29,28, 0),'    2(x)':(12,18,12,25),'    m(x)':(25,18,12,25),
1322        '  2/m(x)':( 1,18, 0,-1),'    2(y)':(13,17,13,24),'    m(y)':(24,17,13,24),'  2/m(y)':( 1,17, 0,-1),
1323        '    2(z)':(14,16,14,23),'    m(z)':(23,16,14,23),'  2/m(z)':( 1,16, 0,-1),'   2(yz)':(10,23,10,22),
1324        '   m(yz)':(22,23,10,22),' 2/m(yz)':( 1,23, 0,-1),'  2(0+-)':(11,24,11,21),'  m(0+-)':(21,24,11,21),
1325        '2/m(0+-)':( 1,24, 0,-1),'   2(xz)':( 8,21, 8,20),'   m(xz)':(20,21, 8,20),' 2/m(xz)':( 1,21, 0,-1),
1326        '  2(+0-)':( 9,22, 9,19),'  m(+0-)':(19,22, 9,19),'2/m(+0-)':( 1,22, 0,-1),'   2(xy)':( 6,19, 6,18),
1327        '   m(xy)':(18,19, 6,18),' 2/m(xy)':( 1,19, 0,-1),'  2(+-0)':( 7,20, 7,17),'  m(+-0)':(17,20, 7,17),
1328        '2/m(+-0)':( 1,20, 0,-1),'  mm2(x)':(12,10, 0,-1),'  mm2(y)':(13,10, 0,-1),'  mm2(z)':(14,10, 0,-1),
1329        ' mm2(yz)':(10,13, 0,-1),'mm2(0+-)':(11,13, 0,-1),' mm2(xz)':( 8,12, 0,-1),'mm2(+0-)':( 9,12, 0,-1),
1330        ' mm2(xy)':( 6,11, 0,-1),'mm2(+-0)':( 7,11, 0,-1),'  222   ':( 1,10, 0,-1),'  222(x)':( 1,13, 0,-1),
1331        '  222(y)':( 1,12, 0,-1),'  222(z)':( 1,11, 0,-1),'  mmm   ':( 1,10, 0,-1),'  mmm(x)':( 1,13, 0,-1),
1332        '  mmm(y)':( 1,12, 0,-1),'  mmm(z)':( 1,11, 0,-1),'  4(100)':(12, 4,12, 0),' -4(100)':( 1, 4,12, 0),
1333        '4/m(100)':( 1, 4,12,-1),'422(100)':( 1, 4, 0,-1),'-42m 100':( 1, 4, 0,-1),'4mm(100)':(12, 4, 0,-1),
1334        '4/mmm100':( 1, 4, 0,-1),'  4(010)':(13, 3,13, 0),' -4(010)':( 1, 3,13, 0),'4/m (10)':( 1, 3,13,-1),
1335        '422(010)':( 1, 3, 0,-1),'-42m 010':( 1, 3, 0,-1),'4mm(010)':(13, 3, 0,-1),'4/mmm010':(1, 3, 0,-1,),
1336        '  4(001)':(14, 2,14, 0),' -4(001)':( 1, 2,14, 0),'4/m(001)':( 1, 2,14,-1),'422(001)':( 1, 2, 0,-1),
1337        '-42m 001':( 1, 2, 0,-1),'4mm(001)':(14, 2, 0,-1),'4/mmm001':( 1, 2, 0,-1),'  3(111)':( 2, 5, 2, 0),
1338        ' -3(111)':( 1, 5, 2, 0),' 32(111)':( 1, 5, 0, 2),' 3m(111)':( 2, 5, 0, 2),'-3m(111)':( 1, 5, 0,-1),
1339        '  3(+--)':( 5, 8, 5, 0),' -3(+--)':( 1, 8, 5, 0),' 32(+--)':( 1, 8, 0, 5),' 3m(+--)':( 5, 8, 0, 5),
1340        '-3m(+--)':( 1, 8, 0,-1),'  3(-+-)':( 4, 7, 4, 0),' -3(-+-)':( 1, 7, 4, 0),' 32(-+-)':( 1, 7, 0, 4),
1341        ' 3m(-+-)':( 4, 7, 0, 4),'-3m(-+-)':( 1, 7, 0,-1),'  3(--+)':( 3, 6, 3, 0),' -3(--+)':( 1, 6, 3, 0),
1342        ' 32(--+)':( 1, 6, 0, 3),' 3m(--+)':( 3, 6, 0, 3),'-3m(--+)':( 1, 6, 0,-1),'   23   ':( 1, 1, 0, 0),
1343        '   m3   ':( 1, 1, 0, 0),'   432  ':( 1, 1, 0, 0),'  -43m  ':( 1, 1, 0, 0),'   m3m  ':( 1, 1, 0, 0),
1344        ' mm2d100':(12,13, 0,-1),' mm2d010':(13,12, 0,-1),' mm2d001':(14,11, 0,-1),'-4m2 100':( 1, 4, 0,-1),
1345        '-4m2 010':( 1, 3, 0,-1),'-4m2 001':( 1, 2, 0,-1),'  6/mmm ':( 1, 9, 0,-1),'-6m2 100':( 1, 9, 0,-1),
1346        '-6m2 120':( 1, 9, 0,-1),'   6mm  ':(14, 9, 0,-1),'   622  ':( 1, 9, 0,-1),'   6/m  ':( 1, 9,14,-1),
1347        '   -6   ':( 1, 9,14, 0),'    6   ':(14, 9,14, 0),'-3m(100)':( 1, 9, 0,-1),'-3m(120)':( 1, 9, 0,-1),
1348        ' 3m(100)':(14, 9, 0,14),' 3m(120)':(14, 9, 0,14),' 32(100)':( 1, 9, 0,14),' 32(120)':( 1, 9, 0,14),
1349        '   -3   ':( 1, 9,14, 0),'    3   ':(14, 9,14, 0),'mmm(100)':( 1,14, 0,-1),'mmm(010)':( 1,15, 0,-1),
1350        'mmm(110)':( 1,11, 0,-1),' mm2z100':(14,14, 0,-1),' mm2z010':(14,15, 0,-1),' mm2z110':(14,11, 0,-1),
1351        'mm2(100)':(12,14, 0,-1),'mm2(010)':(13,15, 0,-1),'mm2(110)':( 6,11, 0,-1),'mm2(120)':(15,14, 0,-1),
1352        'mm2(210)':(16,15, 0,-1),'mm2(+-0)':( 7,11, 0,-1),'222(100)':( 1,14, 0,-1),'222(010)':( 1,15, 0,-1),
1353        '222(110)':( 1,11, 0,-1),'2/m(001)':( 1,16,14,-1),'2/m(100)':( 1,25,12,-1),'2/m(010)':( 1,28,13,-1),
1354        '2/m(110)':( 1,19, 6,-1),'2/m(120)':( 1,27,15,-1),'2/m(210)':( 1,26,16,-1),'2/m(+-0)':( 1,20,17,-1),
1355        ' m(001) ':(23,16,14,23),' m(100) ':(26,25,12,26),' m(010) ':(27,28,13,27),' m(110) ':(18,19, 6,18),
1356        ' m(120) ':(24,27,15,24),' m(210) ':(25,26,16,25),' m(+-0) ':(17,20, 7,17),' 2(001) ':(14,16,14,23),
1357        ' 2(100) ':(12,25,12,26),' 2(010) ':(13,28,13,27),' 2(110) ':( 6,19, 6,18),' 2(120) ':(15,27,15,24),
1358        ' 2(210) ':(16,26,16,25),' 2(+-0) ':( 7,20, 7,17),'   -1   ':( 1,29,28, 0)
1359        }
1360    return NXUPQsym[siteSym]
1361
1362def GetCSxinel(siteSym): 
1363    'Needs a doc string'
1364    CSxinel = [[],                         # 0th empty - indices are Fortran style
1365        [[0,0,0],[ 0.0, 0.0, 0.0]],      #1  0  0  0
1366        [[1,1,1],[ 1.0, 1.0, 1.0]],      #2  X  X  X
1367        [[1,1,1],[ 1.0, 1.0,-1.0]],      #3  X  X -X
1368        [[1,1,1],[ 1.0,-1.0, 1.0]],      #4  X -X  X
1369        [[1,1,1],[ 1.0,-1.0,-1.0]],      #5 -X  X  X
1370        [[1,1,0],[ 1.0, 1.0, 0.0]],      #6  X  X  0
1371        [[1,1,0],[ 1.0,-1.0, 0.0]],      #7  X -X  0
1372        [[1,0,1],[ 1.0, 0.0, 1.0]],      #8  X  0  X
1373        [[1,0,1],[ 1.0, 0.0,-1.0]],      #9  X  0 -X
1374        [[0,1,1],[ 0.0, 1.0, 1.0]],      #10  0  Y  Y
1375        [[0,1,1],[ 0.0, 1.0,-1.0]],      #11 0  Y -Y
1376        [[1,0,0],[ 1.0, 0.0, 0.0]],      #12  X  0  0
1377        [[0,1,0],[ 0.0, 1.0, 0.0]],      #13  0  Y  0
1378        [[0,0,1],[ 0.0, 0.0, 1.0]],      #14  0  0  Z
1379        [[1,1,0],[ 1.0, 2.0, 0.0]],      #15  X 2X  0
1380        [[1,1,0],[ 2.0, 1.0, 0.0]],      #16 2X  X  0
1381        [[1,1,2],[ 1.0, 1.0, 1.0]],      #17  X  X  Z
1382        [[1,1,2],[ 1.0,-1.0, 1.0]],      #18  X -X  Z
1383        [[1,2,1],[ 1.0, 1.0, 1.0]],      #19  X  Y  X
1384        [[1,2,1],[ 1.0, 1.0,-1.0]],      #20  X  Y -X
1385        [[1,2,2],[ 1.0, 1.0, 1.0]],      #21  X  Y  Y
1386        [[1,2,2],[ 1.0, 1.0,-1.0]],      #22  X  Y -Y
1387        [[1,2,0],[ 1.0, 1.0, 0.0]],      #23  X  Y  0
1388        [[1,0,2],[ 1.0, 0.0, 1.0]],      #24  X  0  Z
1389        [[0,1,2],[ 0.0, 1.0, 1.0]],      #25  0  Y  Z
1390        [[1,1,2],[ 1.0, 2.0, 1.0]],      #26  X 2X  Z
1391        [[1,1,2],[ 2.0, 1.0, 1.0]],      #27 2X  X  Z
1392        [[1,2,3],[ 1.0, 1.0, 1.0]],      #28  X  Y  Z
1393        ]
1394    indx = GetNXUPQsym(siteSym)
1395    return CSxinel[indx[0]]
1396   
1397def GetCSuinel(siteSym):
1398    "returns Uij terms, multipliers, GUI flags & Uiso2Uij multipliers"
1399    CSuinel = [[],                                             # 0th empty - indices are Fortran style
1400        [[1,1,1,0,0,0],[ 1.0, 1.0, 1.0, 0.0, 0.0, 0.0],[1,0,0,0,0,0],[1.0,1.0,1.0,0.0,0.0,0.0]],    #1  A  A  A  0  0  0
1401        [[1,1,2,0,0,0],[ 1.0, 1.0, 1.0, 0.0, 0.0, 0.0],[1,0,1,0,0,0],[1.0,1.0,1.0,0.0,0.0,0.0]],    #2  A  A  C  0  0  0
1402        [[1,2,1,0,0,0],[ 1.0, 1.0, 1.0, 0.0, 0.0, 0.0],[1,1,0,0,0,0],[1.0,1.0,1.0,0.0,0.0,0.0]],    #3  A  B  A  0  0  0
1403        [[1,2,2,0,0,0],[ 1.0, 1.0, 1.0, 0.0, 0.0, 0.0],[1,1,0,0,0,0],[1.0,1.0,1.0,0.0,0.0,0.0]],    #4  A  B  B  0  0  0
1404        [[1,1,1,2,2,2],[ 1.0, 1.0, 1.0, 1.0, 1.0, 1.0],[1,0,0,1,0,0],[1.0,1.0,1.0,0.0,0.0,0.0]],    #5  A  A  A  D  D  D
1405        [[1,1,1,2,2,2],[ 1.0, 1.0, 1.0, 1.0,-1.0,-1.0],[1,0,0,1,0,0],[1.0,1.0,1.0,0.0,0.0,0.0]],    #6  A  A  A  D -D -D
1406        [[1,1,1,2,2,2],[ 1.0, 1.0, 1.0, 1.0,-1.0, 1.0],[1,0,0,1,0,0],[1.0,1.0,1.0,0.0,0.0,0.0]],    #7  A  A  A  D -D  D
1407        [[1,1,1,2,2,2],[ 1.0, 1.0, 1.0, 1.0, 1.0,-1.0],[1,0,0,1,0,0],[1.0,1.0,1.0,0.0,0.0,0.0]],    #8  A  A  A  D  D -D
1408        [[1,1,2,1,0,0],[ 1.0, 1.0, 1.0, 0.5, 0.0, 0.0],[1,0,1,0,0,0],[1.0,1.0,1.0,0.5,0.0,0.0]],    #9  A  A  C A/2 0  0
1409        [[1,2,3,0,0,0],[ 1.0, 1.0, 1.0, 0.0, 0.0, 0.0],[1,1,1,0,0,0],[1.0,1.0,1.0,0.0,0.0,0.0]],    #10  A  B  C  0  0  0
1410        [[1,1,2,3,0,0],[ 1.0, 1.0, 1.0, 1.0, 0.0, 0.0],[1,0,1,1,0,0],[1.0,1.0,1.0,0.0,0.0,0.0]],    #11  A  A  C  D  0  0
1411        [[1,2,1,0,3,0],[ 1.0, 1.0, 1.0, 0.0, 1.0, 0.0],[1,1,0,0,1,0],[1.0,1.0,1.0,0.0,0.0,0.0]],    #12  A  B  A  0  E  0
1412        [[1,2,2,0,0,3],[ 1.0, 1.0, 1.0, 0.0, 0.0, 1.0],[1,1,0,0,0,1],[1.0,1.0,1.0,0.0,0.0,0.0]],    #13  A  B  B  0  0  F
1413        [[1,2,3,2,0,0],[ 1.0, 1.0, 1.0, 0.5, 0.0, 0.0],[1,1,1,0,0,0],[1.0,1.0,1.0,0.0,0.5,0.0]],    #14  A  B  C B/2 0  0
1414        [[1,2,3,1,0,0],[ 1.0, 1.0, 1.0, 0.5, 0.0, 0.0],[1,1,1,0,0,0],[1.0,1.0,1.0,0.0,0.5,0.0]],    #15  A  B  C A/2 0  0
1415        [[1,2,3,4,0,0],[ 1.0, 1.0, 1.0, 1.0, 0.0, 0.0],[1,1,1,1,0,0],[1.0,1.0,1.0,0.0,0.0,0.0]],    #16  A  B  C  D  0  0
1416        [[1,2,3,0,4,0],[ 1.0, 1.0, 1.0, 0.0, 1.0, 0.0],[1,1,1,0,1,0],[1.0,1.0,1.0,0.0,0.0,0.0]],    #17  A  B  C  0  E  0
1417        [[1,2,3,0,0,4],[ 1.0, 1.0, 1.0, 0.0, 0.0, 1.0],[1,1,1,0,0,1],[1.0,1.0,1.0,0.0,0.0,0.0]],    #18  A  B  C  0  0  F
1418        [[1,1,2,3,4,4],[ 1.0, 1.0, 1.0, 1.0, 1.0,-1.0],[1,0,1,1,1,0],[1.0,1.0,1.0,0.0,0.0,0.0]],    #19  A  A  C  D  E -E
1419        [[1,1,2,3,4,4],[ 1.0, 1.0, 1.0, 1.0, 1.0, 1.0],[1,0,1,1,1,0],[1.0,1.0,1.0,0.0,0.0,0.0]],    #20  A  A  C  D  E  E
1420        [[1,2,1,3,4,3],[ 1.0, 1.0, 1.0, 1.0, 1.0,-1.0],[1,1,0,1,1,0],[1.0,1.0,1.0,0.0,0.0,0.0]],    #21  A  B  A  D  E -D
1421        [[1,2,1,3,4,3],[ 1.0, 1.0, 1.0, 1.0, 1.0, 1.0],[1,1,0,1,1,0],[1.0,1.0,1.0,0.0,0.0,0.0]],    #22  A  B  A  D  E  D
1422        [[1,2,2,3,3,4],[ 1.0, 1.0, 1.0, 1.0,-1.0, 1.0],[1,1,0,1,0,1],[1.0,1.0,1.0,0.0,0.0,0.0]],    #23  A  B  B  D -D  F
1423        [[1,2,2,3,3,4],[ 1.0, 1.0, 1.0, 1.0, 1.0, 1.0],[1,1,0,1,0,1],[1.0,1.0,1.0,0.0,0.0,0.0]],    #24  A  B  B  D  D  F
1424        [[1,2,3,2,4,4],[ 1.0, 1.0, 1.0, 0.5, 0.5, 1.0],[1,1,1,0,0,1],[1.0,1.0,1.0,0.5,0.0,0.0]],    #25  A  B  C B/2 F/2 F
1425        [[1,2,3,1,0,4],[ 1.0, 1.0, 1.0, 0.5, 0.0, 1.0],[1,1,1,0,0,1],[1.0,1.0,1.0,0.5,0.0,0.0]],    #26  A  B  C A/2  0  F
1426        [[1,2,3,2,4,0],[ 1.0, 1.0, 1.0, 0.5, 1.0, 0.0],[1,1,1,0,1,0],[1.0,1.0,1.0,0.5,0.0,0.0]],    #27  A  B  C B/2  E  0
1427        [[1,2,3,1,4,4],[ 1.0, 1.0, 1.0, 0.5, 1.0, 0.5],[1,1,1,0,1,0],[1.0,1.0,1.0,0.5,0.0,0.0]],    #28  A  B  C A/2  E E/2
1428        [[1,2,3,4,5,6],[ 1.0, 1.0, 1.0, 1.0, 1.0, 1.0],[1,1,1,1,1,1],[1.0,1.0,1.0,0.0,0.0,0.0]],    #29  A  B  C  D  E   F
1429        ]
1430    indx = GetNXUPQsym(siteSym)
1431    return CSuinel[indx[1]]
1432   
1433def getTauT(tau,sop,ssop,XYZ):
1434    ssopinv = nl.inv(ssop[0])
1435    mst = ssopinv[3][:3]
1436    epsinv = ssopinv[3][3]
1437    sdet = nl.det(sop[0])
1438    ssdet = nl.det(ssop[0])
1439    dtau = mst*(XYZ-sop[1])-epsinv*ssop[1][3]
1440    dT = 1.0
1441    if np.any(dtau%.5):
1442        dT = np.tan(np.pi*np.sum(dtau%.5))
1443    tauT = np.inner(mst,XYZ-sop[1])+epsinv*(tau-ssop[1][3])
1444    return sdet,ssdet,dtau,dT,tauT
1445   
1446def OpsfromStringOps(A,SGData,SSGData):
1447    SGOps = SGData['SGOps']
1448    SSGOps = SSGData['SSGOps']
1449    Ax = A.split('+')
1450    Ax[0] = int(Ax[0])
1451    iC = 1
1452    if Ax[0] < 0:
1453        iC = -1
1454    Ax[0] = abs(Ax[0])
1455    nA = Ax[0]%100-1
1456    return SGOps[nA],SSGOps[nA],iC
1457   
1458def GetSSfxuinel(waveType,nH,XYZ,SGData,SSGData,debug=False):
1459   
1460    def orderParms(CSI):
1461        parms = [0,]
1462        for csi in CSI:
1463            for i in [0,1,2]:
1464                if csi[i] not in parms:
1465                    parms.append(csi[i])
1466        for csi in CSI:
1467            for i in [0,1,2]:
1468                csi[i] = parms.index(csi[i])
1469        return CSI
1470       
1471    def fracCrenel(tau,Toff,Twid):
1472        Tau = (tau-Toff[:,np.newaxis])%1.
1473        A = np.where(Tau<Twid[:,np.newaxis],1.,0.)
1474        return A
1475       
1476    def fracFourier(tau,nH,fsin,fcos):
1477        SA = np.sin(2.*nH*np.pi*tau)
1478        CB = np.cos(2.*nH*np.pi*tau)
1479        A = SA[np.newaxis,np.newaxis,:]*fsin[:,:,np.newaxis]
1480        B = CB[np.newaxis,np.newaxis,:]*fcos[:,:,np.newaxis]
1481        return A+B
1482       
1483    def posFourier(tau,nH,psin,pcos):
1484        SA = np.sin(2*nH*np.pi*tau)
1485        CB = np.cos(2*nH*np.pi*tau)
1486        A = SA[np.newaxis,np.newaxis,:]*psin[:,:,np.newaxis]
1487        B = CB[np.newaxis,np.newaxis,:]*pcos[:,:,np.newaxis]
1488        return A+B   
1489
1490    def posSawtooth(tau,Toff,slopes):
1491        Tau = (tau-Toff)%1.
1492        A = slopes[:,np.newaxis]*Tau
1493        return A
1494   
1495    def posZigZag(tau,Toff,slopes):
1496        Tau = (tau-Toff)%1.
1497        A = np.where(Tau <= 0.5,slopes[:,np.newaxis]*Tau,slopes[:,np.newaxis]*(1.-Tau))
1498        return A
1499       
1500    def DoFrac():
1501        delt2 = np.eye(2)*0.001
1502        FSC = np.ones(2,dtype='i')
1503        VFSC = np.ones(2)
1504        CSI = [np.zeros((2),dtype='i'),np.zeros(2)]
1505        if 'Crenel' in waveType:
1506            dF = np.zeros_like(tau)
1507        else:
1508            dF = fracFourier(tau,nH,delt2[:1],delt2[1:]).squeeze()
1509        dFT = np.zeros_like(dF)
1510        dFTP = []
1511        for i in SdIndx:
1512            sop = Sop[i]
1513            ssop = SSop[i]           
1514            sdet,ssdet,dtau,dT,tauT = getTauT(tau,sop,ssop,XYZ)
1515            fsc = np.ones(2,dtype='i')
1516            if 'Crenel' in waveType:
1517                dFT = np.zeros_like(tau)
1518                fsc = [1,1]
1519            else:   #Fourier
1520                dFT = fracFourier(tauT,nH,delt2[:1],delt2[1:]).squeeze()
1521                dFT = nl.det(sop[0])*dFT
1522                dFT = dFT[:,np.argsort(tauT)]
1523                dFT[0] *= ssdet
1524                dFT[1] *= sdet
1525                dFTP.append(dFT)
1526           
1527                if np.any(dtau%.5) and ('1/2' in SSGData['modSymb'] or '1' in SSGData['modSymb']):
1528                    fsc = [1,1]
1529                    CSI = [[[1,0],[1,0]],[[1.,0.],[1/dT,0.]]]
1530                    FSC = np.zeros(2,dtype='i')
1531                    return CSI,dF,dFTP
1532                else:
1533                    for i in range(2):
1534                        if np.allclose(dF[i,:],dFT[i,:],atol=1.e-6):
1535                            fsc[i] = 1
1536                        else:
1537                            fsc[i] = 0
1538                    FSC &= fsc
1539                    if debug: print SSMT2text(ssop).replace(' ',''),sdet,ssdet,epsinv,fsc
1540        n = -1
1541        for i,F in enumerate(FSC):
1542            if F:
1543                n += 1
1544                CSI[0][i] = n+1
1545                CSI[1][i] = 1.0
1546       
1547        return CSI,dF,dFTP
1548       
1549    def DoXYZ():
1550        delt4 = np.ones(4)*0.001
1551        delt6 = np.eye(6)*0.001
1552        if 'Fourier' in waveType:
1553            dX = posFourier(tau,nH,delt6[:3],delt6[3:]) #+np.array(XYZ)[:,np.newaxis,np.newaxis]
1554              #3x6x12 modulated position array (X,Spos,tau)& force positive
1555            CSI = [np.zeros((6,3),dtype='i'),np.zeros((6,3))]
1556        elif waveType == 'Sawtooth':
1557            dX = posSawtooth(tau,delt4[0],delt4[1:])
1558            CSI = [np.array([[1,0,0],[2,0,0],[3,0,0],[4,0,0]]),
1559                np.array([[1.0,.0,.0],[1.0,.0,.0],[1.0,.0,.0],[1.0,.0,.0]])]
1560        elif waveType == 'ZigZag':
1561            dX = posZigZag(tau,delt4[0],delt4[1:])
1562            CSI = [np.array([[1,0,0],[2,0,0],[3,0,0],[4,0,0]]),
1563                np.array([[1.0,.0,.0],[1.0,.0,.0],[1.0,.0,.0],[1.0,.0,.0]])]
1564        XSC = np.ones(6,dtype='i')
1565        dXTP = []
1566        for i in SdIndx:
1567            sop = Sop[i]
1568            ssop = SSop[i]
1569            sdet,ssdet,dtau,dT,tauT = getTauT(tau,sop,ssop,XYZ)
1570            xsc = np.ones(6,dtype='i')
1571            if 'Fourier' in waveType:
1572                dXT = posFourier(np.sort(tauT),nH,delt6[:3],delt6[3:])   #+np.array(XYZ)[:,np.newaxis,np.newaxis]
1573            elif waveType == 'Sawtooth':
1574                dXT = posSawtooth(tauT,delt4[0],delt4[1:])+np.array(XYZ)[:,np.newaxis,np.newaxis]
1575            elif waveType == 'ZigZag':
1576                dXT = posZigZag(tauT,delt4[0],delt4[1:])+np.array(XYZ)[:,np.newaxis,np.newaxis] 
1577            dXT = np.inner(sop[0],dXT.T)    # X modulations array(3x6x49) -> array(3x49x6)
1578            dXT = np.swapaxes(dXT,1,2)      # back to array(3x6x49)
1579            dXT[:,:3,:] *= (ssdet*sdet)            # modify the sin component
1580            dXTP.append(dXT)
1581            if waveType == 'Fourier':
1582                for i in range(3):
1583                    if not np.allclose(dX[i,i,:],dXT[i,i,:]):
1584                        xsc[i] = 0
1585                    if not np.allclose(dX[i,i+3,:],dXT[i,i+3,:]):
1586                        xsc[i+3] = 0
1587                if np.any(dtau%.5) and ('1/2' in SSGData['modSymb'] or '1' in SSGData['modSymb']):
1588                    xsc[3:6] = 0
1589                    CSI = [[[1,0,0],[2,0,0],[3,0,0], [1,0,0],[2,0,0],[3,0,0]],
1590                        [[1.,0.,0.],[1.,0.,0.],[1.,0.,0.], [1.,0.,0.],[1.,0.,0.],[1.,0.,0.]]]                   
1591                    if '(x)' in siteSym:
1592                        CSI[1][3:] = [1./dT,0.,0.],[-dT,0.,0.],[-dT,0.,0.]
1593                        if 'm' in siteSym and len(SdIndx) == 1:
1594                            CSI[1][3:] = [-dT,0.,0.],[1./dT,0.,0.],[1./dT,0.,0.]
1595                    elif '(y)' in siteSym:
1596                        CSI[1][3:] = [-dT,0.,0.],[1./dT,0.,0.],[-dT,0.,0.]
1597                        if 'm' in siteSym and len(SdIndx) == 1:
1598                            CSI[1][3:] = [1./dT,0.,0.],[-dT,0.,0.],[1./dT,0.,0.]
1599                    elif '(z)' in siteSym:
1600                        CSI[1][3:] = [-dT,0.,0.],[-dT,0.,0.],[1./dT,0.,0.]
1601                        if 'm' in siteSym and len(SdIndx) == 1:
1602                            CSI[1][3:] = [1./dT,0.,0.],[1./dT,0.,0.],[-dT,0.,0.]
1603                if '4/mmm' in laue:
1604                    if np.any(dtau%.5) and '1/2' in SSGData['modSymb']:
1605                        if '(xy)' in siteSym:
1606                            CSI[0] = [[1,0,0],[1,0,0],[2,0,0], [1,0,0],[1,0,0],[2,0,0]]
1607                            CSI[1][3:] = [[1./dT,0.,0.],[1./dT,0.,0.],[-dT,0.,0.]]
1608                    if '(xy)' in siteSym or '(+-0)' in siteSym:
1609                        mul = 1
1610                        if '(+-0)' in siteSym:
1611                            mul = -1
1612                        if np.allclose(dX[0,0,:],dXT[1,0,:]):
1613                            CSI[0][3:5] = [[11,0,0],[11,0,0]]
1614                            CSI[1][3:5] = [[1.,0,0],[mul,0,0]]
1615                            xsc[3:5] = 0
1616                        if np.allclose(dX[0,3,:],dXT[0,4,:]):
1617                            CSI[0][:2] = [[12,0,0],[12,0,0]]
1618                            CSI[1][:2] = [[1.,0,0],[mul,0,0]]
1619                            xsc[:2] = 0
1620            XSC &= xsc
1621            if debug: print SSMT2text(ssop).replace(' ',''),sdet,ssdet,epsinv,xsc
1622        if waveType == 'Fourier':
1623            n = -1
1624            if debug: print XSC
1625            for i,X in enumerate(XSC):
1626                if X:
1627                    n += 1
1628                    CSI[0][i][0] = n+1
1629                    CSI[1][i][0] = 1.0
1630       
1631        return CSI,dX,dXTP
1632       
1633    def DoUij():
1634        tau = np.linspace(0,1,49,True)
1635        delt12 = np.eye(12)*0.0001
1636        dU = posFourier(tau,nH,delt12[:6],delt12[6:])                  #Uij modulations - 6x12x12 array
1637        CSI = [np.zeros((12,3),dtype='i'),np.zeros((12,3))]
1638        USC = np.ones(12,dtype='i')
1639        dUTP = []
1640        for i in SdIndx:
1641            sop = Sop[i]
1642            ssop = SSop[i]
1643            sdet,ssdet,dtau,dT,tauT = getTauT(tau,sop,ssop,XYZ)
1644            usc = np.ones(12,dtype='i')
1645            dUT = posFourier(tauT,nH,delt12[:6],delt12[6:])                  #Uij modulations - 6x12x49 array
1646            dUijT = np.rollaxis(np.rollaxis(np.array(Uij2U(dUT)),3),3)    #convert dUT to 12x49x3x3
1647            dUijT = np.rollaxis(np.inner(np.inner(sop[0],dUijT),sop[0].T),3) #transform by sop - 3x3x12x49
1648            dUT = np.array(U2Uij(dUijT))    #convert to 6x12x49
1649            dUT = dUT[:,:,np.argsort(tauT)]
1650            dUT[:,:6,:] *=(ssdet*sdet)
1651            dUTP.append(dUT)
1652            if np.any(dtau%.5) and ('1/2' in SSGData['modSymb'] or '1' in SSGData['modSymb']):
1653                CSI = [[[1,0,0],[2,0,0],[3,0,0],[4,0,0],[5,0,0],[6,0,0], 
1654                [1,0,0],[2,0,0],[3,0,0],[4,0,0],[5,0,0],[6,0,0]],
1655                [[1.,0.,0.],[1.,0.,0.],[1.,0.,0.], [1.,0.,0.],[1.,0.,0.],[1.,0.,0.],
1656                [1./dT,0.,0.],[1./dT,0.,0.],[1./dT,0.,0.], [1.,0.,0.],[1.,0.,0.],[1.,0.,0.]]]
1657                if 'mm2(x)' in siteSym:
1658                    CSI[1][9:] = [0.,0.,0.],[-dT,0.,0.],[0.,0.,0.]
1659                    USC = [1,1,1,0,1,0,1,1,1,0,1,0]
1660                elif '(xy)' in siteSym:
1661                    CSI[0] = [[1,0,0],[1,0,0],[2,0,0],[3,0,0],[4,0,0],[4,0,0],
1662                        [1,0,0],[1,0,0],[2,0,0],[3,0,0],[4,0,0],[4,0,0]]
1663                    CSI[1][9:] = [[1./dT,0.,0.],[-dT,0.,0.],[-dT,0.,0.]]
1664                    USC = [1,1,1,1,1,1,1,1,1,1,1,1]                             
1665                elif '(x)' in siteSym:
1666                    CSI[1][9:] = [-dT,0.,0.],[-dT,0.,0.],[1./dT,0.,0.]
1667                elif '(y)' in siteSym:
1668                    CSI[1][9:] = [-dT,0.,0.],[1./dT,0.,0.],[-dT,0.,0.]
1669                elif '(z)' in siteSym:
1670                    CSI[1][9:] = [1./dT,0.,0.],[-dT,0.,0.],[-dT,0.,0.]
1671                for i in range(6):
1672                    if not USC[i]:
1673                        CSI[0][i] = [0,0,0]
1674                        CSI[1][i] = [0.,0.,0.]
1675                        CSI[0][i+6] = [0,0,0]
1676                        CSI[1][i+6] = [0.,0.,0.]
1677            else:                       
1678                for i in range(6):
1679                    if not np.allclose(dU[i,i,:],dUT[i,i,:]):  #sin part
1680                        usc[i] = 0
1681                    if not np.allclose(dU[i,i+6,:],dUT[i,i+6,:]):   #cos part
1682                        usc[i+6] = 0
1683                if np.any(dUT[1,0,:]):
1684                    if '4/m' in siteSym:
1685                        CSI[0][6:8] = [[12,0,0],[12,0,0]]
1686                        if ssop[1][3]:
1687                            CSI[1][6:8] = [[1.,0.,0.],[-1.,0.,0.]]
1688                            usc[9] = 1
1689                        else:
1690                            CSI[1][6:8] = [[1.,0.,0.],[1.,0.,0.]]
1691                            usc[9] = 0
1692                    elif '4' in siteSym:
1693                        CSI[0][6:8] = [[12,0,0],[12,0,0]]
1694                        CSI[0][:2] = [[11,0,0],[11,0,0]]
1695                        if ssop[1][3]:
1696                            CSI[1][:2] = [[1.,0.,0.],[-1.,0.,0.]]
1697                            CSI[1][6:8] = [[1.,0.,0.],[-1.,0.,0.]]
1698                            usc[2] = 0
1699                            usc[8] = 0
1700                            usc[3] = 1
1701                            usc[9] = 1
1702                        else:
1703                            CSI[1][:2] = [[1.,0.,0.],[1.,0.,0.]]
1704                            CSI[1][6:8] = [[1.,0.,0.],[1.,0.,0.]]
1705                            usc[2] = 1
1706                            usc[8] = 1
1707                            usc[3] = 0               
1708                            usc[9] = 0
1709                    elif 'xy' in siteSym or '+-0' in siteSym:
1710                        if np.allclose(dU[0,0,:],dUT[0,1,:]*sdet):
1711                            CSI[0][4:6] = [[12,0,0],[12,0,0]]
1712                            CSI[0][6:8] = [[11,0,0],[11,0,0]]
1713                            CSI[1][4:6] = [[1.,0.,0.],[sdet,0.,0.]]
1714                            CSI[1][6:8] = [[1.,0.,0.],[sdet,0.,0.]]
1715                            usc[4:6] = 0
1716                            usc[6:8] = 0
1717                       
1718                if debug: print SSMT2text(ssop).replace(' ',''),sdet,ssdet,epsinv,usc
1719            USC &= usc
1720        if debug: print USC
1721        if not np.any(dtau%.5):
1722            n = -1
1723            for i,U in enumerate(USC):
1724                if U:
1725                    n += 1
1726                    CSI[0][i][0] = n+1
1727                    CSI[1][i][0] = 1.0
1728
1729        return CSI,dU,dUTP
1730       
1731    if debug: print 'super space group: ',SSGData['SSpGrp']
1732    CSI = {'Sfrac':[[[1,0],[2,0]],[[1.,0.],[1.,0.]]],
1733        'Spos':[[[1,0,0],[2,0,0],[3,0,0], [4,0,0],[5,0,0],[6,0,0]],
1734            [[1.,0.,0.],[1.,0.,0.],[1.,0.,0.], [1.,0.,0.],[1.,0.,0.],[1.,0.,0.]]],    #sin & cos
1735        'Sadp':[[[1,0,0],[2,0,0],[3,0,0],[4,0,0],[5,0,0],[6,0,0], 
1736            [7,0,0],[8,0,0],[9,0,0],[10,0,0],[11,0,0],[12,0,0]],
1737            [[1.,0.,0.],[1.,0.,0.],[1.,0.,0.], [1.,0.,0.],[1.,0.,0.],[1.,0.,0.],
1738            [1.,0.,0.],[1.,0.,0.],[1.,0.,0.], [1.,0.,0.],[1.,0.,0.],[1.,0.,0.]]],
1739        'Smag':[[[1,0,0],[2,0,0],[3,0,0], [4,0,0],[5,0,0],[6,0,0]],
1740            [[1.,0.,0.],[1.,0.,0.],[1.,0.,0.], [1.,0.,0.],[1.,0.,0.],[1.,0.,0.]]],}
1741    xyz = np.array(XYZ)%1.
1742    xyzt = np.array(XYZ+[0,])%1.
1743    SGOps = copy.deepcopy(SGData['SGOps'])
1744    laue = SGData['SGLaue']
1745    siteSym = SytSym(XYZ,SGData)[0].strip()
1746    if debug: print 'siteSym: ',siteSym
1747    if siteSym == '1':   #"1" site symmetry
1748        if debug:
1749            return CSI,None,None,None,None
1750        else:
1751            return CSI
1752    elif siteSym == '-1':   #"-1" site symmetry
1753        CSI['Sfrac'][0] = [[1,0],[0,0]]
1754        CSI['Spos'][0] = [[1,0,0],[2,0,0],[3,0,0], [0,0,0],[0,0,0],[0,0,0]]
1755        CSI['Sadp'][0] = [[0,0,0],[0,0,0],[0,0,0],[0,0,0],[0,0,0],[0,0,0], 
1756        [1,0,0],[2,0,0],[3,0,0],[4,0,0],[5,0,0],[6,0,0]]
1757        if debug:
1758            return CSI,None,None,None,None
1759        else:
1760            return CSI
1761    SSGOps = copy.deepcopy(SSGData['SSGOps'])
1762    #expand ops to include inversions if any
1763    if SGData['SGInv']:
1764        for op,sop in zip(SGData['SGOps'],SSGData['SSGOps']):
1765            SGOps.append([-op[0],-op[1]%1.])
1766            SSGOps.append([-sop[0],-sop[1]%1.])
1767    #build set of sym ops around special position       
1768    SSop = []
1769    Sop = []
1770    Sdtau = []
1771    for iop,Op in enumerate(SGOps):         
1772        nxyz = (np.inner(Op[0],xyz)+Op[1])%1.
1773        if np.allclose(xyz,nxyz,1.e-4) and iop and MT2text(Op).replace(' ','') != '-X,-Y,-Z':
1774            SSop.append(SSGOps[iop])
1775            Sop.append(SGOps[iop])
1776            ssopinv = nl.inv(SSGOps[iop][0])
1777            mst = ssopinv[3][:3]
1778            epsinv = ssopinv[3][3]
1779            Sdtau.append(np.sum(mst*(XYZ-SGOps[iop][1])-epsinv*SSGOps[iop][1][3]))
1780    SdIndx = np.argsort(np.array(Sdtau))     # just to do in sensible order
1781    if debug: print 'special pos super operators: ',[SSMT2text(ss).replace(' ','') for ss in SSop]
1782    #setup displacement arrays
1783    tau = np.linspace(-1,1,49,True)
1784    #make modulation arrays - one parameter at a time
1785    #site fractions
1786    CSI['Sfrac'],dF,dFTP = DoFrac()
1787    #positions
1788    CSI['Spos'],dX,dXTP = DoXYZ()       
1789    #anisotropic thermal motion
1790    CSI['Sadp'],dU,dUTP = DoUij()
1791    CSI['Spos'][0] = orderParms(CSI['Spos'][0])
1792    CSI['Sadp'][0] = orderParms(CSI['Sadp'][0])           
1793    if debug:
1794        return CSI,tau,[dF,dFTP],[dX,dXTP],[dU,dUTP]
1795    else:
1796        return CSI
1797   
1798def MustrainNames(SGData):
1799    'Needs a doc string'
1800    laue = SGData['SGLaue']
1801    uniq = SGData['SGUniq']
1802    if laue in ['m3','m3m']:
1803        return ['S400','S220']
1804    elif laue in ['6/m','6/mmm','3m1']:
1805        return ['S400','S004','S202']
1806    elif laue in ['31m','3']:
1807        return ['S400','S004','S202','S211']
1808    elif laue in ['3R','3mR']:
1809        return ['S400','S220','S310','S211']
1810    elif laue in ['4/m','4/mmm']:
1811        return ['S400','S004','S220','S022']
1812    elif laue in ['mmm']:
1813        return ['S400','S040','S004','S220','S202','S022']
1814    elif laue in ['2/m']:
1815        SHKL = ['S400','S040','S004','S220','S202','S022']
1816        if uniq == 'a':
1817            SHKL += ['S013','S031','S211']
1818        elif uniq == 'b':
1819            SHKL += ['S301','S103','S121']
1820        elif uniq == 'c':
1821            SHKL += ['S130','S310','S112']
1822        return SHKL
1823    else:
1824        SHKL = ['S400','S040','S004','S220','S202','S022']
1825        SHKL += ['S310','S103','S031','S130','S301','S013']
1826        SHKL += ['S211','S121','S112']
1827        return SHKL
1828       
1829def HStrainVals(HSvals,SGData):
1830    laue = SGData['SGLaue']
1831    uniq = SGData['SGUniq']
1832    DIJ = np.zeros(6)
1833    if laue in ['m3','m3m']:
1834        DIJ[:3] = [HSvals[0],HSvals[0],HSvals[0]]
1835    elif laue in ['6/m','6/mmm','3m1','31m','3']:
1836        DIJ[:4] = [HSvals[0],HSvals[0],HSvals[1],HSvals[0]]
1837    elif laue in ['3R','3mR']:
1838        DIJ = [HSvals[0],HSvals[0],HSvals[0],HSvals[1],HSvals[1],HSvals[1]]
1839    elif laue in ['4/m','4/mmm']:
1840        DIJ[:3] = [HSvals[0],HSvals[0],HSvals[1]]
1841    elif laue in ['mmm']:
1842        DIJ[:3] = [HSvals[0],HSvals[1],HSvals[2]]
1843    elif laue in ['2/m']:
1844        DIJ[:3] = [HSvals[0],HSvals[1],HSvals[2]]
1845        if uniq == 'a':
1846            DIJ[5] = HSvals[3]
1847        elif uniq == 'b':
1848            DIJ[4] = HSvals[3]
1849        elif uniq == 'c':
1850            DIJ[3] = HSvals[3]
1851    else:
1852        DIJ = [HSvals[0],HSvals[1],HSvals[2],HSvals[3],HSvals[4],HSvals[5]]
1853    return DIJ
1854
1855def HStrainNames(SGData):
1856    'Needs a doc string'
1857    laue = SGData['SGLaue']
1858    uniq = SGData['SGUniq']
1859    if laue in ['m3','m3m']:
1860        return ['D11','eA']         #add cubic strain term
1861    elif laue in ['6/m','6/mmm','3m1','31m','3']:
1862        return ['D11','D33']
1863    elif laue in ['3R','3mR']:
1864        return ['D11','D12']
1865    elif laue in ['4/m','4/mmm']:
1866        return ['D11','D33']
1867    elif laue in ['mmm']:
1868        return ['D11','D22','D33']
1869    elif laue in ['2/m']:
1870        Dij = ['D11','D22','D33']
1871        if uniq == 'a':
1872            Dij += ['D23']
1873        elif uniq == 'b':
1874            Dij += ['D13']
1875        elif uniq == 'c':
1876            Dij += ['D12']
1877        return Dij
1878    else:
1879        Dij = ['D11','D22','D33','D12','D13','D23']
1880        return Dij
1881   
1882def MustrainCoeff(HKL,SGData):
1883    'Needs a doc string'
1884    #NB: order of terms is the same as returned by MustrainNames
1885    laue = SGData['SGLaue']
1886    uniq = SGData['SGUniq']
1887    h,k,l = HKL
1888    Strm = []
1889    if laue in ['m3','m3m']:
1890        Strm.append(h**4+k**4+l**4)
1891        Strm.append(3.0*((h*k)**2+(h*l)**2+(k*l)**2))
1892    elif laue in ['6/m','6/mmm','3m1']:
1893        Strm.append(h**4+k**4+2.0*k*h**3+2.0*h*k**3+3.0*(h*k)**2)
1894        Strm.append(l**4)
1895        Strm.append(3.0*((h*l)**2+(k*l)**2+h*k*l**2))
1896    elif laue in ['31m','3']:
1897        Strm.append(h**4+k**4+2.0*k*h**3+2.0*h*k**3+3.0*(h*k)**2)
1898        Strm.append(l**4)
1899        Strm.append(3.0*((h*l)**2+(k*l)**2+h*k*l**2))
1900        Strm.append(4.0*h*k*l*(h+k))
1901    elif laue in ['3R','3mR']:
1902        Strm.append(h**4+k**4+l**4)
1903        Strm.append(3.0*((h*k)**2+(h*l)**2+(k*l)**2))
1904        Strm.append(2.0*(h*l**3+l*k**3+k*h**3)+2.0*(l*h**3+k*l**3+l*k**3))
1905        Strm.append(4.0*(k*l*h**2+h*l*k**2+h*k*l**2))
1906    elif laue in ['4/m','4/mmm']:
1907        Strm.append(h**4+k**4)
1908        Strm.append(l**4)
1909        Strm.append(3.0*(h*k)**2)
1910        Strm.append(3.0*((h*l)**2+(k*l)**2))
1911    elif laue in ['mmm']:
1912        Strm.append(h**4)
1913        Strm.append(k**4)
1914        Strm.append(l**4)
1915        Strm.append(3.0*(h*k)**2)
1916        Strm.append(3.0*(h*l)**2)
1917        Strm.append(3.0*(k*l)**2)
1918    elif laue in ['2/m']:
1919        Strm.append(h**4)
1920        Strm.append(k**4)
1921        Strm.append(l**4)
1922        Strm.append(3.0*(h*k)**2)
1923        Strm.append(3.0*(h*l)**2)
1924        Strm.append(3.0*(k*l)**2)
1925        if uniq == 'a':
1926            Strm.append(2.0*k*l**3)
1927            Strm.append(2.0*l*k**3)
1928            Strm.append(4.0*k*l*h**2)
1929        elif uniq == 'b':
1930            Strm.append(2.0*l*h**3)
1931            Strm.append(2.0*h*l**3)
1932            Strm.append(4.0*h*l*k**2)
1933        elif uniq == 'c':
1934            Strm.append(2.0*h*k**3)
1935            Strm.append(2.0*k*h**3)
1936            Strm.append(4.0*h*k*l**2)
1937    else:
1938        Strm.append(h**4)
1939        Strm.append(k**4)
1940        Strm.append(l**4)
1941        Strm.append(3.0*(h*k)**2)
1942        Strm.append(3.0*(h*l)**2)
1943        Strm.append(3.0*(k*l)**2)
1944        Strm.append(2.0*k*h**3)
1945        Strm.append(2.0*h*l**3)
1946        Strm.append(2.0*l*k**3)
1947        Strm.append(2.0*h*k**3)
1948        Strm.append(2.0*l*h**3)
1949        Strm.append(2.0*k*l**3)
1950        Strm.append(4.0*k*l*h**2)
1951        Strm.append(4.0*h*l*k**2)
1952        Strm.append(4.0*k*h*l**2)
1953    return Strm
1954   
1955def Muiso2Shkl(muiso,SGData,cell):
1956    "this is to convert isotropic mustrain to generalized Shkls"
1957    import GSASIIlattice as G2lat
1958    A = G2lat.cell2AB(cell)[0]
1959   
1960    def minMus(Shkl,muiso,H,SGData,A):
1961        U = np.inner(A.T,H)
1962        S = np.array(MustrainCoeff(U,SGData))
1963        Sum = np.sqrt(np.sum(np.multiply(S,Shkl[:,np.newaxis]),axis=0))
1964        rad = np.sqrt(np.sum((Sum[:,np.newaxis]*H)**2,axis=1))
1965        return (muiso-rad)**2
1966       
1967    laue = SGData['SGLaue']
1968    PHI = np.linspace(0.,360.,60,True)
1969    PSI = np.linspace(0.,180.,60,True)
1970    X = np.outer(npsind(PHI),npsind(PSI))
1971    Y = np.outer(npcosd(PHI),npsind(PSI))
1972    Z = np.outer(np.ones(np.size(PHI)),npcosd(PSI))
1973    HKL = np.dstack((X,Y,Z))
1974    if laue in ['m3','m3m']:
1975        S0 = [1000.,1000.]
1976    elif laue in ['6/m','6/mmm','3m1']:
1977        S0 = [1000.,1000.,1000.]
1978    elif laue in ['31m','3']:
1979        S0 = [1000.,1000.,1000.,1000.]
1980    elif laue in ['3R','3mR']:
1981        S0 = [1000.,1000.,1000.,1000.]
1982    elif laue in ['4/m','4/mmm']:
1983        S0 = [1000.,1000.,1000.,1000.]
1984    elif laue in ['mmm']:
1985        S0 = [1000.,1000.,1000.,1000.,1000.,1000.]
1986    elif laue in ['2/m']:
1987        S0 = [1000.,1000.,1000.,0.,0.,0.,0.,0.,0.]
1988    else:
1989        S0 = [1000.,1000.,1000.,1000.,1000., 1000.,1000.,1000.,1000.,1000., 
1990            1000.,1000.,0.,0.,0.]
1991    S0 = np.array(S0)
1992    HKL = np.reshape(HKL,(-1,3))
1993    result = so.leastsq(minMus,S0,(np.ones(HKL.shape[0])*muiso,HKL,SGData,A))
1994    return result[0]
1995       
1996def SytSym(XYZ,SGData):
1997    '''
1998    Generates the number of equivalent positions and a site symmetry code for a specified coordinate and space group
1999
2000    :param XYZ: an array, tuple or list containing 3 elements: x, y & z
2001    :param SGData: from SpcGroup
2002    :Returns: a two element tuple:
2003
2004     * The 1st element is a code for the site symmetry (see GetKNsym)
2005     * The 2nd element is the site multiplicity
2006
2007    '''
2008    def PackRot(SGOps):
2009        IRT = []
2010        for ops in SGOps:
2011            M = ops[0]
2012            irt = 0
2013            for j in range(2,-1,-1):
2014                for k in range(2,-1,-1):
2015                    irt *= 3
2016                    irt += M[k][j]
2017            IRT.append(int(irt))
2018        return IRT
2019       
2020    SymName = ''
2021    Mult = 1
2022    Isym = 0
2023    if SGData['SGLaue'] in ['3','3m1','31m','6/m','6/mmm']:
2024        Isym = 1073741824
2025    Jdup = 0
2026    Xeqv = GenAtom(XYZ,SGData,True)
2027    IRT = PackRot(SGData['SGOps'])
2028    L = -1
2029    for ic,cen in enumerate(SGData['SGCen']):
2030        for invers in range(int(SGData['SGInv']+1)):
2031            for io,ops in enumerate(SGData['SGOps']):
2032                irtx = (1-2*invers)*IRT[io]
2033                L += 1
2034                if not Xeqv[L][1]:
2035                    Jdup += 1
2036                    jx = GetOprPtrName(str(irtx))
2037                    if jx[2] < 39:
2038                        Isym += 2**(jx[2]-1)
2039    if Isym == 1073741824: Isym = 0
2040    Mult = len(SGData['SGOps'])*len(SGData['SGCen'])*(int(SGData['SGInv'])+1)/Jdup
2041         
2042    return GetKNsym(str(Isym)),Mult
2043   
2044def ElemPosition(SGData):
2045    ''' Under development.
2046    Object here is to return a list of symmetry element types and locations suitable
2047    for say drawing them.
2048    So far I have the element type... getting all possible locations without lookup may be impossible!
2049    '''
2050    SymElements = []
2051    Inv = SGData['SGInv']
2052    Cen = SGData['SGCen']
2053    eleSym = {-3:['','-1'],-2:['',-6],-1:['2','-4'],0:['3','-3'],1:['4','m'],2:['6',''],3:['1','']}
2054    # get operators & expand if centrosymmetric
2055    Ops = SGData['SGOps']
2056    opM = np.array([op[0].T for op in Ops])
2057    opT = np.array([op[1] for op in Ops])
2058    if Inv:
2059        opM = np.concatenate((opM,-opM))
2060        opT = np.concatenate((opT,-opT))
2061    opMT = zip(opM,opT)
2062    for M,T in opMT[1:]:        #skip I
2063        Dt = int(nl.det(M))
2064        Tr = int(np.trace(M))
2065        Dt = -(Dt-1)/2
2066        Es = eleSym[Tr][Dt]
2067        if Dt:              #rotation-inversion
2068            I = np.eye(3)
2069            if Tr == 1:     #mirrors/glides
2070                if np.any(T):       #glide
2071                    M2 = np.inner(M,M)
2072                    MT = np.inner(M,T)+T
2073                    print 'glide',Es,MT
2074                    print M2
2075                else:               #mirror
2076                    print 'mirror',Es,T
2077                    print I-M
2078                X = [-1,-1,-1]
2079            elif Tr == -3:  # pure inversion
2080                X = np.inner(nl.inv(I-M),T)
2081                print 'inversion',Es,X
2082            else:           #other rotation-inversion
2083                M2 = np.inner(M,M)
2084                MT = np.inner(M,T)+T
2085                print 'rot-inv',Es,MT
2086                print M2
2087                X = [-1,-1,-1]
2088        else:               #rotations
2089            print 'rotation',Es
2090            X = [-1,-1,-1]
2091        #SymElements.append([Es,X])
2092       
2093    return #SymElements
2094   
2095def ApplyStringOps(A,SGData,X,Uij=[]):
2096    'Needs a doc string'
2097    SGOps = SGData['SGOps']
2098    SGCen = SGData['SGCen']
2099    Ax = A.split('+')
2100    Ax[0] = int(Ax[0])
2101    iC = 0
2102    if Ax[0] < 0:
2103        iC = 1
2104    Ax[0] = abs(Ax[0])
2105    nA = Ax[0]%100-1
2106    cA = Ax[0]/100
2107    Cen = SGCen[cA]
2108    M,T = SGOps[nA]
2109    if len(Ax)>1:
2110        cellA = Ax[1].split(',')
2111        cellA = np.array([int(a) for a in cellA])
2112    else:
2113        cellA = np.zeros(3)
2114    newX = Cen+(1-2*iC)*(np.inner(M,X).T+T)+cellA
2115    if len(Uij):
2116        U = Uij2U(Uij)
2117        U = np.inner(M,np.inner(U,M).T)
2118        newUij = U2Uij(U)
2119        return [newX,newUij]
2120    else:
2121        return newX
2122       
2123def StringOpsProd(A,B,SGData):
2124    """
2125    Find A*B where A & B are in strings '-' + '100*c+n' + '+ijk'
2126    where '-' indicates inversion, c(>0) is the cell centering operator,
2127    n is operator number from SgOps and ijk are unit cell translations (each may be <0).
2128    Should return resultant string - C. SGData - dictionary using entries:
2129
2130       *  'SGCen': cell centering vectors [0,0,0] at least
2131       *  'SGOps': symmetry operations as [M,T] so that M*x+T = x'
2132
2133    """
2134    SGOps = SGData['SGOps']
2135    SGCen = SGData['SGCen']
2136    #1st split out the cell translation part & work on the operator parts
2137    Ax = A.split('+'); Bx = B.split('+')
2138    Ax[0] = int(Ax[0]); Bx[0] = int(Bx[0])
2139    iC = 0
2140    if Ax[0]*Bx[0] < 0:
2141        iC = 1
2142    Ax[0] = abs(Ax[0]); Bx[0] = abs(Bx[0])
2143    nA = Ax[0]%100-1;  nB = Bx[0]%100-1
2144    cA = Ax[0]/100;  cB = Bx[0]/100
2145    Cen = (SGCen[cA]+SGCen[cB])%1.0
2146    cC = np.nonzero([np.allclose(C,Cen) for C in SGCen])[0][0]
2147    Ma,Ta = SGOps[nA]; Mb,Tb = SGOps[nB]
2148    Mc = np.inner(Ma,Mb.T)
2149#    print Ma,Mb,Mc
2150    Tc = (np.add(np.inner(Mb,Ta)+1.,Tb))%1.0
2151#    print Ta,Tb,Tc
2152#    print [np.allclose(M,Mc)&np.allclose(T,Tc) for M,T in SGOps]
2153    nC = np.nonzero([np.allclose(M,Mc)&np.allclose(T,Tc) for M,T in SGOps])[0][0]
2154    #now the cell translation part
2155    if len(Ax)>1:
2156        cellA = Ax[1].split(',')
2157        cellA = [int(a) for a in cellA]
2158    else:
2159        cellA = [0,0,0]
2160    if len(Bx)>1:
2161        cellB = Bx[1].split(',')
2162        cellB = [int(b) for b in cellB]
2163    else:
2164        cellB = [0,0,0]
2165    cellC = np.add(cellA,cellB)
2166    C = str(((nC+1)+(100*cC))*(1-2*iC))+'+'+ \
2167        str(int(cellC[0]))+','+str(int(cellC[1]))+','+str(int(cellC[2]))
2168    return C
2169           
2170def U2Uij(U):
2171    #returns the UIJ vector U11,U22,U33,U12,U13,U23 from tensor U
2172    return [U[0][0],U[1][1],U[2][2],U[0][1],U[0][2],U[1][2]]
2173   
2174def Uij2U(Uij):
2175    #returns the thermal motion tensor U from Uij as numpy array
2176    return np.array([[Uij[0],Uij[3],Uij[4]],[Uij[3],Uij[1],Uij[5]],[Uij[4],Uij[5],Uij[2]]])
2177
2178def StandardizeSpcName(spcgroup):
2179    '''Accept a spacegroup name where spaces may have not been used
2180    in the names according to the GSAS convention (spaces between symmetry
2181    for each axis) and return the space group name as used in GSAS
2182    '''
2183    rspc = spcgroup.replace(' ','').upper()
2184    # deal with rhombohedral and hexagonal setting designations
2185    rhomb = ''
2186    if rspc[-1:] == 'R':
2187        rspc = rspc[:-1]
2188        rhomb = ' R'
2189    elif rspc[-1:] == 'H': # hexagonal is assumed and thus can be ignored
2190        rspc = rspc[:-1]
2191    # look for a match in the spacegroup lists
2192    for i in spglist.values():
2193        for spc in i:
2194            if rspc == spc.replace(' ','').upper():
2195                return spc + rhomb
2196    # how about the post-2002 orthorhombic names?
2197    for i,spc in sgequiv_2002_orthorhombic:
2198        if rspc == i.replace(' ','').upper():
2199            return spc
2200    # not found
2201    return ''
2202
2203   
2204spglist = {}
2205'''A dictionary of space groups as ordered and named in the pre-2002 International
2206Tables Volume A, except that spaces are used following the GSAS convention to
2207separate the different crystallographic directions.
2208Note that the symmetry codes here will recognize many non-standard space group
2209symbols with different settings. They are ordered by Laue group
2210'''
2211spglist = {
2212    'P1' : ('P 1','P -1',), # 1-2
2213    'P2/m': ('P 2','P 21','P m','P a','P c','P n',
2214        'P 2/m','P 21/m','P 2/c','P 2/a','P 2/n','P 21/c','P 21/a','P 21/n',), #3-15
2215    'C2/m':('C 2','C m','C c','C n',
2216        'C 2/m','C 2/c','C 2/n',),
2217    'Pmmm':('P 2 2 2',
2218        'P 2 2 21','P 21 2 2','P 2 21 2',
2219        'P 21 21 2','P 2 21 21','P 21 2 21',
2220        'P 21 21 21',
2221        'P m m 2','P 2 m m','P m 2 m',
2222        'P m c 21','P 21 m a','P b 21 m','P m 21 b','P c m 21','P 21 a m',
2223        'P c c 2','P 2 a a','P b 2 b',
2224        'P m a 2','P 2 m b','P c 2 m','P m 2 a','P b m 2','P 2 c m',
2225        'P c a 21','P 21 a b','P c 21 b','P b 21 a','P b c 21','P 21 c a',
2226        'P n c 2','P 2 n a','P b 2 n','P n 2 b','P c n 2','P 2 a n',
2227        'P m n 21','P 21 m n','P n 21 m','P m 21 n','P n m 21','P 21 n m',
2228        'P b a 2','P 2 c b','P c 2 a',
2229        'P n a 21','P 21 n b','P c 21 n','P n 21 a','P b n 21','P 21 c n',
2230        'P n n 2','P 2 n n','P n 2 n',
2231        'P m m m','P n n n',
2232        'P c c m','P m a a','P b m b',
2233        'P b a n','P n c b','P c n a',
2234        'P m m a','P b m m','P m c m','P m a m','P m m b','P c m m',
2235        'P n n a','P b n n','P n c n','P n a n','P n n b','P c n n',
2236        'P m n a','P b m n','P n c m','P m a n','P n m b','P c n m',
2237        'P c c a','P b a a','P b c b','P b a b','P c c b','P c a a',
2238        'P b a m','P m c b','P c m a',
2239        'P c c n','P n a a','P b n b',
2240        'P b c m','P m c a','P b m a','P c m b','P c a m','P m a b',
2241        'P n n m','P m n n','P n m n',
2242        'P m m n','P n m m','P m n m',
2243        'P b c n','P n c a','P b n a','P c n b','P c a n','P n a b',
2244        'P b c a','P c a b',
2245        'P n m a','P b n m','P m c n','P n a m','P m n b','P c m n',
2246        ),
2247    'Cmmm':('C 2 2 21','C 2 2 2','C m m 2',
2248        'C m c 21','C c m 21','C c c 2','C m 2 m','C 2 m m',
2249        'C m 2 a','C 2 m b','C c 2 m','C 2 c m','C c 2 a','C 2 c b',
2250        'C m c m','C m c a','C c m b',
2251        'C m m m','C c c m','C m m a','C m m b','C c c a','C c c b',),
2252    'Immm':('I 2 2 2','I 21 21 21',
2253        'I m m 2','I m 2 m','I 2 m m',
2254        'I b a 2','I 2 c b','I c 2 a',
2255        'I m a 2','I 2 m b','I c 2 m','I m 2 a','I b m 2','I 2 c m',
2256        'I m m m','I b a m','I m c b','I c m a',
2257        'I b c a','I c a b',
2258        'I m m a','I b m m ','I m c m','I m a m','I m m b','I c m m',),
2259    'Fmmm':('F 2 2 2','F m m m', 'F d d d',
2260        'F m m 2','F m 2 m','F 2 m m',
2261        'F d d 2','F d 2 d','F 2 d d',),
2262    'P4/mmm':('P 4','P 41','P 42','P 43','P -4','P 4/m','P 42/m','P 4/n','P 42/n',
2263        'P 4 2 2','P 4 21 2','P 41 2 2','P 41 21 2','P 42 2 2',
2264        'P 42 21 2','P 43 2 2','P 43 21 2','P 4 m m','P 4 b m','P 42 c m',
2265        'P 42 n m','P 4 c c','P 4 n c','P 42 m c','P 42 b c','P -4 2 m',
2266        'P -4 2 c','P -4 21 m','P -4 21 c','P -4 m 2','P -4 c 2','P -4 b 2',
2267        'P -4 n 2','P 4/m m m','P 4/m c c','P 4/n b m','P 4/n n c','P 4/m b m',
2268        'P 4/m n c','P 4/n m m','P 4/n c c','P 42/m m c','P 42/m c m',
2269        'P 42/n b c','P 42/n n m','P 42/m b c','P 42/m n m','P 42/n m c',
2270        'P 42/n c m',),
2271    'I4/mmm':('I 4','I 41','I -4','I 4/m','I 41/a','I 4 2 2','I 41 2 2','I 4 m m',
2272        'I 4 c m','I 41 m d','I 41 c d',
2273        'I -4 m 2','I -4 c 2','I -4 2 m','I -4 2 d','I 4/m m m','I 4/m c m',
2274        'I 41/a m d','I 41/a c d'),
2275    'R3-H':('R 3','R -3','R 3 2','R 3 m','R 3 c','R -3 m','R -3 c',),
2276    'P6/mmm': ('P 3','P 31','P 32','P -3','P 3 1 2','P 3 2 1','P 31 1 2',
2277        'P 31 2 1','P 32 1 2','P 32 2 1', 'P 3 m 1','P 3 1 m','P 3 c 1',
2278        'P 3 1 c','P -3 1 m','P -3 1 c','P -3 m 1','P -3 c 1','P 6','P 61',
2279        'P 65','P 62','P 64','P 63','P -6','P 6/m','P 63/m','P 6 2 2',
2280        'P 61 2 2','P 65 2 2','P 62 2 2','P 64 2 2','P 63 2 2','P 6 m m',
2281        'P 6 c c','P 63 c m','P 63 m c','P -6 m 2','P -6 c 2','P -6 2 m',
2282        'P -6 2 c','P 6/m m m','P 6/m c c','P 63/m c m','P 63/m m c',),
2283    'Pm3m': ('P 2 3','P 21 3','P m 3','P n 3','P a 3','P 4 3 2','P 42 3 2',
2284        'P 43 3 2','P 41 3 2','P -4 3 m','P -4 3 n','P m 3 m','P n 3 n',
2285        'P m 3 n','P n 3 m',),
2286    'Im3m':('I 2 3','I 21 3','I m -3','I a -3', 'I 4 3 2','I 41 3 2',
2287        'I -4 3 m', 'I -4 3 d','I m -3 m','I m 3 m','I a -3 d',),
2288    'Fm3m':('F 2 3','F m -3','F d -3','F 4 3 2','F 41 3 2','F -4 3 m',
2289        'F -4 3 c','F m -3 m','F m 3 m','F m -3 c','F d -3 m','F d -3 c',),
2290}
2291
2292ssdict = {}
2293'''A dictionary of superspace group symbols allowed for each entry in spglist
2294(except cubics). Monoclinics are all b-unique setting.
2295'''
2296ssdict = {
2297#1,2
2298    'P 1':['(abg)',],'P -1':['(abg)',],
2299#monoclinic - done
2300#3
2301    'P 2':['(a0g)','(a1/2g)','(0b0)','(0b0)s','(1/2b0)','(0b1/2)',],
2302#4       
2303    'P 21':['(a0g)','(0b0)','(1/2b0)','(0b1/2)',],
2304#5
2305    'C 2':['(a0g)','(0b0)','(0b0)s','(0b1/2)',],
2306#6
2307    'P m':['(a0g)','(a0g)s','(a1/2g)','(0b0)','(1/2b0)','(0b1/2)',],
2308#7
2309    'P a':['(a0g)','(a1/2g)','(0b0)','(0b1/2)',],
2310    'P c':['(a0g)','(a1/2g)','(0b0)','(1/2b0)',],
2311    'P n':['(a0g)','(a1/2g)','(0b0)','(1/2b1/2)',],
2312#8       
2313    'C m':['(a0g)','(a0g)s','(0b0)','(0b1/2)',],
2314#9       
2315    'C c':['(a0g)','(a0g)s','(0b0)',],
2316    'C n':['(a0g)','(a0g)s','(0b0)',],
2317#10       
2318    'P 2/m':['(a0g)','(a0g)0s','(a1/2g)','(0b0)','(0b0)s0','(1/2b0)','(0b1/2)',],
2319#11
2320    'P 21/m':['(a0g)','(a0g)0s','(0b0)','(0b0)s0','(1/2b0)','(0b1/2)',],
2321#12       
2322    'C 2/m':['(a0g)','(a0g)0s','(0b0)','(0b0)s0','(0b1/2)',],
2323#13
2324    'P 2/c':['(a0g)','(a0g)0s','(a1/2g)','(0b0)','(0b0)s0','(1/2b0)',],
2325    'P 2/a':['(a0g)','(a0g)0s','(a1/2g)','(0b0)','(0b0)s0','(0b1/2)',],
2326    'P 2/n':['(a0g)','(a0g)0s','(a1/2g)','(0b0)','(0b0)s0','(1/2b1/2)',],
2327#14
2328    'P 21/c':['(a0g)','(0b0)','(1/2b0)',],
2329    'P 21/a':['(a0g)','(0b0)','(0b1/2)',],
2330    'P 21/n':['(a0g)','(0b0)','(1/2b1/2)',],
2331#15
2332    'C 2/c':['(a0g)','(0b0)','(0b0)s0',],
2333    'C 2/n':['(a0g)','(0b0)','(0b0)s0',],
2334#orthorhombic
2335#16   
2336    'P 2 2 2':['(00g)','(00g)00s','(01/2g)','(1/20g)','(1/21/2g)',
2337        '(a00)','(a00)s00','(a01/2)','(a1/20)','(a1/21/2)',
2338        '(0b0)','(0b0)0s0','(1/2b0)','(0b1/2)','(1/2b1/2)',],
2339#17       
2340    'P 2 2 21':['(00g)','(01/2g)','(1/20g)','(1/21/2g)',
2341        '(a00)','(a00)s00','(a1/20)','(0b0)','(0b0)0s0','(1/2b0)',],
2342    'P 21 2 2':['(a00)','(a01/2)','(a1/20)','(a1/21/2)',
2343        '(0b0)','(0b0)0s0','(1/2b0)','(00g)','(00g)00s','(1/20g)',],
2344    'P 2 21 2':['(0b0)','(0b1/2)','(1/2b0)','(1/2b1/2)',
2345        '(00g)','(00g)00s','(1/20g)','(a00)','(a00)s00','(a1/20)',],
2346#18       
2347    'P 21 21 2':['(00g)','(00g)00s','(a00)','(a01/2)','(0b0)','(0b1/2)',],
2348    'P 2 21 21':['(a00)','(a00)s00','(0b0)','(0b1/2)','(00g)','(01/2g)',],
2349    'P 21 2 21':['(0b0)','(0b0)0s0','(00g)','(01/2g)','(a00)','(a01/2)',],
2350#19       
2351    'P 21 21 21':['(00g)','(a00)','(0b0)',],
2352#20       
2353    'C 2 2 21':['(00g)','(10g)','(01g)','(a00)','(a00)s00','(0b0)','(0b0)0s0',],
2354    'A 21 2 2':['(a00)','(a10)','(a01)','(0b0)','(0b0)0s0','(00g)','(00g)00s',],
2355    'B 2 21 2':['(0b0)','(1b0)','(0b1)','(00g)','(00g)00s','(a00)','(a00)s00',],
2356#21       
2357    'C 2 2 2':['(00g)','(00g)00s','(10g)','(10g)00s','(01g)','(01g)00s',
2358        '(a00)','(a00)s00','(a01/2)','(0b0)','(0b0)0s0','(0b1/2)',],
2359    'A 2 2 2':['(a00)','(a00)s00','(a10)','(a10)s00','(a01)','(a01)s00',
2360        '(0b0)','(0b0)0s0','(1/2b0)','(00g)','(00g)00s','(1/20g)',],
2361    'B 2 2 2':['(0b0)','(0b0)0s0','(1b0)','(1b0)0s0','(0b1)','(0b1)0s0',
2362        '(00g)','(00g)00s','(01/2g)','(a00)','(a00)s00','(a1/20)',],
2363#22       
2364    'F 2 2 2':['(00g)','(00g)00s','(10g)','(01g)',
2365        '(a00)','(a00)s00','(a10)','(a01)',
2366        '(0b0)','(0b0)0s0','(1b0)','(0b1)',],
2367#23       
2368    'I 2 2 2':['(00g)','(00g)00s','(a00)','(a00)s00','(0b0)','(0b0)0s0',],
2369#24       
2370    'I 21 21 21':['(00g)','(00g)00s','(a00)','(a00)s00','(0b0)','(0b0)0s0',],
2371#25       
2372    'P m m 2':['(00g)','(00g)s0s','(00g)0ss','(00g)ss0',
2373        '(01/2g)','(01/2g)s0s','(1/20g)','(1/20g)0ss','(1/21/2g)',
2374        '(a00)','(a00)0s0','(a1/20)','(a01/2)','(a01/2)0s0','(a1/21/2)',
2375        '(0b0)','(0b0)s00','(0b1/2)','(0b1/2)s00','(1/2b0)','(1/2b1/2)',],       
2376    'P 2 m m':['(a00)','(a00)ss0','(a00)s0s','(a00)0ss',
2377        '(a01/2)','(a01/2)ss0','(a1/20)','(a1/20)s0s','(a1/21/2)',
2378        '(0b0)','(0b0)00s','(1/2b0)','(0b1/2)','(0b1/2)00s','(1/2b1/2)',
2379        '(00g)','(00g)0s0','(01/2g)','(01/2g)0s0','(1/20g)','(1/21/2g)',],
2380    'P m 2 m':['(0b0)','(0b0)ss0','(0b0)0ss','(0b0)s0s',
2381        '(0b1/2)','(0b1/2)ss0','(1/2b0)','(1/2b0)0ss','(1/2b1/2)',
2382        '(00g)','(00g)s00','(1/20g)','(01/2g)','(01/2g)s00','(1/21/2g)',
2383        '(a00)','(a00)0s0','(a01/2)','(a01/2)0s0','(a1/20)','(a1/21/2)',],       
2384#26       
2385    'P m c 21':['(00g)','(00g)s0s','(01/2g)','(01/2g)s0s','(1/20g)','(1/21/2g)',
2386        '(a00)','(a00)0s0','(a1/20)','(0b0)','(0b0)s00','(0b1/2)',],
2387    'P 21 m a':['(a00)','(a00)ss0','(a01/2)','(a01/2)ss0','(a1/20)','(a1/21/2)',
2388        '(0b0)','(0b0)00s','(1/2b0)','(00g)','(00g)0s0','(01/2g)',],
2389    'P b 21 m':['(0b0)','(0b0)ss0','(0b1/2)','(0b1/2)ss0','(1/2b0)','(1/2b1/2)',
2390        '(00g)','(00g)s00','(1/20g)','(a00)','(a00)0s0','(a01/2)',],
2391    'P m 21 b':['(a00)','(a00)ss0','(a01/2)','(a01/2)ss0','(a1/20)','(a1/21/2)',
2392        '(00g)','(00g)0s0','(01/2g)','(0b0)','(0b0)s00','(0b1/2)',],
2393    'P c m 21':['(00g)','(00g)0ss','(1/20g)','(1/20g)0ss','(01/2g)','(1/21/2g)',
2394        '(0b0)','(0b0)s00','(1/2b0)','(a00)','(a00)0s0','(a01/2)',],
2395    'P 21 a m':['(0b0)','(0b0)ss0','(0b1/2)','(0b1/2)ss0','(1/2b0)','(1/2b1/2)',
2396        '(a00)','(a00)00s','(a1/20)','(00g)','(00g)s00','(1/20g)',],
2397#27       
2398    'P c c 2':['(00g)','(00g)s0s','(00g)0ss','(01/2g)','(1/20g)','(1/21/2g)',
2399        '(a00)','(a00)0s0','(a1/20)','(0b0)','(0b0)s00','(1/2b0)',],
2400    'P 2 a a':['(a00)','(a00)ss0','(a00)s0s','(a01/2)','(a1/20)','(a1/21/2)',
2401        '(0b0)','(0b0)00s','(0b1/2)','(00g)','(00g)0s0','(01/2g)',],
2402    'P b 2 b':['(0b0)','(0b0)0ss','(0b0)ss0','(1/2b0)','(0b1/2)','(1/2b1/2)',
2403        '(00g)','(00g)s00','(1/20g)','(a00)','(a00)00s','(a01/2)',],
2404#28       
2405    'P m a 2':['(00g)','(00g)s0s','(00g)ss0','(00g)0ss','(01/2g)','(01/2g)s0s',
2406        '(0b1/2)','(0b1/2)s00','(a01/2)','(a00)','(0b0)','(0b0)0s0','(a1/20)','(a1/21/2)'],
2407    'P 2 m b':['(a00)','(a00)s0s','(a00)ss0','(a00)0ss','(a01/2)','(a01/2)s0s',
2408        '(1/20g)','(1/20g)s00','(1/2b0)','(0b0)','(00g)','(00g)0s0','(0b1/2)','(1/2b1/2)'],
2409    'P c 2 m':['(0b0)','(0b0)s0s','(0b0)ss0','(0b0)0ss','(1/2b0)','(1/2b0)s0s',
2410        '(a1/20)','(a1/20)s00','(01/2g)','(00g)','(a00)','(a00)0s0','(1/20g)','(1/21/2g)'],
2411    'P m 2 a':['(0b0)','(0b0)s0s','(0b0)ss0','(0b0)0ss','(0b1/2)','(0b1/2)s0s',
2412        '(01/2g)','(01/2g)s00','(a1/20)','(a00)','(00g)','(00g)0s0','(a01/2)','(a1/21/2)'],
2413    'P b m 2':['(00g)','(00g)s0s','(00g)ss0','(00g)0ss','(1/20g)','(1/20g)s0s',
2414        '(a01/2)','(a01/2)s00','(0b1/2)','(0b0)','(a00)','(a00)0s0','(1/2b0)','(1/2b1/2)'],
2415    'P 2 c m':['(a00)','(a00)s0s','(a00)ss0','(a00)0ss','(a1/20)','(a1/20)s0s',
2416        '(1/2b0)','(1/2b0)s00','(1/20g)','(00g)','(0b0)','(0b0)0s0','(01/2g)','(1/21/2g)'],
2417#29       
2418    'P c a 21':['(00g)','(00g)0ss','(01/2g)','(1/20g)',
2419        '(a00)','(a00)0s0','(a1/20)','(0b0)','(0b0)s00','(1/2b0)',],
2420    'P 21 a b':['(a00)','(a00)s0s','(a01/2)','(a1/20)',
2421        '(0b0)','(0b0)00s','(0b1/2)','(00g)','(00g)0s0','(01/2g)',],
2422    'P c 21 b':['(0b0)','(0b0)ss0','(1/2b0)','(0b1/2)',
2423        '(00g)','(00g)s00','(1/20g)','(a00)','(a00)00s','(a01/2)',],
2424    'P b 21 a':['(0b0)','(0b0)0ss','(0b1/2)','(1/2b0)',
2425        '(a00)','(a00)00s','(a1/20)','(00g)','(00g)s00','(1/20g)',],
2426    'P b c 21':['(00g)','(00g)s0s','(1/20g)','(01/2g)',
2427        '(0b0)','(0b0)s00','(0b1/2)','(a00)','(a00)0s0','(a1/20)',],
2428    'P 21 c a':['(a00)','(a00)ss0','(a1/20)','(a01/2)',
2429        '(00g)','(00g)0s0','(1/20g)','(0b0)','(0b0)00s','(0b1/2)',],
2430#30       
2431    'P c n 2':['(00g)','(00g)s0s','(01/2g)','(a00)','(0b0)','(0b0)s00',
2432        '(a1/20)','(1/2b1/2)q00',],
2433    'P 2 a n':['(a00)','(a00)ss0','(a01/2)','(0b0)','(00g)','(00g)0s0',
2434        '(0b1/2)','(1/21/2g)0q0',],
2435    'P n 2 b':['(0b0)','(0b0)0ss','(1/2b0)','(00g)','(a00)','(a00)00s',
2436        '(1/20g)','(a1/21/2)00q',],
2437    'P b 2 n':['(0b0)','(0b0)ss0','(0b1/2)','(a00)','(00g)','(00g)s00',
2438        '(a01/2)','(1/21/2g)0ss',],
2439    'P n c 2':['(00g)','(00g)0ss','(1/20g)','(0b0)','(a00)','(a00)0s0',
2440        '(1/2b0)','(a1/21/2)s0s',],
2441    'P 2 n a':['(a00)','(a00)s0s','(a1/20)','(00g)','(0b0)','(0b0)00s',
2442        '(01/2g)','(1/2b1/2)ss0',],
2443#31       
2444    'P m n 21':['(00g)','(00g)s0s','(01/2g)','(01/2g)s0s','(a00)','(0b0)',
2445        '(0b0)s00','(a1/20)',],
2446    'P 21 m n':['(a00)','(a00)ss0','(a01/2)','(a01/2)ss0','(0b0)','(00g)',
2447        '(00g)0s0','(0b1/2)',],
2448    'P n 21 m':['(0b0)','(0b0)0ss','(1/2b0)','(1/2b0)0ss','(00g)','(a00)',
2449        '(a00)00s','(1/20g)',],
2450    'P m 21 n':['(0b0)','(0b0)ss0','(0b1/2)','(0b1/2)ss0','(a00)','(00g)',
2451        '(00g)s00','(a01/2)',],
2452    'P n m 21':['(00g)','(00g)0ss','(1/20g)','(1/20g)0ss','(0b0)','(a00)',
2453        '(a00)0s0','(1/2b0)',],
2454    'P 21 n m':['(a00)','(a00)s0s','(a1/20)','(a1/20)s0s','(00g)','(0b0)',
2455        '(0b0)00s','(01/2g)',],
2456#32       
2457    'P b a 2':['(00g)','(00g)s0s','(00g)0ss','(00g)ss0','(1/21/2g)qq0',
2458        '(a00)','(a01/2)','(0b0)','(0b1/2)',],
2459    'P 2 c b':['(a00)','(a00)ss0','(a00)s0s','(a00)0ss','(a1/21/2)0qq',
2460        '(0b0)','(1/2b0)','(00g)','(1/20g)',],
2461    'P c 2 a':['(0b0)','(0b0)ss0','(0b0)0ss','(0b0)s0s','(1/2b1/2)q0q',
2462        '(00g)','01/2g)','(a00)','(a1/20)',],
2463#33       
2464    'P b n 21':['(00g)','(00g)s0s','(1/21/2g)qq0','(a00)','(0b0)',],
2465    'P 21 c n':['(a00)','(a00)ss0','(a1/21/2)0qq','(0b0)','(00g)',],
2466    'P n 21 a':['(0b0)','(0b0)0ss','(1/2b1/2)q0q','(00g)','(a00)',],
2467    'P c 21 n':['(0b0)','(0b0)ss0','(1/2b1/2)q0q','(a00)','(00g)',],
2468    'P n a 21':['(00g)','(00g)0ss','(1/21/2g)qq0','(0b0)','(a00)',],
2469    'P 21 n b':['(a00)','(a00)s0s','(a1/21/2)0qq','(00g)','(0b0)',],
2470#34       
2471    'P n n 2':['(00g)','(00g)s0s','(00g)0ss','(1/21/2g)qq0',
2472        '(a00)','(a1/21/2)0q0','(a1/21/2)00q','(0b0)','(1/2b1/2)q00','(1/2b1/2)00q',],
2473    'P 2 n n':['(a00)','(a00)ss0','(a00)s0s','(a1/21/2)0qq',
2474        '(0b0)','(1/2b1/2)q00','(1/2b1/2)00q','(00g)','(1/21/2g)0q0','(1/21/2g)q00',],
2475    'P n 2 n':['(0b0)','(0b0)ss0','(0b0)0ss','(1/2b1/2)q0q',
2476        '(00g)','(1/21/2g)0q0','(1/21/2g)q00','(a00)','(a1/21/2)00q','(a1/21/2)0q0',],
2477#35       
2478    'C m m 2':['(00g)','(00g)s0s','(00g)ss0','(10g)','(10g)s0s','(10g)ss0',
2479        '(0b0)','(0b0)s00','(0b1/2)','(0b1/2)s00',],
2480    'A 2 m m':['(a00)','(a00)ss0','(a00)0ss','(a10)','(a10)ss0','(a10)0ss',
2481        '(00g)','(00g)0s0','(1/20g)','(1/20g)0s0',],
2482    'B m 2 m':['(0b0)','(0b0)0ss','(0b0)s0s','(0b1)','(0b1)0ss','(0b1)s0s',
2483        '(a00)','(a00)00s','(a1/20)','(a1/20)00s',],
2484#36
2485    'C m c 21':['(00g)','(00g)s0s','(10g)','(10g)s0s','(a00)','(a00)0s0','(0b0)','(0b0)s00',],
2486    'A 21 m a':['(a00)','(a00)ss0','(a10)','(a10)ss0','(0b0)','(0b0)00s','(00g)','(00g)0s0',],
2487    'B m 21 b':['(0b0)','(0b0)ss0','(1b0)','(1b0)ss0','(a00)','(a00)00s','(00g)','(00g)s00',],
2488    'B b 21 m':['(0b0)','(0b0)0ss','(0b1)','(0b1)ss0','(a00)','(a00)00s','(00g)','(00g)s00',],
2489    'C c m 21':['(00g)','(00g)0ss','(01g)','(01g)0ss','(a00)','(a00)0s0','(0b0)','(0b0)s00',],
2490    'A 21 a m':['(a00)','(a00)s0s','(a01)','(a01)s0s','(0b0)','(0b0)00s','(00g)','(00g)0s0',],
2491#37
2492    'C c c 2':['(00g)','(00g)s0s','(00g)0ss','(10g)','(10g)s0s','(10g)0ss','(01g)','(01g)s0s','(01g)0ss',
2493        '(a00)','(a00)0s0','(0b0)','(0b0)s00',],
2494    'A 2 a a':['(a00)','(a00)ss0','(a00)s0s','(a10)','(a10)ss0','(a10)ss0','(a01)','(a01)ss0','(a01)ss0',
2495        '(0b0)','(0b0)00s','(00g)','(00g)0s0',],
2496    'B b 2 b':['(0b0)','(0b0)0ss','(0b0)ss0','(0b1)','(0b1)0ss','(0b1)ss0','(1b0)','(1b0)0ss','(1b0)ss0',
2497        '(a00)','(a00)00s','(00g)','(00g)s00',],
2498#38
2499    'A m m 2':['(a00)','(a00)0s0','(a10)','(a10)0s0','(00g)','(00g)0s0',
2500        '(00g)ss0','(00g)0ss','(1/20g)','(1/20g)0ss','(0b0)','(0b0)s00','(1/2b0)',],
2501    'B 2 m m':['(0b0)','(0b0)00s','(0b1)','(0b1)00s','(a00)','(a00)00s',
2502        '(a00)0ss','(a00)s0s','(a1/20)','(a1/20)s0s','(00g)','(00g)0s0','(01/2g)',],
2503    'C m 2 m':['(00g)','(00g)s00','(10g)','(10g)s00','(0b0)','(0b0)s00',
2504        '(0b0)s0s','(0b0)ss0','(0b1/2)','(0b1/2)ss0','(a00)','(a00)00s','(a01/2)',],
2505    'A m 2 m':['(a00)','(a00)00s','(a01)','(a01)00s','(0b0)','(0b0)00s',
2506        '(0b0)s0s','(0b0)0ss','(1/2b0)','(1/2b0)0ss','(00g)','(00g)s00','(1/20g)',],
2507    'B m m 2':['(0b0)','(0b0)s00','(0b1)','(0b1)s00','(a00)','(a00)0s0',
2508        '(a00)0ss','(a00)ss0','(01/2g)','(01/2g)s0s','(a00)','(a00)0s0','(a1/20)',],
2509    'C 2 m m':['(00g)','(00g)0s0','(10g)','(10g)0s0','(00g)','(00g)s00',
2510        '(0b0)s0s','(0b0)0ss','(a01/2)','(a01/2)ss0','(0b0)','(0b0)00s','(0b1/2)',],
2511#39
2512    'A b m 2':['(a00)','(a00)0s0','(a01)','(a01)0s0','(00g)','(00g)s0s',
2513        '(00g)ss0','(00g)0ss','(1/20g)','(1/20g)0ss','(0b0)','(0b0)s00','(1/2b0)',],
2514    'B 2 c m':['(0b0)','(0b0)00s','(1b0)','(1b0)00s','(a00)','(a00)ss0',
2515        '(a00)0ss','(a00)s0s','(a1/20)','(a1/20)s0s','(00g)','(00g)0s0','(01/2g)',],
2516    'C m 2 a':['(00g)','(00g)s00','(01g)','(01g)s00','(0b0)','(0b0)0ss',
2517        '(0b0)s0s','(0b0)ss0','(0b1/2)','(0b1/2)ss0','(a00)','(a00)00s','(a01/2)',],
2518    'A c 2 m':['(a00)','(a00)00s','(a10)','(a10)00s','(0b0)','(0b0)ss0',
2519        '(0b0)s0s','(0b0)0ss','(1/2b0)','(1/2b0)0ss','(00g)','(00g)s00','(1/20g)',],
2520    'B m a 2':['(0b0)','(0b0)s00','(0b1)','(0b1)s00','(00g)','(00g)s0s',
2521        '(00g)0ss','(00g)ss0','(01/2g)','(01/2g)ss0','(a00)','(a00)00s','(a1/20)',],
2522    'C 2 m b':['(00g)','(00g)0s0','(10g)','(10g)0s0','(a00)','(a00)0ss',
2523        '(a00)ss0','(a00)s0s','(a01/2)','(a01/2)s0s','(0b0)','(0b0)0s0','(0b1/2)',],
2524#40       
2525    'A m a 2':['(a00)','(a01)','(00g)','(00g)s0s','(00g)ss0','(00g)0ss','(0b0)','(0b0)s00',],
2526    'B 2 m b':['(0b0)','(1b0)','(a00)','(a00)ss0','(a00)0ss','(a00)s0s','(00g)','(00g)0s0',],
2527    'C c 2 m':['(00g)','(01g)','(0b0)','(0b0)0ss','(0b0)s0s','(0b0)ss0','(a00)','(a00)00s',],
2528    'A m 2 a':['(a00)','(a10)','(0b0)','(0b0)ss0','(0b0)s0s','(0b0)0ss','(00g)','(00g)s00',],
2529    'B b m 2':['(0b0)','(0b1)','(00g)','(00g)0ss','(00g)ss0','(00g)s0s','(a00)','(a00)0s0',],
2530    'C 2 c m':['(00g)','(10g)','(a00)','(a00)s0s','(a00)0ss','(a00)ss0','(0b0)','(0b0)00s',],
2531#41
2532    'A b a 2':['(a00)','(a01)','(00g)','(00g)s0s','(00g)ss0','(00g)0ss','(0b0)','(0b0)s00',],
2533    'B 2 c b':['(0b0)','(1b0)','(a00)','(a00)ss0','(a00)0ss','(a00)s0s','(00g)','(00g)0s0',],
2534    'C c 2 a':['(00g)','(01g)','(0b0)','(0b0)0ss','(0b0)s0s','(0b0)ss0','(a00)','(a00)00s',],
2535    'A c 2 a':['(a00)','(a10)','(0b0)','(0b0)ss0','(0b0)s0s','(0b0)0ss','(00g)','(00g)s00',],
2536    'B b a 2':['(0b0)','(0b1)','(00g)','(00g)0ss','(00g)ss0','(00g)s0s','(a00)','(a00)0s0',],
2537    'C 2 c b':['(00g)','(10g)','(a00)','(a00)s0s','(a00)0ss','(a00)ss0','(0b0)','(0b0)00s',],
2538       
2539#42       
2540    'F m m 2':['(00g)','(00g)s0s','(00g)0ss','(00g)ss0','(10g)','(10g)ss0','(10g)s0s',
2541        '(01g)','(01g)ss0','(01g)0ss','(a00)','(a00)0s0','(a01)','(a01)0s0',
2542        '(0b0)','(0b0)s00','(0b1)','(0b1)s00',],       
2543    'F 2 m m':['(a00)','(a00)ss0','(a00)s0s','(a00)0ss','(a10)','(a10)0ss','(a10)ss0',
2544        '(a01)','(a01)0ss','(a01)s0s','(0b0)','(0b0)00s','(1b0)','(1b0)00s',
2545        '(00g)','(00g)0s0','(10g)','(10g)0s0',],
2546    'F m 2 m':['(0b0)','(0b0)0ss','(0b0)ss0','(0b0)s0s','(0b1)','(0b1)s0s','(0b1)0ss',
2547        '(1b0)','(1b0)s0s','(1b0)ss0','(00g)','(00g)s00','(01g)','(01g)s00',
2548        '(a00)','(a00)00s','(a10)','(a10)00s',],       
2549#43       
2550    'F d d 2':['(00g)','(00g)0ss','(00g)s0s','(a00)','(0b0)',],
2551    'F 2 d d':['(a00)','(a00)s0s','(a00)ss0','(00g)','(0b0)',],       
2552    'F d 2 d':['(0b0)','(0b0)0ss','(0b0)ss0','(a00)','(00g)',],
2553#44
2554    'I m m 2':['(00g)','(00g)ss0','(00g)s0s','(00g)0ss','(a00)','(a00)0s0','(0b0)','(0b0)s00',],
2555    'I 2 m m':['(a00)','(00g)0ss','(00g)ss0','(00g)s0s','(0b0)','(0b0)00s','(00g)','(00g)0s0',],
2556    'I m 2 m':['(0b0)','(0b0)s0s','(0b0)0ss','(0b0)ss0','(00g)','(00g)s00','(a00)','(a00)00s',],
2557#45       
2558    'I b a 2':['(00g)','(00g)ss0','(00g)s0s','(00g)0ss','(a00)','(a00)0s0','(0b0)','(0b0)s00',],
2559    'I 2 c b':['(0b0)','(0b0)s0s','(0b0)0ss','(0b0)ss0','(00g)','(00g)s00','(a00)','(a00)00s',],
2560    'I c 2 a':['(a00)','(00g)0ss','(00g)ss0','(00g)s0s','(0b0)','(0b0)00s','(00g)','(00g)0s0',],
2561#46       
2562    'I m a 2':['(a00)','(00g)0ss','(00g)ss0','(00g)s0s','(0b0)','(0b0)00s','(00g)','(00g)0s0',],
2563    'I 2 m b':['(0b0)','(0b0)s0s','(0b0)0ss','(0b0)ss0','(00g)','(00g)s00','(a00)','(a00)00s',],       
2564    'I c 2 m':['(a00)','(00g)0ss','(00g)ss0','(00g)s0s','(0b0)','(0b0)00s','(00g)','(00g)0s0',],
2565    'I m 2 a':['(a00)','(00g)0ss','(00g)ss0','(00g)s0s','(0b0)','(0b0)00s','(00g)','(00g)0s0',],
2566    'I b m 2':['(a00)','(00g)0ss','(00g)ss0','(00g)s0s','(0b0)','(0b0)00s','(00g)','(00g)0s0',],
2567    'I 2 c m':['(0b0)','(0b0)s0s','(0b0)0ss','(0b0)ss0','(00g)','(00g)s00','(a00)','(a00)00s',],
2568#47       
2569    'P m m m':['(00g)','(00g)s00','(00g)0s0','(00g)ss0','(01/2g)','(01/2g)s00','(1/20g)','(1/20g)s00','(1/21/2g)',
2570        '(a00)','(a00)0s0','(a00)00s','(a00)0ss','(a01/2)','(a01/2)0s0','(a1/20)','(a1/20)00s','(a1/21/2)',
2571        '(0b0)','(0b0)s00','(0b0)00s','(0b0)s0s','(1/2b0)','(1/2b0)00s','(0b1/2)','(0b1/2)s00','(1/2b1/2)',],
2572#48 o@i qq0,0qq,q0q ->000
2573    'P n n n':['(00g)','(00g)s00','(00g)0s0','(1/21/2g)',
2574        '(a00)','(a00)0s0','(a00)00s','(a1/21/2)',
2575        '(0b0)','(0b0)s00','(0b0)00s','(1/2b1/2)',],
2576#49       
2577    'P c c m':['(00g)','(00g)s00','(00g)0s0','(01/2g)','(1/20g)','(1/21/2g)',
2578        '(a00)','(a00)0s0','(a00)00s','(a00)0ss','(a1/20)','(a1/20)00s',
2579        '(0b0)','(0b0)s00','(0b0)00s','(0b0)s0s','(1/2b0)','(1/2b0)00s',],       
2580    'P m a a':['(a00)','(a00)0s0','(a00)00s','(a01/2)','(a1/20)','(a1/21/2)',
2581        '(0b0)','(0b0)00s','(0b0)s00','(0b0)s0s','(0b1/2)','(0b1/2)s00',
2582        '(00g)','(00g)0s0','(00g)s00','(00g)ss0','(01/2g)','(01/2g)s00',],       
2583    'P b m b':['(0b0)','(0b0)00s','(0b0)s00','(0b1/2)','(1/2b0)','(1/2b1/2)',
2584        '(00g)','(00g)s00','(00g)0s0','(00g)ss0','(1/20g)','(1/20g)0s0',
2585        '(a00)','(a00)00s','(a00)0s0','(a00)0ss','(a01/2)','(a01/2)0s0',],
2586#50 o@i qq0,0qq,q0q ->000
2587    'P b a n':['(00g)','(00g)s00','(00g)0s0','(00g)ss0','(1/21/2g)',
2588        '(a00)','(a00)0s0','(a01/2)','(0b0)','(0b0)s00','(0b1/2)',],
2589    'P n c b':['(a00)','(a00)0s0','(a00)00s','(a00)0ss','(a1/21/2)',
2590        '(0b0)','(0b0)00s','(1/2b0)','(00g)','(00g)0s0','(1/20g)',],
2591    'P c n a':['(0b0)','(0b0)s00','(0b0)00s','(0b0)s0s','(1/2b1/2)',
2592        '(00g)','(00g)s00','(01/2g)','(a00)','(a00)00s','(a1/20)',],
2593#51       
2594    'P m m a':['(00g)','(00g)s00','(00g)ss0','(00g)0s0','(0b0)','(0b0)s00',
2595        '(0b0)s0s','(0b0)00s','(a00)','(a00)0s0','(01/2g)','(01/2g)s00',
2596        '(0b1/2)','(0b1/2)s00','(a01/2)','(a01/2)0s0','(1/2b0)','(1/2b1/2)',],
2597    'P b m m':['(a00)','(a00)0s0','(a00)0ss','(a00)00s','(00g)','(00g)0s0',
2598        '(00g)ss0','(00g)s00','(0b0)','(0b0)00s','(a01/2)','(a01/2)0s0',
2599        '(1/20g)','(1/20g)0s0','(1/2b0)','(1/2b0)00s','(01/2g)','(1/21/2g)',],
2600    'P m c m':['(0b0)','(0b0)00s','(0b0)s0s','(0b0)s00','(a00)','(a00)00s',
2601        '(a00)0ss','(a00)0s0','(00g)','(00g)s00','(1/2b0)','(1/2b0)00s',
2602        '(a1/20)','(a1/20)00s','(01/2g)','(01/2g)s00','(a01/2)','(a1/21/2)',],
2603    'P m a m':['(0b0)','(0b0)s00','(0b0)s0s','(0b0)00s','(00g)','(00g)s00',
2604        '(00g)ss0','(00g)0s0','(a00)','(a00)00s','(0b1/2)','(0b1/2)s00',
2605        '(01/2g)','(01/2g)s00','(a1/20)','(a1/20)00s','(1/20g)','(1/21/2g)',],
2606    'P m m b':['(00g)','(00g)0s0','(00g)ss0','(00g)s00','(a00)','(a00)0s0',
2607        '(a00)0ss','(a00)00s','(0b0)','(0b0)s00','(a00)','(a00)0s0',
2608        '(a01/2)','(a01/2)0s0','(0b1/2)','(0b1/2)s00','(a1/20)','(a1/21/2)',],
2609    'P c m m':['(a00)','(a00)00s','(a00)0ss','(a00)0s0','(0b0)','(0b0)00s',
2610        '(0b0)s0s','(0b0)s00','(00g)','(00g)0s0','(0b0)','(0b0)00s',
2611        '(1/2b0)','(1/2b0)00s','(1/20g)','(1/20g)0s0','(0b1/2)','(1/2b1/2)',],
2612#52   o@i qq0,0qq,q0q ->000     
2613    'P n n a':['(00g)','(00g)s00','(00g)0s0','(a00)','(a00)00s',
2614        '(0b0)','(0b0)00s','(a1/21/2)','(1/2b1/2)',],
2615    'P b n n':['(a00)','(a00)0s0','(a00)00s','(0b0)','(0b0)s00',
2616        '(00g)','(00g)s00','(1/2b1/2)','(1/21/2g)',],
2617    'P n c n':['(0b0)','(0b0)s00','(0b0)00s','(00g)','(00g)0s0',
2618        '(a00)','(a00)0s0','(1/21/2g)','(a1/21/2)',],
2619    'P n a n':['(0b0)','(0b0)s00','(0b0)00s','(00g)','(00g)0s0',
2620        '(a00)','(a00)0s0','(1/21/2g)','(a1/21/2)',],
2621    'P n n b':['(00g)','(00g)s00','(00g)0s0','(a00)','(a00)00s',
2622        '(0b0)','(0b0)00s','(a1/21/2)','(1/2b1/2)',],
2623    'P c n n':['(a00)','(a00)0s0','(a00)00s','(0b0)','(0b0)s00',
2624        '(00g)','(00g)s00','(1/2b1/2)','(1/21/2g)',],
2625#53       
2626    'P m n a':['(00g)','(00g)s00','(a00)','(a00)00s','(0b0)','(0b0)00s',
2627        '(0b0)s0s','(0b0)s00','(01/2g)','(01/2g)s00','(a1/20)',],
2628    'P b m n':['(a00)','(a00)0s0','(0b0)','(0b0)s00','(00g)','(00g)s00',
2629        '(00g)ss0','(00g)0s0','(a01/2)','(a01/2)0s0','(0b1/2)',],
2630    'P n c m':['(0b0)','(0b0)00s','(00g)','(00g)0s0','(a00)','(a00)0s0',
2631        '(a00)0ss','(a00)00s','(1/2b0)','(1/2b0)00s','(1/20g)',],
2632    'P m a n':['(0b0)','(0b0)s00','(a00)','(a00)0s0','(00g)','(00g)0s0',
2633        '(00g)ss0','(00g)s00','(0b1/2)','(0b1/2)s00','(a01/2)',],
2634    'P n m b':['(00g)','(00g)0s0','(0b0)','(0b0)00s','(a00)','(a00)00s',
2635        '(a00)0ss','(a00)0s0','(1/20g)','(1/20g)0s0','(1/2b0)',],
2636    'P c n m':['(a00)','(a00)00s','(00g)','(00g)s00','(0b0)','(0b0)s00',
2637        '(0b0)s0s','(0b0)00s','(a1/20)','(a1/20)00s','(01/2g)',],
2638#54       
2639    'P c c a':['(00g)','(00g)s00','(0b0)','(0b0)s00','(a00)','(a00)0s0',
2640        '(a00)0ss','(a00)00s','(01/2g)','(1/2b0)',],
2641    'P b a a':['(a00)','(a00)0s0','(00g)','(00g)0s0','(0b0)','(0b0)00s',
2642        '(0b0)s0s','(0b0)s00','(a01/2)','(01/2g)',],
2643    'P b c b':['(0b0)','(0b0)00s','(a00)','(a00)00s','(00g)','(00g)s00',
2644        '(00g)ss0','(00g)0s0','(1/2b0)','(a01/2)',],
2645    'P b a b':['(0b0)','(0b0)s00','(00g)','(00g)s00','(a00)','(a00)00s',
2646        '(a00)0ss','(a00)0s0','(0b1/2)','(1/20g)',],
2647    'P c c b':['(00g)','(00g)0s0','(a00)','(a00)0s0','(0b0)','(0b0)s00',
2648        '(0b0)s0s','(0b0)00s','(1/20g)','(a1/20)',],
2649    'P c a a':['(a00)','(a00)00s','(0b0)','(0b0)00s','(00g)','(00g)0s0',
2650        '(00g)ss0','(00g)s00','(a1/20)','(0b1/2)',],
2651#55       
2652    'P b a m':['(00g)','(00g)s00','(00g)0s0','(00g)ss0',
2653        '(a00)','(a00)00s','(a01/2)','(0b0)','(0b0)00s','(0b1/2)'],
2654    'P m c b':['(a00)','(a00)0s0','(a00)00s','(a00)0ss',
2655        '(0b0)','(0b0)s00','(1/2b0)','(00g)','(00g)s00','(1/20g)'],
2656    'P c m a':['(0b0)','(0b0)s00','(0b0)00s','(0b0)s0s',
2657        '(a00)','(a00)0s0','(a1/20)','(00g)','(00g)0s0','(01/2g)'],
2658#56       
2659    'P c c n':['(00g)','(00g)s00','(00g)0s0','(a00)','(a00)0s0',
2660        '(0b0)','(0b0)s00'],
2661    'P n a a':['(a00)','(a00)0s0','(a00)00s','(0b0)','(0b0)00s',
2662        '(00g)','(00g)0s0'],
2663    'P b n b':['(0b0)','(0b0)s00','(0b0)00s','(a00)','(a00)00s',
2664        '(00g)','(00g)s00'],
2665#57       
2666    'P c a m':['(00g)','(00g)0s0','(a00)','(a00)00s','(0b0)','(0b0)s00',
2667        '(0b0)ss0','(0b0)00s','(01/2g)','(a1/20)','(a1/20)00s',],
2668    'P m a b':['(a00)','(a00)00s','(0b0)','(0b0)s00','(00g)','(00g)0s0',
2669        '(00g)s0s','(00g)s00','(a01/2)','(0b1/2)','(0b1/2)s00',],
2670    'P c m b':['(0b0)','(0b0)s00','(00g)','(00g)0s0','(a00)','(a00)00s',
2671        '(a00)0ss','(a00)0s0','(1/2b0)','(1/20g)','(1/20g)0s0',],
2672    'P b m a':['(0b0)','(0b0)00s','(a00)','(a00)0s0','(00g)','(00g)s00',
2673        '(00g)ss0','(00g)0s0','(0b1/2)','(a01/2)','(a01/2)0s0',],
2674    'P m c a':['(a00)','(a00)0s0','(00g)','(00g)s00','(0b0)','(0b0)00s',
2675        '(0b0)s0s','(0b0)s00','(a1/20)','(01/2g)','(01/2g)s00'],
2676    'P b c m':['(00g)','(00g)s00','(0b0)','(0b0)00s','(a00)','(a00)0s0',
2677        '(a00)0ss','(a00)00s','(1/20g)','(1/2b0)','(1/2b0)00s',],
2678#58       
2679    'P n n m':['(00g)','(00g)s00','(00g)0s0','(a00)',
2680        '(a00)00s','(0b0)','(0b0)00s'],
2681    'P m n n':['(00g)','(00g)s00','(a00)','(a00)0s0',
2682        '(a00)00s','(0b0)','(0b0)s00'],
2683    'P n m n':['(00g)','(00g)0s0','(a00)','(a00)0s0',
2684        '(0b0)','(0b0)s00','(0b0)00s',],
2685#59 o@i
2686    'P m m n':['(00g)','(00g)s00','(00g)0s0','(00g)ss0','(a00)','(a00)0s0',
2687        '(a01/2)','(a01/2)0s0','(0b0)','(0b0)s00','(0b1/2)','(0b1/2)s00',],
2688    'P n m m':['(a00)','(a00)0s0','(a00)00s','(a00)0ss','(00g)','(00g)0s0',
2689        '(1/20g)','(1/20g)0s0','(0b0)','(0b0)00s','(1/2b0)','(1/2b0)00s'],
2690    'P m n m':['(0b0)','(0b0)s00','(0b0)00s','(0b0)s0s','(00g)','(00g)s00',
2691        '(01/2g)','(01/2g)s00','(a00)','(a00)00s','(a1/20)','(a1/20)00s'],
2692#60       
2693    'P b c n':['(00g)','(00g)s00','(00g)0s0','(a00)','(a00)0s0',
2694        '(a00)00s','(0b0)','(0b0)s00','(0b0)00s'],
2695    'P n c a':['(00g)','(00g)s00','(00g)0s0','(a00)','(a00)0s0',
2696        '(a00)00s','(0b0)','(0b0)s00','(0b0)00s'],
2697    'P b n a':['(00g)','(00g)s00','(00g)0s0','(a00)','(a00)0s0',
2698        '(a00)00s','(0b0)','(0b0)s00','(0b0)00s'],
2699    'P c n b':['(00g)','(00g)s00','(00g)0s0','(a00)','(a00)0s0',
2700        '(a00)00s','(0b0)','(0b0)s00','(0b0)00s'],
2701    'P c a n':['(00g)','(00g)s00','(00g)0s0','(a00)','(a00)0s0',
2702        '(a00)00s','(0b0)','(0b0)s00','(0b0)00s'],
2703    'P n a b':['(00g)','(00g)s00','(00g)0s0','(a00)','(a00)0s0',
2704        '(a00)00s','(0b0)','(0b0)s00','(0b0)00s'],
2705#61       
2706    'P b c a':['(00g)','(00g)s00','(00g)0s0','(a00)','(a00)0s0','(a00)00s',
2707        '(0b0)','(0b0)s00','(0b0)00s'],
2708    'P c a b':['(00g)','(00g)s00','(00g)0s0','(a00)','(a00)0s0','(a00)00s',
2709        '(0b0)','(0b0)s00','(0b0)00s'],
2710#62       
2711    'P n m a':['(00g)','(00g)0s0','(a00)','(a00)0s0','(0b0)','(0b0)00s'],
2712    'P b n m':['(00g)','(00g)s00','(a00)','(a00)00s','(0b0)','(0b0)00s'],
2713    'P m c n':['(00g)','(00g)s00','(a00)','(a00)0s0','(0b0)','(0b0)s00'],
2714    'P n a m':['(00g)','(00g)0s0','(a00)','(a00)00s','(0b0)','(0b0)00s'],
2715    'P m n b':['(00g)','(00g)s00','(a00)','(a00)00s','(0b0)','(0b0)s00'],
2716    'P c m n':['(00g)','(00g)0s0','(a00)','(a00)0s0','(0b0)','(0b0)s00'],
2717#63
2718    'C m c m':['(00g)','(00g)s00','(10g)','(10g)s00','(a00)','(a00)00s','(a00)0ss','(a00)0s0','(0b0)','(0b0)00s','(0b0)s0s','(0b0)s00',],
2719    'A m m a':['(a00)','(a00)0s0','(a10)','(a10)0s0','(0b0)','(0b0)s00','(0b0)s0s','(00g)00s','(00g)','(00g)s00','(00g)ss0','(00g)0s0',],
2720    'B b m m':['(0b0)','(0b0)00s','(0b1)','(0b1)00s','(00g)','(00g)0s0','(00g)ss0','(00g)s00','(a00)','(a00)0s0','(a00)0ss','(a00)00s',],
2721    'B m m b':['(0b0)','(0b0)s00','(1b0)','(1b0)s00','(a00)','(a00)0s0','(a00)0ss','(a00)00s','(00g)','(00g)0s0','(00g)ss0','(00g)s00',],
2722    'C c m m':['(00g)','(00g)0s0','(01g)','(01g)0s0','(0b0)','(0b0)00s','(0b0)s0s','(0b0)s00','(a00)','(a00)00s','(a00)0ss','(a00)0s0',],
2723    'A m a m':['(a00)','(a00)00s','(a01)','(a01)00s','(00g)','(00g)s00','(00g)ss0','(00g)0s0','(0b0)','(0b0)s00','(0b0)s0s','(0b0)00s',],
2724#64       
2725    'C m c a':['(00g)','(00g)s00','(10g)','(10g)s00','(0b0)','(0b0)00s','(0b0)s0s','(0b0)s00','(a00)','(a00)00s','(a00)0ss','(a00)0s0',],
2726    'A b m a':['(a00)','(a00)0s0','(a10)','(a10)0s0','(00g)','(00g)s00','(00g)ss0','(00g)0s0','(0b0)','(0b0)s00','(0b0)s0s','(0b0)00s',],
2727    'B b c m':['(0b0)','(0b0)00s','(0b1)','(0b1)00s','(a00)','(a00)0s0','(a00)0ss','(a00)00s','(00g)','(00g)0s0','(00g)ss0','(00g)s00',],
2728    'B m a b':['(0b0)','(0b0)s00','(1b0)','(1b0)s00','(00g)','(00g)0s0','(00g)ss0','(00g)s00','(a00)','(a00)0s0','(a00)0ss','(a00)00s',],
2729    'C c m b':['(00g)','(00g)0s0','(01g)','(01g)0s0','(a00)','(a00)00s','(a00)0ss','(a00)0s0','(0b0)','(0b0)00s','(0b0)s0s','(0b0)s00',],
2730    'A c a m':['(a00)','(a00)00s','(a01)','(a01)00s','(0b0)','(0b0)s00','(0b0)s0s','(0b0)00s','(00g)','(00g)s00','(00g)ss0','(00g)0s0',],
2731#65       
2732    'C m m m':['(00g)','(00g)s00','(00g)ss0','(10g)','(10g)s00','(10g)ss0','(0b0)','(0b0)00s','(0b0)s0s','(0b0)s00','(0b1/2)','(0b1/2)s00',],
2733    'A m m m':['(a00)','(a00)0s0','(a00)0ss','(a10)','(a10)0s0','(a10)0ss','(00g)','(00g)s00','(00g)ss0','(00g)0s0','(1/20g)','(1/20g)0s0',],
2734    'B m m m':['(0b0)','(0b0)00s','(0b0)s0s','(0b1)','(0b1)00s','(0b1)s0s','(a00)','(a00)0s0','(a00)0ss','(a00)00s','(a1/20)','(a1/20)00s',],
2735#66       
2736    'C c c m':['(00g)','(00g)s00','(10g)','(10g)s00','(0b0)','(0b0)00s','(0b0)s0s','(0b0)s00',],
2737    'A m m a':['(a00)','(a00)0s0','(a10)','(a10)0s0','(00g)','(00g)s00','(00g)ss0','(00g)0s0',],
2738    'B b m b':['(0b0)','(0b0)00s','(0b1)','(0b1)00s','(a00)','(a00)0s0','(a00)0ss','(a00)00s',],
2739#67       
2740    'C m m a':['(00g)','(00g)s00','(00g)ss0','(10g)','(10g)s00','(10g)ss0','(a00)','(a00)00s','(a00)0ss','(a00)0s0','(a01/2)','(a01/2)0s0',],
2741    'A b m m':['(a00)','(a00)0s0','(a00)0ss','(a10)','(a10)0s0','(a10)0ss','(0b0)','(0b0)s00','(0b0)s0s','(0b0)00s','(1/2b0)','(1/2b0)00s',],
2742    'B m c m':['(0b0)','(0b0)00s','(0b0)s0s','(0b1)','(0b1)00s','(0b1)s0s','(00g)','(00g)0s0','(00g)ss0','(00g)s00','(01/2g)','(01/2g)s00',],
2743    'B m a m':['(0b0)','(0b0)s00','(0b0)s0s','(1b0)','(1b0)s00','(1b0)s0s','(a00)','(a00)0s0','(a00)0ss','(a00)00s','(a1/20)','(a1/20)00s',],
2744    'C m m b':['(00g)','(00g)0s0','(00g)ss0','(01g)','(01g)0s0','(01g)ss0','(0b0)','(0b0)00s','(0b0)s0s','(0b0)s00','(0b1/2)','(0b1/2)s00',],
2745    'A c m m':['(a00)','(a00)00s','(a00)0ss','(a01)','(a01)00s','(a01)0ss','(00g)','(00g)s00','(00g)ss0','(00g)0s0','(1/20g)','(1/20g)0s0',],
2746#68 o@i
2747    'C c c a':['(00g)','(00g)s00','(10g)','(01g)','(10g)s00','(01g)s00',
2748        '(a00)','(a00)s00','(a00)ss0','(a00)0s0','(0b0)','(0b0)s00','(0b0)ss0','(0b0)0s0'],
2749    'A b a a':['(a00)','(a00)s00','(a10)','(a01)','(a10)s00','(a01)s00',
2750        '(0b0)','(0b0)s00','(0b0)ss0','(0b0)0s0','(00g)','(00g)s00','(00g)ss0','(00g)0s0'],
2751    'B b c b':['(0b0)','(0b0)s00','(0b1)','(1b0)','(0b1)s00','(1b0)s00',
2752        '(00g)','(00g)s00','(00g)ss0','(0b0)0s0','(a00)','(a00)s00','(a00)ss0','(a00)0s0'],
2753    'B b a b':['(0b0)','(0b0)s00','(1b0)','(0b1)','(1b0)s00','(0b1)s00',
2754        '(a00)','(a00)s00','(a00)ss0','(a00)0s0','(00g)','(00g)s00','(00g)ss0','(00g)0s0'],
2755    'C c c b':['(00g)','(00g)ss0','(01g)','(10g)','(01g)s00','(10g)s00',
2756        '(0b0)','(0b0)s00','(0b0)ss0','(0b0)0s0','(a00)','(a00)s00','(a00)ss0','(a00)0s0'],
2757    'A c a a':['(a00)','(a00)ss0','(a01)','(a10)','(a01)s00','(a10)s00',
2758        '(00g)','(00g)s00','(00g)ss0','(00g)0s0','(0b0)','(0b0)s00','(0b0)ss0','(0b0)0s0'],
2759#69       
2760    'F m m m':['(00g)','(00g)s00','(00g)ss0','(a00)','(a00)s00',
2761        '(a00)ss0','(0b0)','(0b0)s00','(0b0)ss0',
2762        '(10g)','(10g)s00','(10g)ss0','(a10)','(a10)0s0',
2763        '(a10)00s','(a10)0ss','(0b1)','(0b1)s00','(0b1)00s','(0b1)s0s',
2764        '(01g)','(01g)s00','(01g)ss0','(a01)','(a01)0s0',
2765        '(a01)00s','(a01)0ss','(1b0)','(1b0)s00','(1b0)00s','(1b0)s0s'],
2766#70 o@i       
2767    'F d d d':['(00g)','(00g)s00','(a00)','(a00)s00','(0b0)','(0b0)s00'],       
2768#71
2769    'I m m m':['(00g)','(00g)s00','(00g)ss0','(a00)','(a00)0s0',
2770        '(a00)ss0','(0b0)','(0b0)s00','(0b0)ss0'],
2771#72       
2772    'I b a m':['(00g)','(00g)s00','(00g)0s0','(00g)ss0','(a00)','(a00)0s0',
2773        '(a00)00s','(a00)0ss','(0b0)','(0b0)s00','(0b0)00s','(0b0)s0s'],
2774    'I m c b':['(a00)','(a00)0s0','(a00)00s','(a00)0ss','(0b0)','(0b0)00s',
2775        '(0b0)s00','(0b0)s0s','(00g)','(00g)0s0','(00g)s00','(00g)ss0'],
2776    'I c m a':['(0b0)','(0b0)00s','(0b0)s00','(0b0)s0s','(00g)','(00g)s00',
2777        '(00g)0s0','(00g)ss0','(a00)','(a00)00s','(a00)0s0','(a00)0ss'],
2778#73       
2779    'I b c a':['(00g)','(00g)s00','(00g)0s0','(00g)ss0','(a00)','(a00)0s0',
2780        '(a00)00s','(a00)0ss','(0b0)','(0b0)s00','(0b0)00s','(0b0)s0s'],
2781    'I c a b':['(00g)','(00g)s00','(00g)0s0','(00g)ss0','(a00)','(a00)0s0',
2782        '(a00)00s','(a00)0ss','(0b0)','(0b0)s00','(0b0)00s','(0b0)s0s'],
2783#74       
2784    'I m m a':['(00g)','(00g)s00','(00g)0s0','(00g)ss0','(a00)','(a00)0s0',
2785        '(a00)00s','(a00)0ss','(0b0)','(0b0)s00','(0b0)00s','(0b0)s0s'],
2786    'I b m m':['(00g)','(00g)s00','(00g)0s0','(00g)ss0','(a00)','(a00)0s0',
2787        '(a00)00s','(a00)0ss','(0b0)','(0b0)s00','(0b0)00s','(0b0)s0s'],
2788    'I m c m':['(00g)','(00g)s00','(00g)0s0','(00g)ss0','(a00)','(a00)0s0',
2789        '(a00)00s','(a00)0ss','(0b0)','(0b0)s00','(0b0)00s','(0b0)s0s'],
2790    'I m a m':['(00g)','(00g)s00','(00g)0s0','(00g)ss0','(a00)','(a00)0s0',
2791        '(a00)00s','(a00)0ss','(0b0)','(0b0)s00','(0b0)00s','(0b0)s0s'],
2792    'I m m b':['(00g)','(00g)s00','(00g)0s0','(00g)ss0','(a00)','(a00)0s0',
2793        '(a00)00s','(a00)0ss','(0b0)','(0b0)s00','(0b0)00s','(0b0)s0s'],
2794    'I c m m':['(00g)','(00g)s00','(00g)0s0','(00g)ss0','(a00)','(a00)0s0',
2795        '(a00)00s','(a00)0ss','(0b0)','(0b0)s00','(0b0)00s','(0b0)s0s'],
2796#tetragonal - done & checked
2797#75
2798    'P 4':['(00g)','(00g)q','(00g)s','(1/21/2g)','(1/21/2g)q',],
2799#76
2800    'P 41':['(00g)','(1/21/2g)',],
2801#77
2802    'P 42':['(00g)','(00g)q','(1/21/2g)','(1/21/2g)q',],
2803#78
2804    'P 43':['(00g)','(1/21/2g)',],
2805#79
2806    'I 4':['(00g)','(00g)q','(00g)s',],
2807#80
2808    'I 41':['(00g)','(00g)q',],
2809#81
2810    'P -4':['(00g)','(1/21/2g)',],
2811#82
2812    'I -4':['(00g)',],
2813#83
2814    'P 4/m':['(00g)','(00g)s0','(1/21/2g)',],
2815#84
2816    'P 42/m':['(00g)','(1/21/2g)',],
2817#85 o@i q0 -> 00
2818    'P 4/n':['(00g)','(00g)s0','(1/21/2g)',], #q0?
2819#86 o@i q0 -> 00
2820    'P 42/n':['(00g)','(1/21/2g)',],      #q0?
2821#87
2822    'I 4/m':['(00g)','(00g)s0',],
2823#88
2824    'I 41/a':['(00g)',],
2825#89
2826    'P 4 2 2':['(00g)','(00g)q00','(00g)s00','(1/21/2g)','(1/21/2g)q00',],
2827#90
2828    'P 4 21 2':['(00g)','(00g)q00','(00g)s00',],
2829#91
2830    'P 41 2 2':['(00g)','(1/21/2g)',],
2831#92
2832    'P 41 21 2':['(00g)',],
2833#93
2834    'P 42 2 2':['(00g)','(00g)q00','(1/21/2g)','(1/21/2g)q00',],
2835#94
2836    'P 42 21 2':['(00g)','(00g)q00',],
2837#95
2838    'P 43 2 2':['(00g)','(1/21/2g)',],
2839#96
2840    'P 43 21 2':['(00g)',],
2841#97
2842    'I 4 2 2':['(00g)','(00g)q00','(00g)s00',],
2843#98
2844    'I 41 2 2':['(00g)','(00g)q00',],
2845#99
2846    'P 4 m m':['(00g)','(00g)ss0','(00g)0ss','(00g)s0s','(1/21/2g)','(1/21/2g)0ss'],
2847#100
2848    'P 4 b m':['(00g)','(00g)ss0','(00g)0ss','(00g)s0s','(1/21/2g)qq0','(1/21/2g)qqs',],
2849#101
2850    'P 42 c m':['(00g)','(00g)0ss','(1/21/2g)','(1/21/2g)0ss',],
2851#102
2852    'P 42 n m':['(00g)','(00g)0ss','(1/21/2g)qq0','(1/21/2g)qqs',],
2853#103
2854    'P 4 c c':['(00g)','(00g)ss0','(1/21/2g)',],
2855#104
2856    'P 4 n c':['(00g)','(00g)ss0','(1/21/2g)qq0',],
2857#105
2858    'P 42 m c':['(00g)','(00g)ss0','(1/21/2g)',],
2859#106
2860    'P 42 b c':['(00g)','(00g)ss0','(1/21/2g)qq0',],
2861#107
2862    'I 4 m m':['(00g)','(00g)ss0','(00g)0ss','(00g)s0s',],
2863#108
2864    'I 4 c m':['(00g)','(00g)ss0','(00g)0ss','(00g)s0s',],
2865#109
2866    'I 41 m d':['(00g)','(00g)ss0',],
2867#110
2868    'I 41 c d':['(00g)','(00g)ss0',],
2869#111
2870    'P -4 2 m':['(00g)','(00g)0ss','(1/21/2g)','(1/21/2g)0ss',],
2871#112
2872    'P -4 2 c':['(00g)','(1/21/2g)',],
2873#113
2874    'P -4 21 m':['(00g)','(00g)0ss',],
2875#114
2876    'P -4 21 c':['(00g)',],
2877#115    00s -> 0ss
2878    'P -4 m 2':['(00g)','(00g)0s0','(1/21/2g)',],
2879#116
2880    'P -4 c 2':['(00g)','(1/21/2g)',],
2881#117    00s -> 0ss
2882    'P -4 b 2':['(00g)','(00g)0s0','(1/21/2g)0q0',],
2883#118
2884    'P -4 n 2':['(00g)','(1/21/2g)0q0',],
2885#119
2886    'I -4 m 2':['(00g)','(00g)0s0',],
2887#120
2888    'I -4 c 2':['(00g)','(00g)0s0',],
2889#121    00s -> 0ss
2890    'I -4 2 m':['(00g)','(00g)0ss',],
2891#122
2892    'I -4 2 d':['(00g)',],
2893#123
2894    'P 4/m m m':['(00g)','(00g)s0s0','(00g)00ss','(00g)s00s',
2895        '(1/21/2g)','(1/21/2g)s0s0','(1/21/2g)00ss','(1/21/2g)s00s',],
2896#124
2897    'P 4/m c c':['(00g)','(00g)s0s0','(1/21/2g)',],
2898#125    o@i q0q0 -> 0000, q0qs -> 00ss
2899    'P 4/n b m':['(00g)','(00g)s0s0','(00g)00ss','(00g)s00s','(1/21/2g)','(1/21/2g)00ss',],
2900#126    o@i q0q0 -> 0000
2901    'P 4/n n c':['(00g)','(00g)s0s0','(1/21/2g)',],
2902#127
2903    'P 4/m b m':['(00g)','(00g)s0s0','(00g)00ss','(00g)s00s',],
2904#128
2905    'P 4/m n c':['(00g)','(00g)s0s0',],
2906#129
2907    'P 4/n m m':['(00g)','(00g)s0s0','(00g)00ss','(00g)s00s',],
2908#130
2909    'P 4/n c c':['(00g)','(00g)s0s0',],
2910#131
2911    'P 42/m m c':['(00g)','(00g)s0s0','(1/21/2g)',],
2912#132
2913    'P 42/m c m':['(00g)','(00g)00ss','(1/21/2g)','(1/21/2g)00ss',],
2914#133    o@i q0q0 -> 0000
2915    'P 42/n b c':['(00g)','(00g)s0s0','(1/21/2g)',],
2916#134    o@i q0q0 -> 0000, q0qs -> 00ss
2917    'P 42/n n m':['(00g)','(00g)00ss','(1/21/2g)','(1/21/2g)00ss',],
2918#135
2919    'P 42/m b c':['(00g)','(00g)s0s0',],
2920#136
2921    'P 42/m n m':['(00g)','(00g)00ss',],
2922#137
2923    'P 42/n m c':['(00g)','(00g)s0s0',],
2924#138
2925    'P 42/n c m':['(00g)','(00g)00ss',],
2926#139
2927    'I 4/m m m':['(00g)','(00g)s0s0','(00g)00ss','(00g)s00s',],
2928#140
2929    'I 4/m c m':['(00g)','(00g)s0s0','(00g)00ss','(00g)s00s',],
2930#141
2931    'I 41/a m d':['(00g)','(00g)s0s0',],
2932#142
2933    'I 41/a c d':['(00g)','(00g)s0s0',],
2934    #trigonal/rhombahedral - done & checked
2935#143
2936    'P 3':['(00g)','(00g)t','(1/31/3g)',],
2937#144
2938    'P 31':['(00g)','(1/31/3g)',],
2939#145
2940    'P 32':['(00g)','(1/31/3g)',],
2941#146
2942    'R 3':['(00g)','(00g)t',],
2943#147
2944    'P -3':['(00g)','(1/31/3g)',],
2945#148
2946    'R -3':['(00g)',],
2947#149
2948    'P 3 1 2':['(00g)','(00g)t00','(1/31/3g)',],
2949#150
2950    'P 3 2 1':['(00g)','(00g)t00',],
2951#151
2952    'P 31 1 2':['(00g)','(1/31/3g)',],
2953#152
2954    'P 31 2 1':['(00g)',],
2955#153
2956    'P 32 1 2':['(00g)','(1/31/3g)',],
2957#154
2958    'P 32 2 1':['(00g)',],
2959#155
2960    'R 3 2':['(00g)','(00g)t0',],
2961#156
2962    'P 3 m 1':['(00g)','(00g)0s0',],
2963#157
2964    'P 3 1 m':['(00g)','(00g)00s','(1/31/3g)','(1/31/3g)00s',],
2965#158
2966    'P 3 c 1':['(00g)',],
2967#159
2968    'P 3 1 c':['(00g)','(1/31/3g)',],
2969#160
2970    'R 3 m':['(00g)','(00g)0s',],
2971#161
2972    'R 3 c':['(00g)',],
2973#162
2974    'P -3 1 m':['(00g)','(00g)00s','(1/31/3g)','(1/31/3g)00s',],
2975#163
2976    'P -3 1 c':['(00g)','(1/31/3g)',],
2977#164
2978    'P -3 m 1':['(00g)','(00g)0s0',],
2979#165
2980    'P -3 c 1':['(00g)',],
2981#166       
2982    'R -3 m':['(00g)','(00g)0s',],
2983#167
2984    'R -3 c':['(00g)',],
2985    #hexagonal - done & checked
2986#168
2987    'P 6':['(00g)','(00g)h','(00g)t','(00g)s',],
2988#169
2989    'P 61':['(00g)',],
2990#170
2991    'P 65':['(00g)',],
2992#171
2993    'P 62':['(00g)','(00g)h',],
2994#172
2995    'P 64':['(00g)','(00g)h',],
2996#173
2997    'P 63':['(00g)','(00g)h',],
2998#174
2999    'P -6':['(00g)',],
3000#175
3001    'P 6/m':['(00g)','(00g)s0',],
3002#176
3003    'P 63/m':['(00g)',],
3004#177
3005    'P 6 2 2':['(00g)','(00g)h00','(00g)t00','(00g)s00',],
3006#178
3007    'P 61 2 2':['(00g)',],
3008#179
3009    'P 65 2 2':['(00g)',],
3010#180
3011    'P 62 2 2':['(00g)','(00g)h00',],
3012#181
3013    'P 64 2 2':['(00g)','(00g)h00',],
3014#182
3015    'P 63 2 2':['(00g)','(00g)h00',],
3016#183
3017    'P 6 m m':['(00g)','(00g)ss0','(00g)0ss','(00g)s0s',],
3018#184
3019    'P 6 c c':['(00g)','(00g)s0s',],
3020#185
3021    'P 63 c m':['(00g)','(00g)0ss',],
3022#186
3023    'P 63 m c':['(00g)','(00g)0ss',],
3024#187
3025    'P -6 m 2':['(00g)','(00g)0s0',],
3026#188
3027    'P -6 c 2':['(00g)',],
3028#189
3029    'P -6 2 m':['(00g)','(00g)00s',],
3030#190
3031    'P -6 2 c':['(00g)',],
3032#191
3033    'P 6/m m m':['(00g)','(00g)s0s0','(00g)00ss','(00g)s00s',],
3034#192
3035    'P 6/m c c':['(00g)','(00g)s00s',],
3036#193
3037    'P 63/m c m':['(00g)','(00g)00ss',],
3038#194
3039    'P 63/m m c':['(00g)','(00g)00ss'],
3040    }
3041
3042#'A few non-standard space groups for test use'
3043nonstandard_sglist = ('P 21 1 1','P 1 21 1','P 1 1 21','R 3 r','R 3 2 h', 
3044                      'R -3 r', 'R 3 2 r','R 3 m h', 'R 3 m r',
3045                      'R 3 c r','R -3 c r','R -3 m r',),
3046
3047#A list of orthorhombic space groups that were renamed in the 2002 Volume A,
3048# along with the pre-2002 name. The e designates a double glide-plane'''
3049sgequiv_2002_orthorhombic= (('A e m 2', 'A b m 2',),
3050                            ('A e a 2', 'A b a 2',),
3051                            ('C m c e', 'C m c a',),
3052                            ('C m m e', 'C m m a',),
3053                            ('C c c e', 'C c c a'),)
3054#Use the space groups types in this order to list the symbols in the
3055#order they are listed in the International Tables, vol. A'''
3056symtypelist = ('triclinic', 'monoclinic', 'orthorhombic', 'tetragonal', 
3057               'trigonal', 'hexagonal', 'cubic')
3058
3059# self-test materials follow. Requires files in directory testinp
3060selftestlist = []
3061'''Defines a list of self-tests'''
3062selftestquiet = True
3063def _ReportTest():
3064    'Report name and doc string of current routine when ``selftestquiet`` is False'
3065    if not selftestquiet:
3066        import inspect
3067        caller = inspect.stack()[1][3]
3068        doc = eval(caller).__doc__
3069        if doc is not None:
3070            print('testing '+__file__+' with '+caller+' ('+doc+')')
3071        else:
3072            print('testing '+__file__()+" with "+caller)
3073def test0():
3074    '''self-test #0: exercise MoveToUnitCell'''
3075    _ReportTest()
3076    msg = "MoveToUnitCell failed"
3077    assert (MoveToUnitCell([1,2,3])[0] == [0,0,0]).all, msg
3078    assert (MoveToUnitCell([2,-1,-2])[0] == [0,0,0]).all, msg
3079    assert abs(MoveToUnitCell(np.array([-.1]))[0]-0.9)[0] < 1e-6, msg
3080    assert abs(MoveToUnitCell(np.array([.1]))[0]-0.1)[0] < 1e-6, msg
3081selftestlist.append(test0)
3082
3083def test1():
3084    '''self-test #1: SpcGroup against previous results'''
3085    #'''self-test #1: SpcGroup and SGPrint against previous results'''
3086    _ReportTest()
3087    testdir = ospath.join(ospath.split(ospath.abspath( __file__ ))[0],'testinp')
3088    if ospath.exists(testdir):
3089        if testdir not in sys.path: sys.path.insert(0,testdir)
3090    import spctestinp
3091    def CompareSpcGroup(spc, referr, refdict, reflist): 
3092        'Compare output from GSASIIspc.SpcGroup with results from a previous run'
3093        # if an error is reported, the dictionary can be ignored
3094        msg0 = "CompareSpcGroup failed on space group %s" % spc
3095        result = SpcGroup(spc)
3096        if result[0] == referr and referr > 0: return True
3097        keys = result[1].keys()
3098        #print result[1]['SpGrp']
3099        #msg = msg0 + " in list lengths"
3100        #assert len(keys) == len(refdict.keys()), msg
3101        for key in refdict.keys():
3102            if key == 'SGOps' or  key == 'SGCen':
3103                msg = msg0 + (" in key %s length" % key)
3104                assert len(refdict[key]) == len(result[1][key]), msg
3105                for i in range(len(refdict[key])):
3106                    msg = msg0 + (" in key %s level 0" % key)
3107                    assert np.allclose(result[1][key][i][0],refdict[key][i][0]), msg
3108                    msg = msg0 + (" in key %s level 1" % key)
3109                    assert np.allclose(result[1][key][i][1],refdict[key][i][1]), msg
3110            else:
3111                msg = msg0 + (" in key %s" % key)
3112                assert result[1][key] == refdict[key], msg
3113        msg = msg0 + (" in key %s reflist" % key)
3114        #for (l1,l2) in zip(reflist, SGPrint(result[1])):
3115        #    assert l2.replace('\t','').replace(' ','') == l1.replace(' ',''), 'SGPrint ' +msg
3116        # for now disable SGPrint testing, output has changed
3117        #assert reflist == SGPrint(result[1]), 'SGPrint ' +msg
3118    for spc in spctestinp.SGdat:
3119        CompareSpcGroup(spc, 0, spctestinp.SGdat[spc], spctestinp.SGlist[spc] )
3120selftestlist.append(test1)
3121
3122def test2():
3123    '''self-test #2: SpcGroup against cctbx (sgtbx) computations'''
3124    _ReportTest()
3125    testdir = ospath.join(ospath.split(ospath.abspath( __file__ ))[0],'testinp')
3126    if ospath.exists(testdir):
3127        if testdir not in sys.path: sys.path.insert(0,testdir)
3128    import sgtbxtestinp
3129    def CompareWcctbx(spcname, cctbx_in, debug=0):
3130        'Compare output from GSASIIspc.SpcGroup with results from cctbx.sgtbx'
3131        cctbx = cctbx_in[:] # make copy so we don't delete from the original
3132        spc = (SpcGroup(spcname))[1]
3133        if debug: print spc['SpGrp']
3134        if debug: print spc['SGCen']
3135        latticetype = spcname.strip().upper()[0]
3136        # lattice type of R implies Hexagonal centering", fix the rhombohedral settings
3137        if latticetype == "R" and len(spc['SGCen']) == 1: latticetype = 'P'
3138        assert latticetype == spc['SGLatt'], "Failed: %s does not match Lattice: %s" % (spcname, spc['SGLatt'])
3139        onebar = [1]
3140        if spc['SGInv']: onebar.append(-1)
3141        for (op,off) in spc['SGOps']:
3142            for inv in onebar:
3143                for cen in spc['SGCen']:
3144                    noff = off + cen
3145                    noff = MoveToUnitCell(noff)[0]
3146                    mult = tuple((op*inv).ravel().tolist())
3147                    if debug: print "\n%s: %s + %s" % (spcname,mult,noff)
3148                    for refop in cctbx:
3149                        if debug: print refop
3150                        # check the transform
3151                        if refop[:9] != mult: continue
3152                        if debug: print "mult match"
3153                        # check the translation
3154                        reftrans = list(refop[-3:])
3155                        reftrans = MoveToUnitCell(reftrans)[0]
3156                        if all(abs(noff - reftrans) < 1.e-5):
3157                            cctbx.remove(refop)
3158                            break
3159                    else:
3160                        assert False, "failed on %s:\n\t %s + %s" % (spcname,mult,noff)
3161    for key in sgtbxtestinp.sgtbx:
3162        CompareWcctbx(key, sgtbxtestinp.sgtbx[key])
3163selftestlist.append(test2)
3164
3165def test3(): 
3166    '''self-test #3: exercise SytSym (includes GetOprPtrName, GenAtom, GetKNsym)
3167     for selected space groups against info in IT Volume A '''
3168    _ReportTest()
3169    def ExerciseSiteSym (spc, crdlist):
3170        'compare site symmetries and multiplicities for a specified space group'
3171        msg = "failed on site sym test for %s" % spc
3172        (E,S) = SpcGroup(spc)
3173        assert not E, msg
3174        for t in crdlist:
3175            symb, m = SytSym(t[0],S)
3176            if symb.strip() != t[2].strip() or m != t[1]:
3177                print spc,t[0],m,symb,t[2]
3178            assert m == t[1]
3179            #assert symb.strip() == t[2].strip()
3180
3181    ExerciseSiteSym('p 1',[
3182            ((0.13,0.22,0.31),1,'1'),
3183            ((0,0,0),1,'1'),
3184            ])
3185    ExerciseSiteSym('p -1',[
3186            ((0.13,0.22,0.31),2,'1'),
3187            ((0,0.5,0),1,'-1'),
3188            ])
3189    ExerciseSiteSym('C 2/c',[
3190            ((0.13,0.22,0.31),8,'1'),
3191            ((0.0,.31,0.25),4,'2(y)'),
3192            ((0.25,.25,0.5),4,'-1'),
3193            ((0,0.5,0),4,'-1'),
3194            ])
3195    ExerciseSiteSym('p 2 2 2',[
3196            ((0.13,0.22,0.31),4,'1'),
3197            ((0,0.5,.31),2,'2(z)'),
3198            ((0.5,.31,0.5),2,'2(y)'),
3199            ((.11,0,0),2,'2(x)'),
3200            ((0,0.5,0),1,'222'),
3201            ])
3202    ExerciseSiteSym('p 4/n',[
3203            ((0.13,0.22,0.31),8,'1'),
3204            ((0.25,0.75,.31),4,'2(z)'),
3205            ((0.5,0.5,0.5),4,'-1'),
3206            ((0,0.5,0),4,'-1'),
3207            ((0.25,0.25,.31),2,'4(001)'),
3208            ((0.25,.75,0.5),2,'-4(001)'),
3209            ((0.25,.75,0.0),2,'-4(001)'),
3210            ])
3211    ExerciseSiteSym('p 31 2 1',[
3212            ((0.13,0.22,0.31),6,'1'),
3213            ((0.13,0.0,0.833333333),3,'2(100)'),
3214            ((0.13,0.13,0.),3,'2(110)'),
3215            ])
3216    ExerciseSiteSym('R 3 c',[
3217            ((0.13,0.22,0.31),18,'1'),
3218            ((0.0,0.0,0.31),6,'3'),
3219            ])
3220    ExerciseSiteSym('R 3 c R',[
3221            ((0.13,0.22,0.31),6,'1'),
3222            ((0.31,0.31,0.31),2,'3(111)'),
3223            ])
3224    ExerciseSiteSym('P 63 m c',[
3225            ((0.13,0.22,0.31),12,'1'),
3226            ((0.11,0.22,0.31),6,'m(100)'),
3227            ((0.333333,0.6666667,0.31),2,'3m(100)'),
3228            ((0,0,0.31),2,'3m(100)'),
3229            ])
3230    ExerciseSiteSym('I a -3',[
3231            ((0.13,0.22,0.31),48,'1'),
3232            ((0.11,0,0.25),24,'2(x)'),
3233            ((0.11,0.11,0.11),16,'3(111)'),
3234            ((0,0,0),8,'-3(111)'),
3235            ])
3236selftestlist.append(test3)
3237
3238if __name__ == '__main__':
3239    # run self-tests
3240    selftestquiet = False
3241    for test in selftestlist:
3242        test()
3243    print "OK"
Note: See TracBrowser for help on using the repository browser.