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 108 109 110 111
|
//
//
// Copyright (C) 2020 Schrödinger, 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.
//
#include <GraphMol/MolOps.h>
#include "CIPMol.h"
namespace RDKit {
namespace CIPLabeler {
CIPMol::CIPMol(ROMol &mol) : d_mol{mol} {}
boost::rational<int> CIPMol::getFractionalAtomicNum(Atom *atom) const {
PRECONDITION(atom, "bad atom")
if (d_atomnums.empty()) {
const_cast<CIPMol *>(this)->d_atomnums = calcFracAtomNums(*this);
}
return d_atomnums[atom->getIdx()];
}
unsigned CIPMol::getNumAtoms() const { return d_mol.getNumAtoms(); }
unsigned CIPMol::getNumBonds() const { return d_mol.getNumBonds(); };
Atom *CIPMol::getAtom(int idx) const { return d_mol.getAtomWithIdx(idx); };
CXXAtomIterator<MolGraph, Atom *> CIPMol::atoms() const {
return d_mol.atoms();
}
Bond *CIPMol::getBond(int idx) const { return d_mol.getBondWithIdx(idx); };
CIPMolSpan<Bond *, ROMol::OEDGE_ITER> CIPMol::getBonds(Atom *atom) const {
PRECONDITION(atom, "bad atom")
return {d_mol, d_mol.getAtomBonds(atom)};
}
CIPMolSpan<Atom *, ROMol::ADJ_ITER> CIPMol::getNeighbors(Atom *atom) const {
PRECONDITION(atom, "bad atom")
return {d_mol, d_mol.getAtomNeighbors(atom)};
}
bool CIPMol::isInRing(Bond *bond) const {
PRECONDITION(bond, "bad bond")
const auto rings = d_mol.getRingInfo();
if (!rings->isFindFastOrBetter()) {
MolOps::fastFindRings(d_mol);
}
return rings->numBondRings(bond->getIdx()) != 0u;
};
int CIPMol::getBondOrder(Bond *bond) const {
PRECONDITION(bond, "bad bond")
if (d_kekulized_bonds.empty()) {
RWMol tmp{d_mol};
try {
MolOps::Kekulize(tmp);
} catch (const MolSanitizeException &) {
}
auto& bonds = const_cast<std::vector<RDKit::Bond::BondType>&>(d_kekulized_bonds);
bonds.reserve(d_mol.getNumBonds());
for (const auto &b : tmp.bonds()) {
bonds.push_back(b->getBondType());
}
}
const auto bond_type = d_kekulized_bonds.at(bond->getIdx());
// Dative bonds might need to be considered with a different bond order
// for the end atom at the end of the bond.
switch (bond_type) {
case Bond::ZERO:
case Bond::HYDROGEN:
case Bond::DATIVE:
case Bond::DATIVEL:
case Bond::DATIVER:
return 0;
case Bond::SINGLE:
return 1;
case Bond::AROMATIC:
BOOST_LOG(rdWarningLog)
<< "non kekulizable aromatic bond being treated as bond order 1"
<< std::endl;
return 1;
case Bond::DOUBLE:
return 2;
case Bond::TRIPLE:
return 3;
case Bond::QUADRUPLE:
return 4;
case Bond::QUINTUPLE:
return 5;
case Bond::HEXTUPLE:
return 6;
default:
throw std::runtime_error("Non integer-order bonds are not allowed.");
}
};
} // namespace CIPLabeler
} // namespace RDKit
|