Commit 7ec7b2b7 authored by NOEL Philippe's avatar NOEL Philippe

add backbone selection

parent 1c36fb34
...@@ -6,7 +6,11 @@ fn main() { ...@@ -6,7 +6,11 @@ fn main() {
let toto = parse_pdb("src/tests_file/f2_adn.pdb"); let toto = parse_pdb("src/tests_file/f2_adn.pdb");
println!("Nb res : {}", toto.get_number_residue()); println!("Nb res : {}", toto.get_number_residue());
println!("Nb chain : {}", toto.get_number_chain()); println!("Nb chain : {}", toto.get_number_chain());
let toto_A = toto.select_atoms("Chain A"); println!("Nb atom : {}", toto.get_atom_index().len());
let toto_A = toto.select_atoms("chain A");
let toto_A = toto_A.select_atoms("backbone");
println!("Nb res : {}", toto_A.get_number_residue()); println!("Nb res : {}", toto_A.get_number_residue());
println!("Nb chain : {}", toto_A.get_number_chain()); println!("Nb chain : {}", toto_A.get_number_chain());
println!("Nb atom : {}", toto_A.get_atom_index().len());
println!("Nb atom : {:?}", toto_A.get_atom_index());
} }
use std::ops::Deref;
#[derive(Debug)] #[derive(Debug)]
pub struct Atom { pub struct Atom {
pub name: String, pub name: String,
pub number: u64, pub number: u64,
pub coord: [f32; 3], pub coord: [f32; 3],
pub is_backbone: bool,
} }
impl Atom { impl Atom {
...@@ -18,10 +21,17 @@ impl Atom { ...@@ -18,10 +21,17 @@ impl Atom {
/// ///
/// ```` /// ````
pub fn new(name: String, number: u64, coord: [f32; 3]) -> 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
};
Atom { Atom {
name, name,
number, number,
coord, coord,
is_backbone: back,
} }
} }
......
...@@ -265,7 +265,7 @@ impl<'a> Protein { ...@@ -265,7 +265,7 @@ impl<'a> Protein {
for residue in &chain.lst_res { for residue in &chain.lst_res {
let c_res = residue.res_num; let c_res = residue.res_num;
for atom in &residue.lst_atom { for atom in &residue.lst_atom {
if selection_atom::atom_match(&select, c_chain, c_res) { if selection_atom::atom_match(&select, c_chain, c_res, atom.is_backbone) {
n_prot.update_protein(c_chain, residue.name.clone(), c_res, atom.name.clone(), atom.number, atom.coord); n_prot.update_protein(c_chain, residue.name.clone(), c_res, atom.name.clone(), atom.number, atom.coord);
} }
} }
......
...@@ -91,7 +91,7 @@ pub fn parse_select(select: &str) -> Option<Select> { ...@@ -91,7 +91,7 @@ pub fn parse_select(select: &str) -> Option<Select> {
} }
} }
pub fn atom_match(sel: &Select, chain: char, res_id: u64) -> bool { pub fn atom_match(sel: &Select, chain: char, res_id: u64, back: bool) -> bool {
match sel { match sel {
Select::Chain(x, y) => { Select::Chain(x, y) => {
if chain >= *x && chain <= *y { if chain >= *x && chain <= *y {
...@@ -101,7 +101,11 @@ pub fn atom_match(sel: &Select, chain: char, res_id: u64) -> bool { ...@@ -101,7 +101,11 @@ pub fn atom_match(sel: &Select, chain: char, res_id: u64) -> bool {
} }
}, },
Select::Backbone => { Select::Backbone => {
return false if back {
return true
} else {
return false
}
}, },
Select::Resid(x, y) => { Select::Resid(x, y) => {
if res_id as usize >= *x && res_id as usize <= *y { if res_id as usize >= *x && res_id as usize <= *y {
...@@ -126,17 +130,17 @@ fn test_parse_select() { ...@@ -126,17 +130,17 @@ fn test_parse_select() {
#[test] #[test]
fn test_atom_search_Chain() { fn test_atom_search_Chain() {
assert!(atom_match(&Select::Chain('B', 'C'), 'C', 15)); assert!(atom_match(&Select::Chain('B', 'C'), 'C', 15, true));
assert!(!atom_match(&Select::Chain('A', 'B'), 'C', 15)); assert!(!atom_match(&Select::Chain('A', 'B'), 'C', 15, true));
assert!(atom_match(&Select::Chain('1', '4'), '2', 15)); assert!(atom_match(&Select::Chain('1', '4'), '2', 15, true));
//assert!(atom_match(&Select::Chain('A', '9'), '2', 15)); //assert!(atom_match(&Select::Chain('A', '9'), '2', 15));
assert!(atom_match(&Select::Chain('A', 'a'), 'Z', 15)); assert!(atom_match(&Select::Chain('A', 'a'), 'Z', 15, true));
assert!(!atom_match(&Select::Chain('A', 'a'), 'd', 15)); assert!(!atom_match(&Select::Chain('A', 'a'), 'd', 15, true));
} }
#[test] #[test]
fn test_atom_search_resid() { fn test_atom_search_resid() {
assert!(atom_match(&Select::Resid(1, 105), 'A', 15)); assert!(atom_match(&Select::Resid(1, 105), 'A', 15, true));
assert!(!atom_match(&Select::Resid(1, 105), 'A', 0)); assert!(!atom_match(&Select::Resid(1, 105), 'A', 0, true));
assert!(atom_match(&Select::Resid(1, 105), 'A', 105)); assert!(atom_match(&Select::Resid(1, 105), 'A', 105, true));
} }
\ 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