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 #include <RDGeneral/export.h>
11 #pragma once
12 #include <vector>
13 #include "FMCS.h"
14 #include "MatchTable.h"
15 
16 namespace RDKit {
17 namespace FMCS {
18 struct TargetMatch {
19  bool Empty;
22  std::vector<unsigned> TargetAtomIdx;
23  std::vector<unsigned> TargetBondIdx;
24  std::vector<bool> VisitedTargetBonds;
25  std::vector<bool> VisitedTargetAtoms; // for checking rings
26  public:
27  TargetMatch() : Empty(true), MatchedAtomSize(0), MatchedBondSize(0) {}
28  TargetMatch(const TargetMatch& src) { *this = src; }
30  Empty = src.Empty;
31  if (!Empty) {
32  MatchedAtomSize = src.MatchedAtomSize;
33  MatchedBondSize = src.MatchedBondSize;
34  TargetAtomIdx.resize(src.TargetAtomIdx.size());
35  memcpy(&TargetAtomIdx[0], &src.TargetAtomIdx[0],
36  sizeof(unsigned) * TargetAtomIdx.size());
37  TargetBondIdx.resize(src.TargetBondIdx.size());
38  memcpy(&TargetBondIdx[0], &src.TargetBondIdx[0],
39  sizeof(unsigned) * TargetBondIdx.size());
40  VisitedTargetBonds = src.VisitedTargetBonds; // std::vector<bool> bitset
41  VisitedTargetAtoms = src.VisitedTargetAtoms; // std::vector<bool> bitset
42  }
43  return *this;
44  }
45  bool empty() const { return Empty; }
46  void clear() {
47  Empty = true;
48 
49  TargetAtomIdx.clear();
50  TargetBondIdx.clear();
51  VisitedTargetBonds.clear();
52  VisitedTargetAtoms.clear();
53  }
54  void init(const Seed& seed, const match_V_t& match, const ROMol& query,
55  const Target& target) {
56  TargetAtomIdx.resize(query.getNumAtoms());
57  TargetBondIdx.resize(query.getNumBonds());
58  VisitedTargetBonds.resize(target.Molecule->getNumBonds());
59  VisitedTargetAtoms.resize(target.Molecule->getNumAtoms());
60 
61  memset(&TargetAtomIdx[0], 0xFF, sizeof(unsigned) * TargetAtomIdx.size());
62  memset(&TargetBondIdx[0], 0xFF, sizeof(unsigned) * TargetBondIdx.size());
63  /*
64  for(size_t i = 0; i < TargetAtomIdx.size(); i++)
65  TargetAtomIdx[i] = -1;
66  for(size_t i = 0; i < TargetBondIdx.size(); i++)
67  TargetBondIdx[i] = -1;
68  */
69  for (size_t i = 0; i < VisitedTargetBonds.size(); i++)
70  VisitedTargetBonds[i] = false;
71  for (size_t i = 0; i < VisitedTargetAtoms.size(); i++)
72  VisitedTargetAtoms[i] = false;
73 
74  MatchedAtomSize = match.size();
75  for (match_V_t::const_iterator mit = match.begin(); mit != match.end();
76  mit++) {
77  TargetAtomIdx[seed.MoleculeFragment.AtomsIdx[mit->first]] = mit->second;
78  VisitedTargetAtoms[mit->second] = true;
79  }
80 
81  MatchedBondSize = 0;
82  for (std::vector<const Bond*>::const_iterator bond =
83  seed.MoleculeFragment.Bonds.begin();
84  bond != seed.MoleculeFragment.Bonds.end(); bond++) {
85  unsigned i = (*bond)->getBeginAtomIdx();
86  unsigned j = (*bond)->getEndAtomIdx();
87  unsigned ti = TargetAtomIdx[i];
88  unsigned tj = TargetAtomIdx[j];
89  const Bond* tb = target.Molecule->getBondBetweenAtoms(ti, tj);
90  if (tb) {
91  MatchedBondSize++;
92  TargetBondIdx[(*bond)->getIdx()] = tb->getIdx(); // add
93  VisitedTargetBonds[tb->getIdx()] = true;
94  }
95  }
96  Empty = false;
97  }
98 };
99 }
100 }
std::vector< unsigned > TargetBondIdx
Definition: TargetMatch.h:23
const ROMol * Molecule
Definition: Target.h:22
void init(const Seed &seed, const match_V_t &match, const ROMol &query, const Target &target)
Definition: TargetMatch.h:54
unsigned int getNumAtoms(bool onlyExplicit=1) const
returns our number of atoms
unsigned int getNumBonds(bool onlyHeavy=1) const
returns our number of Bonds
std::vector< unsigned > TargetAtomIdx
Definition: TargetMatch.h:22
std::vector< bool > VisitedTargetAtoms
Definition: TargetMatch.h:25
TargetMatch(const TargetMatch &src)
Definition: TargetMatch.h:28
Bond * getBondBetweenAtoms(unsigned int idx1, unsigned int idx2)
returns a pointer to the bond between two atoms, Null on failure
std::vector< bool > VisitedTargetBonds
Definition: TargetMatch.h:24
Std stuff.
Definition: Atom.h:30
TargetMatch & operator=(const TargetMatch &src)
Definition: TargetMatch.h:29
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:70
std::vector< const Bond * > Bonds
Definition: Seed.h:26
unsigned int getIdx() const
returns our index within the ROMol
Definition: Bond.h:161
std::vector< unsigned > AtomsIdx
Definition: Seed.h:27