×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Difficulty resolving "can not find channel number" error in my code

Difficulty resolving "can not find channel number" error in my code

Difficulty resolving "can not find channel number" error in my code

(OP)
Hi there all,

I have the below code, which is to be interpreted in the software package VMD, and I am having some basic Tcl problems with it. Basically what I want to do is to open a file, discard the first line of that file, and then store the numerical value of the 4th column of the file in a variable called trpshift, which I will use in VMD to color individual molecules.

I know that the coloring part of the script works, because I was able to use a similar script successfully, but now my input files are a bit different and I need to discard the first line (this wasn't an issue before, because I had specially formatted files to access). I found an example of how to discard a line in Tcl on a webpage somewhere, but I keep getting the error "can not find channel number <file contents>" when the script reaches the first nested while loop, the one that is supposed to process the file data. It appears that the entire contents of $file_data are being expanded within the while evaluation, but I can't get this behavior to stop.

Can anyone offer any help with this issue? This is probably a very basic Tcl screw up on my part, but I can't seem to figure it out and would sincerely appreciate any help you can offer!

CODE

while {$i >= $first && $i <= $last} {
        set fp [open "/data/1stn/$mut/pd5/1stn_$mut_$i.pd5" r]
        set file_data [read $fp]
        close $fp

        while {[gets $file_data line] >= -1 } {
        set data [split $file_data "\n"]
        foreach {one} $data {
                lappend trpshift [lindex $one 3]
        }
    }

    set prot [atomselect $mol_ID protein frame $j]
        $prot frame $j
        set user_list {}
        for {set a 0} {$a < 136} {incr a} {
                set u [lindex $trpshift $a]
                lappend user_list $u $u $u
        }
    $prot set user $user_list
        $prot delete

        set wat [atomselect $mol_ID waters frame $j]
        $wat frame $j
        set user_list {}
        for {set a 136} {$a < 10233} {incr a} {
                set u [lindex $trpshift $a]
                lappend user_list $u $u $u
        }
    $wat set user $user_list
        $wat delete

        set ions [atomselect $mol_ID ions frame $j]
        $ions frame $j
        set user_list {}
        for {set a 10233} {$a < 10244} {incr a} {
                set u [lindex $trpshift $a]
                lappend user_list $u $u $u
        }
    $ions set user $user_list
        $ions delete

        unset trpshift
        incr j 1
        incr i 2
}

RE: Difficulty resolving "can not find channel number" error in my code

(OP)
By the way, here are the first few lines of one of the sorts of files I need to read, so you can see the format I am dealing with. The column I want to store in the trpshift list is the 4th one, the pdif column.

#0  pdifc4: indx,amino,rave,pdif,runsum,segid,resid
    1   LYS    32.66     1.16985     1.16985  LYS      6
    2   LEU    26.73     0.03381     1.20365  LEU      7
    3   HIS    31.00    -0.00297     1.20069  HIS      8
    4   LYS    27.72     0.13354     1.33423  LYS      9
    5   GLU    31.13    -0.56292     0.77131  GLU     10
    6   PRO    32.50    -0.04138     0.72992  PRO     11
    7   ALA    29.89     0.03035     0.76028  ALA     12
    8   THR    31.89    -0.05019     0.71009  THR     13
    9   LEU    28.16    -0.01579     0.69430  LEU     14
   10   ILE    31.11     0.03815     0.73245  ILE     15
   11   LYS    28.13     0.34762     1.08007  LYS     16
 

RE: Difficulty resolving "can not find channel number" error in my code

I think you may have made this too complicated.

Quote:

while {$i >= $first && $i <= $last} {
        set fp [open "/data/1stn/$mut/pd5/1stn_$mut_$i.pd5" r]
        set file_data [read $fp]
        close $fp

        while {[gets $file_data line] >= -1 } {
        set data [split $file_data "\n"]
        foreach {one} $data {
                lappend trpshift [lindex $one 3]
        }
    }

The outer while loop seems to be determining which files you open.  Is that a) correct, and b) working right for you?  I suggest you make a list of lines in the erstwhile "read" step:

CODE

while {$i >= $first && $i <= $last} {
        set fp [open "/data/1stn/$mut/pd5/1stn_$mut_$i.pd5" r]
        set data [split [read $fp] \n]
        close $fp
 ...............
    }

Now if all you're interested in doing is to discard the first line of the file (now the first element of the list, data:

CODE

set data [lrange $data 1 end]
Now you seem to be doing something peculiar:

Quote:

while {[gets $file_data line] >= -1 }
In your original code, "file_data" is a string, having been returned from "[read...]" so that's the problem you're seeing: "gets" is trying to interpret the string, file_data, as an open channel number.  Anyway, my way you're already working with a list so without evaluating what you're doing inside the loop:

CODE

while {$i >= $first && $i <= $last} {
        set fp [open "/data/1stn/$mut/pd5/1stn_$mut_$i.pd5" r]
        set data [split [read $fp] \n]
        close $fp
        foreach line [lrange $data 1 end] {
                lappend trpshift [lindex $line 3]
        }
    }
 

_________________
Bob Rashkin

RE: Difficulty resolving "can not find channel number" error in my code

(OP)
Bob, thank you so much for your help, your method is so much simpler and more straightforward than what I was trying to do. My outer while loop *was* in fact working to read in the correct file data, but my clunky attempt to start creating the data list at the 2nd line wasn't working at all (as you could tell). I've only done a very small amount of Tcl programming (and not that much programming at all!) and I had completely forgotten about the extensive list modification methods in Tcl.

Thank you again very much for your help, your time and expertise are sincerely appreciated!

Best,
Nathan



 

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close