use std::fmt;
use std::io;
use std::num::{ParseFloatError, ParseIntError};
#[derive(Debug)]
pub enum PdbError {
IoError(io::Error),
InvalidRecord(String),
ParseError(String),
AtomCountMismatch {
expected: usize,
found: usize,
},
NoAtomsSelected(String),
InsufficientAtoms(String),
NoChainMapping(String),
NoInterfaceContacts(String),
}
impl fmt::Display for PdbError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
PdbError::IoError(e) => write!(f, "IO error: {}", e),
PdbError::InvalidRecord(e) => write!(f, "Invalid record: {}", e),
PdbError::ParseError(e) => write!(f, "Parse error: {}", e),
PdbError::AtomCountMismatch { expected, found } => {
write!(
f,
"Atom count mismatch: expected {} atoms, found {}",
expected, found
)
}
PdbError::NoAtomsSelected(msg) => write!(f, "No atoms selected: {}", msg),
PdbError::InsufficientAtoms(msg) => write!(f, "Insufficient atoms: {}", msg),
PdbError::NoChainMapping(msg) => write!(f, "No chain mapping: {}", msg),
PdbError::NoInterfaceContacts(msg) => write!(f, "No interface contacts: {}", msg),
}
}
}
impl std::error::Error for PdbError {}
impl From<io::Error> for PdbError {
fn from(err: io::Error) -> Self {
PdbError::IoError(err)
}
}
impl From<ParseIntError> for PdbError {
fn from(err: ParseIntError) -> Self {
PdbError::ParseError(format!("Failed to parse integer: {}", err))
}
}
impl From<ParseFloatError> for PdbError {
fn from(err: ParseFloatError) -> Self {
PdbError::ParseError(format!("Failed to parse float: {}", err))
}
}