Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
AlignPoseToInvrotTreeMover.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 // :noTabs=false:tabSize=4:indentSize=4:
4 //
5 // (c) Copyright Rosetta Commons Member Institutions.
6 // (c) This file is part of the Rosetta software suite and is made available under license.
7 // (c) The Rosetta software is developed by the contributing members of the Rosetta Commons.
8 // (c) For more information, see http://www.rosettacommons.org. Questions about this can be
9 // (c) addressed to University of Washington UW TechTransfer, email: license@u.washington.edu.
10 
11 /// @file protocols/toolbox/match_enzdes_util/InvrotTreeNodeBase.hh
12 /// @brief Forward declaration for inverse rotamer tree node base
13 /// @author Florian Richter, flosopher@gmail.com, mar 2012
14 
15 
16 /// unit headeers
18 
19 // package headers
25 
26 
27 ///project headers
28 #include <basic/options/option.hh>
29 #include <basic/options/keys/match.OptionKeys.gen.hh>
30 
33 #include <core/id/AtomID.hh>
34 #include <core/id/AtomID_Map.hh>
36 #include <core/pose/Pose.hh>
37 #include <core/pose/util.hh>
38 #include <core/scoring/rms_util.hh>
39 #include <core/types.hh>
41 
42 #include <basic/Tracer.hh>
43 
44 #include <numeric/random/random.hh>
45 
46 //utility headers
47 #include <utility/pointer/ReferenceCount.hh>
48 #include <utility/vector1.fwd.hh>
49 
50 // C++ headers
51 
52 namespace protocols {
53 namespace toolbox {
54 namespace match_enzdes_util {
55 
56 static basic::Tracer TR( "protocols.toolbox.match_enzdes_util.AlignPoseToInvrotTreeMover" );
57 
58 
60  InvrotTreeCOP invrot_tree,
62  ) : Mover(),
63  add_target_to_pose_(false), invrot_tree_(invrot_tree),
64  seqpos_(seqpos), all_invrots_( invrot_tree->collect_all_inverse_rotamers() )
65 {
67  //this is assuming that every InvrotCollector has the same number of geomcsts.
68  //i can't imagine a situation where this wouldn't be the case...
69  for( core::Size i =1; i <= all_invrots_[1]->invrots().size() - 1; ++i) geomcsts_for_superposition_.push_back(i);
70 }
71 
73 
76  return "AlignPoseToInvrotTreeMover";
77 }
78 
79 
80 /// @details this function does two things
81 /// 1. align one of the seqpos in the pose onto one of the invrots
82 /// in the tree
83 /// 2. grab the InvrotTarget residues and add them to the pose
84 /// this entails setting up the foldtree such that the target
85 /// residues are upstream of the rest of the pose
86 /// WARNING: right now this absolutely only works for InvrotTrees
87 /// where the target is one ligand
88 void
90 
91  //TR << "pose fold tree at apply start: " << pose.fold_tree() << std::endl; //debug
92  //for now, this only works for trees that have one target only
93  //changing it won't be hard, but need to think about how to communicate
94  //chosen state between this mover and other things using it
95  //prolly just use pose datacache
96  runtime_assert( invrot_tree_->num_target_states() == 1 );
97 
98  //1a. get the invrots and pick a random one from the first list
99  //utility::vector1< InvrotCollectorCOP > all_invrots( );
100  Size picked_collector( numeric::random::random_range( 1, all_invrots_.size() ) );
101  Size picked_geomcst( geomcsts_for_superposition_[ numeric::random::random_range( 1, geomcsts_for_superposition_.size() ) ] );
102  Size picked_rotamer( numeric::random::random_range(1, all_invrots_[ picked_collector ]->invrots()[picked_geomcst].size() ) );
103 
104  //temp debug
105  //picked_collector = 1;
106  //picked_geomcst = 1;
107  //picked_rotamer = 1;
108  //temp debug over
109 
110  std::list<core::conformation::ResidueCOP>::const_iterator list_it( all_invrots_[ picked_collector ]->invrots()[picked_geomcst].begin() );
111  for( Size i =1; i < picked_rotamer; ++i ) list_it++; //not ideal, but a list is what we have
112  core::conformation::ResidueCOP ranrot( *list_it );
113 
114  //1b. superimpose pose onto the ranrot,
115  //need to create a pose to use existing functionality
116  core::pose::Pose temp_pose;
117  temp_pose.append_residue_by_jump( *ranrot, (Size) 0 );
118  //temp_pose.dump_pdb("align_to_invrot_template.pdb");
119 
120  //pick a random residue
121  Size picked_seqpos( seqpos_->seqpos_for_geomcst(picked_geomcst)[ numeric::random::random_range(1,seqpos_->seqpos_for_geomcst(picked_geomcst).size() ) ] );
122  //temp debug
123  //picked_seqpos = seqpos_->seqpos_for_geomcst(picked_geomcst)[1];
124  //TR << "there are " << all_invrots.size() << " invrot collectors, picked collector has " << all_invrots[ picked_collector ]->invrots()[0].size() << " rotamers in 0th element." << std::endl;
125  //temp debug over
126 
129  atom_map.set( core::id::AtomID(pose.residue( picked_seqpos ).atom_index("CA"), picked_seqpos ), core::id::AtomID( temp_pose.residue(1).atom_index("CA"), 1 ) );
130  atom_map.set( core::id::AtomID(pose.residue( picked_seqpos ).atom_index("N"), picked_seqpos ), core::id::AtomID( temp_pose.residue(1).atom_index("N"), 1 ) );
131  atom_map.set( core::id::AtomID(pose.residue( picked_seqpos ).atom_index("C"), picked_seqpos ), core::id::AtomID( temp_pose.residue(1).atom_index("C"), 1 ) );
132  atom_map.set( core::id::AtomID(pose.residue( picked_seqpos ).atom_index("CB"), picked_seqpos ), core::id::AtomID( temp_pose.residue(1).atom_index("CB"), 1 ) );
133 
134  core::scoring::superimpose_pose( pose, temp_pose, atom_map );
135 
136  //pose.dump_pdb("align_to_invrot_after_align.pdb");
137 
138  //2. now we need to add the target residues to the aligned pose,
139  //and try to setup the fold tree the right way
140  //2a
141  std::list<core::conformation::ResidueCOP>::const_iterator target_it( all_invrots_[ picked_collector ]->invrots()[0].begin() );
142  Size first_target_seqpos( pose.total_residue() );
143  if( add_target_to_pose_ ){
144  first_target_seqpos++;
145  //have to add something to switch target res to centroid here
146  core::conformation::ResidueCOP ligres( this->switch_residue_type_set( *target_it, pose.residue(1).residue_type_set().name()) );
147 
148  pose.append_residue_by_jump( *ligres, pose.total_residue() );
149  target_it++;
150  //Size jump_num = pose.num_jump();
151 
152  //below commented out for now. need to think about how to best approach a
153  //case where the ligand can have different rotameric states
154  //for( ; target_it != all_invrots[ picked_collector ]->invrots()[0].end(); ++target_it){
155  // core::conformation::ResidueCOP ligres( this->switch_residue_type_set( *target_it, pose.residue(1).residue_type_set().name()) );
156  // pose.append_residue_by_jump( *ligres, first_target_seqpos );
157  //}
158  }
159  // if the target already was in the pose, that means its
160  // position got fucked up during the above superimpose call,
161  // so we need to reset it to the position in the invrot tree
162  // current implemenation absolutely only works for one ligand case
163  else{
164  pose.replace_residue( first_target_seqpos, *(this->switch_residue_type_set( *target_it, pose.residue(1).residue_type_set().name())), false );
165  }
166 
167  //2b. fold tree setup
168  //TR << "pose fold tree before mod: " << pose.fold_tree() << std::endl; //debug
169  this->setup_foldtree_around_anchor_invrot( pose, picked_seqpos, first_target_seqpos );
170  //TR << "pose fold tree after mod: " << pose.fold_tree() << std::endl; //debug
171 
172 }
173 
174 void
176  bool const setting
177 )
178 {
179  add_target_to_pose_ = setting;
180 }
181 
182 void
184  EnzConstraintIOCOP enzcst_io )
185 {
186 
187  utility::vector1< core::Size > found_geomcsts;
188  for( core::Size i = 1; i <= enzcst_io->num_mcfi_lists(); ++i ){
189  std::map< std::string, utility::vector1< std::string > > const &
190  alg_info( enzcst_io->mcfi_list( i )->mcfi( 1 )->algorithm_inputs() );
191 
192  if( alg_info.find("invrot_tree") != alg_info.end() ){
193  utility::vector1< std::string > const & info( alg_info.find( "invrot_tree" )->second );
194  for( core::Size line = 1; line <= info.size(); ++line ){
195  std::istringstream infostr( info[ line ] );
196  std::string first;
197  infostr >> first;
198  std::cout << "'" << first << "'" << std::endl;
199  if( first == "superpose" ){
200  found_geomcsts.push_back( i );
201  break;
202  }
203  }
204  }
205  }
206  if( found_geomcsts.size() != 0 ){
207  geomcsts_for_superposition_ = found_geomcsts;
208  TR << "Superposition of the pose allowed on invrot/seqpos pairs from the following constraint blocks: ";
209  for( core::Size i =1; i <= geomcsts_for_superposition_.size(); ++i ) TR << geomcsts_for_superposition_[i] << " ";
210  TR << std::endl;
211  }
212 }
213 
214 /// @details the simplest possible implementation for now
215 /// assumes the pose only has one chain
216 void
218  core::pose::Pose & pose,
219  Size const anchor_seqpos,
220  Size const first_target_seqpos ) const
221 {
222 
223  using namespace core::kinematics;
224  FoldTree new_fold_tree;
225  new_fold_tree.add_edge( anchor_seqpos, 1, Edge::PEPTIDE );
226  new_fold_tree.add_edge( anchor_seqpos, first_target_seqpos - 1, Edge::PEPTIDE );
227  Size num_jumps_to_add( pose.total_residue() - first_target_seqpos + 1 );
228  for( Size i =0; i < num_jumps_to_add; ++i ){
229  //TR << "URZ adding jump between res " << anchor_seqpos << " of restype " << pose.residue_type( anchor_seqpos ).name() << " and " << first_target_seqpos + i << ", which is of restype " << pose.residue_type( first_target_seqpos + i ).name() << std::endl;
230  new_fold_tree.add_edge( anchor_seqpos, first_target_seqpos +i, i + 1 );
231  }
232  if( !new_fold_tree.check_fold_tree() ) {
233  utility_exit_with_message("Invalid fold tree after trying to set up around invrot anchor residue");
234  }
235  pose.fold_tree( new_fold_tree );
236 }
237 
241  std::string const desired_restype_set_name
242 ) const{
243 
244  if( desired_restype_set_name != residue->residue_type_set().name() ){
245  core::pose::PoseOP temp_pose = new core::pose::Pose();
246  temp_pose->append_residue_by_jump( *residue, (Size) 0 );
247  core::util::switch_to_residue_type_set( *temp_pose, desired_restype_set_name );
248  residue = &(temp_pose->residue(1));
249  }
250  return residue;
251 }
252 
253 }
254 }
255 }