From: Axel Kohlmeyer (akohlmey_at_gmail.com)
Date: Tue Dec 20 2016 - 08:27:51 CST

a long, long time ago, i put together a tutorial for some advanced
scripting with VMD, including some examples for how to dynamically
adapt visualizations during animation from external and on-the-fly
computed data. while none of that will directly resolve this, all the
necessary components are there. the original website has since been
taken down, but a PDF of it still exists at:
https://sites.google.com/site/akohlmey/redirect/cpmd-vmd.pdf?attredirects=0&d=1
the interesting stuff for this case starts at section 5.

axel.

On Tue, Dec 20, 2016 at 8:35 AM, Ashar Malik <asharjm_at_gmail.com> wrote:
> If you are interested in seeing the drawn components change with each frame
> you need to slow down the loop. To do that you need to use the tcl command
>
> after 1000
>
> This will slow down the loop.
>
> You also need to do
>
> display update
>
> in each loop iteration so that while the loop stops for the interval
> specified with "after" the display is updates so you can "visualize" the
> drawn component.
>
> Hope this helps.
>
> Best,
> /A
>
>
> On Dec 21, 2016 02:29, "Ajasja Ljubetič" <ajasja.ljubetic_at_gmail.com> wrote:
>>
>> Hi Amit,
>>
>> I guess, you would like to redraw he arrows after the frame changes.
>> You can do this using TCL callbacks
>> http://www.ks.uiuc.edu/Research/vmd/current/ug/node159.html
>>
>> In particular see vmd_frame(molid).
>>
>> An example that draws the size of the unit cell for each frame is here
>>
>> http://www.ks.uiuc.edu/Research/vmd/script_library/scripts/pbcbox/pbcbox.tcl
>>
>> Best,
>> Ajasja
>>
>>
>> On 20 December 2016 at 13:41, Ashar Malik <asharjm_at_gmail.com> wrote:
>>>
>>> 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. to see the arrow move - I guess your selections for arrows need to
>>>> be updated on a frame by frame basis.
>>>> Try either "$sel update" after "$sel frame $i"
>>>>
>>>> or drop the use of $sel update and use make selections like ...
>>>>
>>>> set end [lindex [[atomselect top "index $n_atom" frame $i] get {x y z}]
>>>> 0]
>>>>
>>>> notice "frame $i" in the command you used. This will force a selection
>>>> in the frame controlled by the loop.
>>>> I think this should fix it. Otherwise - write back.
>>>>
>>>> Best,
>>>> /A
>>>>
>>>> On Tue, Dec 20, 2016 at 10:45 PM, Amit Gupta <amit__at_outlook.in> wrote:
>>>>>
>>>>>
>>>>> Sorry I sent the message below to the person who replied rather than to
>>>>> mailing list:
>>>>>
>>>>>
>>>>> Thank you for the reply. I modified the script as written at the bottom
>>>>> of mail and it worked fine (did not crash). However now i notice that arrows
>>>>> are drawn only once, in the first frame. After which I do not see any
>>>>> movement in the arrows. Is there any way to draw arrows per frame?
>>>>>
>>>>>
>>>>>
>>>>> Modified lines that worked:
>>>>>
>>>>> set end_temp [atomselect top "index $n_atom"]
>>>>> set end [lindex [ $end_temp get {x y z}] 0]
>>>>>
>>>>> set start_temp [atomselect top "index $current_c_atom_index"]
>>>>> set start [lindex [$start_temp get {x y z}] 0]
>>>>>
>>>>> $end_temp delete
>>>>> $start_temp delete
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> From: Norman Geist <norman.geist_at_uni-greifswald.de>
>>>>> Sent: Tuesday, December 20, 2016 2:07:25 PM
>>>>> To: 'Amit Gupta'
>>>>> Subject: AW: vmd-l: Draw arrows in trajectory file
>>>>>
>>>>>
>>>>> You produced a common memory leak with many atomselects which you never
>>>>> clear.
>>>>> After you no more need an atomselect object, you should call “delete”
>>>>> on it to free memory.
>>>>>
>>>>> Eg.:
>>>>>
>>>>> set a [atomselect top all]
>>>>> set list [$a get index]
>>>>> $a delete; #<-------
>>>>>
>>>>> So whats happening is that vmd gets killed for eating up all the
>>>>> memory.
>>>>>
>>>>> Best of luck
>>>>>
>>>>> Norman Geist
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> Von: owner-vmd-l_at_ks.uiuc.edu [mailto:owner-vmd-l_at_ks.uiuc.edu] Im
>>>>> Auftrag von Amit Gupta
>>>>> Gesendet: Dienstag, 20. Dezember 2016 07:31
>>>>> An: vmd-l_at_ks.uiuc.edu
>>>>> Betreff: vmd-l: Draw arrows in trajectory file
>>>>>
>>>>>
>>>>> I want to draw come arrows in a lammps trajectory file, indicating
>>>>> movement of certain vectors.
>>>>> I have written script below, it works fine for single frame, but for
>>>>> more than one frame, VMD crashes without any message (even in console). Can
>>>>> anyone suggest a reason?
>>>>>
>>>>>
>>>>> draw color yellow
>>>>>
>>>>> ##-----------Draw arrow subroutine from VMD website----------
>>>>>
>>>>>
>>>>>
>>>>> 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"] #get indexes of all nitrogens in
>>>>> molecules
>>>>>
>>>>> set all_n_atoms [$n_list get index]
>>>>>
>>>>>
>>>>>
>>>>> for {set i 0} {$i < $n} {incr i} {
>>>>>
>>>>> $sel frame $i
>>>>>
>>>>> foreach n_atom $all_n_atoms {
>>>>>
>>>>> set current_c_atom_index [expr $n_atom - 1] # get index of C
>>>>> attached to N
>>>>>
>>>>> set end [lindex [[atomselect top "index $n_atom"] get {x y z}]
>>>>> 0]
>>>>>
>>>>> set start [lindex [[atomselect top "index
>>>>> $current_c_atom_index"] get {x y z}] 0]
>>>>>
>>>>> draw arrow $start $end
>>>>>
>>>>> }
>>>>>
>>>>> }
>>>>>
>>>>>
>>>>> Sorry if certain logic seems slightly convoluted, still getting used to
>>>>> TCL!
>>>>>
>>>>>
>>>>
>>>>
>>>>
>>>> --
>>>> Best,
>>>> /A
>>>
>>>
>>>
>>>
>>> --
>>> Best,
>>> /A
>>
>>
>

-- 
Dr. Axel Kohlmeyer  akohlmey_at_gmail.com  http://goo.gl/1wk0
College of Science & Technology, Temple University, Philadelphia PA, USA
International Centre for Theoretical Physics, Trieste. Italy.