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++) MatchMatrix.set(i, j,
false);
33 inline void makeRingIndex(
const ROMol* mol2) {
37 for (RingInfo::VECT_INT_VECT::const_iterator r2 = rings2.begin();
38 r2 != rings2.end(); r2++)
39 RingIndex[&*r2] = i++;
41 inline bool isEqual(
unsigned i,
const INT_VECT* r2)
const {
42 return MatchMatrix.at(i, getRingIndex(r2));
44 inline void setMatch(
unsigned i,
const INT_VECT* r2) {
45 MatchMatrix.set(i, getRingIndex(r2),
true);
49 inline unsigned getRingIndex(
const INT_VECT* r2)
const {
50 std::map<const INT_VECT*, unsigned>::const_iterator j =
52 if (RingIndex.end() == j)
throw - 1;
58 std::vector<std::vector<size_t> >* QueryBondRingsIndeces;
59 std::map<const ROMol*, std::vector<std::vector<size_t> > >
60 TargetBondRingsIndecesSet;
62 std::map<const ROMol*, RingMatchTable> MatchMatrixSet;
63 std::map<const INT_VECT*, unsigned> QueryRingIndex;
69 if (QueryBondRingsIndeces) QueryBondRingsIndeces->clear();
70 TargetBondRingsIndecesSet.clear();
71 MatchMatrixSet.clear();
72 QueryRingIndex.clear();
76 return (*QueryBondRingsIndeces)[bi].empty();
79 return (*QueryBondRingsIndeces)[bi];
83 std::map<const ROMol*, std::vector<std::vector<size_t> > >::const_iterator
84 i = TargetBondRingsIndecesSet.find(target);
85 if (TargetBondRingsIndecesSet.end() == i)
throw - 1;
86 return i->second[bi].empty();
90 std::map<const ROMol*, std::vector<std::vector<size_t> > >::const_iterator
91 i = TargetBondRingsIndecesSet.find(target);
92 if (TargetBondRingsIndecesSet.end() == i)
throw - 1;
97 const ROMol* mol2)
const {
98 const RingMatchTable& m = getTargetMatchMatrix(mol2);
99 unsigned i = getQueryRingIndex(r1);
100 return m.isEqual(i, r2);
104 MatchMatrixSet.clear();
108 for (RingInfo::VECT_INT_VECT::const_iterator r = rings.begin();
109 r != rings.end(); r++)
110 QueryRingIndex[&*r] = i++;
111 TargetBondRingsIndecesSet.clear();
112 QueryBondRingsIndeces = &TargetBondRingsIndecesSet[query];
113 QueryBondRingsIndeces->resize(query->
getNumBonds());
115 for (RingInfo::VECT_INT_VECT::const_iterator r = rings.begin();
116 r != rings.end(); r++, ri++)
117 for (INT_VECT::const_iterator bi = r->begin(); bi != r->end();
119 (*QueryBondRingsIndeces)[*bi].push_back(ri);
122 std::vector<std::vector<size_t> >& m = TargetBondRingsIndecesSet[mol2];
127 for (RingInfo::VECT_INT_VECT::const_iterator r = rings.begin();
128 r != rings.end(); r++, ri++)
129 for (INT_VECT::const_iterator bi = r->begin(); bi != r->end();
131 m[*bi].push_back(ri);
135 const ROMol* query,
const ROMol* targetMolecule,
141 addTargetMatchMatrix(targetMolecule, rings1.size(), rings2.size());
144 for (RingInfo::VECT_INT_VECT::const_iterator r1 = rings1.begin();
145 r1 != rings1.end(); r1++, i++) {
147 makeRingGraph(graph1, *r1,
151 for (RingInfo::VECT_INT_VECT::const_iterator r2 = rings2.begin();
152 r2 != rings2.end(); r2++) {
153 if (r1->size() != r2->size())
165 #ifdef NEVER_xxx_PRECOMPUTED_TABLES_MATCH // not computed yet, because 169 tag->BondMatchTable);
170 #else // noticable slowly: 172 graph2, *targetMolecule, graph1, *query, parameters.
AtomTyper,
176 if (match) m.setMatch(i, &*r2);
183 const ROMol* mol)
const {
184 std::map<const Atom*, unsigned> atomMap;
186 for (
size_t i = 0; i < ring.size(); i++) {
192 std::map<const Atom*, unsigned>::const_iterator ai;
193 ai = atomMap.find(atom1);
194 if (atomMap.end() != ai) j1 = ai->second;
195 ai = atomMap.find(atom2);
196 if (atomMap.end() != ai) j2 = ai->second;
198 j1 = g.m_vertices.size();
203 j2 = g.m_vertices.size();
211 inline unsigned getQueryRingIndex(
const INT_VECT* r1)
const {
212 std::map<const INT_VECT*, unsigned>::const_iterator i =
213 QueryRingIndex.find(r1);
214 if (QueryRingIndex.end() == i)
throw - 1;
217 inline const RingMatchTable& getTargetMatchMatrix(
const ROMol* mol2)
const {
218 std::map<const ROMol*, RingMatchTable>::const_iterator mi =
219 MatchMatrixSet.find(mol2);
220 if (MatchMatrixSet.end() == mi)
throw - 1;
224 inline RingMatchTable& addTargetMatchMatrix(
const ROMol* mol2,
unsigned s1,
226 RingMatchTable& m = MatchMatrixSet[mol2];
228 m.makeRingIndex(mol2);
void addAtom(unsigned atom)
bool isQueryBondInRing(unsigned bi) const
Atom * getEndAtom() const
returns a pointer to our end Atom
const VECT_INT_VECT & bondRings() const
returns our bond-rings vectors
unsigned int getNumBonds(bool onlyHeavy=1) const
returns our number of Bonds
void computeRingMatchTable(const ROMol *query, const ROMol *targetMolecule, const MCSParameters ¶meters)
MCSAtomCompareFunction AtomTyper
#define RDKIT_FMCS_EXPORT
void addBond(unsigned bond, unsigned beginAtom, unsigned endAtom)
RingInfo * getRingInfo() const
const std::vector< size_t > & getQueryBondRings(unsigned bi) const
RDKIT_FMCS_EXPORT bool SubstructMatchCustom(const FMCS::Graph &target, const ROMol &mol, const FMCS::Graph &query, const ROMol &querySrc, MCSAtomCompareFunction atomCompare, MCSBondCompareFunction bondCompare, MCSFinalMatchCheckFunction finalCompare, const MCSAtomCompareParameters &acp, const MCSBondCompareParameters &bcp, void *user_data, match_V_t *match=0)
MCSBondCompareFunction BondTyper
Atom * getBeginAtom() const
returns a pointer to our begin Atom
std::vector< int > INT_VECT
unsigned int getIdx() const
returns our index within the ROMol
Bond * getBondWithIdx(unsigned int idx)
returns a pointer to a particular Bond
const std::vector< size_t > & getTargetBondRings(const ROMol *target, unsigned bi) const
bool isTargetBondInRing(const ROMol *target, unsigned bi) const
MCSBondCompareParameters BondCompareParameters
class for representing a bond
void init(const ROMol *query)
RDKIT_FMCS_EXPORT bool SubstructMatchCustomTable(const FMCS::Graph &target, const ROMol &target_mol, const FMCS::Graph &query, const ROMol &querySrc, const MatchTable &atomMatchTable, const MatchTable &bondMatchTable, const MCSParameters *parameters=0, match_V_t *match=0)
std::vector< INT_VECT > VECT_INT_VECT
const unsigned int NotSet
bool isEqual(const INT_VECT *r1, const INT_VECT *r2, const ROMol *mol2) const
void addTargetBondRingsIndeces(const ROMol *mol2)
The class for representing atoms.
MCSAtomCompareParameters AtomCompareParameters