0
votes

New programmer here. I have been trying to run my script through Tk console through a VMD program which works when I copy it into tkconsole, however when I source/load my script into tkconsole, it only runs part of the script before stopping and gives me two issues.

The issue I am having are:

  1. it loads up molecules but does not visually display it in the VMD window
  2. it runs most of my script, but gets stuck at the put $total section and feeds me back invalid command name "put"

I am unsure if I have missed a step when sourcing scripts, however when manually pasting in the whole script it seems to work. Wondering if anyone has input. Please see the script below:

mol new ubiquitin.psf
mol new pulling.dcd
set sel [atomselect top "index 942 963"]
set x [measure bond {59 60} frame all]
set total 0
for {set i 0} {$i <100 } {incr i} {
    puts "I inside first loop: $[measure bond {59 60} frame $i]"; set total [expr {$total + [measure bond {59 60} frame $i]}]
}
put $total
expr {$total/100} 
1
You have a typo: put should be puts (for “put string” originally, but cargo culted from another language).Donal Fellows
Documentation on builtin Tcl commands: tcl-lang.org/man/tcl8.6/TclCmd/contents.htmglenn jackman
Thanks for the page.Mai Pham

1 Answers

1
votes

As Donal commented, your script fails due to a typo: put instead of puts.

The reason it works when run manually is because of a procedure called unknown. This procedure is called whenever the interpreter encounters an unknown command. It then tries different things to handle the command:

  • It will load a library, if that is known to contain the command.
  • It executes an external executable file, if that exists.
  • It runs a command from the command history, if applicable.
  • If the name is a unique prefix of an existing Tcl command, it runs that command instead.

All except the first point are only attempted in interactive mode. So, in that situation the last option kicks in and runs puts when you type put. However, when running a script, that doesn't happen and you get the error you mentioned.