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
|
#include "obtest.h"
#include <openbabel/mol.h>
#include <openbabel/obconversion.h>
/*
#include <openbabel/graphsym.h>
#include <openbabel/stereo/tetrahedral.h>
#include <openbabel/canon.h>
*/
#include <iostream>
#include <vector>
#include <algorithm>
std::string GetFilename(const std::string &filename)
{
std::string path = TESTDATADIR + filename;
return path;
}
using std::cout;
using std::endl;
using namespace OpenBabel;
bool testCanSmiles(const std::string &smiles, const std::string &stable_cansmiles)
{
cout << " Testing: " << smiles << endl;
// read a smiles string
OBMol mol;
OBConversion canConv, smiConv;
OB_REQUIRE( canConv.SetInFormat("smi") );
OB_REQUIRE( canConv.SetOutFormat("can") );
OB_REQUIRE( smiConv.SetOutFormat("smi") );
// read a smiles string
OB_REQUIRE( canConv.ReadString(&mol, smiles) );
// get can smiles
std::string cansmiles = canConv.WriteString(&mol, true);
OB_COMPARE( cansmiles, stable_cansmiles );
// comapare with ref
if (cansmiles != stable_cansmiles) {
cout << " " << cansmiles << endl;
cout << " " << stable_cansmiles << endl;
return false;
}
return true;
}
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
std::ifstream ifs(GetFilename("canonstable.can").c_str());
OB_REQUIRE( ifs );
OBMol mol;
OBConversion conv;
conv.SetInFormat("smi");
conv.SetOutFormat("can");
std::string line;
while (std::getline(ifs, line)) {
OB_REQUIRE( conv.ReadString(&mol, line.c_str()) );
std::vector<OBAtom*> atoms;
FOR_ATOMS_OF_MOL(atom, mol)
atoms.push_back(&*atom);
for (int i = 0; i < 5; ++i) {
// shuffle the atoms
std::random_shuffle(atoms.begin(), atoms.end());
mol.RenumberAtoms(atoms);
// get can smiles
mol.SetTitle("");
std::string cansmi = conv.WriteString(&mol, true);
// comapare with ref
if (cansmi != line) {
cout << "ref = " << line << endl;
cout << "can = " << cansmi << endl;
OB_ASSERT( cansmi == line );
}
}
}
return 0;
}
|