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

clean repo and add globale doc

parent 43b5b277
/target
**/*.rs.bk
Cargo.lock
.vscode
.idea
\ No newline at end of file
//! # 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;
......
......@@ -3,17 +3,12 @@ extern crate pdbparser;
use pdbparser::*;
fn main() {
let toto = parse_pdb("src/tests_file/f2.pdb");
println!("Nb res : {}", toto.get_number_residue());
println!("Nb chain : {}", toto.get_number_chain());
println!("Nb atom : {}", toto.get_atom_index().len());
let toto_A = toto.select_atoms("chain A").unwrap();
//let toto_A = toto_A.select_atoms("backbone").unwrap();
println!("Nb res : {}", toto_A.get_number_residue());
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());
let my_prot = parse_pdb("tests/tests_file/5jpq.pdb", "5jpq");
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());
}
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)]
pub struct Atom {
pub name: String,
......@@ -9,7 +16,6 @@ pub struct Atom {
}
impl Atom {
/// Create a new structure Atom. An atom have a name, a number and x, y, z coordinates
///
/// # Examples
......
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)]
pub struct Chain {
pub name: char,
......
......@@ -6,7 +6,9 @@ use super::selection_atom;
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)]
pub struct Protein {
pub name: String,
......@@ -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
///
/// # Examples
......@@ -112,10 +130,8 @@ impl<'a> Protein {
///
/// my_chain.add_res(lys);
/// my_chain.add_res(pro);
///
/// my_prot.add_chain(my_chain);
///
///
/// assert_eq!(2, my_prot.get_number_residue());
///
/// ````
......@@ -136,7 +152,7 @@ impl<'a> Protein {
/// ````
/// 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());
/// ````
pub fn get_number_atom(&self) -> u64 {
......@@ -201,18 +217,17 @@ impl<'a> Protein {
}
/// 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
/// ```
/// 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();
///
/// assert_eq!(atom_index[0], 1);
/// assert_eq!(atom_index[1], 2);
///
/// ```
pub fn get_atom_index(&self) -> Vec<u64> {
let mut lst: Vec<u64> = Vec::new();
......@@ -257,7 +272,7 @@ impl<'a> Protein {
/// ```
/// 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!(1085, my_prot.get_number_atom());
......
......@@ -50,10 +50,10 @@ fn parse_int(s: &String) -> i64 {
/// # Examples
/// ```
/// 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());
/// ```
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
......@@ -64,16 +64,16 @@ pub fn parse_pdb(f: &str) -> Protein {
];
// 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,
Err(e) => {
println!("Could not open the file \"{}\"\nError: {}", f, e);
println!("Could not open the file \"{}\"\nError: {}", pdb, e);
process::exit(1);
}
};
let reader = BufReader::new(f);
let mut protein = Protein::new("4CIJ".to_string());
let reader = BufReader::new(pdb);
let mut protein = Protein::new(name.to_string());
for line in reader.lines() {
let l = line.unwrap();
......
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)]
pub struct Residue {
pub name: String,
......
This diff is collapsed.
File deleted
extern crate pdbparser;
#[test]
fn test_parse_f2() {
fn parse_f2() {
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!(66, my_prot.get_number_residue());
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