Commit 43b5b277 authored by NOEL Philippe's avatar NOEL Philippe

add support of hexa in atom number

parent 823247e7
......@@ -8,7 +8,7 @@ fn main() {
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();
//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());
......
......@@ -24,6 +24,8 @@ fn parse_float(s: &String) -> f32 {
/// Parse the string to return a i64. The `trim` is used to remove
/// /n and spaces.
/// In large PDB, atom number can be > 99,999.
/// In VMD, the atom number is in hexadecimal after 99,999
///
/// # Errors
/// Will return 0 if the String cannot be convert and print the error
......@@ -32,8 +34,13 @@ fn parse_int(s: &String) -> i64 {
match s.trim().parse::<i64>() {
Ok(n) => n,
Err(e) => {
println!("{}", e);
0
match i64::from_str_radix(s.trim(), 16) {
Ok(n) => return n,
Err(_) => {
println!("{}", e);
return 0
}
}
}
}
}
......@@ -48,6 +55,14 @@ fn parse_int(s: &String) -> i64 {
/// ```
pub fn parse_pdb(f: &str) -> Protein {
// Allocate here to avoid multiple allocation for every call
let lst_res = vec![
"ARG", "HIS", "HSE", "HSD", "LYS", "LYS", "ASP", "GLU", "SER", "THR", "ASN",
"GLN", "CYS", "SEC", "GLY", "PRO", "ALA", "VAL", "ILE", "LEU",
"MET", "PHE", "TYR", "TRP"
];
// Check if the file exist and/or can be read
let f = match File::open(f) {
Ok(f) => f,
......@@ -71,8 +86,22 @@ 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, residue_name.clone(), residue_number as u64, atom_name.clone(), atom_number as u64, [x, y, z]);
if is_protein_res(residue_name, &lst_res) {
protein.update_protein(chain, residue_name.clone(), residue_number as u64, atom_name.clone(), atom_number as u64, [x, y, z]);
}
}
}
protein
}
fn is_protein_res(r: &str, lst: &Vec<&str>) -> bool {
let r = r.to_uppercase();
for res in lst {
if r == *res {
return true
}
}
false
}
\ 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