pub struct State {
pub energy: f64,
pub forces: DVector<f64>,
pub geometry: Geometry,
}Expand description
Represents an electronic state of a molecule with energy, forces, and geometry.
The State struct encapsulates all information about a single electronic state
needed for MECP optimization: the potential energy, the gradient (forces), and
the molecular geometry at which these were evaluated.
In the MECP algorithm, we track two states simultaneously (typically called “state A” and “state B”) and seek the geometry where their energies are equal while minimizing the perpendicular gradient component.
§Unit Conventions
- Energy: Hartree (Ha) - atomic unit of energy
- Forces/Gradients: Hartree/Angstrom (Ha/Å) - converted from native QM output
- Geometry coordinates: Angstrom (Å) - see
Geometrydocumentation
§Force Convention
Forces are the negative gradient of the energy with respect to nuclear positions:
F = -∇EThis is the standard convention in quantum chemistry, where positive forces point in the direction of decreasing energy. Forces are converted from the native QM program output (Ha/Bohr) to Ha/Å for consistency with coordinates.
Fields§
§energy: f64Potential energy of the state in Hartree (Ha)
forces: DVector<f64>Forces (negative gradient) in Hartree/Angstrom (Ha/Å) Stored as a flat vector matching Geometry::coords format
geometry: GeometryMolecular geometry at which energy and forces were evaluated (coordinates in Angstrom)
Implementations§
Source§impl State
impl State
Sourcepub fn validate(&self) -> Result<(), String>
pub fn validate(&self) -> Result<(), String>
Validates that the State contains meaningful data and is not a zero-energy failure.
This method checks for common failure modes where QM calculations appear to succeed but actually return invalid or default values. It prevents silent failures that could lead to incorrect MECP optimization results.
§Validation Criteria
The State is considered invalid if:
- Energy is exactly zero (indicates parsing failure or uninitialized state)
- All force components are zero (indicates gradient calculation failure)
- Forces vector is empty (indicates missing gradient data)
§Returns
Ok(())if the State contains valid, meaningful dataErr(String)with a descriptive error message if validation fails
§Examples
use omecp::geometry::{Geometry, State};
use nalgebra::DVector;
// Valid state with non-zero energy and forces
let geometry = Geometry::new(vec!["H".to_string()], vec![0.0, 0.0, 0.0]);
let valid_state = State {
energy: -0.5,
forces: DVector::from_vec(vec![0.1, -0.2, 0.0]),
geometry,
};
assert!(valid_state.validate().is_ok());
// Invalid state with zero energy
let geometry = Geometry::new(vec!["H".to_string()], vec![0.0, 0.0, 0.0]);
let invalid_state = State {
energy: 0.0,
forces: DVector::from_vec(vec![0.1, -0.2, 0.0]),
geometry,
};
assert!(invalid_state.validate().is_err());Trait Implementations§
Auto Trait Implementations§
impl Freeze for State
impl RefUnwindSafe for State
impl Send for State
impl Sync for State
impl Unpin for State
impl UnsafeUnpin for State
impl UnwindSafe for State
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§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.