use cxx::{let_cxx_string, SharedPtr}; use rdkit_sys::{ro_mol_ffi::ROMol, rw_mol_ffi::RWMol}; #[test] fn test_rw_mol_from_smarts() { cxx::let_cxx_string!(smarts = "[+1!h0!$([*]~[-1,-2,-3,-4]),-1!$([*]~[+1,+2,+3,+4])]"); let rwmol = rdkit_sys::rw_mol_ffi::smarts_to_mol(&smarts).unwrap(); let romol = rdkit_sys::rw_mol_ffi::rw_mol_to_ro_mol(rwmol); let smiles = rdkit_sys::ro_mol_ffi::mol_to_smiles(&romol); assert_eq!(smiles, "*".to_string()); } #[test] fn test_rw_mol_from_mol_block() { let mol_block = r#"1 -OEChem-05172223082D 31 30 0 1 0 0 0 0 0999 V2000 2.8660 0.7500 0.0000 O 0 0 0 0 0 0 0 0 0 0 0 0 2.8660 -2.2500 0.0000 O 0 5 0 0 0 0 0 0 0 0 0 0 2.0000 -0.7500 0.0000 O 0 0 0 0 0 0 0 0 0 0 0 0 3.7320 2.2500 0.0000 O 0 0 0 0 0 0 0 0 0 0 0 0 5.4641 0.2500 0.0000 N 0 3 0 0 0 0 0 0 0 0 0 0 4.5981 0.7500 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 3.7320 0.2500 0.0000 C 0 0 3 0 0 0 0 0 0 0 0 0 6.3301 -0.2500 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 5.9641 1.1160 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 4.9641 -0.6160 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 3.7320 -0.7500 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 2.8660 -1.2500 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 2.8660 1.7500 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 2.0000 2.2500 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 4.9966 1.2250 0.0000 H 0 0 0 0 0 0 0 0 0 0 0 0 4.1996 1.2250 0.0000 H 0 0 0 0 0 0 0 0 0 0 0 0 3.7320 0.8700 0.0000 H 0 0 0 0 0 0 0 0 0 0 0 0 6.0201 -0.7869 0.0000 H 0 0 0 0 0 0 0 0 0 0 0 0 6.8671 -0.5600 0.0000 H 0 0 0 0 0 0 0 0 0 0 0 0 6.6401 0.2869 0.0000 H 0 0 0 0 0 0 0 0 0 0 0 0 6.5010 0.8060 0.0000 H 0 0 0 0 0 0 0 0 0 0 0 0 6.2741 1.6530 0.0000 H 0 0 0 0 0 0 0 0 0 0 0 0 5.4272 1.4260 0.0000 H 0 0 0 0 0 0 0 0 0 0 0 0 4.4272 -0.3060 0.0000 H 0 0 0 0 0 0 0 0 0 0 0 0 4.6541 -1.1530 0.0000 H 0 0 0 0 0 0 0 0 0 0 0 0 5.5010 -0.9260 0.0000 H 0 0 0 0 0 0 0 0 0 0 0 0 3.9441 -1.3326 0.0000 H 0 0 0 0 0 0 0 0 0 0 0 0 4.3426 -0.6423 0.0000 H 0 0 0 0 0 0 0 0 0 0 0 0 2.3100 2.7869 0.0000 H 0 0 0 0 0 0 0 0 0 0 0 0 1.4631 2.5600 0.0000 H 0 0 0 0 0 0 0 0 0 0 0 0 1.6900 1.7131 0.0000 H 0 0 0 0 0 0 0 0 0 0 0 0 1 7 1 0 0 0 0 1 13 1 0 0 0 0 2 12 1 0 0 0 0 3 12 2 0 0 0 0 4 13 2 0 0 0 0 5 6 1 0 0 0 0 5 8 1 0 0 0 0 5 9 1 0 0 0 0 5 10 1 0 0 0 0 6 7 1 0 0 0 0 6 15 1 0 0 0 0 6 16 1 0 0 0 0 7 11 1 0 0 0 0 7 17 1 0 0 0 0 8 18 1 0 0 0 0 8 19 1 0 0 0 0 8 20 1 0 0 0 0 9 21 1 0 0 0 0 9 22 1 0 0 0 0 9 23 1 0 0 0 0 10 24 1 0 0 0 0 10 25 1 0 0 0 0 10 26 1 0 0 0 0 11 12 1 0 0 0 0 11 27 1 0 0 0 0 11 28 1 0 0 0 0 13 14 1 0 0 0 0 14 29 1 0 0 0 0 14 30 1 0 0 0 0 14 31 1 0 0 0 0 M CHG 2 2 -1 5 1 M END > 1 > 1 > 214 > 4 > 0 > 5 > AAADceByOAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAHgAAAAAACBThgAYCCAMABAAIAACQCAAAAAAAAAAAAAEIAAACABQAgAAHAAAFIAAQAAAkAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA== > 3-acetoxy-4-(trimethylammonio)butanoate > 3-acetyloxy-4-(trimethylammonio)butanoate > 3-acetyloxy-4-(trimethylazaniumyl)butanoate > 3-acetyloxy-4-(trimethylazaniumyl)butanoate > 3-acetyloxy-4-(trimethylazaniumyl)butanoate > 3-acetoxy-4-(trimethylammonio)butyrate > InChI=1S/C9H17NO4/c1-7(11)14-8(5-9(12)13)6-10(2,3)4/h8H,5-6H2,1-4H3 > RDHQFKQIGNGIED-UHFFFAOYSA-N > 0.4 > 203.11575802 > C9H17NO4 > 203.24 > CC(=O)OC(CC(=O)[O-])C[N+](C)(C)C > CC(=O)OC(CC(=O)[O-])C[N+](C)(C)C > 66.4 > 203.11575802 > 0 > 14 > 0 > 1 > 0 > 0 > 0 > 1 > 1 > 1 5 255 > 7 11 3 "#; let_cxx_string!(mol_block = mol_block); let rw_mol = rdkit_sys::rw_mol_ffi::rw_mol_from_mol_block(&mol_block, false, false, false); let ro_mol = unsafe { std::mem::transmute::, SharedPtr>(rw_mol) }; let smiles = rdkit_sys::ro_mol_ffi::mol_to_smiles(&ro_mol); assert_eq!("[H]C([H])([H])C(=O)OC([H])(C([H])([H])C(=O)[O-])C([H])([H])[N+](C([H])([H])[H])(C([H])([H])[H])C([H])([H])[H]", &smiles); } #[test] fn test_bad_mol_block() { let bad = r#"24258 -OEChem-02132200252D 5 4 0 0 0 0 0 0 0999 V2000 2.8660 0.0000 0.0000 Cl 0 0 0 0 0 0 0 0 0 0 0 0 3.7320 0.5000 0.0000 F 0 0 0 0 0 0 0 0 0 0 0 0 2.0000 -0.5000 0.0000 O 0 0 0 0 0 0 0 0 0 0 0 0 2.3660 0.8660 0.0000 O 0 0 0 0 0 0 0 0 0 0 0 0 3.3660 -0.8660 0.0000 O 0 0 0 0 0 0 0 0 0 0 0 0 1 2 1 0 0 0 0 1 3 2 0 0 0 0 1 4 2 0 0 0 0 1 5 2 0 0 0 0 M END > 24258 > 1 > 117 > 4 > 0 > 0 > AAADcQAAMQAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA== > perchloryl fluoride > perchloryl fluoride > perchloryl fluoride > perchloryl fluoride > perchloryl fluoride > perchloryl fluoride > InChI=1S/ClFO3/c2-1(3,4)5 > XHFXMNZYIKFCPN-UHFFFAOYSA-N > 3.3 > 101.9519997 > ClFO3 > 102.45 > O=Cl(=O)(=O)F > O=Cl(=O)(=O)F > 51.2 > 101.9519997 > 0 > 5 > 0 > 0 > 0 > 0 > 0 > 1 > 1 > 1 5 255 $"#; let_cxx_string!(bad = bad); let mol = { let mut mol = rdkit_sys::rw_mol_ffi::rw_mol_from_mol_block(&bad, true, false, false); if mol.is_null() { mol = rdkit_sys::rw_mol_ffi::rw_mol_from_mol_block(&bad, false, false, false); } mol }; assert!(!mol.is_null()); // println!("{}", mol.as_smile()); }