recgen_sys/
lib.rs

1#[cxx::bridge()]
2pub mod recgen {
3    unsafe extern "C++" {
4        include!("recgen-sys/src/wrapper.h");
5
6        type Config;
7        fn config_create(
8            db_filepath: &CxxString,
9            in_format: &CxxString,
10        ) -> UniquePtr<Config>;
11        fn config_get_ptable(conf: &UniquePtr<Config>) -> String;
12
13        type Frame;
14        fn frame_create(
15            db_filepath: &CxxString,
16            in_filepath: &CxxString,
17            out_filepath: &CxxString
18        ) -> UniquePtr<Frame>;
19        fn frame_get_n_units(frame: &UniquePtr<Frame>) -> i32;
20        fn build_generate_bfs(
21            db_filepath: &CxxString,
22            in_filepath: &CxxString,
23            out_filepath: &CxxString,
24            verbose: bool
25        ) -> usize;
26        fn build(
27            conf: &UniquePtr<Config>,
28            input: &CxxString,
29            div_idx: usize,
30            div_all: usize
31        ) -> Vec<String>;
32    }
33}
34
35#[cfg(test)]
36mod tests {
37    use super::*;
38
39    #[test]
40    fn test_config() {
41        cxx::let_cxx_string!(db_filepath = "deps/ReCGen/examples/example.db");
42        cxx::let_cxx_string!(in_format = "mol");
43        let conf = recgen::config_create(&db_filepath, &in_format);
44        assert_eq!(recgen::config_get_ptable(&conf), "frag".to_string());
45    }
46
47    #[test]
48    fn test_frame_n_unit() {
49        let results: Vec<i32> = vec![2, 3, 3, 3, 4];
50        cxx::let_cxx_string!(db_filepath = "deps/ReCGen/examples/example.db");
51        cxx::let_cxx_string!(out_filepath = "deps/ReCGen/examples/output.smi");
52        for idx in 0..5 {
53            cxx::let_cxx_string!(in_filepath = format!("deps/ReCGen/examples/sample{}.mol", idx + 1));
54            let frame = recgen::frame_create(&db_filepath, &in_filepath, &out_filepath);
55            assert_eq!(recgen::frame_get_n_units(&frame), results[idx]);
56        }
57    }
58
59    #[test]
60    fn test_build_generate_bfs() {
61        // cxx::let_cxx_string!(db_filepath = "deps/ReCGen/examples/example.db");
62        cxx::let_cxx_string!(db_filepath = "../../../data/recgen/DB/DrugBank_M.db");
63        cxx::let_cxx_string!(out_filepath = "deps/ReCGen/examples/output.smi");
64        // let results: Vec<usize> = vec![2, 2, 0, 0, 0];
65        let results: Vec<usize> = vec![1133, 0, 0, 33, 0]; // the others take long duration of computation
66        // for idx in vec![1, 2, 3, 4, 5] {
67        for idx in vec![1, 4] {
68            cxx::let_cxx_string!(in_filepath = format!("deps/ReCGen/examples/sample{}.mol", idx));
69            assert_eq!(results[idx - 1], recgen::build_generate_bfs(&db_filepath, &in_filepath, &out_filepath, false));
70        }
71    }
72}