RGroupDecompData.h
Go to the documentation of this file.
//
// Copyright (C) 2017 Novartis Institutes for BioMedical Research
//
// @@ 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 RGROUP_DECOMP_DATA
#define RGROUP_DECOMP_DATA
#include "RGroupCore.h"
#include "RGroupDecomp.h"
#include "RGroupMatch.h"
#include "RGroupScore.h"
#include "RGroupFingerprintScore.h"
#include "RGroupGa.h"
#include <vector>
#include <map>
// #define VERBOSE 1
namespace RDKit {
struct RGroupDecompData {
// matches[mol_idx] == vector of potential matches
std::map<int, RCore> cores;
std::map<std::string, int> newCores; // new "cores" found along the way
int newCoreLabel = EMPTY_CORE_LABEL;
// this caches the running product of permutations
// across calls to process()
size_t permutationProduct = 1;
// this caches the size of the previous matches vector
// such that the size of the current chunk can be inferred
size_t previousMatchSize = 0;
// the default for Greedy/GreedyChunks is keeping only the best
// permutation after each call to process()
bool prunePermutations = true;
RGroupDecompositionParameters params;
std::vector<std::vector<RGroupMatch>> matches;
std::set<int> labels;
std::vector<size_t> permutation;
unsigned int pruneLength = 0U;
FingerprintVarianceScoreData prunedFingerprintVarianceScoreData;
std::map<int, std::vector<int>> userLabels;
std::vector<int> processedRlabels;
std::map<int, int> finalRlabelMapping;
mutable RGroupScorer rGroupScorer;
RGroupDecompData(const RWMol &inputCore,
RGroupDecompositionParameters inputParams)
: params(std::move(inputParams)) {
cores[0] = RCore(inputCore);
prepareCores();
}
RGroupDecompData(const std::vector<ROMOL_SPTR> &inputCores,
RGroupDecompositionParameters inputParams)
: params(std::move(inputParams)) {
for (size_t i = 0; i < inputCores.size(); ++i) {
cores[i] = RCore(*inputCores[i]);
}
prepareCores();
}
void prepareCores() {
for (auto &core : cores) {
RWMol *alignCore = core.first ? cores[0].core.get() : nullptr;
CHECK_INVARIANT(params.prepareCore(*core.second.core, alignCore),
"Could not prepare at least one core");
core.second.init();
core.second.labelledCore.reset(new RWMol(*core.second.core));
}
}
void setRlabel(Atom *atom, int rlabel) {
PRECONDITION(rlabel != 0, "RLabels must be >0");
if (params.rgroupLabelling & AtomMap) {
atom->setAtomMapNum(rlabel);
}
if (params.rgroupLabelling & MDLRGroup) {
std::string dLabel = "R" + std::to_string(rlabel);
atom->setProp(common_properties::dummyLabel, dLabel);
setAtomRLabel(atom, rlabel);
}
if (params.rgroupLabelling & Isotope) {
atom->setIsotope(rlabel + 1);
}
}
double scoreFromPrunedData(const std::vector<size_t> &permutation,
bool reset = true) {
PRECONDITION(
static_cast<RGroupScore>(params.scoreMethod) == FingerprintVariance,
"Scoring method is not fingerprint variance!");
PRECONDITION(permutation.size() >= pruneLength,
"Illegal permutation prune length");
if (permutation.size() < pruneLength * 1.5) {
for (unsigned int pos = pruneLength; pos < permutation.size(); ++pos) {
prunedFingerprintVarianceScoreData.addVarianceData(
pos, permutation[pos], matches, labels);
}
double score =
prunedFingerprintVarianceScoreData.fingerprintVarianceGroupScore();
if (reset) {
for (unsigned int pos = pruneLength; pos < permutation.size(); ++pos) {
prunedFingerprintVarianceScoreData.removeVarianceData(
pos, permutation[pos], matches, labels);
}
} else {
pruneLength = permutation.size();
}
return score;
} else {
if (reset) {
return fingerprintVarianceScore(permutation, matches, labels);
} else {
prunedFingerprintVarianceScoreData.clear();
pruneLength = permutation.size();
return fingerprintVarianceScore(permutation, matches, labels,
&prunedFingerprintVarianceScoreData);
}
}
}
void prune() { // prune all but the current "best" permutation of matches
PRECONDITION(permutation.size() <= matches.size(), "permutation.size() should be <= matches.size()");
size_t offset = matches.size() - permutation.size();
for (size_t mol_idx = 0; mol_idx < permutation.size(); ++mol_idx) {
std::vector<RGroupMatch> keepVector;
size_t mi = mol_idx + offset;
keepVector.push_back(matches[mi].at(permutation[mol_idx]));
matches[mi] = keepVector;
}
permutation = std::vector<size_t>(permutation.size(), 0);
if (params.scoreMethod == FingerprintVariance &&
params.matchingStrategy != GA) {
scoreFromPrunedData(permutation, false);
}
}
// Return the RGroups with the current "best" permutation
// of matches.
std::vector<RGroupMatch> GetCurrentBestPermutation() const {
const bool removeAllHydrogenRGroups =
params.removeAllHydrogenRGroups ||
params.removeAllHydrogenRGroupsAndLabels;
std::vector<RGroupMatch> results; // std::map<int, RGroup> > result;
bool isPruned = (permutation.size() < matches.size());
for (size_t i = 0; i < matches.size(); ++i) {
size_t pi = (isPruned ? 0 : permutation.at(i));
results.push_back(matches[i].at(pi));
}
// * if a dynamically-added RGroup (i.e., when onlyMatchAtRGroups=false)
// is all hydrogens, remove it
// * if a user-defined RGroup is all hydrogens and either
// params.removeAllHydrogenRGroups==true or
// params.removeAllHydrogenRGroupsAndLabels==true, remove it
// This logic is a bit tricky, find all labels that have common cores
// and analyze those sets independently.
// i.e. if core 1 doesn't have R1 then don't analyze it in when looking
// at label 1
std::map<int, std::set<int>> labelCores; // map from label->cores
std::set<int> coresVisited;
for (auto &position : results) {
int core_idx = position.core_idx;
if (coresVisited.find(core_idx) == coresVisited.end()) {
coresVisited.insert(core_idx);
auto core = cores.find(core_idx);
if (core != cores.end()) {
for (auto rlabels : getRlabels(*core->second.core)) {
int rlabel = rlabels.first;
labelCores[rlabel].insert(core_idx);
}
}
}
}
for (int label : labels) {
if (label > 0 && !removeAllHydrogenRGroups) {
continue;
}
bool allH = true;
for (auto &position : results) {
R_DECOMP::const_iterator rgroup = position.rgroups.find(label);
bool labelHasCore = labelCores[label].find(position.core_idx) !=
labelCores[label].end();
if (labelHasCore && rgroup != position.rgroups.end() &&
!rgroup->second->is_hydrogen) {
allH = false;
break;
}
}
if (allH) {
for (auto &position : results) {
position.rgroups.erase(label);
}
}
}
return results;
}
class UsedLabels {
public:
std::set<int> labels_used;
bool add(int rlabel) {
if (labels_used.find(rlabel) != labels_used.end()) {
return false;
}
labels_used.insert(rlabel);
return true;
}
int next() {
int i = 1;
while (labels_used.find(i) != labels_used.end()) {
++i;
}
labels_used.insert(i);
return i;
}
};
void addCoreUserLabels(const RWMol &core, std::set<int> &userLabels) {
auto atoms = getRlabels(core);
for (const auto &p : atoms) {
if (p.first > 0) {
userLabels.insert(p.first);
}
}
}
void addAtoms(RWMol &mol,
const std::vector<std::pair<Atom *, Atom *>> &atomsToAdd) {
for (const auto &i : atomsToAdd) {
mol.addAtom(i.second, false, true);
mol.addBond(i.first, i.second, Bond::SINGLE);
if (mol.getNumConformers()) {
MolOps::setTerminalAtomCoords(mol, i.second->getIdx(),
i.first->getIdx());
}
}
}
void relabelCore(RWMol &core, std::map<int, int> &mappings,
UsedLabels &used_labels, const std::set<int> &indexLabels,
const std::map<int, std::vector<int>> &extraAtomRLabels) {
// Now remap to proper rlabel ids
// if labels are positive, they come from User labels
// if they are negative, they come from indices and should be
// numbered *after* the user labels.
//
// Some indices are attached to multiple bonds,
// these rlabels should be incrementally added last
std::map<int, Atom *> atoms = getRlabels(core);
// a core only has one labelled index
// a secondary structure extraAtomRLabels contains the number
// of bonds between this atom and the side chain
// a sidechain atom has a vector of the attachments back to the
// core that takes the place of numBondsToRlabel
std::map<int, std::vector<int>> bondsToCore;
std::vector<std::pair<Atom *, Atom *>> atomsToAdd; // adds -R if necessary
// Deal with user supplied labels
for (const auto &rlabels : atoms) {
int userLabel = rlabels.first;
if (userLabel < 0) {
continue; // not a user specified label
}
Atom *atom = rlabels.second;
mappings[userLabel] = userLabel;
used_labels.add(userLabel);
if (atom->getAtomicNum() == 0 &&
atom->getDegree() == 1) { // add to existing dummy/rlabel
setRlabel(atom, userLabel);
} else { // adds new rlabel
auto *newAt = new Atom(0);
setRlabel(newAt, userLabel);
atomsToAdd.emplace_back(atom, newAt);
}
}
// Deal with non-user supplied labels
for (auto newLabel : indexLabels) {
auto atm = atoms.find(newLabel);
if (atm == atoms.end()) {
continue;
}
Atom *atom = atm->second;
int rlabel;
auto mapping = mappings.find(newLabel);
if (mapping == mappings.end()) {
rlabel = used_labels.next();
mappings[newLabel] = rlabel;
} else {
rlabel = mapping->second;
}
if (atom->getAtomicNum() == 0 &&
!isAnyAtomWithMultipleNeighborsOrNotUserRLabel(
*atom)) { // add to dummy
setRlabel(atom, rlabel);
} else {
auto *newAt = new Atom(0);
setRlabel(newAt, rlabel);
atomsToAdd.emplace_back(atom, newAt);
}
}
// Deal with multiple bonds to the same label
for (const auto &extraAtomRLabel : extraAtomRLabels) {
auto atm = atoms.find(extraAtomRLabel.first);
if (atm == atoms.end()) {
continue; // label not used in the rgroup
}
Atom *atom = atm->second;
for (size_t i = 0; i < extraAtomRLabel.second.size(); ++i) {
int rlabel = used_labels.next();
// Is this necessary?
CHECK_INVARIANT(
atom->getAtomicNum() > 1,
"Multiple attachments to a dummy (or hydrogen) is weird.");
auto *newAt = new Atom(0);
setRlabel(newAt, rlabel);
atomsToAdd.emplace_back(atom, newAt);
}
}
addAtoms(core, atomsToAdd);
for (const auto &rlabels : atoms) {
auto atom = rlabels.second;
atom->clearProp(RLABEL);
atom->clearProp(RLABEL_TYPE);
}
core.updatePropertyCache(false); // this was github #1550
}
void relabelRGroup(RGroupData &rgroup, const std::map<int, int> &mappings) {
PRECONDITION(rgroup.combinedMol.get(), "Unprocessed rgroup");
RWMol &mol = *rgroup.combinedMol.get();
if (rgroup.combinedMol->hasProp(done)) {
rgroup.labelled = true;
return;
}
mol.setProp(done, true);
std::vector<std::pair<Atom *, Atom *>> atomsToAdd; // adds -R if necessary
std::map<int, int> rLabelCoreIndexToAtomicWt;
for (RWMol::AtomIterator atIt = mol.beginAtoms(); atIt != mol.endAtoms();
++atIt) {
Atom *atom = *atIt;
if (atom->hasProp(SIDECHAIN_RLABELS)) {
atom->setIsotope(0);
const std::vector<int> &rlabels =
atom->getProp<std::vector<int>>(SIDECHAIN_RLABELS);
// switch on atom mappings or rlabels....
for (int rlabel : rlabels) {
auto label = mappings.find(rlabel);
CHECK_INVARIANT(label != mappings.end(), "Unprocessed mapping");
if (atom->getAtomicNum() == 0) {
setRlabel(atom, label->second);
} else if (atom->hasProp(RLABEL_CORE_INDEX)) {
atom->setAtomicNum(0);
setRlabel(atom, label->second);
} else {
auto *newAt = new Atom(0);
setRlabel(newAt, label->second);
atomsToAdd.emplace_back(atom, newAt);
}
}
}
if (atom->hasProp(RLABEL_CORE_INDEX)) {
// convert to dummy as we don't want to collapse hydrogens onto the core
// match
auto rLabelCoreIndex = atom->getProp<int>(RLABEL_CORE_INDEX);
rLabelCoreIndexToAtomicWt[rLabelCoreIndex] = atom->getAtomicNum();
atom->setAtomicNum(0);
}
}
addAtoms(mol, atomsToAdd);
if (params.removeHydrogensPostMatch) {
RDLog::BlockLogs blocker;
bool implicitOnly = false;
bool updateExplicitCount = false;
bool sanitize = false;
MolOps::removeHs(mol, implicitOnly, updateExplicitCount, sanitize);
}
mol.updatePropertyCache(false); // this was github #1550
rgroup.labelled = true;
// Restore any core matches that we have set to dummy
for (RWMol::AtomIterator atIt = mol.beginAtoms(); atIt != mol.endAtoms();
++atIt) {
Atom *atom = *atIt;
if (atom->hasProp(RLABEL_CORE_INDEX)) {
// don't need to set IsAromatic on atom - that seems to have been saved
atom->setAtomicNum(
rLabelCoreIndexToAtomicWt[atom->getProp<int>(RLABEL_CORE_INDEX)]);
atom->setNoImplicit(true);
atom->clearProp(RLABEL_CORE_INDEX);
}
atom->clearProp(SIDECHAIN_RLABELS);
}
#ifdef VERBOSE
std::cerr << "Relabel Rgroup smiles " << MolToSmiles(mol) << std::endl;
#endif
}
// relabel the core and sidechains using the specified user labels
// if matches exist for non labelled atoms, these are added as well
void relabel() {
std::vector<RGroupMatch> best = GetCurrentBestPermutation();
// get the labels used
std::set<int> userLabels;
std::set<int> indexLabels;
// Go through all the RGroups and find out which labels were
// actually used.
// some atoms will have multiple attachment points, i.e. cycles
// split these up into new rlabels if necessary
// These are detected at match time
// This vector will hold the extra (new) labels required
std::map<int, std::vector<int>> extraAtomRLabels;
for (auto &it : best) {
for (auto &rgroup : it.rgroups) {
if (rgroup.first > 0) {
userLabels.insert(rgroup.first);
}
if (rgroup.first < 0 && !params.onlyMatchAtRGroups) {
indexLabels.insert(rgroup.first);
}
std::map<int, int> rlabelsUsedInRGroup =
rgroup.second->getNumBondsToRlabels();
for (auto &numBondsUsed : rlabelsUsedInRGroup) {
// Make space for the extra labels
if (numBondsUsed.second > 1) { // multiple rgroup bonds to same atom
extraAtomRLabels[numBondsUsed.first].resize(numBondsUsed.second -
1);
}
}
}
}
// find user labels that are not present in the decomposition
for (auto &core : cores) {
core.second.labelledCore.reset(new RWMol(*core.second.core));
addCoreUserLabels(*core.second.labelledCore, userLabels);
}
// Assign final RGroup labels to the cores and propagate these to
// the scaffold
finalRlabelMapping.clear();
UsedLabels used_labels;
// Add all the user labels now to prevent an index label being assigned to a
// user label when multiple cores are present (e.g. the user label is
// present in the second core, but not the first).
for (auto userLabel : userLabels) {
used_labels.add(userLabel);
}
for (auto &core : cores) {
relabelCore(*core.second.labelledCore, finalRlabelMapping, used_labels,
indexLabels, extraAtomRLabels);
}
for (auto &it : best) {
for (auto &rgroup : it.rgroups) {
relabelRGroup(*rgroup.second, finalRlabelMapping);
}
}
std::set<int> uniqueMappedValues;
std::transform(finalRlabelMapping.cbegin(), finalRlabelMapping.cend(),
std::inserter(uniqueMappedValues, uniqueMappedValues.end()),
[](const std::pair<int, int> &p) { return p.second; });
CHECK_INVARIANT(finalRlabelMapping.size() == uniqueMappedValues.size(),
"Error in uniqueness of final RLabel mapping");
CHECK_INVARIANT(
uniqueMappedValues.size() == userLabels.size() + indexLabels.size(),
"Error in final RMapping size");
}
double score(const std::vector<size_t> &permutation,
FingerprintVarianceScoreData *fingerprintVarianceScoreData =
nullptr) const {
RGroupScore scoreMethod = static_cast<RGroupScore>(params.scoreMethod);
switch (scoreMethod) {
case Match:
return rGroupScorer.matchScore(permutation, matches, labels);
break;
case FingerprintVariance:
return fingerprintVarianceScore(permutation, matches, labels,
fingerprintVarianceScoreData);
break;
default:;
}
return NAN;
}
RGroupDecompositionProcessResult process(bool pruneMatches,
bool finalize = false) {
if (matches.empty()) {
return RGroupDecompositionProcessResult(false, -1);
}
auto t0 = std::chrono::steady_clock::now();
std::unique_ptr<CartesianProduct> iterator;
rGroupScorer.startProcessing();
if (params.matchingStrategy == GA) {
RGroupGa ga(*this, params.timeout >= 0 ? &t0 : nullptr);
if (ga.numberPermutations() < 100 * ga.getPopsize()) {
params.matchingStrategy = Exhaustive;
} else {
if (params.gaNumberRuns > 1) {
auto results = ga.runBatch();
auto best = max_element(results.begin(), results.end(),
[](const GaResult &a, const GaResult &b) {
return a.rGroupScorer.getBestScore() <
b.rGroupScorer.getBestScore();
});
rGroupScorer = best->rGroupScorer;
} else {
auto result = ga.run();
rGroupScorer = result.rGroupScorer;
}
}
}
size_t offset = 0;
if (params.matchingStrategy != GA) {
// Exhaustive search, get the MxN matrix
// (M = matches.size(): number of molecules
// N = iterator.maxPermutations)
std::vector<size_t> permutations;
if (pruneMatches && params.scoreMethod != FingerprintVariance) {
offset = previousMatchSize;
}
previousMatchSize = matches.size();
std::transform(
matches.begin() + offset, matches.end(),
std::back_inserter(permutations),
[](const std::vector<RGroupMatch> &m) { return m.size(); });
permutation = std::vector<size_t>(permutations.size(), 0);
// run through all possible matches and score each
// set
size_t count = 0;
#ifdef DEBUG
std::cerr << "Processing" << std::endl;
#endif
std::unique_ptr<CartesianProduct> it(new CartesianProduct(permutations));
iterator = std::move(it);
// Iterates through the permutation idx, i.e.
// [m1_permutation_idx, m2_permutation_idx, m3_permutation_idx]
while (iterator->next()) {
if (count > iterator->maxPermutations) {
throw ValueErrorException("next() did not finish");
}
#ifdef DEBUG
std::cerr << "**************************************************"
<< std::endl;
#endif
double newscore = params.scoreMethod == FingerprintVariance
? scoreFromPrunedData(iterator->permutation)
: score(iterator->permutation);
if (fabs(newscore - rGroupScorer.getBestScore()) <
1e-6) { // heuristic to overcome floating point comparison issues
rGroupScorer.pushTieToStore(iterator->permutation);
} else if (newscore > rGroupScorer.getBestScore()) {
#ifdef DEBUG
std::cerr << " ===> current best:" << newscore << ">"
<< rGroupScorer.getBestScore() << std::endl;
#endif
rGroupScorer.setBestPermutation(iterator->permutation, newscore);
rGroupScorer.clearTieStore();
rGroupScorer.pushTieToStore(iterator->permutation);
}
++count;
}
}
if (rGroupScorer.tieStoreSize() > 1) {
rGroupScorer.breakTies(matches, labels, iterator, t0, params.timeout);
rGroupScorer.clearTieStore();
} else {
checkForTimeout(t0, params.timeout);
}
permutation = rGroupScorer.getBestPermutation();
if (pruneMatches || finalize) {
prune();
}
if (finalize) {
relabel();
}
return RGroupDecompositionProcessResult(true, rGroupScorer.getBestScore());
}
};
} // namespace RDKit
#endif
CHECK_INVARIANT
#define CHECK_INVARIANT(expr, mess)
Definition: Invariant.h:101
PRECONDITION
#define PRECONDITION(expr, mess)
Definition: Invariant.h:109
RGroupCore.h
RGroupDecomp.h
RGroupFingerprintScore.h
RGroupGa.h
RGroupMatch.h
RGroupScore.h
RDKit::Atom
The class for representing atoms.
Definition: Atom.h:68
RDKit::Atom::setNoImplicit
void setNoImplicit(bool what)
sets our noImplicit flag, indicating whether or not we are allowed to have implicit Hs
Definition: Atom.h:209
RDKit::Atom::setAtomicNum
void setAtomicNum(int newNum)
sets our atomic number
Definition: Atom.h:117
RDKit::Atom::setIsotope
void setIsotope(unsigned int what)
sets our isotope number
RDKit::Atom::getAtomicNum
int getAtomicNum() const
returns our atomic number
Definition: Atom.h:115
RDKit::Atom::setAtomMapNum
void setAtomMapNum(int mapno, bool strict=true)
Set the atom map Number of the atom.
Definition: Atom.h:363
RDKit::Atom::getDegree
unsigned int getDegree() const
RDKit::Bond::SINGLE
@ SINGLE
Definition: Bond.h:57
RDKit::RDProps::clearProp
void clearProp(const std::string &key) const
clears the value of a property
Definition: RDProps.h:132
RDKit::RDProps::getProp
void getProp(const std::string &key, T &res) const
allows retrieval of a particular property value
Definition: RDProps.h:102
RDKit::RDProps::hasProp
bool hasProp(const std::string &key) const
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: RDProps.h:121
RDKit::RDProps::setProp
void setProp(const std::string &key, T val, bool computed=false) const
sets a property value
Definition: RDProps.h:72
RDKit::RGroupDecompData::UsedLabels
Definition: RGroupDecompData.h:214
RDKit::RGroupDecompData::UsedLabels::add
bool add(int rlabel)
Definition: RGroupDecompData.h:217
RDKit::RGroupDecompData::UsedLabels::next
int next()
Definition: RGroupDecompData.h:225
RDKit::RGroupDecompData::UsedLabels::labels_used
std::set< int > labels_used
Definition: RGroupDecompData.h:216
RDKit::RGroupGa
Definition: RGroupGa.h:103
RDKit::RGroupGa::runBatch
vector< GaResult > runBatch()
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::RGroupScorer::pushTieToStore
void pushTieToStore(const std::vector< size_t > &permutation)
store the passed tied permutation for subsequent processing
RDKit::RGroupScorer::startProcessing
void startProcessing()
called when process() starts to initialize State
RDKit::RGroupScorer::setBestPermutation
void setBestPermutation(const std::vector< size_t > &permutation, double score)
set the passed permutation and score as the best one
RDKit::RGroupScorer::breakTies
void breakTies(const std::vector< std::vector< RGroupMatch >> &matches, const std::set< int > &labels, const std::unique_ptr< CartesianProduct > &iterator, const std::chrono::steady_clock::time_point &t0, double timeout)
find the best permutation across the tied ones that were stored
RDKit::RGroupScorer::clearTieStore
void clearTieStore()
clear all stored tied permutations
RDKit::RGroupScorer::getBestPermutation
const std::vector< size_t > & getBestPermutation() const
return the best permutation found so far
Definition: RGroupScore.h:83
RDKit::RGroupScorer::matchScore
double matchScore(const std::vector< size_t > &permutation, const std::vector< std::vector< RGroupMatch >> &matches, const std::set< int > &labels)
score the passed permutation of matches
RDKit::RGroupScorer::tieStoreSize
size_t tieStoreSize() const
number of stored tied permutations
Definition: RGroupScore.h:99
RDKit::RGroupScorer::getBestScore
double getBestScore() const
return the best score found so far
Definition: RGroupScore.h:101
RDKit::ROMol::getNumConformers
unsigned int getNumConformers() const
Definition: ROMol.h:479
RDKit::ROMol::endAtoms
AtomIterator endAtoms()
get an AtomIterator pointing at the end of our Atoms
RDKit::ROMol::updatePropertyCache
void updatePropertyCache(bool strict=true)
calculates any of our lazy properties
RDKit::ROMol::beginAtoms
AtomIterator beginAtoms()
get an AtomIterator pointing at our first Atom
RDKit::RWMol
RWMol is a molecule class that is intended to be edited.
Definition: RWMol.h:32
RDKit::RWMol::addAtom
unsigned int addAtom(bool updateLabel=true)
adds an empty Atom to our collection
RDKit::RWMol::addBond
unsigned int addBond(unsigned int beginAtomIdx, unsigned int endAtomIdx, Bond::BondType order=Bond::UNSPECIFIED)
adds a Bond between the indicated Atoms
ValueErrorException
Class to allow us to throw a ValueError from C++ and have it make it back to Python.
Definition: Exceptions.h:40
RDKit::CIPLabeler::to_string
static std::string to_string(const Descriptor &desc)
Definition: Descriptor.h:54
RDKit::MolOps::setTerminalAtomCoords
RDKIT_GRAPHMOL_EXPORT void setTerminalAtomCoords(ROMol &mol, unsigned int idx, unsigned int otherIdx)
RDKit::MolOps::removeHs
RDKIT_GRAPHMOL_EXPORT ROMol * removeHs(const ROMol &mol, bool implicitOnly=false, bool updateExplicitCount=false, bool sanitize=true)
returns a copy of a molecule with hydrogens removed
RDKit::common_properties::dummyLabel
RDKIT_RDGENERAL_EXPORT const std::string dummyLabel
RDKit
Std stuff.
Definition: Abbreviations.h:18
RDKit::RGroupScore
RGroupScore
Definition: RGroupDecomp.h:61
RDKit::Match
@ Match
Definition: RGroupDecomp.h:62
RDKit::FingerprintVariance
@ FingerprintVariance
Definition: RGroupDecomp.h:63
RDKit::getRlabels
std::map< int, Atom * > getRlabels(const RWMol &mol)
Get the RLabels,atom mapping for the current molecule.
RDKit::Exhaustive
@ Exhaustive
Definition: RGroupDecomp.h:43
RDKit::GA
@ GA
Definition: RGroupDecomp.h:45
RDKit::RLABEL_TYPE
const std::string RLABEL_TYPE
RDKit::RLABEL_CORE_INDEX
const std::string RLABEL_CORE_INDEX
RDKit::setAtomRLabel
RDKIT_GRAPHMOL_EXPORT void setAtomRLabel(Atom *atm, int rlabel)
RDKit::done
const std::string done
RDKit::MolToSmiles
RDKIT_SMILESPARSE_EXPORT std::string MolToSmiles(const ROMol &mol, const SmilesWriteParams &params)
returns canonical SMILES for a molecule
RDKit::RLABEL
RDKIT_RGROUPDECOMPOSITION_EXPORT const std::string RLABEL
RDKit::MDLRGroup
@ MDLRGroup
Definition: RGroupDecomp.h:51
RDKit::AtomMap
@ AtomMap
Definition: RGroupDecomp.h:49
RDKit::Isotope
@ Isotope
Definition: RGroupDecomp.h:50
RDKit::checkForTimeout
bool checkForTimeout(const std::chrono::steady_clock::time_point &t0, double timeout, bool throwOnTimeout=true)
Definition: RGroupDecomp.h:207
RDKit::isAnyAtomWithMultipleNeighborsOrNotUserRLabel
bool isAnyAtomWithMultipleNeighborsOrNotUserRLabel(const Atom &atom)
Definition: RGroupUtils.h:66
RDKit::SIDECHAIN_RLABELS
const std::string SIDECHAIN_RLABELS
RDKit::EMPTY_CORE_LABEL
const unsigned int EMPTY_CORE_LABEL
Definition: RGroupUtils.h:25
RDKit::fingerprintVarianceScore
RDKIT_RGROUPDECOMPOSITION_EXPORT double fingerprintVarianceScore(const std::vector< size_t > &permutation, const std::vector< std::vector< RGroupMatch >> &matches, const std::set< int > &labels, FingerprintVarianceScoreData *fingerprintVarianceScoreData=nullptr)
RDKit::CartesianProduct
iterate through all possible permutations of the rgroups
Definition: RGroupScore.h:20
RDKit::FingerprintVarianceScoreData
Definition: RGroupFingerprintScore.h:42
RDKit::FingerprintVarianceScoreData::fingerprintVarianceGroupScore
double fingerprintVarianceGroupScore()
RDKit::FingerprintVarianceScoreData::addVarianceData
void addVarianceData(int matchNumber, int permutationNumber, const std::vector< std::vector< RGroupMatch >> &matches, const std::set< int > &labels)
RDKit::FingerprintVarianceScoreData::removeVarianceData
void removeVarianceData(int matchNumber, int permutationNumber, const std::vector< std::vector< RGroupMatch >> &matches, const std::set< int > &labels)
RDKit::FingerprintVarianceScoreData::clear
void clear()
RDKit::GaResult
Definition: RGroupGa.h:90
RDKit::RCore
RCore is the core common to a series of molecules.
Definition: RGroupCore.h:24
RDKit::RGroupData
A single rgroup attached to a given core.
Definition: RGroupData.h:27
RDKit::RGroupData::combinedMol
boost::shared_ptr< RWMol > combinedMol
Definition: RGroupData.h:28
RDKit::RGroupData::labelled
bool labelled
Definition: RGroupData.h:41
RDKit::RGroupDecompData
Definition: RGroupDecompData.h:25
RDKit::RGroupDecompData::previousMatchSize
size_t previousMatchSize
Definition: RGroupDecompData.h:35
RDKit::RGroupDecompData::matches
std::vector< std::vector< RGroupMatch > > matches
Definition: RGroupDecompData.h:41
RDKit::RGroupDecompData::newCoreLabel
int newCoreLabel
Definition: RGroupDecompData.h:29
RDKit::RGroupDecompData::prunedFingerprintVarianceScoreData
FingerprintVarianceScoreData prunedFingerprintVarianceScoreData
Definition: RGroupDecompData.h:45
RDKit::RGroupDecompData::RGroupDecompData
RGroupDecompData(const RWMol &inputCore, RGroupDecompositionParameters inputParams)
Definition: RGroupDecompData.h:53
RDKit::RGroupDecompData::score
double score(const std::vector< size_t > &permutation, FingerprintVarianceScoreData *fingerprintVarianceScoreData=nullptr) const
Definition: RGroupDecompData.h:513
RDKit::RGroupDecompData::scoreFromPrunedData
double scoreFromPrunedData(const std::vector< size_t > &permutation, bool reset=true)
Definition: RGroupDecompData.h:96
RDKit::RGroupDecompData::permutationProduct
size_t permutationProduct
Definition: RGroupDecompData.h:32
RDKit::RGroupDecompData::relabelRGroup
void relabelRGroup(RGroupData &rgroup, const std::map< int, int > &mappings)
Definition: RGroupDecompData.h:355
RDKit::RGroupDecompData::permutation
std::vector< size_t > permutation
Definition: RGroupDecompData.h:43
RDKit::RGroupDecompData::prune
void prune()
Definition: RGroupDecompData.h:132
RDKit::RGroupDecompData::userLabels
std::map< int, std::vector< int > > userLabels
Definition: RGroupDecompData.h:46
RDKit::RGroupDecompData::labels
std::set< int > labels
Definition: RGroupDecompData.h:42
RDKit::RGroupDecompData::params
RGroupDecompositionParameters params
Definition: RGroupDecompData.h:39
RDKit::RGroupDecompData::newCores
std::map< std::string, int > newCores
Definition: RGroupDecompData.h:28
RDKit::RGroupDecompData::process
RGroupDecompositionProcessResult process(bool pruneMatches, bool finalize=false)
Definition: RGroupDecompData.h:530
RDKit::RGroupDecompData::cores
std::map< int, RCore > cores
Definition: RGroupDecompData.h:27
RDKit::RGroupDecompData::pruneLength
unsigned int pruneLength
Definition: RGroupDecompData.h:44
RDKit::RGroupDecompData::setRlabel
void setRlabel(Atom *atom, int rlabel)
Definition: RGroupDecompData.h:79
RDKit::RGroupDecompData::addAtoms
void addAtoms(RWMol &mol, const std::vector< std::pair< Atom *, Atom * >> &atomsToAdd)
Definition: RGroupDecompData.h:244
RDKit::RGroupDecompData::relabel
void relabel()
Definition: RGroupDecompData.h:437
RDKit::RGroupDecompData::processedRlabels
std::vector< int > processedRlabels
Definition: RGroupDecompData.h:48
RDKit::RGroupDecompData::prunePermutations
bool prunePermutations
Definition: RGroupDecompData.h:38
RDKit::RGroupDecompData::finalRlabelMapping
std::map< int, int > finalRlabelMapping
Definition: RGroupDecompData.h:50
RDKit::RGroupDecompData::prepareCores
void prepareCores()
Definition: RGroupDecompData.h:69
RDKit::RGroupDecompData::addCoreUserLabels
void addCoreUserLabels(const RWMol &core, std::set< int > &userLabels)
Definition: RGroupDecompData.h:235
RDKit::RGroupDecompData::RGroupDecompData
RGroupDecompData(const std::vector< ROMOL_SPTR > &inputCores, RGroupDecompositionParameters inputParams)
Definition: RGroupDecompData.h:60
RDKit::RGroupDecompData::relabelCore
void relabelCore(RWMol &core, std::map< int, int > &mappings, UsedLabels &used_labels, const std::set< int > &indexLabels, const std::map< int, std::vector< int >> &extraAtomRLabels)
Definition: RGroupDecompData.h:256
RDKit::RGroupDecompData::GetCurrentBestPermutation
std::vector< RGroupMatch > GetCurrentBestPermutation() const
Definition: RGroupDecompData.h:151
RDKit::RGroupDecompData::rGroupScorer
RGroupScorer rGroupScorer
Definition: RGroupDecompData.h:51
RDKit::RGroupDecompositionParameters
Definition: RGroupDecomp.h:75
RDKit::RGroupDecompositionParameters::removeAllHydrogenRGroupsAndLabels
bool removeAllHydrogenRGroupsAndLabels
Definition: RGroupDecomp.h:89
RDKit::RGroupDecompositionParameters::gaNumberRuns
int gaNumberRuns
Definition: RGroupDecomp.h:115
RDKit::RGroupDecompositionParameters::matchingStrategy
unsigned int matchingStrategy
Definition: RGroupDecomp.h:77
RDKit::RGroupDecompositionParameters::onlyMatchAtRGroups
bool onlyMatchAtRGroups
only allow rgroup decomposition at the specified rgroups
Definition: RGroupDecomp.h:84
RDKit::RGroupDecompositionParameters::removeAllHydrogenRGroups
bool removeAllHydrogenRGroups
remove all user-defined rgroups that only have hydrogens
Definition: RGroupDecomp.h:86
RDKit::RGroupDecompositionParameters::timeout
double timeout
timeout in seconds. <=0 indicates no timeout
Definition: RGroupDecomp.h:95
RDKit::RGroupDecompositionParameters::removeHydrogensPostMatch
bool removeHydrogensPostMatch
remove all hydrogens from the output molecules
Definition: RGroupDecomp.h:91
RDKit::RGroupDecompositionParameters::scoreMethod
unsigned int scoreMethod
Definition: RGroupDecomp.h:78
RDKit::RGroupDecompositionParameters::rgroupLabelling
unsigned int rgroupLabelling
Definition: RGroupDecomp.h:79
RDKit::RGroupDecompositionParameters::prepareCore
bool prepareCore(RWMol &, const RWMol *alignCore)
RDKit::RGroupDecompositionProcessResult
Definition: RGroupDecomp.h:66
RDLog::BlockLogs
Definition: RDLog.h:118