OpenStructure
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
entity_impl.hh
Go to the documentation of this file.
1 //------------------------------------------------------------------------------
2 // This file is part of the OpenStructure project <www.openstructure.org>
3 //
4 // Copyright (C) 2008-2011 by the OpenStructure authors
5 //
6 // This library is free software; you can redistribute it and/or modify it under
7 // the terms of the GNU Lesser General Public License as published by the Free
8 // Software Foundation; either version 3.0 of the License, or (at your option)
9 // any later version.
10 // This library is distributed in the hope that it will be useful, but WITHOUT
11 // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12 // FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
13 // details.
14 //
15 // You should have received a copy of the GNU Lesser General Public License
16 // along with this library; if not, write to the Free Software Foundation, Inc.,
17 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 //------------------------------------------------------------------------------
19 #ifndef OST_ENTITY_IMPL_HH
20 #define OST_ENTITY_IMPL_HH
21 
22 #include <map>
23 #include <vector>
24 
25 #include <boost/enable_shared_from_this.hpp>
26 
27 #include <ost/mol/module_config.hh>
28 #include <ost/geom/geom.hh>
29 
31 
32 #include <ost/mol/entity_view.hh>
33 
34 #include <ost/mol/residue_prop.hh>
44 #include <ost/mol/entity_view.hh>
45 #include <ost/mol/entity_handle.hh>
47 
48 
49 #include <ost/generic_property.hh>
50 
51 namespace ost { namespace mol { namespace impl {
52 
54 typedef std::map<AtomImpl*,AtomImplPtr> AtomImplMap;
56 typedef std::map<ResidueImpl*,ResidueImplPtr> ResidueImplMap;
58 typedef std::vector<ChainImplPtr> ChainImplList;
60 typedef std::map<ConnectorImpl*,ConnectorImplP> ConnectorImplMap;
62 typedef std::map<TorsionImpl*,TorsionImplP> TorsionImplMap;
64 typedef std::vector<FragmentImplP> FragmentImplList;
66 typedef std::map<EntityObserver*,EntityObserverPtr> EntityObserverMap;
69 
71 typedef enum {
74  // dirty trace (implies dirty ICS)
79 
80 
83  public boost::enable_shared_from_this<EntityImpl>
84 {
85 public:
86  EntityImpl();
87  ~EntityImpl();
88 
91 
92  Real GetMass() const;
97 
98 
99 
100  // default copy ctor and assignment op should work for now
101  AtomImplPtr CreateAtom(const ResidueImplPtr& rp, const String& name,
102  const geom::Vec3& pos, const String& ele);
103 
105  const ResNum& n,
106  const ResidueKey& k);
107 
108  ChainImplPtr InsertChain(const String& cname);
112  // force deep to be set explicitely, because it is better than implicit
113  // (and since we are on the impl level interface consistency isn't that critical)
114  ChainImplPtr InsertChain(const String& chain_name, const ChainImplPtr& chain, bool deep);
115  ConnectorImplP Connect(const AtomImplPtr& first, const AtomImplPtr& second,
116  Real len, Real theta, Real phi,
117  unsigned char bond_order);
118 
119  TorsionImplP AddTorsion(const String& name, const AtomImplPtr& a1,
120  const AtomImplPtr& a2, const AtomImplPtr& a3,
121  const AtomImplPtr& a4);
122 
123  void TraceDirectionality();
124 
127  const AtomImplPtr& a2,
128  const AtomImplPtr& a3,
129  const AtomImplPtr& a4) const;
130 
131  void RenameChain(ChainImplPtr chain, const String& new_name);
132  bool SetAngle(const AtomImplPtr& a1, const AtomImplPtr& a2,
133  const AtomImplPtr& a3, Real angle);
134 
135  Real GetAngle(const AtomImplPtr& a1, const AtomImplPtr& a2,
136  const AtomImplPtr& a3) const;
137  Real GetAngleXCS(const AtomImplPtr& a1, const AtomImplPtr& a2,
138  const AtomImplPtr& a3) const;
139  Real GetAngleICS(const AtomImplPtr& a1, const AtomImplPtr& a2,
140  const AtomImplPtr& a3) const;
141  // update positions from internal coordinate system
142  void UpdateFromICS();
143 
144  // update internal coordinate system from positions
145  void UpdateFromXCS();
146 
147  void Apply(EntityVisitor& v);
148  void ApplyTransform(const geom::Transform& t);
149 
150  void SetTransform(const geom::Transform& t);
151  const geom::Transform& GetTransform() const {return transform_;}
152  bool HasTransform() const {return has_transform_;}
153  void ClearTransform();
154  void FixTransform();
155 
156  void AttachObserver(const EntityObserverPtr& o);
157  void DetachObserver(const EntityObserverPtr& o);
158  void NotifyObserver();
159 
160 
161  void UpdateOrganizer();
162 
163  AtomImplList FindWithin(const geom::Vec3& pos, Real radius) const;
164  // use query flag defaults
165  EntityView Select(const EntityHandle& h, const Query& q) const;
166  // override query flag defaults with given flags
167  EntityView Select(const EntityHandle& h, const Query& q,
168  QueryFlags flags) const;
169  EntityView CreateFullView(const EntityHandle& h) const;
170  void SetDefaultQueryFlags(QueryFlags f) {default_query_flags_=f;}
171  QueryFlags GetDefaultQueryFlags() const {return default_query_flags_;}
172 
173 
176  ChainImplPtr FindChain(const String& name) const;
177 
178  ResidueImplPtr FindResidue(const String& chain_name,
179  const ResNum& residue) const;
180 
181  AtomImplPtr FindAtom(const String& chain_name,
182  const ResNum& residue,
183  const String& atom_name) const;
184  /*
185  this is a deep-swap which will exchange the internal structure
186  of two implementations, which by design affects _all_ entity handles
187  that point two either of these two implementations
188  */
189  void Swap(EntityImpl& impl);
190 
192  int GetAtomCount() const;
193 
195  int GetBondCount() const;
196 
199 
200 
202  int GetResidueCount() const;
203 
205  int GetChainCount() const;
206 
207  const ChainImplList& GetChainList() const { return chain_list_; }
208 
209  ChainImplList& GetChainList() { return chain_list_; }
210 
211  void DeleteFromConnMap(const ConnectorImplP& conn);
212 
213  void DeleteChain(const ChainImplPtr& chain);
214 
215  void DeleteAtom(const AtomImplPtr& atom);
216 
217  void IncXCSEditorCount();
218  void DecXCSEditorCount();
219 
220  void IncICSEditorCount();
221  void DecICSEditorCount();
222 
224 
225  void UpdateXCSIfNeeded();
226 
227  void UpdateICSIfNeeded();
228 
230 
231  void EnableICS();
232 
233  bool HasICS() const;
234 
235  bool IsXCSDirty() const;
236 
237  void MarkXCSDirty();
238  void MarkICSDirty();
239  void MarkTraceDirty();
240  void MarkOrganizerDirty();
241 
242  void UpdateTransformedPos();
243 
244  const String& GetName() const;
245 
246  impl::ChainImplList::iterator GetChain(const String& name);
247 
249  void SetName(const String& ent_name);
250 
251  void ReorderAllResidues();
252 
253  void RenumberAllResidues(int start, bool keep_spacing);
254 
255  void RenumberChain(const String& name, int start, bool keep_spacing);
256 
257 private:
258  void DoCopy(EntityImplPtr dest);
259 
260  void ReplicateHierarchy(EntityImplPtr dest);
261 
262  void DoCopyBondsAndTorsions(EntityImplPtr dest);
263 
264  AtomImplMap atom_map_;
265  ChainImplList chain_list_;
266  ConnectorImplMap connector_map_;
267  TorsionImplMap torsion_map_;
268 
269  geom::Transform transform_;
270  bool has_transform_;
271 
272  SpatialAtomOrganizer atom_organizer_;
273  FragmentImplList fragment_list_;
274  EntityObserverMap observer_map_;
275 
276  int xcs_editor_count_;
277  int ics_editor_count_;
278  int dirty_flags_;
279  String name_;
280 
281  unsigned long next_index_;
282 
283  QueryFlags default_query_flags_;
284 
285  template <bool always_true>
286  EntityView do_selection(const EntityHandle&, const Query&, QueryFlags) const;
287 };
288 
289 }}} // ns
290 
291 #endif