On 18/12/2010 13:23, Carsten Niehaus wrote: > Moin moin > > I am coding an c++-application using OpenBabel for the chemistry. > > I am using chem-file.sf.net as the database. > > > I would like to check if a given file is for example an alcohol or a > ketone. So far I think that I could use obgrep for this: > > obgrep 'OH' foo.smi > > for alcohols, but I'd like to use the c++-API and furthermore I have > either mol- or cml-file, but not .smi files. > > Is this possible using cml or mol-file? > > > Thanks, > > Carsten > > PS: Only the 2.2.x-API is available, the 2.3.0 has not been generated to > far (it seems): http://openbabel.org/api/2.2.0/index.shtml
Maybe what you want is http://openbabel.org/dev-api/ In data/SMARTS_InteLigand.txt is an extensive list of SMARTS patterns to match functional groups. Use on the command line or via the API. The following has no error checking and is untested, but should point you in the right direction. std::string smarts(...); std::string filename; ifstream ifs(filename.c_str()); OBConversion conv; OBFormat* format = conv.FormatFromExt(filename); conv.SetInFormat(format); OBMol mol; conv.Read(mol, &ifs); OBSmartsPattern sp; sp.Init(smarts.c_str()); if(sp.Match(mol)) std::cout << filename << " is a ..." << endl; On the command line obabel is a more versatile alternative to obgrep: obabel infile.xxx -oyyy -s smarts The input and output formats can be anything. Only molecules matching the smarts will be converted. In 2.3.0 you can draw a svg picture with the functional group highlighted, e.g. for an alcohol obabel infile.xxx -O out.svg -s "[OX2H][CX4;!$(C([OX2H])[O,S,#7,#15])] green" -xu You can get a list of the functional groups (and some other features) in a molecule by: obabel infile.xxx -ofpt -xfFP4 -xs Chris ------------------------------------------------------------------------------ Lotusphere 2011 Register now for Lotusphere 2011 and learn how to connect the dots, take your collaborative environment to the next level, and enter the era of Social Business. http://p.sf.net/sfu/lotusphere-d2d _______________________________________________ OpenBabel-discuss mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/openbabel-discuss
