residue.rs 1.82 KB
Newer Older
NOEL Philippe's avatar
NOEL Philippe committed
1 2
use super::atom::Atom;

3 4 5 6 7 8 9
/// A `Residue` is a sub-structure linked to a `Chain`.
/// It contain one or more `Atom`
/// It stores the following properties:
/// - res name;
/// - res number (resid);
/// - a list of atom(s)
/// 
NOEL Philippe's avatar
NOEL Philippe committed
10
#[derive(Debug)]
NOEL Philippe's avatar
NOEL Philippe committed
11
pub struct Residue {
12 13 14
    pub name: String,
    pub res_num: u64, 
    pub lst_atom: Vec<Atom>,
NOEL Philippe's avatar
NOEL Philippe committed
15 16
}

NOEL Philippe's avatar
NOEL Philippe committed
17
impl Residue {
18 19 20 21 22 23 24 25 26 27 28
    /// Create a new Residue structure with an empty list of atom.
    /// The Residue have a name and a number
    ///
    /// # Examples
    /// 
    /// ````
    /// use pdbparser;
    /// 
    /// let lys = pdbparser::Residue::new(String::from("lysine"), 1);
    /// 
    /// ````
29
    pub fn new(name: String, res_num: u64) -> Residue {
NOEL Philippe's avatar
NOEL Philippe committed
30 31
        Residue {
            name,
NOEL Philippe's avatar
NOEL Philippe committed
32
            res_num, 
NOEL Philippe's avatar
NOEL Philippe committed
33 34 35
            lst_atom: Vec::new(),
        }
    }
NOEL Philippe's avatar
NOEL Philippe committed
36

NOEL Philippe's avatar
NOEL Philippe committed
37 38 39 40 41 42
    /// Get the name of the residue
    /// 
    pub fn name(&self) -> String {
        self.name.clone()
    }

43
    /// Get the number of the residue
NOEL Philippe's avatar
NOEL Philippe committed
44
    /// 
NOEL Philippe's avatar
NOEL Philippe committed
45 46
    pub fn get_res_num(&self) -> u64 {
        self.res_num
NOEL Philippe's avatar
NOEL Philippe committed
47
    }
48

49 50 51 52 53 54 55 56 57 58 59
    /// Get the number of Atom in the Residue
    ///
    /// # Examples
    /// 
    /// ````
    /// use pdbparser;
    /// 
    /// let lys = pdbparser::Residue::new(String::from("lysine"), 1);
    /// assert_eq!(0, lys.get_number_atom());
    /// 
    /// ````
60 61 62
    pub fn get_number_atom(&self) -> u64 {
        self.lst_atom.len() as u64
    }
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80

    /// Add an Atom structure to the Residue
    ///
    /// # Examples
    /// 
    /// ````
    /// use pdbparser;
    /// 
    /// let mut lys = pdbparser::Residue::new(String::from("lysine"), 1);
    /// let carbon = pdbparser::Atom::new(String::from("HT1"), 1, [0.0, 0.0, 0.0]);
    /// 
    /// lys.add_atom(carbon);
    /// 
    /// assert_eq!(1, lys.get_number_atom());
    /// 
    /// ````    
    pub fn add_atom(&mut self, a: Atom) {
        self.lst_atom.push(a);
NOEL Philippe's avatar
NOEL Philippe committed
81 82 83
    }

}