RDKit
Open-source cheminformatics and machine learning.
Loading...
Searching...
No Matches
AtomPairGenerator.h
Go to the documentation of this file.
1//
2// Copyright (C) 2018-2022 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_ATOMPAIRGEN_H_2018_06
13#define RD_ATOMPAIRGEN_H_2018_06
14
17
18namespace RDKit {
19namespace AtomPair {
20using namespace AtomPairs;
21
24 bool df_includeChirality;
25 bool df_topologicalTorsionCorrection;
26
27 public:
28 /**
29 \brief Construct a new AtomPairAtomInvGenerator object
30
31 \param includeChirality toggles the inclusions of bits indicating R/S
32 chirality
33 \param topologicalTorsionCorrection when set subtracts 2 from invariants
34 returned, added so TopologicalTorsionGenerator can use this
35 */
36 AtomPairAtomInvGenerator(bool includeChirality = false,
37 bool topologicalTorsionCorrection = false);
38
39 std::vector<std::uint32_t> *getAtomInvariants(
40 const ROMol &mol) const override;
41
42 std::string infoString() const override;
43 void toJSON(boost::property_tree::ptree &pt) const override;
44 void fromJSON(const boost::property_tree::ptree &pt) override;
45
47};
48
49/*!
50 \brief class that holds atom-pair fingerprint specific arguments
51
52 */
54 : public FingerprintArguments {
55 public:
56 bool df_use2D = true;
57 unsigned int d_minDistance = 1;
58 unsigned int d_maxDistance = maxPathLen - 1;
59
60 std::string infoString() const override;
61 void toJSON(boost::property_tree::ptree &pt) const override;
62 void fromJSON(const boost::property_tree::ptree &pt) override;
63
64 /*!
65 \brief construct a new AtomPairArguments object
66
67 \param countSimulation if set, use count simulation while generating
68 the fingerprint \param includeChirality if set, chirality will be used
69 in the atom invariants, this is ignored if atomInvariantsGenerator is
70 present for the /c FingerprintGenerator that uses this \param use2D if
71 set, the 2D (topological) distance matrix will be used \param
72 minDistance minimum distance between atoms to be considered in a
73 pair, default is 1 bond
74 \param maxDistance maximum distance between atoms to be considered
75 in a pair, default is maxPathLen-1 bonds \param countBounds boundaries
76 for count simulation, corresponding bit will be set if the count is
77 higher than the number provided for that spot \param fpSize size of the
78 generated fingerprint, does not affect the sparse versions
79
80 */
81 AtomPairArguments(const bool countSimulation = true,
82 const bool includeChirality = false,
83 const bool use2D = true, const unsigned int minDistance = 1,
84 const unsigned int maxDistance = (maxPathLen - 1),
85 const std::vector<std::uint32_t> countBounds = {1, 2, 4, 8},
86 const std::uint32_t fpSize = 2048);
87};
88
89/*!
90 \brief class that holds atom-environment data needed for atom-pair fingerprint
91 generation
92
93 */
94template <typename OutputType>
96 : public AtomEnvironment<OutputType> {
97 const unsigned int d_atomIdFirst;
98 const unsigned int d_atomIdSecond;
99 const unsigned int d_distance;
100
101 public:
102 OutputType getBitId(
103 FingerprintArguments *arguments,
104 const std::vector<std::uint32_t> *atomInvariants,
105 const std::vector<std::uint32_t> *bondInvariants, // unused
106 AdditionalOutput *additionalOutput, // unused
107 const bool hashResults = false,
108 const std::uint64_t fpSize = 0 // unused
109 ) const override;
111 size_t bitId) const override;
112
113 /*!
114 \brief construct a new AtomPairAtomEnv object
115
116 \param atomIdFirst id of the first atom of the atom-pair
117 \param atomIdSecond id of the second atom of the atom-pair
118 \param distance distance between the atoms
119 */
120 AtomPairAtomEnv(const unsigned int atomIdFirst,
121 const unsigned int atomIdSecond, const unsigned int distance);
122};
123
124/*!
125 \brief class that generates atom-environments for atom-pair fingerprint
126
127 */
128template <typename OutputType>
130 : public AtomEnvironmentGenerator<OutputType> {
131 public:
132 std::vector<AtomEnvironment<OutputType> *> getEnvironments(
133 const ROMol &mol, FingerprintArguments *arguments,
134 const std::vector<std::uint32_t> *fromAtoms,
135 const std::vector<std::uint32_t> *ignoreAtoms, const int confId,
136 const AdditionalOutput *additionalOutput,
137 const std::vector<std::uint32_t> *atomInvariants,
138 const std::vector<std::uint32_t> *bondInvariants,
139 const bool hashResults = false) const override;
140
141 std::string infoString() const override;
142 void toJSON(boost::property_tree::ptree &pt) const override;
143 OutputType getResultSize() const override;
144};
145
146/*!
147 \brief helper function that generates a /c FingerprintGenerator that generates
148 atom-pair fingerprints
149 \tparam OutputType determines the size of the bitIds and the result, can be 32
150 or 64 bit unsigned integer
151 \param minDistance minimum distance between atoms to be considered in a pair,
152 default is 1 bond
153 \param maxDistance maximum distance between atoms to be considered in a pair,
154 default is maxPathLen-1 bonds
155 \param includeChirality if set, chirality will be used in the atom invariants,
156 this is ignored if atomInvariantsGenerator is provided
157 \param use2D if set, the 2D (topological) distance matrix will be used
158 \param atomInvariantsGenerator atom invariants to be used during fingerprint
159 generation
160 \param useCountSimulation if set, use count simulation while generating the
161 fingerprint
162 \param countBounds boundaries for count simulation, corresponding bit will be
163 set if the count is higher than the number provided for that spot
164 \param fpSize size of the generated fingerprint, does not affect the sparse
165 versions
166 \param ownsAtomInvGen if set atom invariants generator is destroyed with the
167 fingerprint generator
168
169 \return FingerprintGenerator<OutputType>* that generates atom-pair
170 fingerprints
171
172 This generator supports the following \c AdditionalOutput types:
173 - \c atomToBits : which bits each atom is involved in
174 - \c atomCounts : how many bits each atom sets
175 - \c bitInfoMap : map from bitId to (atomId1, atomId2) pairs
176
177 */
178template <typename OutputType>
181 const unsigned int minDistance = 1,
182 const unsigned int maxDistance = maxPathLen - 1,
183 const bool includeChirality = false, const bool use2D = true,
184 AtomInvariantsGenerator *atomInvariantsGenerator = nullptr,
185 const bool useCountSimulation = true, const std::uint32_t fpSize = 2048,
186 const std::vector<std::uint32_t> countBounds = {1, 2, 4, 8},
187 const bool ownsAtomInvGen = false);
188
189//! overload
190template <typename OutputType>
192 const AtomPairArguments &args,
193 AtomInvariantsGenerator *atomInvariantsGenerator = nullptr,
194 const bool ownsAtomInvGen = false);
195} // namespace AtomPair
196} // namespace RDKit
197
198#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
class that holds atom-pair fingerprint specific arguments
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 ...
void toJSON(boost::property_tree::ptree &pt) const override
AtomPairArguments(const bool countSimulation=true, const bool includeChirality=false, const bool use2D=true, const unsigned int minDistance=1, const unsigned int maxDistance=(maxPathLen - 1), const std::vector< std::uint32_t > countBounds={1, 2, 4, 8}, const std::uint32_t fpSize=2048)
construct a new AtomPairArguments object
void updateAdditionalOutput(AdditionalOutput *output, size_t bitId) const override
OutputType getBitId(FingerprintArguments *arguments, const std::vector< std::uint32_t > *atomInvariants, const std::vector< std::uint32_t > *bondInvariants, AdditionalOutput *additionalOutput, const bool hashResults=false, const std::uint64_t fpSize=0) const override
calculates and returns the bit id to be set for this atom-environment
AtomPairAtomEnv(const unsigned int atomIdFirst, const unsigned int atomIdSecond, const unsigned int distance)
construct a new AtomPairAtomEnv object
AtomPairAtomInvGenerator * clone() const override
void toJSON(boost::property_tree::ptree &pt) 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
std::string infoString() const override
method that returns information about this /c AtomInvariantsGenerator and its arguments
AtomPairAtomInvGenerator(bool includeChirality=false, bool topologicalTorsionCorrection=false)
Construct a new AtomPairAtomInvGenerator object.
class that generates atom-environments for atom-pair fingerprint
std::vector< AtomEnvironment< OutputType > * > getEnvironments(const ROMol &mol, FingerprintArguments *arguments, const std::vector< std::uint32_t > *fromAtoms, const std::vector< std::uint32_t > *ignoreAtoms, const int confId, const AdditionalOutput *additionalOutput, const std::vector< std::uint32_t > *atomInvariants, const std::vector< std::uint32_t > *bondInvariants, const bool hashResults=false) const override
generate and return all atom-envorinments from a molecule
void toJSON(boost::property_tree::ptree &pt) const override
std::string infoString() const override
method that returns information about this /c AtomEnvironmentGenerator and its arguments if any
OutputType getResultSize() const override
Returns the size of the fingerprint based on arguments.
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
#define RDKIT_FINGERPRINTS_EXPORT
Definition export.h:193
RDKIT_FINGERPRINTS_EXPORT FingerprintGenerator< OutputType > * getAtomPairGenerator(const unsigned int minDistance=1, const unsigned int maxDistance=maxPathLen - 1, const bool includeChirality=false, const bool use2D=true, AtomInvariantsGenerator *atomInvariantsGenerator=nullptr, const bool useCountSimulation=true, const std::uint32_t fpSize=2048, const std::vector< std::uint32_t > countBounds={1, 2, 4, 8}, const bool ownsAtomInvGen=false)
helper function that generates a /c FingerprintGenerator that generates atom-pair fingerprints
const unsigned int maxPathLen
Std stuff.