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
/*

Kinds of energies for atoms:

- two body
    - Coulomb
    - Lennard-Jones

Kinds of energies for residues:

- one body
    - depends on phi and psi angle
        - Ramachandran energy
- two body
    -

*/

use conformation::{Atom, Pose};

// calculate Lennard-Jones energy
// from two atoms and the distance between them
// which has already been computed
pub fn calculate_lennard_jones_energy(a1: &Atom, a2: &Atom, r: f64) -> f64 {

    let r_m = 1.0; // sum of both radii
    let epsilon = 1.0;

    epsilon * ((r_m/r).powi(12) - 2.0 * (r_m/r).powi(6))
}

pub fn calculate_coulomb_energy(a1: &Atom, a2: &Atom, r: f64) -> f64 {

    let c = 1.0;

    c * a1.charge * a2.charge / r.powi(2)
}

pub fn score(pose: &Pose) -> f64 {

    let lennard_jones_weight: f64 = 1.0;
    let coulomb_weight: f64 = 1.0;

    let mut total_score: f64 = 0.0;
    for i in &pose.atoms {
        for j in &pose.atoms {
            let r: f64 = i.dist(j);
            if r == 0.0 {
                // these are the same atom // do nothing
            } else if r.max(6.0) == 6.0 {
                // these atoms are greater than 12 Å apart, ignore that they interact
            } else {
                total_score += lennard_jones_weight * calculate_lennard_jones_energy(i, j, r);
                total_score += coulomb_weight * calculate_coulomb_energy(i, j, r);
            }
        }
    }

    // It would be better to have a NxN matrix, where N = number of atoms
    // where each entry is the last known distance, and to only operate on
    // a subset of that matrix

    total_score
}