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 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 
155  void AttachObserver(const EntityObserverPtr& o);
156  void DetachObserver(const EntityObserverPtr& o);
157  void NotifyObserver();
158 
159 
160  void UpdateOrganizer();
161 
162  AtomImplList FindWithin(const geom::Vec3& pos, Real radius) const;
163  // use query flag defaults
164  EntityView Select(const EntityHandle& h, const Query& q) const;
165  // override query flag defaults with given flags
166  EntityView Select(const EntityHandle& h, const Query& q,
167  QueryFlags flags) const;
168  EntityView CreateFullView(const EntityHandle& h) const;
169  void SetDefaultQueryFlags(QueryFlags f) {default_query_flags_=f;}
170  QueryFlags GetDefaultQueryFlags() const {return default_query_flags_;}
171 
172 
175  ChainImplPtr FindChain(const String& name) const;
176 
177  ResidueImplPtr FindResidue(const String& chain_name,
178  const ResNum& residue) const;
179 
180  AtomImplPtr FindAtom(const String& chain_name,
181  const ResNum& residue,
182  const String& atom_name) const;
183  /*
184  this is a deep-swap which will exchange the internal structure
185  of two implementations, which by design affects _all_ entity handles
186  that point two either of these two implementations
187  */
188  void Swap(EntityImpl& impl);
189 
191  int GetAtomCount() const;
192 
194  int GetBondCount() const;
195 
198 
199 
201  int GetResidueCount() const;
202 
204  int GetChainCount() const;
205 
206  const ChainImplList& GetChainList() const { return chain_list_; }
207 
208  ChainImplList& GetChainList() { return chain_list_; }
209 
210  void DeleteFromConnMap(const ConnectorImplP& conn);
211 
212  void DeleteChain(const ChainImplPtr& chain);
213 
214  void DeleteAtom(const AtomImplPtr& atom);
215 
216  void IncXCSEditorCount();
217  void DecXCSEditorCount();
218 
219  void IncICSEditorCount();
220  void DecICSEditorCount();
221 
223 
224  void UpdateXCSIfNeeded();
225 
226  void UpdateICSIfNeeded();
227 
229 
230  void EnableICS();
231 
232  bool HasICS() const;
233 
234  bool IsXCSDirty() const;
235 
236  void MarkXCSDirty();
237  void MarkICSDirty();
238  void MarkTraceDirty();
239  void MarkOrganizerDirty();
240 
241  void UpdateTransformedPos();
242 
243  const String& GetName() const;
244 
245  impl::ChainImplList::iterator GetChain(const String& name);
246 
248  void SetName(const String& ent_name);
249 
250  void ReorderAllResidues();
251 
252  void RenumberAllResidues(int start, bool keep_spacing);
253 
254 private:
255  void DoCopy(EntityImplPtr dest);
256 
257  void ReplicateHierarchy(EntityImplPtr dest);
258 
259  void DoCopyBondsAndTorsions(EntityImplPtr dest);
260 
261  AtomImplMap atom_map_;
262  ChainImplList chain_list_;
263  ConnectorImplMap connector_map_;
264  TorsionImplMap torsion_map_;
265 
266  geom::Transform transform_;
267  bool has_transform_;
268 
269  SpatialAtomOrganizer atom_organizer_;
270  FragmentImplList fragment_list_;
271  EntityObserverMap observer_map_;
272 
273  int xcs_editor_count_;
274  int ics_editor_count_;
275  int dirty_flags_;
276  String name_;
277 
278  unsigned long next_index_;
279 
280  QueryFlags default_query_flags_;
281 
282  template <bool always_true>
283  EntityView do_selection(const EntityHandle&, const Query&, QueryFlags) const;
284 };
285 
286 }}} // ns
287 
288 #endif