/
batch_convert.py
61 lines (57 loc) · 2.65 KB
/
batch_convert.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import sys
import subprocess
from lines_to_3d_wave import lines_to_3d_wave
from ift_atom_selection import atom_selection
from rotate_3d import calc_rot_array_from_hkl, rotate as rot
from model import Model
from math import sqrt
def main():
if(len(sys.argv) != 4):
raise Exception("Usage: paramfile, jobid, npix for center positions of spots")
paramfile = sys.argv[1]
jobid = sys.argv[2]
npix = int(sys.argv[3])
#types = ['mgrid','ft_onespot1','ft_onespot2']
types = ['mgrid']
with open(paramfile) as f:
params = f.readlines()
params = [x.strip() for x in params]
modelfile = params[0]
stop = int(params[1])
for i in range(0,stop):
j = i*7 +2
for t in types:
prefix = params[j] + t + '_' + jobid
file = prefix + '.gfx'
lines_to_3d_wave(file, prefix + '.txt')
if(t == 'mgrid'):
p = subprocess.Popen(['/home/maldonis/3dft/stdev',file,jobid], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
for nextline in iter(p.stdout.readline, ""):
sys.stdout.write(nextline)
sys.stdout.flush()
poutput = p.stdout.read()
perr = p.stderr.read()
preturncode = p.wait()
if(preturncode != 0):
print("stdev exit status: "+str(preturncode))
raise Exception("stdev failed on file {0}!".format(file)+perr)
new_model_file_base_name = params[j] + jobid
worked = atom_selection(modelfile, 'stdev_'+jobid+'.gfx', 256, new_model_file_base_name)
x0,y0,z0 = tuple([float(x) for x in params[j+1].split()])
sx,sy,sz = tuple([float(x) for x in params[j+2].split()])
cxy,cxz,cyz = tuple([float(x) for x in params[j+3].split()])
xc = eval(params[j+4].split()[2])
yc = eval(params[j+5].split()[2])
zc = eval(params[j+6].split()[2])
gvec = float(params[j+6].split()[3])
print("g-vector length = {0}".format(gvec))
print("The more correct g-vector length == {0}".format(sqrt((npix/4.0-x0+1)**2 + (npix/4.0-y0+1)**2 + (npix/4.0-z0)**2+1)*3.0/(npix/2)))
if(worked == 0):
m = Model(new_model_file_base_name+'.xyz')
rot_arr = calc_rot_array_from_hkl(npix/2-xc,npix/2-yc,npix/2-zc)
rot(m, rot_arr)
m.write(new_model_file_base_name+'.rotated.xyz')
m.write(new_model_file_base_name+'.rotated.cif')
print('')
if __name__ == '__main__':
main()