-
Notifications
You must be signed in to change notification settings - Fork 5
/
calculate_dihedrals.tcl
272 lines (205 loc) · 8.67 KB
/
calculate_dihedrals.tcl
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
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
# calculates side-chain dihedral (torsion) angles.
# example use:
# source calculate_dihedrals.tcl
# print_sidechain_dihedrals P "resid 1 to 10" top dihedral.angles
#source calculate_dihedrals.tcl
#VMD --- start of VMD description block
#Name:
# calculate dihedrals 1.0
#Synopsis:
# calcualtes side-chain dihedral (torsion) angles
#Version:
# 1.0
#Uses VMD version:
# 1.8
#Ease of use:
# 1
#Procedures:
# print_sidechain_dihedrals -- calcualtes the dihedral angles
#Example output:
# 1 SER 0 999.0-167.0 59.1
# 2 ALA 0 -91.9 -9.4
# 3 ASP 0 -87.6 75.2 -59.1 -83.8
# 4 VAL 0-125.6 46.4-155.2
# 5 ALA 0-102.2 -44.7
# 6 GLY 0 -78.6 -61.4
# 7 ALA 0 -82.9 62.0
# 8 VAL 0 -81.7 154.2 -95.1
# 9 ILE 0-112.6 159.0 77.1 176.3
# 10 ASP 0 -74.5 162.7 -67.1 110.5
#Files:
# <li> calcualte_dihedrals.tcl -- calcualtes the dihedral angles
# <li> dihedral_angles_atom_names.tcl -- procedures to get atom indices of dihedral angles
#Authors:
# Ajasja Ljubetiè ([email protected])
#\VMD --- end of block
source dihedral_angles_atom_names.tcl
proc get_backbone_dihedral_indices {resid resname chainname mol} {
set ressel [atomselect $mol "chain $chainname and resid $resid and name CA"]
set residue_index [$ressel get residue]
$ressel delete
set prev_residue_index [expr $residue_index-1]
set next_residue_index [expr $residue_index+1]
#Nitrogen
set atomsel [atomselect $mol "chain $chainname and residue $residue_index and name \"N\""]
set Ni [$atomsel get index]
$atomsel delete
#CA
set atomsel [atomselect $mol "chain $chainname and residue $residue_index and name \"CA\""]
set CAi [$atomsel get index]
$atomsel delete
#C(O)
set atomsel [atomselect $mol "chain $chainname and residue $residue_index and name \"C\""]
set Ci [$atomsel get index]
$atomsel delete
#if prevous residue exists
if {$prev_residue_index>=0} then {
#previous C(O)
set atomsel [atomselect $mol "chain $chainname and residue $prev_residue_index and name \"C\""]
set pCi [$atomsel get index]
$atomsel delete
lappend phi $pCi $Ni $CAi $Ci
} else {
set phi {}
}
#next N
set atomsel [atomselect $mol "chain $chainname and residue $next_residue_index and name \"N\""]
set nNi [$atomsel get index]
$atomsel delete
#next CA
set atomsel [atomselect $mol "chain $chainname and residue $next_residue_index and name \"CA\""]
set nCAi [$atomsel get index]
$atomsel delete
#if next residue exists
if {$nNi>0} then {
lappend psi $Ni $CAi $Ci $nNi
lappend omega $CAi $Ci $nNi $nCAi
} else {
set psi {}
set omega {}
}
lappend result $phi $psi $omega
return $result
}
proc get_sidechain_inidces {resid resname chain mol} {
lappend result $resid $resname $chain
lappend result [get_backbone_dihedral_indices $resid $resname $chain $mol]
#puts $result
switch $resname {
GLY {lappend result [get_GLY_sidechain_indicies $resid $resname $chain $mol]}
ALA {lappend result [get_ALA_sidechain_indicies $resid $resname $chain $mol]}
SER {lappend result [get_SER_sidechain_indicies $resid $resname $chain $mol]}
CYS {lappend result [get_CYS_sidechain_indicies $resid $resname $chain $mol]}
VAL {lappend result [get_VAL_sidechain_indicies $resid $resname $chain $mol]}
THR {lappend result [get_THR_sidechain_indicies $resid $resname $chain $mol]}
ILE {lappend result [get_ILE_sidechain_indicies $resid $resname $chain $mol]}
PRO {lappend result [get_PRO_sidechain_indicies $resid $resname $chain $mol]}
MET {lappend result [get_MET_sidechain_indicies $resid $resname $chain $mol]}
ASP {lappend result [get_ASP_sidechain_indicies $resid $resname $chain $mol]}
ASN {lappend result [get_ASN_sidechain_indicies $resid $resname $chain $mol]}
LEU {lappend result [get_LEU_sidechain_indicies $resid $resname $chain $mol]}
LYS {lappend result [get_LYS_sidechain_indicies $resid $resname $chain $mol]}
GLU {lappend result [get_GLU_sidechain_indicies $resid $resname $chain $mol]}
GLN {lappend result [get_GLN_sidechain_indicies $resid $resname $chain $mol]}
ARG {lappend result [get_ARG_sidechain_indicies $resid $resname $chain $mol]}
HIS {lappend result [get_HIS_sidechain_indicies $resid $resname $chain $mol]}
HSE {lappend result [get_HIS_sidechain_indicies $resid $resname $chain $mol]}
HSP {lappend result [get_HIS_sidechain_indicies $resid $resname $chain $mol]}
HSD {lappend result [get_HIS_sidechain_indicies $resid $resname $chain $mol]}
PHE {lappend result [get_PHE_sidechain_indicies $resid $resname $chain $mol]}
TYR {lappend result [get_TYR_sidechain_indicies $resid $resname $chain $mol]}
TRP {lappend result [get_TRP_sidechain_indicies $resid $resname $chain $mol]}
UNK {lappend result [get_UNK_sidechain_indicies $resid $resname $chain $mol]}
CMT {lappend result [get_CMT_sidechain_indicies $resid $resname $chain $mol]}
CMTS {lappend result [get_CMT_sidechain_indicies $resid $resname $chain $mol]}
}
return $result
}
proc get_all_sidechain_indices {resinfos chain mol} {
set result {}
foreach {resid resname} $resinfos {
#puts "$resid $resname $chain $mol"
lappend result [get_sidechain_inidces $resid $resname $chain $mol]
}
return $result
}
proc print_all_sidechain_dihedrals {indices frame_num output_file} {
#puts $indices
foreach {resid resname chain backbone_dihedrals dihedrals} $indices {
#puts "| $resid $resname $chain $backbone_dihedrals $dihedrals|"
set phi_indices [lindex $backbone_dihedrals 0]
set psi_indices [lindex $backbone_dihedrals 1]
#set omega_inidces [lindex backbone_dihedrals 2/]
#first phi doesent exist
if {[llength $phi_indices]} then {
set phi [measure dihed $phi_indices]
} else {
set phi 999
}
#lst psi doesent exist
if {[llength $psi_indices]} then {
set psi [measure dihed $psi_indices]
} else {
set psi 999
}
set outstring [format "%4.d%4.4s%9.d%6.1f%6.1f" $resid $resname $frame_num $phi $psi]
#if not empty list
if {[llength $dihedrals]} {
foreach dihedral $dihedrals {
set val [measure dihed $dihedral]
set val_str [format "%6.1f" $val]
append outstring $val_str
} ;#foreach dihedral
} ;# if not empty list
puts $output_file $outstring
} ;#foreach residue
}
puts "calculate dihedrals 1.0"
puts "proc print_sidechain_dihedrals {chain residues {mol top} {output_file_name \"stdout\"} {first_frame 0} {last_frame -1} {stride 1} {print_progress 0}}"
proc print_sidechain_dihedrals {chain residues {mol top} {output_file_name "stdout"} {first_frame 0} {last_frame -1} {stride 1} {print_progress 0}} {
#get residue list
set residues [atomselect $mol "chain $chain and $residues and name CA"]
set resinfos [join [$residues get {resid resname}]]
#puts $resinfos
if {($print_progress>0) && ($output_file_name != "stdout")} then {
set counter [expr [llength $resinfos]/2]
puts "Getting indices for $counter residues."
}
#get the atom indices of the dehidral (torsion) angles
set indices [join [get_all_sidechain_indices $resinfos $chain $mol]]
#puts $indices
if {($print_progress>0) && ($output_file_name != "stdout")} then {
set counter [expr [llength $resinfos]/2]
puts "Done."
}
#set output
if {$output_file_name == "stdout"} then {
set output_file stdout
} else {
set output_file [open $output_file_name w]}
#get current mol frame
set old_frame [molinfo $mol get frame]
#don't update display
display update off
#default last_frame is the number of all frames
if {$last_frame == -1} then {
set last_frame [expr [molinfo $mol get numframes] -1]}
set counter 0
#iterate along through all frames
for {set frame $first_frame} {$frame <= $last_frame} {incr frame $stride} {
incr counter
if {($print_progress>0) && ($counter>=$print_progress) && ($output_file_name != "stdout")} then {
puts "Working on frame $frame."
set counter 0
}
molinfo $mol set frame $frame
print_all_sidechain_dihedrals $indices $frame $output_file
}
#restore frame
molinfo $mol set frame $old_frame
#restore update
display update on
if {$output_file_name != "stdout"} then {
close $output_file}
$residues delete
}