From: Arham Amouie (erham65t_at_REMOVE_yahoo.com)
Date: Sun Aug 07 2016 - 03:13:52 CDT

Thank you Dr. Kohlmeyer. Really helpful.
Arham

      From: Axel Kohlmeyer <akohlmey_at_gmail.com>
 To: Arham Amouie <erham65t_at_yahoo.com>
Cc: "vmd-l_at_ks.uiuc.edu" <vmd-l_at_ks.uiuc.edu>
 Sent: Saturday, August 6, 2016 11:19 PM
 Subject: Re: vmd-l: processing a large "molecule"
   
On Sat, Aug 6, 2016 at 2:12 PM, Arham Amouie <erham65t_at_remove_yahoo.com> wrote:
> Hi. I've written the following tcl script to change the beta value of all
> the atoms of a large "molecule", composed of about 500,000 atoms:
>
> set crystal [atomselect top "all"]
> set atomsNo [$crystal num]
> $crystal delete
> for {set i 0} {$i < $atomsNo} {incr i} {
>    set atom_i [atomselect top "index $i"]
>    set atomcolor [$atom_i get beta]
>    if {$atomcolor < 0.02} {
>        $atom_i set beta 0
>    } else {
>        $atom_i set beta 1.0
>    }
>    $atom_i delete
> }
>
> But it's extremely slow. How can I write a much faster script? Is it
> possible within VMD?

yes. in general, you would not create individual atom selections, but
extract, operate, and loop on lists instead and then assign the list
in one go outside the loop.

since your operation on the atoms itself is extremely simple, it can
be done with even less code, without a loop and just two atom
selections.

set sel [atomselect top "beta < 0.02"]
$sel set beta 0
$sel delete

set sel [atomselect top "beta > 0"]
$sel set beta 1.0
$sel delete

axel.

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