From: Windle,Stephen (snw42_at_drexel.edu)
Date: Sat Nov 04 2017 - 17:05:40 CDT

Ok, so, I have 4 proteins loaded, and I've added a for loop to cycle through each one and perform the task. However, I am getting an error that reads "Bad weight sum: would cause divide by zero." Any advice on what is causing this? Here is the script:

set x 0

for { set x 0 } { $x < 4 } { incr x } {

set allsel [atomselect $x "sidechain and resname ALA"]
set residuelist [lsort -unique -integer [$allsel get residue]]

set ressellist [list ]
foreach residue $residuelist {
lappend ressellist [atomselect top "residue $residue"]
}

set file [open "myoutput.txt" w]

set filename $x

for { set i 0 } { $i < [llength $ressellist] } { incr i } {
for { set j [expr {$i+1}] } { $j < [llength $ressellist] } { incr j } {
puts $file "$i $j [veclength [vecsub [measure center [lindex $ressellist $i]] [measure center [lindex $ressellist $j]]]]"
}

}

close $file

}

Thanks!

________________________________
From: Chitrak Gupta <chgupta_at_mix.wvu.edu>
Sent: Friday, November 3, 2017 7:16:55 PM
To: Windle,Stephen
Cc: Vermaas, Joshua; vmd-l_at_ks.uiuc.edu
Subject: Re: vmd-l: Computing atom distances

Yes, the puts $file is in the wrong place. I haven't read the details of your code, but this is the necessary change

puts "$i $j [veclength [vecsub [measure center [lindex $ressellist $i]] [measure center [lindex $ressellist $j]]]]"

should become

puts $fp "$i $j [veclength [vecsub [measure center [lindex $ressellist $i]] [measure center [lindex $ressellist $j]]]]"

In general, if it is showing up on the Tk console window, it isn't being written to the file. So if it works correctly, you should just see a frozen Tk console screen until the script finishes running.

HTH.
Chitrak.

On Fri, Nov 3, 2017 at 5:29 PM, Windle,Stephen <snw42_at_drexel.edu<mailto:snw42_at_drexel.edu>> wrote:

Thank you all for your tips. They've been most helpful. If I've learned anything in coding, it's that fixing one problem leads to another. This is no exception. For some reason, my output file is empty. The numbers I want are showing up in the TK Console just not making it to the file. I am assuming I'm doing something foolish with the script. Here it is (it's a slightly adjusted variation of what was already posted on this thread):

set allsel [atomselect top "sidechain and resname ALA"]
set residuelist [lsort -unique -integer [$allsel get residue]]

set ressellist [list ]
foreach residue $residuelist {
lappend ressellist [atomselect top "residue $residue"]
}

set file [open "myoutput.dat" w]

puts $file [
for { set i 0 } { $i < [llength $ressellist] } { incr i } {
for { set j [expr {$i+1}] } { $j < [llength $ressellist] } { incr j } {
puts "$i $j [veclength [vecsub [measure center [lindex $ressellist $i]] [measure center [lindex $ressellist $j]]]]"
}
}
]

close $file

Am I putting my "puts $file" command in the wrong place? Should it go inside the for loop? Thanks again!

-Steve

________________________________
From: Vermaas, Joshua <Joshua.Vermaas_at_nrel.gov<mailto:Joshua.Vermaas_at_nrel.gov>>
Sent: Tuesday, October 31, 2017 7:03:12 PM
To: Windle,Stephen; vmd-l_at_ks.uiuc.edu<mailto:vmd-l_at_ks.uiuc.edu>
Subject: Re: vmd-l: Computing atom distances

Hi Steve,

Tcl can be a messy beast. :) In terms of loading every single pdb in a directory, that is fairly simple:

set pdblist [glob *.pdb]
foreach pdb $pdblist {
mol new $pdb
}

Now you want to make some sort of measurement afterward. This also isn't *too* bad, but it really depends on what exactly you want to be measuring, why, and what kind of data format you want to get out. The simplest way might be something like this:

set allsel [atomselect top "protein"]
set residuelist [lsort -unique -integer [$allsel get residue]]

set ressellist [list ]
foreach residue $residuelist {
lappend ressellist [atomselect top "residue $residue"]
}

for { set i 0 } { $i < [llength $ressellist] } { incr i } {
for { set j [expr {$i+1}] } { $j < [llength $ressellist] } { incr j } {
puts "$i $j [veclength [vecsub [measure center [lindex $ressellist $i]] [measure center [lindex $ressellist $j]]]]"
}
}

This will measure the distance between any pair of protein residues in the top molecule, while only making a relatively small number of atomselections. Things a beginning VMDer should definitely read are the userguide (https://na01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww.ks.uiuc.edu%2FResearch%2Fvmd%2Fcurrent%2Fug&data=02%7C01%7Csnw42%40drexel.edu%7C5c2434391fd84f23ac4008d520b394ae%7C3664e6fa47bd45a696708c4f080f8ca6%7C0%7C0%7C636450878022113423&sdata=gxGdXXLbFoeDc9lfFAvLPVhuXoDGk5c%2B%2BZjsY%2BZJ6Is%3D&reserved=0), particularly the sections about Tcl/Tk scripting, and the available vector and matrix commands. Additionally, useful tcl commands to know/read up on are things like glob, expr, and the list-related commands. I often will refer back to https://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fwww.tcl.tk%2Fman%2Ftcl%2FTclCmd%2Fcontents.htm&data=02%7C01%7Csnw42%40drexel.edu%7C5c2434391fd84f23ac4008d520b394ae%7C3664e6fa47bd45a696708c4f080f8ca6%7C0%7C0%7C636450878022113423&sdata=IRYnIC42wio2RpfqIN0vQnd%2BHiqBMiS81rvo6RoHswU%3D&reserved=0.

Happy coding!

-Josh Vermaas

On 10/31/2017 04:17 PM, Windle,Stephen wrote:

VMD Users,

Good afternoon. I am very new to the VMD software, and I am working on putting together a script for a specific purpose, but I am unsure how much of it can be done as a single script. Essentially, I want to measure the distances between all the side chains of a specific amino acid in a given protein (for example distances between all the valine side chains). However, I want to be able to load anywhere from 1000-10,000 molecules into VMD and have the script do this for each molecule consecutively, exporting them into individual files (I should be able to write a loop for this, I imagine). So far I'm able to load a molecule and isolate the side chains of a specific amino acid. So my two key questions are this: Can a loop be written to load every .pdb file in a given folder, and what are the console commands to measure the distance between each side chain once they've been isolated into a named selection. I have tried searching through the indexed messages but to no avail. If someone could point me in the right direction that would be greatly appreciated. Thank you!

Regards,

Steve Windle