mod eindir

module eindir

rgpot as a strict superset of eindir: first-member struct embedding.

rgpot_potential_t embeds eindir_objective_t as its FIRST member, so a rgpot_potential_t* IS-A eindir_objective_t* at the C ABI with zero cost:

rgpot_potential_t *pot = rgpot_potential_new_eindir(...);
eindir_objective_t *obj = (eindir_objective_t*)pot;  // zero-cost cast
double val;
eindir_objective_eval(obj, x, &val);                 // works

The eval_fn / grad_fn stored in the embedded base call through to the rgpot callback, so evaluation logic lives once – there is no duplicate eval path and no conversion method.

Re-exports

  • :rust:any:eindir_core::ffi::eindir_status_t

  • :rust:any:eindir_core::ffi::EindirEvalFn

  • :rust:any:eindir_core::ffi::EindirFreeFn

  • :rust:any:eindir_core::ffi::EindirGradFn

  • :rust:any:eindir_core::ffi::eindir_abi_stamp_t

  • :rust:any:eindir_core::ffi::eindir_objective_eval

  • :rust:any:eindir_core::ffi::eindir_objective_grad

  • :rust:any:eindir_core::ffi::eindir_objective_has_grad

  • :rust:any:eindir_core::ffi::eindir_objective_t

Functions

extern C fn rgpot_eindir_abi_stamp() -> eindir_abi_stamp_t

The eindir ABI stamp of the eindir_objective_t base that rgpot_potential_t embeds as its first member.

A consumer that takes the potential as an eindir objective (rgmin’s rgmin_minimize_eindir, for one) passes this stamp to eindir_core_abi_compatible, so a layout from a different eindir-core revision is refused instead of read as the wrong struct.

unsafe extern C fn rgpot_potential_eval_counts(pot: *const rgpot_potential_t, out: *mut rgpot_eval_counts_t) -> rgpot_status_t

Read the computed and served counters of pot into out.

Safety

pot must be NULL or a live pointer from rgpot_potential_new_eindir, and out NULL or writable. NULL for either yields RGPOT_INVALID_PARAMETER.

unsafe extern C fn rgpot_potential_free_eindir(pot: *mut rgpot_potential_t)

Free a potential created by rgpot_potential_new_eindir.

Calls pot_free_fn(pot_user_data) if provided, frees all owned arrays, then frees the struct. Do NOT call eindir_objective_free on the embedded base; call this function.

Safety

pot must be NULL or a pointer returned by rgpot_potential_new_eindir that has not been freed yet. The pointer is invalid after the call.

unsafe extern C fn rgpot_potential_new_eindir(callback: PotentialCallback, user_data: *mut c_void, free_fn: Option<unsafe extern C fn (*mut c_void)>, n_atoms: usize, atomic_numbers: *const i32, box_matrix: *const f64, bounds_low: *const f64, bounds_high: *const f64) -> *mut rgpot_potential_t

Create a potential that is ALSO a valid eindir objective.

The returned pointer is simultaneously a rgpot_potential_t* and (via zero-cost cast to the first member) an eindir_objective_t*.

  • callback: the rgpot force/energy callback.

  • user_data / free_fn: opaque context for the rgpot callback.

  • n_atoms, atomic_numbers, box_matrix: molecular context.

  • bounds_low, bounds_high: f64 arrays of length n_atoms * 3 (may be NULL; defaults to [-50, 50] per dimension).

The caller must eventually pass the returned pointer to rgpot_potential_free.

Safety

atomic_numbers must be NULL or point to n_atoms readable i32 values, box_matrix NULL or 9 readable f64 values, and each bound NULL or n_atoms * 3 readable f64 values. callback and free_fn must be safe to call with user_data.

unsafe extern C fn rgpot_potential_reset_eval_counts(pot: *const rgpot_potential_t)

Zero the counters of pot.

Safety

pot must be NULL or a live pointer from rgpot_potential_new_eindir.

Structs and Unions

struct rgpot_eval_counts_t

Evaluations a potential handle has answered, split by origin.

computed counts callback invocations; served counts gradients answered from the fused energy-and-gradient result without invoking the callback. A caller that charges evaluations chooses which field to bill.

computed: u64
served: u64
struct rgpot_fused_cache_t

Opaque cache of the last fused energy and gradient evaluation.

Implementations

impl rgpot_fused_cache_t
struct rgpot_potential_t

Superset potential: embeds eindir_objective_t as its first member.

Because base is first and both structs are #[repr(C)], casting a *mut rgpot_potential_t to *mut eindir_objective_t is defined behaviour at the C ABI. No conversion method is needed.

base: eindir_objective_t

Embedded eindir base: the IS-A relationship lives here. MUST remain the first field.

callback: PotentialCallback

The underlying rgpot force/energy callback.

pot_user_data: *mut c_void

Opaque context for callback (distinct from base.user_data).

pot_free_fn: Option<unsafe extern C fn (*mut c_void)>

Optional destructor for pot_user_data.

n_atoms: usize

Atom count; set by rgpot_potential_new_eindir.

atomic_numbers: *mut i32

Atomic numbers, heap-allocated (len = n_atoms), owned by this struct.

box_matrix: [f64; 9]

Box matrix (column-major, 3x3), copied at construction.

Traits implemented

unsafe impl Send for rgpot_potential_t