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