BALL  1.4.2
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
kekulizer.h
Go to the documentation of this file.
1 // -*- Mode: C++; tab-width: 2; -*-
2 // vi: set ts=2:
3 //
4 
5 #ifndef BALL_STRUCTURE_KEKULIZER_H
6 #define BALL_STRUCTURE_KEKULIZER_H
7 
8 #ifndef BALL_COMMON_H
9 # include <BALL/common.h>
10 #endif
11 
12 #ifndef BALL_DATATYPE_HASHMAP_H
13 # include <BALL/DATATYPE/hashMap.h>
14 #endif
15 
16 #include <set>
17 
18 namespace BALL
19 {
20  class Atom;
21  class Molecule;
22  class Bond;
23 
38  {
41  {
42  // needed for sorting:
43  bool operator < (const AtomInfo& info) const;
44  AtomInfo& operator = (const AtomInfo& ai) ;
45 
46  // THE atom
48 
49  // bond to be set to a double bond
51 
52  // aromatic bonds
53  std::vector<Bond*> abonds;
54 
55  // position of the partner atoms in the vector of AtomInfos
56  std::vector<Position> partner_id;
57 
58  // current number of double bonds for this atom
60 
61  // minumum possible number of double bonds for this atom
63 
64  // maximum possible number of double bonds for this atom
66 
67  // number of double bonds for this atom to be uncharged
69  };
70 
71  public:
72 
74 
75 
76  Kekuliser();
77 
79  virtual ~Kekuliser() {}
80 
82  bool setup(Molecule& ac);
83 
85  void setAromaticRings(const std::vector<std::set<Atom*> >& rings) { aromatic_rings_ = rings;}
86 
88  void setRings(const std::vector<std::set<Atom*> >& rings) { rings_ = rings;}
89 
91  const std::vector<Bond*>& getUnassignedBonds() const { return unassigned_bonds_; }
92 
94  void clear();
95 
97  void dump();
98 
100  void setUseFormalCharges(bool state) { use_formal_charges_ = state;}
101 
103  bool useFormalCharges() const { return use_formal_charges_;}
104 
105  protected:
106 
107  bool fixAromaticRings_();
108  void fixAromaticSystem_(Position it);
109  virtual Size getPenalty_(Atom& atom, Index charge);
110 
111  void getMaximumValence_();
112 
113  // merge aromatic rings:
114  void calculateAromaticSystems_();
115  void collectSystems_(Atom& atom);
116  void collectAromaticAtoms_();
117  bool hasAromaticBonds_(Atom& atom);
118  void applySolution_(Position pos);
119  Position calculateDistanceScores_();
120 
122 
123  std::vector<std::set<Atom*> > aromatic_systems_;
124  std::vector<std::set<Atom*> > aromatic_rings_;
125  std::vector<std::set<Atom*> > rings_;
126  std::vector<Bond*> unassigned_bonds_;
127 
128  // atoms that take part in an aromatic bond:
129  std::set<const Atom*> aromatic_atoms_;
130  std::set<const Atom*> all_aromatic_atoms_;
132 
133  std::set<Atom*> current_aromatic_system_;
134 
135  // current aromatic system:
136  std::vector<AtomInfo> atom_infos_;
140 
141  std::vector<std::vector<AtomInfo> > solutions_;
142  };
143 
144 } // namespace BALL
145 
146 #endif // BALL_STRUCTURE_KEKULIZER_H