The thread indicated in the comment by @andselisk dates back to July 2014. It may be condensed to
"A substructure querying with openbabel
requires a good SMARTS string. In case you don't have one, often a good SMILES string may be used instead of a SMARTS string, too."
A check for a rather simple molecular structure of (benzylsulfinyl)benzene

there is more than one way to describe it in either form of a SMARTS, or a SMILES string. Consequently, the strings per se sometimes differ from each other. Consequently, recognizing the relevant entries in the collection of .mol2
with openbabel
sometimes failed.
Below I summerize (status: 2019-May-15) a few experiences: the string offered by the software, its type, and source; eventually, if it worked (i.e., entries retrieved), or not (i.e., entries not retrieved) in a small test set of 419 model data and 7 relevant hits.
|-------------------------------------+--------+--------------------+--------|
| entry | type | source | status |
|-------------------------------------+--------+--------------------+--------|
| c1ccccc1-[#6]-[#16](-c2ccccc2)=[#8] | SMARTS | pubChemSketcher | works |
| C1=CC=CC=C1C[S](C2=CC=CC=C2)=O | SMILES | pubChemSketcher | fails |
|-------------------------------------+--------+--------------------+--------|
| O=S(Cc1ccccc1)c2ccccc2 | SMILES | ACD ChemSketch | works |
|-------------------------------------+--------+--------------------+--------|
| C1=CC=C(C=C1)CS(C(C=CC1)=CC=1)=O | SMILES | ChemDoodle | fails |
|-------------------------------------+--------+--------------------+--------|
| O=S(C1=CC=CC=C1)CC2=CC=CC=C2 | SMILES | ChemDraw Pro12 | fails |
|-------------------------------------+--------+--------------------+--------|
| O=S(CC1=CC=CC=C1)C1=CC=CC=C1 | SMILES | Marvin JS | fails |
|-------------------------------------+--------+--------------------+--------|
| O=S(Cc1ccccc1)c2ccccc2 | SMILES | Peter Ertl JSME | works |
|-------------------------------------+--------+--------------------+--------|
| c1cccc(c1)CS(=O)c1ccccc1 | SMILES | openbabel, default | works |
| c1ccc(cc1)CS(=O)c1ccccc1 | SMILES | dito, universal | works |
| c1ccc(cc1)CS(=O)c1ccccc1 | SMILES | dito, Inchified | works |
| O=S(c1ccccc1)Cc1ccccc1 | SMILES | dito, canonical | works |
|-------------------------------------+--------+--------------------+--------|
PubChem Sketcher: version 2.4, https://pubchem.ncbi.nlm.nih.gov/edit2/index.html
ACD ChemSketch: Freeeware version 2015
ChemDoodle: version 8.1.0, 2019 and webcomponents,
https://web.chemdoodle.com/demos/sketcher/
ChemDraw: version 12 Pro, (then) CambridgeSoft, 2009
Marvin JS: ChemAxon, v19.11.0, on-line test at
https://marvinjs-demo.chemaxon.com/latest/
Its SMARTS (very differently written) equally failed:
O=S([#6]-[#6]-1=[#6]-[#6]=[#6]-[#6]=[#6]-1)[#6]-1=[#6]-[#6]=[#6]-[#6]=[#6]-1
Peter Ertl JSME: https://peter-ertl.com/jsme/JSME_2017-02-26/
Addition:
The approach mentioned in the question basically calls babel
(or òpenbabel
) as an iteration per file. Especially if the data set is accessed more than once to identify different structures, and / or consists of multiple thousand models, this may be tediously slow. Instead, it is worth to "bundle" the individual information
babel *.mol2 mymols.sdf --unique
creating a container like a multi-model .mol2
(this even works with .xyz
files as input). The .sdf
may be indexed
babel mymols.sdf -ofs
by fingerprints (cf. chapter 5 of the manual). Now, very quickly the names of the files about a strucure matching the query substructure are identifed, e.g.
babel mymols.fs -ifs -s"O=S(c1ccccc1)Cc1ccccc1" results.smi -xt
and stored in results.smi
. Consequently, any further work may focus on them.
babel
is the old interface. The recommendobabel
instead now. See openbabel.org/docs/dev/Command-line_tools/… $\endgroup$ – Martin - マーチン♦ May 15 '19 at 14:34