28 #include <ObjexxFCL/string.functions.hh>
31 #include <basic/options/option.hh>
37 #include <utility/tag/Tag.hh>
46 #include <boost/foreach.hpp>
47 #define foreach BOOST_FOREACH
69 #include <utility/vector1.hh>
70 #include <utility/io/izstream.hh>
81 #include <basic/options/keys/parser.OptionKeys.gen.hh>
84 #include <utility/vector0.hh>
85 #include <basic/Tracer.hh>
92 using namespace basic::options;
93 using namespace scoring;
94 using namespace moves;
96 static basic::Tracer
TR(
"protocols.jd2.DockDesignParser" );
133 bool modified_pose(
false );
135 if( !new_input )
return modified_pose;
139 std::string const dock_design_filename( xml_fname ==
"" ? option[ OptionKeys::parser::protocol ] : xml_fname );
140 TR <<
"dock_design_filename=" << dock_design_filename << std::endl;
141 utility::io::izstream fin;
142 fin.open(dock_design_filename.c_str() );
144 utility_exit_with_message(
"Unable to open Rosetta Scripts XML file: '" + dock_design_filename +
"'.");
147 if( option[ OptionKeys::parser::script_vars ].user() ) {
148 std::stringstream fin_sub;
150 tag = utility::tag::Tag::create( fin_sub );
153 tag = utility::tag::Tag::create(fin);
156 TR <<
"Parsed script:" <<
"\n";
159 runtime_assert( tag->getName() ==
"dock_design" || tag->getName() ==
"ROSETTASCRIPTS" );
167 typedef std::pair< std::string const, MoverOP > StringMover_pair;
168 typedef std::pair< std::string const, protocols::filters::FilterOP >
StringFilter_pair;
169 typedef std::pair< std::string const, ScoreFunctionOP > StringScorefxn_pair;
170 typedef std::pair< std::string const, StringScorefxn_pair > ScorefxnObjects_pair;
178 movers.insert( StringMover_pair(
"null", null_mover) );
188 data.
add(
"scorefxns",
"commandline", commandline_sfxn );
189 data.
add(
"scorefxns",
"score12", score12 );
190 data.
add(
"scorefxns",
"score_docking", docking_score );
191 data.
add(
"scorefxns",
"soft_rep", soft_rep );
192 data.
add(
"scorefxns",
"score_docking_low", docking_score_low );
193 data.
add(
"scorefxns",
"score4L", score4L );
197 std::set< std::string > non_data_loader_tags;
198 non_data_loader_tags.insert(
"MOVERS" );
199 non_data_loader_tags.insert(
"APPLY_TO_POSE" );
200 non_data_loader_tags.insert(
"FILTERS" );
201 non_data_loader_tags.insert(
"PROTOCOLS" );
202 non_data_loader_tags.insert(
"OUTPUT" );
206 TagPtrs const all_tags = tag->getTags();
207 for (
Size ii = 0; ii < all_tags.size(); ++ii ) {
208 using namespace parser;
209 TagPtr iitag = all_tags[ ii ];
210 if ( non_data_loader_tags.find( iitag->getName() ) != non_data_loader_tags.end() )
continue;
211 DataLoaderOP loader = DataLoaderFactory::get_instance()->newDataLoader( iitag->getName() );
212 loader->load_data( pose, iitag, data );
214 if ( !tag->hasTag(
"MOVERS") )
215 utility_exit_with_message(
"parser::protocol file must specify MOVERS section");
216 if ( !tag->hasTag(
"PROTOCOLS") )
217 utility_exit_with_message(
"parser::protocol file must specify PROTOCOLS section");
219 foreach(
TagPtr const curr_tag, all_tags ){
221 if ( curr_tag->getName() ==
"APPLY_TO_POSE" ) {
223 TagPtrs const apply_tags( curr_tag->getTags() );
226 foreach(
TagPtr apply_tag_ptr, apply_tags){
227 std::string const mover_type( apply_tag_ptr->getName() );
229 runtime_assert( new_mover );
230 new_mover->apply( pose );
231 TR <<
"Defined and applied mover of type " << mover_type << std::endl;
232 bool const name_exists( movers.find( mover_type ) != movers.end() );
234 utility_exit_with_message(
"Can't apply_to_pose the same mover twice" + mover_type );
237 modified_pose =
true;
246 if ( curr_tag->getName() ==
"FILTERS" ) {
248 foreach(
TagPtr tag_ptr, curr_tag->getTags()){
250 if ( ! tag_ptr->hasOption(
"name") )
251 utility_exit_with_message(
"Can't define unnamed Filter of type " + type );
253 bool const name_exists( filters.find( user_defined_name ) != filters.end() );
255 TR.Error <<
"ERROR filter of name \"" << user_defined_name <<
"\" (with type " << type
256 <<
") already exists. \n" << tag << std::endl;
257 utility_exit_with_message(
"Duplicate definition of Filter with name " + user_defined_name);
260 runtime_assert( new_ddf );
261 filters.insert( std::make_pair( user_defined_name, new_ddf ) );
262 TR <<
"Defined filter named \"" << user_defined_name <<
"\" of type " << type << std::endl;
269 if( curr_tag->getName() ==
"MOVERS" ){
270 foreach(
TagPtr tag_ptr, curr_tag->getTags()){
272 if ( ! tag_ptr->hasOption(
"name") )
273 utility_exit_with_message(
"Can't define unnamed Mover of type " + type );
275 bool const name_exists( movers.find( user_defined_name ) != movers.end() );
277 TR.Error <<
"ERROR mover of name \"" << user_defined_name <<
"\" (with type " << type
278 <<
") already exists.\n" << tag << std::endl;
279 utility_exit_with_message(
"Duplicate definition of Mover with name " + user_defined_name);
283 runtime_assert( new_mover );
284 movers.insert( std::make_pair( user_defined_name, new_mover ) );
285 TR <<
"Defined mover named \"" << user_defined_name <<
"\" of type " << type << std::endl;
292 TagPtr const protocols_tag( tag->getTag(
"PROTOCOLS") );
293 protocol->parse_my_tag( protocols_tag, data, filters, movers, pose );
297 if ( tag->hasTag(
"OUTPUT") ) {
298 TagPtr const output_tag( tag->getTag(
"OUTPUT") );
301 protocol->final_scorefxn( commandline_sfxn );
304 tag->die_for_unaccessed_options_recursively();
306 return modified_pose;
318 map<string,string> var_map;
319 for(
Size ii = 1; ii <= script_vars.size(); ii++ ) {
320 Size eq_pos(script_vars[ii].find(
'='));
321 if(eq_pos != string::npos) {
322 var_map[ script_vars[ii].substr(0,eq_pos) ] = script_vars[ii].substr(eq_pos+1);
326 TR <<
"Variable substitution will occur with the following values: ";
327 for( map<string,string>::const_iterator map_it( var_map.begin() ), map_end( var_map.end() );
328 map_it != map_end; ++map_it ){
329 TR <<
"'%%" << map_it->first <<
"%%'='" << map_it->second <<
"'; ";
334 TR <<
"Substituted script:" <<
"\n";
336 while( getline( in, line ) ) {
339 while( ( pos = line.find(
"%%", last) ) != string::npos) {
340 end = line.find(
"%%", pos+2);
341 if(end == string::npos)
break;
342 outline += line.substr( last, pos-last );
344 string var( line.substr( pos+2, end-(pos+2) ) );
345 if( var_map.find( var ) != var_map.end() ) {
346 outline += var_map[var];
349 outline +=
"%%" + var +
"%%";
352 outline += line.substr( last );
353 TR << outline <<
"\n";
354 out << outline <<
"\n";
379 using namespace core::pose::metrics;
381 if( !CalculatorFactory::Instance().check_calculator_exists(
"sasa_interface" ) ){
383 CalculatorFactory::Instance().register_calculator(
"sasa_interface", int_sasa_calculator );
386 if( !CalculatorFactory::Instance().check_calculator_exists(
"sasa" ) ){
388 CalculatorFactory::Instance().register_calculator(
"sasa", sasa_calculator );
390 if( !CalculatorFactory::Instance().check_calculator_exists(
"ligneigh" ) ){
392 CalculatorFactory::Instance().register_calculator(
"ligneigh", lig_neighbor_calc );
394 if( !CalculatorFactory::Instance().check_calculator_exists(
"liginterfE" ) ){
396 CalculatorFactory::Instance().register_calculator(
"liginterfE", lig_interf_E_calc );