OpenStructure
atom_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-2020 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_ATOM_IMPL_HH
20 #define OST_ATOM_IMPL_HH
21 
22 #include <boost/enable_shared_from_this.hpp>
23 
24 #include <ost/mol/module_config.hh>
25 #include <ost/geom/geom.hh>
28 
34 
35 #include <ost/generic_property.hh>
36 #include <ost/mol/property_id.hh>
37 
38 namespace ost { namespace mol { namespace impl {
39 
50  public boost::enable_shared_from_this<AtomImpl> {
51 public:
52  AtomImpl(const EntityImplPtr& ent, const ResidueImplPtr& res,
53  const String& name, const geom::Vec3& pos, const String& ele,
54  unsigned long index);
55 
57  void Apply(EntityVisitor& h);
58 
59  // for efficiency reasons, the simple setter/getter methods are
60  // replaced by direct access - this is the impl layer after all
61 
62  const String& Name() const {return name_;}
63  String& Name() {return name_;}
64 
65  // DEPRECATED
66  const String& GetName() const {return name_;}
67 
68  const geom::Vec3& TransformedPos() const {return tf_pos_;}
69  geom::Vec3& TransformedPos() {return tf_pos_;}
70 
71  const geom::Vec3& OriginalPos() const {return pos_;}
72  geom::Vec3& OriginalPos() {return pos_;}
73 
75 
77  prim_connector_=bp;
78  }
79 
81  return prim_connector_;
82  }
83 
85  return connector_list_;
86  }
87 
89  return connector_list_;
90  }
91 
93 
94  // updates position and then follows secondary connectors
95  void UpdateFromICS();
96 
97  // derive internal coordinates from position and linkage
98  void UpdateFromXCS();
99 
101 
103 
104  int GetConnectorCount() const {
105  return connector_list_.size()+(prim_connector_ ? 1 : 0);
106  }
107 
108  void SetVisited(bool f) {set_state_bit(0,f);}
109  bool IsVisited() const {return get_state_bit(0);}
110 
111  void SetTraced(bool f) {set_state_bit(1,f);}
112  bool IsTraced() const {return get_state_bit(1);}
113 
114 
115  Real GetBFactor() const { return b_factor_; }
116 
117  const String& GetElement() const { return element_; }
118 
119  void SetElement(const String& ele)
120  {
121  if (element_!=ele) {
122  element_=ele;
123  AtomProp* old_prop = prop_;
124  prop_=impl::AtomProp::GetDefaultProps(element_);
125  if (old_prop && !old_prop->is_default) {
126  if(old_prop->has_anisou) this->SetAnisou(old_prop->anisou);
127  if(old_prop->charge != 0.0) this->SetCharge(old_prop->charge);
128  delete old_prop;
129  }
130  }
131  }
132  bool HasDefaultProps() const { return prop_->is_default; }
133  void SetAnisou(const geom::Mat3& anisou)
134  {
135  if (prop_->is_default && prop_->anisou!=anisou) {
136  prop_=new AtomProp(*prop_);
137  prop_->is_default=false;
138  prop_->has_anisou=true;
139  }
140 
141  prop_->anisou=anisou;
142  }
143 
144  const geom::Mat3& GetAnisou() const
145  {
146  return prop_->anisou;
147  }
148  void SetBFactor(Real factor)
149  {
150  b_factor_=factor;
151  }
152 
153  void SetOccupancy(Real occ)
154  {
155  occupancy_=occ;
156  }
157 
159  {
160  return occupancy_;
161  }
162 
163  Real GetRadius() const { return prop_->radius; }
164 
165  Real GetMass() const { return prop_->mass; }
166  Real GetCharge() const { return prop_->charge; }
167 
168  bool IsHetAtom() { return is_hetatm_; }
169 
170  void SetHetAtom(bool het) { is_hetatm_=het; }
171 
172  void SetMass(Real mass)
173  {
174  if (prop_->is_default && prop_->mass!=mass) {
175  prop_=new AtomProp(*prop_);
176  prop_->is_default=false;
177  }
178  prop_->mass=mass;
179  }
180 
181  void SetRadius(Real radius)
182  {
183  if (prop_->is_default && prop_->radius!=radius) {
184  prop_=new AtomProp(*prop_);
185  prop_->is_default=false;
186  }
187  prop_->radius=radius;
188  }
189 
190  void SetCharge(Real charge)
191  {
192  if (prop_->is_default && prop_->charge!=charge) {
193  prop_=new AtomProp(*prop_);
194  prop_->is_default=false;
195  }
196  prop_->charge=charge;
197  }
198 
199 
200  unsigned int GetState() const
201  {
202  return state_;
203  }
204 
205  void SetState(int state)
206  {
207  state_=state;
208  }
209 
213  int n, unsigned int& c);
214 
215  bool HasPrevious() const {return prim_connector_.get()!=NULL;}
216 
218 
219  void DeleteConnector(const ConnectorImplP& conn,
220  bool delete_other=true);
221 
223 
225 
227 
228  int GetIntProperty(Prop::ID prop_id) const;
229 
230  unsigned long GetIndex() const {return index_;}
231  void SetIndex(unsigned long index) {index_=index;}
232 
233  void SetFragment(FragmentImplP fragment) { fragment_ = fragment; }
234 
235 private:
236  ResidueImplW res_;
237  String name_;
238  geom::Vec3 pos_;
239  geom::Vec3 tf_pos_;
240  Real occupancy_;
241  Real b_factor_;
242  AtomProp* prop_;
243  bool is_hetatm_;
244  String element_;
245  ConnectorImplP prim_connector_;
246  ConnectorImplList connector_list_;
247  FragmentImplP fragment_;
248 
251  geom::Mat3 total_rot_;
252 
255  unsigned int state_;
256 
257  void set_state_bit(unsigned int bit, bool state)
258  {
259  unsigned int mask = 0x1<<bit;
260  if(state) {
261  state_ |= mask;
262  } else {
263  state_ &= ~mask;
264  }
265  }
266 
267  bool get_state_bit(unsigned int bit) const {
268  unsigned int mask = 0x1<<bit;
269  return (state_ & mask)!=0;
270  }
271 
272  unsigned long index_;
273 };
274 
276 std::ostream& operator<<(std::ostream& o, const AtomImplPtr ap);
277 
279 bool ConnectorExists(const AtomImplPtr& a, const AtomImplPtr& b);
280 
283 
284 }}} // ns
285 
286 #endif
287 
Three dimensional vector class, using Real precision.
Definition: vec3.hh:48
base class for the implementation
EntityVisitor interface.
Atom implementation.
Definition: atom_impl.hh:50
String GetStringProperty(Prop::ID prop_id) const
void SetTraced(bool f)
Definition: atom_impl.hh:111
EntityImplPtr GetEntity() const
void SetFragment(FragmentImplP fragment)
Definition: atom_impl.hh:233
bool IsVisited() const
Definition: atom_impl.hh:109
void SetVisited(bool f)
Definition: atom_impl.hh:108
int GetIntProperty(Prop::ID prop_id) const
unsigned int GetState() const
Definition: atom_impl.hh:200
void SetHetAtom(bool het)
Definition: atom_impl.hh:170
void Apply(EntityVisitor &h)
const geom::Mat3 & GetAnisou() const
Definition: atom_impl.hh:144
const ConnectorImplList & GetSecondaryConnectors() const
Definition: atom_impl.hh:84
ConnectorImplList & GetSecondaryConnectors()
Definition: atom_impl.hh:88
void SetCharge(Real charge)
Definition: atom_impl.hh:190
unsigned long GetIndex() const
Definition: atom_impl.hh:230
Real GetRadius() const
Definition: atom_impl.hh:163
geom::Vec3 & TransformedPos()
Definition: atom_impl.hh:69
bool HasDefaultProps() const
Definition: atom_impl.hh:132
void SetBFactor(Real factor)
Definition: atom_impl.hh:148
void SetPrimaryConnector(const ConnectorImplP &bp)
Definition: atom_impl.hh:76
String GetQualifiedName() const
const ConnectorImplP & GetPrimaryConnector() const
Definition: atom_impl.hh:80
ResidueImplPtr GetResidue() const
const String & Name() const
Definition: atom_impl.hh:62
void SetIndex(unsigned long index)
Definition: atom_impl.hh:231
AtomImpl(const EntityImplPtr &ent, const ResidueImplPtr &res, const String &name, const geom::Vec3 &pos, const String &ele, unsigned long index)
void DeleteConnector(const ConnectorImplP &conn, bool delete_other=true)
const geom::Vec3 & OriginalPos() const
Definition: atom_impl.hh:71
void SetOccupancy(Real occ)
Definition: atom_impl.hh:153
void TraceDirectionality(FragmentImplP frag, ConnectorImplP conn, int n, unsigned int &c)
trace directionality
void SetElement(const String &ele)
Definition: atom_impl.hh:119
const geom::Vec3 & TransformedPos() const
Definition: atom_impl.hh:68
geom::Vec3 & OriginalPos()
Definition: atom_impl.hh:72
Real GetBFactor() const
Definition: atom_impl.hh:115
void SetRadius(Real radius)
Definition: atom_impl.hh:181
const String & GetElement() const
Definition: atom_impl.hh:117
Real GetCharge() const
Definition: atom_impl.hh:166
Real GetOccupancy() const
Definition: atom_impl.hh:158
void SetMass(Real mass)
Definition: atom_impl.hh:172
const String & GetName() const
Definition: atom_impl.hh:66
void SetAnisou(const geom::Mat3 &anisou)
Definition: atom_impl.hh:133
int GetConnectorCount() const
Definition: atom_impl.hh:104
bool HasPrevious() const
Definition: atom_impl.hh:215
void AddSecondaryConnector(const ConnectorImplP &bp)
void SetState(int state)
Definition: atom_impl.hh:205
Real GetFloatProperty(Prop::ID prop_id) const
static AtomProp * GetDefaultProps(const String &ele)
float Real
Definition: base.hh:44
std::string String
Definition: base.hh:54
ConnectorImplP GetConnector(const AtomImplPtr &a, const AtomImplPtr &b)
bool ConnectorExists(const AtomImplPtr &a, const AtomImplPtr &b)
boost::shared_ptr< AtomImpl > AtomImplPtr
Definition: atom_impl_fw.hh:33
boost::weak_ptr< ResidueImpl > ResidueImplW
std::ostream & operator<<(std::ostream &o, const AtomImplPtr ap)
boost::shared_ptr< EntityImpl > EntityImplPtr
boost::shared_ptr< FragmentImpl > FragmentImplP
std::list< ConnectorImplP > ConnectorImplList
boost::shared_ptr< ConnectorImpl > ConnectorImplP
boost::shared_ptr< ResidueImpl > ResidueImplPtr
Definition: base.dox:1
ID
Defined properties.
Definition: property_id.hh:41