Seed.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.
//
#include <RDGeneral/export.h>
#pragma once
#include <map>
#include "../RDKitBase.h"
#include "DebugTrace.h" // algorithm optimisation definitions
#include "Graph.h"
#include "DuplicatedSeedCache.h"
#include "SubstructMatchCustom.h"
namespace RDKit {
namespace FMCS {
class MaximumCommonSubgraph;
struct TargetMatch;
struct RDKIT_FMCS_EXPORT
MolFragment { // Reference to a fragment of source molecule
std::vector<const Atom*> Atoms;
std::vector<const Bond*> Bonds;
std::vector<unsigned> AtomsIdx;
std::vector<unsigned> BondsIdx; // need for results and size() only !
std::map<unsigned, unsigned> SeedAtomIdxMap; // Full Query Molecule to Seed
// indices backward conversion
// map
};
struct RDKIT_FMCS_EXPORT NewBond {
unsigned SourceAtomIdx{0}; // index in the seed. Atom is already in the seed
unsigned BondIdx{0}; // index in qmol of new bond scheduled to be added into
// seed. This is outgoing bond from SourceAtomIdx
unsigned NewAtomIdx{0}; // index in qmol of new atom scheduled to be added
// into seed. Another end of new bond
const Atom* NewAtom{nullptr}; // pointer to qmol's new atom scheduled to be
// added into seed. Another end of new bond
unsigned EndAtomIdx{0}; // index in the seed. RING. "New" Atom on the another
// end of new bond is already exists in the seed.
NewBond()
{}
NewBond(unsigned from_atom, unsigned bond_idx, unsigned new_atom,
unsigned to_atom, const Atom* a)
: SourceAtomIdx(from_atom),
BondIdx(bond_idx),
NewAtomIdx(new_atom),
NewAtom(a),
EndAtomIdx(to_atom) {}
};
class RDKIT_FMCS_EXPORT Seed {
private:
mutable std::vector<NewBond> NewBonds; // for multistage growing. all
// directly connected outgoing bonds
public:
bool CopyComplete{false}; // this seed has been completely copied into list.
// postponed non-locked copy for MULTI_THREAD
mutable unsigned GrowingStage{0}; // 0 new seed; -1 finished; n>0 in
// progress, exact stage of growing for SDF
MolFragment MoleculeFragment; // Reference to a fragment of source molecule
Graph Topology; // seed topology with references to source molecule
std::vector<bool> ExcludedBonds;
unsigned LastAddedAtomsBeginIdx{0}; // in this subgraph for improving
// performance of future growing
unsigned LastAddedBondsBeginIdx{0}; // in this subgraph for DEBUG ONLY
unsigned RemainingBonds{0};
unsigned RemainingAtoms{0};
#ifdef DUP_SUBSTRUCT_CACHE
DuplicatedSeedCache::TKey DupCacheKey;
#endif
std::vector<TargetMatch> MatchResult; // for each target
public:
Seed()
{}
void setMoleculeFragment(const Seed& src) {
MoleculeFragment = src.MoleculeFragment;
}
Seed& operator=(const Seed& src) {
NewBonds = src.NewBonds;
GrowingStage = src.GrowingStage;
MoleculeFragment = src.MoleculeFragment;
Topology = src.Topology;
ExcludedBonds = src.ExcludedBonds;
LastAddedAtomsBeginIdx = src.LastAddedAtomsBeginIdx;
LastAddedBondsBeginIdx = src.LastAddedBondsBeginIdx;
RemainingBonds = src.RemainingBonds;
RemainingAtoms = src.RemainingAtoms;
#ifdef DUP_SUBSTRUCT_CACHE
DupCacheKey = src.DupCacheKey;
#endif
MatchResult = src.MatchResult;
CopyComplete = true; // LAST
return *this;
}
void createFromParent(const Seed* parent) {
MoleculeFragment = parent->MoleculeFragment;
Topology = parent->Topology;
ExcludedBonds = parent->ExcludedBonds;
RemainingBonds = parent->RemainingBonds;
RemainingAtoms = parent->RemainingAtoms;
#ifdef DUP_SUBSTRUCT_CACHE
DupCacheKey = parent->DupCacheKey;
#endif
LastAddedAtomsBeginIdx = getNumAtoms(); // previous size
LastAddedBondsBeginIdx = getNumBonds(); // previous size
GrowingStage = 0;
}
unsigned getNumAtoms() const { return MoleculeFragment.AtomsIdx.size(); }
unsigned getNumBonds() const { return MoleculeFragment.BondsIdx.size(); }
void grow(MaximumCommonSubgraph& mcs) const;
bool canGrowBiggerThan(unsigned maxBonds,
unsigned maxAtoms) const { // prune()
return RemainingBonds + getNumBonds() > maxBonds ||
(RemainingBonds + getNumBonds() == maxBonds &&
RemainingAtoms + getNumAtoms() > maxAtoms);
}
void computeRemainingSize(const ROMol& qmol);
unsigned addAtom(const Atom* atom);
unsigned addBond(const Bond* bond);
void fillNewBonds(const ROMol& qmol);
};
} // namespace FMCS
} // namespace RDKit
DebugTrace.h
DuplicatedSeedCache.h
Graph.h
SubstructMatchCustom.h
RDKit::Atom
The class for representing atoms.
Definition: Atom.h:68
RDKit::Bond
class for representing a bond
Definition: Bond.h:46
RDKit::FMCS::DuplicatedSeedCache::TKey
Definition: DuplicatedSeedCache.h:22
RDKit::FMCS::Graph
Definition: Graph.h:26
RDKit::FMCS::MaximumCommonSubgraph
Definition: MaximumCommonSubgraph.h:39
RDKit::FMCS::Seed
Definition: Seed.h:59
RDKit::FMCS::Seed::getNumBonds
unsigned getNumBonds() const
Definition: Seed.h:121
RDKit::FMCS::Seed::canGrowBiggerThan
bool canGrowBiggerThan(unsigned maxBonds, unsigned maxAtoms) const
Definition: Seed.h:124
RDKit::FMCS::Seed::createFromParent
void createFromParent(const Seed *parent)
Definition: Seed.h:106
RDKit::FMCS::Seed::LastAddedBondsBeginIdx
unsigned LastAddedBondsBeginIdx
Definition: Seed.h:74
RDKit::FMCS::Seed::grow
void grow(MaximumCommonSubgraph &mcs) const
RDKit::FMCS::Seed::GrowingStage
unsigned GrowingStage
Definition: Seed.h:66
RDKit::FMCS::Seed::Seed
Seed()
Definition: Seed.h:82
RDKit::FMCS::Seed::getNumAtoms
unsigned getNumAtoms() const
Definition: Seed.h:120
RDKit::FMCS::Seed::RemainingBonds
unsigned RemainingBonds
Definition: Seed.h:75
RDKit::FMCS::Seed::MoleculeFragment
MolFragment MoleculeFragment
Definition: Seed.h:68
RDKit::FMCS::Seed::DupCacheKey
DuplicatedSeedCache::TKey DupCacheKey
Definition: Seed.h:78
RDKit::FMCS::Seed::MatchResult
std::vector< TargetMatch > MatchResult
Definition: Seed.h:80
RDKit::FMCS::Seed::RemainingAtoms
unsigned RemainingAtoms
Definition: Seed.h:76
RDKit::FMCS::Seed::addAtom
unsigned addAtom(const Atom *atom)
RDKit::FMCS::Seed::setMoleculeFragment
void setMoleculeFragment(const Seed &src)
Definition: Seed.h:86
RDKit::FMCS::Seed::fillNewBonds
void fillNewBonds(const ROMol &qmol)
RDKit::FMCS::Seed::ExcludedBonds
std::vector< bool > ExcludedBonds
Definition: Seed.h:71
RDKit::FMCS::Seed::LastAddedAtomsBeginIdx
unsigned LastAddedAtomsBeginIdx
Definition: Seed.h:72
RDKit::FMCS::Seed::computeRemainingSize
void computeRemainingSize(const ROMol &qmol)
RDKit::FMCS::Seed::addBond
unsigned addBond(const Bond *bond)
RDKit::FMCS::Seed::Topology
Graph Topology
Definition: Seed.h:69
RDKit::FMCS::Seed::operator=
Seed & operator=(const Seed &src)
Definition: Seed.h:89
RDKit::ROMol
Definition: ROMol.h:178
export.h
RDKIT_FMCS_EXPORT
#define RDKIT_FMCS_EXPORT
Definition: export.h:145
RDKit
Std stuff.
Definition: Abbreviations.h:18
RDKit::FMCS::MolFragment
Definition: Seed.h:25
RDKit::FMCS::MolFragment::AtomsIdx
std::vector< unsigned > AtomsIdx
Definition: Seed.h:28
RDKit::FMCS::MolFragment::Atoms
std::vector< const Atom * > Atoms
Definition: Seed.h:26
RDKit::FMCS::MolFragment::Bonds
std::vector< const Bond * > Bonds
Definition: Seed.h:27
RDKit::FMCS::MolFragment::BondsIdx
std::vector< unsigned > BondsIdx
Definition: Seed.h:29
RDKit::FMCS::MolFragment::SeedAtomIdxMap
std::map< unsigned, unsigned > SeedAtomIdxMap
Definition: Seed.h:30
RDKit::FMCS::NewBond
Definition: Seed.h:35
RDKit::FMCS::NewBond::NewBond
NewBond()
Definition: Seed.h:46
RDKit::FMCS::NewBond::NewBond
NewBond(unsigned from_atom, unsigned bond_idx, unsigned new_atom, unsigned to_atom, const Atom *a)
Definition: Seed.h:50