RDKit: SynthonSpaceSearch_details.h Source File

| RDKit Open-source cheminformatics and machine learning.

Loading...
Searching...
No Matches
SynthonSpaceSearch_details.h
Go to the documentation of this file.
1//
2// Copyright (C) David Cosgrove 2024.
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#ifndef RDKIT_SYNTHONSPACESEARCHDETAILS_H
12#define RDKIT_SYNTHONSPACESEARCHDETAILS_H
13
14#include <chrono>
15#include <vector>
16
17#include <GraphMol/SynthonSpaceSearch/SynthonSpaceHitSet.h>
18#include <RDGeneral/export.h>
19#include <DataStructs/ExplicitBitVect.h>
20
21 using Clock = std::chrono::steady_clock;
22 using TimePoint = std::chrono::time_point<Clock>;
23
24namespace RDKit {
25class ROMol;
26namespace SynthonSpaceSearch::details {
27
28 RDKIT_SYNTHONSPACESEARCH_EXPORT bool checkTimeOut(const TimePoint *endTime);
29
30// Find all combinations of M things selected from N.
31 RDKIT_SYNTHONSPACESEARCH_EXPORT std::vector<std::vector<unsigned int>>
32combMFromN(unsigned int m, unsigned int n);
33// Find all permutations of M things selected from N.
34 RDKIT_SYNTHONSPACESEARCH_EXPORT std::vector<std::vector<unsigned int>>
35permMFromN(unsigned int m, unsigned int n);
36
37// Split the molecule into fragments. maxNumFrags gives the maximum number
38// of fragments to be produced in each set. There will a vector of vectors of
39// molecules. Each inner vector contains the fragments from a split molecule.
40// The maxNumFrags will be constrained to the maximum number of synthons in
41// the search space as there's no point making more fragments than that.
42// Any complex query atoms will be stripped out of the fragments and replaced
43// by a simple atom query.
44 RDKIT_SYNTHONSPACESEARCH_EXPORT std::vector<std::vector<std::unique_ptr<ROMol>>>
45splitMolecule(const ROMol &query, unsigned int maxNumFrags,
46 const std::uint64_t maxNumFragSets, const TimePoint *endTime,
47 const int numThreads, bool &timedOut);
48// Counts the number of [1*], [2*]...[4*] in the string.
49 RDKIT_SYNTHONSPACESEARCH_EXPORT int countConnections(const ROMol &mol);
50
51// Return a bitset for each fragment giving the connector patterns
52 RDKIT_SYNTHONSPACESEARCH_EXPORT std::vector<boost::dynamic_bitset<>>
53getConnectorPatterns(const std::vector<std::unique_ptr<ROMol>> &fragSet);
54
55// Return a bitset giving the different connector types in this
56// molecule.
57 RDKIT_SYNTHONSPACESEARCH_EXPORT boost::dynamic_bitset<> getConnectorPattern(
58 const std::vector<std::unique_ptr<ROMol>> &fragSet);
59
60// Gets the permutations of connector numbers and the atoms they should
61// be applied to in the molFrags.
62// E.g. if the reaction has 3 connectors, 1, 2 and 3 and the fragged mol has
63// 2, return all permutations of 2 from 3. It's ok if the fragged mol doesn't
64// have all the connections in the reaction, although this may well result in
65// a lot of hits.
66 RDKIT_SYNTHONSPACESEARCH_EXPORT
67std::vector<std::vector<std::vector<std::pair<Atom *, unsigned int>>>>
68getConnectorPermutations(const std::vector<std::unique_ptr<ROMol>> &molFrags,
69 const boost::dynamic_bitset<> &fragConns,
70 const boost::dynamic_bitset<> &reactionConns);
71
72// As above, but just returns the bitsets for the connector permutations,
73// not the molecules.
74 RDKIT_SYNTHONSPACESEARCH_EXPORT
75std::vector<std::vector<boost::dynamic_bitset<>>> getConnectorPermutations(
76 const std::vector<boost::dynamic_bitset<>> &fragConnPatts,
77 const boost::dynamic_bitset<> &reactionConns);
78
79// If all bits in one of the bitsets is unset, it means that nothing matched
80// that synthon. If at least one of the bitsets has a set bit, all products
81// incorporating the synthon with no bits set must match the query so
82// should be used because the query matches products that don't incorporate
83// anything from 1 of the synthon lists. Therefore those bits will all be
84// set on exit. For example, if the synthons are
85// [1*]Nc1c([2*])cccc1 and [1*]=CC=C[2*] and the query is c1ccccc1.
86 RDKIT_SYNTHONSPACESEARCH_EXPORT void expandBitSet(
87 std::vector<boost::dynamic_bitset<>> &bitSets);
88
89 RDKIT_SYNTHONSPACESEARCH_EXPORT void bitSetsToVectors(
90 const std::vector<boost::dynamic_bitset<>> &bitSets,
91 std::vector<std::vector<size_t>> &outVecs);
92
93// class to step through all combinations of lists of different sizes.
94// returns (0,0,0), (0,0,1), (0,1,0) etc.
95 struct RDKIT_SYNTHONSPACESEARCH_EXPORT Stepper {
96 explicit Stepper(const std::vector<size_t> &sizes) : d_sizes(sizes) {
97 d_currState = std::vector<size_t>(sizes.size(), 0);
98 }
99 void step() {
100 // Don't do anything if we're at the end, but expect an infinite
101 // loop if the user isn't wise to this.
102 if (d_currState[0] == d_sizes[0]) {
103 return;
104 }
105 std::int64_t i = static_cast<std::int64_t>(d_currState.size()) - 1;
106 while (i >= 0) {
107 ++d_currState[i];
108 if (d_currState[0] == d_sizes[0]) {
109 return;
110 }
111 if (d_currState[i] == d_sizes[i]) {
112 d_currState[i] = 0;
113 } else {
114 break;
115 }
116 --i;
117 }
118 }
119 std::vector<size_t> d_currState;
120 std::vector<size_t> d_sizes;
121};
122
123// Return a molecule containing the portions of the molecule starting at
124// each dummy atom and going out up to 3 bonds. There may be more than
125// 1 fragment if there are dummy atoms more than 3 bonds apart, and there
126// may be fragments with more than 1 dummy atom if their dummy atoms fall
127// within 3 bonds of each other. E.g. the molecule [1*]CN(C[2*])Cc1ccccc1
128// will give [1*]CN(C)C[1*]. The 2 dummy atoms are 4 bonds apart, but the
129// fragments overlap. All dummy atoms given isotope 1 whatever they had
130// before.
131 RDKIT_SYNTHONSPACESEARCH_EXPORT std::unique_ptr<ROMol> buildConnRegion(
132 const ROMol &mol);
133
134// Take any query atoms out of the molecule, replacing them with the
135// nearest thing possible. Probably this will just be the atomic
136// number. It doesn't change dummy atoms that have an isotope as
137// these will be connectors, or anything with an AtomType query as
138// they are uncontroversial. Returns true if it did something,
139// false if the molecule was left unchanged.
140 RDKIT_SYNTHONSPACESEARCH_EXPORT bool removeQueryAtoms(RWMol &mol);
141
142// Put together a product name in the Enamine style, which uses
143// a semicolon as a separator and has the reagents names followed
144// by the reaction name.
145 RDKIT_SYNTHONSPACESEARCH_EXPORT std::string buildProductName(
146 const std::string &reactionId, const std::vector<std::string> &fragIds);
147 RDKIT_SYNTHONSPACESEARCH_EXPORT std::string buildProductName(
148 const RDKit::SynthonSpaceSearch::SynthonSpaceHitSet *hitset,
149 const std::vector<size_t> &fragNums);
150// Zip the fragments together to make a molecule. Assumes the connection
151// points are marking by isotope numbers on dummy atoms.
152 RDKIT_SYNTHONSPACESEARCH_EXPORT std::unique_ptr<ROMol> buildProduct(
153 const std::vector<const ROMol *> &synthons);
154
155// Make a map that has all the fragments with the same SMILES
156// in a vector keyed by that SMILES.
157 RDKIT_SYNTHONSPACESEARCH_EXPORT std::map<std::string, std::vector<ROMol *>>
158mapFragsBySmiles(std::vector<std::vector<std::unique_ptr<ROMol>>> &fragSets,
159 bool &cancelled);
160
161// Count the number of chiral atoms, both specified and unspecified i.e. any
162// atoms returned by findPotentialStereo. If numExcDummies is not nullptr,
163// it will be sent back with the number of chiral centres excluding those
164// that include 2 or more dummy atoms (which are flagged as chiral if the
165// dummies have different isotopes which will be the case here). They
166// may not be chiral in the final product if the 2 synthons attached are the
167// same. For example in [1*]C([2*])(N)[C@H](O)F with [1*]F and [2*]F, the
168// first C is deemed possibly chiral, but isn't with the 2 F atoms are
169// attached.
170 RDKIT_SYNTHONSPACESEARCH_EXPORT unsigned int countChiralAtoms(
171 ROMol &mol, unsigned int *numExcDummies = nullptr);
172
173} // namespace SynthonSpaceSearch::details
174} // namespace RDKit
175
176#endif // RDKIT_SYNTHONSPACESEARCHDETAILS_H
ExplicitBitVect.h
SynthonSpaceHitSet.h
Clock
std::chrono::steady_clock Clock
Definition SynthonSpaceSearch_details.h:21
TimePoint
std::chrono::time_point< Clock > TimePoint
Definition SynthonSpaceSearch_details.h:22
RDKit::ROMol
Definition ROMol.h:199
RDKit::RWMol
RWMol is a molecule class that is intended to be edited.
Definition RWMol.h:32
export.h
RDKIT_SYNTHONSPACESEARCH_EXPORT
#define RDKIT_SYNTHONSPACESEARCH_EXPORT
Definition export.h:577
RDKit::SynthonSpaceSearch::details::getConnectorPattern
RDKIT_SYNTHONSPACESEARCH_EXPORT boost::dynamic_bitset getConnectorPattern(const std::vector< std::unique_ptr< ROMol > > &fragSet)
RDKit::SynthonSpaceSearch::details::getConnectorPermutations
RDKIT_SYNTHONSPACESEARCH_EXPORT std::vector< std::vector< std::vector< std::pair< Atom *, unsigned int > > > > getConnectorPermutations(const std::vector< std::unique_ptr< ROMol > > &molFrags, const boost::dynamic_bitset<> &fragConns, const boost::dynamic_bitset<> &reactionConns)
RDKit::SynthonSpaceSearch::details::removeQueryAtoms
RDKIT_SYNTHONSPACESEARCH_EXPORT bool removeQueryAtoms(RWMol &mol)
RDKit::SynthonSpaceSearch::details::bitSetsToVectors
RDKIT_SYNTHONSPACESEARCH_EXPORT void bitSetsToVectors(const std::vector< boost::dynamic_bitset<> > &bitSets, std::vector< std::vector< size_t > > &outVecs)
RDKit::SynthonSpaceSearch::details::checkTimeOut
RDKIT_SYNTHONSPACESEARCH_EXPORT bool checkTimeOut(const TimePoint *endTime)
RDKit::SynthonSpaceSearch::details::countConnections
RDKIT_SYNTHONSPACESEARCH_EXPORT int countConnections(const ROMol &mol)
RDKit::SynthonSpaceSearch::details::countChiralAtoms
RDKIT_SYNTHONSPACESEARCH_EXPORT unsigned int countChiralAtoms(ROMol &mol, unsigned int *numExcDummies=nullptr)
RDKit::SynthonSpaceSearch::details::permMFromN
RDKIT_SYNTHONSPACESEARCH_EXPORT std::vector< std::vector< unsigned int > > permMFromN(unsigned int m, unsigned int n)
RDKit::SynthonSpaceSearch::details::getConnectorPatterns
RDKIT_SYNTHONSPACESEARCH_EXPORT std::vector< boost::dynamic_bitset<> > getConnectorPatterns(const std::vector< std::unique_ptr< ROMol > > &fragSet)
RDKit::SynthonSpaceSearch::details::buildConnRegion
RDKIT_SYNTHONSPACESEARCH_EXPORT std::unique_ptr< ROMol > buildConnRegion(const ROMol &mol)
RDKit::SynthonSpaceSearch::details::combMFromN
RDKIT_SYNTHONSPACESEARCH_EXPORT std::vector< std::vector< unsigned int > > combMFromN(unsigned int m, unsigned int n)
RDKit::SynthonSpaceSearch::details::splitMolecule
RDKIT_SYNTHONSPACESEARCH_EXPORT std::vector< std::vector< std::unique_ptr< ROMol > > > splitMolecule(const ROMol &query, unsigned int maxNumFrags, const std::uint64_t maxNumFragSets, const TimePoint *endTime, const int numThreads, bool &timedOut)
RDKit::SynthonSpaceSearch::details::mapFragsBySmiles
RDKIT_SYNTHONSPACESEARCH_EXPORT std::map< std::string, std::vector< ROMol * > > mapFragsBySmiles(std::vector< std::vector< std::unique_ptr< ROMol > > > &fragSets, bool &cancelled)
RDKit::SynthonSpaceSearch::details::buildProduct
RDKIT_SYNTHONSPACESEARCH_EXPORT std::unique_ptr< ROMol > buildProduct(const std::vector< const ROMol * > &synthons)
RDKit::SynthonSpaceSearch::details::buildProductName
RDKIT_SYNTHONSPACESEARCH_EXPORT std::string buildProductName(const std::string &reactionId, const std::vector< std::string > &fragIds)
RDKit::SynthonSpaceSearch::details::expandBitSet
RDKIT_SYNTHONSPACESEARCH_EXPORT void expandBitSet(std::vector< boost::dynamic_bitset<> > &bitSets)
RDKit
Std stuff.
Definition Abbreviations.h:19
RDKit::SynthonSpaceSearch::SynthonSpaceHitSet
Definition SynthonSpaceHitSet.h:27
RDKit::SynthonSpaceSearch::details::Stepper::Stepper
Stepper(const std::vector< size_t > &sizes)
Definition SynthonSpaceSearch_details.h:96
RDKit::SynthonSpaceSearch::details::Stepper::d_sizes
std::vector< size_t > d_sizes
Definition SynthonSpaceSearch_details.h:120
RDKit::SynthonSpaceSearch::details::Stepper::step
void step()
Definition SynthonSpaceSearch_details.h:99
RDKit::SynthonSpaceSearch::details::Stepper::d_currState
std::vector< size_t > d_currState
Definition SynthonSpaceSearch_details.h:119