#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub enum SS {
AlphaHelix,
Helix310,
PiHelix,
PolyProline,
BetaSheet,
BetaBridge,
Turn,
Bend,
#[default]
Coil,
Break,
}
impl SS {
pub fn to_char(self) -> char {
match self {
SS::AlphaHelix => 'H',
SS::Helix310 => 'G',
SS::PiHelix => 'I',
SS::PolyProline => 'P',
SS::BetaSheet => 'E',
SS::BetaBridge => 'B',
SS::Turn => 'T',
SS::Bend => 'S',
SS::Coil => '~',
SS::Break => '=',
}
}
pub fn from_char(c: char) -> Option<Self> {
Some(match c {
'H' => SS::AlphaHelix,
'G' => SS::Helix310,
'I' => SS::PiHelix,
'P' => SS::PolyProline,
'E' => SS::BetaSheet,
'B' => SS::BetaBridge,
'T' => SS::Turn,
'S' => SS::Bend,
'~' | 'C' => SS::Coil,
'=' => SS::Break,
_ => return None,
})
}
pub(crate) fn priority(self) -> u8 {
match self {
SS::Break => 255,
SS::AlphaHelix => 8,
SS::BetaBridge => 7,
SS::BetaSheet => 6,
SS::Helix310 => 5,
SS::PiHelix => 4,
SS::Turn => 3,
SS::Bend => 2,
SS::PolyProline => 1,
SS::Coil => 0,
}
}
pub(crate) fn try_assign(&mut self, new: SS) {
if new.priority() > self.priority() {
*self = new;
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub enum SsAlgorithm {
#[default]
Dssp,
DsspGmx,
Dss,
}
impl SsAlgorithm {
pub fn as_str(self) -> &'static str {
match self {
SsAlgorithm::Dssp => "dssp",
SsAlgorithm::DsspGmx => "dssp_gmx",
SsAlgorithm::Dss => "dss",
}
}
}
impl std::fmt::Display for SsAlgorithm {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.write_str(self.as_str())
}
}
impl std::str::FromStr for SsAlgorithm {
type Err = String;
fn from_str(s: &str) -> Result<Self, Self::Err> {
match s.trim().to_ascii_lowercase().as_str() {
"dssp" | "vanilla" => Ok(SsAlgorithm::Dssp),
"dssp_gmx" | "dssp-gmx" | "gmx" => Ok(SsAlgorithm::DsspGmx),
"dss" | "pymol" => Ok(SsAlgorithm::Dss),
other => Err(format!(
"unknown SS algorithm '{other}' (expected dssp|dssp_gmx|dss)"
)),
}
}
}
pub struct SsResult {
ss: Vec<SS>,
}
impl SsResult {
pub(crate) fn new(ss: Vec<SS>) -> Self {
Self { ss }
}
pub fn ss(&self) -> &[SS] {
&self.ss
}
pub fn ss_string(&self) -> String {
self.ss.iter().map(|s| s.to_char()).collect()
}
pub fn len(&self) -> usize {
self.ss.len()
}
pub fn is_empty(&self) -> bool {
self.ss.is_empty()
}
pub fn into_vec(self) -> Vec<SS> {
self.ss
}
}