Commit 98da9fc3 authored by NOEL Philippe's avatar NOEL Philippe

clean repo and add globale doc

parent 43b5b277
/target /target
**/*.rs.bk **/*.rs.bk
Cargo.lock Cargo.lock
.vscode
.idea
\ No newline at end of file
//! # pdbparser //! # pdbparser
//! //!
//! `pdbparser` is a library to manipulate protein structure. It can parse, create and filter PDB files. //! `pdbparser` is a library to manipulate protein structure. It can parse, and filter PDB files.
//! You can create a protein structure by parsing with parse_pdb function. Then you can add filters on your protein.
//! //!
mod pdb; mod pdb;
......
...@@ -3,17 +3,12 @@ extern crate pdbparser; ...@@ -3,17 +3,12 @@ extern crate pdbparser;
use pdbparser::*; use pdbparser::*;
fn main() { fn main() {
let toto = parse_pdb("src/tests_file/f2.pdb"); let my_prot = parse_pdb("tests/tests_file/5jpq.pdb", "5jpq");
println!("Nb res : {}", toto.get_number_residue());
println!("Nb chain : {}", toto.get_number_chain()); 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!("Nb atom : {}", toto.get_atom_index().len()); println!("Reduce protein");
let toto_A = toto.select_atoms("chain A").unwrap();
//let toto_A = toto_A.select_atoms("backbone").unwrap(); let chainA = my_prot.select_atoms("chain a").unwrap();
println!("Nb res : {}", toto_A.get_number_residue()); println!("Prot : {} \nn chain: {}\nn res: {}\nn atom: {}", chainA.name, chainA.get_number_chain(), chainA.get_number_residue(), chainA.get_number_atom());
println!("Nb chain : {}", toto_A.get_number_chain());
println!("Nb atom : {}", toto_A.get_atom_index().len());
let toto_A_b = toto.select_atoms("resid 10 to 50 and backbone").unwrap();
println!("Nb res : {}", toto_A_b.get_number_residue());
println!("Nb chain : {}", toto_A_b.get_number_chain());
println!("Nb atom : {}", toto_A_b.get_atom_index().len());
} }
use std::ops::Deref; use std::ops::Deref;
/// An `Atom` is a sub-structure linked to a `Residue`.
/// It stores the following properties:
/// - atom name;
/// - atom number (atomid);
/// - Coordinates x, y and z
/// - if the atom is a constituant of the backbone of the protein
///
#[derive(Debug)] #[derive(Debug)]
pub struct Atom { pub struct Atom {
pub name: String, pub name: String,
...@@ -9,7 +16,6 @@ pub struct Atom { ...@@ -9,7 +16,6 @@ pub struct Atom {
} }
impl Atom { impl Atom {
/// Create a new structure Atom. An atom have a name, a number and x, y, z coordinates /// Create a new structure Atom. An atom have a name, a number and x, y, z coordinates
/// ///
/// # Examples /// # Examples
......
use super::residue::Residue; use super::residue::Residue;
/// A `Chain` is a sub-structure linked to a `Protein`.
/// It contain one or more `Residue` and a name
///
#[derive(Debug)] #[derive(Debug)]
pub struct Chain { pub struct Chain {
pub name: char, pub name: char,
......
...@@ -6,7 +6,9 @@ use super::selection_atom; ...@@ -6,7 +6,9 @@ use super::selection_atom;
use std::char; use std::char;
/// A `Protein` is a struct extract from PDB file. It store `Chain` structure(s)
///
/// The `Protein` is the main structure to manipulate
#[derive(Debug)] #[derive(Debug)]
pub struct Protein { pub struct Protein {
pub name: String, pub name: String,
...@@ -34,6 +36,22 @@ impl<'a> Protein { ...@@ -34,6 +36,22 @@ impl<'a> Protein {
} }
} }
/// Get the name of the protein
///
/// # Examples
///
/// ````
/// use pdbparser;
///
/// let my_prot = pdbparser::Protein::new(String::from("my_prot"));
///
/// assert_eq!("my_prot", my_prot.name());
///
/// ````
pub fn name(&self) -> &str {
&self.name
}
/// Return True if the chain is in the protein /// Return True if the chain is in the protein
/// ///
/// # Examples /// # Examples
...@@ -112,10 +130,8 @@ impl<'a> Protein { ...@@ -112,10 +130,8 @@ impl<'a> Protein {
/// ///
/// my_chain.add_res(lys); /// my_chain.add_res(lys);
/// my_chain.add_res(pro); /// my_chain.add_res(pro);
///
/// my_prot.add_chain(my_chain); /// my_prot.add_chain(my_chain);
/// ///
///
/// assert_eq!(2, my_prot.get_number_residue()); /// assert_eq!(2, my_prot.get_number_residue());
/// ///
/// ```` /// ````
...@@ -136,7 +152,7 @@ impl<'a> Protein { ...@@ -136,7 +152,7 @@ impl<'a> Protein {
/// ```` /// ````
/// use pdbparser; /// use pdbparser;
/// ///
/// let my_prot = pdbparser::parse_pdb("src/tests_file/f2.pdb"); /// let my_prot = pdbparser::parse_pdb("tests/tests_file/f2.pdb", "f2");
/// assert_eq!(1085, my_prot.get_number_atom()); /// assert_eq!(1085, my_prot.get_number_atom());
/// ```` /// ````
pub fn get_number_atom(&self) -> u64 { pub fn get_number_atom(&self) -> u64 {
...@@ -201,18 +217,17 @@ impl<'a> Protein { ...@@ -201,18 +217,17 @@ impl<'a> Protein {
} }
/// function that return a vector for atom index /// function that return a vector for atom index
/// Can be used in other program like rrmsd_map to select specific atom /// Can be used in other program like rrmsd_map to select specific atoms
/// ///
/// # Examples /// # Examples
/// ``` /// ```
/// use pdbparser; /// use pdbparser;
/// ///
/// let my_prot = pdbparser::parse_pdb("src/tests_file/f2_adn.pdb"); /// let my_prot = pdbparser::parse_pdb("tests/tests_file/f2_adn.pdb", "f2");
/// let atom_index = my_prot.get_atom_index(); /// let atom_index = my_prot.get_atom_index();
/// ///
/// assert_eq!(atom_index[0], 1); /// assert_eq!(atom_index[0], 1);
/// assert_eq!(atom_index[1], 2); /// assert_eq!(atom_index[1], 2);
///
/// ``` /// ```
pub fn get_atom_index(&self) -> Vec<u64> { pub fn get_atom_index(&self) -> Vec<u64> {
let mut lst: Vec<u64> = Vec::new(); let mut lst: Vec<u64> = Vec::new();
...@@ -257,7 +272,7 @@ impl<'a> Protein { ...@@ -257,7 +272,7 @@ impl<'a> Protein {
/// ``` /// ```
/// use pdbparser; /// use pdbparser;
/// ///
/// let my_prot = pdbparser::parse_pdb("src/tests_file/f2.pdb"); /// let my_prot = pdbparser::parse_pdb("tests/tests_file/f2.pdb", "f2");
/// ///
/// assert_eq!(66, my_prot.get_number_residue()); /// assert_eq!(66, my_prot.get_number_residue());
/// assert_eq!(1085, my_prot.get_number_atom()); /// assert_eq!(1085, my_prot.get_number_atom());
......
...@@ -50,10 +50,10 @@ fn parse_int(s: &String) -> i64 { ...@@ -50,10 +50,10 @@ fn parse_int(s: &String) -> i64 {
/// # Examples /// # Examples
/// ``` /// ```
/// use pdbparser; /// use pdbparser;
/// let my_prot = pdbparser::parse_pdb("src/tests_file/f2.pdb"); /// let my_prot = pdbparser::parse_pdb("tests/tests_file/f2.pdb", "f2");
/// assert_eq!(66, my_prot.get_number_residue()); /// assert_eq!(66, my_prot.get_number_residue());
/// ``` /// ```
pub fn parse_pdb(f: &str) -> Protein { pub fn parse_pdb(pdb: &str, name: &str) -> Protein {
// Allocate here to avoid multiple allocation for every call // Allocate here to avoid multiple allocation for every call
...@@ -64,16 +64,16 @@ pub fn parse_pdb(f: &str) -> Protein { ...@@ -64,16 +64,16 @@ pub fn parse_pdb(f: &str) -> Protein {
]; ];
// Check if the file exist and/or can be read // Check if the file exist and/or can be read
let f = match File::open(f) { let pdb = match File::open(pdb) {
Ok(f) => f, Ok(f) => f,
Err(e) => { Err(e) => {
println!("Could not open the file \"{}\"\nError: {}", f, e); println!("Could not open the file \"{}\"\nError: {}", pdb, e);
process::exit(1); process::exit(1);
} }
}; };
let reader = BufReader::new(f); let reader = BufReader::new(pdb);
let mut protein = Protein::new("4CIJ".to_string()); let mut protein = Protein::new(name.to_string());
for line in reader.lines() { for line in reader.lines() {
let l = line.unwrap(); let l = line.unwrap();
......
use super::atom::Atom; use super::atom::Atom;
/// 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)
///
#[derive(Debug)] #[derive(Debug)]
pub struct Residue { pub struct Residue {
pub name: String, pub name: String,
......
This diff is collapsed.
File deleted
extern crate pdbparser; extern crate pdbparser;
#[test] #[test]
fn test_parse_f2() { fn parse_f2() {
use pdbparser; use pdbparser;
let my_prot = pdbparser::parse_pdb("src/tests_file/f2.pdb"); let my_prot = pdbparser::parse_pdb("tests/tests_file/f2.pdb", "f2");
assert_eq!(1, my_prot.get_number_chain()); assert_eq!(1, my_prot.get_number_chain());
assert_eq!(66, my_prot.get_number_residue()); assert_eq!(66, my_prot.get_number_residue());
assert_eq!(1085, my_prot.get_number_atom()); assert_eq!(1085, my_prot.get_number_atom());
} }
#[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());
assert_eq!(1085, my_prot.get_number_atom());
}
#[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());
assert_eq!(10688, my_prot.get_number_atom());
}
#[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());
}
\ No newline at end of file
This diff is collapsed.
Command being timed: "target/release/pdbparser"
User time (seconds): 0.45
System time (seconds): 0.00
Percent of CPU this job got: 99%
Elapsed (wall clock) time (h:mm:ss or m:ss): 0:00.45
Average shared text size (kbytes): 0
Average unshared data size (kbytes): 0
Average stack size (kbytes): 0
Average total size (kbytes): 0
Maximum resident set size (kbytes): 7352
Average resident set size (kbytes): 0
Major (requiring I/O) page faults: 0
Minor (reclaiming a frame) page faults: 1363
Voluntary context switches: 1
Involuntary context switches: 92
Swaps: 0
File system inputs: 0
File system outputs: 0
Socket messages sent: 0
Socket messages received: 0
Signals delivered: 0
Page size (bytes): 4096
Exit status: 0
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