Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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: 2 additions & 1 deletion AUTHORS
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
Xavier Lange (xrlange@gmail.com)
chrissly31415
Axel Pahl (apahl)
Axel Pahl (apahl)
Benjamin Smith
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "rdkit-sys"
authors = ["Xavier Lange (xrlange@gmail.com)", "chrissly31415"]
authors = ["Xavier Lange (xrlange@gmail.com)", "chrissly31415", "Benjamin Smith"]
version = "0.3.0"
edition = "2021"
license = "MIT"
Expand All @@ -21,3 +21,4 @@ which = "4.2.5"
[features]
default = []
dynamic-linking-from-conda = []
inchi = []
4 changes: 4 additions & 0 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,5 +138,9 @@ fn main() {
println!("cargo:rustc-link-lib=dylib=RDKit{}", lib);
}

if cfg!(feature = "inchi") {
println!("cargo:rustc-link-lib=dylib=RDKitRDInchiLib");
}

println!("cargo:rustc-link-lib=dylib=boost_serialization");
}
14 changes: 14 additions & 0 deletions src/bridge/inchi.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#[cxx::bridge(namespace = "RDKit")]
pub mod ffi {
unsafe extern "C++" {
include!("wrapper/include/ro_mol.h");
include!("wrapper/include/inchi.h");

pub type ROMol = crate::ro_mol_ffi::ROMol;

pub fn mol_to_inchi(mol: SharedPtr<ROMol>) -> String;
pub fn inchi_to_mol(inchi: &CxxString) -> Result<SharedPtr<ROMol>>;

pub fn inchi_to_inchi_key(inchi: &CxxString) -> Result<String>;
}
}
5 changes: 5 additions & 0 deletions src/bridge/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ pub use descriptors::ffi as descriptors_ffi;
mod fingerprint;
pub use fingerprint::ffi as fingerprint_ffi;

#[cfg(feature = "inchi")]
mod inchi;
#[cfg(feature = "inchi")]
pub use inchi::ffi as inchi_ffi;

mod mol_standardize;
pub use mol_standardize::ffi as mol_standardize_ffi;

Expand Down
44 changes: 44 additions & 0 deletions tests/test_inchi.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#[test]
#[cfg(feature = "inchi")]
fn test_mol_to_inchi() {
cxx::let_cxx_string!(smile = "C");
let romol = rdkit_sys::ro_mol_ffi::smiles_to_mol(&smile).unwrap();
let inchi = rdkit_sys::inchi_ffi::mol_to_inchi(romol);
assert_eq!(inchi, "InChI=1S/CH4/h1H4");
}

#[test]
#[cfg(feature = "inchi")]
fn test_good_inchi_to_mol() {
cxx::let_cxx_string!(inchi = "InChI=1S/C2H6/c1-2/h1-2H3");
let romol = rdkit_sys::inchi_ffi::inchi_to_mol(&inchi).unwrap();
assert!(!romol.is_null());
assert_eq!(rdkit_sys::inchi_ffi::mol_to_inchi(romol.clone()), "InChI=1S/C2H6/c1-2/h1-2H3");
assert_eq!(rdkit_sys::ro_mol_ffi::mol_to_smiles(romol), "CC");
}

#[test]
#[cfg(feature = "inchi")]
fn test_bad_inchi_to_mol() {
cxx::let_cxx_string!(bad_inchi = "asd");
let romol = rdkit_sys::inchi_ffi::inchi_to_mol(&bad_inchi);
assert!(romol.is_ok());
assert!(romol.unwrap().is_null());
}

#[test]
#[cfg(feature = "inchi")]
fn test_good_inchi_to_inchi_key() {
cxx::let_cxx_string!(inchi = "InChI=1S/CH4/h1H4");
let inchi_key = rdkit_sys::inchi_ffi::inchi_to_inchi_key(&inchi).unwrap();
assert_eq!(inchi_key, "VNWKTOKETHGBQD-UHFFFAOYSA-N");
}

#[test]
#[cfg(feature = "inchi")]
fn test_bad_inchi_to_inchi_key() {
cxx::let_cxx_string!(bad_inchi = "asd");
let inchi_key = rdkit_sys::inchi_ffi::inchi_to_inchi_key(&bad_inchi);
assert!(inchi_key.is_ok());
assert!(inchi_key.unwrap().is_empty());
}
10 changes: 10 additions & 0 deletions wrapper/include/inchi.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#pragma once

#include "rust/cxx.h"

namespace RDKit {
rust::String mol_to_inchi(std::shared_ptr<ROMol> mol);
std::shared_ptr<ROMol> inchi_to_mol(const std::string &inchi);

rust::String inchi_to_inchi_key(const std::string &inchi);
}
19 changes: 19 additions & 0 deletions wrapper/src/inchi.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#include "rust/cxx.h"
#include <GraphMol/inchi.h>

namespace RDKit {
rust::String mol_to_inchi(std::shared_ptr<ROMol> mol) {
ExtraInchiReturnValues rv;
return MolToInchi(*mol, rv, "");
}

std::shared_ptr<ROMol> inchi_to_mol(const std::string &inchi) {
ExtraInchiReturnValues rv;
ROMol *mol = InchiToMol(inchi, rv);
return std::shared_ptr<ROMol>(mol);
}

rust::String inchi_to_inchi_key(const std::string &inchi) {
return InchiToInchiKey(inchi);
}
}