Rosetta
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
enzyme_design.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 ///
12 /// @brief
13 /// @author Florian Richter (floric@u.washington.edu)
14 
15 #include <protocols/enzdes/EnzdesFixBBProtocol.hh>
16 #include <protocols/enzdes/EnzdesFlexBBProtocol.hh>
17 //#include <devel/enzdes/EnzdesRemodelProtocol.hh>
18 #include <protocols/enzdes/enzdes_util.hh>
19 #include <protocols/enzdes/EnzFilters.hh>
20 
21 #include <devel/init.hh>
22 #include <core/types.hh>
23 #include <basic/options/option.hh>
24 #include <core/pose/Pose.hh>
25 #include <core/pose/datacache/CacheableDataType.hh>
26 #include <basic/Tracer.hh>
28 #include <protocols/toolbox/match_enzdes_util/EnzConstraintIO.hh> //function for reading cstfiles
29 //#include <devel/enzdes/DesignSilentStruct.hh>
30 #include <protocols/jobdist/standard_mains.hh>
31 #include <protocols/jobdist/JobDistributors.hh>
32 
33 #include <utility/string_util.hh>
34 
35 
36 #include <core/io/silent/SilentStruct.hh>
37 #include <core/io/silent/ScoreFileSilentStruct.hh>
38 
39 // option key includes
40 
41 #include <basic/options/keys/out.OptionKeys.gen.hh>
42 #include <basic/options/keys/run.OptionKeys.gen.hh>
43 #include <basic/options/keys/enzdes.OptionKeys.gen.hh>
44 
45 #include <core/io/silent/SilentFileData.hh>
46 #include <utility/vector1.hh>
49 
51 
52 #if defined(WIN32) || defined(__CYGWIN__)
53 #include <ctime>
54 #endif
55 
56 
57 static THREAD_LOCAL basic::Tracer tr( "apps.public.enzdes.enzyme_design" );
58 
59 using namespace core;
60 
61 /////////////////////////////////////////
62 
63 ////main function
64 int
65 main( int argc, char * argv [])
66 {
67  try {
71  basic::options::option.add_relevant( basic::options::OptionKeys::enzdes::flexbb_protocol );
72  basic::options::option.add_relevant( basic::options::OptionKeys::enzdes::process_ligrot_separately );
73  basic::options::option.add_relevant( basic::options::OptionKeys::out::file::o );
74 
75  devel::init(argc, argv);
76 
77  time_t overall_start_time = time(NULL);
78  utility::vector1< protocols::jobdist::BasicJobOP > input_jobs = protocols::jobdist::load_s_and_l();
79 
80  //#ifndef USEMPI
81  // Reduce read contention between processes by randomizing the order in which structures are processed
82  // Do not randomize, though, if job distribution is controlled by MPI
83  //numeric::random::random_permutation( input_jobs, numeric::random::rg() );
84  //#endif
85 
86  protocols::jobdist::PlainPdbJobDistributor jobdist( input_jobs );
87 
88  using namespace basic::options;
89  using namespace basic::options::OptionKeys;
90 
91  if ( option[ out::nooutput ]() ) {
92  jobdist.disable_output();
93  jobdist.enable_ignorefinished();
94  }
95 
96 
97  protocols::enzdes::EnzdesBaseProtocolOP enzdes_protocol;
98  protocols::enzdes::EnzdesScorefileFilterOP enz_scofile;
99 
100  if ( option[ OptionKeys::enzdes::flexbb_protocol ] ) enzdes_protocol = protocols::enzdes::EnzdesBaseProtocolOP( new protocols::enzdes::EnzdesFlexBBProtocol() );
101  //else if( option[ OptionKeys::enzdes::remodel_protocol ] ) enzdes_protocol = new devel::enzdes::EnzdesRemodelProtocol();
102  else enzdes_protocol = protocols::enzdes::EnzdesBaseProtocolOP( new protocols::enzdes::EnzdesFixBBProtocol() );
103 
104  std::string scorefile_name("");
105 
106  if ( option[ OptionKeys::out::file::o ].user() ) {
107  scorefile_name = option[ OptionKeys::out::file::o ]();
108  enz_scofile = protocols::enzdes::EnzdesScorefileFilterOP( new protocols::enzdes::EnzdesScorefileFilter() );
109  //enz_scofile->set_cstio( enzdes_protocol->cst_io() );
110  if ( option[ OptionKeys::out::overwrite ].user() ) {
111  if ( utility::file::file_exists( scorefile_name ) ) utility::file::file_delete( scorefile_name );
112  }
113  }
114  core::io::silent::SilentFileDataOP scorefile( new core::io::silent::SilentFileData() );
115 
116  if ( option[OptionKeys::enzdes::cstfile].user() ) {
117  option[OptionKeys::run::preserve_header ].value(true);
118  //enzdes_protocol->cst_io()->read_enzyme_cstfile(basic::options::option[basic::options::OptionKeys::enzdes::cstfile]);
119  }
120 
121 
122  protocols::jobdist::BasicJobOP curr_job, prev_job;
123  int curr_nstruct=0, num_structures_processed = 0;
124  core::Size prevstruct(0);
125  core::pose::PoseOP input_pose; // starts NULL, coords *never* modified!
126  jobdist.startup();
127 
128  while ( jobdist.next_job(curr_job, curr_nstruct) ) {
129  time_t pdb_start_time = time(NULL);
130  tr << "Starting " << curr_job->output_tag(curr_nstruct) << " ..." << std::endl;
131 
132  if ( curr_nstruct == 1 ) prevstruct = 0;
133 
134  // we read each PDB just once to save on disk I/O
135  if ( curr_job.get() != prev_job.get() || input_pose.get() == NULL ) {
136  input_pose = core::pose::PoseOP( new core::pose::Pose() );
137  //core::import_pose::pose_from_pdb( *input_pose, curr_job->input_tag() );
138  protocols::enzdes::enzutil::read_pose_from_pdb( *input_pose, curr_job->input_tag() );
139  }
140 
141  // Make a modifiable copy of the pose read from disk
142  core::pose::PoseOP the_pose( new core::pose::Pose( *input_pose ) );
143  std::string outext = "_DE";
144  if ( basic::options::option[basic::options::OptionKeys::out::suffix].user() ) {
145  outext = basic::options::option[basic::options::OptionKeys::out::suffix];
146  }
147  std::string prefix = "";
148  if ( basic::options::option[basic::options::OptionKeys::out::prefix].user() ) {
149  prefix = basic::options::option[basic::options::OptionKeys::out::prefix];
150  }
151 
153 
154  if ( option[ OptionKeys::enzdes::process_ligrot_separately ].user() ) {
155 
156  (*enzdes_protocol->get_scorefxn() )( *the_pose );
157  enzdes_protocol->generate_explicit_ligand_rotamer_poses( *the_pose, poses_to_process, enzdes_protocol->get_scorefxn() );
158 
159  if ( poses_to_process.size() == 0 ) poses_to_process.push_back( the_pose );
160  else tr << "For " << curr_job->input_tag() << ", " << poses_to_process.size() << " explicit ligrot poses will be processed." << std::endl;
161  } else poses_to_process.push_back( the_pose );
162 
163  for ( core::Size pose_count = 1; pose_count <= poses_to_process.size(); ++pose_count ) {
164 
165  utility::file::FileName out_name( curr_job->input_tag() );
166  //std::string outtag = out_name.base() + "_" + utility::to_string( curr_nstruct ) + "_" + outext + utility::to_string( pose_count + prevstruct );
167  std::string outtag = prefix + out_name.base() + "_" + outext + "_" + utility::to_string( pose_count + prevstruct );
168 
169  if ( utility::file::file_exists( outtag+".pdb" ) && ! option[ OptionKeys::out::overwrite ].user() ) {
170  tr << "File " << outtag+".pdb" << " already exists, skipping structure. Use option -out::overwrite if you want to overwrite existing files." << std::endl;
171  continue;
172  }
173 
174  using namespace basic::datacache;
175  (poses_to_process[ pose_count ])->data().set(core::pose::datacache::CacheableDataType::JOBDIST_OUTPUT_TAG, DataCache_CacheableData::DataOP( new basic::datacache::CacheableString( outtag ) ) );
176  enzdes_protocol->apply( *(poses_to_process[ pose_count ]) );
177 
178  //in case we're only interested in scoring and there is an output
179  //file, dont write a pdb (can be overriden by nstruct)
180  if ( !( ( option[OptionKeys::enzdes::enz_score] ) &&
181  ( option[ OptionKeys::out::file::o ].user() ) &&
182  ( ! option[ OptionKeys::out::nstruct ].user() ) ) ) {
183  jobdist.dump_pose_and_map( outtag, *(poses_to_process[ pose_count ]) );
184  }
185 
186  //write the score file, eventually maybe even a silent file
187  if ( basic::options::option[ basic::options::OptionKeys::out::file::o ].user() ) {
188 
189  protocols::toolbox::match_enzdes_util::EnzConstraintIOCOP cstio( protocols::enzdes::enzutil::get_enzcst_io( *(poses_to_process[ pose_count ] ) ) );
190  enz_scofile->set_cstio( cstio );
191  core::io::silent::SilentStructOP ss( new core::io::silent::ScoreFileSilentStruct(
192  *(poses_to_process[ pose_count ]), outtag ) );
193  ss->precision( 2 );
194  ss->scoreline_prefix( "" );
195 
196  enz_scofile->examine_pose( *(poses_to_process[ pose_count ]) );
197 
198  if ( option[OptionKeys::enzdes::final_repack_without_ligand] ) {
199  //pose after ligand repack get's written as model 2
200  if ( option[OptionKeys::enzdes::dump_final_repack_without_ligand_pdb] ) {
201  jobdist.dump_pose_and_map( outtag+"_nlrepack", *(enz_scofile->rnl_pose() ) );
202  }
203  } //if( option[OptionKeys::enzdes::final_repack_without_ligand] )
204 
205  ss->silent_energies( enz_scofile->silent_Es() );
206  scorefile->write_silent_struct( *ss, scorefile_name, true );
207  }
208  } // iterator over poses to process
209 
210  prevstruct += poses_to_process.size();
211 
212  prev_job = curr_job; // pointer assignment, not a copy op
213  num_structures_processed += 1;
214  time_t pdb_end_time = time(NULL);
215  //std::cerr << curr_job->output_tag(curr_nstruct) << " done." << std::endl;
216  tr << "Finished " << curr_job->output_tag(curr_nstruct) << " in " << (long)(pdb_end_time - pdb_start_time) << " seconds." << std::endl;
217  } // loop over jobs and nstructs
218  jobdist.shutdown();
219 
220  time_t overall_end_time = time(NULL);
221  tr << "Finished all " << num_structures_processed << " structures in " << (long)(overall_end_time - overall_start_time) << " seconds." << std::endl;
222  if ( num_structures_processed == 0 ) {
223  basic::Warning() << "No structures processed. Existing output files may have been skipped, did you mean to delete them or to use the -overwrite flag?" << std::endl;
224  }
225  return 0;
226  }
227 catch (utility::excn::EXCN_Base const & e ) {
228  std::cout << "caught exception " << e.msg() << std::endl;
229  return -1;
230 }
231 }
232 
#define THREAD_LOCAL
virtual std::string const msg() const
Definition: EXCN_Base.hh:70
void register_options()
A DataCache storing objects derived from basic::datacache::CacheableData.
int main(int argc, char *argv[])
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
Platform independent operations on files (except I/O)
static THREAD_LOCAL basic::Tracer tr("apps.public.enzdes.enzyme_design")
File name class supporting Windows and UN*X/Linux format names.
Definition: FileName.hh:37
common derived classes for thrown exceptions
Wrapper for std::string.
static void add_relevant(const OptionKey &key)
add OptionKey to list of application relevant options
Tracer IO system.
std::vector with 1-based indexing
Definition: vector1.fwd.hh:44
basic::options::IntegerOptionKey const nstruct("nstruct")
rule< Scanner, options_closure::context_t > options
Definition: Tag.cc:377
int file_delete(std::string const &path)
Delete File.
Tracer & Warning(TracerPriority priority=t_warning)
Predefined Warning tracer.
Definition: Tracer.hh:398
utility::options::OptionCollection option
OptionCollection global.
Definition: option.cc:45
ocstream cout(std::cout)
Wrapper around std::cout.
Definition: ocstream.hh:287
FileName & base(std::string const &base_a)
Base assignment.
Definition: FileName.hh:163
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
bool file_exists(std::string const &path)
Does File Exist?
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
rule< Scanner, option_closure::context_t > option
Definition: Tag.cc:378