File: automorphismtest.cpp

package info (click to toggle)
openbabel 2.4.1%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 58,308 kB
  • sloc: cpp: 459,210; ansic: 90,514; php: 13,963; python: 7,899; perl: 6,518; pascal: 793; sh: 179; xml: 97; ruby: 64; makefile: 46; java: 23; cs: 14
file content (122 lines) | stat: -rw-r--r-- 3,322 bytes parent folder | download | duplicates (5)
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
#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;

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 automorphismtest(int argc, char* argv[])
{
  int defaultchoice = 1;
  
  int choice = defaultchoice;

  if (argc > 1) {
    if(sscanf(argv[1], "%d", &choice) != 1) {
      printf("Couldn't parse that input as a number\n");
      return -1;
    }
  }

  // Define location of file formats for testing
  #ifdef FORMATDIR
    char env[BUFF_SIZE];
    snprintf(env, BUFF_SIZE, "BABEL_LIBDIR=%s", FORMATDIR);
    putenv(env);
  #endif  

  OBMol mol;
  OBConversion conv;
  OB_ASSERT( conv.SetInFormat("mol") );

  switch(choice) {
  case 1:
    testAutomorphisms();
    break;
  case 2:
    /*
     * Computers & Chemistry 26 (2002) 119-123
     *
     * Figure 2. Test graphs
     */
    cout << "Hao, Xu paper, fig. 2: structure 1" << endl;
    OB_ASSERT( conv.ReadFile(&mol, OBTestUtil::GetFilename("hao_xu_1.mol")) );
    OB_ASSERT( doAutomorphismTest(mol, 8) );
    break;
  case 3:
    cout << "Hao, Xu paper, fig. 2: structure 2" << endl;
    OB_ASSERT( conv.ReadFile(&mol, OBTestUtil::GetFilename("hao_xu_2.mol")) );
    OB_ASSERT( doAutomorphismTest(mol, 2) );
    break;
  case 4:
    cout << "Hao, Xu paper, fig. 2: structure 3" << endl;
    OB_ASSERT( conv.ReadFile(&mol, OBTestUtil::GetFilename("hao_xu_3.mol")) );
    OB_ASSERT( doAutomorphismTest(mol, 48) );
    break;
  case 5:
    cout << "Hao, Xu paper, fig. 2: structure 4" << endl;
    OB_ASSERT( conv.ReadFile(&mol, OBTestUtil::GetFilename("hao_xu_4.mol")) );
    OB_ASSERT( doAutomorphismTest(mol, 2) );
    break;
  case 6:
    cout << "Hao, Xu paper, fig. 2: structure 5" << endl;
    OB_ASSERT( conv.ReadFile(&mol, OBTestUtil::GetFilename("hao_xu_5.mol")) );
    OB_ASSERT( doAutomorphismTest(mol, 2) );
    break;
  case 7:
    cout << "Hao, Xu paper, fig. 2: structure 6" << endl;
    OB_ASSERT( conv.ReadFile(&mol, OBTestUtil::GetFilename("hao_xu_6.mol")) );
    OB_ASSERT( doAutomorphismTest(mol, 6) );
    break;
  case 8:
    cout << "Hao, Xu paper, fig. 2: structure 7" << endl;
    OB_ASSERT( conv.ReadFile(&mol, OBTestUtil::GetFilename("hao_xu_7.mol")) );
    OB_ASSERT( doAutomorphismTest(mol, 1) );
    break;
  case 9:
    cout << "Hao, Xu paper, fig. 2: structure 8" << endl;
    OB_ASSERT( conv.ReadFile(&mol, OBTestUtil::GetFilename("hao_xu_8.mol")) );
    OB_ASSERT( doAutomorphismTest(mol, 1) );
    break;
  case 10:
    cout << "Hao, Xu paper, fig. 2: structure 9" << endl;
    OB_ASSERT( conv.ReadFile(&mol, OBTestUtil::GetFilename("hao_xu_9.mol")) );
    OB_ASSERT( doAutomorphismTest(mol, 20) );
    break;
  default:
    cout << "Test number " << choice << " does not exist!\n";
    return -1;
  }
  return 0;
}