From: Jim Parker (jimparker96313_at_gmail.com)
Date: Fri Aug 23 2013 - 06:30:11 CDT

Ok, I found my error
In my original code I used a 1-based list rather than a 0-based list, which
gave the error on textformat for the last entry...

So I have a working script, and to make the list 1-based (use keyword
"serial" values) change %i -> %d in the label textformat command, i.e.
label textformat Atoms $i {%d}

I would like to raise Alex's original question "where can you find
documentation of the format string to use with the textformat command?"
Apparently, there is a single character that maps each keyword for use in
the textformat command. It would be nice to have that mapping / table.

Cheers,
--Jim Parker

On Fri, Aug 23, 2013 at 6:02 AM, Jim Parker <jimparker96313_at_gmail.com>wrote:

> An older thread
>
> http://www.ks.uiuc.edu/Research/vmd/mailing_list/vmd-l/21955.html
>
> suggested the following code to label all atoms with their index
>
> proc labelAtoms { molid seltext } {
> label delete Atoms $seltext
> set sel [atomselect $molid $seltext]
> set i 0
> set atomlist [$sel list]
> foreach {atom} $atomlist {
> set atomlabel [format "%d/%d" $molid $atom]
> label add Atoms $atomlabel
> label textformat Atoms $i {%i}
> incr i
> }
> $sel delete
> }
>
> It does not work as a script and throws the error
>
> label textformat failed
>
> The "interesting" part is that label textformat Atoms $i {%i} does work
> when entered as a lone command from the TkConsole. It is also the output
> of generating a logfile and using the GUI to manipulate the label.
>
> Any suggestions on how to correct this script would be appreciated.
>
> Cheers,
>
> --Jim Parker
>
>
> W dniu 17.05.2013 12:22, Axel Kohlmeyer pisze:
> *> On Fri, May 17, 2013 at 11:17 AM, Paweł Kędzierski *
> *> <pawel.kedzierski_at_pwr.wroc.pl<pawel.kedzierski_at_pwr.wroc.pl?Subject=Re:%20%20Formatting%20labels%20in%20script>>
> wrote: *
> *>> Dear VMD users, *
> *>> It is possible to format atom labels using VMD GUI (Graphics->Labels,
> tab *
> *>> Properties), but I can't find in the user guide such functionality
> for the *
> *>> Tcl label command. *
> *>> I want to automate relatively simple tasks like labeling every atom
> with its *
> *>> index: *
> *>> *
> *>> set all [atomselect $molid "all"] *
> *>> foreach atom [$all list] { *
> *>> label add Atoms $molid/$atom *
> *>> } *
> *>> $all delete *
> *>> *
> *>> Can I set the label format to e.g "%i" in Tcl code or via GUI only? *
> *> you can always monitor Tcl commands that do the same thing as the GUI *
> *> by turning on logging. *
> Good idea indeed, thanks :)
> *> please try something like this (untested): *
> *> *
> *> set all [atomselect $molid "all"] *
> *> set i [llength [label list Atoms]] *
> *> foreach atom [$all list] { *
> *> label add Atoms "$molid/$atom" *
> *> label textformat Atoms $i {%i} *
> *> incr i *
> *> } *
> *> $all delete *
> Thanks for the code. I have checked that a single atom can only have one
> label so the indexes will start at 0 and they can't grow beyond the
> number of atoms.
> The code (possibly useful for someone else) would be then:
>
> label delete Atoms all
> set all [atomselect $molid "all"]
> set i 0
> foreach atom [$all list] {
> label add Atoms "$molid/$atom"
> label textformat Atoms $i {%i}
> incr i
> }
> $all delete
>
> The initial deletion of all Atoms labels is there because relabeling of
> an atom actually hides its label.
> Thank you,
> Pawel
> *> *
> *>> Thanks, *
> *>> Pawel *
> *>> *
> *> *
> *> *
> *> -- *
> *> Dr. Axel Kohlmeyer akohlmey_at_gmail.com<akohlmey_at_gmail.com?Subject=Re:%20%20Formatting%20labels%20in%20script>
> http://goo.gl/1wk0 *
> *> International Centre for Theoretical Physics, Trieste. Italy. *
>