Re: Extracting data

From: Jeff Comer (jeffcomer_at_gmail.com)
Date: Wed Feb 04 2015 - 07:56:42 CST

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
>

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