selection
A module containing the Selection class and related functions/classes.
Summary
Classes:
A class for representing a selection. |
|
A class for transforming a Lark parse tree. |
|
A class for visiting a Lark parse tree and returning the indices of parsed selection. |
Reference
- class Selection(
- selection_object: SelectionCompatible = None,
Bases:
object
A class for representing a selection.
If the selection object is a Selection object, the selection is copied.
- There are several ways to create a selection:
None: all atoms are selected
Atom: the given atom is selected
Element: all atoms with the given element type are selected
Atoms: all atoms in the given list are selected
Elements: all atoms with the given element types are selected
Np1DIntArray: the atoms with the given indices are selected
List[str]: all atoms with the given atom type names are selected
str: the given string is parsed and the atoms selected by the
selection are selected
This string will be parsed based on a Lark grammar. Which is defined as follows:
simple word containing only letters and numbers: the
atom type with the given name is selected - <integer>: the atom with the given index is selected - <integer1>..<integer2>: the indices from integer1 to integer2 are selected - <integer1>-<integer2>: the indices from integer1 to integer2 are selected - <integer1>..<integer2>..<integer3>: the indices from integer1 to integer3 with a step size of integer3 are selected - atom(<atomtype>, <atomic_number>): the atom with the given atom type and atomic number is selected - atom(<atomtype>, <element_symbol>): the atom with the given atom type and element symbol is selected - elem(<atomic_number>): all atoms with the given element type are selected - elem(<element_symbol>): all atoms with the given element type are selected - *: all atoms are selected (same as ‘all’), useful if only few atoms should be excluded
All of the above statements can be combined with the following operators:
‘,’: the union of the two statements is selected, meaning that
the atoms selected by the first statement and the atoms selected by the second statement are selected - ‘&’: the intersection of the two statements is selected, meaning that only the atoms selected by both statements are selected - ‘|’: the set difference of the two statements is selected, meaning that only the atoms selected by the first statement are selected, which are not selected by the second statement
The operators are evaluated in the following order: ‘|’ -> ‘&’ -> ‘,’ This means that the ‘,’ operator has the lowest precedence and the ‘|’ operator has the highest precedence and therefore binds the strongest.
Additionally, parentheses can be used to group statements and change the order of evaluation.
Notes
The atom counting always starts with 0!
- Parameters:
selection_object (SelectionCompatible, optional) – The object to create the selection from.
- __repr__() str [source]
Returns the string representation of the selection object.
- Returns:
The string representation of the selection object.
- Return type:
str
- __str__() str [source]
Returns the string representation of the selection object.
- Returns:
The string representation of the selection object.
- Return type:
str
- select(
- topology: Topology,
- use_full_atom_info: bool = False,
Returns the indices of the atoms selected by the selection object.
If the selection_object is None all atoms are selected. With the parameter use_full_atom_info the selection can be performed based on the full atom information (i.e. atom type names and element type information). If use_full_atom_info is False, the selection is performed based on the element type information only.
- Parameters:
topology (Topology) – The topology to get the indices from.
use_full_atom_info (bool, optional) – Whether to use the full atom information, by default False
- Returns:
The indices of the atoms selected by the selection object.
- Return type:
- logger = <CustomLogger PQAnalysis.Selection (INFO)>
- class SelectionCompatible
- A type variable for the Selection class.It can be used to specify the type of the selection object.The following types are supported:- str: the given string is parsed and the atoms selected by the selection are selected- Atom: the given atom is selected- Element: all atoms with the given element type are selected- Atoms: all atoms in the given list are selected- Elements: all atoms with the given element types are selected- Np1DIntArray: the atoms with the given indices are selected- List[str]: all atoms with the given atom type names are selected- Selection: the given selection is copied- None: all atoms are selected
alias of TypeVar(‘SelectionCompatible’, str, PQAnalysis.core.Atom, list[PQAnalysis.core.Atom], PQAnalysis.core.Element, list[PQAnalysis.core.Element], ~PQAnalysis.types.Np1DIntArray, list[str], PQAnalysis.topology.Selection, None)
- class SelectionTransformer(
- topology=Topology with 0 atoms and 0 residues and 0 unique residues.,
- visit_tokens=False,
- use_full_atom_info=False,
Bases:
Transformer
A class for transforming a Lark parse tree.
- Parameters:
Transformer (Transformer) – The type of the Transformer class to inherit from.
visit_tokens (bool, optional) – Whether to visit the tokens, by default False
topology (Topology) – The topology to get the indices from.
use_full_atom_info (bool, optional) – Whether to use the full atom information, by default False
- INT(
- items: list[Token] | Token,
Returns the integer of the given token.
- Parameters:
items (List[Token] | Token) – The token to get the integer of.
- Returns:
The integer of the given token.
- Return type:
int
- UNSIGNED_INT(
- items: Token | list[Token],
Returns the unsigned integer of the given token.
- Parameters:
items (List[Token] | Token) – The token to get the unsigned integer of.
- Returns:
The unsigned integer of the given token.
- Return type:
int
- all(
- _,
Returns all indices.
- Returns:
The indices of the all Token.
- Return type:
- and_statement(
- items: Any,
Returns the indices of the and_statement Token.
- Parameters:
items (List[Np1DIntArray]) – The indices to get the indices of.
- Returns:
The indices of the and_statement Token.
- Return type:
- atom(
- items: Any,
Returns the indices of the given atom.
- Parameters:
items (Any) – The atom to get the indices of.
- Returns:
The indices of the given atom.
- Return type:
- atomtype(
- items: Any,
Returns the indices of the atoms with the given atom type name.
- Parameters:
items (Any) – The atom type name to get the indices of.
- Returns:
The indices of the atoms with the given atom type name.
- Return type:
- element(
- items: Any,
Returns the indices of the given element type.
- Parameters:
items (Any) – The element type to get the indices of.
- Returns:
The indices of the given element type.
- Return type:
- index(
- items: list[int],
Returns the given index as an array.
- Parameters:
items (List[int]) – The index to get the indices of.
- Returns:
The indices of the index Token.
- Return type:
- indices(
- items: list[int],
Returns a range of indices based on the given indices.
if two indices are given, a range from the first index to the second index is returned. if three indices are given, a range from the first index to the third index with a step size of the second index is returned.
- Parameters:
items (List[int]) – The indices to get the indices of.
- Returns:
The indices of the indices Token.
- Return type:
- Raises:
PQValueError – If the indices Token has more than 3 items. Should never be reached.
- integer(
- items: list[Token],
Returns the integer of the given token.
- Parameters:
items (List[Token]) – The token to get the integer of.
- Returns:
The integer of the given token.
- Return type:
int
- letters(
- items: list[Token],
Returns the letters of the given token.
- Parameters:
items (List[Token]) – The token to get the letters of.
- Returns:
The letters of the given token.
- Return type:
str
- or_statement(
- items: Any,
Returns the indices of the or_statement Token.
- Parameters:
items (List[Np1DIntArray]) – The indices to get the indices of.
- Returns:
The indices of the or_statement Token.
- Return type:
- residue(
- items: Any,
Returns the indices of the given residue name.
- Parameters:
items (Any) – The residue name to get the indices of.
- Returns:
The indices of the given residue name.
- Return type:
- residue_number(
- items: Any,
Returns the indices of the given residue number.
- Parameters:
items (Any) – The residue number to get the indices of.
- Returns:
The indices of the given residue number.
- Return type:
- unsigned_integer(
- items: list[Token],
Returns the unsigned integer of the given token.
- Parameters:
items (List[Token]) – The token to get the unsigned integer of.
- Returns:
The unsigned integer of the given token.
- Return type:
int
- without_statement(
- items: Any,
Returns the indices of the the first item without the indices of all other items.
- Parameters:
items (List[Np1DIntArray]) – The indices to get the indices of.
- Returns:
The indices of the given without statement Token.
- Return type:
- class SelectionVisitor[source]
Bases:
Visitor
A class for visiting a Lark parse tree and returning the indices of parsed selection.
- Parameters:
Visitor (Visitor) – The type of the Visitor class to inherit from.
topology (Topology) – The topology to get the indices from.
use_full_atom_info (bool, optional) – Whether to use the full atom information, by default False
- expression(
- tree: Tree,
Visits the given tree and returns the indices of the parsed selection.
- Parameters:
tree (Tree) – The tree to visit.
- Returns:
The indices of the parsed selection.
- Return type:
- visit(
- tree: Tree,
Visits the given tree and returns the indices of the parsed selection.
- Parameters:
tree (Tree) – The tree to visit.
- Returns:
The indices of the parsed selection.
- Return type: