From: Josh Vermaas (vermaas2_at_illinois.edu)
Date: Fri Mar 27 2015 - 08:49:36 CDT

You have an atomselection inside the inner loop. That's gonna be a huge
penalty in performance (atomselects are fast, but they aren't THAT
fast), and there isn't a "$sel delete" statement, so you will run
yourself out of memory as old atomselections are still stored. Here is
how I would do it:

set sel [atomselect top "whatever the selection needs to be" frame 0]
set ixyz [$sel get {x y z}]
for {set f 0} { $f < [molinfo top get numframes] } { incr f } {
     $sel frame $f
     set nxyz [$sel get {x y z}]
     set msd 0.0
     for {set i 0} { $i < [llength $nxyz]} { incr i } {
         set tmp [veclength2 [vecsub $nxyz $ixyz]]
         set msd [expr $msd +$tmp]
     }
     #Put your saving stuff here
}

Notice I'm only updating a single atomselection, which should save you a
bunch of time.

-Josh Vermaas

On 3/27/15 6:33 AM, Bharat Sharma wrote:
> Hello Everyone,
> I am trying to calculate MSD using following script. I just realize
> that it need a lot of memory to complete the calculation for
> reasonably good size of system. I think the most time consuming part
> is calculating MSD and putting in to an array.
>
> Here is my script. Can anyone help me to play my code to save some memory?
>
> Appreciate you suggestions.
>
> Thank you.
>
> Bharat
>
> Here is the scripts (I am only showing some parts of the blocks,
> please ignore some syntax errors coming from missing braces)
> ---------------------------------------------------------------------------------------------
> for {set k [expr $i]} {$k <[expr $i+$msdlength]} {incr k} {
> set msd 0.0
> foreach idx $idxlist {
>
> set sel [atomselect top "index $idx"]
> $sel frame $i
> set ref [measure center $sel]
> $sel frame [expr $k]
> set poslist [measure center $sel]
> set msd [expr $msd + [veclength2 [vecsub $ref $poslist]]]
> }
> # change
> set msdarray($i,$k) [expr $msd]
>
> }
>
>
>
> for {set l 0} {$l <$msdlength} {incr l} {
>
> for {set m 0} {$m <$msdlength} {incr m} {
> set search [lsearch $missing_i $m]
> if {$search == -1} {
> set sum($l) [expr $sum($l)+$msdarray($m,[expr $m+$l])]
> }
> }
> set t [expr $l * 0.0025* $step]
>
> # change
> puts $msdfile "$count00 $t [expr $sum($l)/$count00]"
> }
>
> -----------------------------------------------------------------------------------------------
>
>
>
>
>
>
>
>
>
>
>
>