Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ResiduePairJump.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 src/protocols/jumping/ResiduePairJump.cc
11 /// @brief a class to create jump transform from a pair of residues
12 /// @detailed
13 /// This class is to create possible jump transforms between a pair of residues
14 /// when their sidechains are locked in certain geometry constraints. It starts
15 /// from the predefined constraints and takes backbone-independent rotamer conformation
16 /// into account and reversely generate their backbone positions. Then a jump transform is
17 /// measured.
18 /// @author Chu Wang
19 
20 // Unit Headers
22 
23 // Package Headers
24 
25 // Project Headers
28 // AUTO-REMOVED
31 #include <core/fragment/Frame.hh>
35 #include <core/graph/Graph.hh>
41 #include <core/pose/Pose.hh>
44 // AUTO-REMOVED #include <core/pack/dunbrack/SingleResidueDunbrackLibrary.hh>
45 
46 // ObjexxFCL Headers
47 // AUTO-REMOVED #include <ObjexxFCL/string.functions.hh>
48 // Utility headers
49 #include <numeric/conversions.hh>
50 #include <numeric/xyzVector.hh>
51 // AUTO-REMOVED #include <utility/vector1.hh>
52 #include <utility/exit.hh>
53 
54 //// C++ headers
55 #include <string>
56 
57 #include <core/id/AtomID.hh>
58 #include <core/id/NamedAtomID.hh>
59 #include <utility/vector1.hh>
60 
61 
62 namespace protocols {
63 namespace jumping {
64 
65 
67 
69 
70 
71 ///@brief constructed by residue_type
73  core::chemical::ResidueType const & residue_type
74 ) :
75  residueType_( residue_type.clone() ),
76  fixResidue_( ! residue_type.is_protein() )
77 {}
78 /////////////////////////////////////////////////////////////////////
79 //ResiduePairJumpSingle
80 void
82  utility::vector1< std::string > const & jump_atoms
83 )
84 {
85  jumpAtoms_ = jump_atoms;
86 }
87 
88 /////////////////////////////////////////////////////////////////////
89 void
91  core::Size i,
92  std::string const atom_name
93 )
94 {
95  jumpAtoms_.resize(i,"");
96  jumpAtoms_[i] = atom_name;
97 }
98 /////////////////////////////////////////////////////////////////////
99 void
101  utility::vector1< std::string > const & cst_atoms
102 )
103 {
104  cstAtoms_ = cst_atoms;
105 }
106 /////////////////////////////////////////////////////////////////////
107 void
109  core::Size i,
110  std::string const atom_name
111 )
112 {
113  cstAtoms_.resize(i,"");
114  cstAtoms_[i] = atom_name;
115 }
116 
119 {
120  return residueType_;
121 }
122 
123 
124 /////////////////////////////////////////////////////////////////////
125 //ResiduePairJump
126 
127 
128 // empty constructor
131 
132 // constructed by two input ResidueTypes
134  core::chemical::ResidueType const & residue1,
135  core::chemical::ResidueType const & residue2
136 )
137 {
138  residues_.push_back( new ResiduePairJumpSingle( residue1 ) );
139  residues_.push_back( new ResiduePairJumpSingle( residue2 ) );
140 }
141 
142 void
144  core::chemical::ResidueType const & residue1,
145  core::chemical::ResidueType const & residue2
146 )
147 {
148  residues_.clear();
149  cstInfoMap_.clear();
150  residues_.push_back( new ResiduePairJumpSingle( residue1 ) );
151  residues_.push_back( new ResiduePairJumpSingle( residue2 ) );
152 }
153 /////////////////////////////////////////////////////////////////////
154 void
156  core::chemical::ResidueType const & residue
157 )
158 {
159  if ( residues_.size() < 2 ) {
160  cstInfoMap_.clear();
161  residues_.push_back( new ResiduePairJumpSingle(residue) );
162  } else {
163  utility_exit_with_message("ResiduePairJump can only take two residues\n");
164  }
165 }
166 
167 
168 /////////////////////////////////////////////////////////////////////
169 /// @details add a value to cst type
170 void
172  cstType type,
173  core::Real value
174 )
175 {
176  cstInfoMapIterator it = cstInfoMap_.find( type );
177  if ( it == cstInfoMap_.end() ) {
178  // not in map yet, add it
179  utility::vector1< core::Real > value_vector;
180  value_vector.push_back( value );
181  cstInfoMap_.insert( std::make_pair( type, value_vector ) );
182  } else {
183  utility::vector1< core::Real > & value_vector( it->second );
184  bool redundant = false;
185  for ( core::Size i = 1; i <= value_vector.size(); ++i ) {
186  if ( value == value_vector[i] ) {
187  redundant = true;
188  break;
189  }
190  }
191  if ( ! redundant ) value_vector.push_back( value );
192  }
193 }
194 /////////////////////////////////////////////////////////////////////
195 /// @details add a vector of values to cstInfo type
196 void
198  cstType type,
199  utility::vector1< core::Real > const & values
200 )
201 {
202  for ( core::Size i = 1; i <= values.size(); ++i ) {
203  set_cstInfo( type, values[i] );
204  }
205 }
206 /////////////////////////////////////////////////////////////////////////////////////////////////////////
209 {
210  using namespace core;
211  using namespace core::fragment;
212 
213  // create a frame with proper data structures Frame->FragData->(UpJumpSRFD and DownJumpSRFD)
214  core::kinematics::RT jump_rt;
215  UpJumpSRFDOP up_jump = new UpJumpSRFD(residues_[1]->residueType()->name1());
216  DownJumpSRFDOP down_jump = new DownJumpSRFD( jump_rt, jumpAtoms(2), jumpAtoms(1), residues_[2]->residueType()->name1() );
217  FragDataOP jump_frag = new FragData();
218  jump_frag->add_residue(up_jump);
219  jump_frag->add_residue(down_jump);
220  JumpingFrameOP ResiduePairJumpFrame = new JumpingFrame( 1, 2, 2 ); // from residue 1 to 2
221  ResiduePairJumpFrame->set_pos( 1, 1);
222  ResiduePairJumpFrame->set_pos( 2, 2);
223  ResiduePairJumpFrame->add_fragment( jump_frag );
224 
226 
227  for( Size i = 1; i <= dof_conformers_.size(); ++i ) {
229  //miniPose_->dump_pdb("chutmp_div"+right_string_of(i,4, '0') + ".pdb");
230  ResiduePairJumpFrame->steal( *miniPose_ );
231  }
232 
233  return ResiduePairJumpFrame;
234 }
235 /////////////////////////////////////////////////////////////////////
236 void
238 {
239  using namespace core;
240 
241  runtime_assert( cstAtoms_defined() );
242 
243  miniPose_ = new core::pose::Pose();
244 
245  // initial configuration for how these two residues are connected
246 // Real init_phi = numeric::conversions::radians(180.0);
247 // Real init_theta = numeric::conversions::radians(60.0);
248 // Real init_d = 2.0;
249 // // connection numbers for new connections added to these residues
250 // Size anchor_connection, root_connection;
251  // operation for each of the two residues created and added
252  for ( Size i = 1; i <= 2; ++i ) {
254  // // create atomIcoord
255 // chemical::AtomICoor icoor( init_phi, init_theta, init_d,
256 // rsd->cstAtoms(1), rsd->cstAtoms(2), rsd->cstAtoms(3), *(rsd->residueType()) );
257 // // add a residue connection
258 // Size connection = rsd->residueType()->add_residue_connection( rsd->cstAtoms(1) );
259 // rsd->residueType()->residue_connection(connection).icoor( icoor );
260  conformation::ResidueOP new_residue( conformation::ResidueFactory::create_residue( *( rsd->residueType() ) ) );
261 
262  if ( i == 1 ) {
263  //anchor_connection = connection;
264  miniPose_->append_residue_by_jump( *new_residue, 1 ); // the first residue attached by jump
265  } else {
266  //root_connection = connection;
267  // the second residue is attched to the first residue by bond with defined connection
268  //miniPose_->append_residue_by_bond( *new_residue, true, root_connection, 1, anchor_connection, false );
269  miniPose_->append_residue_by_jump( *new_residue, 1, residues_[1]->cstAtoms(1), rsd->cstAtoms(1), false );
270  }
271  }
272  // build rotamers for each of the sidechains if applicable and add
274 
276 
277  //setup_cstTypeToDofMap();
278 
279  //miniPose_->dump_pdb("chutmp_miniPose.pdb");
280 
281  return;
282 }
283 /////////////////////////////////////////////////////////////////////////////////////////////////////////
284 // void ResiduePairJump::setup_cstTypeToDofMap()
285 // {
286 // // erase any existing data
287 // cstTypeToDofMap_.clear();
288 
289 // // six cst types will be mapped to DOFs of the three atoms in residue 2
290 // ResiduePairJumpSingleOP rsd = residues_[2];
291 // core::chemical::ResidueTypeOP rsd_type = rsd->residueType();
292 // core::id::AtomID atom_id1( rsd_type->atom_index(rsd->cstAtoms(1)), 2 );
293 // core::id::AtomID atom_id2( rsd_type->atom_index(rsd->cstAtoms(2)), 2 );
294 // core::id::AtomID atom_id3( rsd_type->atom_index(rsd->cstAtoms(3)), 2 );
295 // core::id::AtomID bogus_id( 0, 0 );
296 
297 // core::id::DOF_ID dof_id12( miniPose_->atom_tree().bond_length_dof_id( atom_id1, atom_id2 ) );
298 // core::id::DOF_ID dof_id23( miniPose_->atom_tree().bond_length_dof_id( atom_id2, atom_id3 ) );
299 // core::id::DOF_ID dof_id13( miniPose_->atom_tree().bond_length_dof_id( atom_id1, atom_id3 ) );
300 // // sanity check: downstream cstAtoms 1 2 and 3 have to be connected in atom_tree, either 1->2->3 or 2<-1->3
301 // if ( ! ( dof_id12.valid() && ( dof_id23.valid() || dof_id13.valid() ) ) ) {
302 // utility_exit_with_message("setup_cstTypeToDofMap() downstream cstAtoms are not connected in atom tree!\n");
303 // }
304 
305 // for ( cstInfoMapIterator it = cstInfoMap_.begin(), it_end = cstInfoMap_.end(); it != it_end; ++it ) {
306 // cstType cst_type = it->first;
307 // core::id::AtomID atom_id;
308 // core::id::DOF_Type dof_type;
309 // if ( cst_type == disAB ) {
310 // atom_id = atom_id1;
311 // dof_type = core::id::D;
312 // } else if ( cst_type == angleA ) {
313 // atom_id = atom_id1;
314 // dof_type = core::id::THETA;
315 // } else if ( cst_type == dihedralA ) {
316 // atom_id = atom_id1;
317 // dof_type = core::id::PHI;
318 // } else if ( cst_type == angleB ) {
319 // atom_id = atom_id2;
320 // dof_type = core::id::THETA;
321 // } else if ( cst_type == dihedralAB ) {
322 // atom_id = atom_id2;
323 // dof_type = core::id::PHI;
324 // } else if ( cst_type == dihedralB ) {
325 // runtime_assert( dof_id23.valid() ); // dihedralB only meaningful when atom3 is connected atom2
326 // atom_id = atom_id3;
327 // dof_type = core::id::PHI;
328 // } else if ( cst_type == rot1 || cst_type == rot2 ) {
329 // // for sidechain rot1 and rot2, they do not correspond to one single DOF
330 // // so set it as BOGUS_ID to prevent accidental lookup
331 // atom_id = bogus_id;
332 // dof_type = core::id::PHI;
333 // } else {
334 // utility_exit_with_message("unknown cstType defined in ResiduePairJump\n" );
335 // }
336 // core::id::DOF_ID dof_id( atom_id, dof_type);
337 // cstTypeToDofMap_.insert( std::make_pair( cst_type, dof_id ) );
338 // }
339 
340 // return;
341 // }
342 /////////////////////////////////////////////////////////////////////////////////////////////////////////
343 void
345  dofType type,
346  core::Size max_index
347 )
348 {
349  if ( max_index == 0 ) return;
350 
351  if ( dof_conformers_.size() == 0 ) {
352  // is empty, generate initial vector
353  for ( core::Size i = 1; i <= max_index; ++i ) {
354  std::map< dofType, core::Size > map;
355  map.insert( std::make_pair( type, i ) );
356  dof_conformers_.push_back( map );
357  }
358  } else {
359  // conformers exist, diversify them if not redundant
361  dof_conformers_.clear();
362  for ( core::Size j = 1; j <= tmp_conformers.size(); ++j ) {
363  std::map< dofType, core::Size > map( tmp_conformers[j] );
364  if ( map.find(type) == map.end() ) {
365  map.insert( std::make_pair( type, 0 ) );
366  for ( core::Size i = 1; i <= max_index; ++i ) {
367  map[type] = i;
368  dof_conformers_.push_back( map );
369  }
370  }
371  }
372  }
373 }
374 /////////////////////////////////////////////////////////////////////////////////////////////////////////
375 void
377 {
378 
379  dof_conformers_.clear();
380  diversify_dof_conformers( rot1, rotsets_[1]->num_rotamers() );
381  diversify_dof_conformers( rot2, rotsets_[2]->num_rotamers() );
383 
384  return;
385 }
386 /////////////////////////////////////////////////////////////////////////////////////////////////////////
389  std::map< dofType, core::Size > const & conformer_map
390 )
391 {
392  for ( std::map< dofType, core::Size >::const_iterator it = conformer_map.begin(), it_end = conformer_map.end();
393  it != it_end; it++ ) {
394  dofType type = it->first;
395  core::Size index = it->second;
396  if ( ( type == rot1 ) || (type == rot2) ) {// sidechain rotamer dofs
397  core::Size seqpos = (type==rot1) ? 1 : 2;
398  core::conformation::ResidueCOP rotamer = rotsets_[seqpos]->rotamer(index);
399  for ( core::Size i = 1; i <= rotamer->nchi(); ++i ) {
400  miniPose_->set_chi( i, seqpos, rotamer->chi()[i] );
401  }
402  } else { // cst_jump dofs
404  core::id::AtomID jump_atom_id( rsd->residueType()->atom_index(rsd->cstAtoms(1)), 2 );
405  miniPose_->set_jump( jump_atom_id, cst_jumps_[index] );
406  }
407  }
408  return miniPose_;
409 }
410 /////////////////////////////////////////////////////////////////////////////////////////////////////////
411 void
413 {
414  using namespace core::scoring;
415 
416  runtime_assert( miniPose_->total_residue() == 2 );
417 
418  // set up a scorefxn and packer_neighbor_graph for build_rotamers function
421  task->initialize_from_command_line().restrict_to_repacking();
422  (*scorefxn)(*miniPose_);
423  utility::vector1< bool > task_mask( miniPose_->total_residue(), true );
424  for ( core::Size which = 1; which <= residues_.size(); ++which ) {
425  ResiduePairJumpSingleOP rsd = residues_[which];
426 
427  // create one residue pose and generate an empty rotset
430  rotset->set_resid(which);
431  // unless this residue needs to be fixed, build rotamers into this RotamerSet
432  if ( ! rsd->fixResidue() ) {
433  //put phi/psi at popular beta-strand conformation for most unconstrained rotamer conforamtions
434  miniPose_->set_phi(which, -90.0);
435  miniPose_->set_psi(which, 120.0);
436  // set up a simple packer task with this single residue enabled
437  task_mask[which] = true;
438  task->restrict_to_residues( task_mask );
439  core::graph::GraphOP packer_neighbor_graph( core::pack::create_packer_graph( *miniPose_, *scorefxn, task ) );
440  // build possible rotamers for this residue
441  rotset->build_rotamers( *miniPose_, *scorefxn, *task, packer_neighbor_graph );
442  task_mask[which] = false;
443  }
444  // add it into rotsets_ container
445  rotsets_.push_back( rotset );
446  }
447 }
448 /////////////////////////////////////////////////////////////////////////////////////////////////////////
449 void
451 {
453 
454  // generate all combinations of cst_conformers
456 
457  // set up atoms to define the jump transform, from cstAtoms
458  utility::vector1< Vector > atoms_xyz;
459  for ( Size i = 1; i <= 2; ++i ) {
460  for ( Size j = 1; j <= 3 ; ++j ) {
461  atoms_xyz.push_back( miniPose_->xyz( core::id::NamedAtomID( jumpAtoms(i)[j], i ) ) );
462  }
463  }
464  // for each cst conformer conmbination, generate a jump transform
465  for ( Size i = 1; i <= cst_conformers_.size(); ++i ) {
466  std::map< cstType, core::Size > const & conformer( cst_conformers_[i] );
467  utility::vector1< core::Real > cst_values(6);
468  for ( std::map< cstType, core::Size >::const_iterator it = conformer.begin(), it_end = conformer.end(); it != it_end; ++it ) {
469  cstType type = it->first;
470  Size index = it->second;
471  core::Real value = cstInfoMap_.find(type)->second[index];
472  if ( type != disAB ) value = numeric::conversions::radians(value);
473  cst_values[Size(type)] = value;
474  }
476  jump.from_bond_cst( atoms_xyz, cst_values );
477  cst_jumps_.push_back( jump );
478  }
479  return;
480 }
481 /////////////////////////////////////////////////////////////////////////////////////////////////////////
482 void
484  cstType type,
485  core::Size max_index
486 )
487 {
488  if ( cst_conformers_.size() == 0 ) {
489  // is empty, generate initial vector
490  for ( core::Size i = 1; i <= max_index; ++i ) {
491  std::map< cstType, core::Size > map;
492  map.insert( std::make_pair( type, i ) );
493  cst_conformers_.push_back( map );
494  }
495  } else {
496  // conformers exist, diversify them if not redundant
498  cst_conformers_.clear();
499  for ( core::Size j = 1; j <= tmp_conformers.size(); ++j ) {
500  std::map< cstType, core::Size > map( tmp_conformers[j] );
501  if ( map.find(type) == map.end() ) {
502  map.insert( std::make_pair( type, 0 ) );
503  for ( core::Size i = 1; i <= max_index; ++i ) {
504  map[type] = i;
505  cst_conformers_.push_back( map );
506  }
507  }
508  }
509  }
510 }
511 /////////////////////////////////////////////////////////////////////////////////////////////////////////
512 void
514 {
515  for ( cstInfoMapIterator it = cstInfoMap_.begin(), it_end = cstInfoMap_.end(); it != it_end; ++it ) {
516  diversify_cst_conformers( it->first, it->second.size() );
517  }
518  return;
519 }
520 ///////////////////////////////////////////////////////////////////////////////////////////////
521 } //protocols
522 } //jumping
523 
524