source: trunk/GSASIIspc.py @ 2136

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

fix indexing problem in 32 bit versions - Skip in ProgressDialog? doesn't work
skip user excluded reflections in HKLF exporters
modify MergeDialog? & more work on LaueUnique?
add 'O' option to 3DHKLF plots to center on origin

  • Property svn:eol-style set to native
  • Property svn:keywords set to Date Author Revision URL Id
File size: 143.8 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: 2016-01-26 19:16:37 +0000 (Tue, 26 Jan 2016) $
12# $Author: vondreele $
13# $Revision: 2136 $
14# $URL: trunk/GSASIIspc.py $
15# $Id: GSASIIspc.py 2136 2016-01-26 19:16:37Z 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: 2136 $")
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,newMod=True):
973    ''' Checks modulation vector compatibility with supersymmetry space group symbol.
974    if newMod: 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    if newMod:
979        newVec = [0.1 if (vec == 0.0 and mod in ['a','b','g']) else vec for [vec,mod] in zip(Vec,modSymb)]
980        return [Q if mod not in ['a','b','g'] and vec != Q else vec for [vec,mod,Q] in zip(newVec,modSymb,modQ)],  \
981            [True if mod in ['a','b','g'] else False for mod in modSymb]
982    else:
983        return Vec,[True if mod in ['a','b','g'] else False for mod in modSymb]
984
985def SSMT2text(Opr):
986    "From superspace group matrix/translation operator returns text version"
987    XYZS = ('x','y','z','t')    #Stokes, Campbell & van Smaalen notation
988    TRA = ('   ','ERR','1/6','1/4','1/3','ERR','1/2','ERR','2/3','3/4','5/6','ERR')
989    Fld = ''
990    M,T = Opr
991    for j in range(4):
992        IJ = ''
993        for k in range(4):
994            txt = str(int(round(M[j][k])))
995            txt = txt.replace('1',XYZS[k]).replace('0','')
996            if '2' in txt:
997                txt += XYZS[k]
998            if IJ and M[j][k] > 0:
999                IJ += '+'+txt
1000            else:
1001                IJ += txt
1002        IK = int(round(T[j]*12))%12
1003        if IK:
1004            if not IJ:
1005                break
1006            if IJ[0] == '-':
1007                Fld += (TRA[IK]+IJ).rjust(8)
1008            else:
1009                Fld += (TRA[IK]+'+'+IJ).rjust(8)
1010        else:
1011            Fld += IJ.rjust(8)
1012        if j != 3: Fld += ', '
1013    return Fld
1014   
1015def SSLatt2text(SSGCen):
1016    "Lattice centering vectors to text"
1017    lattTxt = ''
1018    lattDir = {4:'1/3',6:'1/2',8:'2/3',0:'0'}
1019    for vec in SSGCen:
1020        lattTxt += ' '
1021        for item in vec:
1022            lattTxt += '%s,'%(lattDir[int(item*12)])
1023        lattTxt = lattTxt.rstrip(',')
1024        lattTxt += ';'
1025    lattTxt = lattTxt.rstrip(';').lstrip(' ')
1026    return lattTxt
1027       
1028def SSpaceGroup(SGSymbol,SSymbol):
1029    '''
1030    Print the output of SSpcGroup in a nicely formatted way.
1031
1032    :param SGSymbol: space group symbol with spaces between axial fields.
1033    :param SSymbol: superspace group symbol extension (string).
1034    :returns: nothing
1035    '''
1036
1037    E,A = SpcGroup(SGSymbol)
1038    if E > 0:
1039        print SGErrors(E)
1040        return
1041    E,B = SSpcGroup(A,SSymbol)   
1042    if E > 0:
1043        print E
1044        return
1045    for l in SSGPrint(B):
1046        print l
1047       
1048def SGProd(OpA,OpB):
1049    '''
1050    Form space group operator product. OpA & OpB are [M,V] pairs;
1051        both must be of same dimension (3 or 4). Returns [M,V] pair
1052    '''
1053    A,U = OpA
1054    B,V = OpB
1055    M = np.inner(B,A.T)
1056    W = np.inner(B,U)+V
1057    return M,W
1058       
1059def MoveToUnitCell(xyz):
1060    '''
1061    Translates a set of coordinates so that all values are >=0 and < 1
1062
1063    :param xyz: a list or numpy array of fractional coordinates
1064    :returns: XYZ - numpy array of new coordinates now 0 or greater and less than 1
1065    '''
1066    XYZ = (np.array(xyz)+10.)%1.
1067    cell = np.asarray(np.rint(xyz-XYZ),dtype=np.int32)
1068    return XYZ,cell
1069       
1070def Opposite(XYZ,toler=0.0002):
1071    '''
1072    Gives opposite corner, edge or face of unit cell for position within tolerance.
1073        Result may be just outside the cell within tolerance
1074
1075    :param XYZ: 0 >= np.array[x,y,z] > 1 as by MoveToUnitCell
1076    :param toler: unit cell fraction tolerance making opposite
1077    :returns:
1078        XYZ: dict of opposite positions; key=unit cell & always contains XYZ
1079    '''
1080    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]]
1081    TB = np.where(abs(XYZ-1)<toler,-1,0)+np.where(abs(XYZ)<toler,1,0)
1082    perm = TB*perm3
1083    cperm = ['%d,%d,%d'%(i,j,k) for i,j,k in perm]
1084    D = dict(zip(cperm,perm))
1085    new = {}
1086    for key in D:
1087        new[key] = np.array(D[key])+np.array(XYZ)
1088    return new
1089       
1090def GenAtom(XYZ,SGData,All=False,Uij=[],Move=True):
1091    '''
1092    Generates the equivalent positions for a specified coordinate and space group
1093
1094    :param XYZ: an array, tuple or list containing 3 elements: x, y & z
1095    :param SGData: from :func:`SpcGroup`
1096    :param All: True return all equivalent positions including duplicates;
1097      False return only unique positions
1098    :param Uij: [U11,U22,U33,U12,U13,U23] or [] if no Uij
1099    :param Move: True move generated atom positions to be inside cell
1100      False do not move atoms       
1101    :return: [[XYZEquiv],Idup,[UijEquiv]]
1102
1103      *  [XYZEquiv] is list of equivalent positions (XYZ is first entry)
1104      *  Idup = [-][C]SS where SS is the symmetry operator number (1-24), C (if not 0,0,0)
1105      * is centering operator number (1-4) and - is for inversion
1106        Cell = unit cell translations needed to put new positions inside cell
1107        [UijEquiv] - equivalent Uij; absent if no Uij given
1108       
1109    '''
1110    XYZEquiv = []
1111    UijEquiv = []
1112    Idup = []
1113    Cell = []
1114    X = np.array(XYZ)
1115    if Move:
1116        X = MoveToUnitCell(X)[0]
1117    for ic,cen in enumerate(SGData['SGCen']):
1118        C = np.array(cen)
1119        for invers in range(int(SGData['SGInv']+1)):
1120            for io,[M,T] in enumerate(SGData['SGOps']):
1121                idup = ((io+1)+100*ic)*(1-2*invers)
1122                XT = np.inner(M,X)+T
1123                if len(Uij):
1124                    U = Uij2U(Uij)
1125                    U = np.inner(M,np.inner(U,M).T)
1126                    newUij = U2Uij(U)
1127                if invers:
1128                    XT = -XT
1129                XT += C
1130                cell = np.zeros(3,dtype=np.int32)
1131                cellj = np.zeros(3,dtype=np.int32)
1132                if Move:
1133                    newX,cellj = MoveToUnitCell(XT)
1134                else:
1135                    newX = XT
1136                cell += cellj
1137                if All:
1138                    if np.allclose(newX,X,atol=0.0002):
1139                        idup = False
1140                else:
1141                    if True in [np.allclose(newX,oldX,atol=0.0002) for oldX in XYZEquiv]:
1142                        idup = False
1143                if All or idup:
1144                    XYZEquiv.append(newX)
1145                    Idup.append(idup)
1146                    Cell.append(cell)
1147                    if len(Uij):
1148                        UijEquiv.append(newUij)                   
1149    if len(Uij):
1150        return zip(XYZEquiv,UijEquiv,Idup,Cell)
1151    else:
1152        return zip(XYZEquiv,Idup,Cell)
1153
1154def GenHKLf(HKL,SGData):
1155    '''
1156    Uses old GSAS Fortran routine genhkl.for
1157
1158    :param HKL:  [h,k,l] must be integral values for genhkl.for to work
1159    :param SGData: space group data obtained from SpcGroup
1160    :returns: iabsnt,mulp,Uniq,phi
1161
1162     *   iabsnt = True if reflection is forbidden by symmetry
1163     *   mulp = reflection multiplicity including Friedel pairs
1164     *   Uniq = numpy array of equivalent hkl in descending order of h,k,l
1165     *   phi = phase offset for each equivalent h,k,l
1166
1167    '''
1168    hklf = list(HKL)+[0,]       #could be numpy array!
1169    Ops = SGData['SGOps']
1170    OpM = np.array([op[0] for op in Ops],order='F')
1171    OpT = np.array([op[1] for op in Ops])
1172    Inv = SGData['SGInv']
1173    Cen = np.array([cen for cen in SGData['SGCen']],order='F')
1174   
1175    Nuniq,Uniq,iabsnt,mulp = pyspg.genhklpy(hklf,len(Ops),OpM,OpT,SGData['SGInv'],len(Cen),Cen)
1176    h,k,l,f = Uniq
1177    Uniq=np.array(zip(h[:Nuniq],k[:Nuniq],l[:Nuniq]))
1178    phi = f[:Nuniq]
1179    return iabsnt,mulp,Uniq,phi
1180   
1181def checkSSLaue(HKL,SGData,SSGData):
1182    #Laue check here - Toss HKL if outside unique Laue part
1183    h,k,l,m = HKL
1184    if SGData['SGLaue'] == '2/m':
1185        if SGData['SGUniq'] == 'a':
1186            if 'a' in SSGData['modSymb'] and h == 0 and m < 0:
1187                return False
1188            elif 'b' in SSGData['modSymb'] and k == 0 and l ==0 and m < 0:
1189                return False
1190            else:
1191                return True
1192        elif SGData['SGUniq'] == 'b':
1193            if 'b' in SSGData['modSymb'] and k == 0 and m < 0:
1194                return False
1195            elif 'a' in SSGData['modSymb'] and h == 0 and l ==0 and m < 0:
1196                return False
1197            else:
1198                return True
1199        elif SGData['SGUniq'] == 'c':
1200            if 'g' in SSGData['modSymb'] and l == 0 and m < 0:
1201                return False
1202            elif 'a' in SSGData['modSymb'] and h == 0 and k ==0 and m < 0:
1203                return False
1204            else:
1205                return True
1206    elif SGData['SGLaue'] == 'mmm':
1207        if 'a' in SSGData['modSymb']:
1208            if h == 0 and m < 0:
1209                return False
1210            else:
1211                return True
1212        elif 'b' in SSGData['modSymb']:
1213            if k == 0 and m < 0:
1214                return False
1215            else:
1216                return True
1217        elif 'g' in SSGData['modSymb']:
1218            if l == 0 and m < 0:
1219                return False
1220            else:
1221                return True
1222    else:   #tetragonal, trigonal, hexagonal (& triclinic?)
1223        if l == 0 and m < 0:
1224            return False
1225        else:
1226            return True
1227       
1228   
1229def checkSSextc(HKL,SSGData):
1230    Ops = SSGData['SSGOps']
1231    OpM = np.array([op[0] for op in Ops])
1232    OpT = np.array([op[1] for op in Ops])
1233    HKLS = np.array([HKL,-HKL])     #Freidel's Law
1234    DHKL = np.reshape(np.inner(HKLS,OpM)-HKL,(-1,4))
1235    PHKL = np.reshape(np.inner(HKLS,OpT),(-1,))
1236    for dhkl,phkl in zip(DHKL,PHKL)[1:]:    #skip identity
1237        if dhkl.any():
1238            continue
1239        else:
1240            if phkl%1.:
1241                return False
1242    return True
1243                                 
1244def GetOprPtrName(key):
1245    'Needs a doc string'
1246    OprPtrName = {
1247        '-6643':[   2,' 1bar ', 1],'6479' :[  10,'  2z  ', 2],'-6479':[   9,'  mz  ', 3],
1248        '6481' :[   7,'  my  ', 4],'-6481':[   6,'  2y  ', 5],'6641' :[   4,'  mx  ', 6],
1249        '-6641':[   3,'  2x  ', 7],'6591' :[  28,' m+-0 ', 8],'-6591':[  27,' 2+-0 ', 9],
1250        '6531' :[  25,' m110 ',10],'-6531':[  24,' 2110 ',11],'6537' :[  61,'  4z  ',12],
1251        '-6537':[  62,' -4z  ',13],'975'  :[  68,' 3+++1',14],'6456' :[ 114,'  3z1 ',15],
1252        '-489' :[  73,' 3+-- ',16],'483'  :[  78,' 3-+- ',17],'-969' :[  83,' 3--+ ',18],
1253        '819'  :[  22,' m+0- ',19],'-819' :[  21,' 2+0- ',20],'2431' :[  16,' m0+- ',21],
1254        '-2431':[  15,' 20+- ',22],'-657' :[  19,' m101 ',23],'657'  :[  18,' 2101 ',24],
1255        '1943' :[  48,' -4x  ',25],'-1943':[  47,'  4x  ',26],'-2429':[  13,' m011 ',27],
1256        '2429' :[  12,' 2011 ',28],'639'  :[  55,' -4y  ',29],'-639' :[  54,'  4y  ',30],
1257        '-6484':[ 146,' 2010 ', 4],'6484' :[ 139,' m010 ', 5],'-6668':[ 145,' 2100 ', 6],
1258        '6668' :[ 138,' m100 ', 7],'-6454':[ 148,' 2120 ',18],'6454' :[ 141,' m120 ',19],
1259        '-6638':[ 149,' 2210 ',20],'6638' :[ 142,' m210 ',21],              #search ends here
1260        '2223' :[  68,' 3+++2',39],
1261        '6538' :[ 106,'  6z1 ',40],'-2169':[  83,' 3--+2',41],'2151' :[  73,' 3+--2',42],
1262        '2205' :[  79,'-3-+-2',43],'-2205':[  78,' 3-+-2',44],'489'  :[  74,'-3+--1',45],
1263        '801'  :[  53,'  4y1 ',46],'1945' :[  47,'  4x3 ',47],'-6585':[  62,' -4z3 ',48],
1264        '6585' :[  61,'  4z3 ',49],'6584' :[ 114,'  3z2 ',50],'6666' :[ 106,'  6z5 ',51],
1265        '6643' :[   1,' Iden ',52],'-801' :[  55,' -4y1 ',53],'-1945':[  48,' -4x3 ',54],
1266        '-6666':[ 105,' -6z5 ',55],'-6538':[ 105,' -6z1 ',56],'-2223':[  69,'-3+++2',57],
1267        '-975' :[  69,'-3+++1',58],'-6456':[ 113,' -3z1 ',59],'-483' :[  79,'-3-+-1',60],
1268        '969'  :[  84,'-3--+1',61],'-6584':[ 113,' -3z2 ',62],'2169' :[  84,'-3--+2',63],
1269        '-2151':[  74,'-3+--2',64],'0':[0,' ????',0]
1270        }
1271    return OprPtrName[key]
1272
1273def GetKNsym(key):
1274    'Needs a doc string'
1275    KNsym = {
1276        '0'         :'    1   ','1'         :'   -1   ','64'        :'    2(x)','32'        :'    m(x)',
1277        '97'        :'  2/m(x)','16'        :'    2(y)','8'         :'    m(y)','25'        :'  2/m(y)',
1278        '2'         :'    2(z)','4'         :'    m(z)','7'         :'  2/m(z)','134217728' :'   2(yz)',
1279        '67108864'  :'   m(yz)','201326593' :' 2/m(yz)','2097152'   :'  2(0+-)','1048576'   :'  m(0+-)',
1280        '3145729'   :'2/m(0+-)','8388608'   :'   2(xz)','4194304'   :'   m(xz)','12582913'  :' 2/m(xz)',
1281        '524288'    :'  2(+0-)','262144'    :'  m(+0-)','796433'    :'2/m(+0-)','1024'      :'   2(xy)',
1282        '512'       :'   m(xy)','1537'      :' 2/m(xy)','256'       :'  2(+-0)','128'       :'  m(+-0)',
1283        '385'       :'2/m(+-0)','76'        :'  mm2(x)','52'        :'  mm2(y)','42'        :'  mm2(z)',
1284        '135266336' :' mm2(yz)','69206048'  :'mm2(0+-)','8650760'   :' mm2(xz)','4718600'   :'mm2(+0-)',
1285        '1156'      :' mm2(xy)','772'       :'mm2(+-0)','82'        :'  222   ','136314944' :'  222(x)',
1286        '8912912'   :'  222(y)','1282'      :'  222(z)','127'       :'  mmm   ','204472417' :'  mmm(x)',
1287        '13369369'  :'  mmm(y)','1927'      :'  mmm(z)','33554496'  :'  4(100)','16777280'  :' -4(100)',
1288        '50331745'  :'4/m(100)','169869394' :'422(100)','84934738'  :'-42m 100','101711948' :'4mm(100)',
1289        '254804095' :'4/mmm100','536870928 ':'  4(010)','268435472' :' -4(010)','805306393' :'4/m (10)',
1290        '545783890' :'422(010)','272891986' :'-42m 010','541327412' :'4mm(010)','818675839' :'4/mmm010',
1291        '2050'      :'  4(001)','4098'      :' -4(001)','6151'      :'4/m(001)','3410'      :'422(001)',
1292        '4818'      :'-42m 001','2730'      :'4mm(001)','8191'      :'4/mmm001','8192'      :'  3(111)',
1293        '8193'      :' -3(111)','2629888'   :' 32(111)','1319040'   :' 3m(111)','3940737'   :'-3m(111)',
1294        '32768'     :'  3(+--)','32769'     :' -3(+--)','10519552'  :' 32(+--)','5276160'   :' 3m(+--)',
1295        '15762945'  :'-3m(+--)','65536'     :'  3(-+-)','65537'     :' -3(-+-)','134808576' :' 32(-+-)',
1296        '67437056'  :' 3m(-+-)','202180097' :'-3m(-+-)','131072'    :'  3(--+)','131073'    :' -3(--+)',
1297        '142737664' :' 32(--+)','71434368'  :' 3m(--+)','214040961' :'-3m(--+)','237650'    :'   23   ',
1298        '237695'    :'   m3   ','715894098' :'   432  ','358068946' :'  -43m  ','1073725439':'   m3m  ',
1299        '68157504'  :' mm2d100','4456464'   :' mm2d010','642'       :' mm2d001','153092172' :'-4m2 100',
1300        '277348404' :'-4m2 010','5418'      :'-4m2 001','1075726335':'  6/mmm ','1074414420':'-6m2 100',
1301        '1075070124':'-6m2 120','1075069650':'   6mm  ','1074414890':'   622  ','1073758215':'   6/m  ',
1302        '1073758212':'   -6   ','1073758210':'    6   ','1073759865':'-3m(100)','1075724673':'-3m(120)',
1303        '1073758800':' 3m(100)','1075069056':' 3m(120)','1073759272':' 32(100)','1074413824':' 32(120)',
1304        '1073758209':'   -3   ','1073758208':'    3   ','1074135143':'mmm(100)','1075314719':'mmm(010)',
1305        '1073743751':'mmm(110)','1074004034':' mm2z100','1074790418':' mm2z010','1073742466':' mm2z110',
1306        '1074004004':'mm2(100)','1074790412':'mm2(010)','1073742980':'mm2(110)','1073872964':'mm2(120)',
1307        '1074266132':'mm2(210)','1073742596':'mm2(+-0)','1073872930':'222(100)','1074266122':'222(010)',
1308        '1073743106':'222(110)','1073741831':'2/m(001)','1073741921':'2/m(100)','1073741849':'2/m(010)',
1309        '1073743361':'2/m(110)','1074135041':'2/m(120)','1075314689':'2/m(210)','1073742209':'2/m(+-0)',
1310        '1073741828':' m(001) ','1073741888':' m(100) ','1073741840':' m(010) ','1073742336':' m(110) ',
1311        '1074003968':' m(120) ','1074790400':' m(210) ','1073741952':' m(+-0) ','1073741826':' 2(001) ',
1312        '1073741856':' 2(100) ','1073741832':' 2(010) ','1073742848':' 2(110) ','1073872896':' 2(120) ',
1313        '1074266112':' 2(210) ','1073742080':' 2(+-0) ','1073741825':'   -1   '
1314        }
1315    return KNsym[key]       
1316
1317def GetNXUPQsym(siteSym):
1318    '''       
1319    The codes XUPQ are for lookup of symmetry constraints for position(X), thermal parm(U) & magnetic moments
1320    (P&Q-not used in GSAS-II)
1321    '''
1322    NXUPQsym = {
1323        '    1   ':(28,29,28,28),'   -1   ':( 1,29,28, 0),'    2(x)':(12,18,12,25),'    m(x)':(25,18,12,25),
1324        '  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),
1325        '    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),
1326        '   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),
1327        '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),
1328        '  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),
1329        '   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),
1330        '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),
1331        ' mm2(yz)':(10,13, 0,-1),'mm2(0+-)':(11,13, 0,-1),' mm2(xz)':( 8,12, 0,-1),'mm2(+0-)':( 9,12, 0,-1),
1332        ' mm2(xy)':( 6,11, 0,-1),'mm2(+-0)':( 7,11, 0,-1),'  222   ':( 1,10, 0,-1),'  222(x)':( 1,13, 0,-1),
1333        '  222(y)':( 1,12, 0,-1),'  222(z)':( 1,11, 0,-1),'  mmm   ':( 1,10, 0,-1),'  mmm(x)':( 1,13, 0,-1),
1334        '  mmm(y)':( 1,12, 0,-1),'  mmm(z)':( 1,11, 0,-1),'  4(100)':(12, 4,12, 0),' -4(100)':( 1, 4,12, 0),
1335        '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),
1336        '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),
1337        '422(010)':( 1, 3, 0,-1),'-42m 010':( 1, 3, 0,-1),'4mm(010)':(13, 3, 0,-1),'4/mmm010':(1, 3, 0,-1,),
1338        '  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),
1339        '-42m 001':( 1, 2, 0,-1),'4mm(001)':(14, 2, 0,-1),'4/mmm001':( 1, 2, 0,-1),'  3(111)':( 2, 5, 2, 0),
1340        ' -3(111)':( 1, 5, 2, 0),' 32(111)':( 1, 5, 0, 2),' 3m(111)':( 2, 5, 0, 2),'-3m(111)':( 1, 5, 0,-1),
1341        '  3(+--)':( 5, 8, 5, 0),' -3(+--)':( 1, 8, 5, 0),' 32(+--)':( 1, 8, 0, 5),' 3m(+--)':( 5, 8, 0, 5),
1342        '-3m(+--)':( 1, 8, 0,-1),'  3(-+-)':( 4, 7, 4, 0),' -3(-+-)':( 1, 7, 4, 0),' 32(-+-)':( 1, 7, 0, 4),
1343        ' 3m(-+-)':( 4, 7, 0, 4),'-3m(-+-)':( 1, 7, 0,-1),'  3(--+)':( 3, 6, 3, 0),' -3(--+)':( 1, 6, 3, 0),
1344        ' 32(--+)':( 1, 6, 0, 3),' 3m(--+)':( 3, 6, 0, 3),'-3m(--+)':( 1, 6, 0,-1),'   23   ':( 1, 1, 0, 0),
1345        '   m3   ':( 1, 1, 0, 0),'   432  ':( 1, 1, 0, 0),'  -43m  ':( 1, 1, 0, 0),'   m3m  ':( 1, 1, 0, 0),
1346        ' mm2d100':(12,13, 0,-1),' mm2d010':(13,12, 0,-1),' mm2d001':(14,11, 0,-1),'-4m2 100':( 1, 4, 0,-1),
1347        '-4m2 010':( 1, 3, 0,-1),'-4m2 001':( 1, 2, 0,-1),'  6/mmm ':( 1, 9, 0,-1),'-6m2 100':( 1, 9, 0,-1),
1348        '-6m2 120':( 1, 9, 0,-1),'   6mm  ':(14, 9, 0,-1),'   622  ':( 1, 9, 0,-1),'   6/m  ':( 1, 9,14,-1),
1349        '   -6   ':( 1, 9,14, 0),'    6   ':(14, 9,14, 0),'-3m(100)':( 1, 9, 0,-1),'-3m(120)':( 1, 9, 0,-1),
1350        ' 3m(100)':(14, 9, 0,14),' 3m(120)':(14, 9, 0,14),' 32(100)':( 1, 9, 0,14),' 32(120)':( 1, 9, 0,14),
1351        '   -3   ':( 1, 9,14, 0),'    3   ':(14, 9,14, 0),'mmm(100)':( 1,14, 0,-1),'mmm(010)':( 1,15, 0,-1),
1352        'mmm(110)':( 1,11, 0,-1),' mm2z100':(14,14, 0,-1),' mm2z010':(14,15, 0,-1),' mm2z110':(14,11, 0,-1),
1353        'mm2(100)':(12,14, 0,-1),'mm2(010)':(13,15, 0,-1),'mm2(110)':( 6,11, 0,-1),'mm2(120)':(15,14, 0,-1),
1354        'mm2(210)':(16,15, 0,-1),'mm2(+-0)':( 7,11, 0,-1),'222(100)':( 1,14, 0,-1),'222(010)':( 1,15, 0,-1),
1355        '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),
1356        '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),
1357        ' m(001) ':(23,16,14,23),' m(100) ':(26,25,12,26),' m(010) ':(27,28,13,27),' m(110) ':(18,19, 6,18),
1358        ' m(120) ':(24,27,15,24),' m(210) ':(25,26,16,25),' m(+-0) ':(17,20, 7,17),' 2(001) ':(14,16,14,23),
1359        ' 2(100) ':(12,25,12,26),' 2(010) ':(13,28,13,27),' 2(110) ':( 6,19, 6,18),' 2(120) ':(15,27,15,24),
1360        ' 2(210) ':(16,26,16,25),' 2(+-0) ':( 7,20, 7,17),'   -1   ':( 1,29,28, 0)
1361        }
1362    return NXUPQsym[siteSym]
1363
1364def GetCSxinel(siteSym): 
1365    'Needs a doc string'
1366    CSxinel = [[],                         # 0th empty - indices are Fortran style
1367        [[0,0,0],[ 0.0, 0.0, 0.0]],      #1  0  0  0
1368        [[1,1,1],[ 1.0, 1.0, 1.0]],      #2  X  X  X
1369        [[1,1,1],[ 1.0, 1.0,-1.0]],      #3  X  X -X
1370        [[1,1,1],[ 1.0,-1.0, 1.0]],      #4  X -X  X
1371        [[1,1,1],[ 1.0,-1.0,-1.0]],      #5 -X  X  X
1372        [[1,1,0],[ 1.0, 1.0, 0.0]],      #6  X  X  0
1373        [[1,1,0],[ 1.0,-1.0, 0.0]],      #7  X -X  0
1374        [[1,0,1],[ 1.0, 0.0, 1.0]],      #8  X  0  X
1375        [[1,0,1],[ 1.0, 0.0,-1.0]],      #9  X  0 -X
1376        [[0,1,1],[ 0.0, 1.0, 1.0]],      #10  0  Y  Y
1377        [[0,1,1],[ 0.0, 1.0,-1.0]],      #11 0  Y -Y
1378        [[1,0,0],[ 1.0, 0.0, 0.0]],      #12  X  0  0
1379        [[0,1,0],[ 0.0, 1.0, 0.0]],      #13  0  Y  0
1380        [[0,0,1],[ 0.0, 0.0, 1.0]],      #14  0  0  Z
1381        [[1,1,0],[ 1.0, 2.0, 0.0]],      #15  X 2X  0
1382        [[1,1,0],[ 2.0, 1.0, 0.0]],      #16 2X  X  0
1383        [[1,1,2],[ 1.0, 1.0, 1.0]],      #17  X  X  Z
1384        [[1,1,2],[ 1.0,-1.0, 1.0]],      #18  X -X  Z
1385        [[1,2,1],[ 1.0, 1.0, 1.0]],      #19  X  Y  X
1386        [[1,2,1],[ 1.0, 1.0,-1.0]],      #20  X  Y -X
1387        [[1,2,2],[ 1.0, 1.0, 1.0]],      #21  X  Y  Y
1388        [[1,2,2],[ 1.0, 1.0,-1.0]],      #22  X  Y -Y
1389        [[1,2,0],[ 1.0, 1.0, 0.0]],      #23  X  Y  0
1390        [[1,0,2],[ 1.0, 0.0, 1.0]],      #24  X  0  Z
1391        [[0,1,2],[ 0.0, 1.0, 1.0]],      #25  0  Y  Z
1392        [[1,1,2],[ 1.0, 2.0, 1.0]],      #26  X 2X  Z
1393        [[1,1,2],[ 2.0, 1.0, 1.0]],      #27 2X  X  Z
1394        [[1,2,3],[ 1.0, 1.0, 1.0]],      #28  X  Y  Z
1395        ]
1396    indx = GetNXUPQsym(siteSym)
1397    return CSxinel[indx[0]]
1398   
1399def GetCSuinel(siteSym):
1400    "returns Uij terms, multipliers, GUI flags & Uiso2Uij multipliers"
1401    CSuinel = [[],                                             # 0th empty - indices are Fortran style
1402        [[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
1403        [[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
1404        [[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
1405        [[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
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]],    #5  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]],    #6  A  A  A  D -D -D
1408        [[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
1409        [[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
1410        [[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
1411        [[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
1412        [[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
1413        [[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
1414        [[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
1415        [[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
1416        [[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
1417        [[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
1418        [[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
1419        [[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
1420        [[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
1421        [[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
1422        [[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
1423        [[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
1424        [[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
1425        [[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
1426        [[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
1427        [[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
1428        [[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
1429        [[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
1430        [[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
1431        ]
1432    indx = GetNXUPQsym(siteSym)
1433    return CSuinel[indx[1]]
1434   
1435def getTauT(tau,sop,ssop,XYZ):
1436    ssopinv = nl.inv(ssop[0])
1437    mst = ssopinv[3][:3]
1438    epsinv = ssopinv[3][3]
1439    sdet = nl.det(sop[0])
1440    ssdet = nl.det(ssop[0])
1441    dtau = mst*(XYZ-sop[1])-epsinv*ssop[1][3]
1442    dT = 1.0
1443    if np.any(dtau%.5):
1444        dT = np.tan(np.pi*np.sum(dtau%.5))
1445    tauT = np.inner(mst,XYZ-sop[1])+epsinv*(tau-ssop[1][3])
1446    return sdet,ssdet,dtau,dT,tauT
1447   
1448def OpsfromStringOps(A,SGData,SSGData):
1449    SGOps = SGData['SGOps']
1450    SSGOps = SSGData['SSGOps']
1451    Ax = A.split('+')
1452    Ax[0] = int(Ax[0])
1453    iC = 1
1454    if Ax[0] < 0:
1455        iC = -1
1456    Ax[0] = abs(Ax[0])
1457    nA = Ax[0]%100-1
1458    return SGOps[nA],SSGOps[nA],iC
1459   
1460def GetSSfxuinel(waveType,nH,XYZ,SGData,SSGData,debug=False):
1461   
1462    def orderParms(CSI):
1463        parms = [0,]
1464        for csi in CSI:
1465            for i in [0,1,2]:
1466                if csi[i] not in parms:
1467                    parms.append(csi[i])
1468        for csi in CSI:
1469            for i in [0,1,2]:
1470                csi[i] = parms.index(csi[i])
1471        return CSI
1472       
1473    def fracCrenel(tau,Toff,Twid):
1474        Tau = (tau-Toff[:,np.newaxis])%1.
1475        A = np.where(Tau<Twid[:,np.newaxis],1.,0.)
1476        return A
1477       
1478    def fracFourier(tau,nH,fsin,fcos):
1479        SA = np.sin(2.*nH*np.pi*tau)
1480        CB = np.cos(2.*nH*np.pi*tau)
1481        A = SA[np.newaxis,np.newaxis,:]*fsin[:,:,np.newaxis]
1482        B = CB[np.newaxis,np.newaxis,:]*fcos[:,:,np.newaxis]
1483        return A+B
1484       
1485    def posFourier(tau,nH,psin,pcos):
1486        SA = np.sin(2*nH*np.pi*tau)
1487        CB = np.cos(2*nH*np.pi*tau)
1488        A = SA[np.newaxis,np.newaxis,:]*psin[:,:,np.newaxis]
1489        B = CB[np.newaxis,np.newaxis,:]*pcos[:,:,np.newaxis]
1490        return A+B   
1491
1492    def posSawtooth(tau,Toff,slopes):
1493        Tau = (tau-Toff)%1.
1494        A = slopes[:,np.newaxis]*Tau
1495        return A
1496   
1497    def posZigZag(tau,Tmm,XYZmax):
1498        DT = Tmm[1]-Tmm[0]
1499        slopeUp = 2.*XYZmax/DT
1500        slopeDn = 2.*XYZmax/(1.-DT)
1501        A = np.array([np.where(Tmm[0] < t%1. <= Tmm[1],-XYZmax+slopeUp*((t-Tmm[0])%1.),XYZmax-slopeDn*((t-Tmm[1])%1.)) for t in tau])
1502        return A
1503
1504    def posBlock(tau,Tmm,XYZmax):
1505        A = np.array([np.where(Tmm[0] < t <= Tmm[1],XYZmax,-XYZmax) for t in tau])
1506        return A
1507       
1508    def DoFrac():
1509        delt2 = np.eye(2)*0.001
1510        FSC = np.ones(2,dtype='i')
1511        VFSC = np.ones(2)
1512        CSI = [np.zeros((2),dtype='i'),np.zeros(2)]
1513        if 'Crenel' in waveType:
1514            dF = np.zeros_like(tau)
1515        else:
1516            dF = fracFourier(tau,nH,delt2[:1],delt2[1:]).squeeze()
1517        dFT = np.zeros_like(dF)
1518        dFTP = []
1519        for i in SdIndx:
1520            sop = Sop[i]
1521            ssop = SSop[i]           
1522            sdet,ssdet,dtau,dT,tauT = getTauT(tau,sop,ssop,XYZ)
1523            fsc = np.ones(2,dtype='i')
1524            if 'Crenel' in waveType:
1525                dFT = np.zeros_like(tau)
1526                fsc = [1,1]
1527            else:   #Fourier
1528                dFT = fracFourier(tauT,nH,delt2[:1],delt2[1:]).squeeze()
1529                dFT = nl.det(sop[0])*dFT
1530                dFT = dFT[:,np.argsort(tauT)]
1531                dFT[0] *= ssdet
1532                dFT[1] *= sdet
1533                dFTP.append(dFT)
1534           
1535                if np.any(dtau%.5) and ('1/2' in SSGData['modSymb'] or '1' in SSGData['modSymb']):
1536                    fsc = [1,1]
1537                    CSI = [[[1,0],[1,0]],[[1.,0.],[1/dT,0.]]]
1538                    FSC = np.zeros(2,dtype='i')
1539                    return CSI,dF,dFTP
1540                else:
1541                    for i in range(2):
1542                        if np.allclose(dF[i,:],dFT[i,:],atol=1.e-6):
1543                            fsc[i] = 1
1544                        else:
1545                            fsc[i] = 0
1546                    FSC &= fsc
1547                    if debug: print SSMT2text(ssop).replace(' ',''),sdet,ssdet,epsinv,fsc
1548        n = -1
1549        for i,F in enumerate(FSC):
1550            if F:
1551                n += 1
1552                CSI[0][i] = n+1
1553                CSI[1][i] = 1.0
1554       
1555        return CSI,dF,dFTP
1556       
1557    def DoXYZ():
1558        delt4 = np.ones(4)*0.001
1559        delt5 = np.ones(5)*0.001
1560        delt6 = np.eye(6)*0.001
1561        if 'Fourier' in waveType:
1562            dX = posFourier(tau,nH,delt6[:3],delt6[3:]) #+np.array(XYZ)[:,np.newaxis,np.newaxis]
1563              #3x6x12 modulated position array (X,Spos,tau)& force positive
1564            CSI = [np.zeros((6,3),dtype='i'),np.zeros((6,3))]
1565        elif waveType == 'Sawtooth':
1566            dX = posSawtooth(tau,delt4[0],delt4[1:])
1567            CSI = [np.array([[1,0,0],[2,0,0],[3,0,0],[4,0,0]]),
1568                np.array([[1.0,.0,.0],[1.0,.0,.0],[1.0,.0,.0],[1.0,.0,.0]])]
1569        elif waveType in ['ZigZag','Block']:
1570            if waveType == 'ZigZag':
1571                dX = posZigZag(tau,delt5[:2],delt5[2:])
1572            else:
1573                dX = posBlock(tau,delt5[:2],delt5[2:])
1574            CSI = [np.array([[1,0,0],[2,0,0],[3,0,0],[4,0,0],[5,0,0]]),
1575                np.array([[1.0,.0,.0],[1.0,.0,.0],[1.0,.0,.0],[1.0,.0,.0],[1.0,.0,.0]])]
1576        XSC = np.ones(6,dtype='i')
1577        dXTP = []
1578        for i in SdIndx:
1579            sop = Sop[i]
1580            ssop = SSop[i]
1581            sdet,ssdet,dtau,dT,tauT = getTauT(tau,sop,ssop,XYZ)
1582            xsc = np.ones(6,dtype='i')
1583            if 'Fourier' in waveType:
1584                dXT = posFourier(np.sort(tauT),nH,delt6[:3],delt6[3:])   #+np.array(XYZ)[:,np.newaxis,np.newaxis]
1585            elif waveType == 'Sawtooth':
1586                dXT = posSawtooth(tauT,delt4[0],delt4[1:])+np.array(XYZ)[:,np.newaxis,np.newaxis]
1587            elif waveType == 'ZigZag':
1588                dXT = posZigZag(tauT,delt5[:2],delt5[2:])+np.array(XYZ)[:,np.newaxis,np.newaxis]
1589            elif waveType == 'Block':
1590                dXT = posBlock(tauT,delt5[:2],delt5[2:])+np.array(XYZ)[:,np.newaxis,np.newaxis]
1591            dXT = np.inner(sop[0],dXT.T)    # X modulations array(3x6x49) -> array(3x49x6)
1592            dXT = np.swapaxes(dXT,1,2)      # back to array(3x6x49)
1593            dXT[:,:3,:] *= (ssdet*sdet)            # modify the sin component
1594            dXTP.append(dXT)
1595            if waveType == 'Fourier':
1596                for i in range(3):
1597                    if not np.allclose(dX[i,i,:],dXT[i,i,:]):
1598                        xsc[i] = 0
1599                    if not np.allclose(dX[i,i+3,:],dXT[i,i+3,:]):
1600                        xsc[i+3] = 0
1601                if np.any(dtau%.5) and ('1/2' in SSGData['modSymb'] or '1' in SSGData['modSymb']):
1602                    xsc[3:6] = 0
1603                    CSI = [[[1,0,0],[2,0,0],[3,0,0], [1,0,0],[2,0,0],[3,0,0]],
1604                        [[1.,0.,0.],[1.,0.,0.],[1.,0.,0.], [1.,0.,0.],[1.,0.,0.],[1.,0.,0.]]]                   
1605                    if '(x)' in siteSym:
1606                        CSI[1][3:] = [1./dT,0.,0.],[-dT,0.,0.],[-dT,0.,0.]
1607                        if 'm' in siteSym and len(SdIndx) == 1:
1608                            CSI[1][3:] = [-dT,0.,0.],[1./dT,0.,0.],[1./dT,0.,0.]
1609                    elif '(y)' in siteSym:
1610                        CSI[1][3:] = [-dT,0.,0.],[1./dT,0.,0.],[-dT,0.,0.]
1611                        if 'm' in siteSym and len(SdIndx) == 1:
1612                            CSI[1][3:] = [1./dT,0.,0.],[-dT,0.,0.],[1./dT,0.,0.]
1613                    elif '(z)' in siteSym:
1614                        CSI[1][3:] = [-dT,0.,0.],[-dT,0.,0.],[1./dT,0.,0.]
1615                        if 'm' in siteSym and len(SdIndx) == 1:
1616                            CSI[1][3:] = [1./dT,0.,0.],[1./dT,0.,0.],[-dT,0.,0.]
1617                if '4/mmm' in laue:
1618                    if np.any(dtau%.5) and '1/2' in SSGData['modSymb']:
1619                        if '(xy)' in siteSym:
1620                            CSI[0] = [[1,0,0],[1,0,0],[2,0,0], [1,0,0],[1,0,0],[2,0,0]]
1621                            CSI[1][3:] = [[1./dT,0.,0.],[1./dT,0.,0.],[-dT,0.,0.]]
1622                    if '(xy)' in siteSym or '(+-0)' in siteSym:
1623                        mul = 1
1624                        if '(+-0)' in siteSym:
1625                            mul = -1
1626                        if np.allclose(dX[0,0,:],dXT[1,0,:]):
1627                            CSI[0][3:5] = [[11,0,0],[11,0,0]]
1628                            CSI[1][3:5] = [[1.,0,0],[mul,0,0]]
1629                            xsc[3:5] = 0
1630                        if np.allclose(dX[0,3,:],dXT[0,4,:]):
1631                            CSI[0][:2] = [[12,0,0],[12,0,0]]
1632                            CSI[1][:2] = [[1.,0,0],[mul,0,0]]
1633                            xsc[:2] = 0
1634            XSC &= xsc
1635            if debug: print SSMT2text(ssop).replace(' ',''),sdet,ssdet,epsinv,xsc
1636        if waveType == 'Fourier':
1637            n = -1
1638            if debug: print XSC
1639            for i,X in enumerate(XSC):
1640                if X:
1641                    n += 1
1642                    CSI[0][i][0] = n+1
1643                    CSI[1][i][0] = 1.0
1644       
1645        return CSI,dX,dXTP
1646       
1647    def DoUij():
1648        tau = np.linspace(0,1,49,True)
1649        delt12 = np.eye(12)*0.0001
1650        dU = posFourier(tau,nH,delt12[:6],delt12[6:])                  #Uij modulations - 6x12x12 array
1651        CSI = [np.zeros((12,3),dtype='i'),np.zeros((12,3))]
1652        USC = np.ones(12,dtype='i')
1653        dUTP = []
1654        for i in SdIndx:
1655            sop = Sop[i]
1656            ssop = SSop[i]
1657            sdet,ssdet,dtau,dT,tauT = getTauT(tau,sop,ssop,XYZ)
1658            usc = np.ones(12,dtype='i')
1659            dUT = posFourier(tauT,nH,delt12[:6],delt12[6:])                  #Uij modulations - 6x12x49 array
1660            dUijT = np.rollaxis(np.rollaxis(np.array(Uij2U(dUT)),3),3)    #convert dUT to 12x49x3x3
1661            dUijT = np.rollaxis(np.inner(np.inner(sop[0],dUijT),sop[0].T),3) #transform by sop - 3x3x12x49
1662            dUT = np.array(U2Uij(dUijT))    #convert to 6x12x49
1663            dUT = dUT[:,:,np.argsort(tauT)]
1664            dUT[:,:6,:] *=(ssdet*sdet)
1665            dUTP.append(dUT)
1666            if np.any(dtau%.5) and ('1/2' in SSGData['modSymb'] or '1' in SSGData['modSymb']):
1667                CSI = [[[1,0,0],[2,0,0],[3,0,0],[4,0,0],[5,0,0],[6,0,0], 
1668                [1,0,0],[2,0,0],[3,0,0],[4,0,0],[5,0,0],[6,0,0]],
1669                [[1.,0.,0.],[1.,0.,0.],[1.,0.,0.], [1.,0.,0.],[1.,0.,0.],[1.,0.,0.],
1670                [1./dT,0.,0.],[1./dT,0.,0.],[1./dT,0.,0.], [1.,0.,0.],[1.,0.,0.],[1.,0.,0.]]]
1671                if 'mm2(x)' in siteSym:
1672                    CSI[1][9:] = [0.,0.,0.],[-dT,0.,0.],[0.,0.,0.]
1673                    USC = [1,1,1,0,1,0,1,1,1,0,1,0]
1674                elif '(xy)' in siteSym:
1675                    CSI[0] = [[1,0,0],[1,0,0],[2,0,0],[3,0,0],[4,0,0],[4,0,0],
1676                        [1,0,0],[1,0,0],[2,0,0],[3,0,0],[4,0,0],[4,0,0]]
1677                    CSI[1][9:] = [[1./dT,0.,0.],[-dT,0.,0.],[-dT,0.,0.]]
1678                    USC = [1,1,1,1,1,1,1,1,1,1,1,1]                             
1679                elif '(x)' in siteSym:
1680                    CSI[1][9:] = [-dT,0.,0.],[-dT,0.,0.],[1./dT,0.,0.]
1681                elif '(y)' in siteSym:
1682                    CSI[1][9:] = [-dT,0.,0.],[1./dT,0.,0.],[-dT,0.,0.]
1683                elif '(z)' in siteSym:
1684                    CSI[1][9:] = [1./dT,0.,0.],[-dT,0.,0.],[-dT,0.,0.]
1685                for i in range(6):
1686                    if not USC[i]:
1687                        CSI[0][i] = [0,0,0]
1688                        CSI[1][i] = [0.,0.,0.]
1689                        CSI[0][i+6] = [0,0,0]
1690                        CSI[1][i+6] = [0.,0.,0.]
1691            else:                       
1692                for i in range(6):
1693                    if not np.allclose(dU[i,i,:],dUT[i,i,:]):  #sin part
1694                        usc[i] = 0
1695                    if not np.allclose(dU[i,i+6,:],dUT[i,i+6,:]):   #cos part
1696                        usc[i+6] = 0
1697                if np.any(dUT[1,0,:]):
1698                    if '4/m' in siteSym:
1699                        CSI[0][6:8] = [[12,0,0],[12,0,0]]
1700                        if ssop[1][3]:
1701                            CSI[1][6:8] = [[1.,0.,0.],[-1.,0.,0.]]
1702                            usc[9] = 1
1703                        else:
1704                            CSI[1][6:8] = [[1.,0.,0.],[1.,0.,0.]]
1705                            usc[9] = 0
1706                    elif '4' in siteSym:
1707                        CSI[0][6:8] = [[12,0,0],[12,0,0]]
1708                        CSI[0][:2] = [[11,0,0],[11,0,0]]
1709                        if ssop[1][3]:
1710                            CSI[1][:2] = [[1.,0.,0.],[-1.,0.,0.]]
1711                            CSI[1][6:8] = [[1.,0.,0.],[-1.,0.,0.]]
1712                            usc[2] = 0
1713                            usc[8] = 0
1714                            usc[3] = 1
1715                            usc[9] = 1
1716                        else:
1717                            CSI[1][:2] = [[1.,0.,0.],[1.,0.,0.]]
1718                            CSI[1][6:8] = [[1.,0.,0.],[1.,0.,0.]]
1719                            usc[2] = 1
1720                            usc[8] = 1
1721                            usc[3] = 0               
1722                            usc[9] = 0
1723                    elif 'xy' in siteSym or '+-0' in siteSym:
1724                        if np.allclose(dU[0,0,:],dUT[0,1,:]*sdet):
1725                            CSI[0][4:6] = [[12,0,0],[12,0,0]]
1726                            CSI[0][6:8] = [[11,0,0],[11,0,0]]
1727                            CSI[1][4:6] = [[1.,0.,0.],[sdet,0.,0.]]
1728                            CSI[1][6:8] = [[1.,0.,0.],[sdet,0.,0.]]
1729                            usc[4:6] = 0
1730                            usc[6:8] = 0
1731                       
1732                if debug: print SSMT2text(ssop).replace(' ',''),sdet,ssdet,epsinv,usc
1733            USC &= usc
1734        if debug: print USC
1735        if not np.any(dtau%.5):
1736            n = -1
1737            for i,U in enumerate(USC):
1738                if U:
1739                    n += 1
1740                    CSI[0][i][0] = n+1
1741                    CSI[1][i][0] = 1.0
1742
1743        return CSI,dU,dUTP
1744       
1745    if debug: print 'super space group: ',SSGData['SSpGrp']
1746    CSI = {'Sfrac':[[[1,0],[2,0]],[[1.,0.],[1.,0.]]],
1747        'Spos':[[[1,0,0],[2,0,0],[3,0,0], [4,0,0],[5,0,0],[6,0,0]],
1748            [[1.,0.,0.],[1.,0.,0.],[1.,0.,0.], [1.,0.,0.],[1.,0.,0.],[1.,0.,0.]]],    #sin & cos
1749        'Sadp':[[[1,0,0],[2,0,0],[3,0,0],[4,0,0],[5,0,0],[6,0,0], 
1750            [7,0,0],[8,0,0],[9,0,0],[10,0,0],[11,0,0],[12,0,0]],
1751            [[1.,0.,0.],[1.,0.,0.],[1.,0.,0.], [1.,0.,0.],[1.,0.,0.],[1.,0.,0.],
1752            [1.,0.,0.],[1.,0.,0.],[1.,0.,0.], [1.,0.,0.],[1.,0.,0.],[1.,0.,0.]]],
1753        'Smag':[[[1,0,0],[2,0,0],[3,0,0], [4,0,0],[5,0,0],[6,0,0]],
1754            [[1.,0.,0.],[1.,0.,0.],[1.,0.,0.], [1.,0.,0.],[1.,0.,0.],[1.,0.,0.]]],}
1755    xyz = np.array(XYZ)%1.
1756    xyzt = np.array(XYZ+[0,])%1.
1757    SGOps = copy.deepcopy(SGData['SGOps'])
1758    laue = SGData['SGLaue']
1759    siteSym = SytSym(XYZ,SGData)[0].strip()
1760    if debug: print 'siteSym: ',siteSym
1761    if siteSym == '1':   #"1" site symmetry
1762        if debug:
1763            return CSI,None,None,None,None
1764        else:
1765            return CSI
1766    elif siteSym == '-1':   #"-1" site symmetry
1767        CSI['Sfrac'][0] = [[1,0],[0,0]]
1768        CSI['Spos'][0] = [[1,0,0],[2,0,0],[3,0,0], [0,0,0],[0,0,0],[0,0,0]]
1769        CSI['Sadp'][0] = [[0,0,0],[0,0,0],[0,0,0],[0,0,0],[0,0,0],[0,0,0], 
1770        [1,0,0],[2,0,0],[3,0,0],[4,0,0],[5,0,0],[6,0,0]]
1771        if debug:
1772            return CSI,None,None,None,None
1773        else:
1774            return CSI
1775    SSGOps = copy.deepcopy(SSGData['SSGOps'])
1776    #expand ops to include inversions if any
1777    if SGData['SGInv']:
1778        for op,sop in zip(SGData['SGOps'],SSGData['SSGOps']):
1779            SGOps.append([-op[0],-op[1]%1.])
1780            SSGOps.append([-sop[0],-sop[1]%1.])
1781    #build set of sym ops around special position       
1782    SSop = []
1783    Sop = []
1784    Sdtau = []
1785    for iop,Op in enumerate(SGOps):         
1786        nxyz = (np.inner(Op[0],xyz)+Op[1])%1.
1787        if np.allclose(xyz,nxyz,1.e-4) and iop and MT2text(Op).replace(' ','') != '-X,-Y,-Z':
1788            SSop.append(SSGOps[iop])
1789            Sop.append(SGOps[iop])
1790            ssopinv = nl.inv(SSGOps[iop][0])
1791            mst = ssopinv[3][:3]
1792            epsinv = ssopinv[3][3]
1793            Sdtau.append(np.sum(mst*(XYZ-SGOps[iop][1])-epsinv*SSGOps[iop][1][3]))
1794    SdIndx = np.argsort(np.array(Sdtau))     # just to do in sensible order
1795    if debug: print 'special pos super operators: ',[SSMT2text(ss).replace(' ','') for ss in SSop]
1796    #setup displacement arrays
1797    tau = np.linspace(-1,1,49,True)
1798    #make modulation arrays - one parameter at a time
1799    #site fractions
1800    CSI['Sfrac'],dF,dFTP = DoFrac()
1801    #positions
1802    CSI['Spos'],dX,dXTP = DoXYZ()       
1803    #anisotropic thermal motion
1804    CSI['Sadp'],dU,dUTP = DoUij()
1805    CSI['Spos'][0] = orderParms(CSI['Spos'][0])
1806    CSI['Sadp'][0] = orderParms(CSI['Sadp'][0])           
1807    if debug:
1808        return CSI,tau,[dF,dFTP],[dX,dXTP],[dU,dUTP]
1809    else:
1810        return CSI
1811   
1812def MustrainNames(SGData):
1813    'Needs a doc string'
1814    laue = SGData['SGLaue']
1815    uniq = SGData['SGUniq']
1816    if laue in ['m3','m3m']:
1817        return ['S400','S220']
1818    elif laue in ['6/m','6/mmm','3m1']:
1819        return ['S400','S004','S202']
1820    elif laue in ['31m','3']:
1821        return ['S400','S004','S202','S211']
1822    elif laue in ['3R','3mR']:
1823        return ['S400','S220','S310','S211']
1824    elif laue in ['4/m','4/mmm']:
1825        return ['S400','S004','S220','S022']
1826    elif laue in ['mmm']:
1827        return ['S400','S040','S004','S220','S202','S022']
1828    elif laue in ['2/m']:
1829        SHKL = ['S400','S040','S004','S220','S202','S022']
1830        if uniq == 'a':
1831            SHKL += ['S013','S031','S211']
1832        elif uniq == 'b':
1833            SHKL += ['S301','S103','S121']
1834        elif uniq == 'c':
1835            SHKL += ['S130','S310','S112']
1836        return SHKL
1837    else:
1838        SHKL = ['S400','S040','S004','S220','S202','S022']
1839        SHKL += ['S310','S103','S031','S130','S301','S013']
1840        SHKL += ['S211','S121','S112']
1841        return SHKL
1842       
1843def HStrainVals(HSvals,SGData):
1844    laue = SGData['SGLaue']
1845    uniq = SGData['SGUniq']
1846    DIJ = np.zeros(6)
1847    if laue in ['m3','m3m']:
1848        DIJ[:3] = [HSvals[0],HSvals[0],HSvals[0]]
1849    elif laue in ['6/m','6/mmm','3m1','31m','3']:
1850        DIJ[:4] = [HSvals[0],HSvals[0],HSvals[1],HSvals[0]]
1851    elif laue in ['3R','3mR']:
1852        DIJ = [HSvals[0],HSvals[0],HSvals[0],HSvals[1],HSvals[1],HSvals[1]]
1853    elif laue in ['4/m','4/mmm']:
1854        DIJ[:3] = [HSvals[0],HSvals[0],HSvals[1]]
1855    elif laue in ['mmm']:
1856        DIJ[:3] = [HSvals[0],HSvals[1],HSvals[2]]
1857    elif laue in ['2/m']:
1858        DIJ[:3] = [HSvals[0],HSvals[1],HSvals[2]]
1859        if uniq == 'a':
1860            DIJ[5] = HSvals[3]
1861        elif uniq == 'b':
1862            DIJ[4] = HSvals[3]
1863        elif uniq == 'c':
1864            DIJ[3] = HSvals[3]
1865    else:
1866        DIJ = [HSvals[0],HSvals[1],HSvals[2],HSvals[3],HSvals[4],HSvals[5]]
1867    return DIJ
1868
1869def HStrainNames(SGData):
1870    'Needs a doc string'
1871    laue = SGData['SGLaue']
1872    uniq = SGData['SGUniq']
1873    if laue in ['m3','m3m']:
1874        return ['D11','eA']         #add cubic strain term
1875    elif laue in ['6/m','6/mmm','3m1','31m','3']:
1876        return ['D11','D33']
1877    elif laue in ['3R','3mR']:
1878        return ['D11','D12']
1879    elif laue in ['4/m','4/mmm']:
1880        return ['D11','D33']
1881    elif laue in ['mmm']:
1882        return ['D11','D22','D33']
1883    elif laue in ['2/m']:
1884        Dij = ['D11','D22','D33']
1885        if uniq == 'a':
1886            Dij += ['D23']
1887        elif uniq == 'b':
1888            Dij += ['D13']
1889        elif uniq == 'c':
1890            Dij += ['D12']
1891        return Dij
1892    else:
1893        Dij = ['D11','D22','D33','D12','D13','D23']
1894        return Dij
1895   
1896def MustrainCoeff(HKL,SGData):
1897    'Needs a doc string'
1898    #NB: order of terms is the same as returned by MustrainNames
1899    laue = SGData['SGLaue']
1900    uniq = SGData['SGUniq']
1901    h,k,l = HKL
1902    Strm = []
1903    if laue in ['m3','m3m']:
1904        Strm.append(h**4+k**4+l**4)
1905        Strm.append(3.0*((h*k)**2+(h*l)**2+(k*l)**2))
1906    elif laue in ['6/m','6/mmm','3m1']:
1907        Strm.append(h**4+k**4+2.0*k*h**3+2.0*h*k**3+3.0*(h*k)**2)
1908        Strm.append(l**4)
1909        Strm.append(3.0*((h*l)**2+(k*l)**2+h*k*l**2))
1910    elif laue in ['31m','3']:
1911        Strm.append(h**4+k**4+2.0*k*h**3+2.0*h*k**3+3.0*(h*k)**2)
1912        Strm.append(l**4)
1913        Strm.append(3.0*((h*l)**2+(k*l)**2+h*k*l**2))
1914        Strm.append(4.0*h*k*l*(h+k))
1915    elif laue in ['3R','3mR']:
1916        Strm.append(h**4+k**4+l**4)
1917        Strm.append(3.0*((h*k)**2+(h*l)**2+(k*l)**2))
1918        Strm.append(2.0*(h*l**3+l*k**3+k*h**3)+2.0*(l*h**3+k*l**3+l*k**3))
1919        Strm.append(4.0*(k*l*h**2+h*l*k**2+h*k*l**2))
1920    elif laue in ['4/m','4/mmm']:
1921        Strm.append(h**4+k**4)
1922        Strm.append(l**4)
1923        Strm.append(3.0*(h*k)**2)
1924        Strm.append(3.0*((h*l)**2+(k*l)**2))
1925    elif laue in ['mmm']:
1926        Strm.append(h**4)
1927        Strm.append(k**4)
1928        Strm.append(l**4)
1929        Strm.append(3.0*(h*k)**2)
1930        Strm.append(3.0*(h*l)**2)
1931        Strm.append(3.0*(k*l)**2)
1932    elif laue in ['2/m']:
1933        Strm.append(h**4)
1934        Strm.append(k**4)
1935        Strm.append(l**4)
1936        Strm.append(3.0*(h*k)**2)
1937        Strm.append(3.0*(h*l)**2)
1938        Strm.append(3.0*(k*l)**2)
1939        if uniq == 'a':
1940            Strm.append(2.0*k*l**3)
1941            Strm.append(2.0*l*k**3)
1942            Strm.append(4.0*k*l*h**2)
1943        elif uniq == 'b':
1944            Strm.append(2.0*l*h**3)
1945            Strm.append(2.0*h*l**3)
1946            Strm.append(4.0*h*l*k**2)
1947        elif uniq == 'c':
1948            Strm.append(2.0*h*k**3)
1949            Strm.append(2.0*k*h**3)
1950            Strm.append(4.0*h*k*l**2)
1951    else:
1952        Strm.append(h**4)
1953        Strm.append(k**4)
1954        Strm.append(l**4)
1955        Strm.append(3.0*(h*k)**2)
1956        Strm.append(3.0*(h*l)**2)
1957        Strm.append(3.0*(k*l)**2)
1958        Strm.append(2.0*k*h**3)
1959        Strm.append(2.0*h*l**3)
1960        Strm.append(2.0*l*k**3)
1961        Strm.append(2.0*h*k**3)
1962        Strm.append(2.0*l*h**3)
1963        Strm.append(2.0*k*l**3)
1964        Strm.append(4.0*k*l*h**2)
1965        Strm.append(4.0*h*l*k**2)
1966        Strm.append(4.0*k*h*l**2)
1967    return Strm
1968   
1969def Muiso2Shkl(muiso,SGData,cell):
1970    "this is to convert isotropic mustrain to generalized Shkls"
1971    import GSASIIlattice as G2lat
1972    A = G2lat.cell2AB(cell)[0]
1973   
1974    def minMus(Shkl,muiso,H,SGData,A):
1975        U = np.inner(A.T,H)
1976        S = np.array(MustrainCoeff(U,SGData))
1977        Sum = np.sqrt(np.sum(np.multiply(S,Shkl[:,np.newaxis]),axis=0))
1978        rad = np.sqrt(np.sum((Sum[:,np.newaxis]*H)**2,axis=1))
1979        return (muiso-rad)**2
1980       
1981    laue = SGData['SGLaue']
1982    PHI = np.linspace(0.,360.,60,True)
1983    PSI = np.linspace(0.,180.,60,True)
1984    X = np.outer(npsind(PHI),npsind(PSI))
1985    Y = np.outer(npcosd(PHI),npsind(PSI))
1986    Z = np.outer(np.ones(np.size(PHI)),npcosd(PSI))
1987    HKL = np.dstack((X,Y,Z))
1988    if laue in ['m3','m3m']:
1989        S0 = [1000.,1000.]
1990    elif laue in ['6/m','6/mmm','3m1']:
1991        S0 = [1000.,1000.,1000.]
1992    elif laue in ['31m','3']:
1993        S0 = [1000.,1000.,1000.,1000.]
1994    elif laue in ['3R','3mR']:
1995        S0 = [1000.,1000.,1000.,1000.]
1996    elif laue in ['4/m','4/mmm']:
1997        S0 = [1000.,1000.,1000.,1000.]
1998    elif laue in ['mmm']:
1999        S0 = [1000.,1000.,1000.,1000.,1000.,1000.]
2000    elif laue in ['2/m']:
2001        S0 = [1000.,1000.,1000.,0.,0.,0.,0.,0.,0.]
2002    else:
2003        S0 = [1000.,1000.,1000.,1000.,1000., 1000.,1000.,1000.,1000.,1000., 
2004            1000.,1000.,0.,0.,0.]
2005    S0 = np.array(S0)
2006    HKL = np.reshape(HKL,(-1,3))
2007    result = so.leastsq(minMus,S0,(np.ones(HKL.shape[0])*muiso,HKL,SGData,A))
2008    return result[0]
2009       
2010def SytSym(XYZ,SGData):
2011    '''
2012    Generates the number of equivalent positions and a site symmetry code for a specified coordinate and space group
2013
2014    :param XYZ: an array, tuple or list containing 3 elements: x, y & z
2015    :param SGData: from SpcGroup
2016    :Returns: a two element tuple:
2017
2018     * The 1st element is a code for the site symmetry (see GetKNsym)
2019     * The 2nd element is the site multiplicity
2020
2021    '''
2022    def PackRot(SGOps):
2023        IRT = []
2024        for ops in SGOps:
2025            M = ops[0]
2026            irt = 0
2027            for j in range(2,-1,-1):
2028                for k in range(2,-1,-1):
2029                    irt *= 3
2030                    irt += M[k][j]
2031            IRT.append(int(irt))
2032        return IRT
2033       
2034    SymName = ''
2035    Mult = 1
2036    Isym = 0
2037    if SGData['SGLaue'] in ['3','3m1','31m','6/m','6/mmm']:
2038        Isym = 1073741824
2039    Jdup = 0
2040    Xeqv = GenAtom(XYZ,SGData,True)
2041    IRT = PackRot(SGData['SGOps'])
2042    L = -1
2043    for ic,cen in enumerate(SGData['SGCen']):
2044        for invers in range(int(SGData['SGInv']+1)):
2045            for io,ops in enumerate(SGData['SGOps']):
2046                irtx = (1-2*invers)*IRT[io]
2047                L += 1
2048                if not Xeqv[L][1]:
2049                    Jdup += 1
2050                    jx = GetOprPtrName(str(irtx))
2051                    if jx[2] < 39:
2052                        Isym += 2**(jx[2]-1)
2053    if Isym == 1073741824: Isym = 0
2054    Mult = len(SGData['SGOps'])*len(SGData['SGCen'])*(int(SGData['SGInv'])+1)/Jdup
2055         
2056    return GetKNsym(str(Isym)),Mult
2057   
2058def ElemPosition(SGData):
2059    ''' Under development.
2060    Object here is to return a list of symmetry element types and locations suitable
2061    for say drawing them.
2062    So far I have the element type... getting all possible locations without lookup may be impossible!
2063    '''
2064    SymElements = []
2065    Inv = SGData['SGInv']
2066    Cen = SGData['SGCen']
2067    eleSym = {-3:['','-1'],-2:['',-6],-1:['2','-4'],0:['3','-3'],1:['4','m'],2:['6',''],3:['1','']}
2068    # get operators & expand if centrosymmetric
2069    Ops = SGData['SGOps']
2070    opM = np.array([op[0].T for op in Ops])
2071    opT = np.array([op[1] for op in Ops])
2072    if Inv:
2073        opM = np.concatenate((opM,-opM))
2074        opT = np.concatenate((opT,-opT))
2075    opMT = zip(opM,opT)
2076    for M,T in opMT[1:]:        #skip I
2077        Dt = int(nl.det(M))
2078        Tr = int(np.trace(M))
2079        Dt = -(Dt-1)/2
2080        Es = eleSym[Tr][Dt]
2081        if Dt:              #rotation-inversion
2082            I = np.eye(3)
2083            if Tr == 1:     #mirrors/glides
2084                if np.any(T):       #glide
2085                    M2 = np.inner(M,M)
2086                    MT = np.inner(M,T)+T
2087                    print 'glide',Es,MT
2088                    print M2
2089                else:               #mirror
2090                    print 'mirror',Es,T
2091                    print I-M
2092                X = [-1,-1,-1]
2093            elif Tr == -3:  # pure inversion
2094                X = np.inner(nl.inv(I-M),T)
2095                print 'inversion',Es,X
2096            else:           #other rotation-inversion
2097                M2 = np.inner(M,M)
2098                MT = np.inner(M,T)+T
2099                print 'rot-inv',Es,MT
2100                print M2
2101                X = [-1,-1,-1]
2102        else:               #rotations
2103            print 'rotation',Es
2104            X = [-1,-1,-1]
2105        #SymElements.append([Es,X])
2106       
2107    return #SymElements
2108   
2109def ApplyStringOps(A,SGData,X,Uij=[]):
2110    'Needs a doc string'
2111    SGOps = SGData['SGOps']
2112    SGCen = SGData['SGCen']
2113    Ax = A.split('+')
2114    Ax[0] = int(Ax[0])
2115    iC = 0
2116    if Ax[0] < 0:
2117        iC = 1
2118    Ax[0] = abs(Ax[0])
2119    nA = Ax[0]%100-1
2120    cA = Ax[0]/100
2121    Cen = SGCen[cA]
2122    M,T = SGOps[nA]
2123    if len(Ax)>1:
2124        cellA = Ax[1].split(',')
2125        cellA = np.array([int(a) for a in cellA])
2126    else:
2127        cellA = np.zeros(3)
2128    newX = Cen+(1-2*iC)*(np.inner(M,X).T+T)+cellA
2129    if len(Uij):
2130        U = Uij2U(Uij)
2131        U = np.inner(M,np.inner(U,M).T)
2132        newUij = U2Uij(U)
2133        return [newX,newUij]
2134    else:
2135        return newX
2136       
2137def StringOpsProd(A,B,SGData):
2138    """
2139    Find A*B where A & B are in strings '-' + '100*c+n' + '+ijk'
2140    where '-' indicates inversion, c(>0) is the cell centering operator,
2141    n is operator number from SgOps and ijk are unit cell translations (each may be <0).
2142    Should return resultant string - C. SGData - dictionary using entries:
2143
2144       *  'SGCen': cell centering vectors [0,0,0] at least
2145       *  'SGOps': symmetry operations as [M,T] so that M*x+T = x'
2146
2147    """
2148    SGOps = SGData['SGOps']
2149    SGCen = SGData['SGCen']
2150    #1st split out the cell translation part & work on the operator parts
2151    Ax = A.split('+'); Bx = B.split('+')
2152    Ax[0] = int(Ax[0]); Bx[0] = int(Bx[0])
2153    iC = 0
2154    if Ax[0]*Bx[0] < 0:
2155        iC = 1
2156    Ax[0] = abs(Ax[0]); Bx[0] = abs(Bx[0])
2157    nA = Ax[0]%100-1;  nB = Bx[0]%100-1
2158    cA = Ax[0]/100;  cB = Bx[0]/100
2159    Cen = (SGCen[cA]+SGCen[cB])%1.0
2160    cC = np.nonzero([np.allclose(C,Cen) for C in SGCen])[0][0]
2161    Ma,Ta = SGOps[nA]; Mb,Tb = SGOps[nB]
2162    Mc = np.inner(Ma,Mb.T)
2163#    print Ma,Mb,Mc
2164    Tc = (np.add(np.inner(Mb,Ta)+1.,Tb))%1.0
2165#    print Ta,Tb,Tc
2166#    print [np.allclose(M,Mc)&np.allclose(T,Tc) for M,T in SGOps]
2167    nC = np.nonzero([np.allclose(M,Mc)&np.allclose(T,Tc) for M,T in SGOps])[0][0]
2168    #now the cell translation part
2169    if len(Ax)>1:
2170        cellA = Ax[1].split(',')
2171        cellA = [int(a) for a in cellA]
2172    else:
2173        cellA = [0,0,0]
2174    if len(Bx)>1:
2175        cellB = Bx[1].split(',')
2176        cellB = [int(b) for b in cellB]
2177    else:
2178        cellB = [0,0,0]
2179    cellC = np.add(cellA,cellB)
2180    C = str(((nC+1)+(100*cC))*(1-2*iC))+'+'+ \
2181        str(int(cellC[0]))+','+str(int(cellC[1]))+','+str(int(cellC[2]))
2182    return C
2183           
2184def U2Uij(U):
2185    #returns the UIJ vector U11,U22,U33,U12,U13,U23 from tensor U
2186    return [U[0][0],U[1][1],U[2][2],U[0][1],U[0][2],U[1][2]]
2187   
2188def Uij2U(Uij):
2189    #returns the thermal motion tensor U from Uij as numpy array
2190    return np.array([[Uij[0],Uij[3],Uij[4]],[Uij[3],Uij[1],Uij[5]],[Uij[4],Uij[5],Uij[2]]])
2191
2192def StandardizeSpcName(spcgroup):
2193    '''Accept a spacegroup name where spaces may have not been used
2194    in the names according to the GSAS convention (spaces between symmetry
2195    for each axis) and return the space group name as used in GSAS
2196    '''
2197    rspc = spcgroup.replace(' ','').upper()
2198    # deal with rhombohedral and hexagonal setting designations
2199    rhomb = ''
2200    if rspc[-1:] == 'R':
2201        rspc = rspc[:-1]
2202        rhomb = ' R'
2203    elif rspc[-1:] == 'H': # hexagonal is assumed and thus can be ignored
2204        rspc = rspc[:-1]
2205    # look for a match in the spacegroup lists
2206    for i in spglist.values():
2207        for spc in i:
2208            if rspc == spc.replace(' ','').upper():
2209                return spc + rhomb
2210    # how about the post-2002 orthorhombic names?
2211    for i,spc in sgequiv_2002_orthorhombic:
2212        if rspc == i.replace(' ','').upper():
2213            return spc
2214    # not found
2215    return ''
2216
2217   
2218spglist = {}
2219'''A dictionary of space groups as ordered and named in the pre-2002 International
2220Tables Volume A, except that spaces are used following the GSAS convention to
2221separate the different crystallographic directions.
2222Note that the symmetry codes here will recognize many non-standard space group
2223symbols with different settings. They are ordered by Laue group
2224'''
2225spglist = {
2226    'P1' : ('P 1','P -1',), # 1-2
2227    'P2/m': ('P 2','P 21','P m','P a','P c','P n',
2228        '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
2229    'C2/m':('C 2','C m','C c','C n',
2230        'C 2/m','C 2/c','C 2/n',),
2231    'Pmmm':('P 2 2 2',
2232        'P 2 2 21','P 21 2 2','P 2 21 2',
2233        'P 21 21 2','P 2 21 21','P 21 2 21',
2234        'P 21 21 21',
2235        'P m m 2','P 2 m m','P m 2 m',
2236        'P m c 21','P 21 m a','P b 21 m','P m 21 b','P c m 21','P 21 a m',
2237        'P c c 2','P 2 a a','P b 2 b',
2238        'P m a 2','P 2 m b','P c 2 m','P m 2 a','P b m 2','P 2 c m',
2239        'P c a 21','P 21 a b','P c 21 b','P b 21 a','P b c 21','P 21 c a',
2240        'P n c 2','P 2 n a','P b 2 n','P n 2 b','P c n 2','P 2 a n',
2241        'P m n 21','P 21 m n','P n 21 m','P m 21 n','P n m 21','P 21 n m',
2242        'P b a 2','P 2 c b','P c 2 a',
2243        'P n a 21','P 21 n b','P c 21 n','P n 21 a','P b n 21','P 21 c n',
2244        'P n n 2','P 2 n n','P n 2 n',
2245        'P m m m','P n n n',
2246        'P c c m','P m a a','P b m b',
2247        'P b a n','P n c b','P c n a',
2248        'P m m a','P b m m','P m c m','P m a m','P m m b','P c m m',
2249        'P n n a','P b n n','P n c n','P n a n','P n n b','P c n n',
2250        'P m n a','P b m n','P n c m','P m a n','P n m b','P c n m',
2251        'P c c a','P b a a','P b c b','P b a b','P c c b','P c a a',
2252        'P b a m','P m c b','P c m a',
2253        'P c c n','P n a a','P b n b',
2254        'P b c m','P m c a','P b m a','P c m b','P c a m','P m a b',
2255        'P n n m','P m n n','P n m n',
2256        'P m m n','P n m m','P m n m',
2257        'P b c n','P n c a','P b n a','P c n b','P c a n','P n a b',
2258        'P b c a','P c a b',
2259        'P n m a','P b n m','P m c n','P n a m','P m n b','P c m n',
2260        ),
2261    'Cmmm':('C 2 2 21','C 2 2 2','C m m 2',
2262        'C m c 21','C c m 21','C c c 2','C m 2 m','C 2 m m',
2263        'C m 2 a','C 2 m b','C c 2 m','C 2 c m','C c 2 a','C 2 c b',
2264        'C m c m','C m c a','C c m b',
2265        'C m m m','C c c m','C m m a','C m m b','C c c a','C c c b',),
2266    'Immm':('I 2 2 2','I 21 21 21',
2267        'I m m 2','I m 2 m','I 2 m m',
2268        'I b a 2','I 2 c b','I c 2 a',
2269        'I m a 2','I 2 m b','I c 2 m','I m 2 a','I b m 2','I 2 c m',
2270        'I m m m','I b a m','I m c b','I c m a',
2271        'I b c a','I c a b',
2272        'I m m a','I b m m ','I m c m','I m a m','I m m b','I c m m',),
2273    'Fmmm':('F 2 2 2','F m m m', 'F d d d',
2274        'F m m 2','F m 2 m','F 2 m m',
2275        'F d d 2','F d 2 d','F 2 d d',),
2276    'P4/mmm':('P 4','P 41','P 42','P 43','P -4','P 4/m','P 42/m','P 4/n','P 42/n',
2277        'P 4 2 2','P 4 21 2','P 41 2 2','P 41 21 2','P 42 2 2',
2278        'P 42 21 2','P 43 2 2','P 43 21 2','P 4 m m','P 4 b m','P 42 c m',
2279        'P 42 n m','P 4 c c','P 4 n c','P 42 m c','P 42 b c','P -4 2 m',
2280        'P -4 2 c','P -4 21 m','P -4 21 c','P -4 m 2','P -4 c 2','P -4 b 2',
2281        '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',
2282        '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',
2283        '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',
2284        'P 42/n c m',),
2285    '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',
2286        'I 4 c m','I 41 m d','I 41 c d',
2287        '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',
2288        'I 41/a m d','I 41/a c d'),
2289    'R3-H':('R 3','R -3','R 3 2','R 3 m','R 3 c','R -3 m','R -3 c',),
2290    'P6/mmm': ('P 3','P 31','P 32','P -3','P 3 1 2','P 3 2 1','P 31 1 2',
2291        'P 31 2 1','P 32 1 2','P 32 2 1', 'P 3 m 1','P 3 1 m','P 3 c 1',
2292        'P 3 1 c','P -3 1 m','P -3 1 c','P -3 m 1','P -3 c 1','P 6','P 61',
2293        'P 65','P 62','P 64','P 63','P -6','P 6/m','P 63/m','P 6 2 2',
2294        'P 61 2 2','P 65 2 2','P 62 2 2','P 64 2 2','P 63 2 2','P 6 m m',
2295        'P 6 c c','P 63 c m','P 63 m c','P -6 m 2','P -6 c 2','P -6 2 m',
2296        'P -6 2 c','P 6/m m m','P 6/m c c','P 63/m c m','P 63/m m c',),
2297    'Pm3m': ('P 2 3','P 21 3','P m 3','P n 3','P a 3','P 4 3 2','P 42 3 2',
2298        'P 43 3 2','P 41 3 2','P -4 3 m','P -4 3 n','P m 3 m','P n 3 n',
2299        'P m 3 n','P n 3 m',),
2300    'Im3m':('I 2 3','I 21 3','I m -3','I a -3', 'I 4 3 2','I 41 3 2',
2301        'I -4 3 m', 'I -4 3 d','I m -3 m','I m 3 m','I a -3 d',),
2302    'Fm3m':('F 2 3','F m -3','F d -3','F 4 3 2','F 41 3 2','F -4 3 m',
2303        'F -4 3 c','F m -3 m','F m 3 m','F m -3 c','F d -3 m','F d -3 c',),
2304}
2305
2306ssdict = {}
2307'''A dictionary of superspace group symbols allowed for each entry in spglist
2308(except cubics). Monoclinics are all b-unique setting.
2309'''
2310ssdict = {
2311#1,2
2312    'P 1':['(abg)',],'P -1':['(abg)',],
2313#monoclinic - done
2314#3
2315    'P 2':['(a0g)','(a1/2g)','(0b0)','(0b0)s','(1/2b0)','(0b1/2)',],
2316#4       
2317    'P 21':['(a0g)','(0b0)','(1/2b0)','(0b1/2)',],
2318#5
2319    'C 2':['(a0g)','(0b0)','(0b0)s','(0b1/2)',],
2320#6
2321    'P m':['(a0g)','(a0g)s','(a1/2g)','(0b0)','(1/2b0)','(0b1/2)',],
2322#7
2323    'P a':['(a0g)','(a1/2g)','(0b0)','(0b1/2)',],
2324    'P c':['(a0g)','(a1/2g)','(0b0)','(1/2b0)',],
2325    'P n':['(a0g)','(a1/2g)','(0b0)','(1/2b1/2)',],
2326#8       
2327    'C m':['(a0g)','(a0g)s','(0b0)','(0b1/2)',],
2328#9       
2329    'C c':['(a0g)','(a0g)s','(0b0)',],
2330    'C n':['(a0g)','(a0g)s','(0b0)',],
2331#10       
2332    'P 2/m':['(a0g)','(a0g)0s','(a1/2g)','(0b0)','(0b0)s0','(1/2b0)','(0b1/2)',],
2333#11
2334    'P 21/m':['(a0g)','(a0g)0s','(0b0)','(0b0)s0','(1/2b0)','(0b1/2)',],
2335#12       
2336    'C 2/m':['(a0g)','(a0g)0s','(0b0)','(0b0)s0','(0b1/2)',],
2337#13
2338    'P 2/c':['(a0g)','(a0g)0s','(a1/2g)','(0b0)','(0b0)s0','(1/2b0)',],
2339    'P 2/a':['(a0g)','(a0g)0s','(a1/2g)','(0b0)','(0b0)s0','(0b1/2)',],
2340    'P 2/n':['(a0g)','(a0g)0s','(a1/2g)','(0b0)','(0b0)s0','(1/2b1/2)',],
2341#14
2342    'P 21/c':['(a0g)','(0b0)','(1/2b0)',],
2343    'P 21/a':['(a0g)','(0b0)','(0b1/2)',],
2344    'P 21/n':['(a0g)','(0b0)','(1/2b1/2)',],
2345#15
2346    'C 2/c':['(a0g)','(0b0)','(0b0)s0',],
2347    'C 2/n':['(a0g)','(0b0)','(0b0)s0',],
2348#orthorhombic
2349#16   
2350    'P 2 2 2':['(00g)','(00g)00s','(01/2g)','(1/20g)','(1/21/2g)',
2351        '(a00)','(a00)s00','(a01/2)','(a1/20)','(a1/21/2)',
2352        '(0b0)','(0b0)0s0','(1/2b0)','(0b1/2)','(1/2b1/2)',],
2353#17       
2354    'P 2 2 21':['(00g)','(01/2g)','(1/20g)','(1/21/2g)',
2355        '(a00)','(a00)s00','(a1/20)','(0b0)','(0b0)0s0','(1/2b0)',],
2356    'P 21 2 2':['(a00)','(a01/2)','(a1/20)','(a1/21/2)',
2357        '(0b0)','(0b0)0s0','(1/2b0)','(00g)','(00g)00s','(1/20g)',],
2358    'P 2 21 2':['(0b0)','(0b1/2)','(1/2b0)','(1/2b1/2)',
2359        '(00g)','(00g)00s','(1/20g)','(a00)','(a00)s00','(a1/20)',],
2360#18       
2361    'P 21 21 2':['(00g)','(00g)00s','(a00)','(a01/2)','(0b0)','(0b1/2)',],
2362    'P 2 21 21':['(a00)','(a00)s00','(0b0)','(0b1/2)','(00g)','(01/2g)',],
2363    'P 21 2 21':['(0b0)','(0b0)0s0','(00g)','(01/2g)','(a00)','(a01/2)',],
2364#19       
2365    'P 21 21 21':['(00g)','(a00)','(0b0)',],
2366#20       
2367    'C 2 2 21':['(00g)','(10g)','(01g)','(a00)','(a00)s00','(0b0)','(0b0)0s0',],
2368    'A 21 2 2':['(a00)','(a10)','(a01)','(0b0)','(0b0)0s0','(00g)','(00g)00s',],
2369    'B 2 21 2':['(0b0)','(1b0)','(0b1)','(00g)','(00g)00s','(a00)','(a00)s00',],
2370#21       
2371    'C 2 2 2':['(00g)','(00g)00s','(10g)','(10g)00s','(01g)','(01g)00s',
2372        '(a00)','(a00)s00','(a01/2)','(0b0)','(0b0)0s0','(0b1/2)',],
2373    'A 2 2 2':['(a00)','(a00)s00','(a10)','(a10)s00','(a01)','(a01)s00',
2374        '(0b0)','(0b0)0s0','(1/2b0)','(00g)','(00g)00s','(1/20g)',],
2375    'B 2 2 2':['(0b0)','(0b0)0s0','(1b0)','(1b0)0s0','(0b1)','(0b1)0s0',
2376        '(00g)','(00g)00s','(01/2g)','(a00)','(a00)s00','(a1/20)',],
2377#22       
2378    'F 2 2 2':['(00g)','(00g)00s','(10g)','(01g)',
2379        '(a00)','(a00)s00','(a10)','(a01)',
2380        '(0b0)','(0b0)0s0','(1b0)','(0b1)',],
2381#23       
2382    'I 2 2 2':['(00g)','(00g)00s','(a00)','(a00)s00','(0b0)','(0b0)0s0',],
2383#24       
2384    'I 21 21 21':['(00g)','(00g)00s','(a00)','(a00)s00','(0b0)','(0b0)0s0',],
2385#25       
2386    'P m m 2':['(00g)','(00g)s0s','(00g)0ss','(00g)ss0',
2387        '(01/2g)','(01/2g)s0s','(1/20g)','(1/20g)0ss','(1/21/2g)',
2388        '(a00)','(a00)0s0','(a1/20)','(a01/2)','(a01/2)0s0','(a1/21/2)',
2389        '(0b0)','(0b0)s00','(0b1/2)','(0b1/2)s00','(1/2b0)','(1/2b1/2)',],       
2390    'P 2 m m':['(a00)','(a00)ss0','(a00)s0s','(a00)0ss',
2391        '(a01/2)','(a01/2)ss0','(a1/20)','(a1/20)s0s','(a1/21/2)',
2392        '(0b0)','(0b0)00s','(1/2b0)','(0b1/2)','(0b1/2)00s','(1/2b1/2)',
2393        '(00g)','(00g)0s0','(01/2g)','(01/2g)0s0','(1/20g)','(1/21/2g)',],
2394    'P m 2 m':['(0b0)','(0b0)ss0','(0b0)0ss','(0b0)s0s',
2395        '(0b1/2)','(0b1/2)ss0','(1/2b0)','(1/2b0)0ss','(1/2b1/2)',
2396        '(00g)','(00g)s00','(1/20g)','(01/2g)','(01/2g)s00','(1/21/2g)',
2397        '(a00)','(a00)0s0','(a01/2)','(a01/2)0s0','(a1/20)','(a1/21/2)',],       
2398#26       
2399    'P m c 21':['(00g)','(00g)s0s','(01/2g)','(01/2g)s0s','(1/20g)','(1/21/2g)',
2400        '(a00)','(a00)0s0','(a1/20)','(0b0)','(0b0)s00','(0b1/2)',],
2401    'P 21 m a':['(a00)','(a00)ss0','(a01/2)','(a01/2)ss0','(a1/20)','(a1/21/2)',
2402        '(0b0)','(0b0)00s','(1/2b0)','(00g)','(00g)0s0','(01/2g)',],
2403    'P b 21 m':['(0b0)','(0b0)ss0','(0b1/2)','(0b1/2)ss0','(1/2b0)','(1/2b1/2)',
2404        '(00g)','(00g)s00','(1/20g)','(a00)','(a00)0s0','(a01/2)',],
2405    'P m 21 b':['(a00)','(a00)ss0','(a01/2)','(a01/2)ss0','(a1/20)','(a1/21/2)',
2406        '(00g)','(00g)0s0','(01/2g)','(0b0)','(0b0)s00','(0b1/2)',],
2407    'P c m 21':['(00g)','(00g)0ss','(1/20g)','(1/20g)0ss','(01/2g)','(1/21/2g)',
2408        '(0b0)','(0b0)s00','(1/2b0)','(a00)','(a00)0s0','(a01/2)',],
2409    'P 21 a m':['(0b0)','(0b0)ss0','(0b1/2)','(0b1/2)ss0','(1/2b0)','(1/2b1/2)',
2410        '(a00)','(a00)00s','(a1/20)','(00g)','(00g)s00','(1/20g)',],
2411#27       
2412    'P c c 2':['(00g)','(00g)s0s','(00g)0ss','(01/2g)','(1/20g)','(1/21/2g)',
2413        '(a00)','(a00)0s0','(a1/20)','(0b0)','(0b0)s00','(1/2b0)',],
2414    'P 2 a a':['(a00)','(a00)ss0','(a00)s0s','(a01/2)','(a1/20)','(a1/21/2)',
2415        '(0b0)','(0b0)00s','(0b1/2)','(00g)','(00g)0s0','(01/2g)',],
2416    'P b 2 b':['(0b0)','(0b0)0ss','(0b0)ss0','(1/2b0)','(0b1/2)','(1/2b1/2)',
2417        '(00g)','(00g)s00','(1/20g)','(a00)','(a00)00s','(a01/2)',],
2418#28       
2419    'P m a 2':['(00g)','(00g)s0s','(00g)ss0','(00g)0ss','(01/2g)','(01/2g)s0s',
2420        '(0b1/2)','(0b1/2)s00','(a01/2)','(a00)','(0b0)','(0b0)0s0','(a1/20)','(a1/21/2)'],
2421    'P 2 m b':['(a00)','(a00)s0s','(a00)ss0','(a00)0ss','(a01/2)','(a01/2)s0s',
2422        '(1/20g)','(1/20g)s00','(1/2b0)','(0b0)','(00g)','(00g)0s0','(0b1/2)','(1/2b1/2)'],
2423    'P c 2 m':['(0b0)','(0b0)s0s','(0b0)ss0','(0b0)0ss','(1/2b0)','(1/2b0)s0s',
2424        '(a1/20)','(a1/20)s00','(01/2g)','(00g)','(a00)','(a00)0s0','(1/20g)','(1/21/2g)'],
2425    'P m 2 a':['(0b0)','(0b0)s0s','(0b0)ss0','(0b0)0ss','(0b1/2)','(0b1/2)s0s',
2426        '(01/2g)','(01/2g)s00','(a1/20)','(a00)','(00g)','(00g)0s0','(a01/2)','(a1/21/2)'],
2427    'P b m 2':['(00g)','(00g)s0s','(00g)ss0','(00g)0ss','(1/20g)','(1/20g)s0s',
2428        '(a01/2)','(a01/2)s00','(0b1/2)','(0b0)','(a00)','(a00)0s0','(1/2b0)','(1/2b1/2)'],
2429    'P 2 c m':['(a00)','(a00)s0s','(a00)ss0','(a00)0ss','(a1/20)','(a1/20)s0s',
2430        '(1/2b0)','(1/2b0)s00','(1/20g)','(00g)','(0b0)','(0b0)0s0','(01/2g)','(1/21/2g)'],
2431#29       
2432    'P c a 21':['(00g)','(00g)0ss','(01/2g)','(1/20g)',
2433        '(a00)','(a00)0s0','(a1/20)','(0b0)','(0b0)s00','(1/2b0)',],
2434    'P 21 a b':['(a00)','(a00)s0s','(a01/2)','(a1/20)',
2435        '(0b0)','(0b0)00s','(0b1/2)','(00g)','(00g)0s0','(01/2g)',],
2436    'P c 21 b':['(0b0)','(0b0)ss0','(1/2b0)','(0b1/2)',
2437        '(00g)','(00g)s00','(1/20g)','(a00)','(a00)00s','(a01/2)',],
2438    'P b 21 a':['(0b0)','(0b0)0ss','(0b1/2)','(1/2b0)',
2439        '(a00)','(a00)00s','(a1/20)','(00g)','(00g)s00','(1/20g)',],
2440    'P b c 21':['(00g)','(00g)s0s','(1/20g)','(01/2g)',
2441        '(0b0)','(0b0)s00','(0b1/2)','(a00)','(a00)0s0','(a1/20)',],
2442    'P 21 c a':['(a00)','(a00)ss0','(a1/20)','(a01/2)',
2443        '(00g)','(00g)0s0','(1/20g)','(0b0)','(0b0)00s','(0b1/2)',],
2444#30       
2445    'P c n 2':['(00g)','(00g)s0s','(01/2g)','(a00)','(0b0)','(0b0)s00',
2446        '(a1/20)','(1/2b1/2)q00',],
2447    'P 2 a n':['(a00)','(a00)ss0','(a01/2)','(0b0)','(00g)','(00g)0s0',
2448        '(0b1/2)','(1/21/2g)0q0',],
2449    'P n 2 b':['(0b0)','(0b0)0ss','(1/2b0)','(00g)','(a00)','(a00)00s',
2450        '(1/20g)','(a1/21/2)00q',],
2451    'P b 2 n':['(0b0)','(0b0)ss0','(0b1/2)','(a00)','(00g)','(00g)s00',
2452        '(a01/2)','(1/21/2g)0ss',],
2453    'P n c 2':['(00g)','(00g)0ss','(1/20g)','(0b0)','(a00)','(a00)0s0',
2454        '(1/2b0)','(a1/21/2)s0s',],
2455    'P 2 n a':['(a00)','(a00)s0s','(a1/20)','(00g)','(0b0)','(0b0)00s',
2456        '(01/2g)','(1/2b1/2)ss0',],
2457#31       
2458    'P m n 21':['(00g)','(00g)s0s','(01/2g)','(01/2g)s0s','(a00)','(0b0)',
2459        '(0b0)s00','(a1/20)',],
2460    'P 21 m n':['(a00)','(a00)ss0','(a01/2)','(a01/2)ss0','(0b0)','(00g)',
2461        '(00g)0s0','(0b1/2)',],
2462    'P n 21 m':['(0b0)','(0b0)0ss','(1/2b0)','(1/2b0)0ss','(00g)','(a00)',
2463        '(a00)00s','(1/20g)',],
2464    'P m 21 n':['(0b0)','(0b0)ss0','(0b1/2)','(0b1/2)ss0','(a00)','(00g)',
2465        '(00g)s00','(a01/2)',],
2466    'P n m 21':['(00g)','(00g)0ss','(1/20g)','(1/20g)0ss','(0b0)','(a00)',
2467        '(a00)0s0','(1/2b0)',],
2468    'P 21 n m':['(a00)','(a00)s0s','(a1/20)','(a1/20)s0s','(00g)','(0b0)',
2469        '(0b0)00s','(01/2g)',],
2470#32       
2471    'P b a 2':['(00g)','(00g)s0s','(00g)0ss','(00g)ss0','(1/21/2g)qq0',
2472        '(a00)','(a01/2)','(0b0)','(0b1/2)',],
2473    'P 2 c b':['(a00)','(a00)ss0','(a00)s0s','(a00)0ss','(a1/21/2)0qq',
2474        '(0b0)','(1/2b0)','(00g)','(1/20g)',],
2475    'P c 2 a':['(0b0)','(0b0)ss0','(0b0)0ss','(0b0)s0s','(1/2b1/2)q0q',
2476        '(00g)','01/2g)','(a00)','(a1/20)',],
2477#33       
2478    'P b n 21':['(00g)','(00g)s0s','(1/21/2g)qq0','(a00)','(0b0)',],
2479    'P 21 c n':['(a00)','(a00)ss0','(a1/21/2)0qq','(0b0)','(00g)',],
2480    'P n 21 a':['(0b0)','(0b0)0ss','(1/2b1/2)q0q','(00g)','(a00)',],
2481    'P c 21 n':['(0b0)','(0b0)ss0','(1/2b1/2)q0q','(a00)','(00g)',],
2482    'P n a 21':['(00g)','(00g)0ss','(1/21/2g)qq0','(0b0)','(a00)',],
2483    'P 21 n b':['(a00)','(a00)s0s','(a1/21/2)0qq','(00g)','(0b0)',],
2484#34       
2485    'P n n 2':['(00g)','(00g)s0s','(00g)0ss','(1/21/2g)qq0',
2486        '(a00)','(a1/21/2)0q0','(a1/21/2)00q','(0b0)','(1/2b1/2)q00','(1/2b1/2)00q',],
2487    'P 2 n n':['(a00)','(a00)ss0','(a00)s0s','(a1/21/2)0qq',
2488        '(0b0)','(1/2b1/2)q00','(1/2b1/2)00q','(00g)','(1/21/2g)0q0','(1/21/2g)q00',],
2489    'P n 2 n':['(0b0)','(0b0)ss0','(0b0)0ss','(1/2b1/2)q0q',
2490        '(00g)','(1/21/2g)0q0','(1/21/2g)q00','(a00)','(a1/21/2)00q','(a1/21/2)0q0',],
2491#35       
2492    'C m m 2':['(00g)','(00g)s0s','(00g)ss0','(10g)','(10g)s0s','(10g)ss0',
2493        '(0b0)','(0b0)s00','(0b1/2)','(0b1/2)s00',],
2494    'A 2 m m':['(a00)','(a00)ss0','(a00)0ss','(a10)','(a10)ss0','(a10)0ss',
2495        '(00g)','(00g)0s0','(1/20g)','(1/20g)0s0',],
2496    'B m 2 m':['(0b0)','(0b0)0ss','(0b0)s0s','(0b1)','(0b1)0ss','(0b1)s0s',
2497        '(a00)','(a00)00s','(a1/20)','(a1/20)00s',],
2498#36
2499    'C m c 21':['(00g)','(00g)s0s','(10g)','(10g)s0s','(a00)','(a00)0s0','(0b0)','(0b0)s00',],
2500    'A 21 m a':['(a00)','(a00)ss0','(a10)','(a10)ss0','(0b0)','(0b0)00s','(00g)','(00g)0s0',],
2501    'B m 21 b':['(0b0)','(0b0)ss0','(1b0)','(1b0)ss0','(a00)','(a00)00s','(00g)','(00g)s00',],
2502    'B b 21 m':['(0b0)','(0b0)0ss','(0b1)','(0b1)ss0','(a00)','(a00)00s','(00g)','(00g)s00',],
2503    'C c m 21':['(00g)','(00g)0ss','(01g)','(01g)0ss','(a00)','(a00)0s0','(0b0)','(0b0)s00',],
2504    'A 21 a m':['(a00)','(a00)s0s','(a01)','(a01)s0s','(0b0)','(0b0)00s','(00g)','(00g)0s0',],
2505#37
2506    'C c c 2':['(00g)','(00g)s0s','(00g)0ss','(10g)','(10g)s0s','(10g)0ss','(01g)','(01g)s0s','(01g)0ss',
2507        '(a00)','(a00)0s0','(0b0)','(0b0)s00',],
2508    'A 2 a a':['(a00)','(a00)ss0','(a00)s0s','(a10)','(a10)ss0','(a10)ss0','(a01)','(a01)ss0','(a01)ss0',
2509        '(0b0)','(0b0)00s','(00g)','(00g)0s0',],
2510    'B b 2 b':['(0b0)','(0b0)0ss','(0b0)ss0','(0b1)','(0b1)0ss','(0b1)ss0','(1b0)','(1b0)0ss','(1b0)ss0',
2511        '(a00)','(a00)00s','(00g)','(00g)s00',],
2512#38
2513    'A m m 2':['(a00)','(a00)0s0','(a10)','(a10)0s0','(00g)','(00g)0s0',
2514        '(00g)ss0','(00g)0ss','(1/20g)','(1/20g)0ss','(0b0)','(0b0)s00','(1/2b0)',],
2515    'B 2 m m':['(0b0)','(0b0)00s','(0b1)','(0b1)00s','(a00)','(a00)00s',
2516        '(a00)0ss','(a00)s0s','(a1/20)','(a1/20)s0s','(00g)','(00g)0s0','(01/2g)',],
2517    'C m 2 m':['(00g)','(00g)s00','(10g)','(10g)s00','(0b0)','(0b0)s00',
2518        '(0b0)s0s','(0b0)ss0','(0b1/2)','(0b1/2)ss0','(a00)','(a00)00s','(a01/2)',],
2519    'A m 2 m':['(a00)','(a00)00s','(a01)','(a01)00s','(0b0)','(0b0)00s',
2520        '(0b0)s0s','(0b0)0ss','(1/2b0)','(1/2b0)0ss','(00g)','(00g)s00','(1/20g)',],
2521    'B m m 2':['(0b0)','(0b0)s00','(0b1)','(0b1)s00','(a00)','(a00)0s0',
2522        '(a00)0ss','(a00)ss0','(01/2g)','(01/2g)s0s','(a00)','(a00)0s0','(a1/20)',],
2523    'C 2 m m':['(00g)','(00g)0s0','(10g)','(10g)0s0','(00g)','(00g)s00',
2524        '(0b0)s0s','(0b0)0ss','(a01/2)','(a01/2)ss0','(0b0)','(0b0)00s','(0b1/2)',],
2525#39
2526    'A b m 2':['(a00)','(a00)0s0','(a01)','(a01)0s0','(00g)','(00g)s0s',
2527        '(00g)ss0','(00g)0ss','(1/20g)','(1/20g)0ss','(0b0)','(0b0)s00','(1/2b0)',],
2528    'B 2 c m':['(0b0)','(0b0)00s','(1b0)','(1b0)00s','(a00)','(a00)ss0',
2529        '(a00)0ss','(a00)s0s','(a1/20)','(a1/20)s0s','(00g)','(00g)0s0','(01/2g)',],
2530    'C m 2 a':['(00g)','(00g)s00','(01g)','(01g)s00','(0b0)','(0b0)0ss',
2531        '(0b0)s0s','(0b0)ss0','(0b1/2)','(0b1/2)ss0','(a00)','(a00)00s','(a01/2)',],
2532    'A c 2 m':['(a00)','(a00)00s','(a10)','(a10)00s','(0b0)','(0b0)ss0',
2533        '(0b0)s0s','(0b0)0ss','(1/2b0)','(1/2b0)0ss','(00g)','(00g)s00','(1/20g)',],
2534    'B m a 2':['(0b0)','(0b0)s00','(0b1)','(0b1)s00','(00g)','(00g)s0s',
2535        '(00g)0ss','(00g)ss0','(01/2g)','(01/2g)ss0','(a00)','(a00)00s','(a1/20)',],
2536    'C 2 m b':['(00g)','(00g)0s0','(10g)','(10g)0s0','(a00)','(a00)0ss',
2537        '(a00)ss0','(a00)s0s','(a01/2)','(a01/2)s0s','(0b0)','(0b0)0s0','(0b1/2)',],
2538#40       
2539    'A m a 2':['(a00)','(a01)','(00g)','(00g)s0s','(00g)ss0','(00g)0ss','(0b0)','(0b0)s00',],
2540    'B 2 m b':['(0b0)','(1b0)','(a00)','(a00)ss0','(a00)0ss','(a00)s0s','(00g)','(00g)0s0',],
2541    'C c 2 m':['(00g)','(01g)','(0b0)','(0b0)0ss','(0b0)s0s','(0b0)ss0','(a00)','(a00)00s',],
2542    'A m 2 a':['(a00)','(a10)','(0b0)','(0b0)ss0','(0b0)s0s','(0b0)0ss','(00g)','(00g)s00',],
2543    'B b m 2':['(0b0)','(0b1)','(00g)','(00g)0ss','(00g)ss0','(00g)s0s','(a00)','(a00)0s0',],
2544    'C 2 c m':['(00g)','(10g)','(a00)','(a00)s0s','(a00)0ss','(a00)ss0','(0b0)','(0b0)00s',],
2545#41
2546    'A b a 2':['(a00)','(a01)','(00g)','(00g)s0s','(00g)ss0','(00g)0ss','(0b0)','(0b0)s00',],
2547    'B 2 c b':['(0b0)','(1b0)','(a00)','(a00)ss0','(a00)0ss','(a00)s0s','(00g)','(00g)0s0',],
2548    'C c 2 a':['(00g)','(01g)','(0b0)','(0b0)0ss','(0b0)s0s','(0b0)ss0','(a00)','(a00)00s',],
2549    'A c 2 a':['(a00)','(a10)','(0b0)','(0b0)ss0','(0b0)s0s','(0b0)0ss','(00g)','(00g)s00',],
2550    'B b a 2':['(0b0)','(0b1)','(00g)','(00g)0ss','(00g)ss0','(00g)s0s','(a00)','(a00)0s0',],
2551    'C 2 c b':['(00g)','(10g)','(a00)','(a00)s0s','(a00)0ss','(a00)ss0','(0b0)','(0b0)00s',],
2552       
2553#42       
2554    'F m m 2':['(00g)','(00g)s0s','(00g)0ss','(00g)ss0','(10g)','(10g)ss0','(10g)s0s',
2555        '(01g)','(01g)ss0','(01g)0ss','(a00)','(a00)0s0','(a01)','(a01)0s0',
2556        '(0b0)','(0b0)s00','(0b1)','(0b1)s00',],       
2557    'F 2 m m':['(a00)','(a00)ss0','(a00)s0s','(a00)0ss','(a10)','(a10)0ss','(a10)ss0',
2558        '(a01)','(a01)0ss','(a01)s0s','(0b0)','(0b0)00s','(1b0)','(1b0)00s',
2559        '(00g)','(00g)0s0','(10g)','(10g)0s0',],
2560    'F m 2 m':['(0b0)','(0b0)0ss','(0b0)ss0','(0b0)s0s','(0b1)','(0b1)s0s','(0b1)0ss',
2561        '(1b0)','(1b0)s0s','(1b0)ss0','(00g)','(00g)s00','(01g)','(01g)s00',
2562        '(a00)','(a00)00s','(a10)','(a10)00s',],       
2563#43       
2564    'F d d 2':['(00g)','(00g)0ss','(00g)s0s','(a00)','(0b0)',],
2565    'F 2 d d':['(a00)','(a00)s0s','(a00)ss0','(00g)','(0b0)',],       
2566    'F d 2 d':['(0b0)','(0b0)0ss','(0b0)ss0','(a00)','(00g)',],
2567#44
2568    'I m m 2':['(00g)','(00g)ss0','(00g)s0s','(00g)0ss','(a00)','(a00)0s0','(0b0)','(0b0)s00',],
2569    'I 2 m m':['(a00)','(00g)0ss','(00g)ss0','(00g)s0s','(0b0)','(0b0)00s','(00g)','(00g)0s0',],
2570    'I m 2 m':['(0b0)','(0b0)s0s','(0b0)0ss','(0b0)ss0','(00g)','(00g)s00','(a00)','(a00)00s',],
2571#45       
2572    'I b a 2':['(00g)','(00g)ss0','(00g)s0s','(00g)0ss','(a00)','(a00)0s0','(0b0)','(0b0)s00',],
2573    'I 2 c b':['(0b0)','(0b0)s0s','(0b0)0ss','(0b0)ss0','(00g)','(00g)s00','(a00)','(a00)00s',],
2574    'I c 2 a':['(a00)','(00g)0ss','(00g)ss0','(00g)s0s','(0b0)','(0b0)00s','(00g)','(00g)0s0',],
2575#46       
2576    'I m a 2':['(a00)','(00g)0ss','(00g)ss0','(00g)s0s','(0b0)','(0b0)00s','(00g)','(00g)0s0',],
2577    'I 2 m b':['(0b0)','(0b0)s0s','(0b0)0ss','(0b0)ss0','(00g)','(00g)s00','(a00)','(a00)00s',],       
2578    'I c 2 m':['(a00)','(00g)0ss','(00g)ss0','(00g)s0s','(0b0)','(0b0)00s','(00g)','(00g)0s0',],
2579    'I m 2 a':['(a00)','(00g)0ss','(00g)ss0','(00g)s0s','(0b0)','(0b0)00s','(00g)','(00g)0s0',],
2580    'I b m 2':['(a00)','(00g)0ss','(00g)ss0','(00g)s0s','(0b0)','(0b0)00s','(00g)','(00g)0s0',],
2581    'I 2 c m':['(0b0)','(0b0)s0s','(0b0)0ss','(0b0)ss0','(00g)','(00g)s00','(a00)','(a00)00s',],
2582#47       
2583    'P m m m':['(00g)','(00g)s00','(00g)0s0','(00g)ss0','(01/2g)','(01/2g)s00','(1/20g)','(1/20g)s00','(1/21/2g)',
2584        '(a00)','(a00)0s0','(a00)00s','(a00)0ss','(a01/2)','(a01/2)0s0','(a1/20)','(a1/20)00s','(a1/21/2)',
2585        '(0b0)','(0b0)s00','(0b0)00s','(0b0)s0s','(1/2b0)','(1/2b0)00s','(0b1/2)','(0b1/2)s00','(1/2b1/2)',],
2586#48 o@i qq0,0qq,q0q ->000
2587    'P n n n':['(00g)','(00g)s00','(00g)0s0','(1/21/2g)',
2588        '(a00)','(a00)0s0','(a00)00s','(a1/21/2)',
2589        '(0b0)','(0b0)s00','(0b0)00s','(1/2b1/2)',],
2590#49       
2591    'P c c m':['(00g)','(00g)s00','(00g)0s0','(01/2g)','(1/20g)','(1/21/2g)',
2592        '(a00)','(a00)0s0','(a00)00s','(a00)0ss','(a1/20)','(a1/20)00s',
2593        '(0b0)','(0b0)s00','(0b0)00s','(0b0)s0s','(1/2b0)','(1/2b0)00s',],       
2594    'P m a a':['(a00)','(a00)0s0','(a00)00s','(a01/2)','(a1/20)','(a1/21/2)',
2595        '(0b0)','(0b0)00s','(0b0)s00','(0b0)s0s','(0b1/2)','(0b1/2)s00',
2596        '(00g)','(00g)0s0','(00g)s00','(00g)ss0','(01/2g)','(01/2g)s00',],       
2597    'P b m b':['(0b0)','(0b0)00s','(0b0)s00','(0b1/2)','(1/2b0)','(1/2b1/2)',
2598        '(00g)','(00g)s00','(00g)0s0','(00g)ss0','(1/20g)','(1/20g)0s0',
2599        '(a00)','(a00)00s','(a00)0s0','(a00)0ss','(a01/2)','(a01/2)0s0',],
2600#50 o@i qq0,0qq,q0q ->000
2601    'P b a n':['(00g)','(00g)s00','(00g)0s0','(00g)ss0','(1/21/2g)',
2602        '(a00)','(a00)0s0','(a01/2)','(0b0)','(0b0)s00','(0b1/2)',],
2603    'P n c b':['(a00)','(a00)0s0','(a00)00s','(a00)0ss','(a1/21/2)',
2604        '(0b0)','(0b0)00s','(1/2b0)','(00g)','(00g)0s0','(1/20g)',],
2605    'P c n a':['(0b0)','(0b0)s00','(0b0)00s','(0b0)s0s','(1/2b1/2)',
2606        '(00g)','(00g)s00','(01/2g)','(a00)','(a00)00s','(a1/20)',],
2607#51       
2608    'P m m a':['(00g)','(00g)s00','(00g)ss0','(00g)0s0','(0b0)','(0b0)s00',
2609        '(0b0)s0s','(0b0)00s','(a00)','(a00)0s0','(01/2g)','(01/2g)s00',
2610        '(0b1/2)','(0b1/2)s00','(a01/2)','(a01/2)0s0','(1/2b0)','(1/2b1/2)',],
2611    'P b m m':['(a00)','(a00)0s0','(a00)0ss','(a00)00s','(00g)','(00g)0s0',
2612        '(00g)ss0','(00g)s00','(0b0)','(0b0)00s','(a01/2)','(a01/2)0s0',
2613        '(1/20g)','(1/20g)0s0','(1/2b0)','(1/2b0)00s','(01/2g)','(1/21/2g)',],
2614    'P m c m':['(0b0)','(0b0)00s','(0b0)s0s','(0b0)s00','(a00)','(a00)00s',
2615        '(a00)0ss','(a00)0s0','(00g)','(00g)s00','(1/2b0)','(1/2b0)00s',
2616        '(a1/20)','(a1/20)00s','(01/2g)','(01/2g)s00','(a01/2)','(a1/21/2)',],
2617    'P m a m':['(0b0)','(0b0)s00','(0b0)s0s','(0b0)00s','(00g)','(00g)s00',
2618        '(00g)ss0','(00g)0s0','(a00)','(a00)00s','(0b1/2)','(0b1/2)s00',
2619        '(01/2g)','(01/2g)s00','(a1/20)','(a1/20)00s','(1/20g)','(1/21/2g)',],
2620    'P m m b':['(00g)','(00g)0s0','(00g)ss0','(00g)s00','(a00)','(a00)0s0',
2621        '(a00)0ss','(a00)00s','(0b0)','(0b0)s00','(a00)','(a00)0s0',
2622        '(a01/2)','(a01/2)0s0','(0b1/2)','(0b1/2)s00','(a1/20)','(a1/21/2)',],
2623    'P c m m':['(a00)','(a00)00s','(a00)0ss','(a00)0s0','(0b0)','(0b0)00s',
2624        '(0b0)s0s','(0b0)s00','(00g)','(00g)0s0','(0b0)','(0b0)00s',
2625        '(1/2b0)','(1/2b0)00s','(1/20g)','(1/20g)0s0','(0b1/2)','(1/2b1/2)',],
2626#52   o@i qq0,0qq,q0q ->000     
2627    'P n n a':['(00g)','(00g)s00','(00g)0s0','(a00)','(a00)00s',
2628        '(0b0)','(0b0)00s','(a1/21/2)','(1/2b1/2)',],
2629    'P b n n':['(a00)','(a00)0s0','(a00)00s','(0b0)','(0b0)s00',
2630        '(00g)','(00g)s00','(1/2b1/2)','(1/21/2g)',],
2631    'P n c n':['(0b0)','(0b0)s00','(0b0)00s','(00g)','(00g)0s0',
2632        '(a00)','(a00)0s0','(1/21/2g)','(a1/21/2)',],
2633    'P n a n':['(0b0)','(0b0)s00','(0b0)00s','(00g)','(00g)0s0',
2634        '(a00)','(a00)0s0','(1/21/2g)','(a1/21/2)',],
2635    'P n n b':['(00g)','(00g)s00','(00g)0s0','(a00)','(a00)00s',
2636        '(0b0)','(0b0)00s','(a1/21/2)','(1/2b1/2)',],
2637    'P c n n':['(a00)','(a00)0s0','(a00)00s','(0b0)','(0b0)s00',
2638        '(00g)','(00g)s00','(1/2b1/2)','(1/21/2g)',],
2639#53       
2640    'P m n a':['(00g)','(00g)s00','(a00)','(a00)00s','(0b0)','(0b0)00s',
2641        '(0b0)s0s','(0b0)s00','(01/2g)','(01/2g)s00','(a1/20)',],
2642    'P b m n':['(a00)','(a00)0s0','(0b0)','(0b0)s00','(00g)','(00g)s00',
2643        '(00g)ss0','(00g)0s0','(a01/2)','(a01/2)0s0','(0b1/2)',],
2644    'P n c m':['(0b0)','(0b0)00s','(00g)','(00g)0s0','(a00)','(a00)0s0',
2645        '(a00)0ss','(a00)00s','(1/2b0)','(1/2b0)00s','(1/20g)',],
2646    'P m a n':['(0b0)','(0b0)s00','(a00)','(a00)0s0','(00g)','(00g)0s0',
2647        '(00g)ss0','(00g)s00','(0b1/2)','(0b1/2)s00','(a01/2)',],
2648    'P n m b':['(00g)','(00g)0s0','(0b0)','(0b0)00s','(a00)','(a00)00s',
2649        '(a00)0ss','(a00)0s0','(1/20g)','(1/20g)0s0','(1/2b0)',],
2650    'P c n m':['(a00)','(a00)00s','(00g)','(00g)s00','(0b0)','(0b0)s00',
2651        '(0b0)s0s','(0b0)00s','(a1/20)','(a1/20)00s','(01/2g)',],
2652#54       
2653    'P c c a':['(00g)','(00g)s00','(0b0)','(0b0)s00','(a00)','(a00)0s0',
2654        '(a00)0ss','(a00)00s','(01/2g)','(1/2b0)',],
2655    'P b a a':['(a00)','(a00)0s0','(00g)','(00g)0s0','(0b0)','(0b0)00s',
2656        '(0b0)s0s','(0b0)s00','(a01/2)','(01/2g)',],
2657    'P b c b':['(0b0)','(0b0)00s','(a00)','(a00)00s','(00g)','(00g)s00',
2658        '(00g)ss0','(00g)0s0','(1/2b0)','(a01/2)',],
2659    'P b a b':['(0b0)','(0b0)s00','(00g)','(00g)s00','(a00)','(a00)00s',
2660        '(a00)0ss','(a00)0s0','(0b1/2)','(1/20g)',],
2661    'P c c b':['(00g)','(00g)0s0','(a00)','(a00)0s0','(0b0)','(0b0)s00',
2662        '(0b0)s0s','(0b0)00s','(1/20g)','(a1/20)',],
2663    'P c a a':['(a00)','(a00)00s','(0b0)','(0b0)00s','(00g)','(00g)0s0',
2664        '(00g)ss0','(00g)s00','(a1/20)','(0b1/2)',],
2665#55       
2666    'P b a m':['(00g)','(00g)s00','(00g)0s0','(00g)ss0',
2667        '(a00)','(a00)00s','(a01/2)','(0b0)','(0b0)00s','(0b1/2)'],
2668    'P m c b':['(a00)','(a00)0s0','(a00)00s','(a00)0ss',
2669        '(0b0)','(0b0)s00','(1/2b0)','(00g)','(00g)s00','(1/20g)'],
2670    'P c m a':['(0b0)','(0b0)s00','(0b0)00s','(0b0)s0s',
2671        '(a00)','(a00)0s0','(a1/20)','(00g)','(00g)0s0','(01/2g)'],
2672#56       
2673    'P c c n':['(00g)','(00g)s00','(00g)0s0','(a00)','(a00)0s0',
2674        '(0b0)','(0b0)s00'],
2675    'P n a a':['(a00)','(a00)0s0','(a00)00s','(0b0)','(0b0)00s',
2676        '(00g)','(00g)0s0'],
2677    'P b n b':['(0b0)','(0b0)s00','(0b0)00s','(a00)','(a00)00s',
2678        '(00g)','(00g)s00'],
2679#57       
2680    'P c a m':['(00g)','(00g)0s0','(a00)','(a00)00s','(0b0)','(0b0)s00',
2681        '(0b0)ss0','(0b0)00s','(01/2g)','(a1/20)','(a1/20)00s',],
2682    'P m a b':['(a00)','(a00)00s','(0b0)','(0b0)s00','(00g)','(00g)0s0',
2683        '(00g)s0s','(00g)s00','(a01/2)','(0b1/2)','(0b1/2)s00',],
2684    'P c m b':['(0b0)','(0b0)s00','(00g)','(00g)0s0','(a00)','(a00)00s',
2685        '(a00)0ss','(a00)0s0','(1/2b0)','(1/20g)','(1/20g)0s0',],
2686    'P b m a':['(0b0)','(0b0)00s','(a00)','(a00)0s0','(00g)','(00g)s00',
2687        '(00g)ss0','(00g)0s0','(0b1/2)','(a01/2)','(a01/2)0s0',],
2688    'P m c a':['(a00)','(a00)0s0','(00g)','(00g)s00','(0b0)','(0b0)00s',
2689        '(0b0)s0s','(0b0)s00','(a1/20)','(01/2g)','(01/2g)s00'],
2690    'P b c m':['(00g)','(00g)s00','(0b0)','(0b0)00s','(a00)','(a00)0s0',
2691        '(a00)0ss','(a00)00s','(1/20g)','(1/2b0)','(1/2b0)00s',],
2692#58       
2693    'P n n m':['(00g)','(00g)s00','(00g)0s0','(a00)',
2694        '(a00)00s','(0b0)','(0b0)00s'],
2695    'P m n n':['(00g)','(00g)s00','(a00)','(a00)0s0',
2696        '(a00)00s','(0b0)','(0b0)s00'],
2697    'P n m n':['(00g)','(00g)0s0','(a00)','(a00)0s0',
2698        '(0b0)','(0b0)s00','(0b0)00s',],
2699#59 o@i
2700    'P m m n':['(00g)','(00g)s00','(00g)0s0','(00g)ss0','(a00)','(a00)0s0',
2701        '(a01/2)','(a01/2)0s0','(0b0)','(0b0)s00','(0b1/2)','(0b1/2)s00',],
2702    'P n m m':['(a00)','(a00)0s0','(a00)00s','(a00)0ss','(00g)','(00g)0s0',
2703        '(1/20g)','(1/20g)0s0','(0b0)','(0b0)00s','(1/2b0)','(1/2b0)00s'],
2704    'P m n m':['(0b0)','(0b0)s00','(0b0)00s','(0b0)s0s','(00g)','(00g)s00',
2705        '(01/2g)','(01/2g)s00','(a00)','(a00)00s','(a1/20)','(a1/20)00s'],
2706#60       
2707    'P b c n':['(00g)','(00g)s00','(00g)0s0','(a00)','(a00)0s0',
2708        '(a00)00s','(0b0)','(0b0)s00','(0b0)00s'],
2709    'P n c a':['(00g)','(00g)s00','(00g)0s0','(a00)','(a00)0s0',
2710        '(a00)00s','(0b0)','(0b0)s00','(0b0)00s'],
2711    'P b n a':['(00g)','(00g)s00','(00g)0s0','(a00)','(a00)0s0',
2712        '(a00)00s','(0b0)','(0b0)s00','(0b0)00s'],
2713    'P c n b':['(00g)','(00g)s00','(00g)0s0','(a00)','(a00)0s0',
2714        '(a00)00s','(0b0)','(0b0)s00','(0b0)00s'],
2715    'P c a n':['(00g)','(00g)s00','(00g)0s0','(a00)','(a00)0s0',
2716        '(a00)00s','(0b0)','(0b0)s00','(0b0)00s'],
2717    'P n a b':['(00g)','(00g)s00','(00g)0s0','(a00)','(a00)0s0',
2718        '(a00)00s','(0b0)','(0b0)s00','(0b0)00s'],
2719#61       
2720    'P b c a':['(00g)','(00g)s00','(00g)0s0','(a00)','(a00)0s0','(a00)00s',
2721        '(0b0)','(0b0)s00','(0b0)00s'],
2722    'P c a b':['(00g)','(00g)s00','(00g)0s0','(a00)','(a00)0s0','(a00)00s',
2723        '(0b0)','(0b0)s00','(0b0)00s'],
2724#62       
2725    'P n m a':['(00g)','(00g)0s0','(a00)','(a00)0s0','(0b0)','(0b0)00s'],
2726    'P b n m':['(00g)','(00g)s00','(a00)','(a00)00s','(0b0)','(0b0)00s'],
2727    'P m c n':['(00g)','(00g)s00','(a00)','(a00)0s0','(0b0)','(0b0)s00'],
2728    'P n a m':['(00g)','(00g)0s0','(a00)','(a00)00s','(0b0)','(0b0)00s'],
2729    'P m n b':['(00g)','(00g)s00','(a00)','(a00)00s','(0b0)','(0b0)s00'],
2730    'P c m n':['(00g)','(00g)0s0','(a00)','(a00)0s0','(0b0)','(0b0)s00'],
2731#63
2732    'C m c m':['(00g)','(00g)s00','(10g)','(10g)s00','(a00)','(a00)00s','(a00)0ss','(a00)0s0','(0b0)','(0b0)00s','(0b0)s0s','(0b0)s00',],
2733    'A m m a':['(a00)','(a00)0s0','(a10)','(a10)0s0','(0b0)','(0b0)s00','(0b0)s0s','(00g)00s','(00g)','(00g)s00','(00g)ss0','(00g)0s0',],
2734    'B b m m':['(0b0)','(0b0)00s','(0b1)','(0b1)00s','(00g)','(00g)0s0','(00g)ss0','(00g)s00','(a00)','(a00)0s0','(a00)0ss','(a00)00s',],
2735    'B m m b':['(0b0)','(0b0)s00','(1b0)','(1b0)s00','(a00)','(a00)0s0','(a00)0ss','(a00)00s','(00g)','(00g)0s0','(00g)ss0','(00g)s00',],
2736    'C c m m':['(00g)','(00g)0s0','(01g)','(01g)0s0','(0b0)','(0b0)00s','(0b0)s0s','(0b0)s00','(a00)','(a00)00s','(a00)0ss','(a00)0s0',],
2737    'A m a m':['(a00)','(a00)00s','(a01)','(a01)00s','(00g)','(00g)s00','(00g)ss0','(00g)0s0','(0b0)','(0b0)s00','(0b0)s0s','(0b0)00s',],
2738#64       
2739    'C m c a':['(00g)','(00g)s00','(10g)','(10g)s00','(0b0)','(0b0)00s','(0b0)s0s','(0b0)s00','(a00)','(a00)00s','(a00)0ss','(a00)0s0',],
2740    'A b m a':['(a00)','(a00)0s0','(a10)','(a10)0s0','(00g)','(00g)s00','(00g)ss0','(00g)0s0','(0b0)','(0b0)s00','(0b0)s0s','(0b0)00s',],
2741    'B b c m':['(0b0)','(0b0)00s','(0b1)','(0b1)00s','(a00)','(a00)0s0','(a00)0ss','(a00)00s','(00g)','(00g)0s0','(00g)ss0','(00g)s00',],
2742    'B m a b':['(0b0)','(0b0)s00','(1b0)','(1b0)s00','(00g)','(00g)0s0','(00g)ss0','(00g)s00','(a00)','(a00)0s0','(a00)0ss','(a00)00s',],
2743    'C c m b':['(00g)','(00g)0s0','(01g)','(01g)0s0','(a00)','(a00)00s','(a00)0ss','(a00)0s0','(0b0)','(0b0)00s','(0b0)s0s','(0b0)s00',],
2744    'A c a m':['(a00)','(a00)00s','(a01)','(a01)00s','(0b0)','(0b0)s00','(0b0)s0s','(0b0)00s','(00g)','(00g)s00','(00g)ss0','(00g)0s0',],
2745#65       
2746    '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',],
2747    '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',],
2748    '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',],
2749#66       
2750    'C c c m':['(00g)','(00g)s00','(10g)','(10g)s00','(0b0)','(0b0)00s','(0b0)s0s','(0b0)s00',],
2751    'A m m a':['(a00)','(a00)0s0','(a10)','(a10)0s0','(00g)','(00g)s00','(00g)ss0','(00g)0s0',],
2752    'B b m b':['(0b0)','(0b0)00s','(0b1)','(0b1)00s','(a00)','(a00)0s0','(a00)0ss','(a00)00s',],
2753#67       
2754    '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',],
2755    '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',],
2756    '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',],
2757    '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',],
2758    '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',],
2759    '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',],
2760#68 o@i
2761    'C c c a':['(00g)','(00g)s00','(10g)','(01g)','(10g)s00','(01g)s00',
2762        '(a00)','(a00)s00','(a00)ss0','(a00)0s0','(0b0)','(0b0)s00','(0b0)ss0','(0b0)0s0'],
2763    'A b a a':['(a00)','(a00)s00','(a10)','(a01)','(a10)s00','(a01)s00',
2764        '(0b0)','(0b0)s00','(0b0)ss0','(0b0)0s0','(00g)','(00g)s00','(00g)ss0','(00g)0s0'],
2765    'B b c b':['(0b0)','(0b0)s00','(0b1)','(1b0)','(0b1)s00','(1b0)s00',
2766        '(00g)','(00g)s00','(00g)ss0','(0b0)0s0','(a00)','(a00)s00','(a00)ss0','(a00)0s0'],
2767    'B b a b':['(0b0)','(0b0)s00','(1b0)','(0b1)','(1b0)s00','(0b1)s00',
2768        '(a00)','(a00)s00','(a00)ss0','(a00)0s0','(00g)','(00g)s00','(00g)ss0','(00g)0s0'],
2769    'C c c b':['(00g)','(00g)ss0','(01g)','(10g)','(01g)s00','(10g)s00',
2770        '(0b0)','(0b0)s00','(0b0)ss0','(0b0)0s0','(a00)','(a00)s00','(a00)ss0','(a00)0s0'],
2771    'A c a a':['(a00)','(a00)ss0','(a01)','(a10)','(a01)s00','(a10)s00',
2772        '(00g)','(00g)s00','(00g)ss0','(00g)0s0','(0b0)','(0b0)s00','(0b0)ss0','(0b0)0s0'],
2773#69       
2774    'F m m m':['(00g)','(00g)s00','(00g)ss0','(a00)','(a00)s00',
2775        '(a00)ss0','(0b0)','(0b0)s00','(0b0)ss0',
2776        '(10g)','(10g)s00','(10g)ss0','(a10)','(a10)0s0',
2777        '(a10)00s','(a10)0ss','(0b1)','(0b1)s00','(0b1)00s','(0b1)s0s',
2778        '(01g)','(01g)s00','(01g)ss0','(a01)','(a01)0s0',
2779        '(a01)00s','(a01)0ss','(1b0)','(1b0)s00','(1b0)00s','(1b0)s0s'],
2780#70 o@i       
2781    'F d d d':['(00g)','(00g)s00','(a00)','(a00)s00','(0b0)','(0b0)s00'],       
2782#71
2783    'I m m m':['(00g)','(00g)s00','(00g)ss0','(a00)','(a00)0s0',
2784        '(a00)ss0','(0b0)','(0b0)s00','(0b0)ss0'],
2785#72       
2786    'I b a 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 b':['(a00)','(a00)0s0','(a00)00s','(a00)0ss','(0b0)','(0b0)00s',
2789        '(0b0)s00','(0b0)s0s','(00g)','(00g)0s0','(00g)s00','(00g)ss0'],
2790    'I c m a':['(0b0)','(0b0)00s','(0b0)s00','(0b0)s0s','(00g)','(00g)s00',
2791        '(00g)0s0','(00g)ss0','(a00)','(a00)00s','(a00)0s0','(a00)0ss'],
2792#73       
2793    'I b c a':['(00g)','(00g)s00','(00g)0s0','(00g)ss0','(a00)','(a00)0s0',
2794        '(a00)00s','(a00)0ss','(0b0)','(0b0)s00','(0b0)00s','(0b0)s0s'],
2795    'I c a b':['(00g)','(00g)s00','(00g)0s0','(00g)ss0','(a00)','(a00)0s0',
2796        '(a00)00s','(a00)0ss','(0b0)','(0b0)s00','(0b0)00s','(0b0)s0s'],
2797#74       
2798    'I m m a':['(00g)','(00g)s00','(00g)0s0','(00g)ss0','(a00)','(a00)0s0',
2799        '(a00)00s','(a00)0ss','(0b0)','(0b0)s00','(0b0)00s','(0b0)s0s'],
2800    'I b m m':['(00g)','(00g)s00','(00g)0s0','(00g)ss0','(a00)','(a00)0s0',
2801        '(a00)00s','(a00)0ss','(0b0)','(0b0)s00','(0b0)00s','(0b0)s0s'],
2802    'I m c m':['(00g)','(00g)s00','(00g)0s0','(00g)ss0','(a00)','(a00)0s0',
2803        '(a00)00s','(a00)0ss','(0b0)','(0b0)s00','(0b0)00s','(0b0)s0s'],
2804    'I m a m':['(00g)','(00g)s00','(00g)0s0','(00g)ss0','(a00)','(a00)0s0',
2805        '(a00)00s','(a00)0ss','(0b0)','(0b0)s00','(0b0)00s','(0b0)s0s'],
2806    'I m m b':['(00g)','(00g)s00','(00g)0s0','(00g)ss0','(a00)','(a00)0s0',
2807        '(a00)00s','(a00)0ss','(0b0)','(0b0)s00','(0b0)00s','(0b0)s0s'],
2808    'I c m m':['(00g)','(00g)s00','(00g)0s0','(00g)ss0','(a00)','(a00)0s0',
2809        '(a00)00s','(a00)0ss','(0b0)','(0b0)s00','(0b0)00s','(0b0)s0s'],
2810#tetragonal - done & checked
2811#75
2812    'P 4':['(00g)','(00g)q','(00g)s','(1/21/2g)','(1/21/2g)q',],
2813#76
2814    'P 41':['(00g)','(1/21/2g)',],
2815#77
2816    'P 42':['(00g)','(00g)q','(1/21/2g)','(1/21/2g)q',],
2817#78
2818    'P 43':['(00g)','(1/21/2g)',],
2819#79
2820    'I 4':['(00g)','(00g)q','(00g)s',],
2821#80
2822    'I 41':['(00g)','(00g)q',],
2823#81
2824    'P -4':['(00g)','(1/21/2g)',],
2825#82
2826    'I -4':['(00g)',],
2827#83
2828    'P 4/m':['(00g)','(00g)s0','(1/21/2g)',],
2829#84
2830    'P 42/m':['(00g)','(1/21/2g)',],
2831#85 o@i q0 -> 00
2832    'P 4/n':['(00g)','(00g)s0','(1/21/2g)',], #q0?
2833#86 o@i q0 -> 00
2834    'P 42/n':['(00g)','(1/21/2g)',],      #q0?
2835#87
2836    'I 4/m':['(00g)','(00g)s0',],
2837#88
2838    'I 41/a':['(00g)',],
2839#89
2840    'P 4 2 2':['(00g)','(00g)q00','(00g)s00','(1/21/2g)','(1/21/2g)q00',],
2841#90
2842    'P 4 21 2':['(00g)','(00g)q00','(00g)s00',],
2843#91
2844    'P 41 2 2':['(00g)','(1/21/2g)',],
2845#92
2846    'P 41 21 2':['(00g)',],
2847#93
2848    'P 42 2 2':['(00g)','(00g)q00','(1/21/2g)','(1/21/2g)q00',],
2849#94
2850    'P 42 21 2':['(00g)','(00g)q00',],
2851#95
2852    'P 43 2 2':['(00g)','(1/21/2g)',],
2853#96
2854    'P 43 21 2':['(00g)',],
2855#97
2856    'I 4 2 2':['(00g)','(00g)q00','(00g)s00',],
2857#98
2858    'I 41 2 2':['(00g)','(00g)q00',],
2859#99
2860    'P 4 m m':['(00g)','(00g)ss0','(00g)0ss','(00g)s0s','(1/21/2g)','(1/21/2g)0ss'],
2861#100
2862    'P 4 b m':['(00g)','(00g)ss0','(00g)0ss','(00g)s0s','(1/21/2g)qq0','(1/21/2g)qqs',],
2863#101
2864    'P 42 c m':['(00g)','(00g)0ss','(1/21/2g)','(1/21/2g)0ss',],
2865#102
2866    'P 42 n m':['(00g)','(00g)0ss','(1/21/2g)qq0','(1/21/2g)qqs',],
2867#103
2868    'P 4 c c':['(00g)','(00g)ss0','(1/21/2g)',],
2869#104
2870    'P 4 n c':['(00g)','(00g)ss0','(1/21/2g)qq0',],
2871#105
2872    'P 42 m c':['(00g)','(00g)ss0','(1/21/2g)',],
2873#106
2874    'P 42 b c':['(00g)','(00g)ss0','(1/21/2g)qq0',],
2875#107
2876    'I 4 m m':['(00g)','(00g)ss0','(00g)0ss','(00g)s0s',],
2877#108
2878    'I 4 c m':['(00g)','(00g)ss0','(00g)0ss','(00g)s0s',],
2879#109
2880    'I 41 m d':['(00g)','(00g)ss0',],
2881#110
2882    'I 41 c d':['(00g)','(00g)ss0',],
2883#111
2884    'P -4 2 m':['(00g)','(00g)0ss','(1/21/2g)','(1/21/2g)0ss',],
2885#112
2886    'P -4 2 c':['(00g)','(1/21/2g)',],
2887#113
2888    'P -4 21 m':['(00g)','(00g)0ss',],
2889#114
2890    'P -4 21 c':['(00g)',],
2891#115    00s -> 0ss
2892    'P -4 m 2':['(00g)','(00g)0s0','(1/21/2g)',],
2893#116
2894    'P -4 c 2':['(00g)','(1/21/2g)',],
2895#117    00s -> 0ss
2896    'P -4 b 2':['(00g)','(00g)0s0','(1/21/2g)0q0',],
2897#118
2898    'P -4 n 2':['(00g)','(1/21/2g)0q0',],
2899#119
2900    'I -4 m 2':['(00g)','(00g)0s0',],
2901#120
2902    'I -4 c 2':['(00g)','(00g)0s0',],
2903#121    00s -> 0ss
2904    'I -4 2 m':['(00g)','(00g)0ss',],
2905#122
2906    'I -4 2 d':['(00g)',],
2907#123
2908    'P 4/m m m':['(00g)','(00g)s0s0','(00g)00ss','(00g)s00s',
2909        '(1/21/2g)','(1/21/2g)s0s0','(1/21/2g)00ss','(1/21/2g)s00s',],
2910#124
2911    'P 4/m c c':['(00g)','(00g)s0s0','(1/21/2g)',],
2912#125    o@i q0q0 -> 0000, q0qs -> 00ss
2913    'P 4/n b m':['(00g)','(00g)s0s0','(00g)00ss','(00g)s00s','(1/21/2g)','(1/21/2g)00ss',],
2914#126    o@i q0q0 -> 0000
2915    'P 4/n n c':['(00g)','(00g)s0s0','(1/21/2g)',],
2916#127
2917    'P 4/m b m':['(00g)','(00g)s0s0','(00g)00ss','(00g)s00s',],
2918#128
2919    'P 4/m n c':['(00g)','(00g)s0s0',],
2920#129
2921    'P 4/n m m':['(00g)','(00g)s0s0','(00g)00ss','(00g)s00s',],
2922#130
2923    'P 4/n c c':['(00g)','(00g)s0s0',],
2924#131
2925    'P 42/m m c':['(00g)','(00g)s0s0','(1/21/2g)',],
2926#132
2927    'P 42/m c m':['(00g)','(00g)00ss','(1/21/2g)','(1/21/2g)00ss',],
2928#133    o@i q0q0 -> 0000
2929    'P 42/n b c':['(00g)','(00g)s0s0','(1/21/2g)',],
2930#134    o@i q0q0 -> 0000, q0qs -> 00ss
2931    'P 42/n n m':['(00g)','(00g)00ss','(1/21/2g)','(1/21/2g)00ss',],
2932#135
2933    'P 42/m b c':['(00g)','(00g)s0s0',],
2934#136
2935    'P 42/m n m':['(00g)','(00g)00ss',],
2936#137
2937    'P 42/n m c':['(00g)','(00g)s0s0',],
2938#138
2939    'P 42/n c m':['(00g)','(00g)00ss',],
2940#139
2941    'I 4/m m m':['(00g)','(00g)s0s0','(00g)00ss','(00g)s00s',],
2942#140
2943    'I 4/m c m':['(00g)','(00g)s0s0','(00g)00ss','(00g)s00s',],
2944#141
2945    'I 41/a m d':['(00g)','(00g)s0s0',],
2946#142
2947    'I 41/a c d':['(00g)','(00g)s0s0',],
2948    #trigonal/rhombahedral - done & checked
2949#143
2950    'P 3':['(00g)','(00g)t','(1/31/3g)',],
2951#144
2952    'P 31':['(00g)','(1/31/3g)',],
2953#145
2954    'P 32':['(00g)','(1/31/3g)',],
2955#146
2956    'R 3':['(00g)','(00g)t',],
2957#147
2958    'P -3':['(00g)','(1/31/3g)',],
2959#148
2960    'R -3':['(00g)',],
2961#149
2962    'P 3 1 2':['(00g)','(00g)t00','(1/31/3g)',],
2963#150
2964    'P 3 2 1':['(00g)','(00g)t00',],
2965#151
2966    'P 31 1 2':['(00g)','(1/31/3g)',],
2967#152
2968    'P 31 2 1':['(00g)',],
2969#153
2970    'P 32 1 2':['(00g)','(1/31/3g)',],
2971#154
2972    'P 32 2 1':['(00g)',],
2973#155
2974    'R 3 2':['(00g)','(00g)t0',],
2975#156
2976    'P 3 m 1':['(00g)','(00g)0s0',],
2977#157
2978    'P 3 1 m':['(00g)','(00g)00s','(1/31/3g)','(1/31/3g)00s',],
2979#158
2980    'P 3 c 1':['(00g)',],
2981#159
2982    'P 3 1 c':['(00g)','(1/31/3g)',],
2983#160
2984    'R 3 m':['(00g)','(00g)0s',],
2985#161
2986    'R 3 c':['(00g)',],
2987#162
2988    'P -3 1 m':['(00g)','(00g)00s','(1/31/3g)','(1/31/3g)00s',],
2989#163
2990    'P -3 1 c':['(00g)','(1/31/3g)',],
2991#164
2992    'P -3 m 1':['(00g)','(00g)0s0',],
2993#165
2994    'P -3 c 1':['(00g)',],
2995#166       
2996    'R -3 m':['(00g)','(00g)0s',],
2997#167
2998    'R -3 c':['(00g)',],
2999    #hexagonal - done & checked
3000#168
3001    'P 6':['(00g)','(00g)h','(00g)t','(00g)s',],
3002#169
3003    'P 61':['(00g)',],
3004#170
3005    'P 65':['(00g)',],
3006#171
3007    'P 62':['(00g)','(00g)h',],
3008#172
3009    'P 64':['(00g)','(00g)h',],
3010#173
3011    'P 63':['(00g)','(00g)h',],
3012#174
3013    'P -6':['(00g)',],
3014#175
3015    'P 6/m':['(00g)','(00g)s0',],
3016#176
3017    'P 63/m':['(00g)',],
3018#177
3019    'P 6 2 2':['(00g)','(00g)h00','(00g)t00','(00g)s00',],
3020#178
3021    'P 61 2 2':['(00g)',],
3022#179
3023    'P 65 2 2':['(00g)',],
3024#180
3025    'P 62 2 2':['(00g)','(00g)h00',],
3026#181
3027    'P 64 2 2':['(00g)','(00g)h00',],
3028#182
3029    'P 63 2 2':['(00g)','(00g)h00',],
3030#183
3031    'P 6 m m':['(00g)','(00g)ss0','(00g)0ss','(00g)s0s',],
3032#184
3033    'P 6 c c':['(00g)','(00g)s0s',],
3034#185
3035    'P 63 c m':['(00g)','(00g)0ss',],
3036#186
3037    'P 63 m c':['(00g)','(00g)0ss',],
3038#187
3039    'P -6 m 2':['(00g)','(00g)0s0',],
3040#188
3041    'P -6 c 2':['(00g)',],
3042#189
3043    'P -6 2 m':['(00g)','(00g)00s',],
3044#190
3045    'P -6 2 c':['(00g)',],
3046#191
3047    'P 6/m m m':['(00g)','(00g)s0s0','(00g)00ss','(00g)s00s',],
3048#192
3049    'P 6/m c c':['(00g)','(00g)s00s',],
3050#193
3051    'P 63/m c m':['(00g)','(00g)00ss',],
3052#194
3053    'P 63/m m c':['(00g)','(00g)00ss'],
3054    }
3055
3056#'A few non-standard space groups for test use'
3057nonstandard_sglist = ('P 21 1 1','P 1 21 1','P 1 1 21','R 3 r','R 3 2 h', 
3058                      'R -3 r', 'R 3 2 r','R 3 m h', 'R 3 m r',
3059                      'R 3 c r','R -3 c r','R -3 m r',),
3060
3061#A list of orthorhombic space groups that were renamed in the 2002 Volume A,
3062# along with the pre-2002 name. The e designates a double glide-plane'''
3063sgequiv_2002_orthorhombic= (('A e m 2', 'A b m 2',),
3064                            ('A e a 2', 'A b a 2',),
3065                            ('C m c e', 'C m c a',),
3066                            ('C m m e', 'C m m a',),
3067                            ('C c c e', 'C c c a'),)
3068#Use the space groups types in this order to list the symbols in the
3069#order they are listed in the International Tables, vol. A'''
3070symtypelist = ('triclinic', 'monoclinic', 'orthorhombic', 'tetragonal', 
3071               'trigonal', 'hexagonal', 'cubic')
3072
3073# self-test materials follow. Requires files in directory testinp
3074selftestlist = []
3075'''Defines a list of self-tests'''
3076selftestquiet = True
3077def _ReportTest():
3078    'Report name and doc string of current routine when ``selftestquiet`` is False'
3079    if not selftestquiet:
3080        import inspect
3081        caller = inspect.stack()[1][3]
3082        doc = eval(caller).__doc__
3083        if doc is not None:
3084            print('testing '+__file__+' with '+caller+' ('+doc+')')
3085        else:
3086            print('testing '+__file__()+" with "+caller)
3087def test0():
3088    '''self-test #0: exercise MoveToUnitCell'''
3089    _ReportTest()
3090    msg = "MoveToUnitCell failed"
3091    assert (MoveToUnitCell([1,2,3])[0] == [0,0,0]).all, msg
3092    assert (MoveToUnitCell([2,-1,-2])[0] == [0,0,0]).all, msg
3093    assert abs(MoveToUnitCell(np.array([-.1]))[0]-0.9)[0] < 1e-6, msg
3094    assert abs(MoveToUnitCell(np.array([.1]))[0]-0.1)[0] < 1e-6, msg
3095selftestlist.append(test0)
3096
3097def test1():
3098    '''self-test #1: SpcGroup against previous results'''
3099    #'''self-test #1: SpcGroup and SGPrint against previous results'''
3100    _ReportTest()
3101    testdir = ospath.join(ospath.split(ospath.abspath( __file__ ))[0],'testinp')
3102    if ospath.exists(testdir):
3103        if testdir not in sys.path: sys.path.insert(0,testdir)
3104    import spctestinp
3105    def CompareSpcGroup(spc, referr, refdict, reflist): 
3106        'Compare output from GSASIIspc.SpcGroup with results from a previous run'
3107        # if an error is reported, the dictionary can be ignored
3108        msg0 = "CompareSpcGroup failed on space group %s" % spc
3109        result = SpcGroup(spc)
3110        if result[0] == referr and referr > 0: return True
3111        keys = result[1].keys()
3112        #print result[1]['SpGrp']
3113        #msg = msg0 + " in list lengths"
3114        #assert len(keys) == len(refdict.keys()), msg
3115        for key in refdict.keys():
3116            if key == 'SGOps' or  key == 'SGCen':
3117                msg = msg0 + (" in key %s length" % key)
3118                assert len(refdict[key]) == len(result[1][key]), msg
3119                for i in range(len(refdict[key])):
3120                    msg = msg0 + (" in key %s level 0" % key)
3121                    assert np.allclose(result[1][key][i][0],refdict[key][i][0]), msg
3122                    msg = msg0 + (" in key %s level 1" % key)
3123                    assert np.allclose(result[1][key][i][1],refdict[key][i][1]), msg
3124            else:
3125                msg = msg0 + (" in key %s" % key)
3126                assert result[1][key] == refdict[key], msg
3127        msg = msg0 + (" in key %s reflist" % key)
3128        #for (l1,l2) in zip(reflist, SGPrint(result[1])):
3129        #    assert l2.replace('\t','').replace(' ','') == l1.replace(' ',''), 'SGPrint ' +msg
3130        # for now disable SGPrint testing, output has changed
3131        #assert reflist == SGPrint(result[1]), 'SGPrint ' +msg
3132    for spc in spctestinp.SGdat:
3133        CompareSpcGroup(spc, 0, spctestinp.SGdat[spc], spctestinp.SGlist[spc] )
3134selftestlist.append(test1)
3135
3136def test2():
3137    '''self-test #2: SpcGroup against cctbx (sgtbx) computations'''
3138    _ReportTest()
3139    testdir = ospath.join(ospath.split(ospath.abspath( __file__ ))[0],'testinp')
3140    if ospath.exists(testdir):
3141        if testdir not in sys.path: sys.path.insert(0,testdir)
3142    import sgtbxtestinp
3143    def CompareWcctbx(spcname, cctbx_in, debug=0):
3144        'Compare output from GSASIIspc.SpcGroup with results from cctbx.sgtbx'
3145        cctbx = cctbx_in[:] # make copy so we don't delete from the original
3146        spc = (SpcGroup(spcname))[1]
3147        if debug: print spc['SpGrp']
3148        if debug: print spc['SGCen']
3149        latticetype = spcname.strip().upper()[0]
3150        # lattice type of R implies Hexagonal centering", fix the rhombohedral settings
3151        if latticetype == "R" and len(spc['SGCen']) == 1: latticetype = 'P'
3152        assert latticetype == spc['SGLatt'], "Failed: %s does not match Lattice: %s" % (spcname, spc['SGLatt'])
3153        onebar = [1]
3154        if spc['SGInv']: onebar.append(-1)
3155        for (op,off) in spc['SGOps']:
3156            for inv in onebar:
3157                for cen in spc['SGCen']:
3158                    noff = off + cen
3159                    noff = MoveToUnitCell(noff)[0]
3160                    mult = tuple((op*inv).ravel().tolist())
3161                    if debug: print "\n%s: %s + %s" % (spcname,mult,noff)
3162                    for refop in cctbx:
3163                        if debug: print refop
3164                        # check the transform
3165                        if refop[:9] != mult: continue
3166                        if debug: print "mult match"
3167                        # check the translation
3168                        reftrans = list(refop[-3:])
3169                        reftrans = MoveToUnitCell(reftrans)[0]
3170                        if all(abs(noff - reftrans) < 1.e-5):
3171                            cctbx.remove(refop)
3172                            break
3173                    else:
3174                        assert False, "failed on %s:\n\t %s + %s" % (spcname,mult,noff)
3175    for key in sgtbxtestinp.sgtbx:
3176        CompareWcctbx(key, sgtbxtestinp.sgtbx[key])
3177selftestlist.append(test2)
3178
3179def test3(): 
3180    '''self-test #3: exercise SytSym (includes GetOprPtrName, GenAtom, GetKNsym)
3181     for selected space groups against info in IT Volume A '''
3182    _ReportTest()
3183    def ExerciseSiteSym (spc, crdlist):
3184        'compare site symmetries and multiplicities for a specified space group'
3185        msg = "failed on site sym test for %s" % spc
3186        (E,S) = SpcGroup(spc)
3187        assert not E, msg
3188        for t in crdlist:
3189            symb, m = SytSym(t[0],S)
3190            if symb.strip() != t[2].strip() or m != t[1]:
3191                print spc,t[0],m,symb,t[2]
3192            assert m == t[1]
3193            #assert symb.strip() == t[2].strip()
3194
3195    ExerciseSiteSym('p 1',[
3196            ((0.13,0.22,0.31),1,'1'),
3197            ((0,0,0),1,'1'),
3198            ])
3199    ExerciseSiteSym('p -1',[
3200            ((0.13,0.22,0.31),2,'1'),
3201            ((0,0.5,0),1,'-1'),
3202            ])
3203    ExerciseSiteSym('C 2/c',[
3204            ((0.13,0.22,0.31),8,'1'),
3205            ((0.0,.31,0.25),4,'2(y)'),
3206            ((0.25,.25,0.5),4,'-1'),
3207            ((0,0.5,0),4,'-1'),
3208            ])
3209    ExerciseSiteSym('p 2 2 2',[
3210            ((0.13,0.22,0.31),4,'1'),
3211            ((0,0.5,.31),2,'2(z)'),
3212            ((0.5,.31,0.5),2,'2(y)'),
3213            ((.11,0,0),2,'2(x)'),
3214            ((0,0.5,0),1,'222'),
3215            ])
3216    ExerciseSiteSym('p 4/n',[
3217            ((0.13,0.22,0.31),8,'1'),
3218            ((0.25,0.75,.31),4,'2(z)'),
3219            ((0.5,0.5,0.5),4,'-1'),
3220            ((0,0.5,0),4,'-1'),
3221            ((0.25,0.25,.31),2,'4(001)'),
3222            ((0.25,.75,0.5),2,'-4(001)'),
3223            ((0.25,.75,0.0),2,'-4(001)'),
3224            ])
3225    ExerciseSiteSym('p 31 2 1',[
3226            ((0.13,0.22,0.31),6,'1'),
3227            ((0.13,0.0,0.833333333),3,'2(100)'),
3228            ((0.13,0.13,0.),3,'2(110)'),
3229            ])
3230    ExerciseSiteSym('R 3 c',[
3231            ((0.13,0.22,0.31),18,'1'),
3232            ((0.0,0.0,0.31),6,'3'),
3233            ])
3234    ExerciseSiteSym('R 3 c R',[
3235            ((0.13,0.22,0.31),6,'1'),
3236            ((0.31,0.31,0.31),2,'3(111)'),
3237            ])
3238    ExerciseSiteSym('P 63 m c',[
3239            ((0.13,0.22,0.31),12,'1'),
3240            ((0.11,0.22,0.31),6,'m(100)'),
3241            ((0.333333,0.6666667,0.31),2,'3m(100)'),
3242            ((0,0,0.31),2,'3m(100)'),
3243            ])
3244    ExerciseSiteSym('I a -3',[
3245            ((0.13,0.22,0.31),48,'1'),
3246            ((0.11,0,0.25),24,'2(x)'),
3247            ((0.11,0.11,0.11),16,'3(111)'),
3248            ((0,0,0),8,'-3(111)'),
3249            ])
3250selftestlist.append(test3)
3251
3252if __name__ == '__main__':
3253    # run self-tests
3254    selftestquiet = False
3255    for test in selftestlist:
3256        test()
3257    print "OK"
Note: See TracBrowser for help on using the repository browser.