Commit 1e2c1108 authored by NOEL Philippe's avatar NOEL Philippe

Add ChainType in read_pdb

parent a9d6a938
use std::collections::HashMap;
use std::ops::Deref;
/// An [`Atom`] is a sub-structure linked to a [`Residue`].
......@@ -66,102 +65,3 @@ impl Atom {
}
}
/// Enumerate to check the types of the parsed atom.
///
/// [`Atom`] will be class into the following map:
/// "ARG" => AtomTypes::AminoAcid
/// "LYS" => AtomTypes::AminoAcid
/// "ASN" => AtomTypes::AminoAcid
/// "ASP" => AtomTypes::AminoAcid
/// "GLU" => AtomTypes::AminoAcid
/// "SER" => AtomTypes::AminoAcid
/// "THR" => AtomTypes::AminoAcid
/// "GLN" => AtomTypes::AminoAcid
/// "CYS" => AtomTypes::AminoAcid
/// "HIS" => AtomTypes::AminoAcid
/// "HSD" => AtomTypes::AminoAcid
/// "HSP" => AtomTypes::AminoAcid
/// "HSD" => AtomTypes::AminoAcid
/// "SEC" => AtomTypes::AminoAcid
/// "GLY" => AtomTypes::AminoAcid
/// "PRO" => AtomTypes::AminoAcid
/// "ALA" => AtomTypes::AminoAcid
/// "VAL" => AtomTypes::AminoAcid
/// "ILE" => AtomTypes::AminoAcid
/// "LEU" => AtomTypes::AminoAcid
/// "MET" => AtomTypes::AminoAcid
/// "PHE" => AtomTypes::AminoAcid
/// "TYR" => AtomTypes::AminoAcid
/// "TRP" => AtomTypes::AminoAcid
/// "ADE" => AtomTypes::NucleicAcid
/// "GUA" => AtomTypes::NucleicAcid
/// "THY" => AtomTypes::NucleicAcid
/// "CYT" => AtomTypes::NucleicAcid
/// "TIP3W" => AtomTypes::Wat
/// "POPC" => AtomTypes::Lipid
/// "POPE" => AtomTypes::Lipid
/// "HOH" => AtomTypes::Water
///
#[derive(PartialEq, Debug, Copy, Clone)]
pub enum AtomTypes {
AminoAcid,
NucleicAcid,
Lipid,
Water,
}
impl AtomTypes {
/// Return a [`AtomTypes`] according to the "residue" of the atom
///
/// ````
/// use pdbparser::AtomTypes;
///
/// assert_eq!(AtomTypes::AminoAcid, *AtomTypes::get("trp").unwrap());
/// assert_eq!(AtomTypes::Lipid, *AtomTypes::get("POPC").unwrap());
/// assert_eq!(None, AtomTypes::get("toto"));
///
/// ````
pub fn get(atom: &str) -> Option<&AtomTypes> {
ATOM_TYPES.get(&atom.to_uppercase()[..])
}
}
lazy_static! {
static ref ATOM_TYPES: HashMap<&'static str, AtomTypes> = [
("ARG", AtomTypes::AminoAcid),
("LYS", AtomTypes::AminoAcid),
("ASN", AtomTypes::AminoAcid),
("ASP", AtomTypes::AminoAcid),
("GLU", AtomTypes::AminoAcid),
("SER", AtomTypes::AminoAcid),
("THR", AtomTypes::AminoAcid),
("GLN", AtomTypes::AminoAcid),
("CYS", AtomTypes::AminoAcid),
("HIS", AtomTypes::AminoAcid),
("HSD", AtomTypes::AminoAcid),
("HSP", AtomTypes::AminoAcid),
("HSD", AtomTypes::AminoAcid),
("SEC", AtomTypes::AminoAcid),
("GLY", AtomTypes::AminoAcid),
("PRO", AtomTypes::AminoAcid),
("ALA", AtomTypes::AminoAcid),
("VAL", AtomTypes::AminoAcid),
("ILE", AtomTypes::AminoAcid),
("LEU", AtomTypes::AminoAcid),
("MET", AtomTypes::AminoAcid),
("PHE", AtomTypes::AminoAcid),
("TYR", AtomTypes::AminoAcid),
("TRP", AtomTypes::AminoAcid),
("ADE", AtomTypes::NucleicAcid),
("GUA", AtomTypes::NucleicAcid),
("THY", AtomTypes::NucleicAcid),
("CYT", AtomTypes::NucleicAcid),
("TIP3W", AtomTypes::Water),
("POPC", AtomTypes::Lipid),
("POPE", AtomTypes::Lipid),
("HOH", AtomTypes::Water),
]
.iter()
.cloned()
.collect();
}
......@@ -72,31 +72,24 @@ pub fn read_pdb(pdb: &str, name: &str) -> Structure {
// If the "residue" is a amino acid, 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();
match AtomTypes::get(&residue_name.to_uppercase()[..]) {
Some(AtomTypes::AminoAcid) => {
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 Structure
structure.update_structure(
chain,
residue_name.to_string(),
residue_number as u64,
atom_name.clone(),
atom_number as u64,
[x, y, z],
);
}
Some(AtomTypes::Water) => (),
Some(AtomTypes::Lipid) => (),
Some(AtomTypes::NucleicAcid) => (),
_ => (), //TODO: Warning with unrecognize atom
}
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 Structure
structure.update_structure(
chain,
residue_name.to_string(),
residue_number as u64,
atom_name.clone(),
atom_number as u64,
[x, y, z],
);
let chain_type = ChainTypes::get(&residue_name.to_uppercase()[..]);
}
}
structure
}
\ 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