Hello,
I would suggest to use a simple program based on Indigo toolkit:
#include "molecule/molecule.h"
#include "molecule/sdf_loader.h"
#include "molecule/molfile_loader.h"
#include "base_cpp/scanner.h"
int main (int argc, char *argv[])
{
bool calc_hydro = true;
bool allow_query = false;
const char *idfield = 0;
if (argc <= 1)
{
fprintf(stderr,
"Usage: sdfcheck file.sdf [-id idfield] [-no-hydro-check] [-allow-query]\n");
return -1;
}
const char *filename = argv[1];
for (int i = 2; i < argc; i++)
{
if (strcmp(argv[i], "-id") == 0)
{
if (++i == argc)
{
fprintf(stderr, "expecting an identifier after '-id'\n");
return -1;
}
idfield = argv[i];
}
else if (strcmp(argv[i], "-no-hydro-check") == 0)
calc_hydro = false;
else if (strcmp(argv[i], "-allow-query") == 0)
allow_query = true;
else
{
fprintf(stderr, "unknown parameter: %s\n", argv[i]);
return -1;
}
}
try
{
FileScanner scanner(filename);
SdfLoader loader(scanner);
int cnt = 0;
if (idfield != 0)
loader.initProperties(idfield);
while (!loader.isEOF())
{
loader.readNext();
const char *id = 0;
if (idfield != 0 && loader.properties.at2(idfield) != 0)
id = loader.properties.at(idfield).ptr();
cnt++;
if (idfield == 0)
printf("reading molecule #%d... ", cnt);
else if (id == 0)
printf("reading molecule #%d, no %s ... ", cnt, idfield);
else
printf("reading molecule #%d, %s=%s ... ", cnt, idfield, id);
fflush(stdout);
Molecule mol;
try
{
BufferScanner molscan(loader.data);
MolfileLoader molload(molscan);
molload.loadMolecule(mol, allow_query);
if (calc_hydro)
mol.calcImplicitHydrogens();
printf("\n");
}
catch (Exception &e)
{
printf("error: %s\n", e.message());
continue;
}
}
}
catch (Exception &e)
{
printf("error: %s\n", e.message());
}
return 0;
}
The steps to compile the program on Linux are:
- Download any Indigo source package containing 'graph' and 'molecule' projects (actually, every our package has them, so you can download any of them, for example Bingo)
- Unpack bingo-src-XXXX.zip
- Go to bingo-src-XXXX folder
- Paste the above code into sdfcheck.cpp file
cd graph; make CONF=Release32; cd ..
cd molecule; make CONF=Release32; cd ..
gcc sdfcheck.cpp -o sdfcheck -O3 -m32 -I. -Icommon molecule/dist/Release32/GNU-Linux-x86/libmolecule.a graph/dist/Release32/GNU-Linux-x86/libgraph.a -lpthread -lstdc++
(In order to get a 64-bit executable, replace 32 with 64 in steps 5, 6, and 7.)
Then you can run the program like this:
./sdfcheck ~/sdf/database.sdf | grep error
or
./sdfcheck ~/sdf/database.sdf -id molregno -no-hydro-check | grep error
or
./sdfcheck ~/sdf/database.sdf -id molregno -no-hydro-check -allow-queries | grep error
With best regards,
Dmitry