-
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.
- Loading branch information
Kviatkovskii, Mikhail (Ext)
committed
Jul 7, 2024
1 parent
fc9a8ff
commit 9f86f20
Showing
28 changed files
with
217 additions
and
200 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 |
---|---|---|
@@ -1,4 +1,3 @@ | ||
pub mod index_item; | ||
pub mod index; | ||
pub mod index_item; | ||
pub mod search; | ||
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
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,2 @@ | ||
mod fingerprints; | ||
mod weight; |
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 @@ | ||
mod ecfp; |
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,84 @@ | ||
use crate::model::atom::Atom; | ||
use crate::model::bond::Bond; | ||
use crate::model::fingerprint::{Fingerprint, FINGERPRINT_SIZE}; | ||
use crate::model::molecule::Molecule; | ||
use fixedbitset::FixedBitSet; | ||
use petgraph::graph::NodeIndex; | ||
use petgraph::prelude::{EdgeRef, StableGraph}; | ||
use petgraph::Undirected; | ||
use std::hash::{DefaultHasher, Hasher}; | ||
|
||
impl Molecule { | ||
pub fn ecfp(&self, radius: usize, fp_length: usize) -> Fingerprint { | ||
let mut fp = FixedBitSet::with_capacity(FINGERPRINT_SIZE); | ||
|
||
for node in self.graph.node_indices() { | ||
ecfp_recursive( | ||
&self.graph, | ||
radius, | ||
1, | ||
node, | ||
&mut fp, | ||
fp_length, | ||
&mut DefaultHasher::new(), | ||
); | ||
} | ||
|
||
Fingerprint(fp) | ||
} | ||
} | ||
|
||
fn ecfp_recursive( | ||
graph: &StableGraph<Atom, Bond, Undirected>, | ||
radius: usize, | ||
depth: usize, | ||
node: NodeIndex, | ||
fp: &mut FixedBitSet, | ||
fp_length: usize, | ||
hasher: &mut DefaultHasher, | ||
) { | ||
if depth > radius { | ||
return; | ||
} | ||
|
||
let atom = graph.node_weight(node).unwrap(); | ||
hasher.write_u8(atom.element.atomic_number); | ||
hasher.write_u8(atom.isotope); | ||
hasher.write_i8(atom.charge); | ||
hasher.write_u8(atom.hs); | ||
|
||
let value = hasher.clone().finish(); | ||
fp.insert(value as usize % fp_length); | ||
|
||
for edge in graph.edges(node) { | ||
let bond = edge.weight(); | ||
hasher.write_u8(bond.order as u8); | ||
|
||
let target = if edge.source() == node { | ||
edge.target() | ||
} else { | ||
edge.source() | ||
}; | ||
|
||
ecfp_recursive(graph, radius, depth + 1, target, fp, fp_length, hasher); | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod test { | ||
use crate::io::smiles::reader::molecule::parse_molecule; | ||
use crate::math::similarity::tanimoto::tanimoto_bitset; | ||
#[test] | ||
fn test_ecfp() { | ||
let ecfp_ibuprofen = parse_molecule("CC(C)CC1=CC=C(C=C1)C(C)C(=O)O") | ||
.unwrap() | ||
.1 | ||
.ecfp(2, 128); | ||
let ecfp_naproxen = parse_molecule("CC(C1=CC2=C(C=C1)C=C(C=C2)OC)C(=O)O") | ||
.unwrap() | ||
.1 | ||
.ecfp(2, 128); | ||
let sim = tanimoto_bitset(&ecfp_ibuprofen.0, &ecfp_naproxen.0); | ||
assert!(0.53 < sim && sim < 0.54); | ||
} | ||
} |
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,11 @@ | ||
use crate::model::molecule::Molecule; | ||
|
||
impl Molecule { | ||
pub fn weight(&self) -> f64 { | ||
let mut weight: f64 = 0.0; | ||
for atom in self.graph.node_weights() { | ||
weight += atom.element.atomic_weight(); | ||
} | ||
weight | ||
} | ||
} |
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(crate) mod smiles; |
File renamed without changes.
File renamed without changes.
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
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
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
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,3 +1,5 @@ | ||
pub mod db; | ||
mod descriptors; | ||
mod io; | ||
mod math; | ||
mod molecule; | ||
mod model; |
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,5 @@ | ||
pub mod atom; | ||
pub mod bond; | ||
pub mod element; | ||
pub mod fingerprint; | ||
pub mod molecule; |
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
File renamed without changes.
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
Oops, something went wrong.