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 112 113 114 115 116 117 118
|
// $Id$
//
// Copyright (C) 2004-2008 Greg Landrum and Rational Discovery 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 "RingInfo.h"
#include <RDGeneral/Invariant.h>
#include <algorithm>
namespace RDKit {
bool RingInfo::isAtomInRingOfSize(unsigned int idx, unsigned int size) const {
PRECONDITION(df_init, "RingInfo not initialized");
if (idx < d_atomMembers.size()) {
return std::find(d_atomMembers[idx].begin(), d_atomMembers[idx].end(),
static_cast<int>(size)) != d_atomMembers[idx].end();
} else {
return false;
}
}
unsigned int RingInfo::minAtomRingSize(unsigned int idx) const {
PRECONDITION(df_init, "RingInfo not initialized");
if (idx < d_atomMembers.size() && d_atomMembers[idx].size()) {
return *std::min_element(d_atomMembers[idx].begin(),
d_atomMembers[idx].end());
} else {
return 0;
}
}
unsigned int RingInfo::numAtomRings(unsigned int idx) const {
PRECONDITION(df_init, "RingInfo not initialized");
if (idx < d_atomMembers.size()) {
return rdcast<unsigned int>(d_atomMembers[idx].size());
} else {
return 0;
}
}
bool RingInfo::isBondInRingOfSize(unsigned int idx, unsigned int size) const {
PRECONDITION(df_init, "RingInfo not initialized");
if (idx < d_bondMembers.size()) {
return std::find(d_bondMembers[idx].begin(), d_bondMembers[idx].end(),
static_cast<int>(size)) != d_bondMembers[idx].end();
} else {
return false;
}
}
unsigned int RingInfo::minBondRingSize(unsigned int idx) const {
PRECONDITION(df_init, "RingInfo not initialized");
if (idx < d_bondMembers.size() && d_bondMembers[idx].size()) {
return *std::min_element(d_bondMembers[idx].begin(),
d_bondMembers[idx].end());
} else {
return 0;
}
}
unsigned int RingInfo::numBondRings(unsigned int idx) const {
PRECONDITION(df_init, "RingInfo not initialized");
if (idx < d_bondMembers.size()) {
return rdcast<unsigned int>(d_bondMembers[idx].size());
} else {
return 0;
}
}
unsigned int RingInfo::numRings() const {
PRECONDITION(df_init, "RingInfo not initialized");
PRECONDITION(d_atomRings.size() == d_bondRings.size(), "length mismatch");
return rdcast<unsigned int>(d_atomRings.size());
}
unsigned int RingInfo::addRing(const INT_VECT &atomIndices,
const INT_VECT &bondIndices) {
PRECONDITION(df_init, "RingInfo not initialized");
PRECONDITION(atomIndices.size() == bondIndices.size(), "length mismatch");
int sz = rdcast<int>(atomIndices.size());
for (auto i : atomIndices) {
if (i >= static_cast<int>(d_atomMembers.size()))
d_atomMembers.resize((i) + 1);
d_atomMembers[i].push_back(sz);
}
for (auto i : bondIndices) {
if (i >= static_cast<int>(d_bondMembers.size()))
d_bondMembers.resize((i) + 1);
d_bondMembers[i].push_back(sz);
}
d_atomRings.push_back(atomIndices);
d_bondRings.push_back(bondIndices);
POSTCONDITION(d_atomRings.size() == d_bondRings.size(), "length mismatch");
return rdcast<unsigned int>(d_atomRings.size());
}
void RingInfo::initialize() {
PRECONDITION(!df_init, "already initialized");
df_init = true;
};
void RingInfo::reset() {
if (!df_init) return;
df_init = false;
d_atomMembers.clear();
d_bondMembers.clear();
d_atomRings.clear();
d_bondRings.clear();
}
void RingInfo::preallocate(unsigned int numAtoms, unsigned int numBonds) {
d_atomMembers.resize(numAtoms);
d_bondMembers.resize(numBonds);
}
}
|