Commit 09450558 authored by NOEL Philippe's avatar NOEL Philippe

Add doc in atom

parent 98da9fc3
......@@ -8,7 +8,7 @@ fn main() {
println!("Prot : {} \nn chain: {}\nn res: {}\nn atom: {}", my_prot.name, my_prot.get_number_chain(), my_prot.get_number_residue(), my_prot.get_number_atom());
println!("Reduce protein");
let chainA = my_prot.select_atoms("chain a").unwrap();
println!("Prot : {} \nn chain: {}\nn res: {}\nn atom: {}", chainA.name, chainA.get_number_chain(), chainA.get_number_residue(), chainA.get_number_atom());
let chain_a = my_prot.select_atoms("chain a").unwrap();
println!("Prot : {} \nn chain: {}\nn res: {}\nn atom: {}", chain_a.name, chain_a.get_number_chain(), chainA.get_number_residue(), chainA.get_number_atom());
}
......@@ -17,6 +17,7 @@ pub struct Atom {
impl Atom {
/// Create a new structure Atom. An atom have a name, a number and x, y, z coordinates
/// If the atom name is "C", "CA", "N", "O", "OT1" or "OT2", it will be consider as backbone
///
/// # Examples
///
......@@ -28,11 +29,7 @@ impl Atom {
/// ````
pub fn new(name: String, number: u64, coord: [f32; 3]) -> Atom {
let n = name.deref();
let back = if n == "C" || n == "CA" || n == "N" || n == "O" || n == "OT1" || n == "OT2" {
true
} else {
false
};
let back = n == "C" || n == "CA" || n == "N" || n == "O" || n == "OT1" || n == "OT2";
Atom {
name,
number,
......@@ -41,6 +38,12 @@ impl Atom {
}
}
/// Get the name of the atom
///
pub fn name(self) -> String{
self.name.clone()
}
/// Compute the distance between 2 Atoms
///
/// # Examples
......
......@@ -286,7 +286,7 @@ impl<'a> Protein {
// ex: don't parse the chain if it's not selected
pub fn select_atoms(&self, pattern: &str) -> Option<Protein> {
let mut n_prot = Protein::new(String::from(self.name.clone()));
let mut n_prot = Protein::new(self.name.clone());
let select = match selection_atom::parse_select(&pattern) {
Some(x) => x,
......
......@@ -12,7 +12,7 @@ use super::protein::Protein;
/// # Errors
/// Will return 0.0 if the String cannot be convert and print the error
///
fn parse_float(s: &String) -> f32 {
fn parse_float(s: &str) -> f32 {
match s.trim().parse::<f32>() {
Ok(n) => n,
Err(e) => {
......@@ -30,15 +30,15 @@ fn parse_float(s: &String) -> f32 {
/// # Errors
/// Will return 0 if the String cannot be convert and print the error
///
fn parse_int(s: &String) -> i64 {
fn parse_int(s: &str) -> i64 {
match s.trim().parse::<i64>() {
Ok(n) => n,
Err(e) => {
match i64::from_str_radix(s.trim(), 16) {
Ok(n) => return n,
Ok(n) => n,
Err(_) => {
println!("{}", e);
return 0
0
}
}
}
......@@ -79,7 +79,7 @@ pub fn parse_pdb(pdb: &str, name: &str) -> Protein {
let l = line.unwrap();
if l.starts_with("HETAM") || l.starts_with("ATOM") {
let atom_name = &l[12..17].trim().to_string();
let residue_name = &l[17..20].trim().to_string();
let residue_name = &l[17..20].trim();
let chain = l[21..22].chars().next().unwrap();
let atom_number = parse_int(&l[6..11].to_string());
let residue_number = parse_int(&l[22..26].to_string());
......@@ -87,14 +87,15 @@ pub fn parse_pdb(pdb: &str, name: &str) -> Protein {
let y = parse_float(&l[38..46].to_string());
let z = parse_float(&l[46..54].to_string());
if is_protein_res(residue_name, &lst_res) {
protein.update_protein(chain, residue_name.clone(), residue_number as u64, atom_name.clone(), atom_number as u64, [x, y, z]);
protein.update_protein(chain, residue_name.to_string(), residue_number as u64, atom_name.clone(), atom_number as u64, [x, y, z]);
}
}
}
protein
}
fn is_protein_res(r: &str, lst: &Vec<&str>) -> bool {
/// Test if the selected line is a residue
///
fn is_protein_res(r: &str, lst: &[&str]) -> bool {
let r = r.to_uppercase();
......
......@@ -34,7 +34,14 @@ impl Residue {
}
}
/// Get the name of the residue
///
pub fn name(&self) -> String {
self.name.clone()
}
/// Get the number of the residue
///
pub fn get_res_num(&self) -> u64 {
self.res_num
}
......
......@@ -2,8 +2,8 @@ extern crate pdbparser;
#[test]
fn parse_f2() {
use pdbparser;
let my_prot = pdbparser::parse_pdb("tests/tests_file/f2.pdb", "f2");
assert_eq!("f2", my_prot.name());
assert_eq!(1, my_prot.get_number_chain());
assert_eq!(66, my_prot.get_number_residue());
assert_eq!(1085, my_prot.get_number_atom());
......@@ -11,7 +11,6 @@ fn parse_f2() {
#[test]
fn parse_f2_adn() {
use pdbparser;
let my_prot = pdbparser::parse_pdb("tests/tests_file/f2_adn.pdb", "f2");
assert_eq!(1, my_prot.get_number_chain());
assert_eq!(66, my_prot.get_number_residue());
......@@ -20,7 +19,6 @@ fn parse_f2_adn() {
#[test]
fn parse_trp() {
use pdbparser;
let my_prot = pdbparser::parse_pdb("tests/tests_file/trp_MD.pdb", "trp");
assert_eq!(1, my_prot.get_number_chain());
assert_eq!(704, my_prot.get_number_residue());
......@@ -29,9 +27,23 @@ fn parse_trp() {
#[test]
fn parse_5jpq() {
use pdbparser;
let my_prot = pdbparser::parse_pdb("tests/tests_file/5jpq.pdb", "5jpq");
assert_eq!(35, my_prot.get_number_chain());
assert_eq!(8173, my_prot.get_number_residue());
assert_eq!(44801, my_prot.get_number_atom());
}
#[test]
fn f2_res() {
let mut my_prot = pdbparser::parse_pdb("tests/tests_file/f2.pdb", "f2");
let chain_a = my_prot.get_chain_ref('A').unwrap();
let res = chain_A.get_residue_ref(1).unwrap();
assert_eq!("THR", res.name());
let res = chain_A.get_residue_ref(2).unwrap();
assert_eq!("SER", res.name());
let res = chain_A.get_residue_ref(chain_A.get_number_residue()).unwrap();
assert_eq!("HSD", res.name());
}
\ No newline at end of file
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