knuckles_parse/records/
modres.rs1#[cfg(feature = "serde")]
2use serde::{Deserialize, Serialize};
3
4#[cfg(feature = "python")]
5use pyo3::prelude::*;
6
7#[cfg(feature = "python")]
8use knuckles_macro::pydefault;
9
10#[derive(Debug, Clone)]
11#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
12#[cfg_attr(feature = "python", pyclass(get_all, set_all))]
13#[cfg_attr(feature = "python", pydefault)]
14pub struct ModresRecord {
15 pub id_code: String,
16 pub res_name: String,
17 pub chain_id: char,
18 pub seq_num: i16,
19 pub i_code: Option<char>,
20 pub std_res_name: String,
21 pub comment: String,
22}
23
24impl ModresRecord {
25 pub fn new(str: &str) -> ModresRecord {
26 ModresRecord::from(str)
27 }
28
29 pub fn from(line: &str) -> Self {
30 Self {
31 id_code: line[7..11].trim().to_string(),
32 res_name: line[12..15].trim().to_string(),
33 chain_id: line.chars().nth(16).unwrap(),
34 seq_num: line[18..22].trim().parse().unwrap(),
35 i_code: line[22..23].trim().parse().ok(),
36 std_res_name: line[24..27].trim().to_string(),
37 comment: line[29..].trim().to_string(),
38 }
39 }
40}
41
42impl From<&str> for ModresRecord {
43 fn from(line: &str) -> Self {
44 Self::from(line)
45 }
46}