Hi,

Thank you for your answer. Since I have posted this question, I have
realized that it can not be done with obabel directly, so I have
looked into the API. I am using C++ and not python and I have found
recently the following way of doing it:

OpenBabel::OBConversion obconversion;
OpenBabel::OBMol mol;
obconversion.SetInFormat("smi");

OpenBabel::OBSmartsPattern smarts;
smarts.Init("XXX"); // The wanted pattern
vector<vector<int> > maplist;
int total = 0;
bool notatend = obconversion.ReadFile(&mol,"Library.smi");
while (notatend) {
     smarts.Match(mol);
     maplist = smarts.GetUMapList();
     total += maplist.size();
     mol.Clear();
     notatend = obconversion.Read(&mol);
     }
cout << "Number of iterations " << total << endl;


It gives me the same value as other chemoinformatic tools I am using.

Nicolas


2014-04-17 4:17 GMT-04:00 Pascal Muller <pascal.jm.mul...@gmail.com>:
> Hi,
>
>
>>
>> I am trying to count how many times a given moiety can be found in a
>> database.
>
> (...)
>>
>> If not, how can it be done with the API?
>>
>
>
> You could try something like this, with pybel:
>
>
> #!/usr/bin/env python
> import sys
> import pybel
>
> # ref :
> #  O=C(NCCCC1CCCC1)c1cccc(c1)C(=O)N moldId
>
> substruct = "NC=O"
> substructSmart = pybel.Smarts(substruct)
>
> for mol in pybel.readfile("smi", sys.argv[1]):
>     subtructCount = len(substructSmart.findall(mol))     # That's the data
> you're wanting
>     print substruct, ":", subtructCount, "in", mol.OBMol.GetTitle()
>
>
>
> Output:
> NC=O : 2 in molId
>
> Is it ok for you?
>
> Regards,
> Pascal

------------------------------------------------------------------------------
Learn Graph Databases - Download FREE O'Reilly Book
"Graph Databases" is the definitive new guide to graph databases and their
applications. Written by three acclaimed leaders in the field,
this first edition is now available. Download your free book today!
http://p.sf.net/sfu/NeoTech
_______________________________________________
OpenBabel-discuss mailing list
OpenBabel-discuss@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/openbabel-discuss

Reply via email to