1use molrs::types::F;
2use std::fmt;
3
4#[derive(Debug, Clone)]
5pub enum PackError {
6 ConstraintsFailed(String),
8 MaxIterations,
10 NoTargets,
12 EmptyMolecule(usize),
14 InvalidPBCBox { min: [F; 3], max: [F; 3] },
17 ConflictingPeriodicBoxes {
21 first: ([F; 3], [F; 3], [bool; 3]),
22 second: ([F; 3], [F; 3], [bool; 3]),
23 },
24}
25
26impl fmt::Display for PackError {
27 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
28 match self {
29 PackError::ConstraintsFailed(msg) => {
30 write!(f, "Packmol failed to satisfy constraints: {msg}")
31 }
32 PackError::MaxIterations => {
33 write!(f, "Maximum iterations reached without convergence")
34 }
35 PackError::NoTargets => write!(f, "No targets provided"),
36 PackError::EmptyMolecule(i) => write!(f, "Target {i} has no atoms"),
37 PackError::InvalidPBCBox { min, max } => write!(
38 f,
39 "Invalid PBC box: min={:?}, max={:?} (all max-min components must be > 0)",
40 min, max
41 ),
42 PackError::ConflictingPeriodicBoxes { first, second } => write!(
43 f,
44 "Conflicting periodic boxes declared by restraints: {first:?} vs {second:?}. \
45 At most one periodic InsideBoxRestraint is allowed per packing run."
46 ),
47 }
48 }
49}
50
51impl std::error::Error for PackError {}