1 | # -*- coding: utf-8 -*- |
---|
2 | """ |
---|
3 | *ISODISTORT: Interface to BYU ISODISTORT web pages* |
---|
4 | ------------------------------- |
---|
5 | |
---|
6 | |
---|
7 | """ |
---|
8 | ########### SVN repository information ################### |
---|
9 | # $Date: 2018-07-10 11:41:00 -0500 (Tue, 10 Jul 2018) $ |
---|
10 | # $Author: vondreele $ |
---|
11 | # $Revision: 3465 $ |
---|
12 | # $URL: https://subversion.xray.aps.anl.gov/pyGSAS/trunk/kSUBGROUPSMAG.py $ |
---|
13 | # $Id: kSUBGROUPSMAG.py 3465 2018-07-10 16:41:00Z vondreele $ |
---|
14 | ########### SVN repository information ################### |
---|
15 | from __future__ import division, print_function |
---|
16 | import requests |
---|
17 | import copy |
---|
18 | isouploadsite = 'https://stokes.byu.edu/iso/isodistortuploadfile.php' |
---|
19 | isoformsite = 'https://iso.byu.edu/iso/isodistortform.php' |
---|
20 | |
---|
21 | def GetISODISTORT(Phase,parentcif): |
---|
22 | '''Run Stokes & Campbell ISODISTORT. |
---|
23 | This requires doing a post to the BYU upload site with a cif file, which returns a BYU local |
---|
24 | copy. This is then sent to the BYU form site with various options, which returns all |
---|
25 | subgroups of the entered space group as the text of a web page with a table containing the space |
---|
26 | group symbol, the transformation matrix and index for each subgroup. Selection of one of these is |
---|
27 | returned to the BYU form site which returns the text of a cif file to be used to create the new phase |
---|
28 | which can apply the distortion mode constraints |
---|
29 | |
---|
30 | :params dict Phase: GSAS-II phase data |
---|
31 | :params str parentcif: parent cif file name - should be local to working directory |
---|
32 | |
---|
33 | :returns: radio: dict of possible distortion structures |
---|
34 | :returns: data2: list of str input for next run of isositortform for extracting cif file |
---|
35 | ''' |
---|
36 | |
---|
37 | print(''' |
---|
38 | For use of ISODISTORT, please cite: |
---|
39 | H. T. Stokes, D. M. Hatch, and B. J. Campbell, ISODISTORT, ISOTROPY Software Suite, iso.byu.edu. |
---|
40 | B. J. Campbell, H. T. Stokes, D. E. Tanner, and D. M. Hatch, "ISODISPLACE: An Internet Tool for Exploring Structural Distortions." |
---|
41 | J. Appl. Cryst. 39, 607-614 (2006). |
---|
42 | ''') |
---|
43 | |
---|
44 | |
---|
45 | #upload cif file to BYU web site |
---|
46 | |
---|
47 | up1 = {'toProcess':(parentcif,open(parentcif,'rb')),} |
---|
48 | out1 = requests.post(isouploadsite,files=up1).text |
---|
49 | |
---|
50 | #retrieve BYU temp file name for cif file |
---|
51 | |
---|
52 | pos = out1.index('<INPUT')+7 |
---|
53 | pos1 = out1.index('VALUE=',pos)+7 |
---|
54 | filename = out1[pos1:out1.index('"',pos1)] |
---|
55 | |
---|
56 | print('filename=',filename) |
---|
57 | |
---|
58 | #submit cif for processing by ISODISTORT |
---|
59 | |
---|
60 | up2 = {'filename':filename,'input':'uploadparentcif'} |
---|
61 | out2 = requests.post(isoformsite,up2).text |
---|
62 | |
---|
63 | #recover required info for the distortion search; includes info from cif file (no longer needed) |
---|
64 | |
---|
65 | pos = out2.index('<p><FORM') |
---|
66 | data = {} |
---|
67 | while True: |
---|
68 | try: |
---|
69 | posB = out2[pos:].index('INPUT TYPE')+pos |
---|
70 | posF = out2[posB:].index('>')+posB |
---|
71 | items = out2[posB:posF].split('=',3) |
---|
72 | name = items[2].split()[0].replace('"','') |
---|
73 | if 'isosystem' in name: |
---|
74 | break |
---|
75 | vals = items[3].replace('"','') |
---|
76 | data[name] = vals |
---|
77 | pos = posF |
---|
78 | except ValueError: |
---|
79 | break |
---|
80 | #save copy for future use |
---|
81 | data2 = copy.deepcopy(data) |
---|
82 | |
---|
83 | #no limits on space group or lattice |
---|
84 | |
---|
85 | data['isosubgroup'] = 'no choice' |
---|
86 | data['isolattice'] = 'no choice' |
---|
87 | data['isoplattice'] = 'no choice' |
---|
88 | |
---|
89 | #do the distortion search - result is radio button list of choices |
---|
90 | |
---|
91 | out3 = requests.post(isoformsite,data=data).text |
---|
92 | |
---|
93 | #extract the radio button collection |
---|
94 | |
---|
95 | radio = {} |
---|
96 | num = 0 |
---|
97 | pos = out3.index('RADIO') |
---|
98 | while True: |
---|
99 | try: |
---|
100 | posF = out3[pos:].index('<BR>')+pos |
---|
101 | num += 1 |
---|
102 | items = out3[pos:posF].split('=',2) |
---|
103 | radio['orderparam%d'%num] = items[2].replace('"','') |
---|
104 | pos = out3[posF:].index('RADIO')+posF |
---|
105 | except ValueError: |
---|
106 | break |
---|
107 | |
---|
108 | return radio,data2 |
---|
109 | |
---|
110 | def GetISODISTORTcif(Phase): |
---|
111 | '''Run Stokes & Campbell ISODISTORT. |
---|
112 | Selection of one of the order parameter disrections is returned to the BYU |
---|
113 | form site which returns the text of a cif file to be used to create the new phase |
---|
114 | which can apply the distortion mode constraints |
---|
115 | |
---|
116 | :params dict Phase: GSAS-II phase data; contains result of GetISODISTORT above & selection |
---|
117 | |
---|
118 | :returns: CIFfile str: name of cif file created by this in local directory |
---|
119 | ''' |
---|
120 | |
---|
121 | ISOdata = Phase['ISODISTORT'] |
---|
122 | data2 = ISOdata['rundata'] |
---|
123 | #choose one & resubmit |
---|
124 | data2['origintype'] = 'method1' |
---|
125 | data2['orderparam'] = ISOdata['selection'][1] |
---|
126 | data2['input'] = 'distort' |
---|
127 | # for item in data2: |
---|
128 | # print(item,data2[item]) |
---|
129 | out4 = requests.post(isoformsite,data=data2).text |
---|
130 | #print(out4) |
---|
131 | #open('pyout4.html','wb').write(out4.encode("utf-8")) |
---|
132 | |
---|
133 | #retrieve data needed for next(last) step |
---|
134 | |
---|
135 | pos = out4.index('<FORM ACTION') |
---|
136 | data3 = {} |
---|
137 | while True: |
---|
138 | try: |
---|
139 | posB = out4[pos:].index('INPUT TYPE')+pos |
---|
140 | posF = out4[posB:].index('>')+posB |
---|
141 | items = out4[posB:posF].split('=',3) |
---|
142 | name = items[2].split()[0].replace('"','') |
---|
143 | if 'subsetting' in name: |
---|
144 | data3[name] = '' |
---|
145 | pos = posF |
---|
146 | continue |
---|
147 | elif 'atomsfile' in name: |
---|
148 | data3[name] = ' ' |
---|
149 | pos = posF |
---|
150 | continue |
---|
151 | vals = items[3].replace('"','') |
---|
152 | data3[name] = vals |
---|
153 | pos = posF |
---|
154 | if 'lattparamsub' in name: |
---|
155 | break |
---|
156 | except ValueError: |
---|
157 | break |
---|
158 | |
---|
159 | #request a cif file |
---|
160 | |
---|
161 | data3['origintype'] = 'structurefile' |
---|
162 | data3['inputvalues'] = 'false' |
---|
163 | data3['atomicradius'] = '0.4' |
---|
164 | data3['bondlength'] = '2.50' |
---|
165 | data3['modeamplitude'] = '1.0' |
---|
166 | data3['strainamplitude'] = '0.1' |
---|
167 | # for item in data3: |
---|
168 | # print(item,data3[item]) |
---|
169 | k = requests.post(isoformsite,data=data3) |
---|
170 | out5 = k.text #this is output cif! |
---|
171 | #print(out5) |
---|
172 | names = ISOdata['selection'][1].split() |
---|
173 | cifFile = '%s_%s%s%s.cif'%(Phase['General']['Name'],names[1],names[2].replace('*','_'),names[3]) |
---|
174 | fl = open(cifFile,'wb') |
---|
175 | fl.write(out5.encode("utf-8")) |
---|
176 | fl.close() |
---|
177 | return cifFile |
---|