-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathcollect_tinker_minimize_results.py
executable file
·187 lines (143 loc) · 5.97 KB
/
collect_tinker_minimize_results.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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
#!/usr/bin/python
from sys import argv,exit
from glob import glob
from os.path import basename,exists
from os import popen,system
import string
outdirs = argv[1:]
native_supplied = 0
if (outdirs[0][-4:] == '.pdb' ): # Native specified
native_pdb = outdirs[ 0 ]
del( outdirs[ 0 ] )
native_supplied = 1
# Do not use outfile!!
for outdir in outdirs:
assert( outdir.count('_OUT' ) )
######################################
# look for rms column in outfile
#outfile_lines = popen( 'grep SCORE '+outfile ).readlines()
#headerline = outfile_lines[0]
#try:
#cols = string.split( headerline )
# found_rms_col = cols.index( 'rms' )
#except:
# found_rms_col = -1
#
#if (found_rms_col > -1 ):
# for line in outfile_lines[1:] :
# cols = string.split( line )
# tag = cols[-1]
# try:
# rms = float( cols[ found_rms_col ] )
# rms_vals[ tag ] = rms
# except:
# continue
native_exists = native_supplied
if not native_exists:
# Still look for native in rhiju's directory.
pos = outdir.index( 'chunk')
rna_name = outdir[pos:(pos+13)]
native_pdb = '/work/rhiju/projects/rna_new_benchmark/bench_final/%s_RNA.pdb' % rna_name
if not exists( native_pdb ):
native_pdb = '/home/rhiju/projects/rna_new_benchmark/bench_final/%s_RNA.pdb' % rna_name
if not exists( native_pdb ):
native_pdb = '/Users/rhiju/projects/rna_new_benchmark/bench_final/%s_RNA.pdb' % rna_name
if exists( native_pdb ):
native_exists = 1
if not native_exists:
print 'Could not find native', native_pdb
exit()
#############################################
# Go through scorefile from tinker minimization
globfiles = glob( outdir+'/*OUT/*sc' )
globfiles.sort()
all_scores = {}
score_terms = []
obligate_score_terms = ['Total_Potential_Energy', 'Intermolecular_Energy']
for score_term in obligate_score_terms:
score_terms.append( score_term )
all_scores[ score_term ] = {}
files_to_calc_rms = []
for file in globfiles:
for score_term in obligate_score_terms: all_scores[score_term][file] = 0.0 #Always have one of these terms.
lines = open( file ).readlines()
for line in lines:
cols = string.split( line.replace(':','') )
try:
score = float( cols[-2] )
score_term = string.join(cols[:-2],'_')
if score_term not in score_terms:
score_terms.append( score_term )
all_scores[ score_term ] = {}
all_scores[ score_term ][ file ] = score
except:
continue
if native_exists:
rmsfile = file.replace('.sc','.rms.txt')
if exists( rmsfile.replace('.rms.txt','.pdb') ) and not exists( rmsfile ):
files_to_calc_rms.append( rmsfile.replace('.rms.txt','.pdb' ) )
rmsfile = rmsfile.replace('min_','').replace('minimize_','')
if exists( rmsfile.replace('.rms.txt','.pdb') ) and not exists( rmsfile ):
files_to_calc_rms.append( rmsfile.replace('.rms.txt','.pdb' ) )
#print score_terms
##########################################################################
# superimpose any files that haven't been supermposed
if native_exists and len( files_to_calc_rms) > 0 :
# Create a text file with the pdbs. This used to go in on command line
# but unix has a limit.
fid = open( 'list.txt', 'w' )
for file in files_to_calc_rms:
fid.write( file+'\n')
fid.close()
command = '~rhiju/python/tinker_superimpose.py '+native_pdb+' list.txt'
print( command )
system( command )
##########################################################################
# read out rms's from saved files.
rms_vals = {}
rms_vals_init = {}
for file in globfiles:
rmsfile = file.replace( '.sc','.rms.txt' )
if not exists( rmsfile): continue
rmslines = popen( 'tail -n 1 '+rmsfile ).readlines()
if len( rmslines ) < 1: continue
rmsline = rmslines[-1]
if len( string.split(rmsline) ) < 1: continue
rms_vals[ file ] = float( string.split( rmsline )[-1] )
rmsfile = rmsfile.replace('min_','').replace('minimize_','')
if not exists( rmsfile): continue
rmslines = popen( 'tail -n 1 '+rmsfile ).readlines()
if len( rmslines ) < 1: continue
rmsline = rmslines[-1]
if len( string.split(rmsline) ) < 1: continue
rms_vals_init[ file ] = float( string.split( rmsline )[-1] )
######################################################
# Output unified scorefile.
new_scorefile = outdir.replace( '_OUT', '_minimize.sc' )
print ' Creating '+new_scorefile
fid = open( new_scorefile ,'w')
fid.write( 'SCORE: ' )
for score_term in score_terms:
fid.write( ' %10s' % score_term[:10] )
if native_exists:
fid.write( ' %8s' % 'rms_init' )
fid.write( ' %8s' % 'rms' )
fid.write( ' description\n' )
for file in globfiles:
if not file in rms_vals.keys(): continue
if not file in rms_vals_init.keys(): continue
score_term_present = 1
for score_term in score_terms:
if not file in all_scores[score_term].keys():
score_term_present = 0
break
if not score_term_present: continue
fid.write( 'SCORE: ' )
for score_term in score_terms:
fid.write( ' %10.4f' % all_scores[ score_term ][file ] )
if native_exists:
#tag = basename( file ).replace('min_','').replace('.sc','').replace('minimize_','')
fid.write( ' %8.4f' % rms_vals_init[ file ] )
fid.write( ' %8.4f' % rms_vals[ file ] )
fid.write( ' '+basename(file).replace('.sc','') + '\n' )
fid.close()