From 1db971cb39adf2a4d97ba60b1b636a881504927f Mon Sep 17 00:00:00 2001 From: Mikhail Kviatkovskii Date: Sat, 6 Jul 2024 13:08:13 +0400 Subject: [PATCH] Eliminate build warnings --- src/ringo/molecule/smiles/reader/atom.rs | 5 ++--- src/ringo/ringo/fingerprint.rs | 2 +- src/ringo/ringo/index.rs | 2 +- src/ringo/ringo/search.rs | 13 ++++++++++--- 4 files changed, 14 insertions(+), 8 deletions(-) diff --git a/src/ringo/molecule/smiles/reader/atom.rs b/src/ringo/molecule/smiles/reader/atom.rs index fe4c12e..9b0cfd1 100644 --- a/src/ringo/molecule/smiles/reader/atom.rs +++ b/src/ringo/molecule/smiles/reader/atom.rs @@ -11,8 +11,7 @@ pub(crate) fn parse_atom(input: &str) -> IResult<&str, Atom> { let mut isotope: Option = None; let mut charge: Option = None; let mut hs: Option = 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)); @@ -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 = None; + let sqrc_found: Option; (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()) diff --git a/src/ringo/ringo/fingerprint.rs b/src/ringo/ringo/fingerprint.rs index 474f0da..c0fd772 100644 --- a/src/ringo/ringo/fingerprint.rs +++ b/src/ringo/ringo/fingerprint.rs @@ -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()) diff --git a/src/ringo/ringo/index.rs b/src/ringo/ringo/index.rs index a4a21bb..a06ccc5 100644 --- a/src/ringo/ringo/index.rs +++ b/src/ringo/ringo/index.rs @@ -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() { diff --git a/src/ringo/ringo/search.rs b/src/ringo/ringo/search.rs index 431fb6b..ddc8b65 100644 --- a/src/ringo/ringo/search.rs +++ b/src/ringo/ringo/search.rs @@ -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(); @@ -49,9 +49,13 @@ pub fn similarity_search(smiles_file: &str, query: &str, min_similarity: f32, li line: line, similarity: similarity }); + + if results.len() >= limit { + break; + } } } - + results } @@ -59,6 +63,9 @@ pub fn similarity_search(smiles_file: &str, query: &str, min_similarity: f32, li 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); + }