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
|
//
// Copyright (C) 2003-2015 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/RDKitQueries.h>
#include <GraphMol/SmilesParse/SmilesParse.h>
#include <iostream>
using namespace std;
using namespace RDKit;
void test1() {
auto *a1 = new Atom(6);
auto *a2 = new Atom(*a1);
Atom *a3 = a1->copy();
delete a1;
delete a2;
delete a3;
}
void test2() {
auto *mol = new RWMol();
mol->addAtom(new Atom(6));
mol->addAtom(new Atom(6));
mol->addAtom(new Atom(8));
mol->addBond(0, 1, Bond::SINGLE);
mol->addBond(1, 2, Bond::SINGLE);
mol->setAtomBookmark(mol->getAtomWithIdx(1), 1);
mol->setBondBookmark(mol->getBondWithIdx(0), 2);
CHECK_INVARIANT(mol->hasAtomBookmark(1), "");
CHECK_INVARIANT(mol->getAtomWithBookmark(1)->getIdx() == 1, "");
CHECK_INVARIANT(mol->hasBondBookmark(2), "");
CHECK_INVARIANT(mol->getBondWithBookmark(2)->getIdx() == 0, "");
auto *mol2 = new RWMol(*mol);
CHECK_INVARIANT(mol2->hasAtomBookmark(1), "");
CHECK_INVARIANT(mol2->getAtomWithBookmark(1)->getIdx() == 1, "");
CHECK_INVARIANT(mol2->hasBondBookmark(2), "");
CHECK_INVARIANT(mol2->getBondWithBookmark(2)->getIdx() == 0, "");
}
void testQueryCopying() {
BOOST_LOG(rdInfoLog)
<< "-----------------------\n Testing behavior of copied queries"
<< std::endl;
{
std::string smi =
"[$([O,S;H1;v2]-[!$(*=[O,N,P,S])]),$([O,S;H0;v2]),$([O,S;-]),$([N;v3;!$"
"(N-*=!@[O,N,P,S])]),$([nH0,o,s;+0])]";
ROMol *m = static_cast<ROMol *>(SmartsToMol(smi));
TEST_ASSERT(m);
std::cerr << "\n\n\nCOPY" << std::endl;
auto *m2 = new ROMol(*m, true);
delete m;
delete m2;
}
BOOST_LOG(rdInfoLog) << "Finished" << std::endl;
}
void testConformerCopying() {
BOOST_LOG(rdInfoLog) << "-----------------------\n Testing copying conformers"
<< std::endl;
{
std::string smi = "CCC";
ROMol *m = static_cast<ROMol *>(SmilesToMol(smi));
TEST_ASSERT(m);
auto *conf = new Conformer(m->getNumAtoms());
conf->setId(1);
m->addConformer(conf, false);
conf = new Conformer(m->getNumAtoms());
conf->setId(2);
m->addConformer(conf, false);
{
auto *m2 = new ROMol(*m);
TEST_ASSERT(m2->getNumConformers() == 2);
delete m2;
}
{
auto *m2 = new ROMol(*m, false, 1);
TEST_ASSERT(m2->getNumConformers() == 1);
TEST_ASSERT(m2->getConformer().getId() == 1);
delete m2;
}
{
auto *m2 = new ROMol(*m, false, 2);
TEST_ASSERT(m2->getNumConformers() == 1);
TEST_ASSERT(m2->getConformer().getId() == 2);
delete m2;
}
{
auto *m2 = new ROMol(*m, false, 3);
TEST_ASSERT(m2->getNumConformers() == 0);
delete m2;
}
delete m;
}
BOOST_LOG(rdInfoLog) << "Finished" << std::endl;
}
// -------------------------------------------------------------------
int main() {
#if 0
test1();
test2();
#endif
testQueryCopying();
testConformerCopying();
return 0;
}
|