source: trunk/ISODISTORT.py @ 5065

Last change on this file since 5065 was 5065, checked in by vondreele, 8 months ago

remove check on Histograms & Phases in beginning of UpdateConstraints? - had prevented viewing constraints when no phases
Always enable SHOWISO - same reason
remove check on length of varyList in LoadParmDict? - prevented export of cif when there was no refinement
checks on failed ISODISTORT runs - now shows resulting html page with error message
fixes to RMCProfile GUI startup
fix distortion mode plotting - now moves bonds & polyhedra
cif importer looks for space group number if symbol not interpretable - i.e. full HM symbol
remove a check on k==0 in line 993 of cif importer; k is always zero in ISODISTORT cifs when there in no preset mode distortion value
fix name bug in line 1008 & remove breakpoint in cif importer
ISODISTORT makes html page & displays it in case of ISODISTORT error

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