.. index:: pair: class; rgpot::PotentialHandle .. _doxid-classrgpot_1_1_potential_handle: class rgpot::PotentialHandle ============================ .. toctree:: :hidden: Overview ~~~~~~~~ Move-only RAII handle around an opaque ``rgpot_potential_t`` pointer. :ref:`More...` .. ref-code-block:: cpp :class: doxyrest-overview-code-block #include class PotentialHandle { public: // construction :ref:`PotentialHandle`(rgpot_potential_t* handle); :ref:`PotentialHandle`(PotentialHandle&& other); :target:`PotentialHandle`(const PotentialHandle&); :ref:`~PotentialHandle`(); // methods PotentialHandle& :ref:`operator=`(PotentialHandle&& other); PotentialHandle& :target:`operator=`(const PotentialHandle&); :ref:`CalcResult` :ref:`calculate`(const :ref:`InputSpec`& input); rgpot_potential_t* :ref:`raw`() const; template static PotentialHandle :ref:`from_impl`(Impl& impl); static PotentialHandle :ref:`from_callback`(rgpot_status_t(*)(void*, const rgpot_force_input_t*, rgpot_force_out_t*) callback, void* user_data, void(*)(void*) free_fn = nullptr); }; .. _details-classrgpot_1_1_potential_handle: Detailed Documentation ~~~~~~~~~~~~~~~~~~~~~~ Move-only RAII handle around an opaque ``rgpot_potential_t`` pointer. The handle is non-copyable. Move semantics transfer ownership of the underlying Rust allocation. On destruction the Rust core frees all resources associated with the potential via ``rgpot_potential_free()``. Construction ------------ .. index:: pair: function; PotentialHandle .. _doxid-classrgpot_1_1_potential_handle_1a71cb187ba8a84c1b54eaab3d1db03e03: .. ref-code-block:: cpp :class: doxyrest-title-code-block PotentialHandle(rgpot_potential_t* handle) Adopt an existing raw handle. *handle* was obtained from ``rgpot_potential_new()`` and has not been freed. .. rubric:: Parameters: .. list-table:: :widths: 20 80 * - handle - Raw pointer to the Rust-side potential object. .. index:: pair: function; PotentialHandle .. _doxid-classrgpot_1_1_potential_handle_1a6dec8cbeff49b3f49bc153ded417a6c4: .. ref-code-block:: cpp :class: doxyrest-title-code-block PotentialHandle(PotentialHandle&& other) Move constructor — transfers ownership. .. rubric:: Parameters: .. list-table:: :widths: 20 80 * - other - Handle to move from; left in a null state. .. _doxid-classrgpot_1_1_potential_handle_1abee932b1fa9323d82707bf43a31d0357: .. ref-code-block:: cpp :class: doxyrest-title-code-block ~PotentialHandle() Destructor — releases the Rust-side allocation. Safe to call on a moved-from handle (internal pointer is ``nullptr``). Methods ------- .. index:: pair: function; operator= .. _doxid-classrgpot_1_1_potential_handle_1a552fe7a058b0411930733882b8512e14: .. ref-code-block:: cpp :class: doxyrest-title-code-block PotentialHandle& operator=(PotentialHandle&& other) Move assignment — releases current handle, transfers ownership. .. rubric:: Parameters: .. list-table:: :widths: 20 80 * - other - Handle to move from; left in a null state. .. rubric:: Returns: Reference to ``*this``. .. index:: pair: function; calculate .. _doxid-classrgpot_1_1_potential_handle_1af864dc8f487587b425fb6c3fdf3bc705: .. ref-code-block:: cpp :class: doxyrest-title-code-block :ref:`CalcResult` calculate(const :ref:`InputSpec`& input) Perform a force/energy calculation. Creates a ``:ref:`CalcResult ```, delegates to ``rgpot_potential_calculate()``, and checks the returned status code. The callback sets the forces tensor in the output struct. .. rubric:: Parameters: .. list-table:: :widths: 20 80 * - input - The atomic configuration to evaluate. * - :ref:`rgpot::Error ` - when the underlying callback reports failure. .. rubric:: Returns: A ``:ref:`CalcResult ``` containing energy, variance, and forces. .. index:: pair: function; raw .. _doxid-classrgpot_1_1_potential_handle_1a864f673374dc6843a4a28dbf98a04839: .. ref-code-block:: cpp :class: doxyrest-title-code-block rgpot_potential_t* raw() const Access the raw opaque handle for C interop. .. rubric:: Returns: Pointer to the underlying ``rgpot_potential_t``. .. index:: pair: function; from_impl .. _doxid-classrgpot_1_1_potential_handle_1af5e646d3175b1fdac6040e17ed014c25: .. ref-code-block:: cpp :class: doxyrest-title-code-block template static PotentialHandle from_impl(Impl& impl) Create a handle from a legacy C++ potential implementation. Registers a template trampoline that extracts raw CPU pointers from the DLPack tensors in ``rgpot_force_input_t``, constructs legacy ``:ref:`ForceInput ``` / ``:ref:`ForceOut ``` types for *Impl::forceImpl()*, and wraps the resulting forces in an owning DLPack tensor. The caller retains ownership of *impl* and **must** keep it alive for the lifetime of the returned handle. .. rubric:: Parameters: .. list-table:: :widths: 20 80 * - Impl - A type with ``void`` ``forceImpl`` (const ``:ref:`ForceInput `&``, ``ForceOut*``). * - impl - Reference to the C++ potential object. .. rubric:: Returns: A new ``:ref:`PotentialHandle ``` wrapping *impl*. .. index:: pair: function; from_callback .. _doxid-classrgpot_1_1_potential_handle_1aecafbe5b4d058843e4853545f26a2dc6: .. ref-code-block:: cpp :class: doxyrest-title-code-block static PotentialHandle from_callback(rgpot_status_t(*)(void*, const rgpot_force_input_t*, rgpot_force_out_t*) callback, void* user_data, void(*)(void*) free_fn = nullptr) Create a handle from an explicit C callback and user data. This is the low-level factory; prefer ``:ref:`from_impl() ``` for C++ potentials. .. rubric:: Parameters: .. list-table:: :widths: 20 80 * - callback - Function pointer matching the ``rgpot_potential_t`` callback signature. * - user_data - Opaque pointer forwarded to every *callback* invocation. * - free_fn - Optional destructor for *user_data* (may be ``nullptr`` if the caller manages the lifetime). .. rubric:: Returns: A new ``:ref:`PotentialHandle ```.