~ubuntu-branches/debian/stretch/openbabel/stretch

« back to all changes in this revision

Viewing changes to test/smilesmatch.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Michael Banck
  • Date: 2008-07-22 23:54:58 UTC
  • mfrom: (3.1.10 intrepid)
  • Revision ID: james.westby@ubuntu.com-20080722235458-3o606czluviz4akx
Tags: 2.2.0-2
* Upload to unstable.
* debian/control: Updated descriptions.
* debian/patches/gauss_cube_format.patch: New patch, makes the 
  gaussian cube format available again.
* debian/rules (DEB_DH_MAKESHLIBS_ARGS_libopenbabel3): Removed.
* debian/rules (DEB_CONFIGURE_EXTRA_FLAGS): Likewise.
* debian/libopenbabel3.install: Adjust formats directory to single 
  version hierarchy.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 /**********************************************************************
 
2
 smilesmatch.cpp - Test SMARTS matching (i.e., SMILES matching themselves)
 
3
 
 
4
 This file is part of the Open Babel project.
 
5
 For more information, see <http://openbabel.sourceforge.net/>
 
6
 
 
7
 Copyright (C) 1998-2001 by OpenEye Scientific Software, Inc.
 
8
 Some portions Copyright (C) 2001-2005 Geoffrey R. Hutchison
 
9
 
 
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.
 
13
 
 
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
 ***********************************************************************/
 
19
 
 
20
// used to set import/export for Cygwin DLLs
 
21
#ifdef WIN32
 
22
#define USING_OBDLL
 
23
#endif
 
24
 
 
25
#include <openbabel/babelconfig.h>
 
26
 
 
27
#include <fstream>
 
28
 
 
29
#include <openbabel/mol.h>
 
30
#include <openbabel/obconversion.h>
 
31
 
 
32
namespace OpenBabel
 
33
{
 
34
  bool SafeOpen(std::ifstream &fs, const char *filename);
 
35
  bool SafeOpen(std::ofstream &fs, const char *filename);
 
36
}
 
37
 
 
38
using namespace std;
 
39
using namespace OpenBabel;
 
40
 
 
41
#ifdef TESTDATADIR
 
42
  string testdatadir = TESTDATADIR;
 
43
  string smilestypes_file = testdatadir + "nci.smi";
 
44
#else
 
45
   string smilestypes_file = "nci.smi";
 
46
#endif
 
47
 
 
48
int main(int argc,char *argv[])
 
49
{
 
50
  // turn off slow sync with C-style output (we don't use it anyway).
 
51
  std::ios::sync_with_stdio(false);
 
52
 
 
53
  if (argc != 1)
 
54
    {
 
55
      cout << "Usage: smilesmatch\n";
 
56
      cout << "   Tests Open Babel SMILES/SMARTS pattern matching." << endl;
 
57
      return 0;
 
58
    }
 
59
  
 
60
  cout << endl << "# Testing SMILES self-matching using SMARTS...  \n";
 
61
  
 
62
  std::ifstream mifs;
 
63
  if (!SafeOpen(mifs, smilestypes_file.c_str()))
 
64
    {
 
65
      cout << "Bail out! Cannot read test data " << smilestypes_file << endl;
 
66
      return -1; // test failed
 
67
    }
 
68
 
 
69
  OBConversion conv(&mifs, &cout);
 
70
  if (! conv.SetInAndOutFormats("SMI","SMI"))
 
71
    {
 
72
      cout << "Bail out! SMILES format is not loaded" << endl;
 
73
      return -1;
 
74
    }
 
75
 
 
76
  unsigned int currentMol = 0;
 
77
  OBSmartsPattern smarts;
 
78
  OBMol mol;
 
79
  string buffer;
 
80
 
 
81
  //read in molecules and see if their SMARTS matches themselves
 
82
  while (getline(mifs, buffer))
 
83
    {
 
84
      mol.Clear();
 
85
      conv.ReadString(&mol, buffer);
 
86
      if (mol.Empty())
 
87
        continue;
 
88
 
 
89
      // trim off any title, etc.
 
90
      string::size_type pos = buffer.find_first_of(" \t\n\r");
 
91
      if (pos != string::npos)
 
92
        buffer.erase(pos);
 
93
 
 
94
      pos = buffer.find_first_of('.');
 
95
      if (pos != string::npos)
 
96
        continue;
 
97
 
 
98
      smarts.Init(buffer);
 
99
      if (smarts.Match(mol))
 
100
        cout << "ok " << ++currentMol << " # SMARTS matched the"
 
101
             << " SMILES molecule\n";
 
102
      else
 
103
        cout << "not ok " << ++currentMol << " # SMARTS did not match"
 
104
             << " for molecule " << buffer << "\n";
 
105
    }
 
106
 
 
107
  // output the number of tests run
 
108
  cout << "1.." << currentMol << endl;
 
109
 
 
110
  // Passed Test
 
111
  return 0;
 
112
}