-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrecenterVolume_rel3.1_NEW_pos4ToIDAf.py
93 lines (70 loc) · 2.09 KB
/
recenterVolume_rel3.1_NEW_pos4ToIDAf.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#!/usr/bin/env python
import optparse
import itertools
import math
import os,sys
import glob
#import heapq
import numpy as np
def setupParserOptions():
parser = optparse.OptionParser()
parser.set_usage("%prog -f run_data.star")
parser.add_option("-f",dest="f1",type="string",metavar="FILE",
help=".star file")
options,args = parser.parse_args()
if len(args) > 1:
parser.error("Unknown commandline options: " +str(args))
if len(sys.argv) < 2:
parser.print_help()
sys.exit()
params={}
for i in parser.option_list:
if isinstance(i.dest,str):
params[i.dest] = getattr(options,i.dest)
return params
def getMat(rot, tilt, psi):
[rot, tilt, psi]=map(np.radians,[rot, tilt, psi])
M1=np.array([ [np.cos(rot), -np.sin(rot), 0],\
[np.sin(rot), np.cos(rot), 0],\
[0, 0, 1]])
M2=np.array([ [np.cos(tilt), 0, -np.sin(tilt)],\
[0, 1, 0],\
[np.sin(tilt), 0, np.cos(tilt)]])
M3=np.array([ [np.cos(psi), -np.sin(psi), 0],\
[np.sin(psi), np.cos(psi), 0],\
[0, 0, 1]])
return np.matmul(M3,np.matmul(M2,M1))
def recenter(rot,tilt,psi,offX,offY,d=[0,0,0]):
M=getMat(-rot,-tilt,-psi)
d1= np.matmul(M,d)
return (offX+d1[0],offY+d1[1])
def mainloop(params):
f1 = file(params['f1'])
l1 = f1.readlines()
d=[200.,0.,100.]
fout = file("%s_pos4ToIDAf.star"%(params['f1'][:-5]),"w")
# first write out the header
#for i in range(100):
# t1 = l1[i].split()
# if len(t1) < 13:
# fout.write("%s"%l1[i])
for line in l1:
l=line.split()
if len(l)>1:
if l[1][0]=='#':
if l[0]=='_rlnAngleRot': rotN=int(l[1].split('#')[1])-1
elif l[0]=='_rlnAngleTilt': tiltN=int(l[1].split('#')[1])-1
elif l[0]=='_rlnAnglePsi': psiN=int(l[1].split('#')[1])-1
elif l[0]=='_rlnOriginXAngst': oxN=int(l[1].split('#')[1])-1
elif l[0]=='_rlnOriginYAngst': oyN=int(l[1].split('#')[1])-1
else:
if len(l)>10:
(l[oxN],l[oyN])=recenter(float(l[rotN]),float(l[tiltN]),float(l[psiN]),float(l[oxN]),float(l[oyN]),d)
for item in l:
fout.write(str(item)+" ")
fout.write("\n")
f1.close()
fout.close()
if __name__ == "__main__":
params = setupParserOptions()
mainloop(params)