From: Peter Freddolino (petefred_at_ks.uiuc.edu)
Date: Thu Apr 13 2006 - 12:04:25 CDT

At the very least, you ought to be deleting proteinsel after each run
through the loop so that you don't run your machine out of memory, so
your loop contents should be:

set proteinsel [atomselect $mol {protein and within 5 of index $atomid}]
$proteinsel writepdb "$atomid.pdb"
$proteinsel delete

Please also note the slightly different selection syntax (addition of an
"and" between protein and within). Let me know if this still doesn't fix
things.

Peter

Vlad Cojocaru wrote:

>Dear vmd users,
>
>I am trying to write some intermediate pdb files for different
>selections using the simple script below .. However, I noticed that each
>of the pdb file contains the same atoms (which correspond to the last
>selection from the foreach loop -- last atom id--)... So, there is
>something wrong with the way writepdb acts within a foreach loop.... Can
>somebody please give me a short hint how to get around this ?... There
>must be something easy ..its just that I am running out of time for a
>deadline ...I am using vmd-1.8.4b10
>
>set mol [mol new {file.pdb} type pdb]
>set pathsel [atomselect $mol {resname XXX}]
>
>foreach atomid [$pathsel get index] {
> set proteinsel [atomselect $mol {protein within 5 of index $atomid}]
> $proteinsel writepdb "$atomid.pdb"
>}
>
>Cheers
>vlad
>
>
>