# SMARTS: distinguish between alcohol and carboxylic acid

I'm new to SMARTS and have to identify substructures with the Python package rdkit, so far so good. Let's say I have a SMILES with an carboxylic acid and a alcohol such as

OC(C1=CC(CO)=CC=C1)=O


and I want to get only the alcohol, then I would try something like this:

    mol = Chem.MolFromSmiles("OC(C1=CC(CO)=CC=C1)=O")
toSearch = Chem.MolFromSmarts("[#6][OX2H]")
bool = mol.HasSubstructMatch(toSearch)
subStruct = mol.GetSubstructMatches(toSearch)
print(bool)
print(subStruct)


which would return:

True
((1, 0), (5, 6))


However, the substructure search also identifies the OH of the acid which I don't want. How can I exclude that? My idea was to use some kind of recursive smarts for the alcohol to exclude all those "alcohols" where the carbon is bonded to another oxygen like "=O".

New contributor
dideldideldum is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.
• Hello! You may also be interested in the Matter Modeling 'sister site'. (though please don't post questions twice) Aug 5 at 16:03

The simplest change to make for your SMARTS pattern would be specifying the total degree of the attached carbon is 4 with "[#6X4][OX2H]". This is enough to discriminate against the carboxylic acid.
The SMARTS pattern is "[OX2H][CX4;!$(C([OX2H])[O,S,#7,#15])]", which stipulates that the carbon attached to the oxygen not also be connected to O, S, N, or P. I made a little interactive widget that takes a molecule name or SMILES in the first field and a SMARTS pattern in the second. • Awesome!!!! Thanks for the answer and the two great links! I have one more question. This smart doesn't hit if the alcohol is on an aromatic carbon. In this Case this smarts "[OX2H][CX4,c;!$(C([OX2H])[O,S,#7,#15])]" should work, shouldn't it? thx! Aug 6 at 13:37