00001
00002
00003
00004
00005 #ifndef BALL_STRUCTURE_KEKULIZER_H
00006 #define BALL_STRUCTURE_KEKULIZER_H
00007
00008 #ifndef BALL_COMMON_H
00009 # include <BALL/common.h>
00010 #endif
00011
00012 #ifndef BALL_DATATYPE_HASHMAP_H
00013 # include <BALL/DATATYPE/hashMap.h>
00014 #endif
00015
00016 #include <set>
00017
00018 namespace BALL
00019 {
00020 class Atom;
00021 class Molecule;
00022 class Bond;
00023
00037 class BALL_EXPORT Kekuliser
00038 {
00040 struct BALL_EXPORT AtomInfo
00041 {
00042
00043 bool operator < (const AtomInfo& info) const;
00044 AtomInfo& operator = (const AtomInfo& ai) ;
00045
00046
00047 Atom* atom;
00048
00049
00050 Bond* double_bond;
00051
00052
00053 std::vector<Bond*> abonds;
00054
00055
00056 std::vector<Position> partner_id;
00057
00058
00059 Index curr_double;
00060
00061
00062 Index min_double;
00063
00064
00065 Index max_double;
00066
00067
00068 Index uncharged_double;
00069 };
00070
00071 public:
00072
00073 BALL_CREATE(Kekuliser)
00074
00075
00076 Kekuliser();
00077
00079 virtual ~Kekuliser() {}
00080
00082 bool setup(Molecule& ac);
00083
00085 void setAromaticRings(const std::vector<std::set<Atom*> >& rings) { aromatic_rings_ = rings;}
00086
00088 void setRings(const std::vector<std::set<Atom*> >& rings) { rings_ = rings;}
00089
00091 const std::vector<Bond*>& getUnassignedBonds() const { return unassigned_bonds_; }
00092
00094 void clear();
00095
00097 void dump();
00098
00100 void setUseFormalCharges(bool state) { use_formal_charges_ = state;}
00101
00103 bool useFormalCharges() const { return use_formal_charges_;}
00104
00105 protected:
00106
00107 bool fixAromaticRings_();
00108 void fixAromaticSystem_(Position it);
00109 virtual Size getPenalty_(Atom& atom, Index charge);
00110
00111 void getMaximumValence_();
00112
00113
00114 void calculateAromaticSystems_();
00115 void collectSystems_(Atom& atom);
00116 void collectAromaticAtoms_();
00117 bool hasAromaticBonds_(Atom& atom);
00118 void applySolution_(Position pos);
00119 Position calculateDistanceScores_();
00120
00121 bool use_formal_charges_;
00122
00123 std::vector<std::set<Atom*> > aromatic_systems_;
00124 std::vector<std::set<Atom*> > aromatic_rings_;
00125 std::vector<std::set<Atom*> > rings_;
00126 std::vector<Bond*> unassigned_bonds_;
00127
00128
00129 std::set<const Atom*> aromatic_atoms_;
00130 std::set<const Atom*> all_aromatic_atoms_;
00131 HashMap<Atom*, Index> max_valence_;
00132
00133 std::set<Atom*> current_aromatic_system_;
00134
00135
00136 std::vector<AtomInfo> atom_infos_;
00137 Molecule* molecule_;
00138 Size lowest_penalty_;
00139 Size current_penalty_;
00140
00141 std::vector<std::vector<AtomInfo> > solutions_;
00142 };
00143
00144 }
00145
00146 #endif // BALL_STRUCTURE_KEKULIZER_H