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
|
#include "obtest.h"
#include <openbabel/isomorphism.h>
#include <openbabel/query.h>
#include <openbabel/mol.h>
#include <openbabel/obconversion.h>
using namespace std;
using namespace OpenBabel;
std::string GetFilename(const std::string &filename)
{
string path = TESTDATADIR + filename;
return path;
}
bool doAutomorphismTest(OBMol &mol, int numAutomorphisms)
{
OBIsomorphismMapper::Mappings G;
FindAutomorphisms(&mol, G);
return (G.size() == numAutomorphisms);
}
void testAutomorphisms()
{
cout << "testAutomorphisms" << endl;
OBMol mol;
OBConversion conv;
conv.SetInFormat("smi");
conv.ReadString(&mol, "C1C(CC2CC2)C1");
Automorphisms aut;
FindAutomorphisms((OBMol*)&mol, aut);
cout << aut.size() << endl;
OB_ASSERT( aut.size() == 8 );
}
/**
* Test detection of stereoisomers
*/
int main(int argc, char **argv)
{
// Define location of file formats for testing
#ifdef FORMATDIR
char env[BUFF_SIZE];
snprintf(env, BUFF_SIZE, "BABEL_LIBDIR=%s", FORMATDIR);
putenv(env);
#endif
testAutomorphisms();
OBMol mol;
OBConversion conv;
OB_ASSERT( conv.SetInFormat("mol") );
/*
* Computers & Chemistry 26 (2002) 119-123
*
* Figure 2. Test graphs
*/
cout << "Hao, Xu paper, fig. 2: structure 1" << endl;
OB_ASSERT( conv.ReadFile(&mol, GetFilename("hao_xu_1.mol")) );
OB_ASSERT( doAutomorphismTest(mol, 8) );
cout << "Hao, Xu paper, fig. 2: structure 2" << endl;
OB_ASSERT( conv.ReadFile(&mol, GetFilename("hao_xu_2.mol")) );
OB_ASSERT( doAutomorphismTest(mol, 2) );
cout << "Hao, Xu paper, fig. 2: structure 3" << endl;
OB_ASSERT( conv.ReadFile(&mol, GetFilename("hao_xu_3.mol")) );
OB_ASSERT( doAutomorphismTest(mol, 48) );
cout << "Hao, Xu paper, fig. 2: structure 4" << endl;
OB_ASSERT( conv.ReadFile(&mol, GetFilename("hao_xu_4.mol")) );
OB_ASSERT( doAutomorphismTest(mol, 2) );
cout << "Hao, Xu paper, fig. 2: structure 5" << endl;
OB_ASSERT( conv.ReadFile(&mol, GetFilename("hao_xu_5.mol")) );
OB_ASSERT( doAutomorphismTest(mol, 2) );
cout << "Hao, Xu paper, fig. 2: structure 6" << endl;
OB_ASSERT( conv.ReadFile(&mol, GetFilename("hao_xu_6.mol")) );
OB_ASSERT( doAutomorphismTest(mol, 6) );
cout << "Hao, Xu paper, fig. 2: structure 7" << endl;
OB_ASSERT( conv.ReadFile(&mol, GetFilename("hao_xu_7.mol")) );
OB_ASSERT( doAutomorphismTest(mol, 1) );
cout << "Hao, Xu paper, fig. 2: structure 8" << endl;
OB_ASSERT( conv.ReadFile(&mol, GetFilename("hao_xu_8.mol")) );
OB_ASSERT( doAutomorphismTest(mol, 1) );
cout << "Hao, Xu paper, fig. 2: structure 9" << endl;
OB_ASSERT( conv.ReadFile(&mol, GetFilename("hao_xu_9.mol")) );
OB_ASSERT( doAutomorphismTest(mol, 20) );
}
|