Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
AtomTreeCollection.cc
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/pack/scmin/AtomTreeCollection.cc
11 /// @brief Implementation for the classes holding sets of AtomTrees used during variuos packing+minimizing schemes
12 /// @author Andrew Leaver-Fay (aleaverfay@gmail.com)
13 
14 // Unit headers
16 
17 // Package Headers
21 
22 // Project Headers
23 #include <core/types.hh>
24 #include <core/id/DOF_ID.hh>
29 //#include <core/conformation/Conformation.hh>
30 #include <core/pose/Pose.hh>
31 
32 // Numeric headers
33 #include <numeric/constants.hh>
34 // AUTO-REMOVED #include <numeric/xyz.functions.hh>
35 
36 // Utility headers
37 #include <utility/vector1.fwd.hh>
38 
39 #include <utility/vector1.hh>
40 
41 
42 namespace core {
43 namespace pack {
44 namespace scmin {
45 
47  restype_index_( 0 ),
48  natoms_( 0 )
49 {}
50 
52 
55 ) :
56  utility::pointer::ReferenceCount(),
57  restype_index_( src.restype_index_ ),
58  natoms_( src.natoms_ ),
59  coords_( src.coords_ )
60 {
61 }
62 
65 {
66  if ( this != & rhs ) {
68  natoms_ = rhs.natoms_;
69  if ( coords_.size() < rhs.coords_.size() ) coords_.resize( rhs.coords_.size() );
70  for ( Size ii = 1, iiend = natoms_; ii <= iiend; ++ii ) coords_[ ii ] = rhs.coords_[ ii ];
71  }
72  return *this;
73 }
74 
76 {
77  restype_index_ = setting;
78 }
79 
81 {
82  if ( coords_.size() < res.natoms() ) { coords_.resize( res.natoms() ); }
83  natoms_ = res.natoms();
84  for ( Size ii = 1, iiend = res.natoms(); ii <= iiend; ++ii ) {
85  coords_[ ii ] = res.xyz( ii );
86  }
87 }
88 
89 
91  task::ResidueLevelTask const & rltask,
92  conformation::Conformation const & conformation,
93  conformation::Residue const & orig_res
94 ) :
95  active_restype_( 0 ),
96  residue_uptodate_( true ),
97  atom_tree_uptodate_( true ),
98  atom_tree_representatives_( rltask.allowed_residue_types().size() ),
99  residue_representatives_( atom_tree_representatives_.size() )
100 {
101  //Size const nrestypes( atom_tree_representatives_.size() );
102  Size const resid( orig_res.seqpos() );
103 
104  Size ii( 0 );
106  allowed_iter = rltask.allowed_residue_types_begin(),
107  allowed_end = rltask.allowed_residue_types_end();
108  allowed_iter != allowed_end; ++allowed_iter ) {
109  ++ii;
110 
112  **allowed_iter, orig_res, conformation, rltask.preserve_c_beta() );
113  residue_representatives_[ ii ]->seqpos( 1 ); // temporary -- while we construct the atom tree, pretend we're residue 1.
114  kinematics::AtomPointer2D tree_atoms2d( 1 ); // 1 residue AtomTree.
115  tree_atoms2d[ 1 ].resize( residue_representatives_[ ii ]->natoms() );
116  kinematics::AtomPointer1D tree_atoms1d( residue_representatives_[ ii ]->natoms() );
117 
118  conformation::build_residue_tree( 1, *residue_representatives_[ ii ], tree_atoms1d, true );
119  std::copy( tree_atoms1d.begin(), tree_atoms1d.end(), tree_atoms2d[1].begin() );
120  atom_tree_representatives_[ ii ] = new kinematics::AtomTree( tree_atoms2d );
121 
122  residue_representatives_[ ii ]->seqpos( resid ); // restore the original sequence position
123  }
124 }
125 
127  rotamer_set::RotamerSet const & rset,
128  core::Size resid
129 ) :
130  active_restype_( 0 ),
131  residue_uptodate_( true ),
132  atom_tree_uptodate_( true ),
133  atom_tree_representatives_( rset.get_n_residue_types() ),
134  residue_representatives_( atom_tree_representatives_.size() )
135 {
136 
137  for ( Size ii = 1; ii <= rset.get_n_residue_types(); ++ii ) {
138  residue_representatives_[ ii ] = rset.rotamer( rset.get_residue_type_begin(ii) )->clone();
139  residue_representatives_[ ii ]->seqpos( 1 ); // temporary -- while we construct the atom tree, pretend we're residue 1.
140  kinematics::AtomPointer2D tree_atoms2d( 1 ); // 1 residue AtomTree.
141  tree_atoms2d[ 1 ].resize( residue_representatives_[ ii ]->natoms() );
142  kinematics::AtomPointer1D tree_atoms1d( residue_representatives_[ ii ]->natoms() );
143 
144  conformation::build_residue_tree( 1, *residue_representatives_[ ii ], tree_atoms1d, true );
145  std::copy( tree_atoms1d.begin(), tree_atoms1d.end(), tree_atoms2d[1].begin() );
146  atom_tree_representatives_[ ii ] = new kinematics::AtomTree( tree_atoms2d );
147 
148  residue_representatives_[ ii ]->seqpos( resid ); // restore the original sequence position
149  }
150 }
151 
153 {}
154 
155 
157 {
158  assert( restype_index > 0 && restype_index <= atom_tree_representatives_.size() );
159  active_restype_ = restype_index;
162 }
163 
164 
165 chemical::ResidueType const &
167 {
168  return active_residue_->type();
169 }
170 
173 {
174  return active_residue_;
175 }
176 
177 /// @brief The responsibility for making sure that the active residue and the active atomtree
178 /// are in synch is offloaded to an external class so that the calls to "active_residue()" and
179 /// "active_atom_tree()" are as fast as possible (and bitwise const for future multithreaded use).
180 /// After a round of set_chi() calls, the user for this class must update the residue coordinates.
182 {
183  using namespace id;
184  using namespace conformation;
185  using namespace kinematics;
186 
187  residue_uptodate_ = true;
188  AtomTree const & tree( * atom_tree_representatives_[ active_restype_ ] );
189  Residue & rsd( *residue_representatives_[ active_restype_ ] );
190  if ( tree.residue_xyz_change_list_begin() != tree.residue_xyz_change_list_end() ) {
191  assert( *( tree.residue_xyz_change_list_begin() ) == 1 );
192  for ( Size ii = 1; ii <= rsd.natoms(); ++ii ) {
193  rsd.set_xyz( ii, tree.xyz( id::AtomID( ii, 1 ) ));
194  }
195 
196  tree.note_coordinate_change_registered();
197  }
198 
199  // copy chi angles from atomtree->res
200  for ( Size ii = 1, ii_end = rsd.nchi(); ii <= ii_end; ++ii ) {
201  //std::cout << "Chi: " << ii << " " << tree.dof( DOF_ID( AtomID( rsd.chi_atoms(ii)[4], 1), PHI )) << " and ";
202  rsd.chi()[ ii ] = numeric::constants::d::radians_to_degrees * tree.dof( DOF_ID( AtomID( rsd.chi_atoms(ii)[4], 1), PHI ));
203  //std::cout << rsd.chi()[ ii ] << std::endl;
204  }
205  active_residue_->update_actcoord();
206 }
207 
208 /// @brief See comments for update_residue(). After a call to "set_rescoords", the user must
209 /// call update_atomtree() to make sure the atomtree and the residue are in synch.
211 {
212  atom_tree_uptodate_ = true;
213 
215  conformation::Residue & rsd( *residue_representatives_[ active_restype_ ] );
216 
217  for ( Size ii = 1; ii <= rsd.natoms(); ++ii ) {
218  tree.set_xyz( id::AtomID( ii, 1 ), rsd.xyz( ii ) );
219  }
220 
221  // force a dof update
222  id::DOF_ID dofid( id::AtomID( 1, 1 ), id::RB1 );
223  tree.dof( dofid );
224 }
225 
227 {
228  return atom_tree_representatives_[ active_restype_ ]->dof( dofid );
229 }
230 
231 /// @brief Assigns the chi dihedral for the active restype. Must be followed by a call to
232 /// update_residue() before the next call to active_residue()
234 {
235  assert( chi_index > 0 && chi_index <= residue_representatives_[ active_restype_ ]->nchi() );
236  residue_uptodate_ = false;
238  id::DOF_ID( id::AtomID( residue_representatives_[ active_restype_ ]->chi_atoms( chi_index )[ 4 ], 1 ), id::PHI ),
239  numeric::constants::d::degrees_to_radians * value );
240 }
241 
243 {
244  Size const effchi = (chi_index==0)? 1 : chi_index;
245  Size const baseatom = (chi_index==0)? 3 : 4;
246 
247  assert( effchi > 0 && effchi <= residue_representatives_[ active_restype_ ]->nchi() );
248  residue_uptodate_ = false;
250  id::DOF_ID( id::AtomID( residue_representatives_[ active_restype_ ]->chi_atoms( effchi )[ baseatom ], 1 ), id::D ),
251  value );
252 }
253 
255 {
256  Size const effchi = (chi_index==0)? 1 : chi_index;
257  Size const baseatom = (chi_index==0)? 3 : 4;
258 
259  assert( effchi > 0 && effchi <= residue_representatives_[ active_restype_ ]->nchi() );
260  residue_uptodate_ = false;
262  id::DOF_ID( id::AtomID( residue_representatives_[ active_restype_ ]->chi_atoms( effchi )[ baseatom ], 1 ), id::THETA ),
263  numeric::constants::d::degrees_to_radians * value );
264 }
265 
266 /// @brief Assigns the coordinates for a residue. Must be followed by a call to
267 /// update_atom_tree() before the next cal to active_atom_tree().
269 {
270  /// trust the the input residue's chi angles are correct
271  assert( & res.type() == & residue_representatives_[ active_restype_ ]->type() );
272  for ( Size ii = 1; ii <= res.natoms(); ++ii ) {
273  residue_representatives_[ active_restype_ ]->set_xyz( ii, res.xyz( ii ) );
274  }
275  for ( Size ii = 1, ii_end = res.nchi(); ii <= ii_end; ++ii ) {
276  residue_representatives_[ active_restype_ ]->set_chi( ii, res.chi( ii ));
277  }
278  residue_representatives_[ active_restype_ ]->update_actcoord();
279  atom_tree_uptodate_ = false;
280 }
281 
282 /// @brief
283 void
285 {
286  /// trust the the input residue's chi angles are correct
287  assert( coords.size() == residue_representatives_[ active_restype_ ]->natoms() );
288  for ( Size ii = 1; ii <= residue_representatives_[ active_restype_ ]->natoms(); ++ii ) {
289  residue_representatives_[ active_restype_ ]->set_xyz( ii, coords[ ii ] );
290  }
291  //residue_representatives_[ active_restype_ ]->update_actcoord();
293  update_residue(); // now, copy the chi angles out of the atom tree
294 }
295 
296 /// @brief
297 void
299  utility::vector1< id::AtomID > const & atms, utility::vector1< Vector > const & coords )
300 {
301  assert( atms.size() == coords.size() );
302  Size natoms = atms.size();
303 
304  /// trust the the input residue's chi angles are correct
305  for ( Size ii = 1; ii <= natoms; ++ii ) {
306  residue_representatives_[ active_restype_ ]->set_xyz( atms[ii].atomno(), coords[ ii ] );
307  }
308  //residue_representatives_[ active_restype_ ]->update_actcoord();
310  update_residue(); // now, copy the chi angles out of the atom tree
311 }
312 
313 void
315 {
319 }
320 
322 {
324  for ( Size ii = 1; ii <= active_residue_->natoms(); ++ii ) {
325  active_residue_->set_xyz( ii, momento.coord( ii ) );
326  }
328  //update_residue();
329  for ( Size ii = 1; ii <= active_residue_->natoms(); ++ii ) {
330  assert( active_residue_->xyz( ii ).distance_squared( momento.coord( ii ) ) < 1e-6 );
331  }
332  using namespace id;
333  for ( Size ii = 1, ii_end = active_residue_->nchi(); ii <= ii_end; ++ii ) {
334  //std::cout << "Chi: " << ii << " " << tree.dof( DOF_ID( AtomID( rsd.chi_atoms(ii)[4], 1), PHI )) << " and ";
335  active_residue_->chi()[ ii ] = numeric::constants::d::radians_to_degrees * atom_tree_representatives_[ active_restype_ ]->dof( DOF_ID( AtomID( active_residue_->chi_atoms(ii)[4], 1), PHI ));
336  /*std::cout << " chi reported:" << active_residue_->chi()[ ii ] << " actual ";
337  std::cout << numeric::dihedral_degrees( active_residue_->xyz( active_residue_->chi_atoms(ii)[ 1 ] ),
338  active_residue_->xyz( active_residue_->chi_atoms(ii)[ 2 ] ),
339  active_residue_->xyz( active_residue_->chi_atoms(ii)[ 3 ] ),
340  active_residue_->xyz( active_residue_->chi_atoms(ii)[ 4 ] ) );
341  std::cout << std::endl;
342  assert( std::abs( active_residue_->chi()[ ii ] -
343  numeric::dihedral_degrees( active_residue_->xyz( active_residue_->chi_atoms(ii)[ 1 ] ),
344  active_residue_->xyz( active_residue_->chi_atoms(ii)[ 2 ] ),
345  active_residue_->xyz( active_residue_->chi_atoms(ii)[ 3 ] ),
346  active_residue_->xyz( active_residue_->chi_atoms(ii)[ 4 ] )) < 1e-6 ) );*/
347  }
348 
349 }
350 
351 
353  pose::Pose const & pose,
354  rotamer_set::RotamerSets const & rsets
355 ) :
356  //rotsets_( rotsets ),
357  resid_2_moltenresid_( pose.total_residue(), 0 ),
358  moltenresid_2_resid_( rsets.nmoltenres() ),
359  res_collections_( rsets.nmoltenres() )
360 {
361  for ( Size ii = 1; ii <= rsets.nmoltenres(); ++ii ) {
362  resid_2_moltenresid_[ rsets.moltenres_2_resid( ii ) ] = ii;
363  moltenresid_2_resid_[ ii ] = rsets.moltenres_2_resid( ii );
365  *rsets.rotamer_set_for_moltenresidue( ii ),
367  );
368  }
369 }
370 
371 
373  pose::Pose const & pose,
374  task::PackerTask const & task
375 ) :
376  //rotsets_( rotsets ),
377  resid_2_moltenresid_( pose.total_residue(), 0 ),
378  moltenresid_2_resid_( task.num_to_be_packed() ),
379  res_collections_( task.num_to_be_packed() )
380 {
381  Size count_moltenres( 0 );
382  for ( Size ii = 1; ii <= pose.total_residue(); ++ii ) {
383  if ( ! task.being_packed( ii ) ) continue;
384  ++count_moltenres;
385  resid_2_moltenresid_[ ii ] = count_moltenres;
386  moltenresid_2_resid_[ count_moltenres ] = ii;
387  res_collections_[ count_moltenres ] =
388  new ResidueAtomTreeCollection( task.residue_task( ii ), pose.conformation(), pose.residue( ii ) );
389  }
390 }
391 
393  pose::Pose const & /*pose*/,
394  rotamer_set::RotamerSet const & rset,
395  Size resid
396 )
397 {
398  res_collections_.resize( 1 );
399  res_collections_[ 1 ] = new ResidueAtomTreeCollection( rset, resid );
400 }
401 
403  pose::Pose const & pose,
404  task::ResidueLevelTask const & rltask,
405  Size resid
406 )
407 {
408  res_collections_.resize( 1 );
409  res_collections_[ 1 ] = new ResidueAtomTreeCollection( rltask, pose.conformation(), pose.residue( resid ) );
410 }
411 
413 
416 {
417  return * res_collections_[ moltenresid ];
418 }
419 
422 {
423  return * residue_atomtree_collection_op( resid );
424 }
425 
428 {
429  if ( resid_2_moltenresid_.size() != 0 ) {
430  assert( resid_2_moltenresid_[ resid ] != 0 );
431  return res_collections_[ resid_2_moltenresid_[ resid ] ];
432  } else {
433  assert( res_collections_.size() == 1 );
434  return res_collections_[ 1 ];
435  }
436 }
437 
438 } // namespace scmin
439 } // namespace pack
440 } // namespace core