Owns one immutable native atom-selection handle. More...
Inherits _ApoObject.
Public Member Functions | |
| None | __init__ (self, ctypes.c_void_p handle) |
| Constructs an owning wrapper around a native selection handle. | |
| int | getNumAtoms (self) |
| Returns the number of atoms represented by the selection. | |
| int | getNumSelected (self) |
| Returns the number of selected atoms. | |
| list[int] | getAtomIndices (self) |
| Returns all selected atom indices. | |
| bool | contains (self, int atom_index) |
| Tests whether one atom index is selected. | |
Owns one immutable native atom-selection handle.
Atom indices are zero-based, sorted in ascending order when returned as a list, and dimensionless. The wrapper stores no coordinates and performs no CUDA transfer or synchronization.
The wrapper owns its C handle. close(), destroy(), context-manager exit, or finalization releases that handle; explicit closure is idempotent. Accessing any query after closure raises RuntimeError. Closing the selector or PSF that produced this object does not invalidate the selection.
The class provides no internal synchronization. Do not overlap close() with a query from another thread.
| None apocharmm.atom_selection.AtomSelection.__init__ | ( | self, | |
| ctypes.c_void_p | handle | ||
| ) |
Constructs an owning wrapper around a native selection handle.
This low-level constructor takes ownership of the pointed-to C handle without copying the native selection. User code should normally call AtomSelector.select() instead. After successful construction, the caller must not destroy or transfer the same native handle separately.
| [in] | handle | Exact ctypes.c_void_p containing a non-NULL, newly owned apo_atom_selection pointer. |
| TypeError | If handle is not a ctypes.c_void_p instance. |
| RuntimeError | If handle.value is None. |
| bool apocharmm.atom_selection.AtomSelection.contains | ( | self, | |
| int | atom_index | ||
| ) |
Tests whether one atom index is selected.
| [in] | atom_index | Zero-based, dimensionless Python int. Boolean values are rejected even though bool subclasses int. The value must first fit a signed C int and then lie in [0, getNumAtoms()). |
True when the atom is selected; otherwise False. | TypeError | If atom_index is not an int or is a bool. |
| ValueError | If atom_index is outside the signed 32-bit C int range. |
| RuntimeError | If this wrapper has been closed. |
| ApoCharmmError | With native status APO_STATUS_INVALID_ARGUMENT if the converted index is outside the selection's atom range, or with another status if the native call fails. |
| list[int] apocharmm.atom_selection.AtomSelection.getAtomIndices | ( | self | ) |
Returns all selected atom indices.
The method allocates a new ctypes buffer and a new Python list. The returned list never aliases native storage and remains valid after this wrapper is closed.
list[int] of zero-based, dimensionless indices in strictly ascending order. Its length equals getNumSelected(). | RuntimeError | If this wrapper has been closed. |
| ApoCharmmError | If either native count or buffer-copy operation fails. |
| MemoryError | If the temporary buffer or Python list cannot be allocated. |
| int apocharmm.atom_selection.AtomSelection.getNumAtoms | ( | self | ) |
Returns the number of atoms represented by the selection.
int. | RuntimeError | If this wrapper has been closed. |
| ApoCharmmError | If the native C ABI rejects the live handle or reports an unexpected runtime failure. |
| int apocharmm.atom_selection.AtomSelection.getNumSelected | ( | self | ) |
Returns the number of selected atoms.
int in [0, getNumAtoms()]. | RuntimeError | If this wrapper has been closed. |
| ApoCharmmError | If the native C ABI rejects the live handle or reports an unexpected runtime failure. |