Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
RelaxProtocolBase.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 relax_protocols
11 /// @brief protocols that are specific to relax
12 /// @detailed
13 /// @author Mike Tyka, Monica Berrondo
14 
15 //#include <protocols/jobdist/Jobs.hh>
16 
19 
21 
22 #include <core/io/pdb/pose_io.hh>
23 
30 //#include <core/scoring/rms_util.hh>
31 //#include <core/sequence/Sequence.hh>
32 #include <core/sequence/util.hh>
33 #include <core/pose/util.hh>
34 
38 
39 #include <core/pose/Pose.hh>
40 #include <core/pose/PDBInfo.hh>
43 #include <basic/options/keys/symmetry.OptionKeys.gen.hh>
44 
45 #include <protocols/loops/Loop.hh>
46 #include <protocols/loops/Loops.hh>
47 
48 #include <basic/options/option.hh>
49 #include <basic/options/keys/relax.OptionKeys.gen.hh>
50 #include <basic/options/keys/in.OptionKeys.gen.hh>
51 
54 
55 //*only for debug structures
59 #include <basic/options/keys/out.OptionKeys.gen.hh>
60 #include <basic/options/keys/run.OptionKeys.gen.hh>
61 
62 // ObjexxFCL Headers
63 #include <ObjexxFCL/string.functions.hh>
64 
65 #ifdef BOINC_GRAPHICS
66 #include <protocols/boinc/boinc.hh>
67 #endif
68 
69 #include <basic/Tracer.hh>
70 
72 //#include <protocols/jobdist/Jobs.hh>
73 //#include <protocols/jd2/JobDistributor.hh>
74 #include <protocols/jd2/util.hh>
75 
76 #include <utility/vector0.hh>
77 #include <utility/vector1.hh>
78 
79 using basic::T;
80 using basic::Error;
81 using basic::Warning;
82 
83 static basic::Tracer TR("protocols.relax.ClassicRelax");
84 
85 using namespace core;
86 using io::pdb::dump_pdb;
87 ////////////////////////////////////////////////////////////////////////////////////////////////////
88 
89 namespace protocols {
90 namespace relax {
91 
92 
93 
94 RelaxProtocolBase::RelaxProtocolBase( core::scoring::ScoreFunctionOP score_in ) :
95  parent( "RelaxProtocol" ),
96  min_type_("dfpmin_armijo_nonmonotone"),
97  scorefxn_( score_in )
98 {
99  set_defaults();
100 }
101 
103  parent( movername ),
104  min_type_("dfpmin_armijo_nonmonotone"),
105  scorefxn_( 0 )
106 {
107  set_defaults();
108 }
109 
111  parent( movername ),
112  min_type_("dfpmin_armijo_nonmonotone"),
113  scorefxn_(score_in )
114 {
115  set_defaults();
116 }
117 
118 
120 
122  core::pose::Pose const & pose,
123  core::kinematics::MoveMap & movemap
124 )
125 {
126  using namespace core::id;
127  if ( minimize_bond_lengths_ ) {
128  // 0 Default all bondlengths
129  // 1 backbone only
130  // 2 sidechain only
131  // 3 CA only (Ca-C,Ca-N and Ca-Cb)
132 
133  if (minimize_bondlength_subset_ == 0) {
134  movemap.set( core::id::D, true );
135  } else if ( minimize_bondlength_subset_ == 1) {
136  for ( Size ii = 1; ii <= pose.total_residue(); ++ii ) {
137  core::chemical::AtomIndices const & ii_mainchain_atoms( pose.residue(ii).mainchain_atoms() );
138  for ( Size jj = 1; jj <= ii_mainchain_atoms.size(); ++jj ) {
139  //if ( jj == 1 ) {
140  // if ( ii > 1 && pose.residue(ii).is_bonded( ii-1 ) && !pose.residue(ii).has_variant_type("CUTPOINT_UPPER")) {
141  // movemap.set( DOF_ID( AtomID( ii_mainchain_atoms[ jj ], ii ), core::id::D ), true );
142  // }
143  //} else {
144  movemap.set( DOF_ID( AtomID( ii_mainchain_atoms[ jj ], ii ), core::id::D ), true );
145  //}
146  }
147  }
148  } else if ( minimize_bondlength_subset_ == 2) {
149  for ( Size ii = 1; ii <= pose.total_residue(); ++ii ) {
150  core::conformation::Residue const &res_i = pose.residue(ii);
151  for ( Size jj = 1; jj <= res_i.natoms(); ++jj ) {
152  if (res_i.atom_is_backbone(jj)) continue;
153  movemap.set( DOF_ID( AtomID( jj, ii ), core::id::D ), true );
154  }
155  }
156  } else if ( minimize_bondlength_subset_ == 3) {
157  for ( Size ii = 1; ii <= pose.total_residue(); ++ii ) {
158  core::conformation::Residue const &res_i = pose.residue(ii);
159  if (res_i.type().has_atom_name( " C "))
160  movemap.set( DOF_ID( AtomID( res_i.atom_index(" C "), ii ), core::id::D ), true );
161  if (res_i.type().has_atom_name( " CA "))
162  movemap.set( DOF_ID( AtomID( res_i.atom_index(" CA "), ii ), core::id::D ), true );
163  if (res_i.type().has_atom_name( " CB "))
164  movemap.set( DOF_ID( AtomID( res_i.atom_index(" CB "), ii ), core::id::D ), true );
165  }
166  }
167  }
168 
169  if ( minimize_bond_angles_ ) {
170 
171 
172  // 0 Default all bondangles
173  // 1 backbone only
174  // 2 sidechain only
175  // 3 tau only
176  // 4 Ca-Cb only
177  if (minimize_bondangle_subset_ == 0) {
178  movemap.set( core::id::THETA, true );
179  } else if ( minimize_bondangle_subset_ == 1) {
180  for ( Size ii = 1; ii <= pose.total_residue(); ++ii ) {
181  core::chemical::AtomIndices const & ii_mainchain_atoms( pose.residue(ii).mainchain_atoms() );
182  for ( Size jj = 1; jj <= ii_mainchain_atoms.size(); ++jj ) {
183  //if ( jj == 1 || jj == 2 ) { //fpd add jj==2
184  // if ( ii > 1 && pose.residue(ii).is_bonded( ii-1 ) && !pose.residue(ii).has_variant_type("CUTPOINT_UPPER")) {
185  // movemap.set( DOF_ID( AtomID( ii_mainchain_atoms[ jj ], ii ), core::id::THETA ), true );
186  // }
187  //} else {
188  movemap.set( DOF_ID( AtomID( ii_mainchain_atoms[ jj ], ii ), core::id::THETA ), true );
189  //}
190  }
191  }
192  } else if ( minimize_bondangle_subset_ == 2) {
193  for ( Size ii = 1; ii <= pose.total_residue(); ++ii ) {
194  core::conformation::Residue const &res_i = pose.residue(ii);
195  for ( Size jj = 1; jj <= res_i.natoms(); ++jj ) {
196  if (res_i.atom_is_backbone(jj)) continue;
197  movemap.set( DOF_ID( AtomID( jj, ii ), core::id::THETA ), true );
198  }
199  }
200  } else if ( minimize_bondangle_subset_ == 3) {
201  for ( Size ii = 1; ii <= pose.total_residue(); ++ii ) {
202  core::conformation::Residue const &res_i = pose.residue(ii);
203  if (res_i.type().has_atom_name( " C "))
204  movemap.set( DOF_ID( AtomID( res_i.atom_index(" C "), ii ), core::id::THETA ), true );
205  }
206  } else if ( minimize_bondangle_subset_ == 4) {
207  for ( Size ii = 1; ii <= pose.total_residue(); ++ii ) {
208  core::conformation::Residue const &res_i = pose.residue(ii);
209  if (res_i.type().has_atom_name( " CB "))
210  movemap.set( DOF_ID( AtomID( res_i.atom_index(" CB "), ii ), core::id::THETA ), true );
211  }
212  }
213  }
214 
215 }
216 
218  scorefxn_ = score;
219 }
220 
222  return scorefxn_;
223 }
224 
226  return scorefxn_;
227 }
228 
233  task_factory_ = 0;
234 
235  using namespace basic::options;
236  using namespace basic::options::OptionKeys;
237  dry_run_ = basic::options::option[ OptionKeys::run::dry_run ]();
238 }
239 
241  using namespace basic::options;
242  using namespace basic::options::OptionKeys;
243  minimize_bond_lengths_ = option[ OptionKeys::relax::minimize_bond_lengths ]();
244  minimize_bond_angles_ = option[ OptionKeys::relax::minimize_bond_angles ]();
245  minimize_bondlength_subset_ = option[ OptionKeys::relax::minimize_bondlength_subset ]();
246  minimize_bondangle_subset_ = option[ OptionKeys::relax::minimize_bondangle_subset ]();
247 
248  //fpd extras
249  cartesian_ = option[ OptionKeys::relax::cartesian ]();
250  if ( option[ OptionKeys::relax::min_type ].user() )
251  min_type_ = option[ OptionKeys::relax::min_type ]();
253  min_type_ = "lbfgs_armijo_nonmonotone"; // default is different for cartesian/fbal minimization
254 }
255 
257  using namespace basic::options;
258  using namespace basic::options::OptionKeys;
259  constrain_relax_to_native_coords_ = option[ OptionKeys::relax::constrain_relax_to_native_coords ]();
260  constrain_relax_to_start_coords_ = option[ OptionKeys::relax::constrain_relax_to_start_coords ]();
262  coord_constrain_sidechains_ = option[ OptionKeys::relax::coord_constrain_sidechains ]();
264  utility_exit_with_message("Option -relax:coord_constrain_sidechains also requires either -relax:constrain_relax_to_start_coords or -relax:constrain_relax_to_native_coords");
265  }
266  explicit_ramp_constraints_ = option[ OptionKeys::relax::ramp_constraints ].user();
267  ramp_down_constraints_ = option[ OptionKeys::relax::ramp_constraints ]();
268  constrain_relax_segments_ = option[ OptionKeys::relax::constrain_relax_segments ].user();
269  limit_aroma_chi2_ = option[ OptionKeys::relax::limit_aroma_chi2 ]();
270 }
271 
273  using namespace basic::options;
274  using namespace basic::options::OptionKeys;
276  movemap_->set_jump( option[ OptionKeys::relax::jump_move ]() );
277  movemap_->set_bb( option[ OptionKeys::relax::bb_move ]() );
278  movemap_->set_chi( option[ OptionKeys::relax::chi_move ]() );
279  if (option[ OptionKeys::in::file::movemap ].user()) {
280  movemap_->init_from_file(option[ OptionKeys::in::file::movemap ]() );
281  }
282 }
283 
285  movemap_ = movemap;
286 }
287 
289  min_type_ = min_type;
290 }
291 
293  task_factory_ = taskf;
294 }
295 
300 
305 
307 {
308  using namespace basic::options;
309  using namespace basic::options::OptionKeys;
310 
311  static bool runonce( false );
312  if ( runonce ) return;
313 
314  runonce = true;
315 
316  option.add_relevant( OptionKeys::relax::minimize_bond_lengths );
317  option.add_relevant( OptionKeys::relax::minimize_bond_angles );
318  option.add_relevant( OptionKeys::relax::minimize_bondlength_subset );
319  option.add_relevant( OptionKeys::relax::minimize_bondlength_subset );
320 
321 }
322 
325 {
326  return movemap_;
327 }
328 
331 {
332  return task_factory_;
333 }
334 
335 
336 //mjo TODO: please move this with the rest of the disulfide code
337 
338 ////////////////////////////////////////////////////////////////////////////////////////////////////////
339 // apply_disulfides
340 // this is really just "repack disulfides", where a repack is called using only the FA disulfide score
341 //
342 // Anyway, the function as is doesn't do much of anything right now that the subsequent repack steps
343 // wouldn't also do. It's in here more as a placeholder, as I'm planning to rewrite it into a minimize
344 // with constraints type disulfide minimizer
345 //
346 // -rvernon
347 ////////////////////////////////////////////////////////////////////////////////////////////////////////
349  using namespace moves;
350  using namespace scoring;
351  using namespace core::pose::datacache;
352 
353 
354  if ( ( basic::options::option[ basic::options::OptionKeys::in::fix_disulf ].user() ) ||
355  ( basic::options::option[ basic::options::OptionKeys::in::detect_disulf ].user() ) ) {
356 
357  std::string weight_set("score12_justdisulfides");
359 
362  task = pack::task::TaskFactory::create_packer_task( pose );
363 
364  utility::vector1<bool> allow_repack(pose.total_residue(), false);
365 
366  for ( Size i = 1; i<= pose.total_residue() ; ++i ) {
367  allow_repack[i] = movemap_->get_chi(i);
368  }
369 
370  if (basic::options::option[ basic::options::OptionKeys::relax::chi_move].user() ){
371  bool const repack = basic::options::option[ basic::options::OptionKeys::relax::chi_move]();
372  allow_repack.assign( pose.total_residue(), repack);
373  }
374 
375  task->initialize_from_command_line().restrict_to_repacking().restrict_to_residues(allow_repack);
376  task->or_include_current( true );
377  if ( basic::options::option[ basic::options::OptionKeys::symmetry::symmetry_definition ].user() ) {
378  full_repack = new simple_moves::symmetry::SymPackRotamersMover( disulf_score_only, task );
379  } else {
380  full_repack = new protocols::simple_moves::PackRotamersMover( disulf_score_only, task );
381  }
382 
383  ( *disulf_score_only )( pose );
384 
385  full_repack->apply(pose);
386  }
387 }
388 
389 
391  using namespace conformation;
392  using namespace core;
393  using namespace basic::options;
394  using namespace basic::options::OptionKeys;
395  using namespace core::pose::datacache;
396  using namespace core::scoring;
397  using namespace core::scoring::constraints;
398  using namespace core::id;
399  using namespace protocols::moves;
400  using namespace core::scoring;
401 
402  core::pose::Pose constraint_target_pose = pose;
403  core::id::SequenceMapping seq_map; // A mapping of pose -> constraint_target_pose numbering
404 
405  //fpd Make ramping on by default if one of -constrain_relax_* is specified
406  //fpd Let it be overridden if '-ramp_constraints false' is specified
407  if (constrain_coords_ && !option[ OptionKeys::relax::ramp_constraints ].user() ) {
408  ramp_down_constraints_ = true;
409  }
410 
412  if ( get_native_pose() ) {
413  constraint_target_pose = *get_native_pose();
414  } else {
415  utility_exit_with_message("Native pose needed for OptionKeys::relax::constrain_relax_to_native_coords");
416  }
417  // TODO: Allow for input of an alignment on commandline
418  if ( pose.total_residue() == constraint_target_pose.total_residue() &&
419  ( !coord_constrain_sidechains_ || pose.sequence() != constraint_target_pose.sequence() ) ) {
420  // We match in size and (for sidechains) sequence - we're looking at the traditional 1:1 mapping.
422  } else {
423  // Try to match on a PDB-identity basis, or a sequence alignment basis if that fails.
424  TR << "Length " << (coord_constrain_sidechains_?"and/or identities ":"") <<
425  "of input structure and native don't match - aligning on PDB identity or sequence." << std::endl;
426  seq_map = core::pose::sequence_map_from_pdbinfo( pose, constraint_target_pose );
427  }
428  // Align the native pose to the input pose to avoid rotation/translation based
429  // errors.
430  //fpd (Only if not already rooted on a VRT to avoid problems with density/symmetry)
431  if ( pose.residue( pose.fold_tree().root() ).aa() != core::chemical::aa_vrt ) {
432  core::id::SequenceMapping rev_seq_map( seq_map ); // constraint_target_pose -> pose mapping
433  rev_seq_map.reverse();
434  core::sequence::calpha_superimpose_with_mapping(constraint_target_pose, pose, rev_seq_map);
435  }
436  } else {
437  // Aligning to input - mapping is 1:1
439  }
440 
441  protocols::loops::Loops coordconstraint_segments_;
443  coordconstraint_segments_ = protocols::loops::Loops( option[ OptionKeys::relax::constrain_relax_segments ]() );
444  }else{
445  coordconstraint_segments_.add_loop( protocols::loops::Loop( 1, pose.total_residue(), 1 ) );
446  }
447 
448  if ( constrain_coords_ ) {
449  //if -relax::coord_cst_width is given, the code instead uses _bounded_ constraints on
450  //heavy atom positions, of the specified width
451  Real const coord_sdev( option[ OptionKeys::relax::coord_cst_stdev ] );
452  bool bounded( option[ OptionKeys::relax::coord_cst_width ].user() );
453  Real const cst_width( option[ OptionKeys::relax::coord_cst_width ]() );
454 
455  // Add virtual root
456  if ( pose.residue( pose.fold_tree().root() ).aa() != core::chemical::aa_vrt ) {
458  }
459 
460  core::Size nres = pose.total_residue();
461 
462  for ( Size i = 1; i<= nres; ++i ) {
463  if ( pose.fold_tree().is_root(i) ) continue; // Skip root virtual atom.
464 
465  if ( coordconstraint_segments_.is_loop_residue( i ) ) {
466  Size j(seq_map[i]);
467  if( j == 0 ) continue;
468  assert( j <= constraint_target_pose.total_residue() ); // Should be, if map was set up properly.
469 
470  Residue const & pose_i_rsd( pose.residue(i) );
471  Residue const & targ_j_rsd( constraint_target_pose.residue(j) );
472  core::Size last_atom( pose_i_rsd.last_backbone_atom() );
473  core::Size last_targ_atom( targ_j_rsd.last_backbone_atom() );
474  bool use_atom_names(false);
476  last_atom = pose_i_rsd.nheavyatoms();
477  last_targ_atom = targ_j_rsd.nheavyatoms();
478  use_atom_names = pose_i_rsd.name() != targ_j_rsd.name(); // Don't bother with lookup if they're the same residue type.
479  }
480  if ( !use_atom_names && last_atom != last_targ_atom ) {
481  TR.Warning << "Warning: Coordinate constraint reference residue has different number of " << (coord_constrain_sidechains_?"heavy":"backbone") << " atoms: ref. "
482  << targ_j_rsd.name() << " (res " << j << ") versus " << pose_i_rsd.name() << " (res " << i << "). - skipping." << std::endl;
483  continue;
484  }
485  for ( Size ii = 1; ii<= last_atom; ++ii ) {
486  Size jj(ii);
487  if ( use_atom_names ) {
488  std::string atomname( pose_i_rsd.atom_name(ii) );
489  if ( ! targ_j_rsd.has(atomname) ) {
490  TR.Debug << "Skip adding coordinate constraints for atom " << atomname << " of residue " << i << " (" << pose_i_rsd.name() <<
491  ") - not found in residue " << j << " (" << targ_j_rsd.name() << ") of reference structure." << std::endl;
492  continue;
493  }
494  jj = targ_j_rsd.atom_index( atomname );
495  }
497  if( bounded ) {
498  function = new BoundFunc( 0, cst_width, coord_sdev, "xyz" );
499  } else {
500  function = new HarmonicFunc( 0.0, coord_sdev );
501  }
503  AtomID(ii,i), AtomID(1,nres), targ_j_rsd.xyz( jj ), function ) );
504  } // for atom
505  } // if(loop)
506  } // for residue
507 
508  if ( get_scorefxn()->get_weight( coordinate_constraint ) == 0 ) {
509  get_scorefxn()->set_weight( coordinate_constraint, 0.5 );
510  }
511 
512  local_movemap.set_jump( pose.num_jump(), true );
513  } // if constrain_coords_
514 
515 
516  if ( option[ OptionKeys::relax::sc_cst_maxdist ].user() && option[ OptionKeys::relax::sc_cst_maxdist ]() > 0 ) {
517  // derive a set of side-chain restraints
518  Real const upper_dist_cutoff( option[ OptionKeys::relax::sc_cst_maxdist ]() );
519  derive_sc_sc_restraints( pose, upper_dist_cutoff );
520 
521  if ( get_scorefxn()->get_weight( atom_pair_constraint ) == 0 ) {
522  get_scorefxn()->set_weight( atom_pair_constraint, 2.0 );
523  }
524  }
525 
526 } // setup_up_constraints
527 
528 
530  using namespace core::io::silent;
531  using namespace basic::options;
532  if ( option[ basic::options::OptionKeys::out::file::silent ].user() ) {
533  std::string silent_file="_"+prefix;
535  if ( output_file_name != "" ) {
536  silent_file = output_file_name + silent_file;
537  } else silent_file = "bla"+silent_file;
538 
539  SilentFileData sfd;
540  //filename might have been changed -- e.g., to also have an MPI rank in there
541 
542  // ProteinSilentStruct pss;
543  io::silent::SilentStructOP pss = io::silent::SilentStructFactory::get_instance()->get_silent_struct_out();
544  pss->fill_struct( pose, get_current_tag() );
545 
546  sfd.write_silent_struct( *pss, silent_file, false /* bWriteScoresOnly */ );
547  } // if option[ out::file::silent ].user()
548 }
549 
550 } // namespace relax
551 } // namespace protocols