18 class RingMatchTable {
20 std::map<const INT_VECT*, unsigned> RingIndex;
27 inline void resize(
unsigned s1,
unsigned s2) {
28 MatchMatrix.
resize(s1, s2);
29 for (
size_t i = 0; i < s1; i++)
30 for (
size_t j = 0; j < s2; j++) MatchMatrix.
set(i, j,
false);
32 inline void makeRingIndex(
const ROMol* mol2) {
36 for (RingInfo::VECT_INT_VECT::const_iterator r2 = rings2.begin();
37 r2 != rings2.end(); r2++)
38 RingIndex[&*r2] = i++;
41 return MatchMatrix.
at(i, getRingIndex(r2));
43 inline void setMatch(
unsigned i,
const INT_VECT* r2) {
44 MatchMatrix.
set(i, getRingIndex(r2),
true);
48 inline unsigned getRingIndex(
const INT_VECT* r2)
const {
49 std::map<const INT_VECT*, unsigned>::const_iterator j =
51 if (RingIndex.end() == j)
throw - 1;
57 std::vector<std::vector<size_t> >* QueryBondRingsIndeces;
58 std::map<const ROMol*, std::vector<std::vector<size_t> > >
59 TargetBondRingsIndecesSet;
61 std::map<const ROMol*, RingMatchTable> MatchMatrixSet;
62 std::map<const INT_VECT*, unsigned> QueryRingIndex;
68 if (QueryBondRingsIndeces) QueryBondRingsIndeces->clear();
69 TargetBondRingsIndecesSet.clear();
70 MatchMatrixSet.clear();
71 QueryRingIndex.clear();
75 return (*QueryBondRingsIndeces)[bi].empty();
78 return (*QueryBondRingsIndeces)[bi];
82 std::map<const ROMol*, std::vector<std::vector<size_t> > >::const_iterator
83 i = TargetBondRingsIndecesSet.find(target);
84 if (TargetBondRingsIndecesSet.end() == i)
throw - 1;
85 return i->second[bi].empty();
89 std::map<const ROMol*, std::vector<std::vector<size_t> > >::const_iterator
90 i = TargetBondRingsIndecesSet.find(target);
91 if (TargetBondRingsIndecesSet.end() == i)
throw - 1;
96 const ROMol* mol2)
const {
97 const RingMatchTable& m = getTargetMatchMatrix(mol2);
98 unsigned i = getQueryRingIndex(r1);
99 return m.isEqual(i, r2);
103 MatchMatrixSet.clear();
107 for (RingInfo::VECT_INT_VECT::const_iterator r = rings.begin();
108 r != rings.end(); r++)
109 QueryRingIndex[&*r] = i++;
110 TargetBondRingsIndecesSet.clear();
111 QueryBondRingsIndeces = &TargetBondRingsIndecesSet[query];
112 QueryBondRingsIndeces->resize(query->
getNumBonds());
114 for (RingInfo::VECT_INT_VECT::const_iterator r = rings.begin();
115 r != rings.end(); r++, ri++)
116 for (INT_VECT::const_iterator bi = r->begin(); bi != r->end();
118 (*QueryBondRingsIndeces)[*bi].push_back(ri);
121 std::vector<std::vector<size_t> >& m = TargetBondRingsIndecesSet[mol2];
126 for (RingInfo::VECT_INT_VECT::const_iterator r = rings.begin();
127 r != rings.end(); r++, ri++)
128 for (INT_VECT::const_iterator bi = r->begin(); bi != r->end();
130 m[*bi].push_back(ri);
134 const ROMol* query,
const ROMol* targetMolecule,
140 addTargetMatchMatrix(targetMolecule, rings1.size(), rings2.size());
143 for (RingInfo::VECT_INT_VECT::const_iterator r1 = rings1.begin();
144 r1 != rings1.end(); r1++, i++) {
146 makeRingGraph(graph1, *r1,
150 for (RingInfo::VECT_INT_VECT::const_iterator r2 = rings2.begin();
151 r2 != rings2.end(); r2++) {
152 if (r1->size() != r2->size())
164 #ifdef NEVER_xxx_PRECOMPUTED_TABLES_MATCH // not computed yet, because 168 tag->BondMatchTable);
169 #else // noticable slowly: 171 graph2, *targetMolecule, graph1, *query, parameters.
AtomTyper,
175 if (match) m.setMatch(i, &*r2);
182 const ROMol* mol)
const {
183 std::map<const Atom*, unsigned> atomMap;
185 for (
size_t i = 0; i < ring.size(); i++) {
191 std::map<const Atom*, unsigned>::const_iterator ai;
192 ai = atomMap.find(atom1);
193 if (atomMap.end() != ai) j1 = ai->second;
194 ai = atomMap.find(atom2);
195 if (atomMap.end() != ai) j2 = ai->second;
197 j1 = g.m_vertices.size();
202 j2 = g.m_vertices.size();
210 inline unsigned getQueryRingIndex(
const INT_VECT* r1)
const {
211 std::map<const INT_VECT*, unsigned>::const_iterator i =
212 QueryRingIndex.find(r1);
213 if (QueryRingIndex.end() == i)
throw - 1;
216 inline const RingMatchTable& getTargetMatchMatrix(
const ROMol* mol2)
const {
217 std::map<const ROMol*, RingMatchTable>::const_iterator mi =
218 MatchMatrixSet.find(mol2);
219 if (MatchMatrixSet.end() == mi)
throw - 1;
223 inline RingMatchTable& addTargetMatchMatrix(
const ROMol* mol2,
unsigned s1,
225 RingMatchTable& m = MatchMatrixSet[mol2];
227 m.makeRingIndex(mol2);
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)
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
void set(size_t row, size_t col, T val)
unsigned int getNumBonds(bool onlyHeavy=1) const
returns our number of Bonds
void computeRingMatchTable(const ROMol *query, const ROMol *targetMolecule, const MCSParameters ¶meters)
ROMol is a molecule class that is intended to have a fixed topology.
MCSAtomCompareFunction AtomTyper
void addBond(unsigned bond, unsigned beginAtom, unsigned endAtom)
RingInfo * getRingInfo() const
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)
const std::vector< size_t > & getQueryBondRings(unsigned bi) const
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)
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 resize(size_t cy, size_t cx)
void addTargetBondRingsIndeces(const ROMol *mol2)
The class for representing atoms.
MCSAtomCompareParameters AtomCompareParameters
T at(size_t row, size_t col)