19 class RingMatchTable {
21 std::map<const INT_VECT*, unsigned> RingIndex;
28 inline void resize(
unsigned s1,
unsigned s2) {
29 MatchMatrix.resize(s1, s2);
30 for (
size_t i = 0; i < s1; i++) {
31 for (
size_t j = 0; j < s2; j++) {
32 MatchMatrix.set(i, j,
false);
36 inline void makeRingIndex(
const ROMol* mol2) {
40 for (RingInfo::VECT_INT_VECT::const_iterator r2 = rings2.begin();
41 r2 != rings2.end(); r2++) {
42 RingIndex[&*r2] = i++;
45 inline bool isEqual(
unsigned i,
const INT_VECT* r2)
const {
46 return MatchMatrix.at(i, getRingIndex(r2));
48 inline void setMatch(
unsigned i,
const INT_VECT* r2) {
49 MatchMatrix.set(i, getRingIndex(r2),
true);
53 inline unsigned getRingIndex(
const INT_VECT* r2)
const {
54 std::map<const INT_VECT*, unsigned>::const_iterator j =
56 if (RingIndex.end() == j) {
64 std::vector<std::vector<size_t>>* QueryBondRingsIndeces{
nullptr};
65 std::map<const ROMol*, std::vector<std::vector<size_t>>>
66 TargetBondRingsIndecesSet;
68 std::map<const ROMol*, RingMatchTable> MatchMatrixSet;
69 std::map<const INT_VECT*, unsigned> QueryRingIndex;
75 if (QueryBondRingsIndeces) {
76 QueryBondRingsIndeces->clear();
78 TargetBondRingsIndecesSet.clear();
79 MatchMatrixSet.clear();
80 QueryRingIndex.clear();
84 return (*QueryBondRingsIndeces)[bi].empty();
87 return (*QueryBondRingsIndeces)[bi];
91 std::map<const ROMol*, std::vector<std::vector<size_t>>>::const_iterator i =
92 TargetBondRingsIndecesSet.find(target);
93 if (TargetBondRingsIndecesSet.end() == i) {
96 return i->second[bi].empty();
100 std::map<const ROMol*, std::vector<std::vector<size_t>>>::const_iterator i =
101 TargetBondRingsIndecesSet.find(target);
102 if (TargetBondRingsIndecesSet.end() == i) {
105 return i->second[bi];
109 const ROMol* mol2)
const {
110 const RingMatchTable& m = getTargetMatchMatrix(mol2);
111 unsigned i = getQueryRingIndex(r1);
112 return m.isEqual(i, r2);
116 MatchMatrixSet.clear();
120 for (RingInfo::VECT_INT_VECT::const_iterator r = rings.begin();
121 r != rings.end(); r++) {
122 QueryRingIndex[&*r] = i++;
124 TargetBondRingsIndecesSet.clear();
125 QueryBondRingsIndeces = &TargetBondRingsIndecesSet[query];
126 QueryBondRingsIndeces->resize(query->
getNumBonds());
128 for (RingInfo::VECT_INT_VECT::const_iterator r = rings.begin();
129 r != rings.end(); r++, ri++) {
130 for (INT_VECT::const_iterator bi = r->begin(); bi != r->end();
132 (*QueryBondRingsIndeces)[*bi].push_back(ri);
137 std::vector<std::vector<size_t>>& m = TargetBondRingsIndecesSet[mol2];
142 for (RingInfo::VECT_INT_VECT::const_iterator r = rings.begin();
143 r != rings.end(); r++, ri++) {
144 for (INT_VECT::const_iterator bi = r->begin(); bi != r->end();
146 m[*bi].push_back(ri);
152 const ROMol* query,
const ROMol* targetMolecule,
158 addTargetMatchMatrix(targetMolecule, rings1.size(), rings2.size());
161 for (RingInfo::VECT_INT_VECT::const_iterator r1 = rings1.begin();
162 r1 != rings1.end(); r1++, i++) {
164 makeRingGraph(graph1, *r1,
168 for (RingInfo::VECT_INT_VECT::const_iterator r2 = rings2.begin();
169 r2 != rings2.end(); r2++) {
170 if (r1->size() != r2->size()) {
183#ifdef NEVER_xxx_PRECOMPUTED_TABLES_MATCH
186 FMCS::SubstructMatchCustomTable(graph2, graph1, tag->AtomMatchTable,
187 tag->BondMatchTable);
189 FMCS::SubstructMatchCustom(
190 graph2, *targetMolecule, graph1, *query, parameters.
AtomTyper,
203 const ROMol* mol)
const {
204 std::map<const Atom*, unsigned> atomMap;
206 for (
size_t i = 0; i < ring.size(); i++) {
212 std::map<const Atom*, unsigned>::const_iterator ai;
213 ai = atomMap.find(atom1);
214 if (atomMap.end() != ai) {
217 ai = atomMap.find(atom2);
218 if (atomMap.end() != ai) {
222 j1 = g.m_vertices.size();
227 j2 = g.m_vertices.size();
235 inline unsigned getQueryRingIndex(
const INT_VECT* r1)
const {
236 std::map<const INT_VECT*, unsigned>::const_iterator i =
237 QueryRingIndex.find(r1);
238 if (QueryRingIndex.end() == i) {
243 inline const RingMatchTable& getTargetMatchMatrix(
const ROMol* mol2)
const {
244 std::map<const ROMol*, RingMatchTable>::const_iterator mi =
245 MatchMatrixSet.find(mol2);
246 if (MatchMatrixSet.end() == mi) {
252 inline RingMatchTable& addTargetMatchMatrix(
const ROMol* mol2,
unsigned s1,
254 RingMatchTable&
m = MatchMatrixSet[mol2];
256 m.makeRingIndex(mol2);
The class for representing atoms.
unsigned int getIdx() const
returns our index within the ROMol
class for representing a bond
Atom * getEndAtom() const
returns a pointer to our end Atom
Atom * getBeginAtom() const
returns a pointer to our begin Atom
void addBond(unsigned bond, unsigned beginAtom, unsigned endAtom)
void addAtom(unsigned atom)
void addTargetBondRingsIndeces(const ROMol *mol2)
void computeRingMatchTable(const ROMol *query, const ROMol *targetMolecule, const MCSParameters ¶meters)
bool isTargetBondInRing(const ROMol *target, unsigned bi) const
bool isQueryBondInRing(unsigned bi) const
const std::vector< size_t > & getTargetBondRings(const ROMol *target, unsigned bi) const
const std::vector< size_t > & getQueryBondRings(unsigned bi) const
bool isEqual(const INT_VECT *r1, const INT_VECT *r2, const ROMol *mol2) const
void init(const ROMol *query)
unsigned int getNumBonds(bool onlyHeavy=1) const
returns our number of Bonds
RingInfo * getRingInfo() const
Bond * getBondWithIdx(unsigned int idx)
returns a pointer to a particular Bond
const VECT_INT_VECT & bondRings() const
std::vector< INT_VECT > VECT_INT_VECT
#define RDKIT_FMCS_EXPORT
const unsigned int NotSet
std::vector< int > INT_VECT
MCSAtomCompareFunction AtomTyper
MCSBondCompareFunction BondTyper
MCSAtomCompareParameters AtomCompareParameters
void * CompareFunctionsUserData
MCSBondCompareParameters BondCompareParameters