From: Florentina Tofoleanu (
Date: Wed Mar 10 2010 - 16:27:37 CST


I wrote a vmd script to count the HBs between a segment in a protein and the
water within a certain distance from the segment. I am using the "pbwithin"
command as my protein sticks out of the box. Even though there is a
difference between "within" and "pbwithin" in the number of water molecules
shown in Representations, there is none whatsoever in the output of HBs. I
believe the number should get higher, but it goes down as the segment sticks
out of the water more and more.

The script is as follows:

set mol1 [mol new file.pdb type pdb waitfor all]
set sel1 [atomselect $mol1 all]

set mol [mol new file.psf type psf waitfor all]
mol addfile file.dcd type dcd waitfor all molid $mol

$sel1 delete
mol delete $mol1

set outfile [open output.dat w];

set numframes [molinfo $mol get numframes]

set refA [atomselect $mol "protein and segname A"]
set refB [atomselect $mol "water pbwithin 5 of protein and segname A"]

for {set frame 0} {$frame < $numframes} {incr frame} {

$refA frame $frame
$refB frame $frame

$refA update
$refB update

set nhb [llength [lindex [measure hbonds 3.1 60 $refA $refB] 0]]

puts $outfile "$frame $nhb"


close $outfile

Is there an error in the script, or just the pbwithin command won't do?

I've seen in this post"(Pbwithin)
does not, however, modify the coordinates - they will still be
the coordinates of the atom in the primary image, so if you want to compute
distances, you need to take into account the periodic boundary conditions
manually. " Could Olaf, or anybody else, explain what taking into account
the pbc manually mean and how can I change my script?

Thank you,


On Sat, Sep 19, 2009 at 9:55 AM, Axel Kohlmeyer <> wrote:

> 2009/9/19 Thomas Evangelidis <>:
> > Hi Katherine,
> >
> > lets say you want to count all the waters(TIP3) within 5 A of resids 1-50
> > taking into account waters in the nearest periodic cells, then the
> command
> > should be:
> >
> > llength [[atomselect top "(oxygen pbwithin 5 of (protein and resid 1 to
> 50))
> > and resname TIP3"] list]
> folks,
> when giving code examples, please make sure that you give examples
> of _good_ coding. this piece of code has a high risk of creating a memory
> leak
> and is inefficient.
> the same can be done by:
> set sel [atomselect top "(oxygen pbwithin 5 of (protein and resid 1 to
> 50)) and resname TIP3"]
> puts "found [$sel num] water molecules"
> $sel delete
> and this code uses the "num" option to do the counting in c rather
> than creating a tcl
> list and counting its length and show that the functions created by
> atomselect have to
> be deleted after use (it is better to always manually delete them
> rather than counting
> on tcl to clean up).
> > I have an alpha version of a plugin to truncate trajectories and keep
> only a
> > specified number of waters within R Angstroms of an atomselection, it
> might
> > be helpful to your analysis.
> that reminds me. having you been able to sort out your issues with bigdcd?
> did the improved re-rentrant version of bigdcd work for you?
> thanks,
> axel.
> >
> > regards,
> > Tom
> >
> >
> >> Dear VMD users:
> >> My sytem contains 18 proteins in a unit cell. I also have several 20ns
> >> trajectories (*.dcd) of this system.
> >> I would like to calculate the distribution of the water molecules around
> >> each one of the proteins and around the different amoinoacids that
> compose
> >> them during the trajectories.
> >> I've been trying to find another VMD mail list posted message containing
> >> this question and somewhere in the VMD user's guide but I haven't found
> >> anything related.
> >> I've worked with some scripts in VMD, using the atomselect command and
> >> doing
> >> loops along trajectories.
> >> What I need is some help with the right command to count water molecules
> >> (TIP3) around a specific part of the protein.
> >> Thank you in advance.
> >> KP
> >>
> >
> >
> > ----- End message from -----
> >
> >
> >
> >
> --
> Dr. Axel Kohlmeyer
> Institute for Computational Molecular Science
> College of Science and Technology
> Temple University, Philadelphia PA, USA.

Florentina Tofoleanu
Postgraduate Research Fellow
Theoretical and Computational Biophysics Group
University College Dublin
School of Physics, Rm. 110
Belfield, Dublin 4, Ireland