00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef OST_ENTITY_IMPL_HH
00020 #define OST_ENTITY_IMPL_HH
00021
00022 #include <map>
00023 #include <vector>
00024
00025 #include <boost/enable_shared_from_this.hpp>
00026
00027 #include <ost/mol/module_config.hh>
00028 #include <ost/geom/geom.hh>
00029
00030 #include <ost/mol/impl/entity_impl_fw.hh>
00031
00032 #include <ost/mol/entity_view.hh>
00033
00034 #include <ost/mol/transform.hh>
00035 #include <ost/mol/residue_prop.hh>
00036 #include <ost/mol/impl/atom_impl_fw.hh>
00037 #include <ost/mol/impl/residue_impl_fw.hh>
00038 #include <ost/mol/impl/chain_impl_fw.hh>
00039 #include <ost/mol/impl/connector_impl_fw.hh>
00040 #include <ost/mol/impl/torsion_impl_fw.hh>
00041 #include <ost/mol/impl/fragment_impl_fw.hh>
00042 #include <ost/mol/impl/pointer_iterator.hh>
00043 #include <ost/mol/entity_visitor_fw.hh>
00044 #include <ost/mol/entity_observer_fw.hh>
00045 #include <ost/mol/entity_view.hh>
00046 #include <ost/mol/entity_handle.hh>
00047 #include <ost/mol/spatial_organizer.hh>
00048
00049
00050 #include <ost/generic_property.hh>
00051
00052 namespace ost { namespace mol { namespace impl {
00053
00055 typedef std::map<AtomImpl*,AtomImplPtr> AtomImplMap;
00057 typedef std::map<ResidueImpl*,ResidueImplPtr> ResidueImplMap;
00059 typedef std::vector<ChainImplPtr> ChainImplList;
00061 typedef std::map<ConnectorImpl*,ConnectorImplP> ConnectorImplMap;
00063 typedef std::map<TorsionImpl*,TorsionImplP> TorsionImplMap;
00065 typedef std::vector<FragmentImplP> FragmentImplList;
00067 typedef std::map<EntityObserver*,EntityObserverPtr> EntityObserverMap;
00069 typedef SpatialOrganizer<AtomImplPtr> SpatialAtomOrganizer;
00070
00072 typedef enum {
00073 DirtyICS=1,
00074 DirtyXCS=2,
00075
00076 DirtyTrace=DirtyICS+4,
00077 DirtyOrganizer=8,
00078 DisableICS=16,
00079 } EntityDirtyFlags;
00080
00081
00083 class EntityImpl: public GenericPropContainerImpl,
00084 public boost::enable_shared_from_this<EntityImpl>
00085 {
00086 public:
00087 EntityImpl();
00088 ~EntityImpl();
00089
00091 EntityImplPtr Copy();
00092
00093 Real GetMass() const;
00094 geom::Vec3 GetCenterOfMass() const;
00095 geom::Vec3 GetCenterOfAtoms() const;
00096 geom::Vec3 GetGeometricCenter() const;
00097 geom::Vec3 GetGeometricStart() const;
00098 geom::Vec3 GetGeometricEnd() const;
00099 geom::Vec3 GetBoundarySize() const;
00100
00101
00102 AtomImplPtr CreateAtom(const ResidueImplPtr& rp, const String& name,
00103 const geom::Vec3& pos, const AtomProp& prop);
00104
00105 ResidueImplPtr CreateResidue(const ChainImplPtr& cp,
00106 const ResNum& n,
00107 const ResidueKey& k);
00108
00109 ChainImplPtr InsertChain(const String& cname);
00113 ChainImplPtr InsertChain(const ChainImplPtr& chain);
00114 ConnectorImplP Connect(const AtomImplPtr& first, const AtomImplPtr& second,
00115 Real len, Real theta, Real phi,
00116 unsigned char bond_order);
00117
00118 TorsionImplP AddTorsion(const String& name, const AtomImplPtr& a1,
00119 const AtomImplPtr& a2, const AtomImplPtr& a3,
00120 const AtomImplPtr& a4);
00121
00122 void TraceDirectionality();
00123
00125 TorsionImplP FindTorsion(const AtomImplPtr& a1,
00126 const AtomImplPtr& a2,
00127 const AtomImplPtr& a3,
00128 const AtomImplPtr& a4) const;
00129
00130 void RenameChain(ChainImplPtr chain, const String& new_name);
00131 bool SetAngle(const AtomImplPtr& a1, const AtomImplPtr& a2,
00132 const AtomImplPtr& a3, Real angle);
00133
00134 Real GetAngle(const AtomImplPtr& a1, const AtomImplPtr& a2,
00135 const AtomImplPtr& a3) const;
00136 Real GetAngleXCS(const AtomImplPtr& a1, const AtomImplPtr& a2,
00137 const AtomImplPtr& a3) const;
00138 Real GetAngleICS(const AtomImplPtr& a1, const AtomImplPtr& a2,
00139 const AtomImplPtr& a3) const;
00140
00141 void UpdateFromICS();
00142
00143
00144 void UpdateFromXCS();
00145
00146 void Apply(EntityVisitor& v);
00147 void ApplyTransform(const geom::Mat4 transfmat);
00148
00149 void SetTransform(const geom::Mat4 transfmat);
00150
00151 void AttachObserver(const EntityObserverPtr& o);
00152 void DetachObserver(const EntityObserverPtr& o);
00153 void NotifyObserver();
00154
00155
00156 void UpdateOrganizer();
00157
00158 AtomImplList FindWithin(const geom::Vec3& pos, Real radius) const;
00159 EntityView Select(const EntityHandle& h, const Query& q,
00160 QueryFlags flags) const;
00161 EntityView CreateFullView(const EntityHandle& h) const;
00162
00165 ChainImplPtr FindChain(const String& name) const;
00166
00167 ResidueImplPtr FindResidue(const String& chain_name,
00168 const ResNum& residue) const;
00169
00170 AtomImplPtr FindAtom(const String& chain_name,
00171 const ResNum& residue,
00172 const String& atom_name) const;
00173
00174
00175
00176
00177
00178 void Swap(EntityImpl& impl);
00179
00181 int GetAtomCount() const;
00182
00184 int GetBondCount() const;
00185
00187 mol::BondHandleList GetBondList() const;
00188
00189
00191 int GetResidueCount() const;
00192
00194 int GetChainCount() const;
00195
00197 const geom::Mat4& GetTransfMatrix() const;
00198
00200 const geom::Mat4& GetInvTransfMatrix() const;
00201
00202 bool IsTransfIdentity() const;
00203
00204 const ChainImplList& GetChainList() const { return chain_list_; }
00205
00206 ChainImplList& GetChainList() { return chain_list_; }
00207
00208 void DeleteFromConnMap(const ConnectorImplP& conn);
00209
00210 void DeleteChain(const ChainImplPtr& chain);
00211
00212 void DeleteAtom(const AtomImplPtr& atom);
00213
00214 void IncXCSEditorCount();
00215 void DecXCSEditorCount();
00216
00217 void IncICSEditorCount();
00218 void DecICSEditorCount();
00219
00220 TorsionImplMap& GetTorsionMap();
00221
00222 void UpdateXCSIfNeeded();
00223
00224 void UpdateICSIfNeeded();
00225
00226 void UpdateOrganizerIfNeeded();
00227
00228 void EnableICS();
00229
00230 bool HasICS() const;
00231
00232 bool IsXCSDirty() const;
00233
00234 void MarkXCSDirty();
00235 void MarkICSDirty();
00236 void MarkTraceDirty();
00237 void MarkOrganizerDirty();
00238
00239 void UpdateTransformedPos();
00240
00241 const String& GetName() const;
00242
00243 impl::ChainImplList::iterator GetChain(const String& name);
00244
00245 pointer_it<ChainImplPtr> GetChainIter(const String& name);
00246 void SetName(const String& ent_name);
00247
00248 private:
00249 void DoCopy(EntityImplPtr dest);
00250
00251 void ReplicateHierarchy(EntityImplPtr dest);
00252
00253 void DoCopyBondsAndTorsions(EntityImplPtr dest);
00254
00255 AtomImplMap atom_map_;
00256 ChainImplList chain_list_;
00257 ConnectorImplMap connector_map_;
00258 TorsionImplMap torsion_map_;
00259
00260 geom::Mat4 transformation_matrix_;
00261 geom::Mat4 inverse_transformation_matrix_;
00262 bool identity_transf_;
00263
00264
00265 SpatialAtomOrganizer atom_organizer_;
00266 FragmentImplList fragment_list_;
00267 EntityObserverMap observer_map_;
00268
00269 int xcs_editor_count_;
00270 int ics_editor_count_;
00271 int dirty_flags_;
00272 String name_;
00273
00274 unsigned long next_index_;
00275
00276 template <bool always_true>
00277 EntityView do_selection(const EntityHandle&, const Query&, QueryFlags) const;
00278 };
00279
00280 }}}
00281
00282 #endif