OBFingerprint Class Reference

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files
- Examples

- Class List
- Class Index
- Class Hierarchy
- Class Members

Classes | Public Types | Public Member Functions | Static Public Member Functions | Static Protected Member Functions | Protected Attributes
OBFingerprint Class Reference

`#include <openbabel/fingerprint.h>`

Inheritance diagram for OBFingerprint:
[legend]

List of all members.

## Classes
struct | bit_or
| Function object to set bits.
## Public Types
enum | FptFlag { FPT_UNIQUEBITS = 1, FPT_NOINFO = 2 }
typedef std::map< const char *, OBPlugin *, CharPtrLess > | PluginMapType
typedef PluginMapType::const_iterator | PluginIterator
## Public Member Functions
virtual | ~OBFingerprint ()
void | SetBit (std::vector< unsigned int > &vec, const unsigned int n)
bool | GetBit (const std::vector< unsigned int > &vec, const unsigned int n)
void | Fold (std::vector< unsigned int > &vec, unsigned int nbits)
virtual bool | GetFingerprint (OBBase *pOb, std::vector< unsigned int > &fp, int nbits=0)=0
virtual unsigned int | Flags ()
virtual void | SetFlags (unsigned int)
virtual std::string | DescribeBits (const std::vector< unsigned int >, bool=true)
virtual const char * | Description ()
virtual bool | Display (std::string &txt, const char *param, const char *ID=NULL)
virtual OBPlugin * | MakeInstance (const std::vector< std::string > &)
virtual void | Init ()
const char * | GetID () const
virtual PluginMapType & | GetMap () const =0
## Static Public Member Functions
static double | Tanimoto (const std::vector< unsigned int > &vec1, const std::vector< unsigned int > &vec2)
static double | Tanimoto (const std::vector< unsigned int > &vec1, const unsigned int *p2)
static unsigned int | Getbitsperint ()
static OBFingerprint * | FindFingerprint (const char *ID)
static OBPlugin * | GetPlugin (const char *Type, const char *ID)
static bool | ListAsVector (const char *PluginID, const char *param, std::vector< std::string > &vlist)
static void | List (const char *PluginID, const char *param=NULL, std::ostream *os=&std::cout)
static std::string | ListAsString (const char *PluginID, const char *param=NULL)
static std::string | FirstLine (const char *txt)
static PluginIterator | Begin (const char *PluginID)
static PluginIterator | End (const char *PluginID)
## Static Protected Member Functions
static PluginMapType & | PluginMap ()
static PluginMapType & | GetTypeMap (const char *PluginID)
static OBPlugin * | BaseFindType (PluginMapType &Map, const char *ID)
## Protected Attributes
const char * | _id

## Detailed Description

The base class for fingerprints.

These fingerprints are condensed representation of molecules (or other objects) as a list of boolean values (actually bits in a vector<unsigned>) with length of a power of 2. The main motivation is for fast searching of data sources containing large numbers of molecules (up to several million). Open Babel provides some routines which can search text files containing lists of molecules in any format. See the documentation on the class FastSearch.

There are descriptions of molecular fingerprints at
http://www.daylight.com/dayhtml/doc/theory/theory.finger.html) and
http://www.mesaac.com/Fingerprint.htm
Many methods of preparing fingerprints have been described, but the type supported currently in OpenBabel has each bit representing a substructure (or other molecular property). If a substructure is present in the molecule, then a particular bit is set to 1. But because the hashing method may also map other substructures to the same bit, a match does not guarantee that a particular substructure is present; there may be false positives. However, with proper design, a large fraction of irrelevant molecules in a data set can be eliminated in a fast search with boolean methods on the fingerprints. It then becomes feasible to make a definitive substructure search by conventional methods on this reduced list even if it is slow.

OpenBabel provides a framework for applying new types of fingerprints without changing any existing code. They are derived from OBFingerprint and the source file is just compiled with the rest of OpenBabel. Alternatively, they can be separately compiled as a DLL or shared library and discovered when OpenBabel runs.

For more on these specific implementations of fingerprints in Open Babel, please take a look at the developer's wiki: http://openbabel.org/wiki/Fingerprints

Fingerprints derived from this abstract base class OBFingerprint can be for any object derived from OBBase (not just for OBMol). Each derived class provides an ID as a string and OBFingerprint keeps a map of these to provides a pointer to the class when requested in FindFingerprint.

#### -- To define a fingerprint type --

