Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ModifyStoredLigandRBConfsMovers.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 .cc file for movers that mess around with additional ligand rigid body conformations
11 /// stored in the enzdes cacheable observer
12 /// @brief
13 /// @author Florian Richter, floric@u.washington.edu, oct 09
14 
15 
16 //unit headers
18 
19 //package headers
21 
22 //project headers
23 //#include <core/conformation/Conformation.hh>
25 #include <core/id/AtomID.hh>
28 //#include <core/pack/rtmin.hh>
32 #include <core/pose/Pose.hh>
34 #include <basic/Tracer.hh>
37 
38 // numeric headers
39 #include <numeric/random/random.hh>
40 #include <numeric/conversions.hh>
41 
42 // C++ headers
43 #include <set>
44 
45 #include <utility/vector1.hh>
46 
47 
48 //debug headers
49 //#include <fstream>
50 //#include <core/io/pdb/pose_io.hh>
51 //#include <utility/string_util.hh>
52 
53 namespace protocols {
54 namespace enzdes {
55 
56 static basic::Tracer tr("protocols.enzdes.ModifyStoredLigandRBConfsMovers");
57 //static core::Size applycalls_ = 0;
58 
60  : parent( name ) {}
61 
63 
66  return "ModifyStoredRBConfs";
67 }
68 
69 void
71  core::pose::Pose & pose,
72  core::conformation::Residue & rescoords
73 ) const
74 {
75  Size seqpos( rescoords.seqpos() );
76  runtime_assert( pose.residue( seqpos ).type().name3() == rescoords.type().name3() );
77  runtime_assert( pose.residue( seqpos ).natoms() == rescoords.natoms() );
78  core::Size res_atoms( pose.residue( seqpos ).natoms() );
79 
80  for( core::Size atm = 1; atm <= res_atoms; ++atm ){
81  core::PointPosition save_pos( pose.residue( seqpos ).xyz( atm ) );
82  core::Size other_ind( rescoords.atom_index( pose.residue( seqpos ).atom_name( atm ) ) );
83  pose.set_xyz( core::id::AtomID ( atm, seqpos ), rescoords.xyz( other_ind ) );
84  rescoords.set_xyz( other_ind, save_pos );
85  }
86 }
87 
90  core::pose::Pose const & pose,
92 ) const
93 {
94  utility::vector1< Real > to_return( confs.size(), 0.0 );
95  if( to_return.size() == 0 ) return to_return;
96  Size center(0), nbr1(0), nbr2(0);
97  core::conformation::Residue const & pose_res( pose.residue( confs[1]->seqpos() ) );
98  runtime_assert( confs[1]->name3() == pose_res.name3() );
99  confs[1]->select_orient_atoms( center, nbr1, nbr2 );
100  runtime_assert( confs[1]->atom_name( center ) == pose_res.atom_name( center ) );
101  runtime_assert( confs[1]->atom_name( nbr1 ) == pose_res.atom_name( nbr1 ) );
102  runtime_assert( confs[1]->atom_name( nbr2 ) == pose_res.atom_name( nbr2 ) );
103 
104  for( Size i = 1; i <= confs.size(); ++i ){
105  Real min_msd( pose_res.xyz( center ).distance_squared( confs[i]->xyz(center) ) + pose_res.xyz( nbr1 ).distance_squared( confs[i]->xyz(nbr1) ) + pose_res.xyz( nbr2 ).distance_squared( confs[i]->xyz(nbr2) ) );
106  for( Size j = 1; j < i; ++j){
107  Real cur_msd( confs[j]->xyz( center ).distance_squared( confs[i]->xyz(center) ) + confs[j]->xyz( nbr1 ).distance_squared( confs[i]->xyz(nbr1) ) + confs[j]->xyz( nbr2 ).distance_squared( confs[i]->xyz(nbr2) ) );
108  if( cur_msd < min_msd ) min_msd = cur_msd;
109  }
110  to_return[i] = min_msd;
111  }
112  return to_return;
113 }
114 
115 
118 {
119  RBConfLists to_return;
120  toolbox::match_enzdes_util::EnzdesCacheableObserverCOP enz_obs( toolbox::match_enzdes_util::get_enzdes_observer( pose ) ); //toolbox::match_enzdes_util::get_enzdes_observer with const pose can return NULL
121  if ( !enz_obs ) return to_return;
122  std::map< core::Size, utility::vector1< core::conformation::ResidueCOP > > const & rb_confs( enz_obs->lig_rigid_body_confs() );
123  for( std::map< core::Size, utility::vector1< core::conformation::ResidueCOP > >::const_iterator map_it = rb_confs.begin(); map_it != rb_confs.end(); ++map_it ){
124  if( pose.residue( map_it->first ).type().is_ligand() ) to_return.push_back( map_it->second );
125  }
126  return to_return;
127 }
128 
129 void
131 {
132  for( core::Size i = 1; i <= rbs.size(); ++i ){
133  if( rbs[i].size() > 0 ){
134  set_rigid_body_confs_for_seqpos( rbs[i][1]->seqpos(), rbs[i], pose );
135  }
136  }
137 }
138 
139 void
141  core::Size seqpos,
143  core::pose::Pose & pose
144 ) const
145 {
146  toolbox::match_enzdes_util::get_enzdes_observer( pose )->set_rigid_body_confs_for_lig( seqpos, confs );
147 }
148 
150  Size num_total_rbconfs,
151  bool include_metals
152 ) : parent( "GenerateStoredRBConfs" ),
153  num_total_rbconfs_( num_total_rbconfs ), include_metals_(include_metals) {}
154 
156 
159  return "GenerateStoredRBConfs";
160 }
161 
162 /// @brief two things happen:
163 /// 1. for ligands which already have multiple
164 /// conformations stored, their number will be increased to num_total_rbconfs_
165 /// in case there are already more rb_confs than num_total_rb_confs_, nothing happens
166 /// 2. for ligands that don't have multiple conformations stored, num_total_rbconfs_
167 /// will be generated
168 void
170  core::pose::Pose & pose )
171 {
172  std::set< Size > present_confs_seqpos;
173  DiversifyStoredRBConfs diversifier( 0.08 );
174 
175  RBConfLists rb_confs( get_rigid_body_confs( pose ) );
176  //1.
177  for( Size i = 1; i <= rb_confs.size(); ++i ){
178  present_confs_seqpos.insert( rb_confs[i][1]->seqpos() );
179  for( Size j = rb_confs[i].size(); j <= num_total_rbconfs_; ++j ){
180  rb_confs[i].push_back( (rb_confs[i][1])->clone() );
181  }
182  diversifier.diversify_all_confs( pose, rb_confs[i] );
183  set_rigid_body_confs_for_seqpos( rb_confs[i][1]->seqpos(), rb_confs[i], pose );
184  }
185 
186  //2.
187  for( Size i = 1; i <= pose.total_residue(); ++i ){
188  if( pose.residue_type(i).is_ligand() && !( !include_metals_ && (pose.residue_type(i).natoms() <= 3) ) ){
189  if( present_confs_seqpos.find( i ) != present_confs_seqpos.end() ) continue;
190 
191  tr << num_total_rbconfs_ << " random new rigid body conformations to be used in packing will be generated for residue " << pose.residue(i).name() << " " << i << "." << std::endl;
193  for( Size j = 1; j <= num_total_rbconfs_; ++j ){
194  new_rb_confs.push_back( pose.residue( i ).clone() );
195  }
196  diversifier.diversify_all_confs( pose, new_rb_confs );
197  set_rigid_body_confs_for_seqpos( i, new_rb_confs, pose );
198  }
199  }
200 }
201 
203  : parent( "ApplyRandomStoredRBConf" ) {}
204 
206 
207 
208 void
210  core::pose::Pose & pose )
211 {
212 
213  RBConfLists rb_confs( get_rigid_body_confs( pose ) );
214  //pose.dump_pdb("random_apply_before.pdb");
215  for( core::Size i = 1; i <= rb_confs.size(); ++i ){
216  core::Size picked_conf( numeric::random::random_range( 1, rb_confs[i].size()) );
217  tr << "Randomly appying conf " << picked_conf << " of " << rb_confs[i].size() <<" for respos " << rb_confs[i][picked_conf]->seqpos() << std::endl;
218  core::conformation::ResidueOP exchange_res( rb_confs[i][picked_conf]->clone() );
219  swap_coordinates_in_pose( pose, *exchange_res );
220  rb_confs[i][picked_conf] = exchange_res;
221  }
222  //update the confs in the pose
223  set_rigid_body_confs( rb_confs, pose );
224  //pose.dump_pdb("random_apply_after.pdb");
225 }
226 
229  return "ApplyRandomStoredRBConf";
230 }
231 
232 
234  : parent( "MinimizeStoredRBConfs" ), sfxn_(sfxn), min_rms_(0.08) {}
235 
237 
238 
239 void
241  core::pose::Pose & pose )
242 {
243  RBConfLists rb_confs( get_rigid_body_confs( pose ) );
244  for( Size i = 1; i <= rb_confs.size(); ++i ){
245  if( rb_confs[i].size() > 0){
246  rb_minimize_all_confs( pose, rb_confs[i] );
247  set_rigid_body_confs_for_seqpos( rb_confs[i][1]->seqpos(), rb_confs[i], pose );
248  }
249  }
250 }
251 
254  return "MinimizeStoredRBConfs";
255 }
256 
257 void
259  core::pose::Pose const & pose,
261 ) const
262 {
263  //we need to make a copy of this pose that doesn't have the
264  //rigid body confs
265  //applycalls_++;
266  core::pose::Pose mod_pose = pose;
267  Size seqpos( confs[1]->seqpos() );
268  Size natoms( confs[1]->natoms() );
270  movemap->set_jump( pose.fold_tree().get_jump_that_builds_residue( seqpos ), true );
271  protocols::simple_moves::MinMover minmover( movemap, sfxn_, "dfpmin", 0.1, true );
272 
273  //I guess we need a task...
275  rtmin_task->initialize_from_command_line();
276  for( Size i = 1; i<= mod_pose.total_residue(); ++i ){
277  if( i == seqpos ) rtmin_task->nonconst_residue_task( i ).restrict_to_repacking();
278  else rtmin_task->nonconst_residue_task( i ).prevent_repacking();
279  }
280  //if( applycalls_ == 1 ) mod_pose.dump_pdb("apply1_start.pdb");
281 
282  for( Size conf = 1; conf <= confs.size(); ++conf ){
283  core::conformation::ResidueOP exchange_res( confs[conf]->clone() );
284  swap_coordinates_in_pose( mod_pose, *exchange_res );
285  //if( applycalls_ == 1 ) mod_pose.dump_pdb("before_rtmin_conf_"+utility::to_string( conf )+".pdb" );
286 
287  //note: ideally this would be rtmin, but i think it's too slow, especially
288  //with a large number of rigid body confs/rotamers...
289  //so let's do rotamer trials followed by a minimization
290  //core::pack::RTMin rtmin( false, true );
291  //rtmin.rtmin( mod_pose, *sfxn_, rtmin_task );
292  core::pack::rotamer_trials( mod_pose, *sfxn_, rtmin_task );
293  minmover.apply( mod_pose );
294  //if( applycalls_ == 1 ) mod_pose.dump_pdb("after_rtmin_conf_"+utility::to_string( conf )+".pdb" );
295  //now that the pose is rtmined, we need to get the new coordinates
296  core::conformation::Residue const & newpos( mod_pose.residue( seqpos ) );
297  for( core::Size atm = 1; atm <= natoms; ++atm ){
298  exchange_res->set_xyz( atm, newpos.xyz( exchange_res->atom_name( atm ) ) );
299  }
300  confs[conf] = exchange_res;
301  } //main rtmin loop over confs
302 
303  //debug
304  /*
305  if( applycalls_ == 1 ) {
306  core::Size atcounter(0);
307  std::ofstream out( "storeconfs_afterothermin.pdb" );
308  for( Size conf = 1; conf <= confs.size(); ++conf ){
309  out << "MODEL " << conf << " " << std::endl;
310  core::io::pdb::dump_pdb_residue( *confs[conf], atcounter, out );
311  out << "ENDMDL " << std::endl;
312  }
313  out.close();
314  }
315  */
316  //debug over
317 
318  //now we need to diversify stuff, so not all rbconfs were minimized to the exact same local minima
319  //diversify_rb_confs( pose, confs, min_rms_ );
320  DiversifyStoredRBConfs diversifier( min_rms_ );
321  diversifier.diversify_all_confs( pose, confs );
322 
323  //debug
324  /*
325  if( applycalls_ == 1 ) {
326  core::Size atcounter(0);
327  std::ofstream out( "storeconfs_afterdiversify.pdb" );
328  for( Size conf = 1; conf <= confs.size(); ++conf ){
329  out << "MODEL " << conf << " " << std::endl;
330  core::io::pdb::dump_pdb_residue( *confs[conf], atcounter, out );
331  out << "ENDMDL " << std::endl;
332  }
333  out.close();
334  }
335  */
336  //debug over
337 }
338 
339 
341  Real min_rms )
342  : parent( "DiversifyStoredRBConfs" ), min_rms_(min_rms), max_trials_(10) {}
343 
345 
346 void
348  core::pose::Pose & pose )
349 {
350 
351  RBConfLists rb_confs( get_rigid_body_confs( pose ) );
352  for( Size i = 1; i <= rb_confs.size(); ++i ){
353  if( rb_confs[i].size() > 0){
354  diversify_all_confs( pose, rb_confs[i] );
355  set_rigid_body_confs_for_seqpos( rb_confs[i][1]->seqpos(), rb_confs[i], pose );
356  }
357  }
358 }
359 
360 
363  return "DiversifyStoredRBConfs";
364 }
365 
366 void
368  core::pose::Pose const & pose,
370 ) const
371 {
372  core::pose::Pose mod_pose = pose;
373  Size natoms( confs[1]->natoms() );
374  Size seqpos( confs[1]->seqpos() );
375  protocols::rigid::RigidBodyPerturbMover simple_rigbod( mod_pose.fold_tree().get_jump_that_builds_residue( confs[1]->seqpos() ), numeric::conversions::degrees(0.05), min_rms_);
376 
377  for( Size i = 1; i <= max_trials_; ++i ){
378  utility::vector1< Real > min_dist( closest_orient_atoms_msd( pose, confs ) );
379  utility::vector1< Size > confs_to_change;
380  //tr << "before trial " << i << ", confs have the following rms: " << std::endl;
381  for( Size j = 1; j <= min_dist.size(); ++j ){
382  //tr << j << " has rms of " << min_dist[j] << std::endl;
383  if( min_dist[j] <= min_rms_ ) confs_to_change.push_back( j );
384  }
385  if( confs_to_change.size() == 0 ) break; // we're done
386 
387  for( Size j = 1; j <= confs_to_change.size(); ++j ){
388  Size conf( confs_to_change[j] );
389  core::conformation::ResidueOP exchange_res( confs[conf]->clone() );
390  swap_coordinates_in_pose( mod_pose, *exchange_res );
391  simple_rigbod.apply( mod_pose );
392  core::conformation::Residue const & newpos( mod_pose.residue( seqpos ) );
393  for( core::Size atm = 1; atm <= natoms; ++atm ){
394  exchange_res->set_xyz( atm, newpos.xyz( exchange_res->atom_name( atm ) ) );
395  }
396  confs[conf] = exchange_res;
397  }
398  }
399 }
400 
401 } // enzdes
402 } //protocols