File: obfingerprint_getfingerprint.cpp

package info (click to toggle)
openbabel 2.3.2%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 75,308 kB
  • ctags: 41,952
  • sloc: cpp: 321,252; ansic: 89,228; python: 7,262; perl: 6,418; pascal: 793; sh: 194; xml: 97; ruby: 55; makefile: 47; java: 23
file content (44 lines) | stat: -rw-r--r-- 1,292 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include <openbabel/mol.h>
#include <openbabel/obconversion.h>
#include <openbabel/fingerprint.h>
#include <iomanip>

using namespace OpenBabel;
int main(int argc,char **argv)
{
  if(argc==2)
  {
    //Make a fingerprint of type FP2(the default)
    //Equivalent to babel filename.xxx -ofpt -xo

    const char* filename = argv[1];
    OBConversion conv;

    //Read in a molecule from a file of any format
    OBMol mol;
    OBFormat* pFormat = conv.FormatFromExt(filename);
    if(pFormat && conv.SetInFormat(pFormat) && conv.ReadFile(&mol, filename))
    {
      //Get a pointer to the OBFingerprint class with id=="FP2"
      OBFingerprint* fptype = OBFingerprint::FindType("FP2");

      //Make a fingerprint of the default size from the molecule
      std::vector<unsigned> fptvec;
      if(fptype->GetFingerprint(&mol, fptvec))
      {
        //Output the fingerprint as hexadecimal, with six 32bit words per line
        for(int i=fptvec.size()-1;i>=0;i--)
        {
          std::cout << std::hex << std::setfill('0') << std::setw(8) << fptvec[i] << " " ;
          if((fptvec.size()-i)%6==0)
            std::cout << std::endl;
        }
      }
      std::cout << std::endl;
    }
  }
  else
    std::cout << "Usage:\n" << argv[0] << " filename.xxx" << std::endl;

  return 0;
}