enter image description here

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.

  • 1
    $\begingroup$ 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 $\endgroup$ – Geoff Hutchison Apr 29 at 19:36
  • $\begingroup$ @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 $\endgroup$ – Theophylline Apr 29 at 21:09
  • $\begingroup$ I believe a duplicate here: chemistry.stackexchange.com/questions/150737/… $\endgroup$ – Shoubhik R Maiti May 1 at 11:14

Your SMARTS works.

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')



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


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.