mirror of
https://github.com/openbabel/openbabel.git
synced 2026-08-10 04:58:04 -05:00
Canonconsistent and canonstable tests updated to new framework.
This commit is contained in:
+3
-1
@@ -10,10 +10,12 @@ add_definitions(-DFORMATDIR="\\"${openbabel_BINARY_DIR}/lib${LIB_SUFFIX}/\\"")
|
||||
|
||||
################ Add new tests here
|
||||
set (cpptests
|
||||
automorphism builder
|
||||
automorphism builder canonconsistent canonstable
|
||||
)
|
||||
set (automorphism_parts 1 2 3 4 5 6 7 8 9 10)
|
||||
set (builder_parts 1 2 3 4 5)
|
||||
set (canonconsistent_parts 1 2 3)
|
||||
set (canonstable_parts 1)
|
||||
##################################
|
||||
|
||||
foreach(cpptest ${cpptests})
|
||||
|
||||
@@ -10,16 +10,7 @@
|
||||
using namespace std;
|
||||
using namespace OpenBabel;
|
||||
|
||||
std::string GetFilename(const std::string &filename)
|
||||
{
|
||||
std::string path = TESTDATADIR + filename;
|
||||
return path;
|
||||
}
|
||||
|
||||
static unsigned int failed = 0;
|
||||
static unsigned int testCount = 0;
|
||||
|
||||
bool doMultiMoleculeFile(const std::string &filename, bool counter = false)
|
||||
bool mdoMultiMoleculeFile(const std::string &filename)
|
||||
{
|
||||
std::ifstream ifs;
|
||||
ifs.open(filename.c_str());
|
||||
@@ -43,6 +34,9 @@ bool doMultiMoleculeFile(const std::string &filename, bool counter = false)
|
||||
|
||||
bool result = true;
|
||||
conv.SetInStream(&ifs);
|
||||
int testCount = 0;
|
||||
int failed = 0;
|
||||
|
||||
while (1) {
|
||||
if (!conv.Read(&mol)) {
|
||||
// failed read, try again
|
||||
@@ -50,7 +44,7 @@ bool doMultiMoleculeFile(const std::string &filename, bool counter = false)
|
||||
break; // we tried twice, so break
|
||||
}
|
||||
testCount++;
|
||||
if (counter && testCount % 1000 == 0)
|
||||
if (testCount % 1000 == 0)
|
||||
cout << testCount << " completed" << endl;
|
||||
|
||||
mol.SetTitle("");
|
||||
@@ -67,32 +61,46 @@ bool doMultiMoleculeFile(const std::string &filename, bool counter = false)
|
||||
cout << "Failed aromaticity: \n " << output << "\n";
|
||||
}
|
||||
}
|
||||
|
||||
cout << "PASSED TESTS: " << testCount - failed << "/" << testCount << endl;
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
int main(int argc, char **argv)
|
||||
int canonconsistenttest(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
|
||||
#endif
|
||||
|
||||
if (argc == 2) {
|
||||
OB_ASSERT( doMultiMoleculeFile(argv[1], true) ); cout << "PASSED TESTS: " << testCount - failed << "/" << testCount << endl;
|
||||
return 0;
|
||||
switch(choice) {
|
||||
case 1:
|
||||
OB_ASSERT( mdoMultiMoleculeFile(OBTestUtil::GetFilename("forcefield.sdf")) );
|
||||
break;
|
||||
case 2:
|
||||
OB_ASSERT( mdoMultiMoleculeFile(OBTestUtil::GetFilename("filterset.sdf")) );
|
||||
break;
|
||||
case 3:
|
||||
OB_ASSERT( mdoMultiMoleculeFile(OBTestUtil::GetFilename("cantest.sdf")) );
|
||||
break;
|
||||
default:
|
||||
cout << "Test numer " << choice << " does not exist!\n";
|
||||
return -1;
|
||||
}
|
||||
|
||||
OB_ASSERT( doMultiMoleculeFile(GetFilename("forcefield.sdf")) );
|
||||
OB_ASSERT( doMultiMoleculeFile(GetFilename("filterset.sdf")) );
|
||||
OB_ASSERT( doMultiMoleculeFile(GetFilename("cantest.sdf")) );
|
||||
// OB_ASSERT( doMultiMoleculeFile(GetFilename("cansmi-roundtrip.smi")) );
|
||||
|
||||
cout << "PASSED TESTS: " << testCount - failed << "/" << testCount << endl;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -2,56 +2,18 @@
|
||||
#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)
|
||||
|
||||
int canonstabletest(int argc, char *argv[])
|
||||
{
|
||||
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];
|
||||
@@ -59,7 +21,7 @@ int main(int argc, char **argv)
|
||||
putenv(env);
|
||||
#endif
|
||||
|
||||
std::ifstream ifs(GetFilename("canonstable.can").c_str());
|
||||
std::ifstream ifs(OBTestUtil::GetFilename("canonstable.can").c_str());
|
||||
OB_REQUIRE( ifs );
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user