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 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341
|
//
// Copyright (C) 2018 Boran Adas, Google Summer of Code
//
// @@ All Rights Reserved @@
// This file is part of the RDKit.
// The contents are covered by the terms of the BSD license
// which is included in the file license.txt, found at the root
// of the RDKit source tree.
//
#include <RDGeneral/export.h>
#ifndef RD_FINGERPRINTGEN_H_2018_05
#define RD_FINGERPRINTGEN_H_2018_05
#include <DataStructs/SparseIntVect.h>
#include <DataStructs/ExplicitBitVect.h>
#include <DataStructs/SparseBitVect.h>
#include <cstdint>
namespace RDKit {
class ROMol;
struct RDKIT_FINGERPRINTS_EXPORT AdditionalOutput {
// will review this structure once more fignerprint types are implemented
std::vector<std::vector<std::uint64_t>> *atomToBits;
std::map<std::uint32_t, std::vector<std::pair<std::uint32_t, std::uint32_t>>>
*bitInfoMap;
// morgan fp
// maps bitId -> vector of (atomId, radius)
std::pair<std::vector<std::vector<std::uint32_t>>,
std::map<std::uint32_t, std::vector<std::vector<int>>>> *bitInfo;
// rdkit fp
// first part, vector of bits set for each atom, must have the same size as
// atom count for molecule
// second part, maps bitId -> vector of paths
std::vector<unsigned int> *atomCounts;
// number of paths that set bits for each atom, must have the same size as
// atom count for molecule
};
/*!
\brief Abstract base class that holds molecule independent arguments that are
common amongst all fingerprint types and classes inherited from this would
hold fingerprint type specific arguments
*/
template <typename OutputType>
class RDKIT_FINGERPRINTS_EXPORT FingerprintArguments
: private boost::noncopyable {
public:
FingerprintArguments(const bool countSimulation,
const std::vector<std::uint32_t> countBounds,
const std::uint32_t fpSize);
const bool d_countSimulation;
const std::vector<std::uint32_t> d_countBounds;
const std::uint32_t d_fpSize;
/*!
\brief Returns the size of the fingerprint based on arguments
\return OutputType size of the fingerprint
*/
virtual OutputType getResultSize() const = 0;
/**
\brief method that returns information string about the fingerprint specific
argument set and the arguments themselves
\return std::string information string
*/
virtual std::string infoString() const = 0;
/**
\brief method that returns information string about common fingerprinting
arguments' values
\return std::string information string
*/
std::string commonArgumentsString() const;
virtual ~FingerprintArguments(){};
};
/*!
\brief abstract base class that holds atom-environments that will be hashed to
generate the fingerprint
*/
template <typename OutputType>
class RDKIT_FINGERPRINTS_EXPORT AtomEnvironment : private boost::noncopyable {
public:
/*!
\brief calculates and returns the bit id to be set for this atom-environment
\param arguments Fingerprinting type specific molecule independent
arguments
\param atomInvariants Atom-invariants to be used during hashing
\param bondInvariants Bond-invariants to be used during hashing
\param hashResults if set results will be ready to be modded
\return OutputType calculated bit id for this environment
*/
virtual OutputType getBitId(FingerprintArguments<OutputType> *arguments,
const std::vector<std::uint32_t> *atomInvariants,
const std::vector<std::uint32_t> *bondInvariants,
const AdditionalOutput *AdditionalOutput,
const bool hashResults = false) const = 0;
virtual ~AtomEnvironment(){};
};
/*!
\brief abstract base class that generates atom-environments from a molecule
*/
template <typename OutputType>
class RDKIT_FINGERPRINTS_EXPORT AtomEnvironmentGenerator
: private boost::noncopyable {
public:
/*!
\brief generate and return all atom-envorinments from a molecule
\param mol molecule to generate the atom-environments from
\param arguments fingerprint type specific molecule independent
arguments
\param fromAtoms atoms to be used during environment generation,
usage of this parameter depends on the implementation of different
fingerprint types
\param ignoreAtoms atoms to be ignored during environment generation,
usage of this parameter depends on the implementation of different
fingerprint types
\param confId which conformation to use during environment
generation, needed for some fingerprint types
\param additionalOutput contains pointers for additional outputs of
fingerprinting operation, usage depends on implementation of the fingerprint
type
\param atomInvariants atom invariants to be used during environment
generation, in some cases some of the hashing can be done during environment
generation so it is also passed here
\param bondInvariants bond invariants to be used during environment
generation, same as atomInvariants it might be needed
\param hashResults if set results will be ready to be modded
\return std::vector<AtomEnvironment *> atom-environments generated from
this molecule
*/
virtual std::vector<AtomEnvironment<OutputType> *> getEnvironments(
const ROMol &mol, FingerprintArguments<OutputType> *arguments,
const std::vector<std::uint32_t> *fromAtoms = nullptr,
const std::vector<std::uint32_t> *ignoreAtoms = nullptr,
const int confId = -1, const AdditionalOutput *additionalOutput = nullptr,
const std::vector<std::uint32_t> *atomInvariants = nullptr,
const std::vector<std::uint32_t> *bondInvariants = nullptr,
const bool hashResults = false) const = 0;
/**
\brief method that returns information about this /c AtomEnvironmentGenerator
and its arguments if any
\return std::string information string
*/
virtual std::string infoString() const = 0;
virtual ~AtomEnvironmentGenerator(){};
};
/*!
\brief abstract base class for atom invariants generators
*/
class RDKIT_FINGERPRINTS_EXPORT AtomInvariantsGenerator
: private boost::noncopyable {
public:
/*!
\brief get atom invariants from a molecule
\param mol molecule to generate the atom invariants for
\return std::vector<std::uint32_t> atom invariants generated for the given
molecule
*/
virtual std::vector<std::uint32_t> *getAtomInvariants(
const ROMol &mol) const = 0;
/**
\brief method that returns information about this /c AtomInvariantsGenerator
and its arguments
\return std::string information string
*/
virtual std::string infoString() const = 0;
virtual ~AtomInvariantsGenerator(){};
virtual AtomInvariantsGenerator *clone() const = 0;
};
/*!
\brief abstract base class for bond invariants generators
*/
class RDKIT_FINGERPRINTS_EXPORT BondInvariantsGenerator
: private boost::noncopyable {
public:
/*!
\brief get bond invariants from a molecule
\param mol molecule to generate the bond invariants for
\return std::vector<std::uint32_t> bond invariants generated for the given
molecule
*/
virtual std::vector<std::uint32_t> *getBondInvariants(
const ROMol &mol) const = 0;
/**
\brief method that returns information about this /c BondInvariantsGenerator
and its arguments
\return std::string information string
*/
virtual std::string infoString() const = 0;
virtual ~BondInvariantsGenerator(){};
virtual BondInvariantsGenerator *clone() const = 0;
}; // namespace RDKit
/*!
\brief class that generates same fingerprint style for different output
formats
*/
template <typename OutputType>
class RDKIT_FINGERPRINTS_EXPORT FingerprintGenerator
: private boost::noncopyable {
FingerprintArguments<OutputType> *dp_fingerprintArguments;
AtomEnvironmentGenerator<OutputType> *dp_atomEnvironmentGenerator;
AtomInvariantsGenerator *dp_atomInvariantsGenerator;
BondInvariantsGenerator *dp_bondInvariantsGenerator;
const bool df_ownsAtomInvGenerator;
const bool df_ownsBondInvGenerator;
SparseIntVect<OutputType> *getFingerprintHelper(
const ROMol &mol, const std::vector<std::uint32_t> *fromAtoms = nullptr,
const std::vector<std::uint32_t> *ignoreAtoms = nullptr,
const int confId = -1, const AdditionalOutput *additionalOutput = nullptr,
const std::vector<std::uint32_t> *customAtomInvariants = nullptr,
const std::vector<std::uint32_t> *customBondInvariants = nullptr,
const std::uint64_t fpSize = 0) const;
public:
FingerprintGenerator(
AtomEnvironmentGenerator<OutputType> *atomEnvironmentGenerator,
FingerprintArguments<OutputType> *fingerprintArguments,
AtomInvariantsGenerator *atomInvariantsGenerator = nullptr,
BondInvariantsGenerator *bondInvariantsGenerator = nullptr,
bool ownsAtomInvGenerator = false, bool ownsBondInvGenerator = false);
~FingerprintGenerator();
SparseIntVect<OutputType> *getSparseCountFingerprint(
const ROMol &mol, const std::vector<std::uint32_t> *fromAtoms = nullptr,
const std::vector<std::uint32_t> *ignoreAtoms = nullptr,
const int confId = -1, const AdditionalOutput *additionalOutput = nullptr,
const std::vector<std::uint32_t> *customAtomInvariants = nullptr,
const std::vector<std::uint32_t> *customBondInvariants = nullptr) const;
SparseBitVect *getSparseFingerprint(
const ROMol &mol, const std::vector<std::uint32_t> *fromAtoms = nullptr,
const std::vector<std::uint32_t> *ignoreAtoms = nullptr,
const int confId = -1, const AdditionalOutput *additionalOutput = nullptr,
const std::vector<std::uint32_t> *customAtomInvariants = nullptr,
const std::vector<std::uint32_t> *customBondInvariants = nullptr) const;
SparseIntVect<std::uint32_t> *getCountFingerprint(
const ROMol &mol, const std::vector<std::uint32_t> *fromAtoms = nullptr,
const std::vector<std::uint32_t> *ignoreAtoms = nullptr,
const int confId = -1, const AdditionalOutput *additionalOutput = nullptr,
const std::vector<std::uint32_t> *customAtomInvariants = nullptr,
const std::vector<std::uint32_t> *customBondInvariants = nullptr) const;
ExplicitBitVect *getFingerprint(
const ROMol &mol, const std::vector<std::uint32_t> *fromAtoms = nullptr,
const std::vector<std::uint32_t> *ignoreAtoms = nullptr,
const int confId = -1, const AdditionalOutput *additionalOutput = nullptr,
const std::vector<std::uint32_t> *customAtomInvariants = nullptr,
const std::vector<std::uint32_t> *customBondInvariants = nullptr) const;
std::string infoString() const;
};
enum class FPType { AtomPairFP, MorganFP, RDKitFP, TopologicalTorsionFP };
//! used to indicate errors for unimplemented fp types in convenience functions
class RDKIT_FINGERPRINTS_EXPORT UnimplementedFPException
: public std::exception {
public:
//! construct with an error message
UnimplementedFPException(const char *msg) : _msg(msg){};
//! construct with an error message
UnimplementedFPException(const std::string &msg) : _msg(msg){};
//! get the error message
const char *message() const { return _msg.c_str(); };
~UnimplementedFPException() throw(){};
private:
std::string _msg;
};
// convenience functions, fingerprint generation with default values
RDKIT_FINGERPRINTS_EXPORT SparseIntVect<std::uint64_t> *getSparseCountFP(
const ROMol &mol, FPType fPType);
RDKIT_FINGERPRINTS_EXPORT SparseBitVect *getSparseFP(const ROMol &mol,
FPType fPType);
RDKIT_FINGERPRINTS_EXPORT SparseIntVect<std::uint32_t> *getCountFP(
const ROMol &mol, FPType fPType);
RDKIT_FINGERPRINTS_EXPORT ExplicitBitVect *getFP(const ROMol &mol,
FPType fPType);
RDKIT_FINGERPRINTS_EXPORT std::vector<SparseIntVect<std::uint64_t> *> *
getSparseCountFPBulk(const std::vector<const ROMol *> molVector, FPType fPType);
RDKIT_FINGERPRINTS_EXPORT std::vector<SparseBitVect *> *getSparseFPBulk(
const std::vector<const ROMol *> molVector, FPType fPType);
RDKIT_FINGERPRINTS_EXPORT std::vector<SparseIntVect<std::uint32_t> *>
*getCountFPBulk(const std::vector<const ROMol *> molVector, FPType fPType);
RDKIT_FINGERPRINTS_EXPORT std::vector<ExplicitBitVect *> *getFPBulk(
const std::vector<const ROMol *> molVector, FPType fPType);
} // namespace RDKit
#endif
|