Rosetta
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
vip.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/apps/public/RosettaVIP/VIP_app.cc
11 /// @brief RosettaVIP protocol. Locates buried voids
12 /// using RosettaHoles and attempts point mutants (using GOE) on a fixed backbone to reduce void
13 /// volumes and improve packing.
14 /// @author ben (bborgo@genetics.wustl.edu)
15 
16 
17 #include <basic/options/option.hh>
18 #include <basic/options/keys/cp.OptionKeys.gen.hh>
19 #include <basic/options/keys/in.OptionKeys.gen.hh>
20 #include <basic/options/option.hh>
21 
22 #include <core/chemical/AA.hh>
23 #include <core/conformation/Residue.hh>
24 #include <core/import_pose/import_pose.hh>
25 #include <core/pose/PDBInfo.hh>
26 #include <core/scoring/Energies.hh>
27 #include <core/scoring/ScoreFunction.hh>
28 #include <core/scoring/ScoreFunctionFactory.hh>
29 
30 //protocols library (Movers)
31 #include <protocols/vip/VIP_Mover.hh>
33 #include <utility/string_util.hh>
34 #include <protocols/simple_moves/ScoreMover.hh>
35 #include <protocols/relax/FastRelax.hh>
36 #include <protocols/relax/ClassicRelax.hh>
37 #include <protocols/relax/MiniRelax.hh>
38 
39 
40 #include <basic/Tracer.hh>
41 static THREAD_LOCAL basic::Tracer TR( "VIP" );
42 
43 //utilities
44 #include <protocols/jd2/JobDistributor.hh>
45 #include <devel/init.hh>
47 
48 //local options
49 namespace core { namespace options { namespace OptionKeys {
50 basic::options::BooleanOptionKey const minimize_sidechains("minimize_sidechains");
51 }}}//basic::options::OptionKeys
52 
53 ///////////////////////////////////////////////////////////////////////////////
54 int
55 main( int argc, char * argv [] )
56 {
57  try {
58  using namespace basic::options;
59  using namespace basic::options::OptionKeys;
60 
61  devel::init( argc, argv );
62 
63  core::Real initial_E = 0.0;
64  core::Real old_energy = 0.0;
65 
66  core::pose::Pose in_pose;
67  core::import_pose::pose_from_pdb(
68  in_pose,
69  option[ OptionKeys::in::file::s ]().vector().front());
70 
71  core::scoring::ScoreFunctionOP scorefxn = core::scoring::ScoreFunctionFactory::create_score_function( option[ cp::relax_sfxn ] );
72  protocols::simple_moves::ScoreMover scoreme = protocols::simple_moves::ScoreMover( scorefxn );
73 
74  // Perform a pre-relaxation of the starting point
75 
76  {
77  std::string rmover = option[ cp::relax_mover ];
78  if ( rmover == "relax" ) {
79  protocols::relax::RelaxProtocolBaseOP relaxmover( new protocols::relax::FastRelax( scorefxn, 15 ) );
80  relaxmover->apply( in_pose );
81  } else if ( rmover == "classic_relax" ) {
82  protocols::relax::RelaxProtocolBaseOP relaxmover( new protocols::relax::ClassicRelax( scorefxn ) );
83  relaxmover->apply( in_pose );
84  } else if ( rmover == "cst_relax" ) {
85  protocols::relax::RelaxProtocolBaseOP cstrelaxmover( new protocols::relax::MiniRelax( scorefxn ) );
86  cstrelaxmover->apply( in_pose );
87  }
88 
89  }
90 
91  // bool iterate = true;
92  core::Size it = 1;
93  core::Size const ncycles = option[ cp::ncycles ];
94  core::Size const max_failures = option[ cp::max_failures ];
95 
96  bool use_unrelaxed_mutants( option[ cp::use_unrelaxed_starting_points ] );
97  bool easy_acceptance( option[ cp::easy_vip_acceptance ] );
98 
99  // How many failures at a given level to tolerate before failing
100  core::Size current_failures( 0 );
101 
102  core::pose::Pose stored_unrelaxed_pose;
103  core::pose::Pose out_pose;
104  bool not_finished( true );
105 
106  while ( not_finished ) {
107  TR << "Entering VIP loop with it # " << it << std::endl;
108  scoreme.apply(in_pose);
109  if ( it == 1 ) {
110  old_energy = in_pose.energies().total_energy();
111  initial_E = old_energy;
112  }
113 
114  protocols::vip::VIP_Mover();
115  protocols::vip::VIP_Mover vip_mover;
116  if ( ( it > 1 ) && use_unrelaxed_mutants && ( stored_unrelaxed_pose.total_residue() > 0 ) ) {
117  vip_mover.set_initial_pose( stored_unrelaxed_pose );
118  //TR << "Recovering stored pose with total residues = " << stored_unrelaxed_pose.total_residue() << std::endl;
119  } else {
120  vip_mover.set_initial_pose( in_pose );
121  }
122  vip_mover.set_iteration( it );
123  vip_mover.apply();
124 
125  out_pose = vip_mover.get_final_pose();
126  core::Real new_energy = vip_mover.get_final_energy();
127 
128  bool improved( new_energy < old_energy ? true : false );
129 
130  // Check for bogus final_pose
131  if ( out_pose.total_residue() == 0 ) {
132  improved = false;
133  } else {
134  if ( use_unrelaxed_mutants ) {
135  stored_unrelaxed_pose = vip_mover.get_unrelaxed_pose();
136  }
137  TR << "Comparing new energy " << new_energy << " with old energy " << old_energy << std::endl;
138  }
139 
140  if ( improved ) {
141  // Print out the accepted mutation
142 
143  for ( core::Size j = 1 ; j <= in_pose.total_residue() ; ++j ) {
144  if ( out_pose.residue( j ).name() != in_pose.residue( j ).name() ) {
145  core::Size pdb_position( out_pose.pdb_info()->number( j ) );
146  char pdb_chain( out_pose.pdb_info()->chain( j ) );
147  TR << "Accepting mutation at position " << pdb_position << " chain " << pdb_chain
148  << " from " << in_pose.residue( j ).name()
149  << " to " << out_pose.residue( j ).name() << std::endl;
150 
151  if ( option[ cp::print_intermediate_pdbs ] ) {
152  std::string pdb_file = "vip_iter_" + utility::to_string( it ) + ".pdb";
153  TR << "Dumping intermediate pdb file " << pdb_file << std::endl;
154  out_pose.dump_pdb( pdb_file );
155  }
156 
157  vip_mover.set_energy_to_beat( easy_acceptance ? initial_E : new_energy );
158  vip_mover.set_use_stored_energy( true );
159  break;
160  }
161  }
162 
163  old_energy = ( easy_acceptance ? initial_E : new_energy );
164  in_pose = out_pose;
165  it++;
166  current_failures = 0;
167  } else {
168  current_failures++;
169  TR << "Rejecting attempted mutation!" << std::endl;
170  }
171 
172  bool done_improving( (current_failures >= max_failures) && !improved );
173 
174  // if the requested ncycles is 0, quit as soon as improvement stops. If ncycles
175  // is set at a non-zero value, quit either after improvement stops or the number of
176  // cycles has been hit.
177  not_finished = ( ncycles == 0 ? !done_improving : ( it <= ncycles && !done_improving ) );
178  }
179 
180  out_pose.dump_pdb( option[ cp::output ] );
181  } catch ( utility::excn::EXCN_Base const & e ) {
182  std::cout << "caught exception " << e.msg() << std::endl;
183  return -1;
184  }
185 }
def vector
Definition: Equations.py:5
#define THREAD_LOCAL
virtual std::string const msg() const
Definition: EXCN_Base.hh:70
void init(int argc, char *argv[])
Command line init() version.
Definition: init.cc:23
core::pose::Pose Pose
Definition: supercharge.cc:101
string output
Definition: contacts.py:31
static THREAD_LOCAL basic::Tracer TR("VIP")
Abstract automatic hidden index key for options.
common derived classes for thrown exceptions
int main(int argc, char *argv[])
Definition: vip.cc:55
tuple scorefxn
Definition: PyMOL_demo.py:63
static THREAD_LOCAL basic::Tracer TR("basic.options")
Tracer IO system.
Automatic hidden index key for boolean options.
basic::options::BooleanOptionKey const minimize_sidechains("minimize_sidechains")
rule< Scanner, options_closure::context_t > options
Definition: Tag.cc:377
utility::options::OptionCollection option
OptionCollection global.
Definition: option.cc:45
double Real
Definition: types.hh:39
ocstream cout(std::cout)
Wrapper around std::cout.
Definition: ocstream.hh:287
Class for handling user debug/warnings/errors. Use instance of this class instead of 'std::cout' for ...
Definition: Tracer.hh:134
std::string to_string(const T &t)
Definition: string_util.hh:205
Some std::string helper functions.
Program options global and initialization function.
platform::Size Size
Definition: random.fwd.hh:30