# Functional group detection from geometry

I am currently looking for an efficient way to detect common functional groups - that is, characterize whether a molecule is an alcohol, an aromatic compound, etc. - in a larger database consisting of xyz geometry files. Is there an existing tool out there that could do this task?

I am aware that the task is not well-defined, since connectivity between different atoms is always up to some empiricism in an xyz file. Moreover, the definition of functional groups is also not super obvious. However, I am aware of tools that would categorize a structure based on a connectivity matrix (such as checkmol), and converting an xyz file to a connectivity matrix should also be a solved issue (for example all visualization softwares seem to do it). It might also be very well possible that such operation is contained in OpenBabel or a similar bundle, I am just not completely familiar with these tools, and I would rather not invest days, or weeks, writing scripts that might already be out there.

Has someone worked on a problem like this, or do you know how to automatically detect functional groups from Cartesian geometry?

EDIT:

Based on the excellent answer below, I've compiled a rudimentary Bash script that sort of does what I wanted it to do. I am sharing it now, as it might be helpful for others

XYZ_DIR=/directory_to_xyz
MOLDIR=/output_of_mols
GROUPDIR=/output_of_groups

for file in $$XYZ_DIR/*xyz; do obabel$$file -omol -O $${file%.xyz}.mol 2> >(grep -v "onvert") ./checkmol$${file%.xyz}.mol > $${file%.xyz}.groups mv$${file%.xyz}.mol $$MOLDIR/ mv$${file%.xyz}.groups \$GROUPDIR
done


Note that the OpenBabel output has been supressed when the conversion is succesfull so as not to clutter the screen.

• @ShoubhikRMaiti - while RDKit has SMILES / SMARTS, it doesn't natively support XYZ because there are no bonds / bond orders / formal charges in an XYZ file. Apr 19 at 16:25

You can probably do it with only OpenBabel or RDKit using SMARTS search strings, but you can get a much easier solution if you combine OpenBabel with checkmol (which you have mentioned in the question).

First, convert the .xyz file into a .mol file that checkmol can recognize. This can be done with Openbabel which can automatically detect bonds from 3D coordinates:

obabel input.xyz -omol -O output.mol


Then use checkmol on the generated .mol file:

checkmol -e output.mol


The -e flag gives you the names of the functional groups in English (as in "carboxylic acid", "lactam" etc.). If you want to use that output somewhere else, you can use the -c flag instead, which will return codes of each functional group. The table of functional groups and their codes can be found here. (link obtained from checkmol homepage)

For example, running the programs on penicilin gives:

>obabel penicilin.xyz -omol -O penicilin.mol

>checkmol -e penicilin.mol

hemithioaminal
carboxylic acid
secondary carboxylic acid amide
tertiary carboxylic acid amide
lactam
aromatic compound
heterocyclic compound


If you have a large number of .xyz files to process, then you can automate them with a shell/batch script. On Windows, you can use something like this:

@echo off
for /f %%f in ('dir /b .\*.xyz') do @(
echo Converting %%f to %%~nf.mol
obabel .\%%f -omol -O .\%%~nf.mol >NUL 2>NUL
echo Writing functional group codes to %%~nf.txt
checkmol -c .\%%~nf.mol > .\%%~nf.txt
erase /Q .\%%~nf.mol >NUL)


Save this as a .bat file, and then run it inside the folder with .xyz files. It will convert each file into .mol, then use checkmol on it, save the functional group codes in a .txt file and then erase the .mol file. The >NUL and 2>NUL flags suppress stdout and stderr (i.e. output and error output) respectively. I added this as OpenBabel for some reason gives a lot of warnings during conversion, even though the .mol file is created successfully. If you are getting unknown errors, then remove those flags to see full output.

(Of course, the openbabel and checkmol executable has to be in PATH for the script to work)

I don't know much about Linux and Mac OS scripting so I can't help there.

OpenBabel: http://openbabel.org/wiki/Main_Page