OpenStructure
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/transform.hh>
35 #include <ost/mol/residue_prop.hh>
45 #include <ost/mol/entity_view.hh>
46 #include <ost/mol/entity_handle.hh>
48 
49 
50 #include <ost/generic_property.hh>
51 
52 namespace ost { namespace mol { namespace impl {
53 
55 typedef std::map<AtomImpl*,AtomImplPtr> AtomImplMap;
57 typedef std::map<ResidueImpl*,ResidueImplPtr> ResidueImplMap;
59 typedef std::vector<ChainImplPtr> ChainImplList;
61 typedef std::map<ConnectorImpl*,ConnectorImplP> ConnectorImplMap;
63 typedef std::map<TorsionImpl*,TorsionImplP> TorsionImplMap;
65 typedef std::vector<FragmentImplP> FragmentImplList;
67 typedef std::map<EntityObserver*,EntityObserverPtr> EntityObserverMap;
70 
72 typedef enum {
75  // dirty trace (implies dirty ICS)
80 
81 
84  public boost::enable_shared_from_this<EntityImpl>
85 {
86 public:
87  EntityImpl();
88  ~EntityImpl();
89 
92 
93  Real GetMass() const;
96 
99 
100 
101 
102  // default copy ctor and assignment op should work for now
103  AtomImplPtr CreateAtom(const ResidueImplPtr& rp, const String& name,
104  const geom::Vec3& pos, const String& ele);
105 
107  const ResNum& n,
108  const ResidueKey& k);
109 
110  ChainImplPtr InsertChain(const String& cname);
114  ChainImplPtr InsertChain(const ChainImplPtr& chain);
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::Mat4 transfmat);
149 
150  void SetTransform(const geom::Mat4 transfmat);
151 
152  void AttachObserver(const EntityObserverPtr& o);
153  void DetachObserver(const EntityObserverPtr& o);
154  void NotifyObserver();
155 
156 
157  void UpdateOrganizer();
158 
159  AtomImplList FindWithin(const geom::Vec3& pos, Real radius) const;
160  EntityView Select(const EntityHandle& h, const Query& q,
161  QueryFlags flags) const;
162  EntityView CreateFullView(const EntityHandle& h) const;
163 
166  ChainImplPtr FindChain(const String& name) const;
167 
168  ResidueImplPtr FindResidue(const String& chain_name,
169  const ResNum& residue) const;
170 
171  AtomImplPtr FindAtom(const String& chain_name,
172  const ResNum& residue,
173  const String& atom_name) const;
174  /*
175  this is a deep-swap which will exchange the internal structure
176  of two implementations, which by design affects _all_ entity handles
177  that point two either of these two implementations
178  */
179  void Swap(EntityImpl& impl);
180 
182  int GetAtomCount() const;
183 
185  int GetBondCount() const;
186 
189 
190 
192  int GetResidueCount() const;
193 
195  int GetChainCount() const;
196 
198  const geom::Mat4& GetTransfMatrix() const;
199 
201  const geom::Mat4& GetInvTransfMatrix() const;
202 
203  bool IsTransfIdentity() const;
204 
205  const ChainImplList& GetChainList() const { return chain_list_; }
206 
207  ChainImplList& GetChainList() { return chain_list_; }
208 
209  void DeleteFromConnMap(const ConnectorImplP& conn);
210 
211  void DeleteChain(const ChainImplPtr& chain);
212 
213  void DeleteAtom(const AtomImplPtr& atom);
214 
215  void IncXCSEditorCount();
216  void DecXCSEditorCount();
217 
218  void IncICSEditorCount();
219  void DecICSEditorCount();
220 
222 
223  void UpdateXCSIfNeeded();
224 
225  void UpdateICSIfNeeded();
226 
228 
229  void EnableICS();
230 
231  bool HasICS() const;
232 
233  bool IsXCSDirty() const;
234 
235  void MarkXCSDirty();
236  void MarkICSDirty();
237  void MarkTraceDirty();
238  void MarkOrganizerDirty();
239 
240  void UpdateTransformedPos();
241 
242  const String& GetName() const;
243 
244  impl::ChainImplList::iterator GetChain(const String& name);
245 
247  void SetName(const String& ent_name);
248 
249  void ReorderAllResidues();
250 
251 private:
252  void DoCopy(EntityImplPtr dest);
253 
254  void ReplicateHierarchy(EntityImplPtr dest);
255 
256  void DoCopyBondsAndTorsions(EntityImplPtr dest);
257 
258  AtomImplMap atom_map_;
259  ChainImplList chain_list_;
260  ConnectorImplMap connector_map_;
261  TorsionImplMap torsion_map_;
262 
263  geom::Mat4 transformation_matrix_;
264  geom::Mat4 inverse_transformation_matrix_;
265  bool identity_transf_;
266 
267 
268  SpatialAtomOrganizer atom_organizer_;
269  FragmentImplList fragment_list_;
270  EntityObserverMap observer_map_;
271 
272  int xcs_editor_count_;
273  int ics_editor_count_;
274  int dirty_flags_;
275  String name_;
276 
277  unsigned long next_index_;
278 
279  template <bool always_true>
280  EntityView do_selection(const EntityHandle&, const Query&, QueryFlags) const;
281 };
282 
283 }}} // ns
284 
285 #endif