Commit 642b84c6 authored by NOEL Philippe's avatar NOEL Philippe

add get_number_atom for Protein

parent 26d47246
//! # 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;
......
......@@ -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());
}
......@@ -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!
......
......@@ -40,7 +40,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
......
extern crate pdbparser;
use pdbparser::Atom;
#[test]
fn test_atom() {
Atom::new();
assert_eq!("rr", "rr");
}
\ No newline at end of file
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());
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment