VMD-L Mailing List
From: Vermaas, Joshua (Joshua.Vermaas_at_nrel.gov)
Date: Fri Dec 15 2017 - 20:03:57 CST
- Next message: RAHUL SURESH: "Re: FFTK, regarding"
- Previous message: Ashar Malik: "Re: Same starting configuration gives two values of backbone RMSD"
- In reply to: Ashar Malik: "Re: Cycling between files using the same output file"
- Next in thread: Windle,Stephen: "Re: Cycling between files using the same output file"
- Reply: Windle,Stephen: "Re: Cycling between files using the same output file"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ] [ attachment ]
Hi Stephen,
A variant on Ashar's method if the files are already loaded is to wrap your existing script like this:
foreach mid [molinfo list] {
set allsel [atomselect $mid "sidechain and resname ALA"]
set residuelist [lsort -unique -integer [$allsel get residue]]
set ressellist [list ]
foreach residue $residuelist {
lappend ressellist [atomselect $mid "residue $residue"]
}
set file [open "myoutput$mid.dat" w]
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
}
If you are deadset on writing it one giant file (which I can't recommend! Its awful to parse out what goes where afterward!), move the file opening and closing outside the loop. You may also want to consider deleting atomselections after you are done with them, as VMD can run out of them given a large enough problemset.
-Josh
On 12/15/2017 05:23 PM, Ashar Malik wrote:
Hey,
To get you to write your own code here is a hint.
(Assuming I understand your question -- this may be way off)
Think that all your PDB files are in a folder.
In your script use glob to populate a list of pdb files using something like
set pdb_list [glob *.pdb]
Now use a for loop over this list. Do something like
foreach pdb_file $pdb_list {
..
}
Inside the for loop load the PDB
mol load pdb_file $pdb
Note that every time you load a molecule it becomes "top". So running the code you sent with "top" will work for the last molecule added.
So now there are two ways -- I can think of.
Given that there is no relationship between the PDB files and all calculations are done with one pdb file. You can simply run through the for loop above loading a new PDB file in each iteration
Making the selections doing your work and deleting those selections to proper memory management.
The other way is that each time a new PDB file is loaded a ID will be assigned to that molecule
Append that to a list using "lappend" and then iterate over that list of molecular IDs.
Note that you may have to put two for loops, one to load the molecules and grab their IDs. The second to iterate over the list of IDs and do the work. If you just want to work on PDB files without having to go back and forth between them you should just used the earlier approach and not log the IDs. To use the molecule's ID you can do something like
[atomselect 17 all] # note that I replaced top with an integer 17 so if I have 30 molecules loaded into VMD - I can use this to select everything in molecule which was assigned mol ID 17.
Hope this helps.
On Sat, Dec 16, 2017 at 11:39 AM, Windle,Stephen <snw42_at_drexel.edu<mailto:snw42_at_drexel.edu>> wrote:
Good evening.
I am running a script to output distances on selected molecules to a specific file. I was trying to get it to loop between all the files loaded, but my loops don't seem to be working. What I want it to do is to run this script, but inside a loop that moves onto the next loaded .pdb file, and do the same, but output it to the end of the .dat file, so that it will cycle through however many files I have loaded and just add them to the end, making one really long file. The script is below (this is what it looks like before I started trying to add a for loop to have it run through the loaded files):
set allsel [atomselect top "sidechain and resname ALA"]
set ressellist [list ]
set file [open "myoutput.dat" w]
for { set i 0 } { $i < [llength $ressellist] } { incr i } {
}
close $file
..I am very new to the VMD environment, and haven't had luck looking through the manuals and readme files, so I'm not sure what I'm doing wrong. Thanks!
-Stephen
Grab that ID using the molinfo command with the ID ( http://www.ks.uiuc.edu/Research/vmd/vmd-1.7.1/ug/node125.html
set residuelist [lsort -unique -integer [$allsel get residue]]
foreach residue $residuelist {
lappend ressellist [atomselect top "residue $residue"]
}
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]]]]"
}
--
Best,
/A