RDKit
Open-source cheminformatics and machine learning.
TargetMatch.h
Go to the documentation of this file.
1 //
2 // Copyright (C) 2014 Novartis Institutes for BioMedical Research
3 //
4 // @@ All Rights Reserved @@
5 // This file is part of the RDKit.
6 // The contents are covered by the terms of the BSD license
7 // which is included in the file license.txt, found at the root
8 // of the RDKit source tree.
9 //
10 #pragma once
11 #include <vector>
12 #include "FMCS.h"
13 #include "MatchTable.h"
14 
15 namespace RDKit {
16 namespace FMCS {
17 struct TargetMatch {
18  bool Empty;
21  std::vector<unsigned> TargetAtomIdx;
22  std::vector<unsigned> TargetBondIdx;
23  std::vector<bool> VisitedTargetBonds;
24  std::vector<bool> VisitedTargetAtoms; // for checking rings
25  public:
26  TargetMatch() : Empty(true), MatchedAtomSize(0), MatchedBondSize(0) {}
27  TargetMatch(const TargetMatch& src) { *this = src; }
29  Empty = src.Empty;
30  if (!Empty) {
31  MatchedAtomSize = src.MatchedAtomSize;
32  MatchedBondSize = src.MatchedBondSize;
33  TargetAtomIdx.resize(src.TargetAtomIdx.size());
34  memcpy(&TargetAtomIdx[0], &src.TargetAtomIdx[0],
35  sizeof(unsigned) * TargetAtomIdx.size());
36  TargetBondIdx.resize(src.TargetBondIdx.size());
37  memcpy(&TargetBondIdx[0], &src.TargetBondIdx[0],
38  sizeof(unsigned) * TargetBondIdx.size());
39  VisitedTargetBonds = src.VisitedTargetBonds; // std::vector<bool> bitset
40  VisitedTargetAtoms = src.VisitedTargetAtoms; // std::vector<bool> bitset
41  }
42  return *this;
43  }
44  bool empty() const { return Empty; }
45  void clear() {
46  Empty = true;
47 
48  TargetAtomIdx.clear();
49  TargetBondIdx.clear();
50  VisitedTargetBonds.clear();
51  VisitedTargetAtoms.clear();
52  }
53  void init(const Seed& seed, const match_V_t& match, const ROMol& query,
54  const Target& target) {
55  TargetAtomIdx.resize(query.getNumAtoms());
56  TargetBondIdx.resize(query.getNumBonds());
57  VisitedTargetBonds.resize(target.Molecule->getNumBonds());
58  VisitedTargetAtoms.resize(target.Molecule->getNumAtoms());
59 
60  memset(&TargetAtomIdx[0], 0xFF, sizeof(unsigned) * TargetAtomIdx.size());
61  memset(&TargetBondIdx[0], 0xFF, sizeof(unsigned) * TargetBondIdx.size());
62  /*
63  for(size_t i = 0; i < TargetAtomIdx.size(); i++)
64  TargetAtomIdx[i] = -1;
65  for(size_t i = 0; i < TargetBondIdx.size(); i++)
66  TargetBondIdx[i] = -1;
67  */
68  for (size_t i = 0; i < VisitedTargetBonds.size(); i++)
69  VisitedTargetBonds[i] = false;
70  for (size_t i = 0; i < VisitedTargetAtoms.size(); i++)
71  VisitedTargetAtoms[i] = false;
72 
73  MatchedAtomSize = match.size();
74  for (match_V_t::const_iterator mit = match.begin(); mit != match.end();
75  mit++) {
76  TargetAtomIdx[seed.MoleculeFragment.AtomsIdx[mit->first]] = mit->second;
77  VisitedTargetAtoms[mit->second] = true;
78  }
79 
80  MatchedBondSize = 0;
81  for (std::vector<const Bond*>::const_iterator bond =
82  seed.MoleculeFragment.Bonds.begin();
83  bond != seed.MoleculeFragment.Bonds.end(); bond++) {
84  unsigned i = (*bond)->getBeginAtomIdx();
85  unsigned j = (*bond)->getEndAtomIdx();
86  unsigned ti = TargetAtomIdx[i];
87  unsigned tj = TargetAtomIdx[j];
88  const Bond* tb = target.Molecule->getBondBetweenAtoms(ti, tj);
89  if (tb) {
90  MatchedBondSize++;
91  TargetBondIdx[(*bond)->getIdx()] = tb->getIdx(); // add
92  VisitedTargetBonds[tb->getIdx()] = true;
93  }
94  }
95  Empty = false;
96  }
97 };
98 }
99 }
std::vector< unsigned > TargetBondIdx
Definition: TargetMatch.h:22
const ROMol * Molecule
Definition: Target.h:21
void init(const Seed &seed, const match_V_t &match, const ROMol &query, const Target &target)
Definition: TargetMatch.h:53
std::vector< unsigned > TargetAtomIdx
Definition: TargetMatch.h:21
unsigned int getNumAtoms(bool onlyExplicit=1) const
returns our number of atoms
std::vector< bool > VisitedTargetAtoms
Definition: TargetMatch.h:24
ROMol is a molecule class that is intended to have a fixed topology.
Definition: ROMol.h:106
TargetMatch(const TargetMatch &src)
Definition: TargetMatch.h:27
Bond * getBondBetweenAtoms(unsigned int idx1, unsigned int idx2)
returns a pointer to the bond between two atoms, Null on failure
unsigned int getNumBonds(bool onlyHeavy=1) const
returns our number of Bonds
std::vector< bool > VisitedTargetBonds
Definition: TargetMatch.h:23
Includes a bunch of functionality for handling Atom and Bond queries.
Definition: Atom.h:29
TargetMatch & operator=(const TargetMatch &src)
Definition: TargetMatch.h:28
class for representing a bond
Definition: Bond.h:47
std::vector< std::pair< FMCS::Graph::vertex_descriptor, FMCS::Graph::vertex_descriptor > > match_V_t
MolFragment MoleculeFragment
Definition: Seed.h:69
std::vector< const Bond * > Bonds
Definition: Seed.h:25
unsigned int getIdx() const
returns our index within the ROMol
Definition: Bond.h:164
std::vector< unsigned > AtomsIdx
Definition: Seed.h:26