Re: Extracting data

From: Axel Kohlmeyer (akohlmey_at_gmail.com)
Date: Wed Feb 04 2015 - 08:24:25 CST

please note that setting the current frame for the molecule does not
update the frame index for selections (at least that is what i
recall).
in any case, this can be done in a simpler fashion with just two
selections. this kind of loop construct is particularly useful, if the
selection strings are complex expressions that need to be updated, so
the number of costly selections updates is minimized.

that all being said, i am not convinced that the creation of the
selections is the time critical factor. since we don't know what is
done with the data in the loop body. that may be more performance
critical than the creation of selections.

axel.

p.s.: here is the (untested and from the top of my head) suggested
optimized script framework.

# please note that the script below assumes that these lists are sorted in
# numerical ascending order. otherwise first apply "lsort -integer -increasing"
set from {1 10 20 30}
set to {40 50 60 70}
set steps_start 101

set fromsel [atomselect top "index $from"]
set tosel [atomselect top "index $to"]

set num_steps [molinfo top get numframes]
# Step through each frame.
for {set i $steps_start} {$i < $num_steps} {incr i} {
   $fromsel frame $i
   $tosel frame $i

# adjust the get lines here to whatever is needed. x y z is used for
illustration
set fromdata [$fromsel get {x y z}]
set todata [$tosel get {x y z}]

for {set j 0} {$j < $fromsel num} {incr j} {
  set fromidx [lindex $from $j]
  set fromxyz [lindex $fromdata $j]

  for {set k 0} {$k < $tosel num} {incr k} {
    set toidx [lindex $to $k]
    set toxyz [lindex $todata $k]

   # now do something with the data
  }
}

$fromsel delete
$tosel delete

>
> foreach fromSel $fromSelList {
> foreach toSel $toSelList {
> # Do something with the selections $toSel and $fromSel.
> }
> }
> }

On Wed, Feb 4, 2015 at 8:56 AM, Jeff Comer <jeffcomer_at_gmail.com> wrote:
> Hi Stephan,
>
> You are making a new selection 16 times per frame. Since your
> selections don't change, I think it would be faster to make the
> selections outside of the loop. Something like:
>
> set from {1 10 20 30}
> set to {40 50 60 70}
> set steps_start 101
>
> # Make lists of selections.
> set fromSelList {}
> foreach ind $from {
> lappend fromSelList [atomselect top "index $ind"]
> }
> set toSelList {}
> foreach ind $to {
> lappend toSelList [atomselect top "index $ind"]
> }
>
> set num_steps [molinfo top get numframes]
> # Step through each frame.
> for {set i $steps_start} {$i < $num_steps} {incr i} {
> molinfo top set frame $i
>
> foreach fromSel $fromSelList {
> foreach toSel $toSelList {
> # Do something with the selections $toSel and $fromSel.
> }
> }
> }
>
> # Delete the selections
> foreach fromSel $fromSelList {
> $fromSel delete
> }
> foreach toSel $toSelList {
> $toSel delete
> }
>
>
> –––––––––––––––––––––––––––––––––––———————
> Jeffrey Comer, PhD
> Assistant Professor
> Institute of Computational Comparative Medicine
> Nanotechnology Innovation Center of Kansas State
> Kansas State University
> Office: P-213 Mosier Hall
> Phone: 785-532-6311
>
>
> On Wed, Feb 4, 2015 at 5:55 AM, Stephan Grein
> <grein_at_informatik.uni-frankfurt.de> wrote:
>> Dear NAMD users,
>>
>> i want to extract information from my DCD file as follows:
>>
>> set from {1 10 20 30}
>> set to {40 50 60 70}
>> set from_len [lindex $from]
>> set to_len [lindex $to]
>> set steps_start 101
>>
>> for {set i $steps_start} {$i < $num_steps} {incr i} {
>> for {set j 0} {$j < $from_len} {incr j} {
>> for {set k 0} {$k < $from_len} {incr k} {
>> set mysel1 [atomselect top "index [lindex $from $j]"]
>> set mysel2 [atomselect top "index [lindex $to $k]"]
>> # do something with the selection, then delete it
>> $mysel1 delete
>> $mysel2 delete
>> }
>> }
>> animate goto $i
>> }
>>
>> But for me, this is horribly slow.
>> Is there any obvious failure in my snippet?
>>
>> Would be glad, if someone could point it out.
>>
>> Best regards,
>> Stephan
>>
>

-- 
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.

This archive was generated by hypermail 2.1.6 : Thu Dec 31 2015 - 23:21:37 CST