Commit f20b7766 authored by NOEL Philippe's avatar NOEL Philippe

optimise parsing pdb

parent 09450558
......@@ -9,6 +9,6 @@ fn main() {
println!("Reduce protein");
let chain_a = my_prot.select_atoms("chain a").unwrap();
println!("Prot : {} \nn chain: {}\nn res: {}\nn atom: {}", chain_a.name, chain_a.get_number_chain(), chainA.get_number_residue(), chainA.get_number_atom());
println!("Prot : {} \nn chain: {}\nn res: {}\nn atom: {}", chain_a.name, chain_a.get_number_chain(), chain_a.get_number_residue(), chain_a.get_number_atom());
}
......@@ -78,15 +78,20 @@ pub fn parse_pdb(pdb: &str, name: &str) -> Protein {
for line in reader.lines() {
let l = line.unwrap();
if l.starts_with("HETAM") || l.starts_with("ATOM") {
let atom_name = &l[12..17].trim().to_string();
// First get the resname.
// If the "residue" is a protein residue, continue to parse the line and add informations to the protein
// else continue to the next one line
let residue_name = &l[17..20].trim();
let chain = l[21..22].chars().next().unwrap();
let atom_number = parse_int(&l[6..11].to_string());
let residue_number = parse_int(&l[22..26].to_string());
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());
if is_protein_res(residue_name, &lst_res) {
let atom_name = &l[12..17].trim().to_string();
let chain = l[21..22].chars().next().unwrap();
let atom_number = parse_int(&l[6..11].to_string());
let residue_number = parse_int(&l[22..26].to_string());
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());
// Add informations to the protein
protein.update_protein(chain, residue_name.to_string(), residue_number as u64, atom_name.clone(), atom_number as u64, [x, y, z]);
}
}
......
......@@ -38,12 +38,12 @@ fn f2_res() {
let mut my_prot = pdbparser::parse_pdb("tests/tests_file/f2.pdb", "f2");
let chain_a = my_prot.get_chain_ref('A').unwrap();
let res = chain_A.get_residue_ref(1).unwrap();
let res = chain_a.get_residue_ref(1).unwrap();
assert_eq!("THR", res.name());
let res = chain_A.get_residue_ref(2).unwrap();
let res = chain_a.get_residue_ref(2).unwrap();
assert_eq!("SER", res.name());
let res = chain_A.get_residue_ref(chain_A.get_number_residue()).unwrap();
let res = chain_a.get_residue_ref(chain_a.get_number_residue()).unwrap();
assert_eq!("HSD", res.name());
}
\ 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