/********************************************************************** fingerprint.h - Base class for fingerprints and fast searching Copyright (C) 2005 by Chris Morley This file is part of the Open Babel project. For more information, see This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation version 2 of the License. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. ***********************************************************************/ #ifndef OB_FINGERPRINT_H #define OB_FINGERPRINT_H #include #include #include #include #include #include #ifndef OBFPRT #define OBFPRT #endif namespace OpenBabel { class OBBase; //Forward declaration; used only as pointer. /// \brief The base class for fingerprints class OBFPRT OBFingerprint { //see end of cpp file for detailed documentation MAKE_PLUGIN(OBFingerprint); public: virtual ~OBFingerprint(){} /// Sets the nth bit void SetBit(std::vector& vec, unsigned int n); /// Repeatedly ORs the top half with the bottom half until no smaller than nbits void Fold(std::vector& vec, unsigned int nbits); /// \return fingerprint in vector, which may be resized, folded to nbits (if nbits!=0) virtual bool GetFingerprint(OBBase* pOb, std::vector& fp, int nbits=0)=0; /// Required short description of the fingerprint type. virtual std::string Description()=0; /// Optional flags enum FptFlag{FPT_UNIQUEBITS=1}; virtual unsigned int Flags() { return 0;}; // Obtain info on available fingerprints // Replaced by FOR_EACH(OBFingerprint) // static bool GetNextFPrt(std::string& id, OBFingerprint*& pFPrt); /// \return the Tanimoto coefficient between two vectors (vector& SeekPositions) static double Tanimoto(const std::vector& vec1, const std::vector& vec2); /// Inline version of Tanimoto() taking a pointer for the second vector static double Tanimoto(const std::vector& vec1, const unsigned int* p2) { ///If used for two vectors, vec1 and vec2, call as Tanimoto(vec1, &vec2[0]); int andbits=0, orbits=0; unsigned int i; for (i=0;i /// \brief Header for fastsearch index file struct OBFPRT FptIndexHeader { unsigned int headerlength;/// /// \brief Structure of fastsearch index files struct OBFPRT FptIndex { FptIndexHeader header; std::vector fptdata; std::vector seekdata; bool Read(std::istream* pIndexstream); /// \return A pointer to FP used or NULL and an error message OBFingerprint* CheckFP(); }; /// \class FastSearch fingerprint.h /// \brief Class to search fingerprint index files class OBFPRT FastSearch { //see end of cpp file for detailed documentation public: /// \brief Loads an index from a file and returns the name of the datafile std::string ReadIndexFile(std::string IndexFilename); std::string ReadIndex(std::istream* pIndexstream); virtual ~FastSearch(){}; /// \brief Does substructure search and returns vector of the file positions of matches bool Find(OBBase* pOb, std::vector& SeekPositions, unsigned int MaxCandidates); /// \brief Similar to Find() but all bits of matching fingerprints have to be the same /// \since version 2.1 bool FindMatch(OBBase* pOb, std::vector& SeekPositions, unsigned int MaxCandidates); /// \return A multimap containing objects whose Tanimoto coefficients with the target /// is greater than the value specified. bool FindSimilar(OBBase* pOb, std::multimap& SeekposMap, double MinTani); /// \return A multimap containing the nCandidates objects with largest Tanimoto /// coefficients with the target. bool FindSimilar(OBBase* pOb, std::multimap& SeekposMap, int nCandidates=0); /// \return a pointer to the fingerprint type used to constuct the index OBFingerprint* GetFingerprint() const{ return _pFP;}; /// \return a pointer to the index header containing size info etc. const FptIndexHeader& GetIndexHeader() const{ return _index.header;}; private: FptIndex _index; OBFingerprint* _pFP; }; //********************************************** /// \class FastSearchIndexer fingerprint.h /// \brief Class to prepare fingerprint index files See FastSearch class for details class OBFPRT FastSearchIndexer { //see end of cpp file for detailed documentation public: ///\brief Constructor with a new index FastSearchIndexer(std::string& datafilename, std::ostream* os, std::string& fpid, int FptBits=0); ///\brief Constructor using existing index FastSearchIndexer(FptIndex* pindex, std::ostream* os); ~FastSearchIndexer(); ///\brief Called for each object bool Add(OBBase* pOb, std::streampos seekpos); private: std::ostream* _indexstream; FptIndex* _pindex; OBFingerprint* _pFP; int _nbits; }; } //namespace OpenBabel #endif //! \file fingerprint.h //! \brief Declaration of OBFingerprint base class and fastsearch classes