Commit 289c78fd authored by NOEL Philippe's avatar NOEL Philippe

Merge branch 'master' of gitlab.inria.fr:pnoel/pdbparser

parents 52586cce f5832f27
//! # 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());
}
......@@ -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) +
......
......@@ -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!
......
......@@ -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
......
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