# Excluding certain sp3-hybridized carbons with SMARTS

Let's say I have a compound shown above (SMILES: CCC(F)(F)F), and I want to exclude the trifluoromethyl group with SMARTS, how would I do that? I have tried [CX4;!$(C(F)(F)F)] but it does not exclude C(F)(F)F according to RDKit: molecule = Chem.MolFromSmiles('CCC(F)(F)F') pattern = Chem.MolFromSmarts('[CX4;!$(C(F)(F)F)]')
molecule.HasSubstructMatch(pattern) --> expected False, but returns True


I think the recursive portion is written incorrectly but I'm not sure how to correct it.

• In your code, the SMARTS reads [CX4;!$(C(F)(F)F)] with ; not & I don't have time to investigate, but SMARTS viewer is usually helpful for these: smarts.plus – Geoff Hutchison Apr 29 at 19:36 • @GeoffHutchison Ah sorry, I corrected it to avoid confusion. I actually tried several variations of the SMARTS patterns and none of them worked. Based on the SMARTS viewer [CX4;!$(C(F)(F)F)] looks correct, but clearly I'm missing something – Theophylline Apr 29 at 21:09
• I believe a duplicate here: chemistry.stackexchange.com/questions/150737/… – Shoubhik R Maiti May 1 at 11:14

To see what a SMARTS finds, it is always a good idea to depict the result.

from rdkit import Chem
from rdkit.Chem.Draw import IPythonConsole

patt = Chem.MolFromSmarts('[CX4;!\$(C(F)(F)F)]')

m = Chem.MolFromSmiles('CCC(F)(F)F')

m.GetSubstructMatches(patt)
m


The SMARTS should find all Carbons with 4 connections (implicit Hydrogen count), but not (C(F)(F)F). That is why HasSubstructMatch returns True.