-
Notifications
You must be signed in to change notification settings - Fork 0
/
GetBonds.tcl
67 lines (63 loc) · 2.47 KB
/
GetBonds.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
# GET GetGGBonds
#------------------------------------------------------------------
# Description: The GetGGBonds procedure gets the bonds from a set of files that
# are (1) located in the directory, and (2) have the same structure (i.e. the same
# amount of atoms and residues). The pair indices are obtained by processing
# the first file in an ordered list, $listfile, provided by the user. These
# pairs are printed in order for the user to save them.
# A set of bond lengths will be appended to a csv file. A
package require csv
proc GetGGBonds {listfile} {
# Read a list since TCL orders files differently with globbing
set rfile [open $listfile r]
set files [read $rfile]
close $rfile
set first 1
foreach struct $files {
mol load pdb $struct
set sel [atomselect top "all"]
if {$first == 1} {
set Pairs [GetBondPairs $sel]
puts [list $Pairs] ;# Pairs are printed for user to save
set first 0
}
WriteCSV $Pairs
mol delete all
}
}
#Description: This function takes in an atomselect selection in order to
proc GetBondPairs {sel} {
set BondPairs {}
set bonds [$sel getbonds]
set siz [llength $bonds]
#For every atom i
for {set atomNum 0} {$atomNum < $siz} {incr atomNum} {
set atom [lindex [$sel list] $atomNum]
foreach bondedToSet [lindex $bonds $atomNum] { ;#For every set of atoms, s, bonded to i
foreach bondedTo $bondedToSet { ;#For every atom in s
set recBond [lsort [list $atom $bondedTo]]
set check [lsearch $BondPairs $recBond]
if { $check == -1} { ;#Only append if it's not there
lappend BondPairs $recBond
}
}
}
}
return lsort -integer -index 0 $BondPairs ;#Order based on first value
}
# Description: After obtaining a list with all pair of indices corresponding to bonds, WriteCSV
# appends, to a CSV file, the bond values. This output is customized for a paticular PDB structure
# containing 2 Guanine structures.
proc WriteCSV {Pairs} {
set file [open bondlengths.csv a+]
for {set pair 0} {$pair < 16} {incr pair} {
lappend bondl [measure bond [lindex $Pairs $pair]]
}
puts $file [::csv::join $bondl]
unset bondl
for {set pair 16} {$pair < 32} {incr pair} {
lappend bondl [measure bond [lindex $Pairs $pair]]
}
puts $file [::csv::join $bondl]
close $file
}