Skip to content

Commit

Permalink
Eliminate build warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
mkviatkovskii committed Jul 6, 2024
1 parent bf86e2c commit 1db971c
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 8 deletions.
5 changes: 2 additions & 3 deletions src/ringo/molecule/smiles/reader/atom.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ pub(crate) fn parse_atom(input: &str) -> IResult<&str, Atom> {
let mut isotope: Option<u8> = None;
let mut charge: Option<i8> = None;
let mut hs: Option<u8> = None;
let mut atomic_number = 0;

let atomic_number: u8;
let (mut input, sqro_found) = opt(nom::character::complete::char('['))(input)?;
if sqro_found.is_some() {
(input, isotope) = opt(parse_isotope)(input).unwrap_or((input, None));
Expand All @@ -21,7 +20,7 @@ pub(crate) fn parse_atom(input: &str) -> IResult<&str, Atom> {
if sqro_found.is_some() {
(input, hs) = opt(parse_hydrogens)(input).unwrap_or((input, None));
(input, charge) = opt(parse_charge)(input).unwrap_or((input, None));
let mut sqrc_found: Option<char> = None;
let sqrc_found: Option<char>;
(input, sqrc_found) = opt(nom::character::complete::char(']'))(input)?;
if (sqro_found.is_some() && sqrc_found.is_none())
|| (sqro_found.is_none() && sqrc_found.is_some())
Expand Down
2 changes: 1 addition & 1 deletion src/ringo/ringo/fingerprint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ mod tests {
fp.0.set(17, true);

let mut buf = vec![0u8; FINGERPRINT_SIZE / 8];
let encoded = bincode::encode_into_slice(&fp, buf.as_mut_slice(), bincode::config::standard()).unwrap();
bincode::encode_into_slice(&fp, buf.as_mut_slice(), bincode::config::standard()).unwrap();

let decoded: Fingerprint =
bincode::decode_from_slice(&buf, bincode::config::standard())
Expand Down
2 changes: 1 addition & 1 deletion src/ringo/ringo/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ fn index(smiles_file: &str) {

// open binary file for index
let mut offset = 0;
let mut fo = File::create(smiles_file.to_owned() + ".fp");
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() {
Expand Down
13 changes: 10 additions & 3 deletions src/ringo/ringo/search.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ pub fn similarity_search(smiles_file: &str, query: &str, min_similarity: f32, li
let mut buf_reader = BufReader::new(fif);

let mut results = Vec::new();
for i in 0..index_count {

for _ in 0..index_count {
// read index item from file
let mut buf = vec![0u8; index_item_size as usize];
buf_reader.read_exact(&mut buf).unwrap();
Expand All @@ -49,16 +49,23 @@ pub fn similarity_search(smiles_file: &str, query: &str, min_similarity: f32, li
line: line,
similarity: similarity
});

if results.len() >= limit {
break;
}
}
}

results
}

#[test]
fn test_similarity_search() {
let results = similarity_search("molecules.smi", "CC(C)CC1=CC=C(C=C1)C(C)C(=O)O", 0.7, 100);
assert_eq!(results.len(), 1);
assert!(results[0].line.starts_with("CC(C)CC1=CC=C(C=C1)C(C)C(=O)O"));
assert_eq!(results[0].similarity, 1.0);
let results = similarity_search("molecules.smi", "CC(C)CC1=CC=C(C=C1)C(C)C(=O)O", 0.5, 100);
assert_eq!(results.len(), 2);

}

0 comments on commit 1db971c

Please sign in to comment.