Re: Fwd: help to improve the script to predict mean square displacement

From: Luca Muccioli (luca_at_ms.fci.unibo.it)
Date: Fri Mar 12 2010 - 17:08:31 CST

dear Jampani,

   I don't know how to improve the script, anyway tcl is probably not the
fastest possible way of doing it, I guess you should resort to a compiled
language such as C++, C or fortran if you want better performance.
On the other side, the calculation of MSD and of any time-dependent property is
known to be very time consuming, if you do it properly i.e. you consider all the
possible time origins (see Leach "Molecular Modelling - principles and
applications" chapter 7).
Some tricks for improving the speed could be:
- using not all configurations but one every N (the value of N depends of the
frequency of saving trajectories and on the molecules you simulate - water moves
fast but larger molecules no)
- to not perform a constant scan in time / delta configuration:
   instead of deltat= 1,2,3,4, ... , N-1, N
   you could use 1,2,3,5,8,13 ... N or any other scheme you find suitable
- typically the long time values of MSD are very noisy, because the number of
   possible time origins is low (only one for the last configuration). Then it's
   better limiting the calculations to the points for which you have let's say
   at least N_mols x N_confs > 100000

hope that this is helpful and nobody strongly disagrees ;)

cheers

Luca

-------------------------------------------

Luca Muccioli, Ph. D.
Dipartimento di Chimica Fisica e Inorganica, INSTM
Universita` di Bologna
Viale Risorgimento 4
40136 Bologna (Italia)

E-mail: luca_at_fci.unibo.it
Phone: +39-051-6446992
Fax: +39-051-2093690
Web: http://www2.fci.unibo.it/~luca/

On Fri, 12 Mar 2010, jampani srinivas wrote:

> Date: Fri, 12 Mar 2010 15:51:55 -0500
> From: jampani srinivas <jampanis_at_gmail.com>
> To: namd-l_at_ks.uiuc.edu
> Subject: namd-l: Fwd: help to improve the script to predict mean square
> displacement
>
> ---------- Forwarded message ----------
> From: jampani srinivas <jampanis_at_gmail.com>
> Date: Thu, Mar 11, 2010 at 8:18 PM
> Subject: help to improve the script to predict mean square displacement
> To: vmd-l_at_ks.uiuc.edu
>
>
> Dear VMD users,
>
> I have written a small script to predict the mean square displacement in
> Tcl. The script is working fine but it is taking huge computational time, it
> took around three hours to finish 200 frames with 6000 water molecules. Can
> anybody help me to improve the script in such way that it
> takes reasonably less time to calculate MSD.
>
> Here is my script
>
> proc MSD {{file ""} {mol top}} {
> # open file if given
> set file_given 0
> if {$file != ""} \
> {
> set fileId [open $file w]
> set file_given 1
> }
> set num_steps [molinfo top get numframes]
> #set frozen [[atomselect top "beta 1.0" frame 0] get index]
> set mobile1 [atomselect top "beta 0"]
> set mobile2 [atomselect top "beta 0"]
> for {set i 0} {$i < $num_steps} {incr i } {
> $mobile1 frame $i
> set coord1 [$mobile1 get {x y z}]
> set list2 []
> for {set j [expr $i+1]} {$j < $num_steps} {incr j}
> {
> set z 0
> $mobile2 frame $j
> set coord2 [$mobile2 get {x y z}]
> for {set l 0} {$l <= [$mobile1 num]} {incr l}
> {
> set dist1 [vecdist [lindex $coord1 $l]
> [lindex $coord2 $l]]
> set dist2 [expr $dist1*$dist1]
> set z [expr $dist2 + $z]
> }
> set conv [expr $z/[$mobile1 num]]
> lappend list2 "$conv"
> }
> for {set k 0} {$k < $i} {incr k} {
> lappend list2 [expr 1.0-1.0]
> }
> set final $list2
> if {$k == 0} {
> set avrfinal $final
> } else {
> set avrfinal [vecadd $avrfinal $final]
> }
> }
> # print to file
> if {$file_given == 1} \
> {
> for {set m 0} {$m < [llength $avrfinal]}
> {incr m} {
> set last [expr [expr 1.0/[expr [llength
> $avrfinal] - $m]]*[lindex $avrfinal $m]]
> puts $fileId "$last"
> }
> }
> #close file
> if {$file_given == 1} \
> {
> close $fileId
> }
> }
>
> Thanks in advance
> Srinivas.
>
>

This archive was generated by hypermail 2.1.6 : Wed Feb 29 2012 - 15:55:34 CST