Re: Vectors and indexing in VMD

From: Chang Sun (sun.changing_at_gmail.com)
Date: Tue Jan 23 2018 - 10:35:35 CST

Hi Chun Heung Wong,

The issues you mentioned have nothing to do with VMD or NAMD. They are due
to the syntax of Tcl language.

In Tcl, if you put variables in a curly bracket, they are treated as
strings rather than variables. A solution to your first problem is
set move_vec [list $a $b $c]
then puts $move_vec gives the result you want
BTW, the command "list $a $b $c" within the bracket will execute first and
output {0 1 2}, which is further used by the set command

In Tcl, the supported way to slice a list is to use the "lindex" command. A
solution to your second problem is
lindex $vec 0

You can find more information here:
http://www.cse.scitech.ac.uk/ccg/software/chemshell/manual/tclbasics.html

Cheers,
Chang

On Tue, Jan 23, 2018 at 6:16 AM, Chun Heung Wong <w.chunheung_at_gmail.com>
wrote:

> Dear all,
>
> I am trying to make my first MD simulation in NAMD, by adapting the
> Nanopore-tutorial files on the website. To accurately set up my problem, I
> need to shift some atoms around along a specific vector. The vector
> components were calculated in previous code, lets say (a, b, c).
>
> I have 2 difficulties:
> # Example vector components
> set a 0
> set b 1
> set c 2
>
> #Creating vector from previous variables
> set mov_vec {$a, $b, $c}
> puts $mov_vec
>
> it returns: $a, $b, $c
> instead of 0, 1, 2
>
> Furthermore, for a given vector "set vec {0,1,2}", I cannot access vector
> components with e.g. vec(1), vec[1], vec{1} etc.
>
> I tried looking up the syntax, but I believe it is not documented. I fixed
> my specific problem by just hard-coding the right coordinates in, but is
> there any way to assign vectors using previously declared variables and to
> access vector components?
>
> Yours sincerely,
>
>
> Chun Heung Wong
>

This archive was generated by hypermail 2.1.6 : Sat Sep 14 2019 - 23:19:13 CDT