Add a geometry selection supporting selecting an zone shaped like a box
Is your feature request related to a problem?
I am now working on an system only z axis periodic, and I need to pick the atoms contained within certain distance in only z axis from a selected group. I tried to use cyzone to implement, but it could not include all atoms because of the shape of selection is a circle in xy plane and could not include all atoms in xy. And the prop selection could not read a dynamic updating selction.
Describe the solution you'd like
I would like to add a new geometry selection (named as box, for example), that could satisfy the requirement.
It would create a zone from center of geometry of given selection to x, y, or z direction in a box.
Describe alternatives you've considered
#4324
@Cloudac7 could you provide a few usage examples here? PR #4324 outlines the general syntax. I'd be interested to see how one might use it in practice, e.g., corresponding to the different cases in your nice illustrations.
E.g.
To select all atoms in a box with length LX, LY, LZ, centered on center of mass of residue 42:
u.select_atoms("box LX LY LZ (resid 42)"
(That's probably not the correct syntax but you get the idea: description of what you are accomplishing and how a user would use your code.)
@Cloudac7 could you provide a few usage examples here? PR #4324 outlines the general syntax. I'd be interested to see how one might use it in practice, e.g., corresponding to the different cases in your nice illustrations.
E.g.
To select all atoms in a box with length LX, LY, LZ, centered on center of mass of residue 42:
u.select_atoms("box LX LY LZ (resid 42)"(That's probably not the correct syntax but you get the idea: description of what you are accomplishing and how a user would use your code.)
OK. Let me give it a try.
To select all atoms within a defined 3D box region relative to the center of geometry (COG) of a specified residue:
Use the select_atoms() method on a Universe object (u) with the following syntax:
u.select_atoms("box <axes> <max> <min> <selection>")
Where:
<axes>specifies which axes to apply the selection on:x,y,z, or any combination likexy,yz, etc.<max>and<min>define the maximum and minimum bounds respectively along each specified axis. Positive values are above/right/front of the COG, negatives are below/left/behind. Should present at the same number of time as the number of axes set.<selection>specifies the selection theboxselection relative to.
For example:
To select all atoms between Zmax above and Zmin below the COG of residue 42 along z:
u.select_atoms("box z Zmax Zmin (resid 42)")
To select an 2D box around residue 114 from Xmin to Xmax on x and Ymin to Ymax on y:
u.select_atoms("box xy Xmax Xmin Ymax Ymin (resid 114)")
To select a 3D box around residue 514:
u.select_atoms("box xyz Xmax Xmin Ymax Ymin Zmax Zmin (resid 514)")
The selection syntax looks reasonable and fits the pattern established with cyzone:
cyzone externalRadius zMax zMin selection
selects all atoms within a cylindric zone centered in the center of geometry (COG) of a given selection, e.g. cyzone 15 4 -8 protein and resid 42 selects the center of geometry of protein and resid 42, and creates a cylinder of external radius 15 centered on the COG. In z, the cylinder extends from 4 above the COG to 8 below. Positive values for zMin, or negative ones for zMax, are allowed.
I just want to confirm that in your case, Xmax and Xmin are also relative to the center, right?
The selection syntax looks reasonable and fits the pattern established with cyzone:
cyzone externalRadius zMax zMin selection selects all atoms within a cylindric zone centered in the center of geometry (COG) of a given selection, e.g. cyzone 15 4 -8 protein and resid 42 selects the center of geometry of protein and resid 42, and creates a cylinder of external radius 15 centered on the COG. In z, the cylinder extends from 4 above the COG to 8 below. Positive values for zMin, or negative ones for zMax, are allowed.
I just want to confirm that in your case,
XmaxandXminare also relative to the center, right?
Yes, exactly.
This set of selections would have come in handy for something I had to do: cut out a system from a bigger system https://fhi-aims-club.gitlab.io/tutorials/fhi-aims-mdanalysis/2-periodic-sub-system/
I have encountered the same problem discussed in the original post. I work on MD simulations of electrochemical materials, and I needed to update the boundaries and atoms of an electrolyte region delimited between two electrodes. While it is possible to create the region on a single frame using the "prop" keyword of select_atoms(), the boundaries for this keyword must be hard-coded - i.e. the must be a string, and cannot be passed as variables nor linked to atomic properties. Eventually, I could bypass this problem by passing the appropriate coordinates to a a string, and creating a new region at each timestep within the main trajectory loop, but that obviously slowed down the calculation and the code writing process, so I would support the creation of a "box" geometry selection which can be dynamically updated.