00001
00002
00003
00004
00005 #ifndef BALL_STRUCTURE_SMILES_PARSER_H
00006 #define BALL_STRUCTURE_SMILES_PARSER_H
00007
00008 #ifndef BALL_COMMON_H
00009 # include <BALL/common.h>
00010 #endif
00011
00012 #ifndef BALL_KERNEL_ATOM_H
00013 # include <BALL/KERNEL/atom.h>
00014 #endif
00015
00016 #ifndef BALL_KERNEL_BOND_H
00017 # include <BALL/KERNEL/bond.h>
00018 #endif
00019
00020 #ifndef BALL_KERNEL_SYSTEM_H
00021 # include <BALL/KERNEL/system.h>
00022 #endif
00023
00024 namespace BALL
00025 {
00026
00036 class BALL_EXPORT SmilesParser
00037 {
00038 public:
00039 enum ZEIsomerType
00040 {
00041 NONE,
00042 Z,
00043 E
00044 };
00045
00046 enum ChiralClass
00047 {
00048 NONCHIRAL,
00049 TH,
00050 AL,
00051 SP,
00052 TB,
00053 OH
00054 };
00055
00056 enum
00057 {
00058 MAX_CONNECTIONS = 100
00059 };
00060
00061 typedef std::pair<ChiralClass, Position> ChiralDef;
00062
00063 class SPAtom;
00064 class SPBond
00065 : public Bond
00066 {
00067 public:
00068 virtual ~SPBond() ;
00069
00070 SPBond(SPAtom* first, SPAtom* second, Index order = 1);
00071
00072 ZEIsomerType getZEType() const;
00073 void setZEType(ZEIsomerType type);
00074
00075 protected:
00076 ZEIsomerType ze_type_;
00077 };
00078
00079 BALL_EXPORT class SPAtom
00080 : public Atom
00081 {
00082 public:
00083
00084 SPAtom(const String& symbol, bool in_brackets);
00085 virtual ~SPAtom() ;
00086
00087 Size getDefaultValence() const;
00088 Size countRealValences() const;
00089
00090 Size getIsotope() const { return isotope_; }
00091 void setIsotope(Size isotope) { isotope_ = isotope; };
00092
00093 Index getFormalCharge() const { return formal_charge_; }
00094 void setFormalCharge(Index charge) { formal_charge_ = charge; }
00095
00096 const ChiralDef& getChirality() const { return chirality_; }
00097 void setChirality(const ChiralDef& chirality) { chirality_ = chirality; }
00098
00099 bool isAromatic() const { return is_aromatic_; }
00100 void setAromatic(bool is_aromatic) { is_aromatic_ = is_aromatic; };
00101 bool isInBrackets() const { return in_brackets_; }
00102 void setInBrackets(bool in_brackets) { in_brackets_ = in_brackets; };
00103
00104 protected:
00105 Size isotope_;
00106 Index formal_charge_;
00107 ChiralDef chirality_;
00108 bool is_aromatic_;
00109 bool in_brackets_;
00110 };
00111
00112 typedef std::list<Position> ConnectionList;
00113
00117
00119 SmilesParser();
00120
00122 SmilesParser(const SmilesParser& parser);
00123
00125 virtual ~SmilesParser();
00127
00133 void parse(const String& s)
00134 throw(Exception::ParseError);
00135
00138 const System& getSystem() const;
00140
00144
00145 SPAtom* createAtom(const String& symbol, bool in_bracket = false);
00146
00148 void createBonds(SPAtom* atom, const ConnectionList* list);
00149
00151 void createBond(SPAtom* left, SPAtom* right, Index order);
00152
00154 void addMissingHydrogens();
00156
00157
00158 struct State
00159 {
00160 Size char_count;
00161 SmilesParser* current_parser;
00162 const char* buffer;
00163 };
00164
00165 static State state;
00166
00167 protected:
00168 System system_;
00169 std::vector<SPAtom*> connections_;
00170 std::vector<SPAtom*> all_atoms_;
00171 static SmilesParser* current_parser_;
00172 };
00173
00174 }
00175
00176 #endif // BALL_STRUCTURE_SMILES_PARSER_H