Re: Script for MD in a loop?

From: nordgren_at_sas.upenn.edu
Date: Wed Jun 15 2005 - 09:13:44 CDT

Hi all,

Shahid -- I do believe you and I have been trying to do similar things
lately. After a fair amount of work, I got a Tcl script (running within
VMD) working, which has a simple loop that repeatedly forces a small,
systematic change in the coordinates, calls NAMD (to run brief
minimization), and repeats. Here is the core of my VMD script:

--------------------------------------------------------------------------
mol load psf $start_psf pdb $start_pdb
set outfile [open $out_name.out w]
set frame 0
set namd_firststep 0
# initial coords are left as-is in frame 0; begin minimizing in next frame
for {set L [expr $max - $del]} {$L >= $min} {set L [expr $L - $del]} {

   # add new frame to the trajectory, with coords copied from current frame
   animate dup frame $frame 0
   incr frame
   animate goto $frame

   # modify coords of new frame (do your own thing here...)

   # call NAMD (in my case, to run "$namd_minsteps" of minimization)
   flush $outfile
   animate write pdb $temp_pdb beg $frame end $frame waitfor all
   set namd_firststep [expr $namd_firststep + $namd_minsteps]
   exec env NAMD_psf=$start_psf \
            NAMD_pdb=$temp_pdb \
            NAMD_filebase=$out_name \
            NAMD_minsteps=$namd_minsteps \
            NAMD_firststep=$namd_firststep \
            namd2 +p4 $namd_configfile >@ $outfile
   flush $outfile

   # replace coords of current frame with new (minimized) coords
   animate delete beg $frame end $frame
   mol addfile $out_name.coor type pdb
}

# write the complete trajectory to disk
# (note that this will append to the file, if it exists already)
animate write dcd $out_name.dcd beg 0 end $frame waitfor all

# clean up
file delete $temp_pdb
file delete $out_name.vel $out_name.vel.BAK
file delete $out_name.coor $out_name.coor.BAK
file delete $out_name.xsc $out_name.xsc.BAK
--------------------------------------------------------------------------

If you aren't a VMD user, now might be a good time to start. :) Of course,
much of the above is just regular Tcl code, but the power of VMD is that it
lets you easily script arbitrary manipulations of the coordinates of certain
types or groups of atoms. Note also that my loop over the parameter "L" goes
from high to low values; you should modify that for your needs.

Your own NAMD script can, of course, do whatever you want -- "run 0" to just
measure the energy as-is, or perform some minimization and/or dynamics. And
you can pass whatever parameters you need from the calling script, by adding
them to the variable list of that "exec env" command. Then, at the start of
your NAMD config file, just put a few lines like these:
set NAMD_psf $env(NAMD_psf)
set NAMD_pdb $env(NAMD_pdb)
set NAMD_filebase $env(NAMD_filebase)
set NAMD_minsteps $env(NAMD_minsteps)
set NAMD_firststep $env(NAMD_firststep)
.. in order to import the parameter values.

In the end, this will produce a DCD "pseudo-trajectory" for you, containing a
series of coord frames, each of which is the end result of your NAMD job.

Hope this is helpful -- good luck,
- Erik

C. Erik Nordgren, Ph.D.
Department of Chemistry
University of Pennsylvania

Quoting Shahid Qamar <qamar13_at_hotmail.com>:
> Hello Folks,
> I have a polymer and want to stretch it for a certain length. I have to
> stretch the polymer for 6 A by applying a constant velocity but I want to
> do it in many steps rather in a single run.
> For example:
> First Run: An atom of the Polymer is moved by 0.1 A by applying a
> constant force/velocity and stops
> 2nd run: Ring moves from 0.1A to 0.2A and stope
> 3rd run: Ring moves from 0.2A to 0.3A
> and so on.
>
> I need a TCL script or config file to do it. If I have 20 run then I want
> to through 20 simulations on 20 different nodes.
> So I need two things
> A) How I can define that and SMD atom just moves 0.1A not more than this
> and simulation stops
> B) How I can displace one atom or COM by 0.1A to go from 0.1A to 0.2 A to
> run 2nd simulation
> and so on
>
> I am trying to find out the energy landscape by running this simulations.
>
> Any comment. help or idea in terms of files any script will be
> appreciated.
>
> Thanks
>
> Shahid
>
>

This archive was generated by hypermail 2.1.6 : Wed Feb 29 2012 - 15:39:33 CST