Skip to main content

Handler

Trait Handler 

Source
pub trait Handler: Send {
    // Required method
    fn on_step(&mut self, info: &StepInfo, sys: &PackContext);

    // Provided methods
    fn on_start(&mut self, _ntotat: usize, _ntotmol: usize) { ... }
    fn on_initialized(&mut self, _sys: &PackContext) { ... }
    fn on_phase_start(&mut self, _info: &PhaseInfo) { ... }
    fn on_finish(&mut self, _sys: &PackContext) { ... }
    fn should_stop(&self) -> bool { ... }
    fn on_inner_iter(&mut self, _iter: u32, _f: F, _sys: &PackContext) { ... }
    fn on_phase_end(&mut self, _info: &PhaseInfo, _report: &PhaseReport) { ... }
}
Expand description

Callback interface called by crate::packer::Molpack during packing.

Required Methods§

Source

fn on_step(&mut self, info: &StepInfo, sys: &PackContext)

Called after each outer optimization loop iteration.

Provided Methods§

Source

fn on_start(&mut self, _ntotat: usize, _ntotmol: usize)

Called immediately at the start of pack, before any computation. Use this for immediate user feedback.

Source

fn on_initialized(&mut self, _sys: &PackContext)

Called once after initialization completes, with valid xcart positions. Use this to write the initial conformation (e.g. XYZHandler).

Source

fn on_phase_start(&mut self, _info: &PhaseInfo)

Called at the start of each packing phase (per-type and all-types). Allows stateful handlers to reset between phases.

Source

fn on_finish(&mut self, _sys: &PackContext)

Called once after the packing loop finishes (convergence or max loops).

Source

fn should_stop(&self) -> bool

Return true to request early termination of the packing loop.

Source

fn on_inner_iter(&mut self, _iter: u32, _f: F, _sys: &PackContext)

Called after each inner GENCAN iteration (more granular than on_step).

Default: no-op. Implement when you need per-inner-iteration feedback (e.g. plotting objective evolution, adaptive stop criteria).

  • iter — 0-based inner iteration counter within the current outer step
  • f — current objective value (pair + restraint)
  • sys — read-only view of the packing context
Source

fn on_phase_end(&mut self, _info: &PhaseInfo, _report: &PhaseReport)

Called at the end of each packing phase, with a summary report.

Default: no-op. Paired with on_phase_start for symmetric setup / teardown hooks.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§