OpenStructure
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 
56  ~AtomImpl();
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 
74  ResidueImplPtr GetResidue() const;
75 
77  prim_connector_=bp;
78  }
79 
81  return prim_connector_;
82  }
83 
85  return connector_list_;
86  }
87 
88  void AddSecondaryConnector(const ConnectorImplP& bp);
89 
90  // updates position and then follows secondary connectors
91  void UpdateFromICS();
92 
93  // derive internal coordinates from position and linkage
94  void UpdateFromXCS();
95 
96  String GetQualifiedName() const;
97 
98  EntityImplPtr GetEntity() const;
99 
100  int GetConnectorCount() const {
101  return connector_list_.size()+(prim_connector_ ? 1 : 0);
102  }
103 
104  void SetVisited(bool f) {set_state_bit(0,f);}
105  bool IsVisited() const {return get_state_bit(0);}
106 
107  void SetTraced(bool f) {set_state_bit(1,f);}
108  bool IsTraced() const {return get_state_bit(1);}
109 
110 
111  Real GetBFactor() const { return b_factor_; }
112 
113  const String& GetElement() const { return element_; }
114 
115  void SetElement(const String& ele)
116  {
117  if (element_!=ele) {
118  element_=ele;
119  AtomProp* old_prop = prop_;
120  prop_=impl::AtomProp::GetDefaultProps(element_);
121  if (old_prop && !old_prop->is_default) {
122  if(old_prop->has_anisou) this->SetAnisou(old_prop->anisou);
123  if(old_prop->charge != 0.0) this->SetCharge(old_prop->charge);
124  delete old_prop;
125  }
126  }
127  }
128  bool HasDefaultProps() const { return prop_->is_default; }
129  void SetAnisou(const geom::Mat3& anisou)
130  {
131  if (prop_->is_default && prop_->anisou!=anisou) {
132  prop_=new AtomProp(*prop_);
133  prop_->is_default=false;
134  prop_->has_anisou=true;
135  }
136 
137  prop_->anisou=anisou;
138  }
139 
140  const geom::Mat3& GetAnisou() const
141  {
142  return prop_->anisou;
143  }
144  void SetBFactor(Real factor)
145  {
146  b_factor_=factor;
147  }
148 
149  void SetOccupancy(Real occ)
150  {
151  occupancy_=occ;
152  }
153 
155  {
156  return occupancy_;
157  }
158 
159  Real GetRadius() const { return prop_->radius; }
160 
161  Real GetMass() const { return prop_->mass; }
162  Real GetCharge() const { return prop_->charge; }
163 
164  bool IsHetAtom() { return is_hetatm_; }
165 
166  void SetHetAtom(bool het) { is_hetatm_=het; }
167 
168  void SetMass(Real mass)
169  {
170  if (prop_->is_default && prop_->mass!=mass) {
171  prop_=new AtomProp(*prop_);
172  prop_->is_default=false;
173  }
174  prop_->mass=mass;
175  }
176 
177  void SetRadius(Real radius)
178  {
179  if (prop_->is_default && prop_->radius!=radius) {
180  prop_=new AtomProp(*prop_);
181  prop_->is_default=false;
182  }
183  prop_->radius=radius;
184  }
185 
186  void SetCharge(Real charge)
187  {
188  if (prop_->is_default && prop_->charge!=charge) {
189  prop_=new AtomProp(*prop_);
190  prop_->is_default=false;
191  }
192  prop_->charge=charge;
193  }
194 
195 
196  unsigned int GetState() const
197  {
198  return state_;
199  }
200 
201  void SetState(int state)
202  {
203  state_=state;
204  }
205 
206  void ClearDirectionality();
209  int n, unsigned int& c);
210 
211  bool HasPrevious() const {return prim_connector_.get()!=NULL;}
212 
213  void DeleteAllConnectors();
214 
215  void DeleteConnector(const ConnectorImplP& conn,
216  bool delete_other=true);
217 
218  void DeleteAllTorsions();
219 
220  String GetStringProperty(Prop::ID prop_id) const;
221 
222  Real GetFloatProperty(Prop::ID prop_id) const;
223 
224  int GetIntProperty(Prop::ID prop_id) const;
225 
226  unsigned long GetIndex() const {return index_;}
227  void SetIndex(unsigned long index) {index_=index;}
228 
229 private:
230  ResidueImplW res_;
231  String name_;
232  geom::Vec3 pos_;
233  geom::Vec3 tf_pos_;
234  Real occupancy_;
235  Real b_factor_;
236  AtomProp* prop_;
237  bool is_hetatm_;
238  String element_;
239  ConnectorImplP prim_connector_;
240  ConnectorImplList connector_list_;
241  FragmentImplP fragment_;
242 
245  geom::Mat3 total_rot_;
246 
249  unsigned int state_;
250 
251  void set_state_bit(unsigned int bit, bool state)
252  {
253  unsigned int mask = 0x1<<bit;
254  if(state) {
255  state_ |= mask;
256  } else {
257  state_ &= ~mask;
258  }
259  }
260 
261  bool get_state_bit(unsigned int bit) const {
262  unsigned int mask = 0x1<<bit;
263  return (state_ & mask)!=0;
264  }
265 
266  unsigned long index_;
267 };
268 
270 std::ostream& operator<<(std::ostream& o, const AtomImplPtr ap);
271 
273 bool ConnectorExists(const AtomImplPtr& a, const AtomImplPtr& b);
274 
277 
278 }}} // ns
279 
280 #endif
281 
EntityImplPtr GetEntity() const
Real GetBFactor() const
Definition: atom_impl.hh:111
void SetIndex(unsigned long index)
Definition: atom_impl.hh:227
unsigned int GetState() const
Definition: atom_impl.hh:196
Real GetMass() const
Definition: atom_impl.hh:161
Real GetOccupancy() const
Definition: atom_impl.hh:154
void SetState(int state)
Definition: atom_impl.hh:201
void SetPrimaryConnector(const ConnectorImplP &bp)
Definition: atom_impl.hh:76
const geom::Vec3 & OriginalPos() const
Definition: atom_impl.hh:71
int GetIntProperty(Prop::ID prop_id) const
unsigned long GetIndex() const
Definition: atom_impl.hh:226
bool HasDefaultProps() const
Definition: atom_impl.hh:128
const String & GetName() const
Definition: atom_impl.hh:66
std::string String
Definition: base.hh:54
float Real
Definition: base.hh:44
const String & GetElement() const
Definition: atom_impl.hh:113
const String & Name() const
Definition: atom_impl.hh:62
bool HasPrevious() const
Definition: atom_impl.hh:211
void SetHetAtom(bool het)
Definition: atom_impl.hh:166
boost::shared_ptr< FragmentImpl > FragmentImplP
String GetStringProperty(Prop::ID prop_id) const
ID
Defined properties.
Definition: property_id.hh:41
void TraceDirectionality(FragmentImplP frag, ConnectorImplP conn, int n, unsigned int &c)
trace directionality
void SetElement(const String &ele)
Definition: atom_impl.hh:115
boost::shared_ptr< ResidueImpl > ResidueImplPtr
bool IsTraced() const
Definition: atom_impl.hh:108
boost::shared_ptr< ConnectorImpl > ConnectorImplP
int GetConnectorCount() const
Definition: atom_impl.hh:100
void SetCharge(Real charge)
Definition: atom_impl.hh:186
boost::weak_ptr< ResidueImpl > ResidueImplW
const geom::Vec3 & TransformedPos() const
Definition: atom_impl.hh:68
EntityVisitor interface.
Atom implementation.
Definition: atom_impl.hh:49
void SetBFactor(Real factor)
Definition: atom_impl.hh:144
String GetQualifiedName() const
const ConnectorImplP & GetPrimaryConnector() const
Definition: atom_impl.hh:80
void SetAnisou(const geom::Mat3 &anisou)
Definition: atom_impl.hh:129
ResidueImplPtr GetResidue() const
void SetMass(Real mass)
Definition: atom_impl.hh:168
boost::shared_ptr< AtomImpl > AtomImplPtr
Definition: atom_impl_fw.hh:33
Real GetCharge() const
Definition: atom_impl.hh:162
void AddSecondaryConnector(const ConnectorImplP &bp)
void SetRadius(Real radius)
Definition: atom_impl.hh:177
boost::shared_ptr< EntityImpl > EntityImplPtr
Real GetRadius() const
Definition: atom_impl.hh:159
geom::Vec3 & TransformedPos()
Definition: atom_impl.hh:69
void SetTraced(bool f)
Definition: atom_impl.hh:107
static AtomProp * GetDefaultProps(const String &ele)
Three dimensional vector class, using Real precision.
Definition: vec3.hh:43
bool ConnectorExists(const AtomImplPtr &a, const AtomImplPtr &b)
Real GetFloatProperty(Prop::ID prop_id) const
AtomImpl(const EntityImplPtr &ent, const ResidueImplPtr &res, const String &name, const geom::Vec3 &pos, const String &ele, unsigned long index)
void SetOccupancy(Real occ)
Definition: atom_impl.hh:149
void Apply(EntityVisitor &h)
void DeleteConnector(const ConnectorImplP &conn, bool delete_other=true)
geom::Vec3 & OriginalPos()
Definition: atom_impl.hh:72
const geom::Mat3 & GetAnisou() const
Definition: atom_impl.hh:140
bool IsVisited() const
Definition: atom_impl.hh:105
std::list< ConnectorImplP > ConnectorImplList
base class for the implementation
const ConnectorImplList & GetSecondaryConnectors() const
Definition: atom_impl.hh:84
ConnectorImplP GetConnector(const AtomImplPtr &a, const AtomImplPtr &b)
void SetVisited(bool f)
Definition: atom_impl.hh:104
std::ostream & operator<<(std::ostream &o, const AtomImplPtr ap)