1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107
|
//
// 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.
//
#include "RGroupUtils.h"
namespace RDKit
{
std::string labellingToString(Labelling type) {
switch (type) {
case Labelling::RGROUP_LABELS:
return "RGroupLabels";
case Labelling::ISOTOPE_LABELS:
return "IsotopeLabels";
case Labelling::ATOMMAP_LABELS:
return "AtomMapLabels";
case Labelling::INDEX_LABELS:
return "IndexLabels";
case Labelling::DUMMY_LABELS:
return "DummyLabels";
case Labelling::INTERNAL_LABELS:
return "InternalLabels";
}
return "unknown";
}
// Return the current set of rlabels for the molecule
// Negative RLabels are ones not assigned by the user and are
// either set to the index of the atom OR set to the index of
// the atom from the core with the best MCS.
// Positive rlabels are user defined (i.e. the user has specified
// specific R1, R2 etc...
std::map<int, Atom *> getRlabels(const RWMol &mol) {
std::map<int, Atom *> atoms;
for (auto atom : mol.atoms()) {
if (atom->hasProp(RLABEL)) {
int rlabel = atom->getProp<int>(RLABEL); // user label
CHECK_INVARIANT(atoms.find(rlabel) == atoms.end(),
"Duplicate labels in rgroup core!");
atoms[rlabel] = atom;
}
}
return atoms;
}
void clearInputLabels(Atom *atom) {
// atom->setIsotope(0); Don't want to clear deuterium and things like that if
// they aren't labels
atom->setAtomMapNum(0);
if (atom->hasProp(common_properties::_MolFileRLabel)) {
atom->clearProp(common_properties::_MolFileRLabel);
}
}
bool setLabel(Atom *atom, int label, std::set<int> &labels, int &maxLabel,
bool relabel, Labelling type) {
if (type == Labelling::ISOTOPE_LABELS) {
atom->setIsotope(0);
} else if (type == Labelling::ATOMMAP_LABELS) {
atom->setAtomMapNum(0);
} else if (type == Labelling::RGROUP_LABELS) {
if (atom->hasProp(common_properties::_MolFileRLabel)) {
atom->clearProp(common_properties::_MolFileRLabel);
atom->setIsotope(0);
}
}
if (label) {
if (labels.find(label) != labels.end()) {
if (relabel) {
if (type == Labelling::INTERNAL_LABELS) {
BOOST_LOG(rdWarningLog) << "Relabelling existing label" << std::endl;
}
label = maxLabel;
} else {
// XXX FIX me - get label id
throw ValueErrorException(
std::string("Duplicate label in input, current type is:") +
labellingToString(type));
}
}
atom->setProp<int>(RLABEL, label);
labels.insert(label);
maxLabel = (std::max)(maxLabel, label + 1);
return true;
}
return false;
}
bool hasDummy(const RWMol &core) {
for (RWMol::ConstAtomIterator atIt = core.beginAtoms();
atIt != core.endAtoms(); ++atIt) {
if ((*atIt)->getAtomicNum() == 0) {
return true;
}
}
return false;
}
} // namespace
|