apoCHARMM 1.0.0
High-performance molecular dynamics simulations on GPUs
 
Loading...
Searching...
No Matches
apocharmm.atom_selection.AtomSelection Class Reference

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.
 

Detailed Description

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.

See also
atom_selection

Constructor & Destructor Documentation

◆ __init__()

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.

Parameters
[in]handleExact ctypes.c_void_p containing a non-NULL, newly owned apo_atom_selection pointer.
Exceptions
TypeErrorIf handle is not a ctypes.c_void_p instance.
RuntimeErrorIf handle.value is None.
Postcondition
On success, this wrapper owns the native handle until closure.

Member Function Documentation

◆ contains()

bool apocharmm.atom_selection.AtomSelection.contains (   self,
int  atom_index 
)

Tests whether one atom index is selected.

Parameters
[in]atom_indexZero-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()).
Returns
True when the atom is selected; otherwise False.
Exceptions
TypeErrorIf atom_index is not an int or is a bool.
ValueErrorIf atom_index is outside the signed 32-bit C int range.
RuntimeErrorIf this wrapper has been closed.
ApoCharmmErrorWith 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.

◆ getAtomIndices()

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.

Returns
A newly owned list[int] of zero-based, dimensionless indices in strictly ascending order. Its length equals getNumSelected().
Exceptions
RuntimeErrorIf this wrapper has been closed.
ApoCharmmErrorIf either native count or buffer-copy operation fails.
MemoryErrorIf the temporary buffer or Python list cannot be allocated.

◆ getNumAtoms()

int apocharmm.atom_selection.AtomSelection.getNumAtoms (   self)

Returns the number of atoms represented by the selection.

Returns
A non-negative, dimensionless Python int.
Exceptions
RuntimeErrorIf this wrapper has been closed.
ApoCharmmErrorIf the native C ABI rejects the live handle or reports an unexpected runtime failure.

◆ getNumSelected()

int apocharmm.atom_selection.AtomSelection.getNumSelected (   self)

Returns the number of selected atoms.

Returns
A dimensionless Python int in [0, getNumAtoms()].
Exceptions
RuntimeErrorIf this wrapper has been closed.
ApoCharmmErrorIf the native C ABI rejects the live handle or reports an unexpected runtime failure.