From: Giacomo Fiorin (
Date: Wed Apr 18 2018 - 09:57:57 CDT

Hi Sandip, the "open" command gives a file descriptor to an open file, so
that you can write to it with "puts" or related commands.

Instead, the "writepdb" command of the atom selection takes a file *name*:

*writeXXX filename*: write the selected atoms to a file of type XXX; e.g.,
pdb, dcd. *New in VMD 1.8*: writepdb requires a filename; omitting the
filename no longer returns the PDB data as a string. To get the PDB data as
a string, first write to a file, then enter the following commands: set fd
[open *filename* r]; set s [read $fd]; close $fd. The text will be
contained in the variable s.

The part about using the file descriptor is for getting the contents of the
PDB file as a string.

Perhaps that note can be removed from now on: VMD 1.8 is very old, and if
somebody wants the string content, they can definitely write those commands
on their own.


On Wed, Apr 18, 2018 at 10:29 AM, Sandip Mondal <>

> 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

Giacomo Fiorin
Associate Professor of Research, Temple University, Philadelphia, PA
Contractor, National Institutes of Health, Bethesda, MD