Atom selections¶
Analysis commands and Python objects select atoms with
PQAnalysis.topology.selection.Selection. The same string language is
used in input-file keys such as reference_selection and
target_selection. Indices are 0-based.
Always check that the selection contains the intended atoms. RDF normalization, MSD statistics and VACF amplitudes all scale with that population.
String language¶
A selection string is parsed with a Lark grammar. Applied to
examples/water/trajectory.xyz, whose atoms are O (index 0), H (1) and
H (2), the common forms select:
String |
Meaning |
Atoms selected |
|---|---|---|
|
Atom-type name |
O |
|
Atom-type name |
both H |
|
Single index |
O |
|
Inclusive index range |
both H |
|
Inclusive index range |
all three |
|
Range with step |
O and the second H |
|
Element number or symbol |
O |
|
Element symbol |
both H |
|
Atom type and element |
O |
|
Every atom |
all three |
|
Set difference (all except H) |
O |
|
Union |
all three |
|
Intersection |
both H |
Operators¶
Statements combine with:
,union
&intersection
|set difference (left minus right)
Use parentheses whenever you mix operators. The parser’s implicit grouping
does not follow the order the class docstring describes (O,H&H is read as
(O,H)&H; see issue #185), so an
unparenthesized mix is not portable across versions.
Python¶
import numpy as np
from PQAnalysis.io import read_trajectory
from PQAnalysis.topology import Selection
traj = read_trajectory("examples/water/trajectory.xyz")
topology = traj[0].topology
Selection("O").select(topology) # array([0])
Selection("H").select(topology) # array([1, 2])
Selection("*|H").select(topology) # array([0])
Selection(np.array([0, 2])).select(topology) # array([0, 2])
Selection(None).select(topology) # all atoms
Selection also accepts a single Atom or Element. A plain Python
list of integers is rejected; pass a NumPy integer array.
use_full_atom_info¶
By default select(..., use_full_atom_info=False) matches on element type
only. Set use_full_atom_info=True to distinguish atom-type names that share
an element (PQ residue atom types). Residue-aware RDF exclusions additionally
need a restart and a moldescriptor; see Radial Distribution Function.
Analysis objects take the same strings as reference_species,
target_species or selection:
from PQAnalysis.analysis import RDF
from PQAnalysis.io import TrajectoryReader
RDF(
TrajectoryReader("examples/water/trajectory.xyz"),
reference_species="O",
target_species="H",
delta_r=0.5,
r_max=4.0,
)