Loading...
Searching...
No Matches
RGroupGa.h
Go to the documentation of this file.
//
// Copyright (C) 2020 Gareth Jones, Glysade LLC
//
// @@ All Rights Reserved @@
// This file is part of the RDKit.
// The contents are covered by the terms of the BSD license
// which is included in the file license.txt, found at the root
// of the RDKit source tree.
//
#ifndef RGROUPDECOMPGA_H_
#define RGROUPDECOMPGA_H_
#include <vector>
#include <memory>
#include <map>
#include <chrono>
#include "../../../External/GA/ga/StringChromosome.h"
#include "../../../External/GA/ga/GaBase.h"
#include "../../../External/GA/ga/GaOperation.h"
#include "../../../External/GA/ga/LinkedPopLinearSel.h"
#include "../../../External/GA/ga/IntegerStringChromosomePolicy.h"
#include "RGroupFingerprintScore.h"
#include "RGroupScore.h"
namespace RDKit {
using namespace GapeGa;
using namespace std;
class RGroupDecompositionChromosome;
class RGroupGa;
struct RGroupDecompData;
typedef LinkedPopLinearSel<RGroupDecompositionChromosome, RGroupGa>
RGroupGaPopulation;
typedef enum {
RgroupMutate = 0x01,
Crossover = 0x02,
Create = 0x04,
} OperationName;
class RGroupDecompositionChromosome : public IntegerStringChromosome {
public:
RGroupDecompositionChromosome(RGroupGa &rGroupGa);
double getFitness() const { return fitness; }
OperationName getOperationName() const { return operationName; }
void setOperationName(OperationName operationName) {
this->operationName = operationName;
}
std::string info() const;
double score();
double recalculateScore();
bool isOk() { return true; }
void decode();
void copyGene(const StringChromosomeBase &other) override;
FingerprintVarianceScoreData &getFingerprintVarianceScoreData() {
return fingerprintVarianceScoreData;
}
const vector<size_t> &getPermutation() const { return permutation; }
const RGroupGa &getRGroupGA() const { return rGroupGa; }
private:
RGroupDecompositionChromosome(const RGroupDecompositionChromosome &other) =
delete;
RGroupDecompositionChromosome &operator=(
const RGroupDecompositionChromosome &other) = delete;
double fitness;
FingerprintVarianceScoreData fingerprintVarianceScoreData;
OperationName operationName = Create;
vector<size_t> permutation;
RGroupGa &rGroupGa;
};
struct GaResult {
RGroupScorer rGroupScorer;
GaResult(const double score, const vector<vector<size_t>> &permutations)
: rGroupScorer(RGroupScorer(permutations, score)) {}
GaResult(const GaResult &other) : rGroupScorer(other.rGroupScorer) {}
GaResult() {}
// Copy constructor required by MSVC for future<GaResult>
GaResult &operator=(const GaResult &other);
};
class RDKIT_RGROUPDECOMPOSITION_EXPORT RGroupGa : public GaBase {
public:
RGroupGa(const RGroupDecompData &rGroupData,
const chrono::steady_clock::time_point *const t0 = nullptr);
IntegerStringChromosomePolicy &getChromosomePolicy() {
return chromosomePolicy;
}
int chromosomeLength() const { return chromLength; }
int numberDecompositions() const { return numberDecomps; }
GaResult run(int runNumber = 1);
vector<GaResult> runBatch();
shared_ptr<RGroupDecompositionChromosome> createChromosome();
const RGroupDecompData &getRGroupData() const { return rGroupData; }
const vector<shared_ptr<GaOperation<RGroupDecompositionChromosome>>>
getOperations() const;
unsigned int numberPermutations() const { return numPermutations; }
private:
RGroupGa(const RGroupGa &other) = delete;
RGroupGa &operator=(const RGroupGa &other) = delete;
const RGroupDecompData &rGroupData;
IntegerStringChromosomePolicy chromosomePolicy;
int numberOperations;
int numberOperationsWithoutImprovement;
int chromLength;
unsigned int numPermutations;
int numberDecomps;
const chrono::steady_clock::time_point *const t0;
void createOperations();
static void rGroupMutateOperation(
const std::vector<std::shared_ptr<RGroupDecompositionChromosome>>
&parents,
std::vector<std::shared_ptr<RGroupDecompositionChromosome>> &children);
static void rGroupCrossoverOperation(
const std::vector<std::shared_ptr<RGroupDecompositionChromosome>>
&parents,
std::vector<std::shared_ptr<RGroupDecompositionChromosome>> &children);
};
void copyVarianceData(const FingerprintVarianceScoreData &fromData,
FingerprintVarianceScoreData &toData);
void clearVarianceData(
FingerprintVarianceScoreData &fingerprintVarianceScoreData);
} // namespace RDKit
#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:441
RDKit
Std stuff.
Definition Abbreviations.h:19
RDKit::rdvalue_is
bool rdvalue_is(const RDValue_cast_t)
Definition RDValue-doublemagic.h:372
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