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/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;
98 
99 
100 
101  // default copy ctor and assignment op should work for now
102  AtomImplPtr CreateAtom(const ResidueImplPtr& rp, const String& name,
103  const geom::Vec3& pos, const String& ele);
104 
106  const ResNum& n,
107  const ResidueKey& k);
108 
109  ChainImplPtr InsertChain(const String& cname);
113  ChainImplPtr InsertChain(const ChainImplPtr& chain);
114  ConnectorImplP Connect(const AtomImplPtr& first, const AtomImplPtr& second,
115  Real len, Real theta, Real phi,
116  unsigned char bond_order);
117 
118  TorsionImplP AddTorsion(const String& name, const AtomImplPtr& a1,
119  const AtomImplPtr& a2, const AtomImplPtr& a3,
120  const AtomImplPtr& a4);
121 
122  void TraceDirectionality();
123 
126  const AtomImplPtr& a2,
127  const AtomImplPtr& a3,
128  const AtomImplPtr& a4) const;
129 
130  void RenameChain(ChainImplPtr chain, const String& new_name);
131  bool SetAngle(const AtomImplPtr& a1, const AtomImplPtr& a2,
132  const AtomImplPtr& a3, Real angle);
133 
134  Real GetAngle(const AtomImplPtr& a1, const AtomImplPtr& a2,
135  const AtomImplPtr& a3) const;
136  Real GetAngleXCS(const AtomImplPtr& a1, const AtomImplPtr& a2,
137  const AtomImplPtr& a3) const;
138  Real GetAngleICS(const AtomImplPtr& a1, const AtomImplPtr& a2,
139  const AtomImplPtr& a3) const;
140  // update positions from internal coordinate system
141  void UpdateFromICS();
142 
143  // update internal coordinate system from positions
144  void UpdateFromXCS();
145 
146  void Apply(EntityVisitor& v);
147  void ApplyTransform(const geom::Mat4 transfmat);
148 
149  void SetTransform(const geom::Mat4 transfmat);
150 
151  void AttachObserver(const EntityObserverPtr& o);
152  void DetachObserver(const EntityObserverPtr& o);
153  void NotifyObserver();
154 
155 
156  void UpdateOrganizer();
157 
158  AtomImplList FindWithin(const geom::Vec3& pos, Real radius) const;
159  // use query flag defaults
160  EntityView Select(const EntityHandle& h, const Query& q) const;
161  // override query flag defaults with given flags
162  EntityView Select(const EntityHandle& h, const Query& q,
163  QueryFlags flags) const;
164  EntityView CreateFullView(const EntityHandle& h) const;
165  void SetDefaultQueryFlags(QueryFlags f) {default_query_flags_=f;}
166  QueryFlags GetDefaultQueryFlags() const {return default_query_flags_;}
167 
168 
171  ChainImplPtr FindChain(const String& name) const;
172 
173  ResidueImplPtr FindResidue(const String& chain_name,
174  const ResNum& residue) const;
175 
176  AtomImplPtr FindAtom(const String& chain_name,
177  const ResNum& residue,
178  const String& atom_name) const;
179  /*
180  this is a deep-swap which will exchange the internal structure
181  of two implementations, which by design affects _all_ entity handles
182  that point two either of these two implementations
183  */
184  void Swap(EntityImpl& impl);
185 
187  int GetAtomCount() const;
188 
190  int GetBondCount() const;
191 
194 
195 
197  int GetResidueCount() const;
198 
200  int GetChainCount() const;
201 
203  const geom::Mat4& GetTransfMatrix() const;
204 
206  const geom::Mat4& GetInvTransfMatrix() const;
207 
208  bool IsTransfIdentity() const;
209 
210  const ChainImplList& GetChainList() const { return chain_list_; }
211 
212  ChainImplList& GetChainList() { return chain_list_; }
213 
214  void DeleteFromConnMap(const ConnectorImplP& conn);
215 
216  void DeleteChain(const ChainImplPtr& chain);
217 
218  void DeleteAtom(const AtomImplPtr& atom);
219 
220  void IncXCSEditorCount();
221  void DecXCSEditorCount();
222 
223  void IncICSEditorCount();
224  void DecICSEditorCount();
225 
227 
228  void UpdateXCSIfNeeded();
229 
230  void UpdateICSIfNeeded();
231 
233 
234  void EnableICS();
235 
236  bool HasICS() const;
237 
238  bool IsXCSDirty() const;
239 
240  void MarkXCSDirty();
241  void MarkICSDirty();
242  void MarkTraceDirty();
243  void MarkOrganizerDirty();
244 
245  void UpdateTransformedPos();
246 
247  const String& GetName() const;
248 
249  impl::ChainImplList::iterator GetChain(const String& name);
250 
252  void SetName(const String& ent_name);
253 
254  void ReorderAllResidues();
255 
256  void RenumberAllResidues(int start, bool keep_spacing);
257 
258 private:
259  void DoCopy(EntityImplPtr dest);
260 
261  void ReplicateHierarchy(EntityImplPtr dest);
262 
263  void DoCopyBondsAndTorsions(EntityImplPtr dest);
264 
265  AtomImplMap atom_map_;
266  ChainImplList chain_list_;
267  ConnectorImplMap connector_map_;
268  TorsionImplMap torsion_map_;
269 
270  geom::Mat4 transformation_matrix_;
271  geom::Mat4 inverse_transformation_matrix_;
272  bool identity_transf_;
273 
274 
275  SpatialAtomOrganizer atom_organizer_;
276  FragmentImplList fragment_list_;
277  EntityObserverMap observer_map_;
278 
279  int xcs_editor_count_;
280  int ics_editor_count_;
281  int dirty_flags_;
282  String name_;
283 
284  unsigned long next_index_;
285 
286  QueryFlags default_query_flags_;
287 
288  template <bool always_true>
289  EntityView do_selection(const EntityHandle&, const Query&, QueryFlags) const;
290 };
291 
292 }}} // ns
293 
294 #endif