From: Josh Vermaas (
Date: Sun Dec 14 2014 - 14:35:14 CST

Hi Kshatresh,

You need an "and" in between the water and the within 3 of resname HEM.
The atomselection language just uses logical operations. The "water"
refers to a macro that selects water molecules, which needs to be
combined with a logical and with the selection of "within 3 of resname
HEM". You also have some other elements in your script that may cause
problems: a list operation when you try to write it out to the file that
probably won't do what you expect. Here is what I would use for your script:

set outfile [open waters.dat w];
set nf [molinfo top get numframes]
#I don't know if this matters to you, but I usually think its more
useful to count by molecule rather than #by atom. This selection will
only include water oxygen atoms that are in the same residue of
#something within 3 of resname HEM.
set sel [atomselect top "noh and water and same residue as within 3 of
resname HEM"]
for {set i 0 } {$i < $nf } { incr i } {
    $sel frame $i
     #The number of water molecules nearby will change, so the selection
needs to change with the frame
    $sel update
    puts $outfile "$i [$sel num]"
close $outfile

-Josh Vermaas

On 12/14/2014 10:02 AM, Kshatresh Dutta Dubey wrote:
> Hi,
> I want to analyze the number of water molecules/per frame within some
> cutoff distance of residue of my simulated trajectories. I dont have
> expertise of tcl scripting however I tried following scripts:
> set outfile [open waters.dat w];
> set nf [molinfo top get numframes]
> set frame0 [atomselect top "water within 3 of resname HEM" frame 0]
> set sel [atomselect top "water within 3 of resname HEM"]
> for {set i 1 } {$i < $nf } { incr i } {
> $sel frame $i
> puts $outfile "[[ $sel $frame0] num] "
> }
> close $outfile
> But every time it is stops with error: atomselection: improper method:
> atomselect28, that means something is not right in last 3rd line.
> I will be thankful if someone suggests me to figure out the issue.
> Regards
> Kshatresh