Commit 51ee583e authored by NOEL Philippe's avatar NOEL Philippe

Optimize read time

parent 1e2c1108
Pipeline #74822 failed with stages
in 2 minutes and 1 second
......@@ -14,6 +14,6 @@ pub use self::pdb::tools::*;
pub use self::pdb::write_pdb::write_pdb;
pub use self::pdb::atom::*;
pub use self::pdb::chain::Chain;
pub use self::pdb::chain::{Chain, ChainTypes};
pub use self::pdb::residue::Residue;
pub use self::pdb::structure::Structure;
......@@ -3,15 +3,15 @@ extern crate pdbparser;
use pdbparser::*;
fn main() {
let my_prot = read_pdb("tests/tests_file/f2.pdb", "5jpq");
match write_pdb(&my_prot, "toto.pdb") {
Ok(_) => (),
Err(e) => println!("Error : {}", e),
};
//let my_prot = read_pdb("tests/tests_file/f2.pdb", "5jpq");
//match write_pdb(&my_prot, "toto.pdb") {
// Ok(_) => (),
// Err(e) => println!("Error : {}", e),
//};
use pdbparser;
let my_prot = pdbparser::read_pdb("tests/tests_file/f2.pdb", "f2");
let my_prot = pdbparser::read_pdb("tests/tests_file/trp_MD.pdb", "5JPQ");
/*
let mut backbone = my_prot.select_atoms("backbone").unwrap();
let lst_atom_id = backbone.get_atom_index();
......
......@@ -8,6 +8,7 @@ use std::collections::HashMap;
pub struct Chain {
pub name: char,
pub lst_res: Vec<Residue>,
pub chain_type: ChainTypes,
}
impl Chain {
......@@ -18,13 +19,14 @@ impl Chain {
/// ````
/// use pdbparser;
///
/// let my_chain = pdbparser::Chain::new('a');
/// let my_chain = pdbparser::Chain::new('a', pdbparser::ChainTypes::Protein);
///
/// ````
pub fn new(name: char) -> Chain {
pub fn new(name: char, t: ChainTypes) -> Chain {
Chain {
name,
lst_res: Vec::new(),
chain_type: t,
}
}
......@@ -35,7 +37,7 @@ impl Chain {
/// ````
/// use pdbparser;
///
/// let mut my_chain = pdbparser::Chain::new('a');
/// let mut my_chain = pdbparser::Chain::new('a', pdbparser::ChainTypes::Protein);
/// let lys = pdbparser::Residue::new(String::from("lysine"), 1);
///
/// my_chain.add_res(lys);
......@@ -54,7 +56,7 @@ impl Chain {
/// ````
/// use pdbparser;
///
/// let my_chain = pdbparser::Chain::new('a');
/// let my_chain = pdbparser::Chain::new('a', pdbparser::ChainTypes::Protein);
///
/// assert_eq!(0, my_chain.get_number_residue());
///
......@@ -71,7 +73,7 @@ impl Chain {
/// ````
/// use pdbparser;
///
/// let mut my_chain = pdbparser::Chain::new('a');
/// let mut my_chain = pdbparser::Chain::new('a', pdbparser::ChainTypes::Protein);
/// let lys = pdbparser::Residue::new(String::from("lysine"), 1);
/// my_chain.add_res(lys);
///
......@@ -149,9 +151,9 @@ impl ChainTypes {
/// ````
/// use pdbparser::ChainTypes;
///
/// assert_eq!(ChainTypes::Protein, *ChainTypes::get("trp").unwrap());
/// assert_eq!(ChainTypes::Lipid, *ChainTypes::get("POPC").unwrap());
/// assert_eq!(None, ChainTypes::get("toto"));
/// assert_eq!(ChainTypes::Protein, ChainTypes::get("trp"));
/// assert_eq!(ChainTypes::Lipid, ChainTypes::get("POPC"));
/// assert_eq!(ChainTypes::Unknown, ChainTypes::get("toto"));
///
/// ````
pub fn get(atom: &str) -> ChainTypes {
......
......@@ -88,7 +88,6 @@ pub fn read_pdb(pdb: &str, name: &str) -> Structure {
atom_number as u64,
[x, y, z],
);
let chain_type = ChainTypes::get(&residue_name.to_uppercase()[..]);
}
}
structure
......
use super::atom::Atom;
use super::chain::Chain;
use super::chain::{Chain, ChainTypes};
use super::residue::Residue;
use super::selection_atom;
......@@ -55,7 +55,7 @@ impl Structure {
/// use pdbparser;
///
/// let mut my_struct = pdbparser::Structure::new(String::from("my_struct"));
/// let my_chain_a = pdbparser::Chain::new('a');
/// let my_chain_a = pdbparser::Chain::new('a', pdbparser::ChainTypes::Lipid);
///
/// my_struct.add_chain(my_chain_a);
///
......@@ -75,7 +75,7 @@ impl Structure {
/// use pdbparser;
///
/// let mut my_struct = pdbparser::Structure::new(String::from("my_struct"));
/// let my_chain_a = pdbparser::Chain::new('a');
/// let my_chain_a = pdbparser::Chain::new('a', pdbparser::ChainTypes::Protein);
/// my_struct.add_chain(my_chain_a);
///
/// assert!(my_struct.is_chain('a'));
......@@ -115,7 +115,7 @@ impl Structure {
/// use pdbparser;
///
/// let mut my_struct = pdbparser::Structure::new(String::from("my_struct"));
/// let mut my_chain = pdbparser::Chain::new('n');
/// let mut my_chain = pdbparser::Chain::new('n', pdbparser::ChainTypes::Protein);
/// let lys = pdbparser::Residue::new(String::from("lysine"), 1);
/// let pro = pdbparser::Residue::new(String::from("proline"), 2);
///
......@@ -192,7 +192,7 @@ impl Structure {
/// use pdbparser;
///
/// let mut my_struct = pdbparser::Structure::new(String::from("my_struct"));
/// my_struct.add_chain(pdbparser::Chain::new('n'));
/// my_struct.add_chain(pdbparser::Chain::new('n', pdbparser::ChainTypes::Protein));
/// assert_eq!('n', my_struct.chains[0].get_name());
/// {
/// let mut reference = my_struct.get_chain_ref('n').unwrap();
......@@ -212,6 +212,7 @@ impl Structure {
/// Function that add information on the [`Structure`] (used in the parsing)
/// /!\Change this to a macro!
///
#[warn(clippy::too_many_arguments)]
pub fn update_structure(
&mut self,
chain: char,
......@@ -226,7 +227,8 @@ impl Structure {
let chain = match self.get_chain_ref(chain) {
Some(c) => c,
None => {
self.add_chain(Chain::new(chain));
let chain_type = ChainTypes::get(&res_name.to_uppercase()[..]);
self.add_chain(Chain::new(chain, chain_type));
self.get_chain_ref(chain).unwrap()
}
};
......@@ -300,6 +302,7 @@ impl Structure {
};
for chain in &self.chains {
let c_chain = chain.name;
let chain_type = chain.chain_type;
for residue in &chain.lst_res {
let c_res = residue.res_num;
for atom in &residue.lst_atom {
......@@ -333,12 +336,12 @@ impl Structure {
/// assert_eq!(1, lst_atom_id[0]);
/// assert_eq!(5, lst_atom_id[1]);
///
/// backbone.refine_dialing();
/// backbone.refine_atom_numbering();
/// let lst_atom_id = backbone.get_atom_index();
/// assert_eq!(1, lst_atom_id[0]);
/// assert_eq!(2, lst_atom_id[1]);
/// ```
pub fn refine_dialing(&mut self) {
pub fn refine_atom_numbering(&mut self) {
let mut n_atom = 1;
for chain in &mut self.chains {
for residue in &mut chain.lst_res {
......
......@@ -12,17 +12,17 @@ fn parse_f2() {
#[test]
fn parse_f2_adn() {
let my_struct = pdbparser::read_pdb("tests/tests_file/f2_adn.pdb", "f2");
assert_eq!(1, my_struct.get_chain_number());
assert_eq!(66, my_struct.get_residue_number());
assert_eq!(5, my_struct.get_chain_number());
assert_eq!(8382, my_struct.get_residue_number());
assert_eq!(1085, my_struct.get_atom_number());
}
#[test]
fn parse_trp() {
let my_struct = pdbparser::read_pdb("tests/tests_file/trp_MD.pdb", "trp");
assert_eq!(1, my_struct.get_chain_number());
assert_eq!(704, my_struct.get_residue_number());
assert_eq!(10688, my_struct.get_atom_number());
assert_eq!(3, my_struct.get_chain_number());
assert_eq!(9970, my_struct.get_residue_number());
assert_eq!(396_109, my_struct.get_atom_number());
}
#[test]
......
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