From: Peter Freddolino (
Date: Tue Jan 09 2007 - 09:49:21 CST

Hi Brian,
you can do this with a tcl array or list. Using a list is easier, in
which case the relevant lines would be
lappend Calist [atomselect top "resid [lindex $res_list 0 $i] and name CA"]
puts "[[lindex $Calist $i] get {x y z}]"

Using an array you can have arbitrary (instead of consecutive numerical

initialize it with
set Caarray [array set]

Then in the loop

array set Caarray {$i [atomselect top ...]}
puts "[$Caarray($i) get {x y z}]


Brian Kidd wrote:
> hello,
> i'm interested in specifying an input list of residue numbers. the
> number of residues (elements) in this list will vary and i'd like to
> create the a set of variables to store each element in the list.
> ultimately, i'd like to loop through the list of variables and set an
> atomtype based on the element in the list. how can i specify the
> variable to store each value as i'm looping through the list so that i
> can retrieve it later? below is a snippet of code for how this might
> work, but i don't know the correct syntax for line 8 or 9 where i set
> the variable and retrieve its contents respectively. thanks, brian
> proc read_inputlist {instring} {
> set res_list [list $instring]
> set res_num [llength ($res_list)]
> # store Calpha values for each residue in list
> for { set i 0 } { $i < $res_num } { incr i } {
> set Ca_{i} [atomselect top "resid [lindex $res_list 0 $i] and name CA"]
> puts "[$Ca_{i} get {x y z}]"
> }