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 Angstromx_old: Previous geometry coordinates in Angstromopt_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: u32Checkpoint format version.
- Version 1: Coordinates in Angstrom (legacy)
- Version 2: Coordinates in Bohr (legacy, deprecated)
- Version 3: Coordinates in Angstrom (current, unit standardization)
step: usizeCurrent optimization step number
geometry: SerializableGeometryCurrent molecular geometry
x_old: Vec<f64>Previous geometry (for gradient computation)
hessian: Vec<Vec<f64>>Current approximate Hessian matrix
opt_state: SerializableOptimizationStateOptimization state with history
config: ConfigComplete calculation configuration
Implementations§
Source§impl Checkpoint
impl Checkpoint
Sourcepub fn new(
step: usize,
geometry: &Geometry,
x_old: &DVector<f64>,
hessian: &DMatrix<f64>,
opt_state: &OptimizationState,
config: &Config,
) -> Self
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 numbergeometry- Current molecular geometryx_old- Previous geometry coordinateshessian- Current approximate Hessian matrixopt_state- Optimization state with historyconfig- 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
);Sourcepub fn save(&self, path: &Path) -> Result<(), Box<dyn Error>>
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(())
}Sourcepub fn load(path: &Path) -> Result<CheckpointLoad, Box<dyn Error>>
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 numbergeometry: Molecular geometryx_old: Previous geometry coordinateshessian: Hessian matrixopt_state: Optimization stateconfig: 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
impl<'de> Deserialize<'de> for Checkpoint
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Auto Trait Implementations§
impl Freeze for Checkpoint
impl RefUnwindSafe for Checkpoint
impl Send for Checkpoint
impl Sync for Checkpoint
impl Unpin for Checkpoint
impl UnsafeUnpin for Checkpoint
impl UnwindSafe for Checkpoint
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read more§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.