From: Ashar Malik (
Date: Wed Apr 18 2018 - 09:53:53 CDT

Best programming practice is to always close what you open.

Second you don't necessarily have to provide "writepdb" a file handle. I
haven't used it this way and I am not sure if it can handle that!!??

What you can do is something like this

$atoms writepdb frame_$i.pdb

This should create a pdb-file with "frame_" and the value of the variable "
*i"* ...

Be sure to always delete any selections you make when you no longer need

On Thu, Apr 19, 2018 at 2:29 AM, Sandip Mondal <> wrote:

> Dear user,
> I am new in writing tcl script. I wrote a simple script for writing
> selected regions in pdb format from a dcd.
> The script is as follows
> set atoms [atomselect top "not water"]
> set nf [molinfo top get numframes]
> set out [open "file.pdb" w]
> for {set i 0} {$i < $nf} {incr i} {
> if {$i == 123} {
> $atoms frame $i
> $atoms writepdb $out
> }
> }
> Here 123th frame of a dcd is just for example. This script doesn't
> write anything in that $out file, however it creates a new file which I
> expect in $out file. Can you plz suggest the way.
> Thanking you,
> Sandip