smilesParser.h

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