Loading...
Searching...
No Matches
TautomerQuery.h
Go to the documentation of this file.
//
// Created by Gareth Jones on 5/7/2020.
//
// Copyright 2020-2022 Schrodinger, Inc and other RDKit contributors
// @@ 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>
#ifndef RDKIT_TAUTOMERQUERY_H
#define RDKIT_TAUTOMERQUERY_H
#include <GraphMol/ROMol.h>
#include <GraphMol/MolPickler.h>
#include <vector>
#include <GraphMol/Substruct/SubstructMatch.h>
#include <DataStructs/ExplicitBitVect.h>
#ifdef RDK_USE_BOOST_SERIALIZATION
#include <RDGeneral/BoostStartInclude.h>
#include <boost/serialization/vector.hpp>
#include <boost/serialization/shared_ptr.hpp>
#include <boost/serialization/split_member.hpp>
#include <RDGeneral/BoostEndInclude.h>
#endif
namespace RDKit {
class RWMol;
RDKIT_TAUTOMERQUERY_EXPORT bool TautomerQueryCanSerialize();
class RDKIT_TAUTOMERQUERY_EXPORT TautomerQuery {
private:
// Tautomers of the query
std::vector<ROMOL_SPTR> d_tautomers;
// Template query for substructure search
std::unique_ptr<const ROMol> d_templateMolecule;
// Tautomeric bonds and atoms
std::vector<size_t> d_modifiedAtoms;
std::vector<size_t> d_modifiedBonds;
// tests if a match to the template matches a specific tautomer
bool matchTautomer(const ROMol &mol, const ROMol &tautomer,
const std::vector<unsigned int> &match,
const SubstructMatchParameters &params) const;
public:
TautomerQuery(std::vector<ROMOL_SPTR> tautomers,
const ROMol *const templateMolecule,
std::vector<size_t> modifiedAtoms,
std::vector<size_t> modifiedBonds);
//! Copy constructor performs a deep copy
TautomerQuery(const TautomerQuery &other)
: d_templateMolecule(other.d_templateMolecule
? new ROMol(*other.d_templateMolecule)
: nullptr),
d_modifiedAtoms(other.d_modifiedAtoms),
d_modifiedBonds(other.d_modifiedBonds) {
PRECONDITION(other.d_templateMolecule != nullptr, "Null template");
for (auto taut : other.d_tautomers) {
PRECONDITION(taut.get() != nullptr, "Null tautomer");
d_tautomers.push_back(boost::make_shared<ROMol>(*taut));
}
}
TautomerQuery(const std::string &pickle) { initFromString(pickle); }
// Factory to build TautomerQuery
// Caller owns the memory
static TautomerQuery *fromMol(
const ROMol &molecule,
const std::string &tautomerTransformFile = std::string());
// Substructure search
std::vector<MatchVectType> substructOf(
const ROMol &mol,
const SubstructMatchParameters &params = SubstructMatchParameters(),
std::vector<ROMOL_SPTR> *matchingTautomers = nullptr) const;
// SubstructureMatch
bool isSubstructOf(const ROMol &mol, const SubstructMatchParameters &params =
SubstructMatchParameters());
// Query fingerprint
ExplicitBitVect *patternFingerprintTemplate(
unsigned int fpSize = 2048U) const;
// Static method to Fingerprint a target
static ExplicitBitVect *patternFingerprintTarget(const ROMol &target,
unsigned int fpSize = 2048U);
// accessors
// pointer is owned by TautomerQuery
const ROMol &getTemplateMolecule() const { return *d_templateMolecule; }
const std::vector<ROMOL_SPTR> getTautomers() const { return d_tautomers; }
const std::vector<size_t> getModifiedAtoms() const { return d_modifiedAtoms; }
const std::vector<size_t> getModifiedBonds() const { return d_modifiedBonds; }
//! serializes (pickles) to a stream
void toStream(std::ostream &ss) const;
//! returns a string with a serialized (pickled) representation
std::string serialize() const;
//! initializes from a stream pickle
void initFromStream(std::istream &ss);
//! initializes from a string pickle
void initFromString(const std::string &text);
friend class TautomerQueryMatcher;
#ifdef RDK_USE_BOOST_SERIALIZATION
template <class Archive>
void save(Archive &ar, const unsigned int version) const {
RDUNUSED_PARAM(version);
std::vector<std::string> pkls;
for (const auto &taut : d_tautomers) {
std::string pkl;
MolPickler::pickleMol(*taut, pkl, PicklerOps::AllProps);
pkls.push_back(pkl);
}
ar << pkls;
std::string molpkl;
MolPickler::pickleMol(*d_templateMolecule, molpkl, PicklerOps::AllProps);
ar << molpkl;
ar << d_modifiedAtoms;
ar << d_modifiedBonds;
}
template <class Archive>
void load(Archive &ar, const unsigned int version) {
RDUNUSED_PARAM(version);
std::vector<std::string> pkls;
ar >> pkls;
d_tautomers.clear();
for (const auto &pkl : pkls) {
d_tautomers.push_back(ROMOL_SPTR(new ROMol(pkl)));
}
std::string molpkl;
ar >> molpkl;
d_templateMolecule.reset(new ROMol(molpkl));
ar >> d_modifiedAtoms;
ar >> d_modifiedBonds;
}
BOOST_SERIALIZATION_SPLIT_MEMBER()
#endif
};
// so we can use the templates in Code/GraphMol/Substruct/SubstructMatch.h
RDKIT_TAUTOMERQUERY_EXPORT std::vector<MatchVectType> SubstructMatch(
const ROMol &mol, const TautomerQuery &query,
const SubstructMatchParameters &params);
} // namespace RDKit
#endif // RDKIT_TAUTOMERQUERY_H
BoostEndInclude.h
BoostStartInclude.h
ExplicitBitVect.h
RDUNUSED_PARAM
#define RDUNUSED_PARAM(x)
Definition Invariant.h:196
PRECONDITION
#define PRECONDITION(expr, mess)
Definition Invariant.h:109
MolPickler.h
ROMol.h
Defines the primary molecule class ROMol as well as associated typedefs.
SubstructMatch.h
ExplicitBitVect
a class for bit vectors that are densely occupied
Definition ExplicitBitVect.h:29
RDKit::ROMol
Definition ROMol.h:199
RDKit::TautomerQuery
Definition TautomerQuery.h:36
RDKit::TautomerQuery::patternFingerprintTemplate
ExplicitBitVect * patternFingerprintTemplate(unsigned int fpSize=2048U) const
RDKit::TautomerQuery::serialize
std::string serialize() const
returns a string with a serialized (pickled) representation
RDKit::TautomerQuery::TautomerQuery
TautomerQuery(const TautomerQuery &other)
Copy constructor performs a deep copy.
Definition TautomerQuery.h:58
RDKit::TautomerQuery::getModifiedAtoms
const std::vector< size_t > getModifiedAtoms() const
Definition TautomerQuery.h:103
RDKit::TautomerQuery::getTemplateMolecule
const ROMol & getTemplateMolecule() const
Definition TautomerQuery.h:99
RDKit::TautomerQuery::getModifiedBonds
const std::vector< size_t > getModifiedBonds() const
Definition TautomerQuery.h:105
RDKit::TautomerQuery::TautomerQuery
TautomerQuery(const std::string &pickle)
Definition TautomerQuery.h:71
RDKit::TautomerQuery::isSubstructOf
bool isSubstructOf(const ROMol &mol, const SubstructMatchParameters &params=SubstructMatchParameters())
RDKit::TautomerQuery::initFromString
void initFromString(const std::string &text)
initializes from a string pickle
RDKit::TautomerQuery::getTautomers
const std::vector< ROMOL_SPTR > getTautomers() const
Definition TautomerQuery.h:101
RDKit::TautomerQuery::TautomerQuery
TautomerQuery(std::vector< ROMOL_SPTR > tautomers, const ROMol *const templateMolecule, std::vector< size_t > modifiedAtoms, std::vector< size_t > modifiedBonds)
RDKit::TautomerQuery::initFromStream
void initFromStream(std::istream &ss)
initializes from a stream pickle
RDKit::TautomerQuery::patternFingerprintTarget
static ExplicitBitVect * patternFingerprintTarget(const ROMol &target, unsigned int fpSize=2048U)
RDKit::TautomerQuery::toStream
void toStream(std::ostream &ss) const
serializes (pickles) to a stream
RDKit::TautomerQuery::fromMol
static TautomerQuery * fromMol(const ROMol &molecule, const std::string &tautomerTransformFile=std::string())
RDKit::TautomerQuery::substructOf
std::vector< MatchVectType > substructOf(const ROMol &mol, const SubstructMatchParameters &params=SubstructMatchParameters(), std::vector< ROMOL_SPTR > *matchingTautomers=nullptr) const
export.h
RDKIT_TAUTOMERQUERY_EXPORT
#define RDKIT_TAUTOMERQUERY_EXPORT
Definition export.h:521
RDKit
Std stuff.
Definition Abbreviations.h:19
RDKit::SubstructMatch
RDKIT_SUBSTRUCTMATCH_EXPORT std::vector< MatchVectType > SubstructMatch(const ROMol &mol, const ROMol &query, const SubstructMatchParameters &params=SubstructMatchParameters())
Find a substructure match for a query in a molecule.
RDKit::TautomerQueryCanSerialize
RDKIT_TAUTOMERQUERY_EXPORT bool TautomerQueryCanSerialize()
RDKit::SubstructMatchParameters
Definition SubstructMatch.h:41