Rosetta
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
pocket_relax.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
11 /// @brief
12 
13 // C++ headers
14 #include <iostream>
15 #include <string>
16 
17 // option key includes
18 
19 #include <basic/options/option.hh>
20 #include <basic/options/keys/relax.OptionKeys.gen.hh>
21 #include <basic/options/keys/in.OptionKeys.gen.hh>
22 #include <basic/options/keys/edensity.OptionKeys.gen.hh>
23 #include <basic/options/keys/constraints.OptionKeys.gen.hh>
24 #include <basic/options/keys/symmetry.OptionKeys.gen.hh>
25 #include <basic/options/keys/run.OptionKeys.gen.hh>
26 #include <basic/options/keys/pocket_grid.OptionKeys.gen.hh>
27 
29 
30 #include <basic/Tracer.hh>
31 
32 #include <core/conformation/Residue.hh>
33 
34 #include <core/kinematics/Jump.hh>
35 #include <core/kinematics/MoveMap.hh>
36 
37 #include <core/import_pose/import_pose.hh>
38 
39 #include <core/optimization/AtomTreeMinimizer.hh>
40 #include <core/optimization/MinimizerOptions.hh>
41 
42 #include <core/pose/Pose.hh>
43 
44 #include <core/scoring/ScoreFunctionFactory.hh>
45 #include <core/scoring/ScoreFunction.hh>
46 #include <core/scoring/ScoreFunction.fwd.hh>
47 #include <core/scoring/ScoreType.hh>
48 #include <core/scoring/constraints/util.hh>
49 
50 #include <core/types.hh>
51 
52 #include <devel/init.hh>
53 
54 #include <numeric/random/random.hh>
55 
57 
58 #include <protocols/electron_density/SetupForDensityScoringMover.hh>
59 
60 #include <protocols/jd2/JobDistributor.hh>
61 #include <protocols/jd2/util.hh>
62 
63 #include <protocols/moves/Mover.hh>
64 #include <protocols/moves/Mover.fwd.hh>
65 #include <protocols/moves/MoverContainer.hh>
66 
67 #include <protocols/pockets/PocketGrid.hh>
68 
69 #include <protocols/relax/ClassicRelax.hh>
70 #include <protocols/relax/RelaxProtocolBase.hh>
71 #include <protocols/relax/util.hh>
72 
73 #include <protocols/simple_moves/symmetry/SetupForSymmetryMover.hh>
74 #include <protocols/simple_moves/SuperimposeMover.hh>
75 #include <protocols/simple_moves/ConstraintSetMover.hh>
76 
77 #include <utility/vector0.hh>
78 #include <utility/vector1.hh>
80 
81 
82 using basic::T;
83 using basic::Error;
84 using basic::Warning;
85 
86 
87 using namespace core;
88 using namespace protocols;
89 using namespace protocols::moves;
90 using namespace core::scoring;
91 
92 using utility::vector1;
93 
94 static THREAD_LOCAL basic::Tracer TR( "pocket_relax" );
95 OPT_KEY( String, exemplar_target_pdb_num )
96 
97 //This is copy/pasted from src/apps/public/minimize.cc, but has had the constraints removed
98 class NCMinimize : public moves::Mover {
99 
100  public:
101  NCMinimize();
102 
103  ~NCMinimize();
104 
105  virtual MoverOP clone() const;
106  virtual MoverOP fresh_instance() const;
107 
108  virtual void apply( Pose & pose );
109  virtual std::string get_name() const;
110  virtual void test_move( Pose & pose )
111  {
112  apply(pose);
113 }
114 
115 private:
116 ScoreFunctionOP score_function_;
117 };
118 
120  Mover( "benchmark" ),
121  score_function_( get_score_function() )
122 {
123 
124  using namespace basic::options;
125  using namespace basic::options::OptionKeys;
126 
127 }
128 
130 
131 MoverOP NCMinimize::clone() const {
132  return MoverOP( new NCMinimize( *this ) );
133 }
134 
135 MoverOP NCMinimize::fresh_instance() const {
136  return MoverOP( new NCMinimize );
137 }
138 
140  using namespace pose;
141  using namespace basic::options;
142  using namespace basic::options::OptionKeys;
143 
144  score_function_->set_weight ( pocket_constraint, 0);
145  std::string min_type = option[ OptionKeys::run::min_type ]();
146  core::Real min_tol = option[ OptionKeys::run::min_tolerance ]();
147  core::optimization::MinimizerOptions options( min_type, min_tol, true, false );
148  core::kinematics::MoveMap final_mm;
149  final_mm.set_chi( true );
150  final_mm.set_bb( true );
151 
152  /*core::Real start_score =*/ (*score_function_)(pose);
153  core::Size repeats = 1;
154  for ( core::Size i = 0; i < repeats; i++ ) {
155  core::optimization::AtomTreeMinimizer().run( pose, final_mm, *score_function_, options );
156  TR << "Score: " << i << " " << (*score_function_)(pose) << std::endl;
157  }
158 
159  core::Real final_score = (*score_function_)(pose);
160  TR << "FinalScore: " << final_score << std::endl;
161 
162 }
163 
164 std::string NCMinimize::get_name() const {
165  return "NCMinimize";
166 }
167 
168 
169 ///////////////////////////////////////////////////////////////////////////////
170 
171 int
172 main( int argc, char * argv [] )
173 {
174  try {
175  using namespace core;
176  using namespace protocols::moves;
177  using namespace scoring;
178  using namespace basic::options;
179  using namespace protocols::jobdist;
180  using namespace protocols::relax;
181  using namespace basic::options::OptionKeys;
182  using protocols::moves::MoverOP;
183 
184  NEW_OPT( exemplar_target_pdb_num, "Target residue(s) for exemplar generation", "");
185 
186 
187 
188 
189 
190 
193  option.add_relevant( OptionKeys::in::file::fullatom );
194  option.add_relevant( OptionKeys::in::file::movemap );
195  option.add_relevant( OptionKeys::relax::fast );
196  devel::init(argc, argv);
197 
198  std::string const resid_c = option[exemplar_target_pdb_num];
199 
200  //validate that the exemplar_target_pdb_num is properly formatted
201  if ( resid_c.length() ) {
202  const std::string & delimiters = ";";
203  std::string::size_type lastPos = resid_c.find_first_not_of(delimiters, 0);
204 
205  // Find first "non-delimiter".
206  std::string::size_type pos = resid_c.find_first_of(delimiters, lastPos);
207  while ( std::string::npos != pos || std::string::npos != lastPos ) {
208  std::string const & resid_list = resid_c.substr( lastPos, pos - lastPos );
209  lastPos = resid_c.find_first_not_of(delimiters, pos);
210  pos = resid_c.find_first_of(delimiters, lastPos);
211 
212  const std::string & subdelimiters = ",";
213  std::string::size_type lastSubPos = resid_list.find_first_not_of(subdelimiters, 0);
214  // Find first "non-delimiter".
215  std::string::size_type subpos = resid_list.find_first_of(subdelimiters, lastSubPos);
216  while ( std::string::npos != subpos || std::string::npos != lastSubPos ) {
217  std::string const & resid = resid_list.substr( lastSubPos, subpos - lastSubPos );
218  lastSubPos = resid_list.find_first_not_of(subdelimiters, subpos);
219  subpos = resid_list.find_first_of(subdelimiters, lastSubPos);
220  std::size_t fpos( resid.find(':') );
221  if ( fpos != std::string::npos ) {
222  if ( fpos != resid.length() -2 || fpos == 0 ) {
223  throw(utility::excn::EXCN_BadInput(" invalid exemplar_target_pdb_num " + resid_c));
224  }
225  char chain = resid[resid.length() -1];
226  if ( !( (chain >='A' && chain <='Z') || (chain >='a' && chain <='z') ) ) {
227  throw(utility::excn::EXCN_BadInput(" invalid exemplar_target_pdb_num " + resid_c));
228  }
229  for ( int i = 0; i< (int) fpos; ++i ) {
230  if ( !(resid[i] >='0' && resid[i] <='9') ) {
231  throw(utility::excn::EXCN_BadInput(" invalid exemplar_target_pdb_num " + resid_c));
232  }
233  }
234  } else {
235  for ( int i = 0; i< (int) resid.length(); ++i ) {
236  if ( !(resid[i] >='0' && resid[i] <='9') ) {
237  throw(utility::excn::EXCN_BadInput(" invalid exemplar_target_pdb_num " + resid_c));
238  }
239  }
240  }
241  }
242  }
243  }
244 
245 
246  //return relax::Relax_main( false );
247 
248  protocols::moves::MoverOP protocol = generate_relax_from_cmd();
249  protocols::jd2::set_native_in_mover( *protocol );
250 
251  // add constraints from cmd line
252  if ( option[ OptionKeys::constraints::cst_fa_file ].user() || option[ OptionKeys::constraints::cst_file ].user() ) {
253  protocols::moves::SequenceMoverOP seqmov( new protocols::moves::SequenceMover );
254  protocols::simple_moves::ConstraintSetMoverOP loadCsts( new protocols::simple_moves::ConstraintSetMover );
255  if ( option[ OptionKeys::constraints::cst_fa_file ].user() ) {
256  loadCsts->constraint_file( core::scoring::constraints::get_cst_fa_file_option() );
257  } else {
258  loadCsts->constraint_file( core::scoring::constraints::get_cst_file_option() );
259  }
260  seqmov->add_mover( loadCsts );
261  seqmov->add_mover( protocol );
262  protocol = seqmov;
263  }
264 
265  // set pose for density scoring if a map was input
266  // (potentially) dock map into density
267  if ( option[ OptionKeys::edensity::mapfile ].user() ) {
268  protocols::moves::SequenceMoverOP seqmov( new protocols::moves::SequenceMover );
269  seqmov->add_mover( MoverOP( new protocols::electron_density::SetupForDensityScoringMover ) );
270  seqmov->add_mover( protocol );
271  protocol = seqmov;
272  }
273 
274  // setup symmetry mover ... this should happen _before_ SetupForDensityScoringMover
275  // to avoid adding extra VRTs
276  if ( option[ OptionKeys::symmetry::symmetry_definition ].user() ) {
277  protocols::moves::SequenceMoverOP seqmov( new protocols::moves::SequenceMover );
278  seqmov->add_mover( MoverOP( new protocols::simple_moves::symmetry::SetupForSymmetryMover ) );
279  seqmov->add_mover( protocol );
280  protocol = seqmov;
281  }
282 
283  // superimpose input model to the native structure or to a supplied PDB file
284  if ( option[ OptionKeys::relax::superimpose_to_file ].user() ||
286  ) {
287  core::pose::Pose ref_pose;
288  std::string ref_filename;
289  if ( option[ OptionKeys::relax::superimpose_to_file ].user() ) ref_filename = option[ basic::options::OptionKeys::relax::superimpose_to_file ]();
291  core::import_pose::pose_from_pdb( ref_pose, ref_filename );
292  protocols::moves::SequenceMoverOP seqmov( new protocols::moves::SequenceMover );
293  protocols::simple_moves::SuperimposeMoverOP sm( new protocols::simple_moves::SuperimposeMover );
294  sm->set_reference_pose( ref_pose );
295  seqmov->add_mover( sm );
296  seqmov->add_mover( protocol );
297  protocol = seqmov;
298  }
299 
300  protocols::moves::SequenceMoverOP seqmov( new protocols::moves::SequenceMover );
301  seqmov->add_mover( protocol );
302 
303 
304  MoverOP minprotocol( new NCMinimize() );
305  seqmov->add_mover( minprotocol );
306 
307  protocol = seqmov;
308 
309  protocols::jd2::JobDistributor::get_instance()->go( protocol );
310 
311 
312  } catch ( utility::excn::EXCN_Base const & e ) {
313  std::cout << "caught exception " << e.msg() << std::endl;
314  return -1;
315  }
316 }
virtual MoverOP fresh_instance() const
#define THREAD_LOCAL
virtual std::string const msg() const
Definition: EXCN_Base.hh:70
void register_options()
std::string String
Definition: remodel.cc:69
vector0: std::vector with assert-checked bounds
virtual void test_move(Pose &pose)
virtual MoverOP clone() const
void init(int argc, char *argv[])
Command line init() version.
Definition: init.cc:23
BooleanOptionKey const user("options:user")
Definition: OptionKeys.hh:40
core::pose::Pose Pose
Definition: supercharge.cc:101
Random number generator system.
Tracer & T(std::string const &channel, TracerPriority priority)
T is special function for assign tracer property on the static object.
Definition: Tracer.cc:567
common derived classes for thrown exceptions
virtual void apply(Pose &pose)
Tracer & Error(TracerPriority priority=t_error)
Predefined Error tracer.
Definition: Tracer.hh:395
Tracer IO system.
std::vector with 1-based indexing
Definition: vector1.fwd.hh:44
static THREAD_LOCAL basic::Tracer TR("pocket_relax")
rule< Scanner, options_closure::context_t > options
Definition: Tag.cc:377
#define OPT_KEY(type, key)
Tracer & Warning(TracerPriority priority=t_warning)
Predefined Warning tracer.
Definition: Tracer.hh:398
string min_type
Definition: loops_kic.py:76
list native
Definition: ContactMap.py:108
double Real
Definition: types.hh:39
virtual std::string get_name() const
#define NEW_OPT(akey, help, adef)
ocstream cout(std::cout)
Wrapper around std::cout.
Definition: ocstream.hh:287
vector1: std::vector with 1-based indexing
Class for handling user debug/warnings/errors. Use instance of this class instead of 'std::cout' for ...
Definition: Tracer.hh:134
int main(int argc, char *argv[])
tuple movemap
Definition: loops.py:29
Program options global and initialization function.
static void clone(T *&dst, S *src, int n)
Definition: Svm.cc:22
platform::Size Size
Definition: random.fwd.hh:30
BooleanOptionKey superimpose_to_native("score_app:superimpose_to_native")
ScoreFunctionOP score_function_
rule< Scanner, option_closure::context_t > option
Definition: Tag.cc:378