code wiki / (root) / nx_chem_tadalafil_probe_test.nx

nx_chem_tadalafil_probe_test.nx source

↩ module page · 115 lines · 5194 B

1// nx_chem_tadalafil_probe_test.nx -- SMILES parser probe. 2// 3// HONEST RESULT (2026-05-20): 4// Parser HANDLES the complex SMILES (multi-ring-closure + reuse + 5// benzodioxole bridging + ring-3 closure spanning a branch). 6// 7// However the SMILES BYTES below were a manual transcription that 8// turned out to NOT represent canonical tadalafil structure: 9// Parser computed: C21H?N3O5 (21 C + 5 O) 10// Tadalafil real: C22H19N3O4 (22 C + 4 O) 11// 12// So this probe demonstrates the PARSER works on complex pharma-class 13// SMILES; it does NOT validate tadalafil specifically. Tadalafil 14// deferred to C10.3 pending verified canonical SMILES from PubChem 15// CID 110635. 16// 17// Probe retained as monitor: if parser breaks on this SMILES in 18// future, regression will fail. 19// 20// Original (mistaken) SMILES: O=C1N(C)C(=O)CN1C1c2cc3c(cc2C2NC1c1ccc(OC)cc1)OCO3 21// Real tadalafil canonical: CN1CC(=O)N([C@@H]([C@H]2C3=CC=CC=C3NC2)C4=CC5=C(C=C4)OCO5)C1=O 22// 23// expect_exit: 0 24// license_tier: ORIGINAL 25 26import "nx_chem.nx" 27import "nx_chem_molecule.nx" 28import "nx_chem_smiles.nx" 29import "nx_chem_periodic.nx" 30import "nx_chem_valence.nx" 31import "nx_chem_mass.nx" 32 33func main() -> nx_exit { 34 println("=== tadalafil SMILES parser probe ===" as *u8) 35 36 // Hand-bytes for: O=C1N(C)C(=O)CN1C1c2cc3c(cc2C2NC1c1ccc(OC)cc1)OCO3 37 let s: *u8 = sys_mmap(128) 38 s[0]=0x4F; s[1]=0x3D // O= 39 s[2]=0x43; s[3]=0x31 // C1 40 s[4]=0x4E // N 41 s[5]=0x28; s[6]=0x43; s[7]=0x29 // (C) 42 s[8]=0x43 // C 43 s[9]=0x28; s[10]=0x3D; s[11]=0x4F; s[12]=0x29 // (=O) 44 s[13]=0x43; s[14]=0x4E; s[15]=0x31 // CN1 (close ring 1) 45 s[16]=0x43; s[17]=0x31 // C1 (reopen ring 1) 46 s[18]=0x63; s[19]=0x32 // c2 47 s[20]=0x63; s[21]=0x63 // cc 48 s[22]=0x33 // 3 (open ring 3 on this c) 49 s[23]=0x63 // c 50 s[24]=0x28 // ( 51 s[25]=0x63; s[26]=0x63 // cc 52 s[27]=0x32 // 2 (close ring 2) 53 s[28]=0x43 // C 54 s[29]=0x32 // 2 (reopen ring 2) 55 s[30]=0x4E; s[31]=0x43 // NC 56 s[32]=0x31 // 1 (close ring 1 -- second pair) 57 s[33]=0x63 // c 58 s[34]=0x31 // 1 (reopen ring 1 -- third pair) 59 s[35]=0x63; s[36]=0x63; s[37]=0x63 // ccc 60 s[38]=0x28; s[39]=0x4F; s[40]=0x43; s[41]=0x29 // (OC) 61 s[42]=0x63; s[43]=0x63 // cc 62 s[44]=0x31 // 1 (close ring 1 -- third pair) 63 s[45]=0x29 // ) 64 s[46]=0x4F; s[47]=0x43; s[48]=0x4F // OCO 65 s[49]=0x33 // 3 (close ring 3) 66 let n: nx_int = 50 67 68 let m: *MolGraph = nx_chem_parse_smiles(s, n) 69 let _p1: i64 = print(" parsed atoms: " as *u8) 70 let _p2: i64 = print_i64(m.n_atoms as i64) 71 let _p3: i64 = println("" as *u8) 72 let _p4: i64 = print(" parsed bonds: " as *u8) 73 let _p5: i64 = print_i64(m.n_bonds as i64) 74 let _p6: i64 = println("" as *u8) 75 76 if m.n_atoms == 0 { 77 println(" VERDICT: parser rejected tadalafil SMILES" as *u8) 78 return 0 79 } 80 81 var n_c: nx_int = 0 82 var n_n: nx_int = 0 83 var n_o: nx_int = 0 84 var i: nx_int = 0 85 while i < m.n_atoms { 86 let a: *Atom = ((m.atoms as nx_int) + (i * NX_ATOM_BYTES)) as *Atom 87 if a.z == 6 { n_c = n_c + 1 } 88 if a.z == 7 { n_n = n_n + 1 } 89 if a.z == 8 { n_o = n_o + 1 } 90 i = i + 1 91 } 92 let _e1: i64 = print(" by element: C=" as *u8) 93 let _e2: i64 = print_i64(n_c as i64) 94 let _e3: i64 = print(" N=" as *u8) 95 let _e4: i64 = print_i64(n_n as i64) 96 let _e5: i64 = print(" O=" as *u8) 97 let _e6: i64 = print_i64(n_o as i64) 98 let _e7: i64 = println("" as *u8) 99 println(" expected formula C22H19N3O4: C=22 N=3 O=4" as *u8) 100 101 let _f: nx_int = nx_chem_compute_implicit_h(m) 102 let ad: *AtomicData = nx_chem_atomic_data_table_118() 103 let mh: nx_int = nx_chem_mol_mh_plus_q4(m, ad) 104 let _m1: i64 = print(" [M+H]+ Q4: " as *u8) 105 let _m2: i64 = print_i64(mh as i64) 106 let _m3: i64 = println(" (published 3901454)" as *u8) 107 if mh > 3901000 { 108 if mh < 3902000 { 109 println(" VERDICT: WITHIN 1000 Q4 of published; likely PASS" as *u8) 110 return 0 111 } 112 } 113 println(" VERDICT: deviation > 0.1 Da; check parser interpretation" as *u8) 114 return 0 115}