1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
// Conformation (smaller to larger, Atom > Residue > Pose)

use io::Record;

#[derive(Debug)]
pub struct XYZ {
    pub x: f64,
    pub y: f64,
    pub z: f64,

    // add the Add trait!
}

/// Holds Cartesian coordinates
///
/// # Example
///
/// ```
/// //use conformation::XYZ; 
///
/// //let xyz = XYZ::new(0.123, 0.234, 0.345); 
///
/// //assert_eq!(0.123, xyz.x); 
/// ```
impl XYZ {
    pub fn new(x: f64, y: f64, z: f64) -> XYZ {
        XYZ { x, y, z }
    }

    pub fn clone(&self) -> XYZ {
        let x = self.x.clone();
        let y = self.y.clone();
        let z = self.z.clone();

        XYZ { x, y, z }
    }
}

/// Holds a protein 
pub struct Pose {
    pub atoms: Vec<Atom>,
}

impl Pose {
    pub fn from_atoms(atoms: Vec<Atom>) -> Pose {

        Pose { atoms }
    }
}

pub struct Residue {
    atoms: Vec<Atom>,
    residue_name: String,
    residue_index: i32,
}

pub struct Atom {
    pub charge: f64,
    pub xyz: XYZ,
    pub element: String,
}

impl Atom {
    pub fn new(record: &Record) -> Atom {
        let xyz = record.xyz.clone();
        let charge = record.charge.clone();
        let element = record.element.clone();
        // we will probably do some more construction at some point

        Atom { xyz, charge, element }
    }

    pub fn dist(&self, other: &Atom) -> f64 {
        ((self.xyz.x - other.xyz.x).powi(2) +
         (self.xyz.y - other.xyz.y).powi(2) +
         (self.xyz.z - other.xyz.z).powi(2)).sqrt()
    }

    /*

    pub fn polarize(&self, other: &mut Atom, magnitude: f64) {
        // let total_charge: f64 = self.charge + other.charge;
        self.charge += magnitude;
        other.charge -= magnitude;
    }

    */

}