18 class RingMatchTable {
20 std::map<const INT_VECT*, unsigned> RingIndex;
26 inline void resize(
unsigned s1,
unsigned s2) {
27 MatchMatrix.
resize(s1, s2);
28 for(
size_t i = 0; i < s1; i++)
29 for(
size_t j = 0; j < s2; j++)
30 MatchMatrix.
set(i, j,
false);
32 inline void makeRingIndex(
const ROMol* mol2) {
36 for(RingInfo::VECT_INT_VECT::const_iterator r2 = rings2.begin(); r2 != rings2.end(); r2++)
37 RingIndex[&*r2] = i++;
40 return MatchMatrix.
at(i, getRingIndex(r2));
42 inline void setMatch(
unsigned i,
const INT_VECT* r2) {
43 MatchMatrix.
set(i, getRingIndex(r2),
true);
46 inline unsigned getRingIndex(
const INT_VECT* r2)
const {
47 std::map<const INT_VECT*, unsigned>::const_iterator j = RingIndex.find(r2);
48 if(RingIndex.end() == j)
55 std::vector<std::vector<size_t> >* QueryBondRingsIndeces;
56 std::map<const ROMol*, std::vector<std::vector<size_t> > > TargetBondRingsIndecesSet;
58 std::map<const ROMol*, RingMatchTable> MatchMatrixSet;
59 std::map<const INT_VECT*, unsigned> QueryRingIndex;
65 if(QueryBondRingsIndeces)
66 QueryBondRingsIndeces->clear();
67 TargetBondRingsIndecesSet.clear();
68 MatchMatrixSet.clear();
69 QueryRingIndex.clear();
74 return (*QueryBondRingsIndeces)[bi].empty();
77 return (*QueryBondRingsIndeces)[bi];
81 std::map<const ROMol*, std::vector<std::vector<size_t> > >::const_iterator
82 i = TargetBondRingsIndecesSet.find(target);
83 if(TargetBondRingsIndecesSet.end() == i)
85 return i->second[bi].empty();
88 std::map<const ROMol*, std::vector<std::vector<size_t> > >::const_iterator
89 i = TargetBondRingsIndecesSet.find(target);
90 if(TargetBondRingsIndecesSet.end() == i)
96 const RingMatchTable& m = getTargetMatchMatrix(mol2);
97 unsigned i = getQueryRingIndex(r1);
98 return m.isEqual(i,r2);
102 MatchMatrixSet.clear();
106 for(RingInfo::VECT_INT_VECT::const_iterator r = rings.begin(); r != rings.end(); r++)
107 QueryRingIndex[&*r] = i++;
108 TargetBondRingsIndecesSet.clear();
109 QueryBondRingsIndeces = &TargetBondRingsIndecesSet[query];
110 QueryBondRingsIndeces->resize(query->
getNumBonds());
112 for(RingInfo::VECT_INT_VECT::const_iterator r = rings.begin(); r != rings.end(); r++, ri++)
113 for(INT_VECT::const_iterator bi = r->begin(); bi != r->end(); bi++)
114 (*QueryBondRingsIndeces)[*bi].push_back(ri);
117 std::vector<std::vector<size_t> >& m = TargetBondRingsIndecesSet[mol2];
122 for(RingInfo::VECT_INT_VECT::const_iterator r = rings.begin(); r != rings.end(); r++, ri++)
123 for(INT_VECT::const_iterator bi = r->begin(); bi != r->end(); bi++)
124 m[*bi].push_back(ri);
130 RingMatchTable& m = addTargetMatchMatrix(targetMolecule, rings1.size(), rings2.size());
133 for(RingInfo::VECT_INT_VECT::const_iterator r1 = rings1.begin(); r1 != rings1.end(); r1++, i++) {
135 makeRingGraph(graph1, *r1, query);
138 for(RingInfo::VECT_INT_VECT::const_iterator r2 = rings2.begin(); r2 != rings2.end(); r2++) {
139 if(r1->size() != r2->size())
142 makeRingGraph(graph2, *r2, targetMolecule);
149 #ifdef NEVER_xxx_PRECOMPUTED_TABLES_MATCH // not computed yet, because MatchTable computation usees this ring info table 151 #else //noticable slowly: 163 std::map<const Atom*, unsigned> atomMap;
165 for(
size_t i=0; i < ring.size(); i++) {
171 std::map<const Atom*, unsigned>::const_iterator ai;
172 ai = atomMap.find(atom1);
173 if(atomMap.end() != ai)
175 ai = atomMap.find(atom2);
176 if(atomMap.end() != ai)
179 j1 = g.m_vertices.size();
184 j2 = g.m_vertices.size();
192 inline unsigned getQueryRingIndex(
const INT_VECT* r1)
const {
193 std::map<const INT_VECT*, unsigned>::const_iterator i = QueryRingIndex.find(r1);
194 if(QueryRingIndex.end() == i)
198 inline const RingMatchTable& getTargetMatchMatrix(
const ROMol* mol2)
const {
199 std::map<const ROMol*, RingMatchTable>::const_iterator mi = MatchMatrixSet.find(mol2);
200 if(MatchMatrixSet.end() == mi)
205 inline RingMatchTable& addTargetMatchMatrix(
const ROMol* mol2,
unsigned s1,
unsigned s2) {
206 RingMatchTable& m = MatchMatrixSet[mol2];
208 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 isTargetBondInRing(const ROMol *target, unsigned bi) const
void set(size_t row, size_t col, T val)
void computeRingMatchTable(const ROMol *query, const ROMol *targetMolecule, const MCSParameters ¶meters)
unsigned int getIdx() const
returns our index within the ROMol
ROMol is a molecule class that is intended to have a fixed topology.
MCSAtomCompareFunction AtomTyper
const std::vector< size_t > & getTargetBondRings(const ROMol *target, unsigned bi) const
void addBond(unsigned bond, unsigned beginAtom, unsigned endAtom)
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)
unsigned int getNumBonds(bool onlyHeavy=1) const
returns our number of Bonds
MCSBondCompareFunction BondTyper
std::vector< int > INT_VECT
Bond * getBondWithIdx(unsigned int idx)
returns a pointer to a particular Bond
Atom * getEndAtom() const
returns a pointer to our end Atom
Includes a bunch of functionality for handling Atom and Bond queries.
const VECT_INT_VECT & bondRings() const
returns our bond-rings vectors
MCSBondCompareParameters BondCompareParameters
class for representing a bond
void init(const ROMol *query)
bool isQueryBondInRing(unsigned bi) const
bool isEqual(const INT_VECT *r1, const INT_VECT *r2, const ROMol *mol2) const
RingInfo * getRingInfo() const
std::vector< INT_VECT > VECT_INT_VECT
void resize(size_t cy, size_t cx)
Atom * getBeginAtom() const
returns a pointer to our begin Atom
void addTargetBondRingsIndeces(const ROMol *mol2)
The class for representing atoms.
const std::vector< size_t > & getQueryBondRings(unsigned bi) const
MCSAtomCompareParameters AtomCompareParameters
T at(size_t row, size_t col)