I am running a code with tk console in VMD (Visual Molecular Dynamics). The first problem I encountered was that the code took up too much of my computer's processing power and caused VMD to shut down. I think this is because I was having it print every result to the file. I really only need to look at the results where the distance is less than 20. Below is the original code that was causing VMD to close:
set seg1 [atomselect top "segname LA0 and name CA"]
set seg2 [atomselect top "segname RA0 and name CA"]
set file [open "Contact_map27.dat" w]
set list1 [$seg1 get index]
set list2 [$seg2 get index]
foreach atom1 $list1 {
foreach atom2 $list2 {
set index1 [atomselect top "index $atom1"]
set index2 [atomselect top "index $atom2"]
set resid1 [[atomselect top "index $atom1"] get resid]
set resid2 [[atomselect top "index $atom2"] get resid]
set resnm1 [[atomselect top "index $atom1"] get resname]
set resnm2 [[atomselect top "index $atom2"] get resname]
puts $file "$resnm1 $resid1 $resnm2 $resid2 [veclength [vecsub [measure center $index1] [measure center $index2]]]"
$index1 delete
$index2 delete
}
}
close $file
Below is the modification I made that should only print the values if the distance is less than 20:
set seg1 [atomselect top "segname LA0 and name CA"]
set seg2 [atomselect top "segname RA0 and name CA"]
set file [open "Contact_map27.dat" w]
set list1 [$seg1 get index]
set list2 [$seg2 get index]
foreach atom1 $list1 {
foreach atom2 $list2 {
set index1 [atomselect top "index $atom1"]
set index2 [atomselect top "index $atom2"]
set resid1 [[atomselect top "index $atom1"] get resid]
set resid2 [[atomselect top "index $atom2"] get resid]
set resnm1 [[atomselect top "index $atom1"] get resname]
set resnm2 [[atomselect top "index $atom2"] get resname]
set dist [[veclength [vecsub [measure center $index1] [measure center $index2]]]]
if {$dist < 20} {
puts $file "$resnm1 $resid1 $resnm2 $resid2 $dist"}
else {puts $file " "}
$index1 delete
$index2 delete
}
}
close $file
The error message I get when I run the second code is "invalid command name "26.774817104116487""
If anyone can just give me a second pair of eyes and let me know what is going on I would greatly appreciate it! Thanks in advance!