source: trunk/SUBGROUPS.py @ 3765

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

make super group ComboBox? allow editing for nonOSX.

File size: 10.9 KB
Line 
1# -*- coding: utf-8 -*-
2"""
3*SUBGROUPS: Interface to special GSAS Bilbao SUBGROUPS & k-SUBGROUPSMAG web pages*
4-------------------------------
5
6Extraction of  space subgroups for a given space group and a propagation vector
7from the GSAS version of SUBGROUPS & k-SUBGROUPSMAG web page on the Bilbao Crystallographic server
8
9"""
10########### SVN repository information ###################
11# $Date: 2018-07-10 11:41:00 -0500 (Tue, 10 Jul 2018) $
12# $Author: vondreele $
13# $Revision: 3465 $
14# $URL: https://subversion.xray.aps.anl.gov/pyGSAS/trunk/kSUBGROUPSMAG.py $
15# $Id: kSUBGROUPSMAG.py 3465 2018-07-10 16:41:00Z vondreele $
16########### SVN repository information ###################
17from __future__ import division, print_function
18import requests
19import GSASIIspc as G2spc
20import GSASIIpath
21GSASIIpath.SetBinaryPath()
22submagSite = 'http://www.cryst.ehu.es/cgi-bin/cryst/programs/subgrmag1_general_GSAS.pl'
23
24def GetNonStdSubgroups(SGData, kvec,star=False,landau=False,maximal=False):
25    '''Run Bilboa's SUBGROUPS for a non-standard space group.
26    This requires doing a post to the Bilboa site, which returns all
27    subgroups of the entered space group as the text of a web page
28    with a table containing the space group symbol, the
29    transformation matrix and index for each subgroup.
30
31    :params list kvec: propogation vector as a list of nine string fractions or blank
32    :params SGData: space group object (see :ref:`Space Group object<SGData_table>`)
33
34    :returns: (error,text) error: if True no error or False; where
35      text containts a possible web page text
36    '''
37    print('''
38    For use of SUBGROUPS, please cite:
39      Symmetry-Based Computational Tools for Magnetic Crystallography,
40      J.M. Perez-Mato, S.V. Gallego, E.S. Tasci, L. Elcoro, G. de la Flor, and M.I. Aroyo
41      Annu. Rev. Mater. Res. 2015. 45,217-48.
42      doi: 10.1146/annurev-matsci-070214-021008
43    ''')
44       
45       
46    def getSpGrp(item):
47        return item.replace('<i>','').replace('</i>','').replace('<sub>','').replace('</sub>','')
48   
49    def getMatVec(item):
50        return item.replace('{','[').replace('}',']')
51               
52    starmag = 'no'
53    if star:
54        starmag = 'yes'
55    land = 'no'
56    if landau:
57        land = 'yes'
58    celtodas = 'no'
59    limite = 'spgroup'
60    if maximal:
61        limite = 'maximal'
62    postdict = {'centrosymmetry':'0','crystalsystem':'0','landau':land,
63               'eleccion':'subgrmag1_k','inicio':'nostandard','celtodas':celtodas,
64               'limite':limite,'list':'Submit','listado':'lista','starmagnetica':starmag,
65               'pointgroup':'0','polarity':'0','sub':'1',
66               'super':'','tipog':'gesp','wyckoffstrain':''}
67    text,table = G2spc.SGPrint(SGData)
68    OpList = G2spc.TextOps(text,table,reverse=True)
69#    GenList = G2spc.TextGen(SGData,reverse=True)
70    for item in OpList:
71        item += '\n'
72    sym = ""
73    for i in OpList:
74        if sym: sym += '\n'
75        #if sym: sym += ' ' # use this for testing to generate an error in place of previous
76        sym += i.lower()
77    postdict['generators'] = sym
78    for j in [1,2,3]:
79        if kvec[3*j-3] == ' ':
80            break
81        for i,k in zip(('x','y','z'),kvec[3*j-3:3*j]):
82            postdict['knm%d%s'%(j,i)] = k
83    try:
84        r = requests.post(submagSite,postdict)
85    except:     #ConnectionError?
86        page = ''
87        print('connection error - not on internet')
88        return None,None
89    if r.status_code == 200:
90        print('request OK')
91        page = r.text
92        page = page.replace('<font style= "text-decoration: overline;">','<font>-')
93    else:
94        page = ''
95        print('request failed. Reason=',r.reason)
96        return None,None
97    r.close()
98   
99    result = page.replace('&','\n')
100    result = result.split('\n')
101    SPGPs = []
102    MVs = []
103    baseList = []
104    itemList = []
105    superList = []
106    altList = []
107    start = 0
108    for line in result:    #work around bug report from Bilbao
109        start += 1
110        if 'yesz' in line:
111            break
112    for line in result[start:]:
113        if 'GGG' in line:
114            lines = line.split('GGG')
115            line = lines[0]
116            alts = []
117            beg = True
118            for sline in lines:
119                items = sline.split('z')
120                gid = int(items[0])
121                if beg:
122                    baseList.append(gid)
123                    beg = False
124                alts.append(gid)
125                itemList.append(gid)
126                superList.append(getMatVec(items[7]))
127                SPGPs.append(getSpGrp(items[4]))
128                MVs.append([getMatVec(items[5]),getMatVec(items[6])])
129            altList.append(alts)
130            for sline in lines[1:]:
131                altList.append([])
132        else:
133            items = line.split('z')
134            gid = int(items[0])
135            altList.append([gid,])
136            baseList.append(gid)
137            itemList.append(gid)
138            superList.append(getMatVec(items[7]))
139            SPGPs.append(getSpGrp(items[4]))
140            MVs.append([getMatVec(items[5]),getMatVec(items[6])])
141    result = list(zip(SPGPs,MVs,itemList,altList,superList))
142    return result,baseList
143
144def GetNonStdSubgroupsmag(SGData, kvec,star=False,landau=False,maximal=False):
145    '''Run Bilboa's k-Subgroupsmag for a non-standard space group.
146    This requires doing a post to the Bilboa site, which returns all
147    magnetic subgroups of the entered subgroup as the text of a web page
148    with a table containing the BNS magnetic space group symbol, the
149    transformation matrix and index for each subgroup.
150
151    :params list kvec: propogation vector as a list of three numbers
152    :params SGData: space group object (see :ref:`Space Group object<SGData_table>`)
153
154    :returns: (error,text) error: if True no error or False; where
155      text containts a possible web page text
156    '''
157    print('''
158    For use of k-SUBGROUPSMAG, please cite:
159      Symmetry-Based Computational Tools for Magnetic Crystallography,
160      J.M. Perez-Mato, S.V. Gallego, E.S. Tasci, L. Elcoro, G. de la Flor, and M.I. Aroyo
161      Annu. Rev. Mater. Res. 2015. 45,217-48.
162      doi: 10.1146/annurev-matsci-070214-021008
163    ''')
164
165    def getSpGrp(item):
166        return item.replace('<i>','').replace('</i>','').replace('<sub>','').replace('</sub>','')
167   
168    def getBNS(item):
169        spgrp = getSpGrp(item)
170        bns = ''
171        sid = item.find('<sub>')
172        if sid == 8:
173            bns = spgrp[1]
174            spgrp = '%s_%s %s'%(spgrp[0],bns,spgrp[2:])
175        return spgrp,bns
176   
177    def getMatVec(item):
178        return item.replace('{','[').replace('}',']')
179               
180    starmag = 'no'
181    if star:
182        starmag = 'yes'
183    land = 'no'
184    if landau:
185        land = 'yes'
186    celtodas = 'no'
187    limite = 'spgroup'
188    if maximal:
189        limite = 'maximal'
190    postdict = {'centrosymmetry':'0','crystalsystem':'0','landau':land,
191               'eleccion':'subgrmag1_k','inicio':'nostandard','celtodas':celtodas,
192               'limite':limite,'list':'Submit','listado':'lista','starmagnetica':starmag,
193               'pointgroup':'0','polarity':'0','sub':'1.1',
194               'super':'','tipog':'gmag','wyckoffstrain':''}
195    text,table = G2spc.SGPrint(SGData)
196    OpList = G2spc.TextOps(text,table,reverse=True)
197#    OpList = G2spc.TextGen(SGData,reverse=True)
198    for item in OpList:
199        item += '\n'
200    sym = ""
201    for i in OpList:
202        if sym: sym += '\n'
203        #if sym: sym += ' ' # use this for testing to generate an error in place of previous
204        sym += i.lower()
205    postdict['generators'] = sym
206    for j in [1,2,3]:
207        if kvec[3*j-3] == ' ':
208            break
209        for i,k in zip(('x','y','z'),kvec[3*j-3:3*j]):
210            postdict['km%d%s'%(j,i)] = k
211    try:
212        r = requests.post(submagSite,postdict)
213    except:     #ConnectionError?
214        page = ''
215        print('connection error - not on internet')
216        return None,None
217    if r.status_code == 200:
218        print('request OK')
219        page = r.text
220        page = page.replace('<font style= "text-decoration: overline;">','<font>-')
221    else:
222        page = ''
223        print('request failed. Reason=',r.reason)
224        return None,None
225    r.close()
226
227    result = page.replace('&','\n')
228    result = result.split('\n')
229    start = 0
230    for line in result:    #work around bug report from Bilbao
231        start += 1
232        if 'yesz' in line:
233            break
234    SPGPs = []
235    BNSs = []
236    MVs = []
237    baseList = []
238    itemList = []
239    superList = []
240    altList = []
241    for line in result[start:]:
242        if 'GGG' in line:
243            lines = line.split('GGG')
244            alts = []
245            beg = True
246            for sline in lines:
247                items = sline.split('z')
248                gid = int(items[0])
249                if beg:
250                    baseList.append(gid)
251                    beg = False
252                alts.append(gid)
253                itemList.append(gid)
254                superList.append(getMatVec(items[7]))
255                spgrp,bns = getBNS(items[4])
256                SPGPs.append(spgrp)
257                BNSs.append(bns)
258                MVs.append([getMatVec(items[5]),getMatVec(items[6])])
259            altList.append(alts)
260            for sline in lines[1:]:
261                altList.append([])
262        else:
263            items = line.split('z')
264            gid = int(items[0])
265            altList.append([gid,])
266            baseList.append(gid)
267            itemList.append(gid)
268            superList.append(getMatVec(items[7]))
269            spgrp,bns = getBNS(items[4])
270            SPGPs.append(spgrp)
271            BNSs.append(bns)
272            MVs.append([getMatVec(items[5]),getMatVec(items[6])])
273    result = list(zip(SPGPs,BNSs,MVs,itemList,altList,superList))
274    return result,baseList
275
276def test():
277    SGData = G2spc.SpcGroup('f d -3 m')[1]
278   
279    print('test SUBGROUPSMAG')           
280    results,baseList = GetNonStdSubgroupsmag(SGData,('0','0','0',' ',' ',' ',' ',' ',' ',' '))
281    if results:
282        for [spgp,bns,mv,gid,altList,supList] in results:
283            if gid in baseList:
284                print('Space group: %d %s BNS: %s'%(gid,spgp,bns))
285                print('MV',mv)
286                print('altList:',altList)
287                print('superList: ',supList)
288               
289    print('test SUBGROUPS')
290    results,baseList = GetNonStdSubgroups(SGData,('1/3','1/3','1/2',' ',' ',' ',' ',' ',' ',' '))
291    if results:
292        for [spgp,mv,gid,altList,supList] in results:
293            if gid in baseList:
294                print('Space group: %d %s'%(gid,spgp))
295                print('MV',mv)
296                print('altList:',altList)
297                print('superList: ',supList)
298               
299       
300
301if __name__ == '__main__':
302    # run self-tests
303    selftestquiet = False
304    test()
305    print ("OK")
Note: See TracBrowser for help on using the repository browser.