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
|
//
// Substructure searching - example14.cpp
#include <iostream>
#include <vector>
#include <GraphMol/GraphMol.h>
#include <GraphMol/FileParsers/MolSupplier.h>
#include <GraphMol/SmilesParse/SmilesParse.h>
#include <GraphMol/Substruct/SubstructMatch.h>
int main(int argc, char **argv) {
std::shared_ptr<RDKit::ROMol> mol1(RDKit::SmilesToMol("c1ccccc1O"));
std::shared_ptr<RDKit::RWMol> patt(RDKit::SmartsToMol("ccO"));
RDKit::MatchVectType res;
if (RDKit::SubstructMatch(*mol1, *patt, res)) {
std::cout << "Pattern matched molecule : " << std::endl;
for (size_t i = 0; i < res.size(); ++i) {
std::cout << "(" << res[i].first << "," << res[i].second << ")";
}
std::cout << std::endl;
}
std::vector<RDKit::MatchVectType> hits_vect;
if (RDKit::SubstructMatch(*mol1, *patt, hits_vect)) {
for (size_t i = 0; i < hits_vect.size(); ++i) {
std::cout << "Match " << i + 1 << " : ";
for (size_t j = 0; j < hits_vect[i].size(); ++j) {
std::cout << "(" << hits_vect[i][j].first << ","
<< hits_vect[i][j].second << ")";
}
std::cout << std::endl;
}
}
std::string file_root = getenv("RDBASE");
file_root += "/Docs/Book";
std::string sdf_file = file_root + "/data/actives_5ht3.sdf";
RDKit::SDMolSupplier mol_supplier(sdf_file, true);
std::shared_ptr<RDKit::RWMol> patt1(RDKit::SmartsToMol("c[NH1]"));
std::vector<std::shared_ptr<RDKit::ROMol>> matches;
while (!mol_supplier.atEnd()) {
std::shared_ptr<RDKit::ROMol> mol3(mol_supplier.next());
if (mol3 && RDKit::SubstructMatch(*mol3, *patt1, res)) {
matches.push_back(mol3);
}
}
std::cout << "There were " << matches.size() << " hits in the file."
<< std::endl;
std::shared_ptr<RDKit::ROMol> mol4(RDKit::SmilesToMol("C1=CC=CC=C1OC"));
std::shared_ptr<RDKit::RWMol> smi_mol1(RDKit::SmilesToMol("CO"));
if (RDKit::SubstructMatch(*mol4, *smi_mol1, res)) {
std::cout << "SMILES match" << std::endl;
} else {
std::cout << "Not SMILES match" << std::endl;
}
std::shared_ptr<RDKit::RWMol> smt_mol1(RDKit::SmartsToMol("CO"));
if (RDKit::SubstructMatch(*mol4, *smt_mol1, res)) {
std::cout << "SMARTS match" << std::endl;
} else {
std::cout << "Not SMARTS match" << std::endl;
}
std::shared_ptr<RDKit::RWMol> smi_mol2(RDKit::SmilesToMol("COC"));
if (RDKit::SubstructMatch(*mol4, *smi_mol2, res)) {
std::cout << "SMILES match" << std::endl;
} else {
std::cout << "Not SMILES match" << std::endl;
}
std::shared_ptr<RDKit::RWMol> smt_mol2(RDKit::SmartsToMol("COC"));
if (RDKit::SubstructMatch(*mol4, *smt_mol2, res)) {
std::cout << "SMARTS match" << std::endl;
} else {
std::cout << "Not SMARTS match" << std::endl;
}
// Needs aromatic C
std::shared_ptr<RDKit::RWMol> smt_mol3(RDKit::SmartsToMol("COc"));
if (RDKit::SubstructMatch(*mol4, *smt_mol3, res)) {
std::cout << "SMARTS match" << std::endl;
} else {
std::cout << "Not SMARTS match" << std::endl;
}
}
|