From: Teletchéa Stéphane (steletch_at_biomedicale.univ-paris5.fr)
Date: Thu Nov 20 2003 - 02:54:12 CST

Le mer 19/11/2003 à 18:21, Justin Gullingsrud a écrit :
> Hi Stef,
>
> I haven't tested this but it sounds like it could be generally useful.
> Rather than immediately replacing what we have, since we're so close
> to releasing VMD 1.8.2, I would suggest placing it in the VMD script
> library, so that people who want to use this custom version can just
> download the script and source it (this was the reason for making the
> graphing behavior scriptable in the first place).

OK. I think also it should need a more extensive test procedure before
being included - if it has ever a chance of being ...-

> By the way, you can chop that final "-" with the command
>
> set input [string trimright $input "- "]
>
> Hope I didn't spoil your fun. ;)

No, it is really cool like this now. I wasn't aware of this function in
tcl scripts so it is good to have your help.

> Cheers,
> Justin

Cheers,
Stef

BTW, i'm just putting the modified version inline if someone is
interested/ or want to put in into the vmd script library. Do i have the
right to put it on my web site ?

############################################################################
#cr
#cr (C) Copyright 1995-2003 The Board of Trustees of
the
#cr University of
Illinois
#cr All Rights
Reserved
#cr
############################################################################

# Callback for plotting values of labels. Triggered by the "graph"
button
# on the Labels menu.

# This callback sends data to xmgr, one dataset at a time. If xmgrace
is
# not found, it reverts to the save dialog.
proc vmd_labelcb_xmgr { args } {
  global vmd_graph_label
  foreach item $vmd_graph_label {
    foreach { type id } $item { break }
    set data [label graph $type $id]
    set info [label list $type]

    switch [lindex $item 0] {
        "Bonds" {
            set fin 2
            }
        "Angles" {
            set fin 3
            }
        "Dihedrals" {
            set fin 4
            }
    }

    set input "@type xy\n@ title \""
    
    for {set deb 0} { $deb < $fin } {incr deb 1} {
    
    set atom [lindex [lindex [lindex $info 0] $deb] 1]
    set sel [atomselect top "index $atom"]
    set atomname [$sel get name]
    set resid [$sel get resid]
    set resname [$sel get resname]
    append input "$resname $resid:$atomname - "
    }
    
    set input [string trimright $input "- "]
    append input "\"\n"

    set i 0
    foreach elem $data {
      append input " $i $elem\n"
      incr i
    }
    set rc [catch {exec xmgrace -pipe << $input &} msg]
    if { $rc } {
      vmd_labelcb_save
    }
  }
}

# This callback simply saves the data to a file of the user's choice
using
# the Tk dialog box if available, otherwise through the text interface.
proc vmd_labelcb_save { args } {
  global vmd_graph_label tk_version
  foreach item $vmd_graph_label {
    foreach { type id } $item { break }
    set data [label graph $type $id]
    set title "Enter filename to save label data for $item"
    if [info exists tk_version] {
      set fname [tk_getSaveFile -title $title]
    } else {
      puts $title
      gets stdin fname
    }
    if { [string length $fname] } {
      set fd [open $fname w]
      foreach elem $data { puts $fd $elem }
      close $fd
    }
  }
}

# Choose a callback based on the platform: xmgr for unix, save for
everyone
# else (for now). Exception: if a command named vmd_labelcb_user is
defined,
# use that one instead of the default.
proc vmd_labelcb { args } {
  global tcl_platform
  if { [llength [info commands vmd_labelcb_user]] } {
    vmd_labelcb_user $args
  } else {
    switch $tcl_platform(platform) {
      unix {
        # Set the display variable to :0.0, unless it's already been set
        global env
        if { ![info exists env(DISPLAY)] } {
          puts "Setting DISPLAY environment variable to :0.0."
          set env(DISPLAY) :0.0
        }
        vmd_labelcb_xmgr $args
      }
      default {
        vmd_labelcb_save $args
      }
    }
  }
}

trace variable vmd_graph_label w vmd_labelcb

> On Wed, Nov 19, 2003 at 06:01:41PM +0100, Teletchéa Stéphane wrote:
> > Le mar 18/11/2003 à 18:26, Justin Gullingsrud a écrit :
> > > Hi,
> > >
> > > > Thanks, i've looked at it, and i think it could be trivial or not.
> > > > The title is written via the $item command, line 19 of the script:
> > > >
> > > > set input "@type xy\n@ title \"$item\"\n"
> > > >
> > > > And i suspect that $item contains an internal vmd variable designing the
> > > > bond, angle, ... like bond0, bond1, ...
> > >
> > > You could do something like the following:
> > >
> > > set info [lindex [label list $type] $item]
> > >
> >
> > Thank you very much for your guidelines. I've used them and now it
> > works. Here is the modified procedure in tcl (extract of the file
> > vmd/scripts/vmd/graphlabels.tcl) :
> >
> > proc vmd_labelcb_xmgr { args } {
> > global vmd_graph_label
> > foreach item $vmd_graph_label {
> > foreach { type id } $item { break }
> > set data [label graph $type $id]
> > set info [label list $type]
> >
> > switch [lindex $item 0] {
> > "Bonds" {
> > set fin 2
> > }
> > "Angles" {
> > set fin 3
> > }
> > "Dihedrals" {
> > set fin 4
> > }
> > }
> >
> > set input "@type xy\n@ title \""
> >
> > for {set deb 0} { $deb < $fin } {incr deb 1} {
> >
> > set atom [lindex [lindex [lindex $info 0] $deb] 1]
> > set sel [atomselect top "index $atom"]
> > set atomname [$sel get name]
> > set resid [$sel get resid]
> > set resname [$sel get resname]
> > append input "$resname $resid:$atomname - "
> > }
> >
> > append input "\"\n"
> >
> > set i 0
> > foreach elem $data {
> > append input " $i $elem\n"
> > incr i
> > }
> > set rc [catch {exec xmgrace -pipe << $input &} msg]
> > if { $rc } {
> > vmd_labelcb_save
> > }
> > }
> > }
> >
> > The only problem is that it produces lines like this :
> >
> > GUA 15:C5 - CYT 16:C4 - <-- note there is an extra '-'
> >
> > It would be better to not have this extra '-'. but since the most
> > important thing for me was to have atom names instead of
> > Bond/Angle/Dihedral, i think it is quite ok. May be i'll find a clever
> > way to do it tomorrow.
> >
> > Could this improvement be considered to be included in 1.8.2 ?
> >
> > I have not tested it with a protein, but as i used vmd own's variables,
> > i think it should be straightforward.
> >
> > Some comments about the code :
> >
> > Variables fin and deb are (in French, like this i'm sure they won't
> > interfere with the code ;-)) for :
> >
> > fin : end
> > deb : début (beginning)
> >
> >
> >
> > Thanks for your comments,
> > Stef
> >
> > --
> > 17:55:27 up 36 days, 4:30, 9 users, load average: 0.00, 0.01, 0.00
> > http://www.steletch.org
> > Linux 2.4.21-0.25mdk #1 Thu Jul 24 13:10:52 MDT 2003

--
09:45:34 up 36 days, 20:20, 9 users, load average: 0.00, 0.01, 0.00
http://www.steletch.org
Linux 2.4.21-0.25mdk #1 Thu Jul 24 13:10:52 MDT 2003