1
/**********************************************************************
2
smilesmatch.cpp - Test SMARTS matching (i.e., SMILES matching themselves)
4
This file is part of the Open Babel project.
5
For more information, see <http://openbabel.sourceforge.net/>
7
Copyright (C) 1998-2001 by OpenEye Scientific Software, Inc.
8
Some portions Copyright (C) 2001-2005 Geoffrey R. Hutchison
10
This program is free software; you can redistribute it and/or modify
11
it under the terms of the GNU General Public License as published by
12
the Free Software Foundation version 2 of the License.
14
This program is distributed in the hope that it will be useful,
15
but WITHOUT ANY WARRANTY; without even the implied warranty of
16
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
GNU General Public License for more details.
18
***********************************************************************/
20
// used to set import/export for Cygwin DLLs
25
#include <openbabel/babelconfig.h>
29
#include <openbabel/mol.h>
30
#include <openbabel/obconversion.h>
34
bool SafeOpen(std::ifstream &fs, const char *filename);
35
bool SafeOpen(std::ofstream &fs, const char *filename);
39
using namespace OpenBabel;
42
string testdatadir = TESTDATADIR;
43
string smilestypes_file = testdatadir + "nci.smi";
45
string smilestypes_file = "nci.smi";
48
int main(int argc,char *argv[])
50
// turn off slow sync with C-style output (we don't use it anyway).
51
std::ios::sync_with_stdio(false);
55
cout << "Usage: smilesmatch\n";
56
cout << " Tests Open Babel SMILES/SMARTS pattern matching." << endl;
60
cout << endl << "# Testing SMILES self-matching using SMARTS... \n";
63
if (!SafeOpen(mifs, smilestypes_file.c_str()))
65
cout << "Bail out! Cannot read test data " << smilestypes_file << endl;
66
return -1; // test failed
69
OBConversion conv(&mifs, &cout);
70
if (! conv.SetInAndOutFormats("SMI","SMI"))
72
cout << "Bail out! SMILES format is not loaded" << endl;
76
unsigned int currentMol = 0;
77
OBSmartsPattern smarts;
81
//read in molecules and see if their SMARTS matches themselves
82
while (getline(mifs, buffer))
85
conv.ReadString(&mol, buffer);
89
// trim off any title, etc.
90
string::size_type pos = buffer.find_first_of(" \t\n\r");
91
if (pos != string::npos)
94
pos = buffer.find_first_of('.');
95
if (pos != string::npos)
99
if (smarts.Match(mol))
100
cout << "ok " << ++currentMol << " # SMARTS matched the"
101
<< " SMILES molecule\n";
103
cout << "not ok " << ++currentMol << " # SMARTS did not match"
104
<< " for molecule " << buffer << "\n";
107
// output the number of tests run
108
cout << "1.." << currentMol << endl;