Skip to content

Commit

Permalink
Merge pull request #514 from MDAnalysis/issue-362
Browse files Browse the repository at this point in the history
updates/fixes for selections (related to #362)

- unused code was removed
- bonded selections fully implemented
- performance improvements
  • Loading branch information
orbeckst committed Nov 3, 2015
2 parents aac24f9 + 88f4798 commit 35fb1b0
Show file tree
Hide file tree
Showing 4 changed files with 635 additions and 442 deletions.
4 changes: 3 additions & 1 deletion package/CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ Enhancement

* GRO file reading approximately 50% faster for large files (Issue #212)
* GRO file writing now will write velocities where possible (Issue #494)
* Added bonded selection (Issue #362)
* Spherical layer and spherical zone selections now much faster (Issue #362)

Changes
* built html doc files are no longer version controlled (Issue #491)
Expand All @@ -45,7 +47,7 @@ Fixes
* Fixed non-compliant Amber NCDFWriter (Issue #488)
* Fixed many Timestep methods failing when positions weren't present
(Issue #512)

* Fixed PointSelection using KDTree (Issue #362)

10/08/15

Expand Down
114 changes: 66 additions & 48 deletions package/MDAnalysis/core/AtomGroup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4383,38 +4383,40 @@ def select_atoms(self, sel, *othersel, **selgroups):
**Simple selections**
protein, backbone, nucleic, nucleicbackbone
selects all atoms that belong to a standard set of residues; a protein
is identfied by a hard-coded set of residue names so it may not
work for esoteric residues.
selects all atoms that belong to a standard set of residues;
a protein is identfied by a hard-coded set of residue names so
it may not work for esoteric residues.
segid *seg-name*
select by segid (as given in the topology), e.g. ``segid 4AKE`` or ``segid DMPC``
select by segid (as given in the topology), e.g. ``segid 4AKE``
or ``segid DMPC``
resid *residue-number-range*
resid can take a single residue number or a range of numbers. A range
consists of two numbers separated by a colon (inclusive) such
as ``resid 1:5``. A residue number ("resid") is taken directly from the
topology.
resid can take a single residue number or a range of numbers. A
range consists of two numbers separated by a colon (inclusive)
such as ``resid 1:5``. A residue number ("resid") is taken
directly from the topology.
resnum *resnum-number-range*
resnum is the canonical residue number; typically it is set to the residue id
in the original PDB structure.
resnum is the canonical residue number; typically it is set to
the residue id in the original PDB structure.
resname *residue-name*
select by residue name, e.g. ``resname LYS``
name *atom-name*
select by atom name (as given in the topology). Often, this is force
field dependent. Example: ``name CA`` (for Cα atoms) or ``name OW`` (for SPC water oxygen)
select by atom name (as given in the topology). Often, this is
force field dependent. Example: ``name CA`` (for Cα atoms)
or ``name OW`` (for SPC water oxygen)
type *atom-type*
select by atom type; this is either a string or a number and depends on
the force field; it is read from the topology file (e.g. the CHARMM PSF
file contains numeric atom types). It has non-sensical values when a
PDB or GRO file is used as a topology.
select by atom type; this is either a string or a number and
depends on the force field; it is read from the topology file
(e.g. the CHARMM PSF file contains numeric atom types). It has
non-sensical values when a PDB or GRO file is used as a topology
atom *seg-name* *residue-number* *atom-name*
a selector for a single atom consisting of segid resid atomname,
e.g. ``DMPC 1 C2`` selects the C2 carbon of the first residue of the DMPC
segment
e.g. ``DMPC 1 C2`` selects the C2 carbon of the first residue of
the DMPC segment
altloc *alternative-location*
a selection for atoms where alternative locations are available,
which is often the case with high-resolution crystal structures
e.g. `resid 4 and resname ALA and altloc B` selects only the atoms
of ALA-4 that have an altloc B record.
e.g. `resid 4 and resname ALA and altloc B` selects only the
atoms of ALA-4 that have an altloc B record.
**Boolean**
Expand All @@ -4423,65 +4425,81 @@ def select_atoms(self, sel, *othersel, **selgroups):
all atoms that aren't part of a protein
and, or
combine two selections according to the rules of boolean algebra,
e.g. ``protein and not (resname ALA or resname LYS)`` selects all atoms
that belong to a protein, but are not in a lysine or alanine residue
combine two selections according to the rules of boolean
algebra, e.g. ``protein and not (resname ALA or resname LYS)``
selects all atoms that belong to a protein, but are not in a
lysine or alanine residue
**Geometric**
around *distance* *selection*
selects all atoms a certain cutoff away from another selection,
e.g. ``around 3.5 protein`` selects all atoms not belonging to protein
that are within 3.5 Angstroms from the protein
e.g. ``around 3.5 protein`` selects all atoms not belonging to
protein that are within 3.5 Angstroms from the protein
point *x* *y* *z* *distance*
selects all atoms within a cutoff of a point in space, make sure
coordinate is separated by spaces, e.g. ``point 5.0 5.0 5.0 3.5`` selects
all atoms within 3.5 Angstroms of the coordinate (5.0, 5.0, 5.0)
coordinate is separated by spaces,
e.g. ``point 5.0 5.0 5.0 3.5`` selects all atoms within 3.5
Angstroms of the coordinate (5.0, 5.0, 5.0)
prop [abs] *property* *operator* *value*
selects atoms based on position, using *property* **x**, **y**, or
**z** coordinate. Supports the **abs** keyword (for absolute value) and
the following *operators*: **<, >, <=, >=, ==, !=**. For example, ``prop z >= 5.0``
selects all atoms with z coordinate greater than 5.0; ``prop abs z <= 5.0``
selects all atoms within -5.0 <= z <= 5.0.
selects atoms based on position, using *property* **x**, **y**,
or **z** coordinate. Supports the **abs** keyword (for absolute
value) and the following *operators*: **<, >, <=, >=, ==, !=**.
For example, ``prop z >= 5.0`` selects all atoms with z
coordinate greater than 5.0; ``prop abs z <= 5.0`` selects all
atoms within -5.0 <= z <= 5.0.
sphzone *radius* *selection*
Selects all atoms that are within *radius* of the center of
geometry of *selection*
sphlayer *inner radius* *outer radius* *selection*
Similar to sphzone, but also excludes atoms that are within
*inner radius* of the selection COG
**Connectivity**
byres *selection*
selects all atoms that are in the same segment and residue as
selection, e.g. specify the subselection after the byres keyword
bonded *selection*
selects all atoms that are bonded to selection
eg: ``select name H bonded name O`` selects only hydrogens
bonded to oxygens
**Index**
bynum *index-range*
selects all atoms within a range of (1-based) inclusive indices,
e.g. ``bynum 1`` selects the first atom in the universe; ``bynum 5:10``
selects atoms 5 through 10 inclusive. All atoms in the
:class:`MDAnalysis.Universe` are consecutively numbered, and the index
runs from 1 up to the total number of atoms.
e.g. ``bynum 1`` selects the first atom in the universe;
``bynum 5:10`` selects atoms 5 through 10 inclusive. All atoms
in the :class:`MDAnalysis.Universe` are consecutively numbered,
and the index runs from 1 up to the total number of atoms.
**Preexisting selections**
group *group-name*
selects the atoms in the :class:`AtomGroup` passed to the function as an
argument named *group-name*. Only the atoms common to *group-name* and the
instance :meth:`~select_atoms` was called from will be considered.
*group-name* will be included in the parsing just by comparison of atom indices.
This means that it is up to the user to make sure they were defined in an
appropriate :class:`Universe`.
selects the atoms in the :class:`AtomGroup` passed to the
function as an argument named *group-name*. Only the atoms
common to *group-name* and the instance :meth:`~select_atoms`
was called from will be considered. *group-name* will be
included in the parsing just by comparison of atom indices.
This means that it is up to the user to make sure they were
defined in an appropriate :class:`Universe`.
fullgroup *group-name*
just like the ``group`` keyword with the difference that all the atoms of
*group-name* are included. The resulting selection may therefore have atoms
that were initially absent from the instance :meth:`~select_atoms` was
called from.
just like the ``group`` keyword with the difference that all the
atoms of *group-name* are included. The resulting selection may
therefore have atoms that were initially absent from the
instance :meth:`~select_atoms` was called from.
.. versionchanged:: 0.7.4
Added *resnum* selection.
.. versionchanged:: 0.8.1
Added *group* and *fullgroup* selections.
.. versionchanged:: 0.13.0
Added *bonded* selection
"""
from . import Selection # can ONLY import in method, otherwise cyclical import!
# can ONLY import in method, otherwise cyclical import!
from . import Selection

atomgrp = Selection.Parser.parse(sel, selgroups).apply(self)
if len(othersel) == 0:
Expand Down
Loading

0 comments on commit 35fb1b0

Please sign in to comment.