diff --git a/src/lib.rs b/src/lib.rs index 39a60faf76b258d4188b0ce02a48e0c73d98f171..91dcd5abe3df5c1275faea2d3d2d48e3bf8d4e19 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,3 +1,8 @@ +//! # pdbparser +//! +//! `pdbparser` is a library to manipulate protein structure. It can parse, create and filter PDB files. +//! + mod pdb; pub use self::pdb::read_pdb::parse_pdb as parse_pdb; diff --git a/src/main.rs b/src/main.rs index 0cbcc05f38001e989eb1cf48170f5a4c53f8ed5b..332460bbe7ae3a050558754e7b12bb95201feec0 100644 --- a/src/main.rs +++ b/src/main.rs @@ -4,7 +4,7 @@ use pdbparser::*; fn main() { //let tutu = open_pdb_file("src/tests/f2_adn.pdb"); - let tutu = parse_pdb("src/tests_file/5jpq.pdb"); + let tutu = parse_pdb("src/tests_file/f2.pdb"); println!("Nb res : {}", tutu.get_number_residue()); println!("Nb chain : {}", tutu.get_number_chain()); } diff --git a/src/pdb/atom.rs b/src/pdb/atom.rs index ce83d01d56f54231bdacc3a50e37d9c97724069d..ff4ed1698afb0610ba1ee234ca1a64f8e889a34c 100644 --- a/src/pdb/atom.rs +++ b/src/pdb/atom.rs @@ -35,10 +35,10 @@ impl Atom { /// let h1 = pdbparser::Atom::new(String::from("HT1"), 1, [1.0, 5.0, 2.0]); /// let h2 = pdbparser::Atom::new(String::from("HT1"), 1, [11.0, 17.0, 5.0]); /// - /// assert_eq!(15.905973, h1.compute_distance(h2)); + /// assert_eq!(15.905973, h1.compute_distance(&h2)); /// /// ```` - pub fn compute_distance(&self, a: Atom) -> f32 { + pub fn compute_distance(&self, a: &Atom) -> f32 { ( (self.coord[0] - a.coord[0]).powi(2) + (self.coord[1] - a.coord[1]).powi(2) + diff --git a/src/pdb/protein.rs b/src/pdb/protein.rs index be05aa80a263f0ba1ae0fc6ab87d1c657c39f542..1e756585675904cc2d7a377bdd63060e27a08457 100644 --- a/src/pdb/protein.rs +++ b/src/pdb/protein.rs @@ -50,7 +50,7 @@ impl<'a> Protein { return true } } - return false + false } /// Return a mutable reference of a chaine with its name. Return None if the @@ -147,6 +147,27 @@ impl<'a> Protein { n } + /// Return the number of atom in the protein + /// + /// # Examples + /// + /// ```` + /// use pdbparser; + /// + /// let my_prot = pdbparser::parse_pdb("src/tests_file/f2.pdb"); + /// assert_eq!(1085, my_prot.get_number_atom()); + /// ```` + pub fn get_number_atom(&self) -> u64 { + let mut n: u64 = 0; + for chain in self.lst_chain.iter() { + for res in chain.lst_res.iter() { + for _ in res.lst_atom.iter() { + n += 1; + } + } + } + n + } /// Function that add information on the protein (used in the parsing) /// /!\Change this to a macro! diff --git a/src/pdb/read_pdb.rs b/src/pdb/read_pdb.rs index 360339c04c1282fddd30b1d64d299d27641e97a9..7978476ae640d25ce860abe07dbd82b0875378d4 100644 --- a/src/pdb/read_pdb.rs +++ b/src/pdb/read_pdb.rs @@ -4,9 +4,7 @@ use std::io::BufReader; use std::process; use super::protein::Protein; -use super::chain::Chain; -use super::residue::Residue; -use super::atom::Atom; + /// Parse the string to return a f32. The `trim` is used to remove /// /n and spaces. @@ -40,7 +38,14 @@ fn parse_int(s: &String) -> i64 { } } - +/// Parse the pdb file and return a protein structure +/// +/// # Examples +/// ``` +/// use pdbparser; +/// let my_prot = pdbparser::parse_pdb("src/tests_file/f2.pdb"); +/// assert_eq!(66, my_prot.get_number_residue()); +/// ``` pub fn parse_pdb(f: &str) -> Protein { // Check if the file exist and/or can be read @@ -66,7 +71,7 @@ pub fn parse_pdb(f: &str) -> Protein { let x = parse_float(&l[30..38].to_string()); let y = parse_float(&l[38..46].to_string()); let z = parse_float(&l[46..54].to_string()); - protein.update_protein(chain.clone(), residue_name.clone(), residue_number as u64, atom_name.clone(), atom_number as u64, [x, y, z]); + protein.update_protein(chain, residue_name.clone(), residue_number as u64, atom_name.clone(), atom_number as u64, [x, y, z]); } } protein diff --git a/src/tests/test.rs b/src/tests/test.rs deleted file mode 100644 index cd841a1d1182967f1f7e9d29e9e265c20c8bfae5..0000000000000000000000000000000000000000 --- a/src/tests/test.rs +++ /dev/null @@ -1,9 +0,0 @@ -extern crate pdbparser; - -use pdbparser::Atom; - -#[test] -fn test_atom() { - Atom::new(); - assert_eq!("rr", "rr"); -} \ No newline at end of file diff --git a/tests/test.rs b/tests/test.rs new file mode 100644 index 0000000000000000000000000000000000000000..38f4b2038c89fd699ef20bcf66818ca51e92ad66 --- /dev/null +++ b/tests/test.rs @@ -0,0 +1,11 @@ +extern crate pdbparser; + +#[test] +fn test_parse_f2() { + use pdbparser; + let my_prot = pdbparser::parse_pdb("src/tests_file/f2.pdb"); + assert_eq!(1, my_prot.get_number_chain()); + assert_eq!(66, my_prot.get_number_residue()); + assert_eq!(1085, my_prot.get_number_atom()); +} +