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 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123
|
//
// Copyright (c) 2023, Greg Landrum 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 XQMOL_H_MAY2023
#define XQMOL_H_MAY2023
#include <variant>
#include <memory>
#include <string>
#include <vector>
#include <RDGeneral/BoostStartInclude.h>
#include <boost/core/noncopyable.hpp>
#include <RDGeneral/BoostEndInclude.h>
#include <GraphMol/RDKitBase.h>
#include <GraphMol/MolOps.h>
#include <GraphMol/MolBundle.h>
#include <GraphMol/TautomerQuery/TautomerQuery.h>
#include <GraphMol/Substruct/SubstructMatch.h>
namespace RDKit {
namespace GeneralizedSubstruct {
struct RDKIT_GENERALIZEDSUBSTRUCT_EXPORT ExtendedQueryMol {
enum ExtendedQueryMolTypes : unsigned char {
XQM_MOL = 1,
XQM_MOLBUNDLE = 2,
XQM_TAUTOMERQUERY = 3,
XQM_TAUTOMERBUNDLE = 4
};
using RWMol_T = std::unique_ptr<RWMol>;
using MolBundle_T = std::unique_ptr<MolBundle>;
using TautomerQuery_T = std::unique_ptr<TautomerQuery>;
using TautomerBundle_T =
std::unique_ptr<std::vector<std::unique_ptr<TautomerQuery>>>;
using ContainedType =
std::variant<RWMol_T, MolBundle_T, TautomerQuery_T, TautomerBundle_T>;
ExtendedQueryMol(std::unique_ptr<RWMol> mol) : xqmol(std::move(mol)) {}
ExtendedQueryMol(std::unique_ptr<MolBundle> bundle)
: xqmol(std::move(bundle)) {}
ExtendedQueryMol(std::unique_ptr<TautomerQuery> tq) : xqmol(std::move(tq)) {}
ExtendedQueryMol(
std::unique_ptr<std::vector<std::unique_ptr<TautomerQuery>>> tqs)
: xqmol(std::move(tqs)) {}
ExtendedQueryMol(const ExtendedQueryMol &other) { initFromOther(other); }
ExtendedQueryMol &operator=(const ExtendedQueryMol &other) {
if (this == &other) {
return *this;
}
initFromOther(other);
return *this;
}
ExtendedQueryMol(ExtendedQueryMol &&o) noexcept : xqmol(std::move(o.xqmol)) {}
ExtendedQueryMol(const std::string &text, bool isJSON = false);
void initFromBinary(const std::string &pkl);
void initFromJSON(const std::string &text);
void initFromOther(const ExtendedQueryMol &other);
ContainedType xqmol;
std::string toBinary() const;
std::string toJSON() const;
// Query fingerprint
std::unique_ptr<ExplicitBitVect> patternFingerprintQuery(
unsigned int fpSize = 2048U) const;
};
//! Creates an ExtendedQueryMol from the input molecule
/*!
This takes a query molecule and, conceptually, performs the following steps to
produce an ExtendedQueryMol:
1. Enumerates features like Link Nodes and SRUs
2. Converts everything into TautomerQueries
3. Runs adjustQueryProperties()
Each step is optional
\param mol the molecule to start with
\param doEnumeration enumerate features like Link Nodes and SRUs
\param doTautomers generate TautomerQueries
\param adjustQueryProperties call adjustQueryProperties on each of the
results
\param params AdjustQueryParameters object controlling the operation of
adjustQueryProperties
\return The new ExtendedQueryMol
*/
RDKIT_GENERALIZEDSUBSTRUCT_EXPORT ExtendedQueryMol createExtendedQueryMol(
const RWMol &mol, bool doEnumeration = true, bool doTautomers = true,
bool adjustQueryProperties = false,
MolOps::AdjustQueryParameters params = {});
//! does a substructure search with an ExtendedQueryMol
RDKIT_GENERALIZEDSUBSTRUCT_EXPORT std::vector<MatchVectType> SubstructMatch(
const ROMol &mol, const ExtendedQueryMol &query,
const SubstructMatchParameters ¶ms = SubstructMatchParameters());
//! Fingerprints a target molecule
RDKIT_GENERALIZEDSUBSTRUCT_EXPORT std::unique_ptr<ExplicitBitVect>
patternFingerprintTargetMol(const ROMol &mol, unsigned int fpSize = 2048U);
//! checks if a molecule has a match to an ExtendedQueryMol
inline bool hasSubstructMatch(
const ROMol &mol, const ExtendedQueryMol &query,
const SubstructMatchParameters ¶ms = SubstructMatchParameters()) {
SubstructMatchParameters lparams = params;
lparams.maxMatches = 1;
return !SubstructMatch(mol, query, lparams).empty();
}
} // namespace GeneralizedSubstruct
} // namespace RDKit
#endif
|