lightdock/
lib.rs

1#[macro_use]
2extern crate lazy_static;
3extern crate rand;
4
5pub mod constants;
6pub mod dfire;
7pub mod dna;
8pub mod glowworm;
9pub mod pydock;
10pub mod qt;
11pub mod scoring;
12pub mod swarm;
13
14use log::info;
15use rand::rngs::StdRng;
16use rand::SeedableRng;
17use scoring::Score;
18use swarm::Swarm;
19
20pub struct GSO<'a> {
21    pub swarm: Swarm<'a>,
22    pub rng: StdRng,
23    pub output_directory: String,
24}
25
26impl<'a> GSO<'a> {
27    pub fn new(
28        positions: &[Vec<f64>],
29        seed: u64,
30        scoring: &'a Box<dyn Score>,
31        use_anm: bool,
32        rec_num_anm: usize,
33        lig_num_anm: usize,
34        output_directory: String,
35    ) -> Self {
36        let mut gso = GSO {
37            swarm: Swarm::new(),
38            rng: SeedableRng::seed_from_u64(seed),
39            output_directory,
40        };
41        gso.swarm
42            .add_glowworms(positions, scoring, use_anm, rec_num_anm, lig_num_anm);
43        gso
44    }
45
46    pub fn run(&mut self, steps: u32) {
47        for step in 1..steps + 1 {
48            info!("Step {}", step);
49            self.swarm.update_luciferin();
50            self.swarm.movement_phase(&mut self.rng);
51            if step % 10 == 0 || step == 1 {
52                match self.swarm.save(step, &self.output_directory) {
53                    Ok(ok) => ok,
54                    Err(why) => panic!("Error saving GSO output: {:?}", why),
55                }
56            }
57        }
58    }
59}