From: Ajasja Ljubetič (ajasja.ljubetic_at_gmail.com)
Date: Tue Dec 20 2016 - 08:50:20 CST

Hi

Below is a skeleton script to get you started.
drawcallback is called every time the frame of the molecule changes.

proc enabletrace {} {
  global vmd_frame;
  trace variable vmd_frame([molinfo top]) w drawcallback
}

proc disabletrace {} {
  global vmd_frame;
  trace vdelete vmd_frame([molinfo top]) w drawcallback
}

proc drawcallback { name element op } {
  global vmd_frame;

  set i $vmd_frame([molinfo top])

  draw delete all
  # puts "callback!"
  #### Insert your arrow drawing code (for one frame) here
}

#load the molecule than call

enabletrace {}

On 20 December 2016 at 14:25, Amit Gupta <amit__at_outlook.in> wrote:

> Hi, Thank you for time and patience. No it did not work. I gave draw
> delete all and it deleted all arrows except from the last frame.
>
> "all this in a loop and deleting in the same iteration - it might get
> drawn and deleted too fast " - yes that is what is happening. I want each
> frame to retain arrows drawn by itself only. basically arrows should move
> when molecules move. Is it possible? I know conceptually similar things
> have been done with text like here: http://www.ks.uiuc.edu/
> Research/vmd/mailing_list/vmd-l/20596.html
>
>
> but i do not fully understand it.
>
> I also tried 'display update on' as one of the example does it on vmd and
> it says on website "update: Force a display update. Used if the display
> update is off or to force a redraw."
>
> but of no help.
>
>
> at present my script looks like this:
>
>
> draw delete all
> draw color yellow
> proc vmd_draw_arrow {mol start end} {
> # an arrow is made of a cylinder and a cone
> set middle [vecadd $start [vecscale 0.75 [vecsub $end $start]]]
> graphics $mol cylinder $start $middle radius 0.1
> graphics $mol cone $middle $end radius 0.3
> }
>
> set n [molinfo top get numframes]
> set sel [atomselect top {all}]
> set n_list [atomselect top "type 6"]
> set all_n_atoms [$n_list get index]
> $n_list delete
> for {set i 0} {$i < $n} {incr i} {
> #display update on
> #draw delete all
> #draw color yellow
> #$sel frame $i
> foreach n_atom $all_n_atoms {
> #get index of atoms from whihc vectors are to be drawn
> set current_c_atom_index [expr $n_atom - 1]
> set current_c_atom_index1 [expr $n_atom + 1]
> set current_c_atom_index2 [expr $n_atom + 2]
> set current_c_atom_index3 [expr $n_atom + 3]
>
> #get coords of all atoms
> set start_temp [atomselect top "index $current_c_atom_index" frame
> $i]
> set start [lindex [$start_temp get {x y z}] 0]
>
> set c1_temp [atomselect top "index $current_c_atom_index1" frame
> $i]
> set c1 [lindex [$c1_temp get {x y z}] 0]
>
> set c2_temp [atomselect top "index $current_c_atom_index2" frame
> $i]
> set c2 [lindex [$c2_temp get {x y z}] 0]
>
> set c3_temp [atomselect top "index $current_c_atom_index3" frame
> $i]
> set c3 [lindex [$c3_temp get {x y z}] 0]
>
> #avergae opsition of c1 c2 and c3
> set temp [vecadd $c1 $c2 $c3]
> set end [list [expr [lindex $temp 0]/3] [expr [lindex $temp 1]/3]
> [expr [lindex $temp 2]/3]]
>
> draw arrow $start $end
>
> #free memory, else it crashes
> $start_temp delete
> $c1_temp delete
> $c2_temp delete
> $c3_temp delete
> }
> }
>
>
>
>
> ------------------------------
> *From:* Ashar Malik <asharjm_at_gmail.com>
> *Sent:* Tuesday, December 20, 2016 6:11 PM
>
> *To:* Amit Gupta
> *Cc:* vmd-l_at_ks.uiuc.edu
> *Subject:* Re: Fw: vmd-l: Draw arrows in trajectory file
>
> since you are drawing a new thing every frame and don't need to see the
> previous thing in the current selection - you should use
>
> draw delete all
>
> I think this should delete everything drawn and redraw at the new
> positions you pass it - which I am guessing is coming from the loop.
> (If you are drawing all this in a loop and deleting in the same iteration
> - it might get drawn and deleted too fast -- ??? Not sure if that is what
> you want ?? )
> Hope this helps. Otherwise write back.
>
>
> On Wed, Dec 21, 2016 at 1:28 AM, Amit Gupta <amit__at_outlook.in> wrote:
>
>> Hi,
>>
>> Yes I realized it and added it later on. Now I can see all the arrows,
>> but together! I mean they are not changing with frame, rather all arrows
>> from all frames are visible all the time
>> ------------------------------
>> *From:* Ashar Malik <asharjm_at_gmail.com>
>> *Sent:* Tuesday, December 20, 2016 5:49:33 PM
>> *To:* Amit Gupta
>> *Cc:* vmd-l_at_ks.uiuc.edu
>> *Subject:* Re: Fw: vmd-l: Draw arrows in trajectory file
>>
>> Hi,
>>
>> I think this maybe because you are not updating your selections properly--001a11464df6cc775805441827d2--