Andreas Maunz wrote: > Hi list, > > this is strictly speaking not an OB question: How can I match a SMARTS > pattern with optional branch? > Example: My compound is "C-C(-O)=C-C". The SMARTS expressions are > s1="[#6]-[#6](-[#8])=[#6]" matches, as well as s2="[#6]-[#6]=[#6]". > Since s2 is contained in s1 in terms of subgraphs, I was thinking about > combining s1 and s2 into a single SMARTS by enforcing the common part > and make the part that solely occurs in s1 (i.e. the branch to oxygen) > optional. > > Is there a way to combine s1 and s2 into a single SMARTS expression? I > know about "([#6]-[#6](-[#8])=[#6],[#6]-[#6]=[#6])", but that is not > what I want. > I want an expression that states: > > carbon - single_edge - carbon - optional(begin) (single_edge oxygen) > optional(end) - double_edge - carbon > > i.e. the optional part is "inside" the SMARTS pattern. Any ideas?
You may be able to do this using recursive SMARTS. In a recursive SMARTS, an atom expression can itself be a whole SMARTS, ad infinitum. And since an atom can be an OR list of alternatives, you can have an atom that is "This OR that", where "this" and "that" are entire SMARTS expressions. I'm not sure if this is what you want, but it might be something like this: [#6]-[$([#6]),$([#6]-[#8])]=[#6] In this case, the second atom in the SMARTS has two comma-separated recursive expressions, [$(...),$(...)], and if the whole expression matches, then the atom is considered a match. But beware of recursion, you have to understand it. The recursive expression matches a SINGLE ATOM, that is, the match of the oxygen is "forgotten" in this case once it's determined that the carbon to which is attached matches. Craig ------------------------------------------------------------------------------ Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day trial. Simplify your report design, integration and deployment - and focus on what you do best, core application coding. Discover what's new with Crystal Reports now. http://p.sf.net/sfu/bobj-july _______________________________________________ OpenBabel-discuss mailing list OpenBabel-discuss@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/openbabel-discuss