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 <RDGeneral/export.h>
18
19using Clock = std::chrono::steady_clock;
20using TimePoint = std::chrono::time_point<Clock>;
21
22namespace RDKit {
23class ROMol;
24namespace SynthonSpaceSearch::details {
25
27
28// Find all combinations of M things selected from N.
29RDKIT_SYNTHONSPACESEARCH_EXPORT std::vector<std::vector<unsigned int>>
30combMFromN(unsigned int m, unsigned int n);
31// Find all permutations of M things selected from N.
32RDKIT_SYNTHONSPACESEARCH_EXPORT std::vector<std::vector<unsigned int>>
33permMFromN(unsigned int m, unsigned int n);
35 std::vector<std::unique_ptr<ROMol>> &molFrags);
36
37// Split the molecule into fragments. maxBondSplits gives the maximum number
38// of bonds to be used in each split. There will a vector of vectors of
39// molecules, 1 inner vector for each split i.e. maxBondSplits in total, the
40// first with 1 split, the 2nd with 2 etc. Each inner vector contains the
41// fragments from a split molecule. The maxBondSplits will be constrained to
42// between 1 and 4 inclusive, so if it is supplied outside that range, it will
43// be altered. Also, you can't split a molecule on 3 bonds if it only contains
44// 2.
45RDKIT_SYNTHONSPACESEARCH_EXPORT std::vector<std::vector<std::unique_ptr<ROMol>>>
46splitMolecule(const ROMol &query, unsigned int maxBondSplits,
47 std::uint64_t maxNumFrags, TimePoint *endTime, bool &timedOut);
48// Counts the number of [1*], [2*]...[4*] in the string.
50
51// Return a bitset for each fragment giving the connector patterns
52RDKIT_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.
58 const std::vector<std::unique_ptr<ROMol>> &fragSet);
59
60// Return copies of the mol fragments will all permutations of the connectors
61// in the reaction onto the connectors in the fragments.
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.
66RDKIT_SYNTHONSPACESEARCH_EXPORT std::vector<std::vector<std::unique_ptr<ROMol>>>
67getConnectorPermutations(const std::vector<std::unique_ptr<ROMol>> &molFrags,
68 const boost::dynamic_bitset<> &fragConns,
69 const boost::dynamic_bitset<> &reactionConns);
70
71// If all bits in one of the bitsets is unset, it means that nothing matched
72// that synthon. If at least one of the bitsets has a set bit, all products
73// incorporating the synthon with no bits set must match the query so
74// should be used because the query matches products that don't incorporate
75// anything from 1 of the synthon lists. For example, if the synthons are
76// [1*]Nc1c([2*])cccc1 and [1*]=CC=C[2*] and the query is c1ccccc1.
78 std::vector<boost::dynamic_bitset<>> &bitSets);
79
81 const std::vector<boost::dynamic_bitset<>> &bitSets,
82 std::vector<std::vector<size_t>> &outVecs);
83
84// class to step through all combinations of lists of different sizes.
85// returns (0,0,0), (0,0,1), (0,1,0) etc.
87 explicit Stepper(const std::vector<size_t> &sizes) : d_sizes(sizes) {
88 d_currState = std::vector<size_t>(sizes.size(), 0);
89 }
90 void step() {
91 // Don't do anything if we're at the end, but expect an infinite
92 // loop if the user isn't wise to this.
93 if (d_currState[0] == d_sizes[0]) {
94 return;
95 }
96 std::int64_t i = static_cast<std::int64_t>(d_currState.size()) - 1;
97 while (i >= 0) {
98 ++d_currState[i];
99 if (d_currState[0] == d_sizes[0]) {
100 return;
101 }
102 if (d_currState[i] == d_sizes[i]) {
103 d_currState[i] = 0;
104 } else {
105 break;
106 }
107 --i;
108 }
109 }
110 std::vector<size_t> d_currState;
111 std::vector<size_t> d_sizes;
112};
113
114} // namespace SynthonSpaceSearch::details
115} // namespace RDKit
116
117#endif // RDKIT_SYNTHONSPACESEARCHDETAILS_H
std::chrono::steady_clock Clock
std::chrono::time_point< Clock > TimePoint
#define RDKIT_SYNTHONSPACESEARCH_EXPORT
Definition export.h:545
RDKIT_SYNTHONSPACESEARCH_EXPORT boost::dynamic_bitset getConnectorPattern(const std::vector< std::unique_ptr< ROMol > > &fragSet)
RDKIT_SYNTHONSPACESEARCH_EXPORT void bitSetsToVectors(const std::vector< boost::dynamic_bitset<> > &bitSets, std::vector< std::vector< size_t > > &outVecs)
RDKIT_SYNTHONSPACESEARCH_EXPORT bool checkTimeOut(const TimePoint *endTime)
RDKIT_SYNTHONSPACESEARCH_EXPORT std::vector< std::vector< unsigned int > > permMFromN(unsigned int m, unsigned int n)
RDKIT_SYNTHONSPACESEARCH_EXPORT std::vector< boost::dynamic_bitset<> > getConnectorPatterns(const std::vector< std::unique_ptr< ROMol > > &fragSet)
RDKIT_SYNTHONSPACESEARCH_EXPORT void fixAromaticRingSplits(std::vector< std::unique_ptr< ROMol > > &molFrags)
RDKIT_SYNTHONSPACESEARCH_EXPORT int countConnections(const ROMol &frag)
RDKIT_SYNTHONSPACESEARCH_EXPORT std::vector< std::vector< unsigned int > > combMFromN(unsigned int m, unsigned int n)
RDKIT_SYNTHONSPACESEARCH_EXPORT std::vector< std::vector< std::unique_ptr< ROMol > > > splitMolecule(const ROMol &query, unsigned int maxBondSplits, std::uint64_t maxNumFrags, TimePoint *endTime, bool &timedOut)
RDKIT_SYNTHONSPACESEARCH_EXPORT void expandBitSet(std::vector< boost::dynamic_bitset<> > &bitSets)
RDKIT_SYNTHONSPACESEARCH_EXPORT std::vector< std::vector< std::unique_ptr< ROMol > > > getConnectorPermutations(const std::vector< std::unique_ptr< ROMol > > &molFrags, const boost::dynamic_bitset<> &fragConns, const boost::dynamic_bitset<> &reactionConns)
Std stuff.
bool rdvalue_is(const RDValue_cast_t)