This file is indexed.

/usr/include/openbabel-2.0/openbabel/parsmart.h is in libopenbabel-dev 2.3.2+dfsg-1.1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  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
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
/**********************************************************************
parsmart.h - Daylight SMARTS parser.

Copyright (C) 1998-2001 by OpenEye Scientific Software, Inc.
Some portions Copyright (C) 2001-2005 by Geoffrey R. Hutchison

This file is part of the Open Babel project.
For more information, see <http://openbabel.org/>

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation version 2 of the License.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.
***********************************************************************/

#ifndef OB_PARSMART_H
#define OB_PARSMART_H

#include <string>
#include <vector>

#include <openbabel/babelconfig.h>
#include <openbabel/mol.h>

/*==========================*/
/*  SMARTS Data Structures  */
/*==========================*/

namespace OpenBabel
{

  // mark this so that SWIG will not attempt to wrap for scripting languages

#ifndef SWIG

  //! \union _AtomExpr parsmart.h <openbabel/parsmart.h>
  //! \brief An internal (SMARTS parser) atomic expression
  typedef union _AtomExpr {
    int type;
    struct
    {
      int type;
      int prop;
      int value;
    }
      leaf;
    struct
    {
      int type;
      void *recur;
    }
      recur;
    struct
    {
      int type;
      union _AtomExpr *arg;
    }
      mon;
    struct
    {
      int type;
      union _AtomExpr *lft;
      union _AtomExpr *rgt;
    }
      bin;
  } AtomExpr;

#define BE_LEAF      0x01
#define BE_ANDHI     0x02
#define BE_ANDLO     0x03
#define BE_NOT       0x04
#define BE_OR        0x05

#define BL_CONST     0x01
#define BL_TYPE      0x02

#define BT_SINGLE     0x01
#define BT_DOUBLE     0x02
#define BT_TRIPLE     0x03
#define BT_AROM       0x04
#define BT_UP         0x05
#define BT_DOWN       0x06
#define BT_UPUNSPEC   0x07
#define BT_DOWNUNSPEC 0x08
#define BT_RING       0x09
#define BT_QUAD       0x0A //quadruple bond $

  //! \union _BondExpr parsmart.h <openbabel/parsmart.h>
  //! \brief An internal (SMARTS parser) bond expression
  typedef union _BondExpr {
    int type;
    struct
    {
      int type;
      int prop;
      int value;
    }
      leaf;
    struct
    {
      int type;
      union _BondExpr *arg;
    }
      mon;
    struct
    {
      int type;
      union _BondExpr *lft;
      union _BondExpr *rgt;
    }
      bin;
  } BondExpr;

  //! \struct BondSpec parsmart.h <openbabel/parsmart.h>
  //! \brief An internal (SMARTS parser) bond specification
  typedef struct
  {
    BondExpr *expr;
    int src,dst;
    int visit;
    bool grow;
  }
  BondSpec;

  //! \struct AtomSpec parsmart.h <openbabel/parsmart.h>
  //! \brief An internal (SMARTS parser) atom specification
  typedef struct
  {
    AtomExpr *expr;
    int visit;
    int part;
    int chiral_flag;
    int vb;
  }
  AtomSpec;

  //! \struct Pattern parsmart.h <openbabel/parsmart.h>
  //! \brief A SMARTS parser internal pattern
  typedef struct
  {
    int aalloc,acount;
    int balloc,bcount;
    bool ischiral;
    AtomSpec *atom;
    BondSpec *bond;
    int parts;
    bool hasExplicitH;
    std::vector<int> bond_parse_order; // Used to recover the order in which bonds were parsed
  }
  Pattern;

  //! \struct ParseState parsmart.h <openbabel/parsmart.h>
  //! \brief A SMARTS parser internal state
  typedef struct
  {
    BondExpr *closord[100];
    int       closure[100];
    int       closindex;
  } ParseState;

#else
  // for SWIG, just forward declare that we have some Pattern struct
  // (but this is private and not wrapped for scripting languages)
  struct Pattern;
#endif

  //! Internal class for extending OBSmartsPattern
  class OBSmartsPrivate;

  ///@addtogroup substructure Substructure Searching
  ///@{

