• ## Outreach

From: Josh Vermaas (vermaas2_at_illinois.edu)
Date: Sun Sep 07 2014 - 12:22:46 CDT

Hi Eric,

It looks very much like somewhere a sign got messed up. I'm not going to
dig into it too deeply, as I didn't have the time (and still don't) to
work out the exact math myself (which would be why I looked for
plausible wikipedia links). If you only need to make this selection
once, I'd prefer the approach of "lets translate the problem to the
x-axis, make the selection there, and rotate back", which I've included
below:

set p1 [list 0 1 2] ; #I'm calling this the origin of the cylinder
set p2 [list 3 4 5] ; #This is the second point to define the cylinder
set vec [vecsub \$p2 \$p1] ; #If you don't have a second point, this just
defines the direction.
set r 4 ; #The radius

set all [atomselect top "all"]
\$all moveby [vecscale -1 \$p1] ; #Move p1 to the origin
\$all move [transvecinv \$vec] ;#Move the vector to the x-axis
set sel [atomselect top "y*y + z*z < \$r*\$r"] ;#Compute what is NOW
within the radius of the x-axis
set ilist [\$sel get index]
\$all move [transvec \$vec] ;#Move the x-axis back to the vector
\$all moveby \$p1 ;#Move the origin back to p1.

The upside to this approach it is its *relative* simplicity, although if
probably make it cost prohibitive relative to the straightforward
approach you tried. I believe they should work out to be the same thing
(after all, transvec and transvecinv just use rotation matrices, which
is where the correct derivation should come from), but I can't be more
useful than that.

-Josh Vermaas

On 09/07/2014 05:32 AM, Eric Smoll wrote:
> Hi Josh,
>
> Thanks again for your help on the vmd message board.
>
> I rederived the "cylinder about an arbitrary axis" wiki page
> linked using the angle conventions here
> <https://en.wikipedia.org/wiki/Spherical_coordinate_system> and the
> rotation matrices here
> <https://en.wikipedia.org/wiki/Rotation_matrix#In_three_dimensions>. I
> am close but there must be some error in my thinking because my
> selection does not match my input. Any idea what I am doing wrong?
>
> My derivation is in cyl.pdf, a vmd tcl script based on this derivation
> is in cyl.tcl, and a tcl script-rendered image of my system is in
> cyl.png (blue line is desired cylinder axis, yellow atoms are the
> selection).
>
> Best,
> Eric
>
>
> On Sat, Sep 6, 2014 at 5:58 PM, Eric Smoll <ericsmoll_at_gmail.com
> <mailto:ericsmoll_at_gmail.com>> wrote:
>
> On Sat, Sep 6, 2014 at 10:53 AM, Josh Vermaas
> <vermaas2_at_illinois.edu <mailto:vermaas2_at_illinois.edu>> wrote:
>
> Hi Eric,
>
> ...
> What you really want to do is define your region as a cylinder
> from the
> get-go, and see which atoms fall within the cylinder. This is
> at the
>
>
> Yes, that will work perfectly.
>
> If you need a bit more guidance, I answered a
> similar question a while ago with some handy links:
> http://www.ks.uiuc.edu/Research/vmd/mailing_list/vmd-l/23783.html
>
> Thank you for the link Josh. I don't trust that wiki page you
> referenced. The angle conventions are not those in the linked
> "spherical coordinates" page, there is an error in the expression
> for phi, and a quick visualization of the cylinder from the
> derived expressions for A and B do not generate the expected
> surface. Are you aware of another derivation?
>
> -Josh Vermaas
>
> On 09/06/2014 03:39 AM, Ana Celia Vila Verde wrote:
> > Hi Eric,
> >
> > I would do it in two steps:
> >
> > First, rotate your VMD molecule so that the line coincides
> with one of
> > the axes. Use VMD's matrice routines.
> >
> > Then, assuming that your line now coincides with the z axis,
> you can
> > select all atoms of type AAA within a certain distance R of
> that line
> > at frame \$frm with:
> >
> > set sel [atomselect top "(x**2 + y**2< R**2) and type AAA"]
> > \$sel frame \$frm
> > \$sel update
> >
> > By the way, if type AAA is, for example, the water oxygen or
> some
> > other atom type that's very abundant in your trajectory, it
> is more
> > efficient to write
> > set sel [atomselect top "(x**2 + y**2< R**2) and type AAA"]
> > set sel [atomselect top "type AAA and (x**2 + y**2< R**2) "]
> >
> > I hope it helps.
> >
> > Ana
> >
> > On 06/09/14 08:40, Eric Smoll wrote:
> >> Hello VMD users,
> >>
> >> What is the best way to select all atoms a certain distance
> from a
> >> line defined between two points?
> >>
> >> Toying with selections using a symmetric representation of
> the line,
> >> I noticed that I cannot select atoms within a certain
> distance of a
> >> plane. Only inequalities seem to work (greater-than or
> less-than the
> >> plane). So, to achieve selection along a line, I have to
> resort to a
> >> cumbersome expression like
> >>
> >> (within X of EXP1 < 0) and
> >> (within X of EXP1 > 0) and
> >> (within X of EXP2 < 0) and
> >> (within X of EXP2 > 0)
> >>
> >> Is there a better way?
> >>
> >> Best,
> >> Eric
> >
>
>
>