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 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187
|
//
// Copyright (C) 2003-2018 Greg Landrum and Rational Discovery LLC
//
// @@ 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/test.h>
#include <GraphMol/RDKitBase.h>
#include <GraphMol/SmilesParse/SmilesParse.h>
#include <GraphMol/SmilesParse/SmilesWrite.h>
#include <GraphMol/SmilesParse/SmartsWrite.h>
#include <GraphMol/Subgraphs/Subgraphs.h>
#include <GraphMol/Subgraphs/SubgraphUtils.h>
#include <boost/foreach.hpp>
#include <iostream>
using namespace std;
using namespace RDKit;
void test1() {
std::cout << "-----------------------\n Test1: pathToSubmol" << std::endl;
{
std::string smiles = "CC1CC1";
RWMol *mol = SmilesToMol(smiles);
TEST_ASSERT(mol);
PATH_LIST sgs;
sgs = findAllSubgraphsOfLengthN(*mol, 3, false, 0);
TEST_ASSERT(sgs.size() == 3);
BOOST_FOREACH (PATH_TYPE tmp, sgs) {
TEST_ASSERT(tmp[0] == 0);
TEST_ASSERT(tmp.size() == 3);
ROMol *frag = Subgraphs::pathToSubmol(*mol, tmp, false);
smiles = MolToSmiles(*frag, true, false, 0, false);
if (tmp[1] == 1) {
if (tmp[2] == 2) {
TEST_ASSERT(smiles == "CCCC");
} else if (tmp[2] == 3) {
TEST_ASSERT(smiles == "CC(C)C");
} else {
TEST_ASSERT(0);
}
} else if (tmp[1] == 3) {
if (tmp[2] == 2) {
TEST_ASSERT(smiles == "CCCC");
} else if (tmp[2] == 1) {
TEST_ASSERT(smiles == "CC(C)C");
} else {
TEST_ASSERT(0);
}
} else {
TEST_ASSERT(0);
}
delete frag;
}
delete mol;
}
std::cout << "Finished" << std::endl;
}
void test2() {
std::cout << "-----------------------\n Test2: Atom Environments"
<< std::endl;
{
std::string smiles = "CC1CC1";
RWMol *mol = SmilesToMol(smiles);
TEST_ASSERT(mol);
PATH_TYPE pth = findAtomEnvironmentOfRadiusN(*mol, 1, 0);
TEST_ASSERT(pth.size() == 1);
TEST_ASSERT(pth[0] == 0);
pth = findAtomEnvironmentOfRadiusN(*mol, 2, 0);
TEST_ASSERT(pth.size() == 3);
TEST_ASSERT(pth[0] == 0);
pth = findAtomEnvironmentOfRadiusN(*mol, 3, 0);
TEST_ASSERT(pth.size() == 4);
TEST_ASSERT(pth[0] == 0);
pth = findAtomEnvironmentOfRadiusN(*mol, 4, 0);
TEST_ASSERT(pth.size() == 0);
pth = findAtomEnvironmentOfRadiusN(*mol, 1, 1);
TEST_ASSERT(pth.size() == 3);
pth = findAtomEnvironmentOfRadiusN(*mol, 2, 1);
TEST_ASSERT(pth.size() == 4);
pth = findAtomEnvironmentOfRadiusN(*mol, 3, 1);
TEST_ASSERT(pth.size() == 0);
delete mol;
}
{
std::string smiles = "CC1CC1";
RWMol *mol = SmilesToMol(smiles);
TEST_ASSERT(mol);
ROMol *mH = MolOps::addHs(static_cast<const ROMol &>(*mol));
PATH_TYPE pth = findAtomEnvironmentOfRadiusN(*mH, 1, 0);
TEST_ASSERT(pth.size() == 1);
TEST_ASSERT(pth[0] == 0);
pth = findAtomEnvironmentOfRadiusN(*mH, 1, 0, true);
TEST_ASSERT(pth.size() == 4);
delete mol;
delete mH;
}
{
std::string smiles = "O=C(O)CCCC=CC(C1C(O)CC(O)C1(C=CC(O)CCCCC))";
RWMol *mol = SmilesToMol(smiles);
TEST_ASSERT(mol);
smiles = MolToSmiles(*mol);
PATH_TYPE pth = findAtomEnvironmentOfRadiusN(*mol, 2, 9);
TEST_ASSERT(pth.size() == 8);
ROMol *frag = Subgraphs::pathToSubmol(*mol, pth, false);
smiles = MolToSmiles(*frag, true, false, 0, false);
TEST_ASSERT(smiles == "C(C(C(O)C)C(C)C)C");
delete frag;
delete mol;
}
std::cout << "Finished" << std::endl;
}
void testGithubIssue103() {
std::cout << "-----------------------\n Testing github Issue103: "
"stereochemistry and pathToSubmol"
<< std::endl;
{
std::string smiles = "O=C(O)C(=O)C[C@@]1(C(=O)O)C=C[C@H](O)C=C1";
RWMol *mol = SmilesToMol(smiles);
TEST_ASSERT(mol);
PATH_TYPE pth = findAtomEnvironmentOfRadiusN(*mol, 2, 12);
TEST_ASSERT(pth.size() == 5);
ROMol *frag = Subgraphs::pathToSubmol(*mol, pth, false);
smiles = MolToSmiles(*frag, true);
TEST_ASSERT(smiles == "C=CC(O)C=C");
delete frag;
delete mol;
}
{
std::string smiles = "O=C(O)C(=O)C[C@@]1(C(=O)O)C=C[C@H](O)C=C1";
RWMol *mol = SmilesToMol(smiles);
TEST_ASSERT(mol);
PATH_TYPE pth = findAtomEnvironmentOfRadiusN(*mol, 2, 12);
TEST_ASSERT(pth.size() == 5);
ROMol *frag = Subgraphs::pathToSubmol(*mol, pth, false);
smiles = MolToSmarts(*frag);
TEST_ASSERT(smiles == "[#6](-[#6@H](-[#8])-[#6]=[#6])=[#6]");
delete frag;
delete mol;
}
{
std::string smiles = "O=C(O)C(=O)C[C@@]1(C(=O)O)C=C[C@H](O)C=C1";
RWMol *mol = SmilesToMol(smiles);
TEST_ASSERT(mol);
PATH_TYPE pth = findAtomEnvironmentOfRadiusN(*mol, 2, 12);
TEST_ASSERT(pth.size() == 5);
ROMol *frag = Subgraphs::pathToSubmol(*mol, pth, true);
smiles = MolToSmarts(*frag);
TEST_ASSERT(smiles == "[#6](-[#6@](-[#8])-[#6]=[#6])=[#6]");
delete frag;
delete mol;
}
std::cout << "Finished" << std::endl;
}
// -------------------------------------------------------------------
int main() {
test1();
test2();
testGithubIssue103();
return 0;
}
|