Skip to main content
← OpenMECP Documentation

Checkpoint

Struct Checkpoint 

Source
pub struct Checkpoint {
    pub version: u32,
    pub step: usize,
    pub geometry: SerializableGeometry,
    pub x_old: Vec<f64>,
    pub hessian: Vec<Vec<f64>>,
    pub opt_state: SerializableOptimizationState,
    pub config: Config,
}
Expand description

Checkpoint structure for saving/restoring MECP calculations.

A checkpoint contains all information needed to continue an optimization from a specific step, including the current geometry, optimization history, and calculation configuration.

§Unit Conventions

As of version 3 (unit standardization), all coordinates are stored in Angstrom (Å):

  • geometry.coords: Molecular coordinates in Angstrom
  • x_old: Previous geometry coordinates in Angstrom
  • opt_state.geom_history: Geometry history in Angstrom

Gradients are stored in Hartree/Angstrom (Ha/Å):

  • opt_state.grad_history: Gradient history in Ha/Å

§Version History

  • Version 1: Original format with coordinates in Angstrom
  • Version 2: Intermediate format with coordinates in Bohr (deprecated)
  • Version 3: Current format with coordinates in Angstrom (unit standardization)

Validates: Requirement 1.5

Fields§

§version: u32

Checkpoint format version.

  • Version 1: Coordinates in Angstrom (legacy)
  • Version 2: Coordinates in Bohr (legacy, deprecated)
  • Version 3: Coordinates in Angstrom (current, unit standardization)
§step: usize

Current optimization step number

§geometry: SerializableGeometry

Current molecular geometry

§x_old: Vec<f64>

Previous geometry (for gradient computation)

§hessian: Vec<Vec<f64>>

Current approximate Hessian matrix

§opt_state: SerializableOptimizationState

Optimization state with history

§config: Config

Complete calculation configuration

Implementations§

Source§

impl Checkpoint

Source

pub fn new( step: usize, geometry: &Geometry, x_old: &DVector<f64>, hessian: &DMatrix<f64>, opt_state: &OptimizationState, config: &Config, ) -> Self

Create a new checkpoint from current optimization state.

§Arguments
  • step - Current optimization step number
  • geometry - Current molecular geometry
  • x_old - Previous geometry coordinates
  • hessian - Current approximate Hessian matrix
  • opt_state - Optimization state with history
  • config - Calculation configuration
§Examples
use omecp::checkpoint::Checkpoint;
use omecp::geometry::Geometry;
use omecp::optimizer::OptimizationState;
use omecp::config::Config;
use nalgebra::{DMatrix, DVector};

let elements = vec!["H".to_string()];
let coords = vec![0.0, 0.0, 0.0];
let geometry = Geometry::new(elements, coords);
let x_old = vec![0.0, 0.0, 0.0];
let hessian = DMatrix::identity(3, 3);
let opt_state = OptimizationState::new(5);  // max_history = 5
let config = Config::default();

let checkpoint = Checkpoint::new(
    5,                          // Step 5
    &geometry,                  // Current geometry
    &DVector::from_vec(x_old),  // Previous coords
    &hessian,                   // Hessian matrix
    &opt_state,                 // Optimization state
    &config,                    // Configuration
);
Source

pub fn save(&self, path: &Path) -> Result<(), Box<dyn Error>>

Save checkpoint to a JSON file.

§Arguments
  • path - Path where checkpoint will be saved
§Errors

Returns an error if:

  • The file cannot be written
  • Serialization fails
§Examples
use omecp::checkpoint::Checkpoint;
use std::path::Path;
use omecp::geometry::Geometry;
use omecp::optimizer::OptimizationState;
use omecp::config::Config;
use nalgebra::{DMatrix, DVector};

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let elements = vec!["H".to_string()];
    let coords = vec![0.0, 0.0, 0.0];
    let geometry = Geometry::new(elements, coords);
    let x_old = vec![0.0, 0.0, 0.0];
    let hessian = DMatrix::identity(3, 3);
    let opt_state = OptimizationState::new(5);  // max_history = 5
    let config = Config::default();

    let checkpoint = Checkpoint::new(
        5,
        &geometry,
        &DVector::from_vec(x_old),
        &hessian,
        &opt_state,
        &config,
    );

    checkpoint.save(Path::new("mecp.chk"))?;
    std::fs::remove_file("mecp.chk")?;
    Ok(())
}
Source

pub fn load(path: &Path) -> Result<CheckpointLoad, Box<dyn Error>>

Load checkpoint from a JSON file.

§Arguments
  • path - Path to checkpoint file
§Returns

Returns a CheckpointLoad struct containing:

  • step: Optimization step number
  • geometry: Molecular geometry
  • x_old: Previous geometry coordinates
  • hessian: Hessian matrix
  • opt_state: Optimization state
  • config: Calculation configuration
§Errors

Returns an error if:

  • The file cannot be read
  • Deserialization fails
  • File format is invalid
§Examples
use omecp::checkpoint::{Checkpoint, CheckpointLoad};
use std::path::Path;
use omecp::geometry::Geometry;
use omecp::optimizer::OptimizationState;
use omecp::config::Config;
use nalgebra::{DMatrix, DVector};

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let elements = vec!["H".to_string()];
    let coords = vec![0.0, 0.0, 0.0];
    let geometry = Geometry::new(elements, coords);
    let x_old = vec![0.0, 0.0, 0.0];
    let hessian = DMatrix::identity(3, 3);
    let opt_state = OptimizationState::new(5);  // max_history = 5
    let config = Config::default();

    let checkpoint = Checkpoint::new(
        5,
        &geometry,
        &DVector::from_vec(x_old),
        &hessian,
        &opt_state,
        &config,
    );

    checkpoint.save(Path::new("mecp.chk"))?;

    let loaded: CheckpointLoad = Checkpoint::load(Path::new("mecp.chk"))?;

    std::fs::remove_file("mecp.chk")?;
    Ok(())
}

Trait Implementations§

Source§

impl<'de> Deserialize<'de> for Checkpoint

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Serialize for Checkpoint

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,