Skip to content

Commit

Permalink
Squashed commit of the following:
Browse files Browse the repository at this point in the history
commit 8d7f2ce
Author: Futaki Haduki <[email protected]>
Date:   Thu Nov 9 17:23:57 2023 +0800

    Update package/MDAnalysis/core/groups.py

    Co-authored-by: Rocco Meli <[email protected]>

commit cfdec5b
Author: Futaki Haduki <[email protected]>
Date:   Thu Nov 9 17:23:44 2023 +0800

    Update package/MDAnalysis/core/groups.py

    Co-authored-by: Rocco Meli <[email protected]>
  • Loading branch information
Cloudac7 committed Nov 10, 2023
1 parent 036eea5 commit 0090016
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 31 deletions.
9 changes: 4 additions & 5 deletions package/MDAnalysis/core/groups.py
Original file line number Diff line number Diff line change
Expand Up @@ -3111,14 +3111,13 @@ def select_atoms(self, sel, *othersel, periodic=True, rtol=1e-05,
radius 5, external radius 10 centered on the COG. In z, the
cylinder extends from 10 above the COG to 8 below. Positive
values for *zMin*, or negative ones for *zMax*, are allowed.
box *dimensions* *dN_min* *dN_max* *selection*
box *dimensions* *dN_min* *dN_max* [*dN_min* *dN_max*] [*dN_min* *dN_max*] *selection*
Select all atoms within a box region centered
on the center of geometry (COG) of a given selection.
*dimensions* Specifies which dimension(s) to apply
the box selection on. Can be ``x``, ``y``, ``z``,
or any combination like ``xy``, ``yz``, ``zx``, ``xyz``
(up to 3 characters). *dN_min*, *dN_max* are the minimum and
maximum bounds along the first specified dimension.
the box selection on. Can be ``x``, ``y``, ``z``, ``xy``,
``yz``, ``xz``, or ``xyz`. *dN_min*, *dN_max* are the minimum
and maximum bounds along each specified dimension.
Positive values are above/right/front of the COG,
negatives are below/left/behind, and should be specified
for each dimension. *selection* specifies the selection
Expand Down
39 changes: 16 additions & 23 deletions package/MDAnalysis/core/selection.py
Original file line number Diff line number Diff line change
Expand Up @@ -540,24 +540,8 @@ def _apply(self, group):
class BoxSelection(Selection):
token = "box"
precedence = 1
combination = [
"x",
"y",
"z",
"xy",
"xz",
"yz",
"yx",
"zx",
"zy",
"xyz",
"xzy",
"yxz",
"yzx",
"zxy",
"zyx",
]
axis_map = ["x", "y", "z"]
axis_set = {"x", "y", "z", "xy", "xz", "yz", "xyz"}

def __init__(self, parser, tokens):
super().__init__(parser, tokens)
Expand All @@ -566,22 +550,31 @@ def __init__(self, parser, tokens):
self.xmin, self.xmax = None, None
self.ymin, self.ymax = None, None
self.zmin, self.zmax = None, None
if self.direction not in self.combination:
raise ValueError(
"The direction '{}' is not valid. Must be combination of {}"
"".format(self.direction, ["x", "y", "z"])
)
else:

if self.direction in self.axis_set:
for d in self.direction:
if d == "x":
self.xmin = float(tokens.popleft())
self.xmax = float(tokens.popleft())
if self.xmin > self.xmax:
raise ValueError("xmin must be less than or equal to xmax")
elif d == "y":
self.ymin = float(tokens.popleft())
self.ymax = float(tokens.popleft())
if self.ymin > self.ymax:
raise ValueError("ymin must be less than or equal to ymax")
elif d == "z":
self.zmin = float(tokens.popleft())
self.zmax = float(tokens.popleft())
if self.zmin > self.zmax:
raise ValueError("zmin must be less than or equal to zmax")
else:
raise ValueError(
"The direction '{}' is not valid. "
"Must be one of {}"
"".format(self.direction, ", ".join(self.axis_set))
)

self.sel = parser.parse_expression(self.precedence)

@return_empty_on_apply
Expand Down
6 changes: 3 additions & 3 deletions package/doc/sphinx/source/documentation_pages/selections.rst
Original file line number Diff line number Diff line change
Expand Up @@ -280,9 +280,9 @@ cyzone *externalRadius* *zMax* *zMin* *selection*
box *dimensions* *dN_min* *dN_max* *selection*
Select all atoms within a box region centered on the center of
geometry (COG) of a given selection. *dimensions* Specifies
which dimension(s) to apply the box selection on. Can be ``x``,
``y``, ``z``, or any combination like ``xy``, ``yz``, ``zx``, ``xyz``
(up to 3 characters). *dN_min*, *dN_max* are the minimum and maximum
which dimension(s) to apply the box selection on.
Can be ``x``, ``y``, ``z``, ``xy``, ``yz``, ``xz``, or ``xyz`.
*dN_min*, *dN_max* are the minimum and maximum
bounds along the first specified dimension. Positive values are
above/right/front of the COG, negatives are below/left/behind.
Should be specified for each dimension. *selection* specifies the selection
Expand Down

0 comments on commit 0090016

Please sign in to comment.