RDKit
Open-source cheminformatics and machine learning.
Loading...
Searching...
No Matches
RDKitFPGenerator.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_RDFINGERPRINTGEN_H_2018_07
13#define RD_RDFINGERPRINTGEN_H_2018_07
14
16
17namespace RDKit {
18namespace RDKitFP {
19
21 public:
22 unsigned int d_minPath = 1;
23 unsigned int d_maxPath = 7;
24 bool df_useHs = true;
25 bool df_branchedPaths = true;
26 bool df_useBondOrder = true;
27
28 std::string infoString() const override;
29 void toJSON(boost::property_tree::ptree &pt) const override;
30 void fromJSON(const boost::property_tree::ptree &pt) override;
31
32 /**
33 \brief Construct a new RDKitFPArguments object
34
35 \param minPath the minimum path length (in bonds) to be included
36 \param maxPath the maximum path length (in bonds) to be included
37 \param useHs toggles inclusion of Hs in paths (if the molecule has
38 explicit Hs)
39 \param branchedPaths toggles generation of branched subgraphs, not just
40 linear paths
41 \param useBondOrder toggles inclusion of bond orders in the path hashes
42 \param countSimulation if set, use count simulation while
43 generating the fingerprint
44 \param countBounds boundaries for count simulation, corresponding bit will
45 be set if the count is higher than the number provided for that spot
46 \param fpSize size of the generated fingerprint, does not affect the sparse
47 versions
48 \param numBitsPerFeature controls the number of bits that are set for each
49 path/subgraph found
50
51 */
52 RDKitFPArguments(unsigned int minPath = 1, unsigned int maxPath = 7,
53 bool useHs = true, bool branchedPaths = true,
54 bool useBondOrder = true, bool countSimulation = false,
55 const std::vector<std::uint32_t> countBounds = {1, 2, 4, 8},
56 std::uint32_t fpSize = 2048,
57 std::uint32_t numBitsPerFeature = 2);
58};
59
62 public:
63 std::vector<std::uint32_t> *getAtomInvariants(
64 const ROMol &mol) const override;
65
66 std::string infoString() const override;
67 void toJSON(boost::property_tree::ptree &pt) const override;
68 void fromJSON(const boost::property_tree::ptree &pt) override;
69
70 RDKitFPAtomInvGenerator *clone() const override;
71};
72
73template <typename OutputType>
75 : public AtomEnvironment<OutputType> {
76 const OutputType d_bitId;
77 const boost::dynamic_bitset<> d_atomsInPath;
78 const INT_VECT d_bondPath;
79
80 public:
81 OutputType getBitId(
82 FingerprintArguments *arguments, // unused
83 const std::vector<std::uint32_t> *atomInvariants, // unused
84 const std::vector<std::uint32_t> *bondInvariants, // unused
85 AdditionalOutput *additionalOutput, // unused
86 bool hashResults = false, // unused
87 const std::uint64_t fpSize = 0 // unused
88 ) const override;
90 std::uint64_t bitId) const override;
91
92 /**
93 \brief Construct a new RDKitFPAtomEnv object
94
95 \param bitId bitId generated for this environment
96 \param atomsInPath holds atoms in this environment to set additional output
97 \param bondPath the bond path defining the environment
98
99 */
100 RDKitFPAtomEnv(const OutputType bitId, boost::dynamic_bitset<> atomsInPath,
101 INT_VECT bondPath)
102 : d_bitId(bitId),
103 d_atomsInPath(std::move(atomsInPath)),
104 d_bondPath(std::move(bondPath)) {}
105};
106
107template <typename OutputType>
109 : public AtomEnvironmentGenerator<OutputType> {
110 public:
111 /**
112 \brief Get the atom environments for a molecule
113
114 \param mol molecule to generate the atom-environments from
115 \param arguments fingerprint type specific arguments
116 \param fromAtoms only generate subgraphs starting at these atoms
117 \param ignoreAtoms ignore any subgraphs that contain these atoms
118 \param confId IGNORED
119 \param additionalOutput IGNORED
120 \param atomInvariants atom invariants to be used
121 \param bondInvariants IGNORED
122 \param hashResults IGNORED
123 */
124 std::vector<AtomEnvironment<OutputType> *> getEnvironments(
125 const ROMol &mol, FingerprintArguments *arguments,
126 const std::vector<std::uint32_t> *fromAtoms,
127 const std::vector<std::uint32_t> *ignoreAtoms, int confId,
128 const AdditionalOutput *additionalOutput,
129 const std::vector<std::uint32_t> *atomInvariants,
130 const std::vector<std::uint32_t> *bondInvariants,
131 bool hashResults = false) const override;
132
133 std::string infoString() const override;
134 void toJSON(boost::property_tree::ptree &pt) const override;
135 void fromJSON(const boost::property_tree::ptree &pt) override;
136
137 OutputType getResultSize() const override;
138
139}; // namespace RDKitFP
140
141/**
142 \brief Get a RDKit fingerprint generator with given parameters
143
144 \tparam OutputType determines the size of the bitIds and the result, can be 32
145 or 64 bit unsigned integer
146 \param minPath the minimum path length (in bonds) to be included
147 \param maxPath the maximum path length (in bonds) to be included
148 \param useHs toggles inclusion of Hs in paths (if the molecule has
149 explicit Hs)
150 \param branchedPaths toggles generation of branched subgraphs, not just
151 linear paths
152 \param useBondOrder toggles inclusion of bond orders in the path hashes
153 \param atomInvariantsGenerator custom atom invariants generator to use
154 \param countSimulation if set, use count simulation while
155 generating the fingerprint
156 \param countBounds boundaries for count simulation, corresponding bit will be
157 set if the count is higher than the number provided for that spot
158 \param fpSize size of the generated fingerprint, does not affect the sparse
159 versions
160 \param numBitsPerFeature controls the number of bits that are set for each
161 path/subgraph found
162 \param ownsAtomInvGen if set atom invariants generator is destroyed with the
163 fingerprint generator
164
165 /return FingerprintGenerator<OutputType>* that generates RDKit fingerprints
166
167 This generator supports the following \c AdditionalOutput types:
168 - \c atomToBits : which bits each atom is involved in
169 - \c atomCounts : how many bits each atom sets
170 - \c bitPaths : map from bitId to vectors of bond indices for the individual
171 subgraphs
172
173 */
174template <typename OutputType>
176 unsigned int minPath = 1, unsigned int maxPath = 7, bool useHs = true,
177 bool branchedPaths = true, bool useBondOrder = true,
178 AtomInvariantsGenerator *atomInvariantsGenerator = nullptr,
179 bool countSimulation = false,
180 const std::vector<std::uint32_t> countBounds = {1, 2, 4, 8},
181 std::uint32_t fpSize = 2048, std::uint32_t numBitsPerFeature = 2,
182 bool ownsAtomInvGen = false);
183// \overload
184template <typename OutputType>
186 const RDKitFPArguments &args,
187 AtomInvariantsGenerator *atomInvariantsGenerator = nullptr,
188 bool ownsAtomInvGen = false);
189
190} // namespace RDKitFP
191} // namespace RDKit
192
193#endif
abstract base class that generates atom-environments from a molecule
abstract base class that holds atom-environments that will be hashed to generate the fingerprint
abstract base class for atom invariants generators
Abstract base class that holds molecule independent arguments that are common amongst all fingerprint...
FingerprintArguments(bool countSimulation, const std::vector< std::uint32_t > countBounds, std::uint32_t fpSize, std::uint32_t numBitsPerFeature=1, bool includeChirality=false)
class that generates same fingerprint style for different output formats
void toJSON(boost::property_tree::ptree &pt) const override
void fromJSON(const boost::property_tree::ptree &pt) override
std::string infoString() const override
method that returns information string about the fingerprint specific argument set and the arguments ...
RDKitFPArguments(unsigned int minPath=1, unsigned int maxPath=7, bool useHs=true, bool branchedPaths=true, bool useBondOrder=true, bool countSimulation=false, const std::vector< std::uint32_t > countBounds={1, 2, 4, 8}, std::uint32_t fpSize=2048, std::uint32_t numBitsPerFeature=2)
Construct a new RDKitFPArguments object.
RDKitFPAtomEnv(const OutputType bitId, boost::dynamic_bitset<> atomsInPath, INT_VECT bondPath)
Construct a new RDKitFPAtomEnv object.
OutputType getBitId(FingerprintArguments *arguments, const std::vector< std::uint32_t > *atomInvariants, const std::vector< std::uint32_t > *bondInvariants, AdditionalOutput *additionalOutput, bool hashResults=false, const std::uint64_t fpSize=0) const override
calculates and returns the bit id to be set for this atom-environment
void updateAdditionalOutput(AdditionalOutput *output, std::uint64_t bitId) const override
void fromJSON(const boost::property_tree::ptree &pt) override
std::vector< std::uint32_t > * getAtomInvariants(const ROMol &mol) const override
get atom invariants from a molecule
void toJSON(boost::property_tree::ptree &pt) const override
std::string infoString() const override
method that returns information about this /c AtomInvariantsGenerator and its arguments
RDKitFPAtomInvGenerator * clone() const override
OutputType getResultSize() const override
Returns the size of the fingerprint based on arguments.
void toJSON(boost::property_tree::ptree &pt) const override
void fromJSON(const boost::property_tree::ptree &pt) override
std::vector< AtomEnvironment< OutputType > * > getEnvironments(const ROMol &mol, FingerprintArguments *arguments, const std::vector< std::uint32_t > *fromAtoms, const std::vector< std::uint32_t > *ignoreAtoms, int confId, const AdditionalOutput *additionalOutput, const std::vector< std::uint32_t > *atomInvariants, const std::vector< std::uint32_t > *bondInvariants, bool hashResults=false) const override
Get the atom environments for a molecule.
std::string infoString() const override
method that returns information about this /c AtomEnvironmentGenerator and its arguments if any
#define RDKIT_FINGERPRINTS_EXPORT
Definition export.h:241
RDKIT_FINGERPRINTS_EXPORT FingerprintGenerator< OutputType > * getRDKitFPGenerator(unsigned int minPath=1, unsigned int maxPath=7, bool useHs=true, bool branchedPaths=true, bool useBondOrder=true, AtomInvariantsGenerator *atomInvariantsGenerator=nullptr, bool countSimulation=false, const std::vector< std::uint32_t > countBounds={1, 2, 4, 8}, std::uint32_t fpSize=2048, std::uint32_t numBitsPerFeature=2, bool ownsAtomInvGen=false)
Get a RDKit fingerprint generator with given parameters.
Std stuff.
std::vector< int > INT_VECT
Definition types.h:224