  // class introduction in parsmart.cpp
  //! \brief SMARTS (SMiles ARbitrary Target Specification) substructure searching
  class OBAPI OBSmartsPattern
  {
  protected:
    OBSmartsPrivate                *_d;        //!< Internal data storage for future expansion
    std::vector<bool>          		  _growbond; //!< \deprecated (Not used)
    std::vector<std::vector<int> >	_mlist;    //!< The list of matches
    Pattern                        *_pat;      //!< The parsed SMARTS pattern
    std::string				              _str;      //!< The string of the SMARTS expression

    char *_buffer;
    char *LexPtr;
    char *MainPtr;

    Pattern *ParseSMARTSPattern( void );
    Pattern *ParseSMARTSPart( Pattern*, int );
    Pattern *SMARTSError( Pattern *pat );
    Pattern *ParseSMARTSError( Pattern *pat, BondExpr *expr );
    AtomExpr *ParseSimpleAtomPrimitive( void );
    AtomExpr *ParseComplexAtomPrimitive( void );
    AtomExpr *ParseAtomExpr( int level );
    BondExpr *ParseBondPrimitive( void );
    BondExpr *ParseBondExpr( int level );
    Pattern *ParseSMARTSString( char *ptr );
    Pattern *ParseSMARTSRecord( char *ptr );
    int GetVectorBinding();
    Pattern *SMARTSParser( Pattern *pat, ParseState *stat,
                           int prev, int part );

  public:
  OBSmartsPattern() : _pat(NULL), _buffer(NULL), LexPtr(NULL), MainPtr(NULL) { }
    virtual ~OBSmartsPattern();

  OBSmartsPattern(const OBSmartsPattern& cp): _pat(NULL), _buffer(NULL), LexPtr(NULL), MainPtr(NULL)
      {
        *this = cp;
      }

    OBSmartsPattern& operator=(const OBSmartsPattern& cp)
      {
        if (this == &cp)
          return *this;

        if (_pat)
          delete[] _pat;
        if (_buffer)
          delete[] _buffer;
        _buffer = NULL;
        _pat = NULL;
        std::string s = cp._str;
        Init(s);
        return (*this);
      }


    //! \name Initialization Methods
    //@{
    //! Parse the @p pattern SMARTS string.
    //! \return Whether the pattern is a valid SMARTS expression
    bool         Init(const char* pattern);
    //! Parse the @p pattern SMARTS string.
    //! \return Whether the pattern is a valid SMARTS expression
    bool         Init(const std::string& pattern);
    //@}

    //! \name Pattern Properties
    //@{
    //! \return the SMARTS string which is currently used
    const std::string &GetSMARTS() const    {      return _str;    }
    //! \return the SMARTS string which is currently used
#ifndef SWIG    
    std::string  &GetSMARTS()               {      return _str;    }
#endif
    //! \return If the SMARTS pattern is an empty expression (e.g., invalid)
    bool         Empty() const     {      return(_pat == NULL);    }
    //! \return If the SMARTS pattern is a valid expression
    bool         IsValid() const   {      return(_pat != NULL);    }

    //! \return the number of atoms in the SMARTS pattern
    unsigned int NumAtoms()   const
    {
      return _pat ? _pat->acount : 0;
    }
    //! \return the number of bonds in the SMARTS pattern
    unsigned int NumBonds()   const
    {
      return _pat ? _pat->bcount : 0;
    }

    //! Access the bond @p idx in the internal pattern
    //! \param src The index of the beginning atom
    //! \param dst The index of the end atom
    //! \param ord The bond order of this bond
    //! \param idx The index of the bond in the SMARTS pattern
    void         GetBond(int& src,int& dst,int& ord,int idx);
    //! \return the atomic number of the atom @p idx in the internal pattern
    int          GetAtomicNum(int idx);
    //! \return the formal charge of the atom @p idx in the internal pattern
    int          GetCharge(int idx);

    //! \return the vector binding of the atom @p idx in the internal pattern
    int          GetVectorBinding(int idx) const
    {
      return(_pat->atom[idx].vb);
    }
    //@}

    // number and kind of matches to return
    enum MatchType {All, Single, AllUnique};

    //! \name Matching methods (SMARTS on a specific OBMol)
    //@{
    //! Perform SMARTS matching for the pattern specified using Init().
    //! \param mol The molecule to use for matching
    //! \param single Whether only a single match is required (faster). Default is false.
    //! \return Whether matches occurred
    bool Match(OBMol &mol, bool single=false);

