OBFingerprint Class Reference

The base class for fingerprints. More...

#include <openbabel/fingerprint.h>

Inheritance diagram for OBFingerprint:

List of all members.


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

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 OBPluginMakeInstance (const std::vector< std::string > &)
virtual void Init ()
const char * GetID () const
virtual PluginMapTypeGetMap () 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 OBFingerprintFindFingerprint (const char *ID)
static OBPluginGetPlugin (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 PluginMapTypePluginMap ()
static void LoadAllPlugins ()
static PluginMapTypeGetTypeMap (const char *PluginID)
static OBPluginBaseFindType (PluginMapType &Map, const char *ID)

Protected Attributes

const char * _id

Static Protected Attributes

static int AllPluginsLoaded = 0

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
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);
          use SetBit(fp,n); to set the nth bit

             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


    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 Typedef Documentation

typedef std::map<const char*, OBPlugin*, CharPtrLess> PluginMapType [inherited]

Member Enumeration Documentation

enum FptFlag

Optional flags.


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]
fingerprint in vector, which may be resized, folded to nbits (if nbits!=0)

Referenced by FastSearchIndexer::Add(), FastSearch::Find(), FastSearch::FindMatch(), and FastSearch::FindSimilar().

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]
a description of each bit that is set (or unset, if bSet=false)
version 2.2
double Tanimoto ( const std::vector< unsigned int > &  vec1,
const std::vector< unsigned int > &  vec2 
) [static]
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 OBFingerprint* FindFingerprint ( const char *  ID  )  [inline, static]

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

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

Referenced by FptIndex::CheckFP().

The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines