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
|
/**********************************************************************
Copyright (C) 1998-2001 by OpenEye Scientific Software, Inc.
Some portions Copyright (c) 2001-2002 by Geoffrey R. Hutchison
This file is part of the Open Babel project.
For more information, see <http://openbabel.sourceforge.net/>
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_BASE_H
#define OB_BASE_H
#include <vector>
#include <iostream>
namespace OpenBabel
{
class OBBase;
class OBNodeBase;
class OBEdgeBase;
class OBGraphBase;
//
//Base Classes
//
class OBBase
{
public:
};
class OBNodeBase : public OBBase
{
protected:
unsigned short int _idx;
OBGraphBase *_parent;
std::vector<OBEdgeBase*> _vbond;
public:
bool Visit;
OBNodeBase() {Visit = false;}
virtual ~OBNodeBase() {}
void SetIdx(int idx) {_idx = idx;}
void AddEdge(OBEdgeBase *b) {_vbond.push_back(b);}
void SetParent(OBGraphBase*);
virtual int GetFormalCharge() const {((OBNodeBase*)this)->Error(1); return(0);}
virtual unsigned int GetIdx() const {return(_idx);}
virtual unsigned int ExplicitHydrogenCount() const {((OBNodeBase*)this)->Error(22); return(0);}
virtual unsigned int ImplicitHydrogenCount() const {((OBNodeBase*)this)->Error(22); return(0);}
virtual unsigned int GetImplicitValence() const {((OBNodeBase*)this)->Error(3); return(0);}
virtual unsigned int GetValence() const {return(_vbond.size());}
virtual unsigned int GetHvyValence() const {((OBNodeBase*)this)->Error(4);return(0);}
virtual unsigned int KBOSum() const {((OBNodeBase*)this)->Error(5);return(0);}
virtual unsigned int GetHyb() const {((OBNodeBase*)this)->Error(6);return(0);}
virtual unsigned int MemberOfRingCount() const {((OBNodeBase*)this)->Error(7);return(0);}
virtual unsigned int GetAtomicNum() const {((OBNodeBase*)this)->Error(8);return(0);}
virtual void SetMatch(OBNodeBase*) {}
virtual void SetAromatic() {}
virtual bool IsInRingSize(int) const {((OBNodeBase*)this)->Error(9);return(false);}
virtual bool IsAromatic() const {((OBNodeBase*)this)->Error(10);return(false);}
virtual bool IsInRing() const {((OBNodeBase*)this)->Error(11);return(false);}
virtual bool Eval(OBNodeBase*) const {((OBNodeBase*)this)->Error(12);return(false);}
virtual bool IsConnected(OBNodeBase*);
virtual OBNodeBase *GetMatch() {((OBNodeBase*)this)->Error(13); return(NULL);}
virtual OBGraphBase *GetParent() {return(_parent);}
OBEdgeBase *Begin(std::vector<OBEdgeBase*>::iterator&);
OBEdgeBase *Next(std::vector<OBEdgeBase*>::iterator&);
OBNodeBase *BeginNbr(std::vector<OBEdgeBase*>::iterator&);
OBNodeBase *NextNbr(std::vector<OBEdgeBase*>::iterator&);
void Error(int f) {std::cerr << "atom vf called = " << f << std::endl;}
};
class OBEdgeBase : public OBBase
{
protected:
unsigned short int _idx;
OBNodeBase *_bgn;
OBNodeBase *_end;
OBGraphBase *_parent;
public:
bool Visit;
OBEdgeBase() {Visit = false; _bgn = _end = NULL;}
OBEdgeBase(OBNodeBase *bgn,OBNodeBase *end) {}
virtual ~OBEdgeBase() {}
virtual void SetClosure() {}
virtual bool IsAromatic() const {((OBEdgeBase*)this)->Error(1); return(false);}
virtual bool IsInRing() const {((OBEdgeBase*)this)->Error(2); return(false);}
virtual bool IsClosure() {((OBEdgeBase*)this)->Error(3); return(false);}
virtual bool Eval(OBEdgeBase*) {((OBEdgeBase*)this)->Error(4); return(false);}
virtual unsigned int GetBO() const {((OBEdgeBase*)this)->Error(5); return(0);}
virtual OBGraphBase* GetParent() {return(_parent);}
unsigned int GetIdx() {return(_idx);}
void SetIdx(int idx) {_idx = idx;}
void SetEnd(OBNodeBase *n) {_end = n;}
void SwapEnds() {std::swap(_bgn,_end);}
void SetParent(OBGraphBase*);
OBNodeBase *GetBgn() {return(_bgn);}
OBNodeBase *GetEnd() {return(_end);}
void Error(int f) {std::cerr << "bond vf err = " << f << std::endl;}
};
class OBGraphBase : public OBBase
{
protected:
bool _vlock;
std::vector<OBNodeBase*> _vatom;
std::vector<OBEdgeBase*> _vbond;
public:
OBGraphBase()
{
_vlock = false;
_vatom.clear();
_vbond.clear();
}
OBGraphBase(const OBGraphBase &src)
{
}
virtual ~OBGraphBase() {}
unsigned int NumNodes() {return(_vatom.empty() ? 0 : _vatom.size());}
unsigned int NumEdges() {return(_vbond.empty() ? 0 : _vbond.size());}
void ResetVisitFlags();
bool SetVisitLock(bool);
bool GetVisitLock() {return(_vlock);}
OBNodeBase *Begin(std::vector<OBNodeBase*>::iterator&);
OBNodeBase *Next(std::vector<OBNodeBase*>::iterator&);
OBEdgeBase *Begin(std::vector<OBEdgeBase*>::iterator&);
OBEdgeBase *Next(std::vector<OBEdgeBase*>::iterator&);
//substructure search functions
virtual bool SingleMatch() const {return(false);}
virtual void SetSingleMatch(bool) {}
virtual bool FinishedMatch() const {return(false);}
virtual void SetFinishedMatch(bool) {}
virtual void ClearMatches() {}
virtual void PushBack(std::vector<OBNodeBase*>&) {}
virtual void PrepForMatch() {}
virtual std::vector<std::pair<OBNodeBase*,std::vector<OBEdgeBase*> > >::iterator BgnMatch()
{return((std::vector<std::pair<OBNodeBase*,std::vector<OBEdgeBase*> > >::iterator) NULL);}
virtual std::vector<std::pair<OBNodeBase*,std::vector<OBEdgeBase*> > >::iterator EndMatch()
{return((std::vector<std::pair<OBNodeBase*,std::vector<OBEdgeBase*> > >::iterator) NULL);}
virtual OBNodeBase *GetFirstSeed() {return((OBNodeBase*)NULL);}
bool Match(OBGraphBase &,bool singleMatch=false);
bool Match(OBGraphBase &,
std::vector<std::pair<OBNodeBase*,std::vector<OBEdgeBase*> > >::iterator,
std::vector<OBEdgeBase*>::iterator);
};
} //namespace OpenBabel
#endif // OB_BASE_H
|