Rosetta
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
mg_modeler.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 
14 // libRosetta headers
15 #include <core/types.hh>
16 #include <core/chemical/ChemicalManager.hh>
17 #include <core/import_pose/import_pose.hh>
18 #include <core/io/pdb/pose_io.hh>
19 #include <core/pose/Pose.hh>
20 #include <core/pose/util.hh>
21 #include <protocols/magnesium/util.hh>
22 #include <protocols/magnesium/minimize_util.hh>
23 #include <protocols/magnesium/MgOrbitalFrameFinder.hh>
24 #include <protocols/magnesium/MgWaterHydrogenPacker.hh>
25 #include <protocols/magnesium/MgHydrater.hh>
26 #include <protocols/magnesium/MgMonteCarlo.hh>
27 #include <protocols/magnesium/MgScanner.hh>
28 #include <protocols/viewer/viewers.hh>
29 #include <core/scoring/ScoreFunction.hh>
30 #include <core/scoring/ScoreFunctionFactory.hh>
31 #include <basic/options/option.hh>
33 #include <basic/Tracer.hh>
34 #include <devel/init.hh>
35 #include <utility/vector1.hh>
37 
38 //silly using/typedef
39 // option key includes
40 #include <basic/options/keys/out.OptionKeys.gen.hh>
41 #include <basic/options/keys/in.OptionKeys.gen.hh>
42 #include <basic/options/keys/score.OptionKeys.gen.hh>
43 #include <basic/options/keys/magnesium.OptionKeys.gen.hh>
44 
45 using namespace core;
46 using namespace basic::options;
47 using namespace basic::options::OptionKeys;
48 
49 using utility::vector1;
50 using io::pdb::dump_pdb;
51 
52 static THREAD_LOCAL basic::Tracer TR( "mg_modeler" );
53 
54 ///////////////////////////////////////////////////////////////////////////////
55 //
56 // Model Mg(2+), including waters for hexahydrates -- output PDB stats
57 // to help define a potential. Now use virtual atoms to help track the 'ligand field'
58 // which favors octahedral coordination of lone pair donors.
59 //
60 // 1. Orient Mg(2+) ligand-field ('orbital') frames
61 // 2. Pack hydrogens in existing waters that ligate Mg(2+).
62 // 3. Pack waters around existing Mg(2+).
63 // 4. Sample Mg(2+) & water position by monte carlo.
64 // 5. Dock Mg(2+)
65 //
66 // Rhiju, April 2015
67 //
68 ///////////////////////////////////////////////////////////////////////////////
69 
70 void
72 {
73  using namespace basic::options;
74  using namespace basic::options::OptionKeys;
75  using namespace core::chemical;
76  using namespace core::pose;
77  using namespace core::scoring;
78  using namespace protocols::magnesium;
79 
80  std::string const file_path( option[ in::path::pdb ]( 1 ) );
81  vector1< std::string > const input_pdb_files( option[ in::file::s ]() );
82  ResidueTypeSetCOP rsd_set( core::chemical::ChemicalManager::get_instance()->residue_type_set( core::chemical::FA_STANDARD ) );
83  vector1< Size > input_pdb_mg_res = option[ magnesium::mg_res ]();
84  Pose pose;
85 
86  for ( Size q = 1; q <= input_pdb_files.size(); q++ ) {
87  std::string const pdb_file = input_pdb_files[ q ];
88  import_pose::pose_from_pdb( pose, *rsd_set, file_path + '/' + pdb_file );
89  PoseCOP reference_pose( pose.clone() ); // can update to actual user-supplied native later.
90  std::cout << "Doing input file ==> " << pdb_file << std::endl;
91 
92  if ( q == 1 ) protocols::viewer::add_conformation_viewer ( pose.conformation(), "current", 500, 500, false );
93 
94  // mg_res usually is alist of all mg(2+) in one pose. But if there are multiple poses, assume a single res specified
95  // for each -- makes benchmark code easy.
96  vector1< Size > pdb_mg_res( input_pdb_mg_res );
97  if ( input_pdb_files.size() > 0 && pdb_mg_res.size() > 0 ) {
98  runtime_assert( input_pdb_files.size() == input_pdb_mg_res.size() );
99  pdb_mg_res = utility::tools::make_vector1( input_pdb_mg_res[ q ] );
100  }
101 
102  std::string tag;
103  if ( option[ magnesium::fixup ]() ) {
104  fixup_magnesiums( pose );
105  TR << TR.Blue << "Just did basic fixup -- mg frame orientation & water-bound mg repacking." << TR.Reset << std::endl;
106  TR << TR.Blue << "If you want to build mg2+-bound waters, run this app with -hydrate flag." << TR.Reset << std::endl;
107  tag = "mg_fixup";
108  } else if ( option[ magnesium::pack_water_hydrogens ]() ) {
109  MgOrbitalFrameFinder mg_orbital_frame_finder;
110  mg_orbital_frame_finder.apply( pose );
111  remove_waters_except_mg_bound( pose, get_mg_water_pairs( pose, pdb_to_pose( pose, pdb_mg_res ) ) ); // note that numbering can change again
112  MgWaterHydrogenPacker mg_water_hydrogen_packer( pdb_to_pose( pose, pdb_mg_res ) );
113  mg_water_hydrogen_packer.set_use_fast_heuristic( !option[ magnesium::scored_hydrogen_sampling ]() );
114  mg_water_hydrogen_packer.apply( pose );
115  tag = "pack_water_hydrogens";
116  } else if ( option[ magnesium::hydrate ]() ) {
117  remove_mg_bound_waters( pose, pdb_to_pose( pose, pdb_mg_res ), option[ magnesium::leave_other_waters ] ); // remove any mg-bound waters
118  MgHydrater mg_hydrater( pdb_to_pose( pose, pdb_mg_res ) );
119  mg_hydrater.set_use_fast_frame_heuristic( !option[ magnesium::all_hydration_frames ]() );
120  mg_hydrater.set_verbose( true );
121  mg_hydrater.apply( pose );
122  tag = "hydrate";
123  if ( option[ magnesium::minimize ]() ) {
124  update_mg_hoh_fold_tree( pose );
125  minimize_magnesium_and_hydration_shell( pose, pdb_to_pose( pose, pdb_mg_res ), get_mg_scorefxn(), option[ magnesium::minimize_mg_coord_constraint_distance ]() );
126  }
127  // produce some diagnostic output.
128  get_hydration_stats( pose, *reference_pose, pdb_mg_res,
129  option[ out::file::o ].user() ? option[ out::file::o ]() : "default.out" );
130  } else if ( option[ magnesium::monte_carlo ]() ) {
131  MgMonteCarlo mg_monte_carlo;
132  mg_monte_carlo.set_cycles( option[ magnesium::montecarlo::cycles ]() );
133  mg_monte_carlo.set_temperature( option[ magnesium::montecarlo::temperature ]() );
134  mg_monte_carlo.set_add_delete_frequency( option[ magnesium::montecarlo::add_delete_frequency ]() );
135  mg_monte_carlo.set_output_pdb( option[ magnesium::montecarlo::dump ]() );
136  mg_monte_carlo.apply( pose );
137  tag = "monte_carlo";
138  } else {
139  strip_out_magnesiums( pose );
140  add_single_magnesium( pose );
141 
142  // actually could encapsulate mg_positions & mg_energies as extra 'energy' values in pose. Would be way more compact.
143  MgScanner mg_scanner;
144  mg_scanner.set_score_cut( option[ magnesium::score_cut ] );
145  ScoreFunctionOP scorefxn = ( option[ score::weights ].user() ) ? get_score_function() : get_mg_scorefxn();
146  mg_scanner.set_scorefxn( scorefxn );
147  mg_scanner.set_native_pose( reference_pose );
148  if ( option[ in::file::input_res ].user() ) utility_exit_with_message( "Use -pose_ligand_res instead of -input_res." );
149  vector1< Size > input_scan_res = option[ magnesium::ligand_res ].user() ? pdb_to_pose( pose, option[ magnesium::ligand_res ].resnum_and_chain() ) :
150  vector1<Size>( option[ magnesium::pose_ligand_res ]() );
151  mg_scanner.set_input_scan_res( input_scan_res );
152  mg_scanner.set_silent_file( option[ out::file::silent ]() );
153  mg_scanner.set_hydrate( !option[ magnesium::lores_scan ]() );
154  mg_scanner.set_minimize_during_scoring( option[ magnesium::minimize_during_scoring ]() );
155  mg_scanner.set_minimize( option[ magnesium::minimize ]() );
156  mg_scanner.set_tether_to_closest_res( option[ magnesium::tether_to_closest_res ]() );
157  mg_scanner.set_xyz_step( option[ magnesium::xyz_step ]() );
158  mg_scanner.set_minimize_mg_coord_constraint_distance( option[ magnesium::minimize_mg_coord_constraint_distance ]() );
159  mg_scanner.set_integration_test( option[ magnesium::integration_test ]() );
160  if ( option[ out::file::o ].user() ) mg_scanner.set_output_pdb( option[ out::file::o]() );
161  mg_scanner.set_score_cut_PDB( option[ magnesium::score_cut_PDB ] );
162 
163  mg_scanner.apply( pose );
164 
165  tag = "scan";
166  }
167 
168  std::string outpath = option[ out::path::pdb ]();
169  std::string const outfile = outpath + utility::replace_in( pdb_file, ".pdb", "." + tag + ".pdb" );
170  std::cout << "Outputting: " << outfile << std::endl;
171 
172  pose.dump_pdb( outfile );
173  }
174 
175 }
176 
177 
178 ///////////////////////////////////////////////////////////////
179 void*
180 my_main( void* )
181 {
182  clock_t const my_main_time_start( clock() );
183  mg_modeler_test();
184  protocols::viewer::clear_conformation_viewers();
185  std::cout << "Total time to run " << static_cast<Real>( clock() - my_main_time_start ) / CLOCKS_PER_SEC << " seconds." << std::endl;
186  exit( 0 );
187 }
188 
189 ///////////////////////////////////////////////////////////////////////////////
190 int
191 main( int argc, char * argv [] )
192 {
193 
194  try {
195 
196  option.add_relevant( out::file::silent );
197  option.add_relevant( magnesium::scan );
198  option.add_relevant( magnesium::mg_res );
199  option.add_relevant( magnesium::minimize_during_scoring );
200  option.add_relevant( magnesium::ligand_res );
201  option.add_relevant( magnesium::pose_ligand_res );
202  option.add_relevant( magnesium::lores_scan );
203  option.add_relevant( magnesium::xyz_step );
204  option.add_relevant( magnesium::score_cut );
205  option.add_relevant( magnesium::score_cut_PDB );
206  option.add_relevant( magnesium::integration_test );
207  option.add_relevant( magnesium::tether_to_closest_res );
208  option.add_relevant( magnesium::fixup );
209  option.add_relevant( magnesium::pack_water_hydrogens );
210  option.add_relevant( magnesium::hydrate );
211  option.add_relevant( magnesium::monte_carlo );
212  option.add_relevant( magnesium::scored_hydrogen_sampling );
213  option.add_relevant( magnesium::all_hydration_frames );
214  option.add_relevant( magnesium::leave_other_waters );
215  option.add_relevant( magnesium::minimize );
216  option.add_relevant( magnesium::minimize_mg_coord_constraint_distance );
217  option.add_relevant( magnesium::montecarlo::temperature );
218  option.add_relevant( magnesium::montecarlo::cycles );
219  option.add_relevant( magnesium::montecarlo::dump );
220  option.add_relevant( magnesium::montecarlo::add_delete_frequency );
221 
222  ////////////////////////////////////////////////////////////////////////////
223  // setup
224  ////////////////////////////////////////////////////////////////////////////
225 
226  devel::init(argc, argv);
227 
228  ////////////////////////////////////////////////////////////////////////////
229  // end of setup
230  ////////////////////////////////////////////////////////////////////////////
231 
232  protocols::viewer::viewer_main( my_main );
233 
234  } catch ( utility::excn::EXCN_Base const & e ) {
235  std::cout << "caught exception " << e.msg() << std::endl;
236  return -1;
237  }
238 
239 }
#define utility_exit_with_message(m)
Exit with file + line + message.
Definition: exit.hh:47
void * my_main(void *)
Definition: mg_modeler.cc:180
#define THREAD_LOCAL
static THREAD_LOCAL basic::Tracer TR("mg_modeler")
virtual std::string const msg() const
Definition: EXCN_Base.hh:70
def dump
Definition: __init__.py:177
def scan
Definition: __init__.py:21
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
#define runtime_assert(_Expression)
Assert that the condition holds. Evaluated for both debug and release builds.
Definition: exit.hh:63
tuple scorefxn
Definition: PyMOL_demo.py:63
void mg_modeler_test()
Definition: mg_modeler.cc:71
Tracer IO system.
static utility::CSI_Sequence Reset
Definition: Tracer.hh:265
std::vector with 1-based indexing
Definition: vector1.fwd.hh:44
std::string replace_in(std::string const &name_in, std::string const &find_string, std::string const &replace_string)
Generate new string from 'source' by replacing all occurrences of 'from' to 'to' string.
Definition: string_util.cc:710
rule< Scanner, options_closure::context_t > options
Definition: Tag.cc:377
static utility::CSI_Sequence Blue
Definition: Tracer.hh:265
double Real
Definition: types.hh:39
ocstream cout(std::cout)
Wrapper around std::cout.
Definition: ocstream.hh:287
BooleanOptionKey const exit("options:exit")
Definition: OptionKeys.hh:51
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[])
Definition: mg_modeler.cc:191
Program options global and initialization function.
rule< Scanner, tag_closure::context_t > tag
Definition: Tag.cc:373
platform::Size Size
Definition: random.fwd.hh:30
utility::vector1< T > make_vector1(const T i0)
Definition: make_vector1.hh:24
int const silent
Named verbosity levels.
rule< Scanner, option_closure::context_t > option
Definition: Tag.cc:378