Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor periodic table #41

Closed
wants to merge 26 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
e40ae89
added get_most_common_isotope_mass function to periodic table
mvisani Jun 21, 2024
b9f58ad
Merge branch 'rdkit-rs:main' into main
mvisani Jun 25, 2024
cb25437
Merge branch 'main' into main
mvisani Jul 3, 2024
0b4fc96
Merge branch 'rdkit-rs:main' into main
mvisani Jul 9, 2024
5fa1c47
added formatting for c++ files
mvisani Jul 9, 2024
5d3c7a6
reformatted cpp files according to clang-format
mvisani Jul 9, 2024
2c2d91a
implemented getProp and setProp
mvisani Jul 17, 2024
20ceaa2
minor change in function name
mvisani Jul 17, 2024
0d37a80
fixed mutable ref problems
mvisani Jul 18, 2024
6d8fdd4
fixed typo
mvisani Jul 18, 2024
070652d
added getNumRadicalElectrons for Atom
mvisani Jul 18, 2024
97e8951
added getDegree for Atom
mvisani Jul 18, 2024
f36efe2
changed struct import in rdkit crate
mvisani Jul 18, 2024
4ee20c4
changed struct import in rdkit crate
mvisani Jul 18, 2024
bd2d49f
reformatted rust code according to rustfmt.toml
mvisani Jul 19, 2024
5889f1e
Merge branch 'rdkit-rs:main' into renaming-existing-bindings
mvisani Jul 22, 2024
4e2a4e3
formatted files according to rustfmt
mvisani Aug 22, 2024
c0a2ab9
merged adding-new-bindings branch into main
mvisani Sep 4, 2024
1168b96
Merge branch 'rdkit-rs:main' into main
mvisani Sep 4, 2024
dc49d99
Merge branch 'renaming-existing-bindings'
mvisani Sep 7, 2024
853e2fd
added SetNoImplicit function to atom
mvisani Sep 7, 2024
20ad76b
corrected typo
mvisani Sep 7, 2024
f1d24bc
testing if frag_catalog works on github actions. My computer seems to…
mvisani Sep 8, 2024
bf8485c
solved issue. Turns out I needed to add the dylib files that were mis…
mvisani Sep 8, 2024
0ba7715
Merge branch 'rdkit-rs:main' into main
mvisani Oct 10, 2024
746568a
changed get_most_common_isotope_mass to getMostCommonIsotopeMass whic…
mvisani Oct 10, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,6 @@
.idea/
tests/fixtures/*
*.iml
.vscode
.env
.DS_Store
6 changes: 5 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@
name = "rdkit"
version = "0.4.11"
edition = "2021"
authors = ["Xavier Lange <[email protected]>", "Javier Pineda <[email protected]"]
authors = [
"Xavier Lange <[email protected]>",
"Javier Pineda <[email protected]",
]
license = "MIT"
description = "High level RDKit functionality for rust"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
Expand All @@ -14,6 +17,7 @@ members = ["rdkit-sys"]
bitvec = "1"
byteorder = "1.4.3"
cxx = "1"
dotenvy = "0.15.7"
flate2 = "1"
log = "0.4"
rdkit-sys = { path = "rdkit-sys", version = "0.4.9" }
Expand Down
2 changes: 1 addition & 1 deletion benches/molecule_benchmark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#![feature(test)]
extern crate test;

use rdkit::ROMol;
use rdkit::graphmol::ro_mol::ROMol;

#[bench]
fn bench_molecules(bencher: &mut test::bench::Bencher) {
Expand Down
2 changes: 1 addition & 1 deletion examples/tautomer_enumerator.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use rdkit::{ROMol, TautomerEnumerator};
use rdkit::{graphmol::ro_mol::ROMol, mol_standardize::TautomerEnumerator};

fn main() {
let mol = ROMol::from_smiles("c1ccccc1C(=O)NC").unwrap();
Expand Down
1 change: 1 addition & 0 deletions rdkit-sys/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ cxx = "1.0.109"
env_logger = "0.10.0"
cxx-build = "1.0.109"
which = "4.4.2"
dotenvy = "0.15.7"

[features]
default = []
Expand Down
27 changes: 14 additions & 13 deletions rdkit-sys/build.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
const CPP_VERSION_FLAG: &str = "-std=c++17";
const CPP_VERSION_FLAG: &str = "c++17";

fn main() {
dotenvy::dotenv().ok();
if std::env::var("DOCS_RS").is_ok() {
return;
}

env_logger::init();

let use_conda = std::env::var("CARGO_FEATURE_DYNAMIC_LINKING_FROM_CONDA").is_ok();
Expand Down Expand Up @@ -106,7 +106,7 @@ fn main() {
.files(wrapper_cc_paths)
.includes(include_paths)
.include(std::env::var("CARGO_MANIFEST_DIR").unwrap())
.flag(CPP_VERSION_FLAG)
.std(CPP_VERSION_FLAG)
.warnings(false)
// rdkit has warnings that blow up our build. we could enumerate all those warnings and tell
// the compiler to allow them... .warnings_into_errors(true)
Expand All @@ -118,25 +118,26 @@ fn main() {
// println!("cargo:rustc-link-lib=static=c++");

for lib in &[
// "Catalogs",
// "ChemReactions",
// "ChemTransforms",
"Catalogs",
"ChemReactions",
"ChemTransforms",
"DataStructs",
// "Depictor",
"Depictor",
"Descriptors",
"FileParsers",
"Fingerprints",
// "GenericGroups",
"FragCatalog",
"GenericGroups",
"GraphMol",
"MolStandardize",
// "MolTransforms",
// "PartialCharges",
"MolTransforms",
"PartialCharges",
"RDGeneral",
// "RDGeometryLib",
// "RingDecomposerLib",
"RDGeometryLib",
"RingDecomposerLib",
"ScaffoldNetwork",
"SmilesParse",
// "Subgraphs",
"Subgraphs",
"SubstructMatch",
] {
println!("cargo:rustc-link-lib=dylib=RDKit{}", lib);
Expand Down
10 changes: 10 additions & 0 deletions rdkit-sys/src/bridge/frag_catalog.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#[cxx::bridge(namespace = "RDKit")]
pub mod ffi {
unsafe extern "C++" {
include!("wrapper/include/frag_catalog.h");

pub type FragCatParams;

pub fn init_frat_cat_from_string(text: &CxxString) -> SharedPtr<FragCatParams>;
}
}
3 changes: 3 additions & 0 deletions rdkit-sys/src/bridge/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,6 @@ pub use scaffold_network::ffi as scaffold_network_ffi;

mod substruct_match;
pub use substruct_match::ffi as substruct_match_ffi;

mod frag_catalog;
pub use frag_catalog::ffi as frag_catalog_ffi;
2 changes: 2 additions & 0 deletions rdkit-sys/src/bridge/mol_ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,5 +83,7 @@ pub mod ffi {
pub fn romol_set_hybridization(mol: &mut SharedPtr<ROMol>);

pub fn clean_up(rw_mol: &mut SharedPtr<RWMol>);

pub fn get_number_of_fragments(mol: &SharedPtr<ROMol>) -> u32;
}
}
3 changes: 2 additions & 1 deletion rdkit-sys/src/bridge/periodic_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
pub mod ffi {
unsafe extern "C++" {
include!("wrapper/include/periodic_table.h");
type PeriodicTable;
pub fn get_valence_list(atomic_number: u32) -> &'static CxxVector<i32>;
pub fn get_most_common_isotope_mass(atom: &CxxString) -> f64;
pub fn getMostCommonIsotopeMass(self: &PeriodicTable, atom: &CxxString) -> f64;
}
}
1 change: 1 addition & 0 deletions rdkit-sys/src/bridge/ro_mol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ pub mod ffi {
pub fn get_total_valence(atom: Pin<&Atom>) -> u32;
pub fn set_formal_charge(atom: Pin<&mut Atom>, what: i32);
pub fn set_num_explicit_hs(atom: Pin<&mut Atom>, what: i32);
pub fn set_no_implicit(atom: Pin<&mut Atom>, what: bool);
pub fn atom_update_property_cache(atom: Pin<&mut Atom>, strict: bool) -> Result<()>;
pub fn atom_set_hybridization(atom: Pin<&mut Atom>, what: HybridizationType);
pub fn atom_get_hybridization(atom: Pin<&Atom>) -> HybridizationType;
Expand Down
7 changes: 7 additions & 0 deletions rdkit-sys/tests/frag_catalog.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
use cxx::let_cxx_string;

#[test]
fn test_frag_catalog() {
let_cxx_string!(s = "0 20 1e-008\n1\nNitroGroup [N+](=O)[O-]\n");
let _frag_cat_params = rdkit_sys::frag_catalog_ffi::init_frat_cat_from_string(&s);
}
13 changes: 13 additions & 0 deletions rdkit-sys/tests/test_mol_ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,16 @@ fn test_mol_ops_cleanup() {
let smiles = rdkit_sys::ro_mol_ffi::mol_to_smiles(&new_ro_mol);
assert_eq!(smiles, "C");
}

#[test]
fn test_number_of_fragments() {
cxx::let_cxx_string!(smiles = "CC");
let ro_mol = rdkit_sys::ro_mol_ffi::smiles_to_mol(&smiles).unwrap();
let num_frags = rdkit_sys::mol_ops_ffi::get_number_of_fragments(&ro_mol);
assert_eq!(num_frags, 1);

cxx::let_cxx_string!(smiles = "CC(=O)[O-].[NH3+]C");
let ro_mol = rdkit_sys::ro_mol_ffi::smiles_to_mol(&smiles).unwrap();
let num_frags = rdkit_sys::mol_ops_ffi::get_number_of_fragments(&ro_mol);
assert_eq!(num_frags, 2);
}
8 changes: 8 additions & 0 deletions rdkit-sys/wrapper/include/frag_catalog.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#pragma once

#include "rust/cxx.h"
#include <GraphMol/FragCatalog/FragCatParams.h>

namespace RDKit {
std::shared_ptr<FragCatParams> init_frat_cat_from_string(const std::string &text);
} // namespace RDKit
6 changes: 6 additions & 0 deletions rdkit-sys/wrapper/include/mol_ops.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "rust/cxx.h"
#include <GraphMol/GraphMol.h>
#include <GraphMol/MolOps.h>
#include <vector>

namespace RDKit {
// pub fn new_remove_hs_parameters() -> SharedPtr<RemoveHsParameters>;
Expand Down Expand Up @@ -67,4 +68,9 @@ void romol_set_hybridization(std::shared_ptr<ROMol> &mol);

// pub fn clean_up(rw_mol: &mut SharedPtr<RWMol>)
void clean_up(std::shared_ptr<RWMol> &rw_mol);

// get molecule fragments RETURNS: a tuple of tuples with IDs for the atoms
// in each fragment or a tuple of molecules.
unsigned int get_number_of_fragments(const std::shared_ptr<ROMol> &romol);

} // namespace RDKit
3 changes: 2 additions & 1 deletion rdkit-sys/wrapper/include/periodic_table.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
#pragma once

#include "rust/cxx.h"
#include <rdkit/GraphMol/PeriodicTable.h>

namespace RDKit {
const std::vector<int> &get_valence_list(unsigned int atomic_number);
double get_most_common_isotope_mass(const std::string &symbol);
// double get_most_common_isotope_mass(const std::string &symbol);
} // namespace RDKit
1 change: 1 addition & 0 deletions rdkit-sys/wrapper/include/ro_mol.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ unsigned int get_total_num_hs(const Atom &atom);
unsigned int get_total_valence(const Atom &atom);
void set_formal_charge(Atom &atom, int what);
void set_num_explicit_hs(Atom &atom, int what);
void set_no_implicit(Atom &atom, bool what);
void atom_update_property_cache(Atom &atom, bool strict);

using HybridizationType = Atom::HybridizationType;
Expand Down
13 changes: 13 additions & 0 deletions rdkit-sys/wrapper/src/frag_catalog.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#include "rust/cxx.h"
#include <GraphMol/FragCatalog/FragCatParams.h>
// #include <GraphMol/GraphMol.h>
#include <GraphMol/MolOps.h>
#include <memory>

namespace RDKit {
std::shared_ptr<FragCatParams> init_frat_cat_from_string(const std::string &text) {
return std::shared_ptr<FragCatParams>(new FragCatParams(text));
}

// here we need to do something
} // namespace RDKit
7 changes: 6 additions & 1 deletion rdkit-sys/wrapper/src/mol_ops.cc
Original file line number Diff line number Diff line change
Expand Up @@ -106,4 +106,9 @@ std::shared_ptr<ROMol> add_hs(const std::shared_ptr<ROMol> &mol, bool explicit_o
void romol_set_hybridization(std::shared_ptr<ROMol> &mol) { MolOps::setHybridization(*mol); }

void clean_up(std::shared_ptr<RWMol> &rw_mol) { MolOps::cleanUp(*rw_mol); }
} // namespace RDKit

unsigned int get_number_of_fragments(const std::shared_ptr<ROMol> &romol) {
std::vector<int> mapping;
return RDKit::MolOps::getMolFrags(*romol, mapping);
}
} // namespace RDKit
8 changes: 4 additions & 4 deletions rdkit-sys/wrapper/src/periodic_table.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ const std::vector<int> &get_valence_list(unsigned int atomic_number) {
return pt->getValenceList(atomic_number);
}

double get_most_common_isotope_mass(const std::string &symbol) {
PeriodicTable *pt = RDKit::PeriodicTable::getTable();
return pt->getMostCommonIsotopeMass(symbol);
}
// double get_most_common_isotope_mass(const std::string &symbol) {
// PeriodicTable *pt = RDKit::PeriodicTable::getTable();
// return pt->getMostCommonIsotopeMass(symbol);
// }
} // namespace RDKit
1 change: 1 addition & 0 deletions rdkit-sys/wrapper/src/ro_mol.cc
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ unsigned int get_total_num_hs(const Atom &atom) { return atom.getTotalNumHs(); }
unsigned int get_total_valence(const Atom &atom) { return atom.getTotalValence(); }
void set_formal_charge(Atom &atom, int what) { atom.setFormalCharge(what); }
void set_num_explicit_hs(Atom &atom, int what) { atom.setNumExplicitHs(what); }
void set_no_implicit(Atom &atom, bool what) { atom.setNoImplicit(what); }
void atom_update_property_cache(Atom &atom, bool strict) { atom.updatePropertyCache(strict); }

using HybridizationType = Atom::HybridizationType;
Expand Down
2 changes: 1 addition & 1 deletion src/descriptors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::collections::HashMap;

use cxx::SharedPtr;

use crate::ROMol;
use crate::graphmol::ro_mol::ROMol;

pub struct Properties {
ptr: SharedPtr<rdkit_sys::descriptors_ffi::Properties>,
Expand Down
2 changes: 1 addition & 1 deletion src/file_parsers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use std::{

use flate2::bufread::GzDecoder;

use crate::RWMol;
use crate::graphmol::rw_mol::RWMol;

pub struct MolBlockIter<R: BufRead> {
buf_read: R,
Expand Down
4 changes: 4 additions & 0 deletions src/graphmol/atom.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ impl<'a> Atom<'a> {
ro_mol_ffi::set_num_explicit_hs(self.ptr.as_mut(), what)
}

pub fn set_no_implicit(&mut self, what: bool) {
ro_mol_ffi::set_no_implicit(self.ptr.as_mut(), what)
}

pub fn update_property_cache(&mut self, strict: bool) -> Result<(), cxx::Exception> {
ro_mol_ffi::atom_update_property_cache(self.ptr.as_mut(), strict)
}
Expand Down
13 changes: 13 additions & 0 deletions src/graphmol/frag_catalog.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
use cxx::let_cxx_string;
use rdkit_sys::*;
pub struct FragCatParams {
pub(crate) ptr: cxx::SharedPtr<frag_catalog_ffi::FragCatParams>,
}

impl FragCatParams {
pub fn new_from_string(text: &str) -> Self {
let_cxx_string!(cxx_text = text);
let ptr = rdkit_sys::frag_catalog_ffi::init_frat_cat_from_string(&cxx_text);
FragCatParams { ptr }
}
}
16 changes: 5 additions & 11 deletions src/graphmol/mod.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
mod atom;
pub use atom::*;

mod mol_ops;
pub use mol_ops::*;

mod ro_mol;
pub use ro_mol::*;

mod rw_mol;
pub use rw_mol::*;
pub mod atom;
pub mod frag_catalog;
pub mod mol_ops;
pub mod ro_mol;
pub mod rw_mol;
9 changes: 8 additions & 1 deletion src/graphmol/mol_ops.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use cxx::SharedPtr;
use rdkit_sys::ro_mol_ffi as ro_mol;

use crate::{ROMol, RWMol};
use crate::graphmol::{ro_mol::ROMol, rw_mol::RWMol};

#[derive(Debug, PartialEq)]
pub enum MolSanitizeException {
Expand Down Expand Up @@ -209,3 +209,10 @@ pub fn set_hybridization(romol: &mut ROMol) {
pub fn clean_up(rw_mol: &mut RWMol) {
rdkit_sys::mol_ops_ffi::clean_up(&mut rw_mol.ptr);
}

/// Returns the number of fragments in the molecule.
/// This could arguably be a method on ROMol. But to respect
/// RDKit's design, it is a free function of the mol_ops module.
pub fn get_number_of_fragments(ro_mol: &ROMol) -> u32 {
rdkit_sys::mol_ops_ffi::get_number_of_fragments(&ro_mol.ptr)
}
5 changes: 4 additions & 1 deletion src/graphmol/ro_mol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ use std::fmt::{Debug, Formatter};
use cxx::let_cxx_string;
use rdkit_sys::*;

use crate::{Atom, Fingerprint, RWMol};
use crate::{
fingerprint::Fingerprint,
graphmol::{atom::Atom, rw_mol::RWMol},
};

pub struct ROMol {
pub(crate) ptr: cxx::SharedPtr<ro_mol_ffi::ROMol>,
Expand Down
2 changes: 1 addition & 1 deletion src/graphmol/rw_mol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::fmt::Formatter;
use cxx::{let_cxx_string, SharedPtr};
use rdkit_sys::*;

use crate::ROMol;
use crate::graphmol::ro_mol::ROMol;

pub struct RWMol {
pub(crate) ptr: SharedPtr<rdkit_sys::rw_mol_ffi::RWMol>,
Expand Down
Loading
Loading