00001 // -*- Mode: C++; tab-width: 2; -*- 00002 // vi: set ts=2: 00003 // 00004 // $Id: kekulizer.h,v 1.1.4.4 2007/04/22 11:46:12 amoll Exp $ 00005 // 00006 00007 #ifndef BALL_STRUCTURE_KEKULIZER_H 00008 #define BALL_STRUCTURE_KEKULIZER_H 00009 00010 #ifndef BALL_COMMON_H 00011 # include <BALL/common.h> 00012 #endif 00013 00014 #ifndef BALL_DATATYPE_HASHMAP_H 00015 # include <BALL/DATATYPE/hashMap.h> 00016 #endif 00017 00018 #include <set> 00019 00020 namespace BALL 00021 { 00022 class Atom; 00023 class Molecule; 00024 class Bond; 00025 00039 class BALL_EXPORT Kekuliser 00040 { 00042 struct BALL_EXPORT AtomInfo 00043 { 00044 // needed for sorting: 00045 bool operator < (const AtomInfo& info) const; 00046 AtomInfo& operator = (const AtomInfo& ai) ; 00047 00048 // THE atom 00049 Atom* atom; 00050 00051 // bond to be set to a double bond 00052 Bond* double_bond; 00053 00054 // aromatic bonds 00055 std::vector<Bond*> abonds; 00056 00057 // position of the partner atoms in the vector of AtomInfos 00058 std::vector<Position> partner_id; 00059 00060 // current number of double bonds for this atom 00061 Index curr_double; 00062 00063 // minumum possible number of double bonds for this atom 00064 Index min_double; 00065 00066 // maximum possible number of double bonds for this atom 00067 Index max_double; 00068 00069 // number of double bonds for this atom to be uncharged 00070 Index uncharged_double; 00071 }; 00072 00073 public: 00074 00075 BALL_CREATE(Kekuliser) 00076 00077 00078 Kekuliser(); 00079 00081 virtual ~Kekuliser() {} 00082 00084 bool setup(Molecule& ac); 00085 00087 void setAromaticRings(const std::vector<std::set<Atom*> >& rings) { aromatic_rings_ = rings;} 00088 00090 void setRings(const std::vector<std::set<Atom*> >& rings) { rings_ = rings;} 00091 00093 const std::vector<Bond*>& getUnassignedBonds() const { return unassigned_bonds_; } 00094 00096 void clear(); 00097 00099 void dump(); 00100 00102 void setUseFormalCharges(bool state) { use_formal_charges_ = state;} 00103 00105 bool useFormalCharges() const { return use_formal_charges_;} 00106 00107 protected: 00108 00109 bool fixAromaticRings_(); 00110 void fixAromaticSystem_(Position it); 00111 virtual Size getPenalty_(Atom& atom, Index charge); 00112 00113 void getMaximumValence_(); 00114 00115 // merge aromatic rings: 00116 void calculateAromaticSystems_(); 00117 void collectSystems_(Atom& atom); 00118 void collectAromaticAtoms_(); 00119 bool hasAromaticBonds_(Atom& atom); 00120 void applySolution_(Position pos); 00121 Position calculateDistanceScores_(); 00122 00123 bool use_formal_charges_; 00124 00125 std::vector<std::set<Atom*> > aromatic_systems_; 00126 std::vector<std::set<Atom*> > aromatic_rings_; 00127 std::vector<std::set<Atom*> > rings_; 00128 std::vector<Bond*> unassigned_bonds_; 00129 00130 // atoms that take part in an aromatic bond: 00131 std::set<const Atom*> aromatic_atoms_; 00132 std::set<const Atom*> all_aromatic_atoms_; 00133 HashMap<Atom*, Index> max_valence_; 00134 00135 std::set<Atom*> current_aromatic_system_; 00136 00137 // current aromatic system: 00138 std::vector<AtomInfo> atom_infos_; 00139 Molecule* molecule_; 00140 Size lowest_penalty_; 00141 Size current_penalty_; 00142 00143 std::vector<std::vector<AtomInfo> > solutions_; 00144 }; 00145 00146 } // namespace BALL 00147 00148 #endif // BALL_STRUCTURE_KEKULIZER_H