RDKit
Open-source cheminformatics and machine learning.
RGroupScore.h
Go to the documentation of this file.
1 //
2 // Copyright (C) 2017 Novartis Institutes for BioMedical Research
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 #ifndef RGROUP_SCORE_H
11 #define RGROUP_SCORE_H
12 
13 #include "RGroupMatch.h"
14 #include <vector>
15 #include <set>
16 namespace RDKit {
17 
18 //! iterate through all possible permutations of the rgroups
20  std::vector<size_t> permutation;
21  std::vector<size_t> sizes;
22  std::deque<size_t> bases;
25  CartesianProduct(const std::vector<size_t> &inputSizes)
26  : permutation(inputSizes.size(), 0),
27  sizes(inputSizes),
28  permutationCount(0) {
29  maxPermutations = 1;
30  for (unsigned long size : sizes) {
31  bases.push_front(maxPermutations);
32  maxPermutations *= size; // may overflow....
33  }
34  }
35 
36  bool next() {
38  if (permutationCount == 1) {
39  return true;
40  }
41 
42  return increment(0);
43  }
44 
45  size_t value() {
46  size_t v = 0;
47  for (size_t i = 0; i < permutation.size(); ++i) {
48  v += bases[i] * permutation[i];
49  }
50  return v;
51  }
52 
53  bool increment(size_t rowToIncrement) {
55  return false;
56  }
57 
58  permutation[rowToIncrement] += 1;
59  size_t max_index_of_row = sizes[rowToIncrement] - 1;
60  if (permutation[rowToIncrement] > max_index_of_row) {
61  permutation[rowToIncrement] = 0;
62  return increment(rowToIncrement + 1);
63  }
64  return true;
65  }
66 };
67 
68 double score(const std::vector<size_t> &permutation,
69  const std::vector<std::vector<RGroupMatch>> &matches,
70  const std::set<int> &labels);
71 }
72 #endif
Std stuff.
Definition: Abbreviations.h:17
double score(const std::vector< size_t > &permutation, const std::vector< std::vector< RGroupMatch >> &matches, const std::set< int > &labels)
iterate through all possible permutations of the rgroups
Definition: RGroupScore.h:19
std::vector< size_t > sizes
Definition: RGroupScore.h:21
std::deque< size_t > bases
Definition: RGroupScore.h:22
CartesianProduct(const std::vector< size_t > &inputSizes)
Definition: RGroupScore.h:25
bool increment(size_t rowToIncrement)
Definition: RGroupScore.h:53
std::vector< size_t > permutation
Definition: RGroupScore.h:20