// // 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 #ifndef XQMOL_H_MAY2023 #define XQMOL_H_MAY2023 #include #include #include #include #include #include #include #include #include #include #include #include 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; using MolBundle_T = std::unique_ptr; using TautomerQuery_T = std::unique_ptr; using TautomerBundle_T = std::unique_ptr>>; using ContainedType = std::variant; ExtendedQueryMol(std::unique_ptr mol) : xqmol(std::move(mol)) {} ExtendedQueryMol(std::unique_ptr bundle) : xqmol(std::move(bundle)) {} ExtendedQueryMol(std::unique_ptr tq) : xqmol(std::move(tq)) {} ExtendedQueryMol( std::unique_ptr>> 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 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 SubstructMatch( const ROMol &mol, const ExtendedQueryMol &query, const SubstructMatchParameters ¶ms = SubstructMatchParameters()); //! Fingerprints a target molecule RDKIT_GENERALIZEDSUBSTRUCT_EXPORT std::unique_ptr 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