1 | # -*- coding: utf-8 -*- |
---|
2 | """ |
---|
3 | *MAXMAGN: Interface to Bilbao MAXMAGN web page* |
---|
4 | ------------------------------- |
---|
5 | |
---|
6 | Extraction of Maximal magnetic space groups for a given space group and a propagation vector |
---|
7 | from the MAXMAGN 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/MAXMAGN.py $ |
---|
15 | # $Id: MAXMAGN.py 3465 2018-07-10 16:41:00Z vondreele $ |
---|
16 | ########### SVN repository information ################### |
---|
17 | from __future__ import division, print_function |
---|
18 | import requests |
---|
19 | try: |
---|
20 | import HTMLParser as HTML |
---|
21 | except ImportError: |
---|
22 | import html.parser as HTML # Python 3 |
---|
23 | |
---|
24 | site='http://www.cryst.ehu.es/cgi-bin/cryst/programs/nph-msglist2' |
---|
25 | |
---|
26 | class TableParser(HTML.HTMLParser): |
---|
27 | def __init__(self): |
---|
28 | HTML.HTMLParser.__init__(self) |
---|
29 | self.spgp = '' |
---|
30 | self.in_sp = False |
---|
31 | self.in_pre = False |
---|
32 | self.in_sub = False |
---|
33 | self.MV = '' |
---|
34 | self.BNS = '' |
---|
35 | self.beg = False |
---|
36 | self.SPGPs = [] |
---|
37 | self.MVs = [] |
---|
38 | self.BNSs = [] |
---|
39 | |
---|
40 | def handle_starttag(self, tag, attrs): |
---|
41 | # print('tag:',tag) |
---|
42 | if tag == 'i' and self.beg: |
---|
43 | self.in_sp = True |
---|
44 | self.spgp = '' |
---|
45 | self.BNS = '' |
---|
46 | elif tag == 'pre': |
---|
47 | self.in_pre = True |
---|
48 | self.MV = '' |
---|
49 | elif tag == 'sub': |
---|
50 | self.in_sub = True |
---|
51 | |
---|
52 | def handle_data(self, data): |
---|
53 | # print('*',data) |
---|
54 | if self.in_sp: |
---|
55 | if self.in_sub and len(self.spgp) == 1: |
---|
56 | self.spgp += '_' |
---|
57 | self.spgp += data |
---|
58 | if len(self.spgp) == 3 and '_' in self.spgp: |
---|
59 | self.spgp += ' ' |
---|
60 | self.BNS = data |
---|
61 | if self.in_pre: |
---|
62 | self.MV = data |
---|
63 | |
---|
64 | def handle_endtag(self, tag): |
---|
65 | # print ('end tag:',tag) |
---|
66 | if tag == 'h2': |
---|
67 | self.beg = True |
---|
68 | elif tag == 'i' and self.beg: |
---|
69 | self.in_sp = False |
---|
70 | if self.spgp[:3] not in ['Sys','Ten']: |
---|
71 | self.SPGPs.append(self.spgp) |
---|
72 | self.BNSs.append(self.BNS) |
---|
73 | # print('space group:',self.spgp,' BNS: ',self.BNS) |
---|
74 | self.spgp = '' |
---|
75 | elif tag == 'pre': |
---|
76 | self.in_pre = False |
---|
77 | self.MVs.append(self.MV.replace('\n',' ')) |
---|
78 | # print('MV:') |
---|
79 | # print(self.MV) |
---|
80 | elif tag == 'sub': |
---|
81 | self.in_sub = False |
---|
82 | |
---|
83 | def MAXMAGN(sg,kvec): |
---|
84 | print(''' |
---|
85 | For use of MAXMAGN, please cite: |
---|
86 | Symmetry-Based Computational Tools for Magnetic Crystallography, |
---|
87 | J.M. Perez-Mato, S.V. Gallego, E.S. Tasci, L. Elcoro, G. de la Flor, and M.I. Aroyo |
---|
88 | Annu. Rev. Mater. Res. 2015. 45,217â48. |
---|
89 | doi: 10.1146/annurev-matsci-070214-021008 |
---|
90 | ''') |
---|
91 | postdict = {'gua':'','gor':'','grha':'','kb':'conventional+dual+%28ITA%29', |
---|
92 | 'bnsog':'BNS','list':'Submit'} |
---|
93 | postdict['gnum'] = str(sg) |
---|
94 | for i,k in zip(('x','y','z'),kvec): |
---|
95 | postdict['k'+i] = str(k) |
---|
96 | r = requests.post(site,postdict) |
---|
97 | if r.status_code == 200: |
---|
98 | print('request OK') |
---|
99 | page = r.text |
---|
100 | else: |
---|
101 | page = '' |
---|
102 | print('request failed. Reason=',r.reason) |
---|
103 | return [] |
---|
104 | r.close() |
---|
105 | |
---|
106 | p = TableParser() |
---|
107 | p.feed(page) |
---|
108 | result = list(zip(p.SPGPs,p.BNSs,p.MVs)) |
---|
109 | return result |
---|
110 | |
---|
111 | def test(): |
---|
112 | results = MAXMAGN(141,(0.5,0,0)) |
---|
113 | if results: |
---|
114 | for spgp,bns,mv in results: |
---|
115 | print('Space group:',spgp, 'BNS:',bns) |
---|
116 | print('MV') |
---|
117 | print(mv) |
---|
118 | |
---|
119 | |
---|
120 | if __name__ == '__main__': |
---|
121 | # run self-tests |
---|
122 | selftestquiet = False |
---|
123 | test() |
---|
124 | print ("OK") |
---|