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