40
41
void GenerateRingReference();
42
int main(int argc,char *argv[])
46
if (strncmp(argv[1], "-g", 2))
48
cout << "Usage: ringtest" << endl;
49
cout << " Tests Open Babel ring perception testing." << endl;
54
GenerateRingReference();
59
cout << endl << "Testing RINGS..." << endl;
63
string testdatadir = TESTDATADIR;
64
string results_file = testdatadir + "ringresults.txt";
65
string smilestypes_file = testdatadir + "attype.00.smi";
44
string testdatadir = TESTDATADIR;
45
string results_file = testdatadir + "ringresults.txt";
46
string smilestypes_file = testdatadir + "attype.00.smi";
68
string results_file = "ringresults.txt";
69
string smilestypes_file = "attype.00.smi";
48
string results_file = "files/ringresults.txt";
49
string smilestypes_file = "files/attype.00.smi";
73
if (!SafeOpen(mifs, (char*)smilestypes_file.c_str()))
75
return -1; // test failed
79
if (!SafeOpen(rifs, (char*)results_file.c_str()))
81
return -1; // test failed
88
char buffer[BUFF_SIZE];
94
vector<string>::iterator i;
95
vector<OBEdgeBase*>::iterator j;
96
vector<OBNodeBase*>::iterator k;
97
vector<OBRing*>::iterator m;
98
OBConversion conv(&mifs, &cout);
100
if(! conv.SetInAndOutFormats("SMI","SMI"))
102
ThrowError("SMILES format is not loaded");
112
if (!rifs.getline(buffer,BUFF_SIZE))
114
ThrowError("error reading reference data");
115
return -1; // test failed
119
vb.resize(mol.NumBonds(),false);
122
for (i = vs.begin();i != vs.end();i++)
123
vb[atoi((char*)i->c_str())] = true;
125
for (bond = mol.BeginBond(j);bond;bond = mol.NextBond(j))
126
if (vb[bond->GetIdx()] != bond->IsInRing())
128
ThrowError("ring bond data different than reference");
129
ThrowError((char*)mol.GetTitle());
130
return -1; // test failed
134
if (!rifs.getline(buffer,BUFF_SIZE))
136
ThrowError("error reading reference data");
137
return -1; // test failed
139
sscanf(buffer,"%d",&size);
140
if (vr.size() != size) //check SSSR size
142
ThrowError("SSSR size different than reference");
143
ThrowError((char*)mol.GetTitle());
144
return -1; // test failed
147
if (!rifs.getline(buffer,BUFF_SIZE))
149
ThrowError("error reading reference data");
150
return -1; // test failed
155
for (atom = mol.BeginAtom(k);atom;atom = mol.NextAtom(k))
159
ThrowError("Error in SSSR count");
160
ThrowError((char*)mol.GetTitle());
161
return -1; // test failed
164
for (m = vr.begin();m != vr.end();m++)
165
if ((*m)->_pathset[atom->GetIdx()])
168
if (atoi((char*)i->c_str()) != count)
170
ThrowError("Ring membership test failed");
171
ThrowError((char*)mol.GetTitle());
172
return -1; // test failed
52
int main(int argc,char *argv[])
54
// turn off slow sync with C-style output (we don't use it anyway).
55
std::ios::sync_with_stdio(false);
59
if (strncmp(argv[1], "-g", 2))
61
cout << "Usage: ringtest" << endl;
62
cout << " Tests Open Babel ring perception testing." << endl;
67
GenerateRingReference();
72
cout << "# Testing ring perception..." << endl;
75
if (!SafeOpen(mifs, smilestypes_file.c_str()))
77
cout << "Bail out! Cannot read file " << smilestypes_file << endl;
78
return -1; // test failed
82
if (!SafeOpen(rifs, results_file.c_str()))
84
cout << "Bail out! Cannot read file " << results_file << endl;
85
return -1; // test failed
92
char buffer[BUFF_SIZE];
98
vector<string>::iterator i;
99
vector<OBEdgeBase*>::iterator j;
100
vector<OBNodeBase*>::iterator k;
101
vector<OBRing*>::iterator m;
102
OBConversion conv(&mifs, &cout);
103
unsigned int currentTest = 0;
105
if(! conv.SetInAndOutFormats("SMI","SMI"))
107
cout << "Bail out! SMILES format is not loaded" << endl;
117
if (!rifs.getline(buffer,BUFF_SIZE))
119
cout << "Bail out! error reading reference data" << endl;
120
return -1; // test failed
124
vb.resize(mol.NumBonds(),false);
127
for (i = vs.begin();i != vs.end();i++)
128
vb[atoi(i->c_str())] = true;
130
for (bond = mol.BeginBond(j);bond;bond = mol.NextBond(j))
132
if (vb[bond->GetIdx()] != bond->IsInRing())
134
cout << "not ok " << ++currentTest
135
<< " # ring bond data different than reference\n";
136
cout << "# Molecule: " << mol.GetTitle() << "\n";
139
cout << "ok " << ++currentTest
140
<< " # correct ring bond data\n";
144
if (!rifs.getline(buffer,BUFF_SIZE))
146
cout << "Bail out! error reading reference data\n";
147
return -1; // test failed
149
sscanf(buffer,"%d",&size);
150
if (vr.size() != size) //check SSSR size
152
cout << "not ok " << ++currentTest
153
<< " # SSSR size different than reference\n";
154
cout << "# Molecule: " << mol.GetTitle() << "\n";
157
cout << "ok " << ++currentTest
158
<< " # SSSR size matches reference\n";
160
if (!rifs.getline(buffer,BUFF_SIZE))
162
cout << "Bail out! error reading reference data" << endl;
163
return -1; // test failed
168
for (atom = mol.BeginAtom(k);atom;atom = mol.NextAtom(k))
172
cout << "not ok " << ++currentTest << " # error in SSSR count\n";
173
cout << "# Molecule: " << mol.GetTitle() << "\n";
176
cout << "ok " << ++currentTest << " # correct SSSR count\n";
179
for (m = vr.begin();m != vr.end();m++)
180
if ((*m)->_pathset[atom->GetIdx()])
183
if (atoi(i->c_str()) != count)
185
cout << "not ok " << ++currentTest << "# ring membership test failed\n";
186
cout << "# Molecule: " << mol.GetTitle() << "\n";
189
cout << "ok " << ++currentTest << " # ring membership passed\n";
197
// return number of tests run
198
cout << "1.." << currentTest << endl;
185
204
void GenerateRingReference()
188
if (!SafeOpen(ifs,"attype.00.smi"))
192
if (!SafeOpen(ofs,"ringresults.txt"))
198
char buffer[BUFF_SIZE];
200
vector<OBEdgeBase*>::iterator i;
201
vector<OBNodeBase*>::iterator j;
202
vector<OBRing*>::iterator k;
204
OBConversion conv(&ifs, &cout);
206
if(! conv.SetInAndOutFormats("SMI","SMI"))
208
if (!SafeOpen(ifs,smilestypes_file.c_str()))
212
if (!SafeOpen(ofs,results_file.c_str()))
218
char buffer[BUFF_SIZE];
220
vector<OBEdgeBase*>::iterator i;
221
vector<OBNodeBase*>::iterator j;
222
vector<OBRing*>::iterator k;
224
OBConversion conv(&ifs, &cout);
226
if(! conv.SetInAndOutFormats("SMI","SMI"))
208
ThrowError("SMILES format is not loaded");
228
cerr << " SMILES format is not loaded" << endl;
219
//write out ring bonds
220
for (bond = mol.BeginBond(i);bond;bond = mol.NextBond(i))
221
if (bond->IsInRing())
223
sprintf(buffer,"%3d",bond->GetIdx());
229
//write the total number of rings
230
ofs << vr.size() << endl;
232
//write the number of rings that each atom is a member of
233
for (atom = mol.BeginAtom(j);atom;atom = mol.NextAtom(j))
236
for (k = vr.begin();k != vr.end();k++)
237
if ((*k)->_pathset[atom->GetIdx()])
240
sprintf(buffer,"%3d",count);
239
//write out ring bonds
240
for (bond = mol.BeginBond(i);bond;bond = mol.NextBond(i))
241
if (bond->IsInRing())
243
sprintf(buffer,"%3d",bond->GetIdx());
249
//write the total number of rings
250
ofs << vr.size() << endl;
252
//write the number of rings that each atom is a member of
253
for (atom = mol.BeginAtom(j);atom;atom = mol.NextAtom(j))
256
for (k = vr.begin();k != vr.end();k++)
257
if ((*k)->_pathset[atom->GetIdx()])
260
sprintf(buffer,"%3d",count);
247
ThrowError("Ring perception test results written successfully");
267
cerr << " Ring perception test results written successfully" << endl;