Auwreath
Auwreath

Reputation: 1

Difference tcl script tkconsole to load gro file in VMD

My problem is simple: I'm trying to write a tcl script to use $grofile instead writing every time I need this file name. So, what I did in TkConsole was:

% set grofile "file.gro"

% mol load gro ${grofile}

and, indeed, I succeeded uploading the file. In the script I have the same lines, but still have this error:

wrong # args: should be "set varName ?newValue?"

can't read "grofile": no such variable

I tried to solve my problem with

% set grofile [./file.gro]

and I have this error,

invalid command name "./file.gro"

can't read "grofile": no such variable

I tried also with

% set grofile [file ./file.gro r]

and I got the first error, again.

I haven't found any simple way to avoid using the explicit name of the file I want to upload. It seems like you only can use the most trivial, but tedious way:

mol load file.gro
mol addfile file.xtc

and so on and so on...

Can you help me with a brief explanation about why in the TkConsole I can upload the file and use it as a variable while I can not in the tcl script? Also, if you have where is my mistake, I will appreciate it.

I apologize if it is basic, but I could not find any answer. Thanks.

I add the head of my script:

set grofile "sim.part0001_protein_lipid.gro"
set xtcfile "protein_lipid.xtc"
set intime  "0-5ms"
set system  "lower"
source view_change_render.tcl
source cg_bonds.tcl

mol load gro $grofile xtc ${system}_${intime}_${xtcfile}

It was solved, thanks for your help.

Upvotes: 0

Views: 746

Answers (1)

Donal Fellows
Donal Fellows

Reputation: 137607

You may think you've typed the same thing, but you haven't. I'm guessing that your real filename has spaces in it, and that you've not put double-quotes around it. That will confuse set as Tcl's general parser will end up giving set more arguments than it expects. (Tcl's general parser does not know that set only takes one or two arguments, by very long standing policy of the language.)

So you should really do:

set grofile "file.gro"

Don't leave the double quotes out if you have a complicated name.


Also, this won't work:

set grofile [./file.gro]

because [] is used to indicate running something as a command and using the result of that. While ./file.gro is actually a legal command name in Tcl, it's… highly unlikely.

And this won't work:

set grofile [file ./file.gro r]

Because the file command requires a subcommand as a first argument. The word you give is not one of the standard file subcommands, and none of them accept those arguments anyway, which look suitable for open (though that returns a channel handle suitable for use with commands like gets and read).


The TkConsole is actually pretty reasonable as quick-and-dirty terminal emulations go (given that it omits a lot of the complicated cases). The real problem is that you're not being consistently accurate about what you're really typing; that matters hugely in most programming languages, not just Tcl. You need to learn to be really exacting; cut-n-paste when creating a question helps a lot.

Upvotes: 0

Related Questions