    //! \name Matching methods (SMARTS on a specific OBMol)
    //@{
    //! Perform SMARTS matching for the pattern specified using Init().
    //! This version is (more) thread safe.
    //! \param mol The molecule to use for matching
    //! \param mlist The resulting match list
    //! \param mtype The match type to use. Default is All.
    //! \return Whether matches occurred
    bool Match(OBMol &mol, std::vector<std::vector<int> > & mlist, MatchType mtype = All) const;

    //! \name Matching methods (SMARTS on a specific OBMol)
    //@{
    //! Thread safe check for any SMARTS match
    //! \param mol The molecule to use for matching
    //! \return Whether there exists any match
    bool HasMatch(OBMol &mol) const;

    bool RestrictedMatch(OBMol &mol, std::vector<std::pair<int,int> > &pairs, bool single=false);

    bool RestrictedMatch(OBMol &mol, OBBitVec &bv, bool single=false);
    //! \return the number of non-unique SMARTS matches
    //! To get the number of unique SMARTS matches, query GetUMapList()->size()
    unsigned int NumMatches() const
    {
      return static_cast<unsigned int>(_mlist.size());
    }

    //! \return the entire list of non-unique matches for this pattern
    //! \see GetUMapList()
    std::vector<std::vector<int> > &GetMapList()
      {
        return(_mlist);
      }
    //! \return An iterator over the (non-unique) match list, starting at the beginning
    std::vector<std::vector<int> >::iterator BeginMList()
      {
        return(_mlist.begin());
      }
    //! \return An iterator over the non-unique match list, set to the end
    std::vector<std::vector<int> >::iterator EndMList()
      {
        return(_mlist.end());
      }

    //! \return the entire list of unique matches for this pattern
    /**
       A unique match is defined as one which does not cover the
       identical atoms that a previous match has covered.

       For instance, the pattern [OD1]~C~[OD1] describes a
       carboxylate group. This pattern will match both atom number
       permutations of the carboxylate, and if GetMapList() is called, both
       matches will be returned. If GetUMapList() is called only unique
       matches of the pattern will be returned.
    **/
    std::vector<std::vector<int> > &GetUMapList();
    //@}

    //! Debugging -- write a list of matches to the output stream
    void         WriteMapList(std::ostream&);
  };

  ///@}

  //! \class OBSmartsMatcher parsmart.h <openbabel/parsmart.h>
  //! \brief Internal class: performs matching; a wrapper around previous
  //! C matching code to make it thread safe.
  class OBAPI OBSmartsMatcher
  {
  protected:
	  //recursive smarts cache
	  std::vector<std::pair<const Pattern*,std::vector<bool> > > RSCACHE;
	  // list of fragment patterns (e.g., (*).(*)
	  std::vector<const Pattern*> Fragments;
    /*
      bool EvalAtomExpr(AtomExpr *expr,OBAtom *atom);
      bool EvalBondExpr(BondExpr *expr,OBBond *bond);
      int GetVectorBinding();
      int CreateAtom(Pattern*,AtomExpr*,int,int vb=0);
    */
    bool EvalAtomExpr(AtomExpr *expr,OBAtom *atom);
    bool EvalBondExpr(BondExpr *expr,OBBond *bond);
    void SetupAtomMatchTable(std::vector<std::vector<bool> > &ttab,
	                           const Pattern *pat, OBMol &mol);
    void FastSingleMatch(OBMol &mol,const Pattern *pat,
                         std::vector<std::vector<int> > &mlist);

    friend class OBSSMatch;
  public:
    OBSmartsMatcher() {}
    virtual ~OBSmartsMatcher() {}

    bool match(OBMol &mol, const Pattern *pat,std::vector<std::vector<int> > &mlist,bool single=false);

  };

  //! \class OBSSMatch parsmart.h <openbabel/parsmart.h>
  //! \brief Internal class: performs fast, exhaustive matching used to find
  //! just a single match in match() using recursion and explicit stack handling.
  class OBAPI OBSSMatch
  {
  protected:
    bool        *_uatoms;
    OBMol       *_mol;
    const Pattern     *_pat;
    std::vector<int>  _map;

  public:
    OBSSMatch(OBMol&,const Pattern*);
    ~OBSSMatch();
    void Match(std::vector<std::vector<int> > &v, int bidx=-1);
  };

  OBAPI void SmartsLexReplace(std::string &,
                              std::vector<std::pair<std::string,std::string> > &);

} // end namespace OpenBabel

#endif // OB_PARSMART_H

//! \file parsmart.h
//! \brief Daylight SMARTS parser.