The classes derived form OBFingerprint are required to provide a GetFingerprint() routine and a Description() routine

        class MyFpType : OBFingerprint
        {
           MyFpType(const char* id) : OBFingerprint(id){};

           virtual bool GetFingerprint(OBBase* pOb, vector<unsigned int>& fp, int nbits)
           {
              //Convert pOb to the required type, usually OBMol
              OBMol* pmol = dynamic_cast<OBMol*>(pOb);
              fp.resize(required_number_of_words);
              ...
              use SetBit(fp,n); to set the nth bit

              if(nbits)
                 Fold(fp, nbits);
           }

           virtual const char* Description(){ return "Some descriptive text";}
           ...
        };

Declare a global instance with the ID you will use in -f options to specify its use.

        MyFpType theMyFpType("myfpID");

#### -- To obtain a fingerprint --

        OBMol mol;
        ...
        vector<unsigned int> fp;
        OBFingerprint::GetDefault()->GetFingerprint(&mol, fp); //gets default size of fingerprint

or

        vector<unsigned int> fp;
        OBFingerPrint* pFP = OBFingerprint::FindFingerprint("myfpID");
        ...and maybe...
        pFP->GetFingerprint(&mol,fp, 128); //fold down to 128bits if was originally larger

#### -- To print a list of available fingerprint types --

        std::string id;
        OBFingerPrint* pFPrt=NULL;
        while(OBFingerprint::GetNextFPrt(id, pFPrt))
        {
           cout << id << " -- " << pFPrt->Description() << endl;
        }

Fingerprints are handled as vector<unsigned int> so that the number of bits in this vector and their order will be platform and compiler dependent, because of size of int types and endian differences. Use fingerprints (and fastsearch indexes containing them) only for comparing with other fingerprints prepared on the same machine.

The FingerprintFormat class is an output format which displays fingerprints as hexadecimal. When multiple molecules are supplied it will calculate the Tanimoto coefficient from the first molecule to each of the others. It also shows whether the first molecule is a possible substructure to all the others, i.e. whether all the bits set in the fingerprint for the first molecule are set in the fingerprint of the others. To display hexadecimal information when multiple molecules are provided it is necessay to use the -xh option.

To see a list of available format types, type babel -F on the command line. The -xF option of the FingerprintFormat class also provides this output, but due to a quirk in the way the program works, it is necessary to have a valid input molecule for this option to work.

## Member Enumeration Documentation

enum FptFlag

Optional flags.

Enumerator:

  FPT_UNIQUEBITS |
  FPT_NOINFO |

## Constructor & Destructor Documentation

virtual ~OBFingerprint | ( |  | ) | `[inline, virtual]`

## Member Function Documentation

void SetBit | ( | std::vector< unsigned int > & | vec,
|  | const unsigned int | n
| ) |  |

Sets the nth bit.

bool GetBit | ( | const std::vector< unsigned int > & | vec,
|  | const unsigned int | n
| ) |  |

return true if the nth bit is set;

void Fold | ( | std::vector< unsigned int > & | vec,
|  | unsigned int | nbits
| ) |  |

Repeatedly ORs the top half with the bottom half until no smaller than nbits.

virtual bool GetFingerprint | ( | OBBase * | pOb,
|  | std::vector< unsigned int > & | fp,
|  | int | nbits = `0`
| ) |  | `[pure virtual]`

Returns:
  fingerprint in vector, which may be resized, folded to nbits (if nbits!=0)

virtual unsigned int Flags | ( |  | ) | `[inline, virtual]`

virtual void SetFlags | ( | unsigned | int | ) | `[inline, virtual]`

virtual std::string DescribeBits | ( | const std::vector< unsigned int > | ,
|  | bool | = `true`
| ) |  | `[inline, virtual]`

Returns:
  a description of each bit that is set (or unset, if bSet=false)

Since:
  version 2.2

double Tanimoto | ( | const std::vector< unsigned int > & | vec1,
|  | const std::vector< unsigned int > & | vec2
| ) |  | `[static]`

Returns:
  the Tanimoto coefficient between two vectors (vector<unsigned int>& SeekPositions)

static double Tanimoto | ( | const std::vector< unsigned int > & | vec1,
|  | const unsigned int * | p2
| ) |  | `[inline, static]`

Inline version of Tanimoto() taking a pointer for the second vector.

If used for two vectors, vec1 and vec2, call as Tanimoto(vec1, &vec2[0]);

static unsigned int Getbitsperint | ( |  | ) | `[inline, static]`

static OBFingerprint* FindFingerprint | ( | const char * | ID | ) | `[inline, static]`

For backward compatibility; a synonym of OBFingerprint::FindType.

Returns:
  a pointer to a fingerprint (the default if ID is empty), or NULL if not available

The documentation for this class was generated from the following files:

- fingerprint.h
- fingerprint.cpp

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines