Dear George, On Sat, Mar 14, 2009 at 9:40 PM, George Oakman <[email protected]> wrote: > Hi All, > > Unsurprisingly, the following C++ code craches: > > ROMol *mol=SmilesToMol("O1c2cc(c(COCCOCCOCCCC)cc2OC1)CCC"); > ROMol *pattern=SmartsToMol("O1c2cc"); > std::vector<MatchVectType> matches; > unsigned int nMatches = SubstructMatch(*mol,*pattern,matches) > > I guess because the SMARTS "O1c2cc" is not a valid SMARTS (unclosed > branches).
That would be my guess too. :-) > > The problem is that at runtime SubstructMatch fires an unhandled exception > (access violation). Rather than letting the exception crash the thread, it > would be better to validate the SMARTS string before sending it to > SubstructMatch. > > Are there any existing ways in the RDKit to do a sanity check on a SMARTS > string in C++? Sure; if the SMARTS parser (or the SMILES parser, or any of the molecule parsers) fails to generate a valid molecule, it returns NULL. so if you just check the return value of SmartsToMol() you should be fine. -greg

