RDKit: FingerprintUtil.h Source File

| RDKit Open-source cheminformatics and machine learning.

Loading...
Searching...
No Matches
FingerprintUtil.h
Go to the documentation of this file.
1//
2// Copyright (C) 2018 Boran Adas, Google Summer of Code
3//
4// @@ All Rights Reserved @@
5// This file is part of the RDKit.
6// The contents are covered by the terms of the BSD license
7// which is included in the file license.txt, found at the root
8// of the RDKit source tree.
9//
10
11#include <RDGeneral/export.h>
12#ifndef RD_FINGERPRINTUTIL_H_2018_07
13#define RD_FINGERPRINTUTIL_H_2018_07
14
15#include <GraphMol/RDKitBase.h>
16#include <DataStructs/SparseIntVect.h>
17#include <DataStructs/BitVects.h>
18#include <cstdint>
19#include <tuple>
20#include <vector>
21#include <map>
22#include <DataStructs/ExplicitBitVect.h>
23
24#include <GraphMol/Subgraphs/Subgraphs.h>
25
26namespace RDKit {
27namespace AtomPairs {
28 const unsigned int numTypeBits = 4;
29 const unsigned int atomNumberTypes[1 << numTypeBits] = {
30 5, 6, 7, 8, 9, 14, 15, 16, 17, 33, 34, 35, 51, 52, 53};
31 const unsigned int numPiBits = 2;
32 const unsigned int maxNumPi = (1 << numPiBits) - 1;
33 const unsigned int numBranchBits = 3;
34 const unsigned int maxNumBranches = (1 << numBranchBits) - 1;
35 const unsigned int numChiralBits = 2;
36 const unsigned int codeSize = numTypeBits + numPiBits + numBranchBits;
37 const unsigned int numPathBits = 5;
38 const unsigned int maxPathLen = (1 << numPathBits) - 1;
39 const unsigned int numAtomPairFingerprintBits =
40 numPathBits + 2 * codeSize; // note that this is only accurate if chirality
41 // is not included
42
43//! returns a numeric code for the atom (the atom's hash in the
44//! atom-pair scheme)
45/*!
46 \param atom the atom to be considered
47 \param branchSubtract (optional) a constant to subtract from
48 the number of neighbors when the hash
49 is calculated (used in the topological
50 torsions code)
51 \param includeChirality toggles the inclusions of bits indicating R/S
52 chirality
53*/
54 RDKIT_FINGERPRINTS_EXPORT std::uint32_t getAtomCode(
55 const Atom *atom, unsigned int branchSubtract = 0,
56 bool includeChirality = false);
57
58//! returns an atom pair hash based on two atom hashes and the
59//! distance between the atoms.
60/*!
61 \param codeI the hash for the first atom
62 \param codeJ the hash for the second atom
63 \param dist the distance (number of bonds) between the two
64 atoms
65 \param includeChirality toggles the inclusions of bits indicating R/S
66 chirality
67*/
68 RDKIT_FINGERPRINTS_EXPORT std::uint32_t getAtomPairCode(
69 std::uint32_t codeI, std::uint32_t codeJ, unsigned int dist,
70 bool includeChirality = false);
71
72//! returns an topological torsion hash based on the atom hashes
73//! passed in
74/*!
75 \param atomCodes the vector of atom hashes
76*/
77 RDKIT_FINGERPRINTS_EXPORT std::uint64_t getTopologicalTorsionCode(
78 const std::vector<std::uint32_t> &atomCodes, bool includeChirality = false);
79
80 RDKIT_FINGERPRINTS_EXPORT std::uint32_t getTopologicalTorsionHash(
81 const std::vector<std::uint32_t> &pathCodes);
82
83} // namespace AtomPairs
84
85 namespace MorganFingerprints {
86
87 class RDKIT_FINGERPRINTS_EXPORT ss_matcher {
88 public:
89 ss_matcher();
90 ss_matcher(const std::string &pattern);
91
92 // const RDKit::ROMOL_SPTR &getMatcher() const { return m_matcher; }
93 const RDKit::ROMol *getMatcher() const;
94
95 private:
96 RDKit::ROMOL_SPTR m_matcher;
97};
98
99 typedef std::tuple<boost::dynamic_bitset<>, uint32_t, unsigned int> AccumTuple;
100
101 RDKIT_FINGERPRINTS_EXPORT extern std::vector<std::string> defaultFeatureSmarts;
102
103//! returns the connectivity invariants for a molecule
104/*!
105
106 \param mol : the molecule to be considered
107 \param invars : used to return the results
108 \param includeRingMembership : if set, whether or not the atom is in
109 a ring will be used in the invariant list.
110*/
111 RDKIT_FINGERPRINTS_EXPORT void getConnectivityInvariants(
112 const ROMol &mol, std::vector<std::uint32_t> &invars,
113 bool includeRingMembership = true);
114 const std::string morganConnectivityInvariantVersion = "1.0.0";
115
116//! returns the feature invariants for a molecule
117/*!
118
119 \param mol: the molecule to be considered
120 \param invars : used to return the results
121 \param patterns: if provided should contain the queries used to assign
122 atom-types.
123 if not provided, feature definitions adapted from reference:
124 Gobbi and Poppinger, Biotech. Bioeng. _61_ 47-54 (1998)
125 will be used for Donor, Acceptor, Aromatic, Halogen, Basic,
126 Acidic
127
128*/
129 RDKIT_FINGERPRINTS_EXPORT void getFeatureInvariants(
130 const ROMol &mol, std::vector<std::uint32_t> &invars,
131 std::vector<const ROMol *> *patterns = nullptr);
132 const std::string morganFeatureInvariantVersion = "0.1.0";
133
134} // namespace MorganFingerprints
135
136 namespace RDKitFPUtils {
137
138 RDKIT_FINGERPRINTS_EXPORT void buildDefaultRDKitFingerprintAtomInvariants(
139 const ROMol &mol, std::vector<std::uint32_t> &lAtomInvariants);
140
141 RDKIT_FINGERPRINTS_EXPORT void enumerateAllPaths(
142 const ROMol &mol, std::map<int, std::list<std::vector<int>>> &allPaths,
143 const std::vector<std::uint32_t> *fromAtoms, bool branchedPaths, bool useHs,
144 unsigned int minPath, unsigned int maxPath);
145
146 RDKIT_FINGERPRINTS_EXPORT void identifyQueryBonds(
147 const ROMol &mol, std::vector<const Bond *> &bondCache,
148 std::vector<short> &isQueryBond);
149
150 RDKIT_FINGERPRINTS_EXPORT std::vector<unsigned int> generateBondHashes(
151 const ROMol &mol, boost::dynamic_bitset<> &atomsInPath,
152 const std::vector<const Bond *> &bondCache,
153 const std::vector<short> &isQueryBond, const std::vector<int> &path,
154 bool useBondOrder, const std::vector<std::uint32_t> *atomInvariants);
155
156} // namespace RDKitFPUtils
157
158} // namespace RDKit
159
160#endif
BitVects.h
Pulls in all the BitVect classes.
ExplicitBitVect.h
RDKitBase.h
pulls in the core RDKit functionality
SparseIntVect.h
Subgraphs.h
functionality for finding subgraphs and paths in molecules
RDKit::Atom
The class for representing atoms.
Definition Atom.h:74
RDKit::MorganFingerprints::ss_matcher::ss_matcher
ss_matcher()
RDKit::MorganFingerprints::ss_matcher::getMatcher
const RDKit::ROMol * getMatcher() const
RDKit::MorganFingerprints::ss_matcher::ss_matcher
ss_matcher(const std::string &pattern)
RDKit::ROMol
Definition ROMol.h:199
export.h
RDKIT_FINGERPRINTS_EXPORT
#define RDKIT_FINGERPRINTS_EXPORT
Definition export.h:193
RDKit::AtomPairs
Definition AtomPairs.h:43
RDKit::AtomPairs::numPiBits
const unsigned int numPiBits
Definition FingerprintUtil.h:31
RDKit::AtomPairs::getTopologicalTorsionCode
RDKIT_FINGERPRINTS_EXPORT std::uint64_t getTopologicalTorsionCode(const std::vector< std::uint32_t > &atomCodes, bool includeChirality=false)
RDKit::AtomPairs::numPathBits
const unsigned int numPathBits
Definition FingerprintUtil.h:37
RDKit::AtomPairs::maxNumPi
const unsigned int maxNumPi
Definition FingerprintUtil.h:32
RDKit::AtomPairs::numChiralBits
const unsigned int numChiralBits
Definition FingerprintUtil.h:35
RDKit::AtomPairs::atomNumberTypes
const unsigned int atomNumberTypes[1<< numTypeBits]
Definition FingerprintUtil.h:29
RDKit::AtomPairs::maxNumBranches
const unsigned int maxNumBranches
Definition FingerprintUtil.h:34
RDKit::AtomPairs::getAtomPairCode
RDKIT_FINGERPRINTS_EXPORT std::uint32_t getAtomPairCode(std::uint32_t codeI, std::uint32_t codeJ, unsigned int dist, bool includeChirality=false)
RDKit::AtomPairs::codeSize
const unsigned int codeSize
Definition FingerprintUtil.h:36
RDKit::AtomPairs::numTypeBits
const unsigned int numTypeBits
Definition FingerprintUtil.h:28
RDKit::AtomPairs::numBranchBits
const unsigned int numBranchBits
Definition FingerprintUtil.h:33
RDKit::AtomPairs::numAtomPairFingerprintBits
const unsigned int numAtomPairFingerprintBits
Definition FingerprintUtil.h:39
RDKit::AtomPairs::getTopologicalTorsionHash
RDKIT_FINGERPRINTS_EXPORT std::uint32_t getTopologicalTorsionHash(const std::vector< std::uint32_t > &pathCodes)
RDKit::AtomPairs::maxPathLen
const unsigned int maxPathLen
Definition FingerprintUtil.h:38
RDKit::AtomPairs::getAtomCode
RDKIT_FINGERPRINTS_EXPORT std::uint32_t getAtomCode(const Atom *atom, unsigned int branchSubtract=0, bool includeChirality=false)
RDKit::MorganFingerprints
Definition FingerprintUtil.h:85
RDKit::MorganFingerprints::defaultFeatureSmarts
RDKIT_FINGERPRINTS_EXPORT std::vector< std::string > defaultFeatureSmarts
RDKit::MorganFingerprints::getFeatureInvariants
RDKIT_FINGERPRINTS_EXPORT void getFeatureInvariants(const ROMol &mol, std::vector< std::uint32_t > &invars, std::vector< const ROMol * > *patterns=nullptr)
returns the feature invariants for a molecule
RDKit::MorganFingerprints::morganFeatureInvariantVersion
const std::string morganFeatureInvariantVersion
Definition FingerprintUtil.h:132
RDKit::MorganFingerprints::morganConnectivityInvariantVersion
const std::string morganConnectivityInvariantVersion
Definition FingerprintUtil.h:114
RDKit::MorganFingerprints::getConnectivityInvariants
RDKIT_FINGERPRINTS_EXPORT void getConnectivityInvariants(const ROMol &mol, std::vector< std::uint32_t > &invars, bool includeRingMembership=true)
returns the connectivity invariants for a molecule
RDKit::MorganFingerprints::AccumTuple
std::tuple< boost::dynamic_bitset<>, uint32_t, unsigned int > AccumTuple
Definition FingerprintUtil.h:99
RDKit::RDKitFPUtils
Definition FingerprintUtil.h:136
RDKit::RDKitFPUtils::enumerateAllPaths
RDKIT_FINGERPRINTS_EXPORT void enumerateAllPaths(const ROMol &mol, std::map< int, std::list< std::vector< int > > > &allPaths, const std::vector< std::uint32_t > *fromAtoms, bool branchedPaths, bool useHs, unsigned int minPath, unsigned int maxPath)
RDKit::RDKitFPUtils::identifyQueryBonds
RDKIT_FINGERPRINTS_EXPORT void identifyQueryBonds(const ROMol &mol, std::vector< const Bond * > &bondCache, std::vector< short > &isQueryBond)
RDKit::RDKitFPUtils::generateBondHashes
RDKIT_FINGERPRINTS_EXPORT std::vector< unsigned int > generateBondHashes(const ROMol &mol, boost::dynamic_bitset<> &atomsInPath, const std::vector< const Bond * > &bondCache, const std::vector< short > &isQueryBond, const std::vector< int > &path, bool useBondOrder, const std::vector< std::uint32_t > *atomInvariants)
RDKit::RDKitFPUtils::buildDefaultRDKitFingerprintAtomInvariants
RDKIT_FINGERPRINTS_EXPORT void buildDefaultRDKitFingerprintAtomInvariants(const ROMol &mol, std::vector< std::uint32_t > &lAtomInvariants)
RDKit
Std stuff.
Definition Abbreviations.h:19
RDKit::ROMOL_SPTR
boost::shared_ptr< ROMol > ROMOL_SPTR
Definition ChemTransforms.h:22