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

Replaces a CHARMM-style restart file with current simulation state. More...

Inheritance diagram for apocharmm.restart_subscriber.RestartSubscriber:
apocharmm.subscriber.Subscriber

Public Member Functions

None __init__ (self, FilePath path, int|None report_frequency=None)
 Constructs and owns a native restart writer.
 
None close (self)
 Releases the owned concrete C handle and clears its base view.
 
- Public Member Functions inherited from apocharmm.subscriber.Subscriber
ctypes.c_void_p subscriber_handle (self)
 Returns the borrowed C base-subscriber pointer.
 
None setReportFrequency (self, int report_frequency)
 Sets the native reporting interval.
 
int getReportFrequency (self)
 Returns the native reporting interval.
 

Detailed Description

Replaces a CHARMM-style restart file with current simulation state.

Construction immediately creates or truncates the text output. During propagation, each scheduled native update rewrites the complete file with current context state and supported-integrator state. Box lengths and coordinates use angstroms, velocities use angstroms per AKMA time unit, and average temperature uses kelvin.

Native updates support CudaNoseHooverIntegrator, CudaLangevinPistonIntegrator, and CudaLangevinThermostatIntegrator. Device-backed state is copied to host, and each transfer synchronizes the current CUDA device.

The wrapper owns the concrete C handle. Its subscriber_handle property is a borrowed view into that handle. Use the object as a context manager or call close() through the wrapper; never destroy the borrowed view.

Warning
Unsubscribe before closing the wrapper. Closing invalidates the C base view even when the native integrator still retains the underlying C++ subscriber.
Each update truncates the target before all sections are written. A native failure can replace a usable restart with a partial file.

See also
subscriber

Constructor & Destructor Documentation

◆ __init__()

None apocharmm.restart_subscriber.RestartSubscriber.__init__ (   self,
FilePath  path,
int | None   report_frequency = None 
)

Constructs and owns a native restart writer.

path is converted with os.fsencode() through the package helper and copied by native construction. Accepted path objects are str, bytes, os.PathLike[str], and os.PathLike[bytes]. The original Python object is retained in _path, but native file access does not borrow it.

report_frequency=None selects the native default of 1000 steps. An explicit ordinary Python int must fit a signed 32-bit C int and be positive. Boolean values follow Python integer conversion: True becomes one and False is rejected by native validation.

Parameters
[in]pathFilesystem path to create or truncate. It must encode to a nonempty native path; when the path has a nonempty parent path, that parent path must exist. Encoded bytes are passed as a null-terminated C string, so an embedded null byte truncates the path observed by native code.
[in]report_frequencyOptional positive, dimensionless number of propagated steps between restart replacements.
Exceptions
TypeErrorIf path is not accepted by os.fsencode(), or an explicit frequency cannot be compared with integer bounds or converted by ctypes.c_int.
UnicodeEncodeErrorIf the platform filesystem encoding cannot encode a string path.
ValueErrorIf an explicit frequency is outside the signed 32-bit C int range.
ApoCharmmErrorWith native status APO_STATUS_INVALID_ARGUMENT if native construction rejects the path or frequency, or APO_STATUS_RUNTIME_ERROR if file opening, allocation, base-view conversion, or an unexpected native exception fails.
RuntimeErrorIf a native function reports success but returns a null concrete or base handle.
Postcondition
On success, the file has been created or truncated and this wrapper owns both the concrete handle and a live borrowed base view.

Reimplemented from apocharmm.subscriber.Subscriber.

Member Function Documentation

◆ close()

None apocharmm.restart_subscriber.RestartSubscriber.close (   self)

Releases the owned concrete C handle and clears its base view.

The inherited close operation is idempotent. On the first call it invokes apo_restart_subscriber_destroy, then this override clears the borrowed subscriber_handle regardless of whether the concrete handle had already been released.

Returns
None.
Postcondition
Later subscriber operations raise RuntimeError.
Warning
Call CudaIntegrator.unsubscribe(self) before closure. Native unsubscription requires the borrowed base view that this method clears.