Commit 8f1754a8 authored by NOEL Philippe's avatar NOEL Philippe

Add PDB writer

parent 32e67797
......@@ -7,6 +7,8 @@
mod pdb;
pub use self::pdb::read_pdb::parse_pdb as parse_pdb;
pub use self::pdb::write_pdb::write_pdb;
pub use self::pdb::protein::Protein;
pub use self::pdb::atom::Atom;
......
......@@ -3,12 +3,18 @@ extern crate pdbparser;
use pdbparser::*;
fn main() {
let my_prot = parse_pdb("tests/tests_file/5jpq.pdb", "5jpq");
let my_prot = parse_pdb("tests/tests_file/f2.pdb", "5jpq");
match write_pdb(&my_prot, "toto.pdb"){
Ok(_) => (),
Err(e) => println!("Error : {}", e),
};
// println!("Prot : {} \nn chain: {}\nn res: {}\nn atom: {}", my_prot.name, my_prot.get_number_chain(), my_prot.get_number_residue(), my_prot.get_number_atom());
// 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(), chain_a.get_number_residue(), chain_a.get_number_atom());
println!("Prot : {} \nn chain: {}\nn res: {}\nn atom: {}", my_prot.name, my_prot.get_number_chain(), my_prot.get_number_residue(), my_prot.get_number_atom());
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(), chain_a.get_number_residue(), chain_a.get_number_atom());
}
......@@ -40,7 +40,7 @@ impl Atom {
/// Get the name of the atom
///
pub fn name(self) -> String{
pub fn name(&self) -> String{
self.name.clone()
}
......
......@@ -3,5 +3,6 @@ pub mod protein;
pub mod residue;
pub mod read_pdb;
pub mod chain;
pub mod write_pdb;
mod selection_atom;
\ No newline at end of file
......@@ -40,7 +40,7 @@ impl Residue {
self.name.clone()
}
/// Get the number of the residue
/// Get the residue ID of the residue
///
pub fn get_res_num(&self) -> u64 {
self.res_num
......
use super::protein::Protein;
use std::fs::File;
use std::io::Write;
use std::io;
/// Write a PDB file for the `Protein`.
/// Be careful, the protein is write with the atom numbers in its structure. Remind to use the method
/// my_protein.refine_numerotation() before !
pub fn write_pdb(my_prot: &Protein, file: &str) -> io::Result<()>{
let mut output_pdb = File::create(file)?;
for chain in &my_prot.lst_chain {
let chain_name = chain.get_name();
for residue in &chain.lst_res {
let res_name = residue.name();
let res_id = residue.get_res_num();
for atom in &residue.lst_atom {
let atom_name = atom.name();
let atom_id = atom.number;
let atom_coord = atom.coord;
output_pdb.write_fmt(format_args!("ATOM {:>5} {:<4}{:>3} {}{:>4} {:>8.3}{:>8.3}{:>8.3}{:>6.2}{:>6.2}\n",
atom_id,
atom_name,
res_name,
chain_name,
res_id,
atom_coord[0],
atom_coord[1],
atom_coord[2],
1.0, 0.0
))?;
}
}
}
Ok(())
}
\ No newline at end of file
This diff is collapsed.
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