Skip to content

Commit

Permalink
added constructor for periodic table and fixed typo for tests in peri…
Browse files Browse the repository at this point in the history
…odic table
  • Loading branch information
mvisani committed Oct 10, 2024
1 parent 07c2251 commit 7e3c57b
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 1 deletion.
1 change: 1 addition & 0 deletions rdkit-sys/src/bridge/periodic_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ pub mod ffi {
unsafe extern "C++" {
type PeriodicTable;
include!("wrapper/include/periodic_table.h");
pub fn get_periodic_table() -> UniquePtr<PeriodicTable>;
pub fn get_valence_list(atomic_number: u32) -> &'static CxxVector<i32>;
pub fn getMostCommonIsotopeMass(self: &PeriodicTable, atom: &CxxString) -> f64;
}
Expand Down
3 changes: 2 additions & 1 deletion rdkit-sys/tests/test_periodic_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ fn test_get_valence_list() {
#[test]
fn test_get_monoisotopic_mass() {
let_cxx_string!(atom = "C");
let mass = rdkit_sys::periodic_table_ffi::get_most_common_isotope_mass(&atom);
let periodic_table = rdkit_sys::periodic_table_ffi::get_periodic_table();
let mass = periodic_table.getMostCommonIsotopeMass(&atom);
assert_eq!(mass, 12.00);
}
1 change: 1 addition & 0 deletions rdkit-sys/wrapper/include/periodic_table.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <GraphMol/PeriodicTable.h>

namespace RDKit {
std::unique_ptr<PeriodicTable> get_periodic_table();
const std::vector<int> &get_valence_list(unsigned int atomic_number);
// double get_most_common_isotope_mass(const std::string &symbol);
} // namespace RDKit
7 changes: 7 additions & 0 deletions rdkit-sys/wrapper/src/periodic_table.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@
#include <rdkit/GraphMol/PeriodicTable.h>

namespace RDKit {
std::unique_ptr<PeriodicTable> get_periodic_table() {
// in rdkit we have the following:
// PeriodicTable::getTable() return : const PeriodicTable*
// so we need to take into account that it is a const pointer
return std::make_unique<PeriodicTable>(*PeriodicTable::getTable());
}

const std::vector<int> &get_valence_list(unsigned int atomic_number) {
PeriodicTable *pt = RDKit::PeriodicTable::getTable();
return pt->getValenceList(atomic_number);
Expand Down

0 comments on commit 7e3c57b

Please sign in to comment.