RDKit
Open-source cheminformatics and machine learning.
Toggle main menu visibility
Loading...
Searching...
No Matches
RGroupGa.h
Go to the documentation of this file.
1
//
2
// Copyright (C) 2020 Gareth Jones, Glysade LLC
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 RGROUPDECOMPGA_H_
12
#define RGROUPDECOMPGA_H_
13
14
#include <vector>
15
#include <memory>
16
#include <map>
17
#include <chrono>
18
19
#include "../../../External/GA/ga/StringChromosome.h"
20
#include "../../../External/GA/ga/GaBase.h"
21
#include "../../../External/GA/ga/GaOperation.h"
22
#include "../../../External/GA/ga/LinkedPopLinearSel.h"
23
#include "../../../External/GA/ga/IntegerStringChromosomePolicy.h"
24
#include "
RGroupFingerprintScore.h
"
25
#include "
RGroupScore.h
"
26
27
namespace
RDKit
{
28
29
using namespace
GapeGa;
30
using namespace
std;
31
32
class
RGroupDecompositionChromosome
;
33
class
RGroupGa
;
34
struct
RGroupDecompData
;
35
36
typedef
LinkedPopLinearSel<RGroupDecompositionChromosome, RGroupGa>
37
RGroupGaPopulation
;
38
39
typedef
enum
{
40
RgroupMutate
= 0x01,
41
Crossover
= 0x02,
42
Create
= 0x04,
43
}
OperationName
;
44
45
class
RGroupDecompositionChromosome
:
public
IntegerStringChromosome {
46
public
:
47
RGroupDecompositionChromosome
(
RGroupGa
&rGroupGa);
48
49
double
getFitness
()
const
{
return
fitness; }
50
51
OperationName
getOperationName
()
const
{
return
operationName; }
52
53
void
setOperationName
(
OperationName
operationName) {
54
this->operationName = operationName;
55
}
56
57
std::string
info
()
const
;
58
59
double
score
();
60
61
double
recalculateScore
();
62
63
bool
isOk
() {
return
true
; }
64
65
void
decode
();
66
67
void
copyGene
(
const
StringChromosomeBase &other)
override
;
68
69
FingerprintVarianceScoreData
&
getFingerprintVarianceScoreData
() {
70
return
fingerprintVarianceScoreData;
71
}
72
73
const
vector<size_t> &
getPermutation
()
const
{
return
permutation; }
74
75
const
RGroupGa
&
getRGroupGA
()
const
{
return
rGroupGa; }
76
77
private
:
78
RGroupDecompositionChromosome
(
const
RGroupDecompositionChromosome
&other) =
79
delete
;
80
RGroupDecompositionChromosome
&operator=(
81
const
RGroupDecompositionChromosome
&other) =
delete
;
82
double
fitness{0.0};
83
FingerprintVarianceScoreData fingerprintVarianceScoreData;
84
OperationName
operationName =
Create
;
85
vector<size_t> permutation;
86
87
RGroupGa &rGroupGa;
88
};
89
90
struct
GaResult
{
91
RGroupScorer
rGroupScorer
;
92
93
GaResult
(
const
double
score,
const
vector<vector<size_t>> &permutations)
94
:
rGroupScorer
(
RGroupScorer
(permutations, score)) {}
95
GaResult
(
const
GaResult
&other) :
rGroupScorer
(other.
rGroupScorer
) {}
96
97
GaResult
() {}
98
99
// Copy constructor required by MSVC for future<GaResult>
100
GaResult
&
operator=
(
const
GaResult
&other);
101
};
102
103
class
RDKIT_RGROUPDECOMPOSITION_EXPORT
RGroupGa
:
public
GaBase {
104
public
:
105
RGroupGa
(
const
RGroupDecompData
&rGroupData,
106
const
chrono::steady_clock::time_point *
const
t0 =
nullptr
);
107
108
IntegerStringChromosomePolicy &
getChromosomePolicy
() {
109
return
chromosomePolicy;
110
}
111
112
int
chromosomeLength
()
const
{
return
chromLength; }
113
114
int
numberDecompositions
()
const
{
return
numberDecomps; }
115
116
GaResult
run
(
int
runNumber = 1);
117
118
vector<GaResult>
runBatch
();
119
120
shared_ptr<RGroupDecompositionChromosome>
createChromosome
();
121
122
const
RGroupDecompData
&
getRGroupData
()
const
{
return
rGroupData; }
123
124
const
vector<shared_ptr<GaOperation<RGroupDecompositionChromosome>>>
125
getOperations
()
const
;
126
127
unsigned
int
numberPermutations
()
const
{
return
numPermutations; }
128
129
private
:
130
RGroupGa
(
const
RGroupGa
&other) =
delete
;
131
RGroupGa
&operator=(
const
RGroupGa
&other) =
delete
;
132
const
RGroupDecompData
&rGroupData;
133
134
IntegerStringChromosomePolicy chromosomePolicy;
135
int
numberOperations;
136
int
numberOperationsWithoutImprovement;
137
int
chromLength;
138
unsigned
int
numPermutations;
139
int
numberDecomps;
140
const
chrono::steady_clock::time_point *
const
t0;
141
142
void
createOperations();
143
144
static
void
rGroupMutateOperation(
145
const
std::vector<std::shared_ptr<RGroupDecompositionChromosome>>
146
&parents,
147
std::vector<std::shared_ptr<RGroupDecompositionChromosome>> &children);
148
static
void
rGroupCrossoverOperation(
149
const
std::vector<std::shared_ptr<RGroupDecompositionChromosome>>
150
&parents,
151
std::vector<std::shared_ptr<RGroupDecompositionChromosome>> &children);
152
};
153
154
void
copyVarianceData
(
const
FingerprintVarianceScoreData
&fromData,
155
FingerprintVarianceScoreData
&toData);
156
157
void
clearVarianceData
(
158
FingerprintVarianceScoreData
&fingerprintVarianceScoreData);
159
160
}
// namespace RDKit
161
162
#endif
// RGROUPDECOMPGA_H_
RGroupFingerprintScore.h
RGroupScore.h
RDKit::RGroupDecompositionChromosome
Definition
RGroupGa.h:45
RDKit::RGroupDecompositionChromosome::score
double score()
RDKit::RGroupDecompositionChromosome::getPermutation
const vector< size_t > & getPermutation() const
Definition
RGroupGa.h:73
RDKit::RGroupDecompositionChromosome::RGroupDecompositionChromosome
RGroupDecompositionChromosome(RGroupGa &rGroupGa)
RDKit::RGroupDecompositionChromosome::getOperationName
OperationName getOperationName() const
Definition
RGroupGa.h:51
RDKit::RGroupDecompositionChromosome::setOperationName
void setOperationName(OperationName operationName)
Definition
RGroupGa.h:53
RDKit::RGroupDecompositionChromosome::info
std::string info() const
RDKit::RGroupDecompositionChromosome::getFitness
double getFitness() const
Definition
RGroupGa.h:49
RDKit::RGroupDecompositionChromosome::recalculateScore
double recalculateScore()
RDKit::RGroupDecompositionChromosome::getRGroupGA
const RGroupGa & getRGroupGA() const
Definition
RGroupGa.h:75
RDKit::RGroupDecompositionChromosome::copyGene
void copyGene(const StringChromosomeBase &other) override
RDKit::RGroupDecompositionChromosome::getFingerprintVarianceScoreData
FingerprintVarianceScoreData & getFingerprintVarianceScoreData()
Definition
RGroupGa.h:69
RDKit::RGroupDecompositionChromosome::isOk
bool isOk()
Definition
RGroupGa.h:63
RDKit::RGroupDecompositionChromosome::decode
void decode()
RDKit::RGroupGa
Definition
RGroupGa.h:103
RDKit::RGroupGa::getChromosomePolicy
IntegerStringChromosomePolicy & getChromosomePolicy()
Definition
RGroupGa.h:108
RDKit::RGroupGa::runBatch
vector< GaResult > runBatch()
RDKit::RGroupGa::getRGroupData
const RGroupDecompData & getRGroupData() const
Definition
RGroupGa.h:122
RDKit::RGroupGa::chromosomeLength
int chromosomeLength() const
Definition
RGroupGa.h:112
RDKit::RGroupGa::getOperations
const vector< shared_ptr< GaOperation< RGroupDecompositionChromosome > > > getOperations() const
RDKit::RGroupGa::numberDecompositions
int numberDecompositions() const
Definition
RGroupGa.h:114
RDKit::RGroupGa::createChromosome
shared_ptr< RGroupDecompositionChromosome > createChromosome()
RDKit::RGroupGa::RGroupGa
RGroupGa(const RGroupDecompData &rGroupData, const chrono::steady_clock::time_point *const t0=nullptr)
RDKit::RGroupGa::run
GaResult run(int runNumber=1)
RDKit::RGroupGa::numberPermutations
unsigned int numberPermutations() const
Definition
RGroupGa.h:127
RDKit::RGroupScorer
Definition
RGroupScore.h:71
RDKIT_RGROUPDECOMPOSITION_EXPORT
#define RDKIT_RGROUPDECOMPOSITION_EXPORT
Definition
export.h:601
RDKit
Std stuff.
Definition
Abbreviations.h:19
RDKit::copyVarianceData
void copyVarianceData(const FingerprintVarianceScoreData &fromData, FingerprintVarianceScoreData &toData)
RDKit::OperationName
OperationName
Definition
RGroupGa.h:39
RDKit::Crossover
@ Crossover
Definition
RGroupGa.h:41
RDKit::Create
@ Create
Definition
RGroupGa.h:42
RDKit::RgroupMutate
@ RgroupMutate
Definition
RGroupGa.h:40
RDKit::clearVarianceData
void clearVarianceData(FingerprintVarianceScoreData &fingerprintVarianceScoreData)
RDKit::RGroupGaPopulation
LinkedPopLinearSel< RGroupDecompositionChromosome, RGroupGa > RGroupGaPopulation
Definition
RGroupGa.h:37
RDKit::FingerprintVarianceScoreData
Definition
RGroupFingerprintScore.h:42
RDKit::GaResult
Definition
RGroupGa.h:90
RDKit::GaResult::rGroupScorer
RGroupScorer rGroupScorer
Definition
RGroupGa.h:91
RDKit::GaResult::operator=
GaResult & operator=(const GaResult &other)
RDKit::GaResult::GaResult
GaResult(const double score, const vector< vector< size_t > > &permutations)
Definition
RGroupGa.h:93
RDKit::GaResult::GaResult
GaResult()
Definition
RGroupGa.h:97
RDKit::GaResult::GaResult
GaResult(const GaResult &other)
Definition
RGroupGa.h:95
RDKit::RGroupDecompData
Definition
RGroupDecompData.h:24
GraphMol
RGroupDecomposition
RGroupGa.h
Generated on
for RDKit by
1.17.0