File: TargetMatch.h

package info (click to toggle)
rdkit 201809.1%2Bdfsg-6
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 123,688 kB
  • sloc: cpp: 230,509; python: 70,501; java: 6,329; ansic: 5,427; sql: 1,899; yacc: 1,739; lex: 1,243; makefile: 445; xml: 229; fortran: 183; sh: 123; cs: 93
file content (100 lines) | stat: -rw-r--r-- 3,542 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
//
//  Copyright (C) 2014 Novartis Institutes for BioMedical Research
//
//   @@ All Rights Reserved @@
//  This file is part of the RDKit.
//  The contents are covered by the terms of the BSD license
//  which is included in the file license.txt, found at the root
//  of the RDKit source tree.
//
#include <RDGeneral/export.h>
#pragma once
#include <vector>
#include "FMCS.h"
#include "MatchTable.h"

namespace RDKit {
namespace FMCS {
struct TargetMatch {
  bool Empty;
  size_t MatchedAtomSize;
  size_t MatchedBondSize;
  std::vector<unsigned> TargetAtomIdx;
  std::vector<unsigned> TargetBondIdx;
  std::vector<bool> VisitedTargetBonds;
  std::vector<bool> VisitedTargetAtoms;  // for checking rings
 public:
  TargetMatch() : Empty(true), MatchedAtomSize(0), MatchedBondSize(0) {}
  TargetMatch(const TargetMatch& src) { *this = src; }
  TargetMatch& operator=(const TargetMatch& src) {
    Empty = src.Empty;
    if (!Empty) {
      MatchedAtomSize = src.MatchedAtomSize;
      MatchedBondSize = src.MatchedBondSize;
      TargetAtomIdx.resize(src.TargetAtomIdx.size());
      memcpy(&TargetAtomIdx[0], &src.TargetAtomIdx[0],
             sizeof(unsigned) * TargetAtomIdx.size());
      TargetBondIdx.resize(src.TargetBondIdx.size());
      memcpy(&TargetBondIdx[0], &src.TargetBondIdx[0],
             sizeof(unsigned) * TargetBondIdx.size());
      VisitedTargetBonds = src.VisitedTargetBonds;  // std::vector<bool> bitset
      VisitedTargetAtoms = src.VisitedTargetAtoms;  // std::vector<bool> bitset
    }
    return *this;
  }
  bool empty() const { return Empty; }
  void clear() {
    Empty = true;

    TargetAtomIdx.clear();
    TargetBondIdx.clear();
    VisitedTargetBonds.clear();
    VisitedTargetAtoms.clear();
  }
  void init(const Seed& seed, const match_V_t& match, const ROMol& query,
            const Target& target) {
    TargetAtomIdx.resize(query.getNumAtoms());
    TargetBondIdx.resize(query.getNumBonds());
    VisitedTargetBonds.resize(target.Molecule->getNumBonds());
    VisitedTargetAtoms.resize(target.Molecule->getNumAtoms());

    memset(&TargetAtomIdx[0], 0xFF, sizeof(unsigned) * TargetAtomIdx.size());
    memset(&TargetBondIdx[0], 0xFF, sizeof(unsigned) * TargetBondIdx.size());
    /*
                for(size_t i = 0; i < TargetAtomIdx.size(); i++)
                    TargetAtomIdx[i] = -1;
                for(size_t i = 0; i < TargetBondIdx.size(); i++)
                    TargetBondIdx[i] = -1;
    */
    for (size_t i = 0; i < VisitedTargetBonds.size(); i++)
      VisitedTargetBonds[i] = false;
    for (size_t i = 0; i < VisitedTargetAtoms.size(); i++)
      VisitedTargetAtoms[i] = false;

    MatchedAtomSize = match.size();
    for (match_V_t::const_iterator mit = match.begin(); mit != match.end();
         mit++) {
      TargetAtomIdx[seed.MoleculeFragment.AtomsIdx[mit->first]] = mit->second;
      VisitedTargetAtoms[mit->second] = true;
    }

    MatchedBondSize = 0;
    for (std::vector<const Bond*>::const_iterator bond =
             seed.MoleculeFragment.Bonds.begin();
         bond != seed.MoleculeFragment.Bonds.end(); bond++) {
      unsigned i = (*bond)->getBeginAtomIdx();
      unsigned j = (*bond)->getEndAtomIdx();
      unsigned ti = TargetAtomIdx[i];
      unsigned tj = TargetAtomIdx[j];
      const Bond* tb = target.Molecule->getBondBetweenAtoms(ti, tj);
      if (tb) {
        MatchedBondSize++;
        TargetBondIdx[(*bond)->getIdx()] = tb->getIdx();  // add
        VisitedTargetBonds[tb->getIdx()] = true;
      }
    }
    Empty = false;
  }
};
}
}