TargetMatch.h
Go to the documentation of this file.
//
// 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.
//
#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;
}
};
}
}
RDKit::FMCS::TargetMatch::TargetBondIdx
std::vector< unsigned > TargetBondIdx
Definition: TargetMatch.h:22
RDKit::FMCS::Target::Molecule
const ROMol * Molecule
Definition: Target.h:21
RDKit::FMCS::Seed
Definition: Seed.h:60
FMCS.h
RDKit::FMCS::TargetMatch::init
void init(const Seed &seed, const match_V_t &match, const ROMol &query, const Target &target)
Definition: TargetMatch.h:53
RDKit::ROMol::getNumAtoms
unsigned int getNumAtoms(bool onlyExplicit=1) const
returns our number of atoms
RDKit::ROMol::getNumBonds
unsigned int getNumBonds(bool onlyHeavy=1) const
returns our number of Bonds
RDKit::FMCS::TargetMatch::TargetAtomIdx
std::vector< unsigned > TargetAtomIdx
Definition: TargetMatch.h:21
RDKit::FMCS::TargetMatch::VisitedTargetAtoms
std::vector< bool > VisitedTargetAtoms
Definition: TargetMatch.h:24
RDKit::ROMol
ROMol is a molecule class that is intended to have a fixed topology.
Definition: ROMol.h:102
RDKit::FMCS::TargetMatch::TargetMatch
TargetMatch(const TargetMatch &src)
Definition: TargetMatch.h:27
RDKit::FMCS::TargetMatch::clear
void clear()
Definition: TargetMatch.h:45
RDKit::ROMol::getBondBetweenAtoms
Bond * getBondBetweenAtoms(unsigned int idx1, unsigned int idx2)
returns a pointer to the bond between two atoms, Null on failure
RDKit::FMCS::TargetMatch::TargetMatch
TargetMatch()
Definition: TargetMatch.h:26
RDKit::FMCS::TargetMatch::Empty
bool Empty
Definition: TargetMatch.h:18
RDKit::FMCS::TargetMatch::empty
bool empty() const
Definition: TargetMatch.h:44
RDKit::FMCS::TargetMatch::VisitedTargetBonds
std::vector< bool > VisitedTargetBonds
Definition: TargetMatch.h:23
RDKit
Includes a bunch of functionality for handling Atom and Bond queries.
Definition: Atom.h:28
RDKit::FMCS::TargetMatch::operator=
TargetMatch & operator=(const TargetMatch &src)
Definition: TargetMatch.h:28
RDKit::FMCS::TargetMatch::MatchedAtomSize
size_t MatchedAtomSize
Definition: TargetMatch.h:19
RDKit::FMCS::TargetMatch::MatchedBondSize
size_t MatchedBondSize
Definition: TargetMatch.h:20
RDKit::FMCS::Target
Definition: Target.h:20
RDKit::Bond
class for representing a bond
Definition: Bond.h:46
RDKit::FMCS::match_V_t
std::vector< std::pair< FMCS::Graph::vertex_descriptor, FMCS::Graph::vertex_descriptor > > match_V_t
Definition: SubstructMatchCustom.h:19
RDKit::FMCS::Seed::MoleculeFragment
MolFragment MoleculeFragment
Definition: Seed.h:69
RDKit::FMCS::MolFragment::Bonds
std::vector< const Bond * > Bonds
Definition: Seed.h:25
MatchTable.h
RDKit::Bond::getIdx
unsigned int getIdx() const
returns our index within the ROMol
Definition: Bond.h:158
RDKit::FMCS::TargetMatch
Definition: TargetMatch.h:17
RDKit::FMCS::MolFragment::AtomsIdx
std::vector< unsigned > AtomsIdx
Definition: Seed.h:26