Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Atom_.hh
Go to the documentation of this file.
1 // -*- mode:c++;tab-width:2;indent-tabs-mode:t;show-trailing-whitespace:t;rm-trailing-spaces:t -*-
2 // vi: set ts=2 noet:
3 //
4 // (c) Copyright Rosetta Commons Member Institutions.
5 // (c) This file is part of the Rosetta software suite and is made available under license.
6 // (c) The Rosetta software is developed by the contributing members of the Rosetta Commons.
7 // (c) For more information, see http://www.rosettacommons.org. Questions about this can be
8 // (c) addressed to University of Washington UW TechTransfer, email: license@u.washington.edu.
9 
10 /// @file core/kinematics/tree/Atom_.hh
11 /// @brief Kinematics Atom abstract base class
12 /// @author Phil Bradley
13 
14 
15 #ifndef INCLUDED_core_kinematics_tree_Atom__hh
16 #define INCLUDED_core_kinematics_tree_Atom__hh
17 
18 
19 // Package headers
23 #include <core/id/AtomID.hh>
24 // AUTO-REMOVED #include <core/kinematics/Stub.hh>
25 
26 // Numeric headers
27 #include <numeric/xyzVector.hh>
28 
29 // Utility headers
30 //#include <utility/pointer/access_ptr.hh>
31 
32 
33 namespace core {
34 namespace kinematics {
35 namespace tree {
36 
37 
38 /// Kinematics Atom abstract base class
39 class Atom_ :
40  public Atom
41 {
42 
43 
44 private: // Types
45 
46 
47  typedef Atom Super;
48 
49 
50 public: // Types
51 
52 
55  using Super::insert_atom;
56 
57 
58 protected: // Creation
59 
60 
61  /// @brief Default constructor
62  inline
63  Atom_() :
64  this_weak_ptr_( 0 ),
66  {
67  atoms_.reserve( 4 );
68  }
69 
70 
71  /// @brief Copy constructor
72  /// @note Copies value and type state but not context state
73  inline
74  Atom_( Atom_ const & atom ) :
75  Super( atom ),
76  this_weak_ptr_( 0 ),
77  position_( atom.position_ ),
79  {
80  atoms_.reserve( 4 );
81  }
82 
83 
84 public: // Creation
85 
86 
87  /// @brief Destructor
88  // does not clear pointers, use erase
89  virtual
91  {}
92 
93 
94 protected: // Assignment
95 
96 
97  /// @brief Copy assignment
98  /// @note Copies value and type state but not context state
99  inline
100  Atom_ &
101  operator =( Atom_ const & atom )
102  {
103  if ( this != &atom ) {
104  position_ = atom.position_;
106  }
107  return *this;
108  }
109 
110 
111 public: // Methods
112 
113  virtual
114  void
116  AtomAP weak_ptr
117  );
118 
119  // assumes coords for our input stub are good
120  /// @brief update xyz position of this atom and its offspring atoms
121  void
123 
124  /// @brief update internal coords of this atom and its offspring atoms (if recursive)
125  void
127  bool const recursive
128  );
129 
130  /// @brief recursively add all atoms into the AtomPointers map
131 // void
132 // update_atom_pointer(
133 // AtomPointers & atom_pointer,
134 // bool const allow_overwriting = false
135 // );
136 
137 
138  /// @brief for DOFs which must be kept fixed due to topology of tree
139  /** eg, phi of stub_atoms for jump_atoms */
140  inline
141  bool
143  DOF_Type const //type
144  ) const
145  {
146  return false;
147  }
148 
149  /// @brief dihedral angle between two bonded children to this atom
150  Real
152  AtomCOP child1,
153  AtomCOP child2
154  ) const;
155 
156  /// @brief dump out AtomID for this atom, its parent and all its offspring
157  void
158  show() const;
159 
160  /// @brief dump out AtomID for this atom, its parent and all its offspring up to n_level
161  void
162  show(int const & n_level) const;
163 
164  ///////////////////////////////////////////////////////////////////////////
165  /// @brief update domain map
166  void
168  int & current_color,
169  int & biggest_color,
170  DomainMap & domain_map,
171  AtomID_Mask const & dof_moved,
172  AtomID_Mask const & atom_moved
173  ) const;
174 
175 
176  ///////////////////////////////////////////////////////////////////////////
177  // manage atom_list
178 
179  /// @brief starting const iterator of the children atom list
180  inline
182  atoms_begin() const
183  {
184  return atoms_.begin();
185  }
186 
187  /// @brief ending const iterator of the children atom list
188  inline
190  atoms_end() const
191  {
192  return atoms_.end();
193  }
194 
195  /// @brief starting iterator of the children atom list
196  inline
199  {
200  return atoms_.begin();
201  }
202 
203  /// @brief ending iterator of the children atom list
204  inline
207  {
208  return atoms_.end();
209  }
210 
211  /// @brief number of children atoms
212  inline
213  Size
214  n_atom() const
215  {
216  return atoms_.size();
217  }
218 
219  /// @brief append an atom as this atom's child
220  void
221  append_atom( AtomOP );
222 
223  /// @brief remove an atom from this atom's children
224  void
225  delete_atom( AtomOP );
226 
227  /// @brief insert an atom as this atom's child
228  void
229  insert_atom( AtomOP );
230 
231 
232  /// @brief tries to insert at the position specified by the second argument
233  void
234  insert_atom( AtomOP, int const /*index*/ );
235 
236  /// @brief replace the old atom by the new atom in the child atom list
237  void
238  replace_atom(
239  AtomOP const old_atom,
240  AtomOP const new_atom
241  );
242 
243  /// @brief get non-jump atom by its index from the children atoms list
244  AtomCOP
246  Size const i
247  ) const;
248 
249  /// @brief delete this atom and all its children
250 // void
251 // erase();
252 
253  /// @brief number of the child atoms
254  Size
255  n_children() const;
256 
257  /// @brief number of the non-jump child atoms
258  Size
260  {
261  return atoms_end() - nonjump_atoms_begin();
262  }
263 
264  /// @brief get a child atom by index (const method)
265  AtomCOP
266  child( Size const k ) const;
267 
268  /// @brief get a child atom by index
269  AtomOP
270  child( Size const k );
271 
272  /// @brief the atom-index of this child
273  Size
274  child_index( AtomCOP child ) const;
275 
276  /// @brief whether atom1 is downstream of this atom.
277  bool
278  downstream( AtomCOP atom1 ) const;
279 
280 
281 public: // Properties
282 
283 
284  /// @brief Atom identifier
285  inline
286  AtomID const &
287  id() const
288  {
289  return atom_id_;
290  }
291 
292 
293  /// @brief AtomID assignment
294  inline
295  void
296  id( AtomID const & id_in )
297  {
298  atom_id_ = id_in;
299  }
300 
301 
302  /// @brief Atom identifier
303  inline
304  AtomID const &
305  atom_id() const
306  {
307  return atom_id_;
308  }
309 
310 
311  /// @brief Position
312  inline
313  Position const &
314  position() const
315  {
316  return position_;
317  }
318 
319 
320  /// @brief Position assignment
321  inline
322  void
323  position( Position const & position_a )
324  {
325  position_ = position_a;
326  }
327 
328 
329  /// @brief Position
330  inline
331  Position const &
332  xyz() const
333  {
334  return position_;
335  }
336 
337 
338  /// @brief Position assignment
339  inline
340  void
341  xyz( Position const & position_a )
342  {
343  position_ = position_a;
344  }
345 
346 
347  /// @brief x coordinate
348  inline
349  Length const &
350  x() const
351  {
352  return position_.x();
353  }
354 
355 
356  /// @brief y coordinate
357  inline
358  Length const &
359  y() const
360  {
361  return position_.y();
362  }
363 
364 
365  /// @brief z coordinate
366  inline
367  Length const &
368  z() const
369  {
370  return position_.z();
371  }
372 
373 
374  /// @brief Distance to an Atom
375  inline
376  Length
377  distance( Atom const & atom ) const
378  {
379  return position_.distance( atom.position() );
380  }
381 
382 
383  /// @brief Distance squared to an Atom
384  inline
385  Length
386  distance_squared( Atom const & atom ) const
387  {
388  return position_.distance_squared( atom.position() );
389  }
390 
391 
392  /// @brief Parent atom pointer
393  inline
394  AtomCOP
395  parent() const
396  {
397  return parent_();
398  }
399 
400 
401  ///
402  void
403  parent( AtomAP parent_in )
404  {
405  parent_ = parent_in;
406  }
407 
408 
409  /// @brief Parent atom pointer
410  inline
411  AtomOP
413  {
414  return parent_();
415  }
416 
417  /// @brief stub centerd at this atom
418  Stub
419  get_stub() const;
420 
421  /// @brief stub used to build this atom
422  Stub
423  get_input_stub() const;
424 
425  /// @brief stub atom1 's id
426  inline // PHIL: These AtomID fxns could be faster by implementing analogs to the atom lookup calls at the cost of more near-duplicate code
427  AtomID const &
429  {
430  return stub_atom1()->id();
431  }
432 
433  /// @brief stub atom2's id
434  inline
435  AtomID const &
437  {
438  return stub_atom2()->id();
439  }
440 
441  /// @brief stub atom3's id
442  inline
443  AtomID const &
445  {
446  return stub_atom3()->id();
447  }
448 
449  /// @brief the center of the input stub for refolding this atom
450  /** it is its parent*/
451  inline
452  AtomCOP
454  {
455  assert( parent_ );
456  return parent_();
457  }
458 
459  /// @brief the first atom to construct the input stub for refolding this atom
460  /** it is its parent's stub_atom1, which normally the parent itself*/
461  inline
462  AtomCOP
464  {
465  assert( parent_ );
466  return parent_->stub_atom1();
467  }
468 
469  /// @brief the second atom to construct the input stub for refolding this atom
470  /** it is its parent's stub_atom2, which normally the parent's parent*/
471  inline
472  AtomCOP
474  {
475  assert( parent_ );
476  return parent_->stub_atom2();
477  }
478 
479  /// @brief the third atom to construct the input stub for refolding this atom
480  /** it is either its previous sibling or its parent's stub_atom3,*/
481  inline
482  AtomCOP
484  {
485  assert( parent_ );
486  AtomCOP sibling( previous_sibling() );
487  if ( is_jump() || sibling == 0 || sibling->is_jump() ||
488  ( parent_->is_jump() && sibling->id() == parent_->stub_atom2_id() ) ) {
489  return parent_->stub_atom3();
490  } else {
491  return sibling;
492  }
493  }
494 
495  /// @brief input stub atom0's id
496  inline
497  AtomID const &
499  {
500  return input_stub_atom0()->id();
501  }
502 
503  /// @brief input stub atom1's id
504  inline
505  AtomID const &
507  {
508  return input_stub_atom1()->id();
509  }
510 
511  /// @brief input stub atom2's id
512  inline
513  AtomID const &
515  {
516  return input_stub_atom2()->id();
517  }
518 
519  /// @brief input stub atom3's id
520  inline
521  AtomID const &
523  {
524  return input_stub_atom3()->id();
525  }
526 
527 
528  /// @brief routines for navigating the tree
529  /// find the sibling atom before itself
530  AtomCOP
531  previous_sibling() const;
532 
533  /// @brief find the child atom before this child in the list
534  AtomCOP
536  AtomCOP child
537  ) const;
538 
539  /// @brief find the child atom after this child in the list
540  AtomOP
541  next_child(
542  AtomCOP child
543  );
544 
545  /// @brief whether a Stub can be defined for this atom
546  bool
547  stub_defined() const;
548 
549 
550 protected: // Methods
551 
552  /// @brief Read access to the replacement "this" pointer
554 
555  /// @brief Read access to the replacement "this" pointer
557 
558  /// @brief when subtrees have changed their coordinates
559  void
561  AtomOP const child
562  );
563 
564  /// @brief constant iterator of the first non-jump (bonded) atom in the vector of children atoms.
566  nonjump_atoms_begin() const;
567 
568  /// @brief iterator of the first non-jump (bonded) atom in the vector of children atoms.
571 
572  /// @brief helper function to abort if something is wrong in atom tree
573  void
574  abort_bad_call() const;
575 
576 
577  /// @brief Transform atom and children by linear transformation
578  virtual
579  void
581  Matrix const & A,
582  Vector const & b,
583  ResidueCoordinateChangeList & res_change_list
584  );
585 
586 
587  ///
588  //virtual
589  void
591 
592 
593  ///
594  bool
595  atom_is_on_path_from_root( AtomCOP atm ) const;
596 
597 
598  /// @brief Records this atom as having a changed DOF in the input list
599  /// of Atoms with changed DOFs. For use in output-sensitive refold subroutine.
600  void
602  AtomDOFChangeSet & changset
603  );
604 
605  /// @brief To ensure proper function of the output-senstive refold
606  /// subroutine, derived classes must invoke this function during their
607  /// update_xyz_coord subroutines.
608  inline
609  void
611  {
612  dof_refold_index_ = 0;
613  }
614 
615 
616 public:
617 
618  /// @brief base class implementation that traverses the subtree routed at this node
619  /// in the depth-first traversal of the atoms requiring coordinate updates.
620  virtual
621  void
622  dfs(
623  AtomDOFChangeSet & changeset,
624  ResidueCoordinateChangeList & res_change_list,
625  Size const start_atom_index
626  ) const;
627 
628 protected:
629 
630  /// @brief read access for derived classes
631  inline
632  Size
634  return dof_refold_index_;
635  }
636 
637 protected: // Fields -- should be private...
638 // private: // Fields
639 
640  /// @brief Each atom must hold a weak pointer to itself, and this weak pointer must
641  /// be given to the atom at its construction
643 
644  /// @brief Atom ID
646 
647  /// @brief Associated conformation Atom
648  //conformation::AtomAP conformation_atom_p_;
649 
650  /// @brief Parent atom pointer
652 
653  /// @brief xyz
655 
656  /// @brief Children atom pointers
658 
659 private:
660 
661  /// @brief Track my position in my owner's list of Atoms with modified DOFs.
662  /// 0 when my dofs have not changed since the last update_coords.
664 
665 }; // Atom_
666 
667 
668 }
669 } // namespace kinematics
670 } // namespace core
671 
672 
673 #endif // INCLUDED_core_kinematics_Atom__HH