From: Josh Vermaas (vermaasj_at_msu.edu)
Date: Mon Oct 03 2022 - 09:03:37 CDT

Hi Eduardo,

I think this is what you want:

/set outfile [open output.txt w]
set nf [molinfo top get numframes]
set tube [atomselect top "type 3  4"]
set waterwithin3 [atomselect top "type 1  2 and same residue as within 3
of type 3 4"]
for {set i 0} {$i<$nf} {incr i} {
      $///waterwithin3/ frame $i
      $///waterwithin3/ update
      puts $outfile "$i  [expr {[$waterwithin3 num]/3}]"
}
close $outfile /

The atomselection text is super powerful, and can combine this together.
The only thing I'm not sure on is if the "residue" selection will work
correctly. I know it will for CHARMM, but you might be working with
LAMMPS, and I'm not sure if VMD's atomselection logic will work in quite
the same way. However, assuming it does, the waterwithin3 selection will
pick all atoms with type 1 or 2 that belong to the same residue as an
atom within 3 of types 3 or 4. Since water has three atoms, the number
of molecules is divided by 3.

-Josh

On 10/1/22 7:52 AM, Eduardo Estevez wrote:
> Dear VMD users
>
> I am trying to calculate the number of water molecules that are 3 Å
> from a nanoparticle (metal oxide), however I get an error *(
> atomselect: cannot parse selection text: within 3 of atomselect0*) , I
> have the following Tk script:
>
> /set outfile [open output.txt w]
> set nf [molinfo top get numframes]
> set tube [atomselect top "type 3  4"]
> set water [atomselect top "type 1  2"]
> for {set i 0} {$i<$nf} {incr i} {
>      $tube frame $i
>      $water frame $i
>      $tube update
>      $water update
>      set a [atomselect top "within 3 of $tube" frame $i]
>      puts $outfile "$i  $water"
> }
> close $outfile /
>
>
> Sincerely
>
> Eduardo

-- 
Josh Vermaas
vermaasj_at_msu.edu
Assistant Professor, Plant Research Laboratory and Biochemistry and Molecular Biology
Michigan State University
vermaaslab.github.io