Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 32 additions & 24 deletions source/src/protocols/rosetta_scripts/MultipleOutputWrapper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#include <protocols/moves/MoverFactory.hh>
#include <protocols/rosetta_scripts/RosettaScriptsParser.hh>
#include <protocols/rosetta_scripts/ParsedProtocol.hh>
#include <protocols/rosetta_scripts/util.hh>

// Package headers
#include <basic/datacache/DataMap.fwd.hh>
Expand Down Expand Up @@ -64,7 +65,6 @@ using namespace protocols::moves;

MultipleOutputWrapper::MultipleOutputWrapper() :
Mover( "MultipleOutputWrapper" ),
mover_tag_(/* NULL */),
rosetta_scripts_tag_(/* NULL */),
reference_pose_(/* NULL */),
max_poses_(0),
Expand Down Expand Up @@ -103,29 +103,27 @@ core::pose::PoseOP MultipleOutputWrapper::get_additional_output()

bool MultipleOutputWrapper::generate_pose(core::pose::Pose & pose)
{
// Empty objects... may not work...
basic::datacache::DataMap data;
if ( !keep_mover_state_ ) {
mover_ = nullptr;
}
runtime_assert( mover_ != nullptr );

if ( !mover_ && rosetta_scripts_tag_ ) {
protocols::rosetta_scripts::RosettaScriptsParser parser;
mover_ = parser.parse_protocol_tag( rosetta_scripts_tag_, basic::options::option );
}
protocols::moves::MoverOP local_mover;

if ( !mover_ && mover_tag_ ) {
mover_ = MoverFactory::get_instance()->newMover(mover_tag_, data);
if ( keep_mover_state_ ) {
local_mover = mover_;
} else {
if ( rosetta_scripts_tag_ ) {
protocols::rosetta_scripts::RosettaScriptsParser parser;
local_mover = parser.parse_protocol_tag( rosetta_scripts_tag_, basic::options::option );
} else {
local_mover = mover_->clone();
}
}

runtime_assert( mover_ != nullptr );

core::Size attempts;
for ( attempts = 1; attempts <= max_attempts_; ++attempts ) {

mover_->apply(pose);
local_mover->apply(pose);

protocols::moves::MoverStatus status = mover_->get_last_move_status();
protocols::moves::MoverStatus status = local_mover->get_last_move_status();
set_last_move_status(status);
if ( status != protocols::moves::MS_SUCCESS ) {
TR << "Sub-mover or protocol reported failure on attempt " << attempts << " of " << max_attempts_ << std::endl;
Expand Down Expand Up @@ -179,6 +177,18 @@ void MultipleOutputWrapper::parse_my_tag(
keep_mover_state_ = tag->getOption<bool>("keep_mover_state");
}

if ( tag->hasOption("mover") ) {
mover_ = rosetta_scripts::parse_mover( tag->getOption< std::string >( "mover", "null" ), data );
}

if ( mover_ && tag->getTags().size() > 0 ) {
TR.Warning << "MultipleOutputWrapper specified with mover in options and as subtags -- using subtag definiton only." << std::endl;
}

if ( tag->getTags().size() > 0 ) {
TR.Warning << "MultipleOutputWrapper has multiple subtag specifications -- only using the first" << std::endl;
}

try {

// Children of tag are movers
Expand All @@ -187,22 +197,19 @@ void MultipleOutputWrapper::parse_my_tag(
if ( curr_tag->getName() == "ROSETTASCRIPTS" ) {
// Treat subtag as a ROSETTASCRIPTS protocol
protocols::rosetta_scripts::RosettaScriptsParser parser;
protocols::moves::MoverOP mover( parser.parse_protocol_tag( curr_tag, basic::options::option ) );
rosetta_scripts_tag_ = curr_tag;
mover_ = parser.parse_protocol_tag( curr_tag, basic::options::option );
} else {
// Treat subtag as a regular mover tag
std::string name = curr_tag->getOption<std::string>("name");
protocols::moves::MoverOP new_mover(
protocols::moves::MoverFactory::get_instance()->
newMover(curr_tag, data)
);
mover_tag_ = curr_tag;
mover_ = MoverFactory::get_instance()->newMover(curr_tag, data);
}
// Only first mover used -- add warning when multiple defined?
break;
break; // Warned about multiple tags above
}

if ( !mover_tag_ && !rosetta_scripts_tag_ ) {
if ( !mover_ ) {
throw CREATE_EXCEPTION(utility::excn::Exception, "No mover or ROSETTASCRIPTS tag found.");
}

Expand Down Expand Up @@ -231,7 +238,8 @@ void MultipleOutputWrapper::provide_xml_schema( utility::tag::XMLSchemaDefinitio
+ optional_name_attribute()
+ Attr( "max_output_poses", xsct_non_negative_integer, "XRW TO DO" )
+ Attr( "max_attempts", xsct_non_negative_integer, "XRW TO DO" )
+ Attr( "keep_mover_state", xsct_rosetta_bool, "XRW TO DO" );
+ Attr( "keep_mover_state", xsct_rosetta_bool, "XRW TO DO" )
+ Attr( "mover", xs_string, "The mover to apply multiple times" );

XMLSchemaSimpleSubelementList subelements;
subelements.add_already_defined_subelement(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ public:

private:
std::string name_;
utility::tag::TagCOP mover_tag_;
utility::tag::TagCOP rosetta_scripts_tag_;
core::pose::PoseOP reference_pose_;
core::Size max_poses_;
Expand Down
82 changes: 57 additions & 25 deletions source/src/protocols/rosetta_scripts/MultiplePoseMover.cc
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
#include <protocols/moves/Mover.hh>
#include <protocols/rosetta_scripts/RosettaScriptsParser.hh>
#include <protocols/rosetta_scripts/ParsedProtocol.hh>
#include <protocols/rosetta_scripts/util.hh>

// XSD XRW Includes
#include <utility/tag/XMLSchemaGeneration.hh>
Expand Down Expand Up @@ -261,27 +262,28 @@ std::deque < core::pose::PoseOP > MultiplePoseMover::process_poses( std::deque <
/// @brief Process a single input pose by the RosettaScripts mover
bool MultiplePoseMover::process_pose( core::pose::Pose & pose, utility::vector1 < core::pose::PoseOP > & additional_poses )
{
if ( !rosetta_scripts_tag_ ) {
return true;
}
protocols::moves::MoverOP mover;

protocols::rosetta_scripts::RosettaScriptsParser parser;
if ( rosetta_scripts_tag_ ) {
protocols::rosetta_scripts::RosettaScriptsParser parser;

// rosetta_scripts_tag_ has been pre-parsed in parse_my_tag() so no parsing exception should be thrown here
// No longer true, in fact, as the original parse_my_tag call has been removed, since the Pose needed for that
// call is not present until we get to the MPM's apply call.
protocols::moves::MoverOP mover;
try {
rosetta_scripts_tag_->reset_accessed_options();
mover = parser.parse_protocol_tag( rosetta_scripts_tag_, basic::options::option );
if ( !mover ) {
TR << "Failed to parse protocol? This should not happen. Not applying protocol to pose." << std::endl;
return false;
// This can throw if the tag can't be properly parsed
try {
rosetta_scripts_tag_->reset_accessed_options();
mover = parser.parse_protocol_tag( rosetta_scripts_tag_, basic::options::option );
if ( !mover ) {
TR << "Failed to parse protocol? This should not happen. Not applying protocol to pose." << std::endl;
return false;
}
} catch ( utility::excn::Exception const & e ) {
std::ostringstream oss;
oss << "MultiplePoseMover could not create the inner parsed protocol; error message generated from parser.parse_protocol_tag:\n" << e.msg();
throw CREATE_EXCEPTION(utility::excn::Exception, oss.str() );
}
} catch ( utility::excn::Exception const & e ) {
std::ostringstream oss;
oss << "MultiplePoseMover could not create the inner parsed protocol; error message generated from parser.parse_protocol_tag:\n" << e.msg();
throw CREATE_EXCEPTION(utility::excn::Exception, oss.str() );
} else if ( mover_ ) {
mover = mover_->clone(); // New copy to keep from saving state across calls
} else {
return true;
}

mover->apply(pose);
Expand Down Expand Up @@ -327,6 +329,12 @@ void MultiplePoseMover::parse_my_tag(
utility::tag::TagCOP tag,
basic::datacache::DataMap & data
) {
std::string my_name;
if ( tag->hasOption("name") ) {
my_name = tag->getOption<std::string>("name");
} else {
my_name = "Anonymous " + tag->getName();
}

if ( tag->hasOption("max_input_poses") ) {
max_input_poses_ = tag->getOption<int>("max_input_poses", 0);
Expand All @@ -338,6 +346,10 @@ void MultiplePoseMover::parse_my_tag(
cached_ = tag->getOption<bool>("cached");
}

if ( tag->hasOption("mover") ) {
mover_ = rosetta_scripts::parse_mover( tag->getOption< std::string >( "mover", "null" ), data );
}

try {

// ROSETTASCRIPTS tag (optional)
Expand All @@ -349,6 +361,20 @@ void MultiplePoseMover::parse_my_tag(
// protocols::moves::MoverOP mover( parser.parse_protocol_tag( rosetta_scripts_tag_ ) );
recursively_access_all_attributes( rs_tag );
}
if ( mover_ && rosetta_scripts_tag_ ) {
TR.Warning << "Both a mover and a ROSETTASCRIPTS specification was set with a MultiplePoseMover -- the script will take precedence, and the mover will be ignored." << std::endl;
}

if ( tag->hasTag("PROTOCOLS") ) {
if ( mover_ ) {
TR.Warning << "Both a mover and a PROTOCOLS block was set with a MultiplePoseMover -- the protocols block will take precedence, and the mover will be ignored." << std::endl;
}
if ( rosetta_scripts_tag_ ) {
TR.Warning << "Both a PROTOCOLS and a ROSETTASCRIPTS specification was set with a MultiplePoseMover -- the script will take precedence, and the PROTOCOLS will be ignored." << std::endl;
}
mover_ = utility::pointer::make_shared< protocols::rosetta_scripts::ParsedProtocol >();
mover_->parse_my_tag( tag->getTag("PROTOCOLS"), data );
}

// SELECT tag (optional)
if ( tag->hasTag("SELECT") ) {
Expand All @@ -367,16 +393,15 @@ void MultiplePoseMover::parse_my_tag(
}
}


// Warn if no ROSETTASCRIPTS protocol and no SELECTOR (i.e. null mover)
if ( selectors_.size() < 1 && !rosetta_scripts_tag_ ) {
std::string my_name( tag->getOption<std::string>("name") );
TR.Warning << "Neither a ROSETTASCRIPTS protocol nor a SELECT statement specified in MultiplePoseMover with name \"" << my_name << "\". This mover has no effect. Are you sure this is what you intended?" << std::endl;
if ( selectors_.size() < 1 && !rosetta_scripts_tag_ && !mover_ ) {
TR.Warning << "Neither a ROSETTASCRIPTS protocol nor a SELECT statement nor a mover or PROTOCOLS specified in MultiplePoseMover with name \"" << my_name << "\". This mover has no effect. Are you sure this is what you intended?" << std::endl;
}

// TODO: Should we complain here is there are tags specified that we don't understand?

} catch( utility::excn::Exception const & e ) {
std::string my_name( tag->getOption<std::string>("name") );
throw CREATE_EXCEPTION(utility::excn::Exception, "Exception in MultiplePoseMover with name \"" + my_name + "\": " + e.msg());
}

Expand Down Expand Up @@ -408,6 +433,8 @@ void MultiplePoseMover::parse_my_tag(
/// @brief Used by RosettaScripts to set the previous mover to pull poses from
void MultiplePoseMover::set_previous_mover( protocols::moves::MoverOP const m ) { previous_mover_ = m; }

void MultiplePoseMover::set_main_mover( protocols::moves::MoverOP const m ) { mover_ = m; }

/// @brief sets rosettascripts tag
void MultiplePoseMover::set_rosetta_scripts_tag( utility::tag::TagCOP tag ) { rosetta_scripts_tag_ = tag; }

Expand All @@ -433,7 +460,8 @@ void MultiplePoseMover::provide_xml_schema( utility::tag::XMLSchemaDefinition &
attlist
+ Attr( "max_input_poses", xsct_non_negative_integer, "XSD TO DO" )
+ Attr( "max_output_poses", xsct_non_negative_integer, "XSD TO DO" )
+ Attr( "cached", xsct_rosetta_bool, "XSD TO DO" );
+ Attr( "cached", xsct_rosetta_bool, "XSD TO DO" )
+ Attr( "mover", xs_string, "The mover to apply to each of the poses (instead of the script)" );

PoseSelectorFactory::get_instance()->define_pose_selector_group( xsd );

Expand All @@ -446,20 +474,24 @@ void MultiplePoseMover::provide_xml_schema( utility::tag::XMLSchemaDefinition &
.description( "XRW TO DO" )
.write_complex_type_to_schema( xsd );

XMLSchemaSimpleSubelementList rs_element, select_element;
XMLSchemaSimpleSubelementList rs_element, select_element, protocol_element;
rs_element.add_already_defined_subelement(
RosettaScriptsParser::rosetta_scripts_element_name(),
& RosettaScriptsParser::rosetta_scripts_complex_type_naming_func );
select_element.add_already_defined_subelement(
"SELECT", & mpm_mangler );
protocol_element.add_already_defined_subelement_w_alt_element_name(
"PROTOCOLS", ParsedProtocol::mover_name(), & moves::complex_type_name_for_mover );

XMLSchemaComplexTypeGenerator ct_gen;
ct_gen.element_name( mover_name() )
.complex_type_naming_func( & protocols::moves::complex_type_name_for_mover )
.add_attributes( attlist )
.add_optional_name_attribute()
.add_ordered_subelement_set_as_optional( select_element )
.add_ordered_subelement_set_as_optional( rs_element )
.description( "XRW TO DO" )
.add_ordered_subelement_set_as_optional( protocol_element )
.description( "Take multiple poses generated by the previous mover in the protocol list and apply selectors and additional movers on them." )
.write_complex_type_to_schema( xsd );
}

Expand Down
4 changes: 4 additions & 0 deletions source/src/protocols/rosetta_scripts/MultiplePoseMover.hh
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ public:
/// @brief sets rosettascripts tag
void set_rosetta_scripts_tag( utility::tag::TagCOP tag );

/// @brief sets the mover to use on each structure (versus the RosettaScripts script)
void set_main_mover( protocols::moves::MoverOP const m );

std::string
get_name() const override;

Expand All @@ -93,6 +96,7 @@ private:
bool cached_;
core::Size max_input_poses_, max_output_poses_;
utility::tag::TagCOP rosetta_scripts_tag_;
protocols::moves::MoverOP mover_; // Use a mover instead of a RosettaScripts tag
utility::tag::TagCOP selector_tag_;
protocols::moves::MoverOP previous_mover_;
utility::vector1 < PoseSelectorOP > selectors_;
Expand Down
Loading