-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#6: code refactored and reorganized, added new binaries stubs
- Loading branch information
1 parent
1db971c
commit bc6a100
Showing
18 changed files
with
297 additions
and
213 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
mod bin; | ||
pub mod ringo; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
pub mod fingerprint; | ||
pub mod math; | ||
pub mod molecule; | ||
mod ringo; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
pub mod fingerprint; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,28 @@ | ||
use crate::ringo::molecule::model::element::Element; | ||
|
||
#[derive(Hash, Eq, PartialEq)] | ||
#[derive(Hash, Eq, PartialEq, Debug)] | ||
pub struct Atom { | ||
pub element: Element, | ||
pub isotope: u8, | ||
pub charge: i8, | ||
pub hs: u8, | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use super::*; | ||
|
||
#[test] | ||
fn test_atom() { | ||
let atom = Atom { | ||
element: Element { atomic_number: 6 }, | ||
isotope: 12, | ||
charge: 0, | ||
hs: 0, | ||
}; | ||
assert_eq!(atom.element, Element { atomic_number: 6 }); | ||
assert_eq!(atom.isotope, 12); | ||
assert_eq!(atom.charge, 0); | ||
assert_eq!(atom.hs, 0); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,93 +1,106 @@ | ||
#[derive(Hash, Eq, PartialEq)] | ||
#[derive(Hash, Eq, PartialEq, Debug)] | ||
pub struct Element { | ||
pub atomic_number: u8, | ||
} | ||
|
||
pub fn atomic_weight(element: &Element) -> f64 { | ||
match element.atomic_number { | ||
1 => 1.007825, | ||
2 => 4.002603, | ||
3 => 6.938, | ||
4 => 9.0121831, | ||
5 => 10.806, | ||
6 => 12.011, | ||
7 => 14.007, | ||
8 => 15.999, | ||
9 => 18.998403163, | ||
10 => 20.180, | ||
11 => 22.990, | ||
12 => 24.305, | ||
13 => 26.9815385, | ||
14 => 28.085, | ||
15 => 30.973761998, | ||
16 => 32.06, | ||
17 => 35.45, | ||
18 => 39.948, | ||
19 => 39.0983, | ||
20 => 40.078, | ||
21 => 44.955908, | ||
22 => 47.867, | ||
23 => 50.9415, | ||
24 => 51.9961, | ||
25 => 54.938044, | ||
26 => 55.845, | ||
27 => 58.933194, | ||
28 => 58.6934, | ||
29 => 63.546, | ||
30 => 65.38, | ||
31 => 69.723, | ||
32 => 72.630, | ||
33 => 74.921595, | ||
34 => 78.96, | ||
35 => 79.904, | ||
36 => 83.798, | ||
37 => 85.4678, | ||
38 => 87.62, | ||
39 => 88.90584, | ||
40 => 91.224, | ||
41 => 92.90637, | ||
42 => 95.95, | ||
43 => 98.0, | ||
44 => 101.07, | ||
45 => 102.90550, | ||
46 => 106.42, | ||
47 => 107.8682, | ||
48 => 112.414, | ||
49 => 114.818, | ||
50 => 118.710, | ||
51 => 121.760, | ||
52 => 127.60, | ||
53 => 126.90447, | ||
54 => 131.293, | ||
55 => 132.90545196, | ||
56 => 137.327, | ||
57 => 138.90547, | ||
58 => 140.116, | ||
59 => 140.90766, | ||
60 => 144.242, | ||
61 => 145.0, | ||
62 => 150.36, | ||
63 => 151.964, | ||
64 => 157.25, | ||
65 => 158.92535, | ||
66 => 162.500, | ||
67 => 164.93033, | ||
68 => 167.259, | ||
69 => 168.93422, | ||
70 => 173.054, | ||
71 => 174.9668, | ||
72 => 178.49, | ||
73 => 180.94788, | ||
74 => 183.84, | ||
75 => 186.207, | ||
76 => 190.23, | ||
77 => 192.217, | ||
78 => 195.084, | ||
79 => 196.966569, | ||
80 => 200.592, | ||
81 => 204.38, | ||
82 => 207.2, | ||
83 => 208.98040, | ||
_ => panic!("Unsupported atomic number {}", element.atomic_number), | ||
impl Element { | ||
pub fn atomic_weight(&self) -> f64 { | ||
match self.atomic_number { | ||
1 => 1.007825, | ||
2 => 4.002603, | ||
3 => 6.938, | ||
4 => 9.0121831, | ||
5 => 10.806, | ||
6 => 12.011, | ||
7 => 14.007, | ||
8 => 15.999, | ||
9 => 18.998403163, | ||
10 => 20.180, | ||
11 => 22.990, | ||
12 => 24.305, | ||
13 => 26.9815385, | ||
14 => 28.085, | ||
15 => 30.973761998, | ||
16 => 32.06, | ||
17 => 35.45, | ||
18 => 39.948, | ||
19 => 39.0983, | ||
20 => 40.078, | ||
21 => 44.955908, | ||
22 => 47.867, | ||
23 => 50.9415, | ||
24 => 51.9961, | ||
25 => 54.938044, | ||
26 => 55.845, | ||
27 => 58.933194, | ||
28 => 58.6934, | ||
29 => 63.546, | ||
30 => 65.38, | ||
31 => 69.723, | ||
32 => 72.630, | ||
33 => 74.921595, | ||
34 => 78.96, | ||
35 => 79.904, | ||
36 => 83.798, | ||
37 => 85.4678, | ||
38 => 87.62, | ||
39 => 88.90584, | ||
40 => 91.224, | ||
41 => 92.90637, | ||
42 => 95.95, | ||
43 => 98.0, | ||
44 => 101.07, | ||
45 => 102.90550, | ||
46 => 106.42, | ||
47 => 107.8682, | ||
48 => 112.414, | ||
49 => 114.818, | ||
50 => 118.710, | ||
51 => 121.760, | ||
52 => 127.60, | ||
53 => 126.90447, | ||
54 => 131.293, | ||
55 => 132.90545196, | ||
56 => 137.327, | ||
57 => 138.90547, | ||
58 => 140.116, | ||
59 => 140.90766, | ||
60 => 144.242, | ||
61 => 145.0, | ||
62 => 150.36, | ||
63 => 151.964, | ||
64 => 157.25, | ||
65 => 158.92535, | ||
66 => 162.500, | ||
67 => 164.93033, | ||
68 => 167.259, | ||
69 => 168.93422, | ||
70 => 173.054, | ||
71 => 174.9668, | ||
72 => 178.49, | ||
73 => 180.94788, | ||
74 => 183.84, | ||
75 => 186.207, | ||
76 => 190.23, | ||
77 => 192.217, | ||
78 => 195.084, | ||
79 => 196.966569, | ||
80 => 200.592, | ||
81 => 204.38, | ||
82 => 207.2, | ||
83 => 208.98040, | ||
_ => panic!("Unsupported atomic number {}", self.atomic_number), | ||
} | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod test { | ||
use crate::ringo::molecule::model::element::Element; | ||
|
||
#[test] | ||
fn test_element() { | ||
let element = Element { atomic_number: 1 }; | ||
assert_eq!(element.atomic_weight(), 1.007825); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,2 @@ | ||
pub(crate) mod fingerprint; | ||
mod index; | ||
mod index_item; | ||
mod search; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,3 @@ | ||
use crate::ringo::molecule::smiles::reader::molecule::parse_molecule; | ||
use crate::ringo::ringo::index_item::IndexItem; | ||
use std::fs::File; | ||
use std::io::{BufRead, BufWriter, Write}; | ||
use bincode::{encode_into_slice}; | ||
use crate::ringo::ringo::fingerprint::FINGERPRINT_SIZE; | ||
|
||
#[cfg(windows)] | ||
const LINE_ENDING_LENGTH: usize = 2; | ||
#[cfg(not(windows))] | ||
const LINE_ENDING_LENGTH: usize = 1; | ||
|
||
fn index(smiles_file: &str) { | ||
// open file for reading | ||
let fi = File::open(smiles_file).expect("Could not open file"); | ||
|
||
// open binary file for index | ||
let mut offset = 0; | ||
let fo = File::create(smiles_file.to_owned() + ".fp"); | ||
let mut writer = BufWriter::new(fo.unwrap()); | ||
|
||
for line in std::io::BufReader::new(fi).lines() { | ||
let line = line.unwrap(); | ||
let molecule = parse_molecule(&line).unwrap().1; | ||
let index_item = IndexItem { | ||
position: offset, | ||
fingerprint: molecule.ecfp(2, 512), | ||
}; | ||
offset += line.len() + LINE_ENDING_LENGTH; | ||
|
||
let mut buf = vec![0u8; FINGERPRINT_SIZE / 8 + 8]; | ||
|
||
encode_into_slice(&index_item, buf.as_mut_slice(), bincode::config::standard()).unwrap(); | ||
writer.write(&buf).unwrap(); | ||
} | ||
} | ||
|
||
#[test] | ||
fn test_index() { | ||
index("molecules.smi"); | ||
} | ||
pub(crate) mod index; | ||
pub mod index_item; | ||
mod main; |
Oops, something went wrong.