Commit 3f2eb34a authored by NOEL Philippe's avatar NOEL Philippe

Add doc in atom and add distance function

parent b90ed716
#[derive(Debug)]
pub struct Atom {
name: String,
number: u64,
coord: [f32; 3],
pub name: String,
pub number: u64,
pub coord: [f32; 3],
}
impl Atom {
/// Create a new structure Atom. An atom have a name, a number and x, y, z coordinates
///
/// # Examples
///
/// ````
/// use pdbparser;
///
/// let hydrogen = pdbparser::Atom::new(String::from("HT1"), 1, [0.0, 0.0, 0.0]);
///
/// ````
pub fn new(name: String, number: u64, coord: [f32; 3]) -> Atom {
Atom {
name,
......@@ -14,4 +25,24 @@ impl Atom {
}
}
/// Compute the distance between 2 Atoms
///
/// # Examples
///
/// ````
/// use pdbparser;
///
/// let h1 = pdbparser::Atom::new(String::from("HT1"), 1, [1.0, 5.0, 2.0]);
/// let h2 = pdbparser::Atom::new(String::from("HT1"), 1, [11.0, 17.0, 5.0]);
///
/// assert_eq!(15.905973, h1.compute_distance(h2));
///
/// ````
pub fn compute_distance(&self, a: Atom) -> f32 {
(
(self.coord[0] - a.coord[0]).powi(2) +
(self.coord[1] - a.coord[1]).powi(2) +
(self.coord[2] - a.coord[2]).powi(2)
).sqrt()
}
}
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