28 #include <basic/Tracer.hh>
29 #include <numeric/expression_parser/Arithmetic.hh>
34 #include <utility/exit.hh>
35 #include <utility/string_util.hh>
36 #include <utility/vector1.functions.hh>
37 #include <utility/mpi_util.hh>
38 #include <utility/excn/Exceptions.hh>
47 #include <utility/vector0.hh>
48 #include <utility/vector1.hh>
52 namespace pack_daemon {
54 static basic::Tracer
TR(
"protocols.pack_daemon.DynamicAggregateFunction" );
56 using namespace numeric::expression_parser;
66 utility_exit_with_message(
"Illegal call to operator() on VectorExpression named " +
name() );
73 utility_exit_with_message(
"Illegal call to differentiate() on VectorExpression named " +
name() );
98 for (
Size ii = 1; ii <=
vars_.size(); ++ii ) {
99 vals[ ii ] = (*
vars_[ ii ])();
110 std::list< std::string >
113 utility_exit_with_message(
"VariableVectorExpression::active_variables should not be called" );
114 return std::list< std::string >();
121 for (
Size ii = 1; ii <=
vars_.size(); ++ii ) {
122 active_vars_vector[ ii ] =
vars_[ ii ]->active_variables();
129 return active_vars_vector;
156 std::map< std::string, VectorExpressionCOP >
const & vector_varnames,
161 Size s = vector_varnames.size();
165 for ( std::map< std::string, VectorExpressionCOP >::const_iterator
166 iter = vector_varnames.begin(), iter_end = vector_varnames.end();
167 iter != iter_end; ++iter ) {
174 for (
Size ii = 2; ii <= s; ++ii ) {
176 utility_exit_with_message(
"IterativeVectorExpression " +
name() +
" initialized with vector-expressions of uneven sizes: "
189 expression_ = expression_creator.create_expression_tree( expresion_ast );
197 if ( s == 0 ) {
values empty;
return empty; }
201 for (
Size ii = 1; ii <= s; ++ii ) {
204 if ( vec_of_values[ ii ].
size() != vec_of_values[ ii - 1 ].
size() ) {
205 utility_exit_with_message(
"IterativeVectorExpression " +
name() +
" recieved vectors of uneven sizes from its children: "
211 values return_vals( vec_of_values[ 1 ].
size(), 0.0 );
212 for (
Size ii = 1; ii <= return_vals.size(); ++ii ) {
213 for (
Size jj = 1; jj <= s; ++jj ) {
216 return_vals[ ii ] = (*expression_)();
234 VariableExpressionCOP
237 std::map< std::string, VariableExpressionCOP >::const_iterator varit =
local_variable_map_.find( varname );
239 return varit->second;
244 std::list< std::string >
247 utility_exit_with_message(
"IterativeVectorExpression::active_variables should not be called" );
248 return std::list< std::string >();
258 utility_exit_with_message(
"IterativeVectorExpression::active_variables_vector has not yet been implemented. Email Andrew");
259 return active_varibles_vector;
272 return utility::max( vals );
278 utility_exit_with_message(
"VMax cannot be differentiated" );
282 std::list< std::string >
287 Size index = utility::arg_max( vals );
288 return act_vars_vect[ index ];
301 return utility::min( vals );
307 utility_exit_with_message(
"VMin cannot be differentiated" );
311 std::list< std::string >
316 Size index = utility::arg_min( vals );
322 return act_vars_vect[ index ];
335 assert( vals2.size() == vals1.size() );
337 Size index = utility::arg_max( vals1 );
338 return vals2[ index ];
344 utility_exit_with_message(
"VMaxBy cannot be differentiated" );
348 std::list< std::string >
353 assert( vals1.size() == act_vars_vect2.size() );
355 Size index = utility::arg_max( vals1 );
356 return act_vars_vect2[ index ];
369 assert( vals1.size() == vals2.size() );
371 Size index = utility::arg_min( vals1 );
372 return vals2[ index ];
378 utility_exit_with_message(
"VMinBy cannot be differentiated" );
382 std::list< std::string >
387 assert( vals1.size() == act_vars_vect2.size() );
389 Size index = utility::arg_min( vals1 );
390 return act_vars_vect2[ index ];
402 return std::pow( (*e1())(), (*e2())() );
408 utility_exit_with_message(
"PowExpression::diffrentiate is unimplemented!" );
420 return std::exp( (*ex())() );
426 utility_exit_with_message(
"ExpExpression::diffrentiate is unimplemented!" );
439 return std::log( (*ex())() );
445 utility_exit_with_message(
"LnExpression::diffrentiate is unimplemented!" );
473 utility_exit_with_message(
"InSetExpression::diffrentiate is unimplemented!" );
491 FunctionTokenCOP
function,
495 ExpressionCOP parent_expression = parent::handle_function_expression(
function, args );
496 if ( parent_expression ) {
497 return parent_expression;
509 root_expression_( 0 )
517 root_expression_( 0 )
526 std::list< std::string >
532 std::list< std::string > empty_list;
556 if ( setting == 0 ) {
557 throw utility::excn::EXCN_Msg_Exception(
"DynamicAggregateFunction::set_num_entity_elements may not be"
558 "passed a number of entity elements == 0" );
561 throw utility::excn::EXCN_Msg_Exception(
"DynamicAggregateFunction::set_num_entity_elements may only"
593 if ( TR.visible( basic::t_debug )) {
594 TR.Debug <<
"DAF::eval";
595 for (
Size ii = 1; ii <= state_energies.size(); ++ii ) {
596 TR.Debug <<
" " << state_energies[ ii ];
604 if ( TR.visible( basic::t_debug )) {
605 TR.Debug <<
" s: " << score << std::endl;
627 TR <<
"Recovering relevant states" << std::endl;
629 std::list< std::string > active_varnames =
fitness_exp_->active_variables();
630 StateIndices active_indices; active_indices.reserve( active_varnames.size() );
631 for ( std::list< std::string >::const_iterator
632 iter = active_varnames.begin(), iter_end = active_varnames.end();
633 iter != iter_end; ++iter ) {
638 TR <<
"The variable named '" << *iter <<
"' contributes to the fitness but does not correspond to a state." << std::endl;
644 std::sort( active_indices.begin(), active_indices.end() );
645 StateIndices::const_iterator end_iter = std::unique( active_indices.begin(), active_indices.end() );
646 StateIndices return_indices; return_indices.reserve( active_indices.size() );
647 StateIndices::const_iterator iter = active_indices.begin();
648 while ( iter != end_iter ) {
649 return_indices.push_back( *iter );
652 for (
core::Size ii = 1; ii <= return_indices.size(); ++ii ) {
653 TR <<
" FitnessFunction relevant state indices " << return_indices[ ii ] << std::endl;
655 return return_indices;
665 }
catch ( utility::excn::EXCN_Msg_Exception & e ) {
667 TR <<
"Initialization from input file failed with exception: " << e.msg() << std::endl;
668 TR <<
"Remote daemon sets are spinning down" << std::endl;
681 if ( var_node.is_literal() ) {
682 utility_exit_with_message(
"Error in DynamicAggregateFunction::variable_expression; non-variable (literal) node recieved" +
683 utility::to_string( var_node.literal_value() ));
689 if ( iterative_vector_expression_local_variable )
return iterative_vector_expression_local_variable;
692 std::map< std::string, ExpressionCOP >::const_iterator named_state_iter =
695 return named_state_iter->second;
698 std::map< std::string, VariableVectorExpressionOP >::const_iterator vector_variable_iter =
701 return vector_variable_iter->second;
704 std::map< std::string, VariableExpressionCOP >::const_iterator scalar_expression_iter =
707 return scalar_expression_iter->second;
710 std::map< std::string, VectorExpressionCOP >::const_iterator vector_expression_iter =
713 return vector_expression_iter->second;
716 std::map< std::string, std::pair< EntityFuncOP, VariableExpressionOP > >::const_iterator
717 entity_funcs_iter =
entity_funcs_.find( var_node.variable_name() );
719 return entity_funcs_iter->second.second;
722 throw utility::excn::EXCN_Msg_Exception(
"Unexpected variable expression encountered while "
723 "forming an expression from an ExpressionAST (after scanning/parsing completed!): " + var_node.variable_name() );
734 FunctionTokenCOP
function,
740 if ( fname ==
"vmax" ) {
742 return new VMax( vector_expressions[1] );
743 }
else if ( fname ==
"vmin" ) {
745 return new VMin( vector_expressions[1] );
746 }
else if ( fname ==
"vmax_by" ) {
748 return new VMaxBy( vector_expressions[1], vector_expressions[2] );
749 }
else if ( fname ==
"vmin_by" ) {
751 return new VMinBy( vector_expressions[1], vector_expressions[2] );
752 }
else if ( fname ==
"exp" ) {
753 if ( args.size() != 1 ) {
754 throw utility::excn::EXCN_Msg_Exception(
"exp expression construction requested with more than one argument: " + utility::to_string( args.size() ) );
757 }
else if ( fname ==
"ln" ) {
758 if ( args.size() != 1 ) {
759 throw utility::excn::EXCN_Msg_Exception(
"ln expression construction requested with more than one argument: " + utility::to_string( args.size() ) );
762 }
else if ( fname ==
"pow" ) {
763 if ( args.size() != 2 ) {
764 throw utility::excn::EXCN_Msg_Exception(
"pow expression construction requested with nargs != 2. Nargs= " + utility::to_string( args.size() ) );
767 }
else if ( fname ==
"ite" ) {
768 if ( args.size() != 3 ) {
769 throw utility::excn::EXCN_Msg_Exception(
"ite expression construction requested with nargs != 3. Nargs= " + utility::to_string( args.size() ) );
771 return new ITEExpression( args[ 1 ], args[ 2 ], args[ 3 ] );
772 }
else if ( fname ==
"abs" ) {
773 if ( args.size() != 1 ) {
774 throw utility::excn::EXCN_Msg_Exception(
"abs expression construction requested with nargs != 1. Nargs= " + utility::to_string( args.size() ) );
776 return new AbsoluteValueExpression( args[ 1 ] );
777 }
else if ( fname ==
"gt" ) {
778 if ( args.size() != 2 ) {
779 throw utility::excn::EXCN_Msg_Exception(
"gt expression construction requested with nargs != 2. Nargs= " + utility::to_string( args.size() ) );
781 return new GT_Expression( args[ 1 ], args[ 2 ] );
782 }
else if ( fname ==
"lt" ) {
783 if ( args.size() != 2 ) {
784 throw utility::excn::EXCN_Msg_Exception(
"lt expression construction requested with nargs != 2. Nargs= " + utility::to_string( args.size() ) );
786 return new LT_Expression( args[ 1 ], args[ 2 ] );
787 }
else if ( fname ==
"gte" ) {
788 if ( args.size() != 2 ) {
789 throw utility::excn::EXCN_Msg_Exception(
"gte expression construction requested with nargs != 2. Nargs= " + utility::to_string( args.size() ) );
791 return new GTE_Expression( args[ 1 ], args[ 2 ] );
792 }
else if ( fname ==
"lte" ) {
793 if ( args.size() != 2 ) {
794 throw utility::excn::EXCN_Msg_Exception(
"lte expression construction requested with nargs != 2. Nargs= " + utility::to_string( args.size() ) );
796 return new LTE_Expression( args[ 1 ], args[ 2 ] );
797 }
else if ( fname ==
"and" ) {
798 if ( args.size() != 2 ) {
799 throw utility::excn::EXCN_Msg_Exception(
"and expression construction requested with nargs != 2. Nargs= " + utility::to_string( args.size() ) );
801 return new AndExpression( args[ 1 ], args[ 2 ] );
802 }
else if ( fname ==
"or" ) {
803 if ( args.size() != 2 ) {
804 throw utility::excn::EXCN_Msg_Exception(
"or expression construction requested with nargs != 2. Nargs= " + utility::to_string( args.size() ) );
806 return new OrExpression( args[ 1 ], args[ 2 ] );
807 }
else if ( fname ==
"not" ) {
808 if ( args.size() != 1 ) {
809 throw utility::excn::EXCN_Msg_Exception(
"not expression construction requested with nargs != 1. Nargs= " + utility::to_string( args.size() ) );
811 return new NotExpression( args[ 1 ] );
813 throw utility::excn::EXCN_Msg_Exception(
"Unrecognized function requested of DynamicAggregateFunction: " + fname );
861 std::map< std::string, ArithmeticASTExpressionOP > scalar_expression_asts;
862 std::map< std::string, std::list< std::string > > vector_variables;
863 std::map< std::string, std::pair< std::map< std::string, std::string >,
ArithmeticASTExpressionOP > > vector_expression_asts;
870 Size count_line( 0 );
874 std::getline( ( std::istream & ) input, line );
875 if ( line.size() == 0 )
continue;
877 std::istringstream input_line( line );
878 if ( input_line.peek() ==
'#' )
continue;
881 input_line >> command;
882 if ( command ==
"STATE" ) {
884 }
else if ( command ==
"STATE_VECTOR" ) {
886 }
else if ( command ==
"POSE_ENERGY" ) {
888 }
else if ( command ==
"POSE_ENERGY_VECTOR" ) {
890 }
else if ( command ==
"NPD_PROPERTY" ) {
892 }
else if ( command ==
"VECTOR_VARIABLE" ) {
894 }
else if ( command ==
"SCALAR_EXPRESSION" ) {
896 }
else if ( command ==
"VECTOR_EXPRESSION" ) {
898 }
else if ( command ==
"ENTITY_FUNCTION" ) {
900 }
else if ( command ==
"FITNESS" ) {
903 throw utility::excn::EXCN_Msg_Exception(
"Unable to recognize command '" + command +
"' while reading DynamicAggregateFunction file" );
907 if ( ! fitness_expression_ast ) {
908 throw utility::excn::EXCN_Msg_Exception(
"Unable to find FITNESS command in the file describing the DynamicAggretateFunction.\n"
909 "The FITNESS command must exist " );
921 Size n_vector_states( 0 );
922 for (
Size ii = 1; ii <= strucvec_filenames.size(); ++ii ) {
923 read_state_vector_file( strucvec_filenames[ ii ].first, strucvec_filenames[ ii ].second, n_vector_states );
928 Size const n_variables = n_states + n_npd_properties + scalar_expression_asts.size();
937 Size count_state( 0 ), count_npd_index( 0 ), count_variable_index( 0 );
953 scanner_ =
new ArithmeticScanner(
false );
954 scanner_->add_function(
"sqrt", 1 );
955 scanner_->add_function(
"vmax", 1 );
956 scanner_->add_function(
"vmin", 1 );
957 scanner_->add_function(
"vmax_by", 2 );
958 scanner_->add_function(
"vmin_by", 2 );
989 std::istream & input_line
993 if ( ! input_line ) {
994 throw utility::excn::EXCN_Msg_Exception(
"Expected to read state name in the DynamicAggregateFunction"
995 " input file after reading STATE on line " + utility::to_string( line_number ) +
"\n" + line );
998 if ( ! input_line ) {
999 throw utility::excn::EXCN_Msg_Exception(
"Expected to read state variable name in the DynamicAggregateFunction"
1000 " input file after reading STATE name on line " + utility::to_string( line_number ) +
"\n" + line );
1002 if ( state_name.size() == 0 ) {
1003 throw utility::excn::EXCN_Msg_Exception(
"Expected to read state variable name in the DynamicAggregateFunction"
1004 " input file after reading STATE on line " + utility::to_string( line_number ) +
"\n" + line );
1009 input_line >> structure_file;
1010 if ( ! input_line ) {
1011 throw utility::excn::EXCN_Msg_Exception(
"Expected to read pdb file name in the DynamicAggregateFunction"
1012 " input file after reading STATE pdb file on line " + utility::to_string( line_number ) +
"\n" + line );
1014 if ( structure_file.size() == 0 ) {
1015 throw utility::excn::EXCN_Msg_Exception(
"Expected to read pdb file name in the DynamicAggregateFunction"
1016 " input file after reading STATE name on line " + utility::to_string( line_number ) +
"\n" + line );
1018 input_line >> correspondence_file;
1019 if ( ! input_line ) {
1020 throw utility::excn::EXCN_Msg_Exception(
"Expected to read secondary resfile name in the DynamicAggregateFunction"
1021 " input file after reading STATE correspondence file on line " + utility::to_string( line_number ) +
"\n" + line );
1023 if ( correspondence_file.size() == 0 ) {
1024 throw utility::excn::EXCN_Msg_Exception(
"Expected to read correspondence file name in the DynamicAggregateFunction"
1025 " input file after reading STATE pdb file on line " + utility::to_string( line_number ) +
"\n" + line );
1027 input_line >> secondary_resfile;
1028 if ( secondary_resfile.size() == 0 ) {
1029 throw utility::excn::EXCN_Msg_Exception(
"Expected to read secondary resfile name in the DynamicAggregateFunction"
1030 " input file after reading STATE correspondence file on line " + utility::to_string( line_number ) +
"\n" + line );
1034 TR <<
"Read STATE line. Name= " << state_name
1035 <<
" PDB= " << structure_file <<
" Corr= " << correspondence_file
1036 <<
" 2RF= " << secondary_resfile << std::endl;
1038 scanner_->add_variable( state_name );
1064 std::istream & input_line,
1065 utility::vector1< std::pair< std::string, std::string > > & strucvec_filenames
1068 std::string state_vector_variable_name, state_vector_filename;
1069 if ( ! input_line ) {
1070 throw utility::excn::EXCN_Msg_Exception(
"Expected to read state-vector variable name in the DynamicAggregateFunction"
1071 " input file after reading STATE_VECTOR on line " + utility::to_string( line_number ) +
"\n" + line );
1073 input_line >> state_vector_variable_name;
1074 if ( state_vector_variable_name.size() == 0 ) {
1075 throw utility::excn::EXCN_Msg_Exception(
"Expected to read state-vector variable name in the DynamicAggregateFunction"
1076 " input file after reading STATE_VECTOR on line " + utility::to_string( line_number ) +
"\n" + line );
1078 if ( ! input_line ) {
1079 throw utility::excn::EXCN_Msg_Exception(
"Expected to read state-vector file name in the DynamicAggregateFunction"
1080 " input file after reading STATE_VECTOR variable name on line " + utility::to_string( line_number ) +
"\n" + line );
1085 input_line >> state_vector_filename;
1086 if ( state_vector_filename.size() == 0 ) {
1087 throw utility::excn::EXCN_Msg_Exception(
"Expected to read state-vector file name in the DynamicAggregateFunction"
1088 " input file after reading STATE_VECTOR variable name on line " + utility::to_string( line_number ) +
"\n" + line );
1092 TR <<
"Read STATE_VECTOR line. Name= " << state_vector_variable_name
1093 <<
" File= " << state_vector_filename << std::endl;
1098 scanner_->add_variable( state_vector_variable_name );
1100 strucvec_filenames.push_back( std::make_pair( state_vector_variable_name, state_vector_filename ) );
1107 std::istream & input_line
1110 if ( ! input_line ) {
1111 throw utility::excn::EXCN_Msg_Exception(
"Expected to read variable name in the DynamicAggregateFunction"
1112 " input file after reading POSE_ENERGY on line " + utility::to_string( line_number ) +
"\n" + line );
1116 input_line >> varname;
1117 if ( varname.size() == 0 ) {
1118 throw utility::excn::EXCN_Msg_Exception(
"Expected to read variable name in the DynamicAggregateFunction"
1119 " input file after reading POSE_ENERGY on line " + utility::to_string( line_number ) +
"\n" + line );
1121 if ( ! input_line ) {
1122 throw utility::excn::EXCN_Msg_Exception(
"Expected to read a PDB name in the DynamicAggregateFunction"
1123 " input file after reading the variable name '" + varname +
"' on line " + utility::to_string( line_number ) +
"\n" + line );
1128 input_line >> pdb_name;
1130 TR <<
" Importing pose from pdb file '" << pdb_name <<
"'" << std::endl;
1137 pdb_string = utility::file_contents( pdb_name );
1138 }
catch ( utility::excn::EXCN_Msg_Exception & e ) {
1139 throw utility::excn::EXCN_Msg_Exception(
"Failed to open pdb file named '"
1140 + pdb_name +
"' given in the POSE_ENERGY command on line " + utility::to_string( line_number)
1141 +
"of the DynamicAggregateFunction fitness file" );
1149 throw utility::excn::EXCN_Msg_Exception(
"Input pose given in file '"
1150 + pdb_name +
"' has zero residues. Encountered while processing the '" + varname +
"' variable in the DynamicAggregateFunction"
1151 " input file on line " + utility::to_string( line_number ) +
"\n" + line );
1155 TR <<
" Scoring pose from pdb file '" << pdb_name <<
"'" << std::endl;
1159 TR <<
"Saving POSE_ENERGY of " << score <<
" in variable " << varname << std::endl;
1166 std::istream & input_line
1169 if ( ! input_line ) {
1170 throw utility::excn::EXCN_Msg_Exception(
"Expected to read variable name in the DynamicAggregateFunction"
1171 " input file after reading POSE_ENERGY_VECTOR on line " + utility::to_string( line_number ) +
"\n" + line );
1175 input_line >> varname;
1176 if ( varname.size() == 0 ) {
1177 throw utility::excn::EXCN_Msg_Exception(
"Expected to read variable name in the DynamicAggregateFunction"
1178 " input file after reading POSE_ENERGY_VECTOR on line " + utility::to_string( line_number ) +
"\n" + line );
1180 if ( ! input_line ) {
1181 throw utility::excn::EXCN_Msg_Exception(
"Expected to read the name of a list file in the DynamicAggregateFunction"
1182 " input file after reading the variable name '" + varname +
"' on line " + utility::to_string( line_number ) +
"\n" + line );
1187 input_line >> fname;
1189 std::istringstream pdbvec_file;
1195 pdbvec_file.str( fc );
1196 }
catch ( utility::excn::EXCN_Msg_Exception & e ) {
1197 throw utility::excn::EXCN_Msg_Exception(
"Failed to open pdb list file named '"
1198 + fname +
"' given in the POSE_ENERGY_VECTOR command on line " + utility::to_string( line_number)
1199 +
"of the DynamicAggregateFunction fitness file" );
1203 std::list< std::string > pdb_names;
1204 Size count_pdbs = 0;
1205 Size pdbvec_linenum = 0;
1206 while ( pdbvec_file ) {
1209 std::getline( (std::istream &) (pdbvec_file), line );
1210 if ( line.size() == 0 )
continue;
1212 std::istringstream input_line( line );
1213 if ( input_line.peek() ==
'#' )
continue;
1215 input_line >> pdbname;
1217 pdb_names.push_back( pdbname );
1222 for ( std::list< std::string >::const_iterator iter = pdb_names.begin(), iter_end = pdb_names.end(); iter != iter_end; ++iter ) {
1224 assert( count_pdbs <= pose_energy_variables.size() );
1225 TR <<
" Importing pose from pdb file " << *iter << std::endl;
1232 pdb_string = utility::file_contents( *iter );
1233 }
catch ( utility::excn::EXCN_Msg_Exception & e ) {
1234 throw utility::excn::EXCN_Msg_Exception(
"Failed to open pdb file named '"
1235 + *iter +
"' given in the POSE_ENERGY_VECTOR command on line " + utility::to_string( line_number)
1236 +
"of the DynamicAggregateFunction fitness file" );
1243 throw utility::excn::EXCN_Msg_Exception(
"Input pose given in file '"
1244 + *iter +
"' has zero residues. Encountered while processing the '" + varname +
"' variable in the DynamicAggregateFunction"
1245 " input file on line " + utility::to_string( line_number ) +
"\n" + line );
1248 TR <<
" Scoring pose from pdb file '" << *iter << std::endl;
1251 TR <<
" Saving score of " << score <<
" in variable " << newvar << std::endl;
1265 std::istream & input_line
1268 if ( ! input_line ) {
1269 throw utility::excn::EXCN_Msg_Exception(
"Expected to read variable name in the DynamicAggregateFunction"
1270 " input file after reading NPD_PROPERTY on line " + utility::to_string( line_number ) +
"\n" + line );
1274 input_line >> varname;
1275 if ( varname.size() == 0 ) {
1276 throw utility::excn::EXCN_Msg_Exception(
"Expected to read variable name in the DynamicAggregateFunction"
1277 " input file after reading NPD_PROPERTY on line " + utility::to_string( line_number ) +
"\n" + line );
1279 if ( ! input_line ) {
1280 throw utility::excn::EXCN_Msg_Exception(
"Expected to read an existing state- or state-vector "
1281 " variable name in the DynamicAggregateFunction"
1282 " input file after reading NPD_PROPERTY on line " + utility::to_string( line_number ) +
"\n" + line );
1288 input_line >> original_varname;
1289 if ( original_varname.size() == 0 ) {
1290 throw utility::excn::EXCN_Msg_Exception(
"Expected to read an existing state- or state-vector"
1291 " variable in the DynamicAggregateFunction"
1292 " input file after reading the new variable name on line " + utility::to_string( line_number ) +
"\n" + line );
1294 bool original_was_state_vector(
false );
1299 original_was_state_vector =
true;
1304 throw utility::excn::EXCN_Msg_Exception(
"Expected to read the name for the existing state or state vector"
1305 " in the DynamicAggregateFunction input file, but instead was given the name of a non-state variable, "
1306 + original_varname +
" that had previously been declared on line " +
1308 ".\n Error while processing line " + utility::to_string( line_number ) +
"\n" + line );
1310 throw utility::excn::EXCN_Msg_Exception(
"Read the name '" + original_varname +
"' but "
1311 " expected to read the variable name for the existing state- or state-vector"
1312 " variable in the DynamicAggregateFunction"
1313 " input file after reading the new variable name on line " + utility::to_string( line_number ) +
"\n" + line );
1319 if ( ! input_line ) {
1320 throw utility::excn::EXCN_Msg_Exception(
"Expected to read a non-pairwise decomposable property"
1321 " name after reading the existing state- or state-vector"
1322 " variable name in the DynamicAggregateFunction"
1323 " input file on line " + utility::to_string( line_number ) +
"\n" + line );
1325 input_line >> npd_property;
1326 if ( npd_property.size() == 0 ) {
1327 throw utility::excn::EXCN_Msg_Exception(
"Expected to read a non-pairwise decomposable property"
1328 " name after reading the existing state- or state-vector"
1329 " variable name in the DynamicAggregateFunction"
1330 " input file on line " + utility::to_string( line_number ) +
"\n" + line );
1337 if ( original_was_state_vector ) {
1352 std::istream & input_line,
1353 std::map<
std::string, std::list< std::string > > & vector_variables
1356 std::string vector_variable_name, equals_sign, scalar_variable_name;
1357 if ( ! input_line ) {
1358 throw utility::excn::EXCN_Msg_Exception(
"Expected to read vector variable name in the DynamicAggregateFunction"
1359 " input file after reading VECTOR_VARIABLE on line " + utility::to_string( line_number ) +
"\n" + line );
1361 input_line >> vector_variable_name;
1362 if ( vector_variable_name.size() == 0 ) {
1363 throw utility::excn::EXCN_Msg_Exception(
"Expected to read vector variable name in the DynamicAggregateFunction"
1364 " input file after reading VECTOR_VARIABLE on line " + utility::to_string( line_number ) +
"\n" + line );
1369 if ( ! input_line ) {
1370 throw utility::excn::EXCN_Msg_Exception(
"Expected to read equals sign in the DynamicAggregateFunction"
1371 " input file after reading " + vector_variable_name +
" varname in the VECTOR_VARIABLE command on line " + utility::to_string( line_number ) +
"\n" + line );
1373 input_line >> equals_sign;
1374 if ( equals_sign !=
"=" ) {
1375 throw utility::excn::EXCN_Msg_Exception(
"Expected to read equals sign in the DynamicAggregateFunction"
1376 " input file after reading " + vector_variable_name +
" varname, but found '" + equals_sign +
"' instead in the VECTOR_VARIABLE command on line " + utility::to_string( line_number ) +
"\n" + line );
1379 std::list< std::string > varname_list;
1380 while ( input_line ) {
1381 input_line >> scalar_variable_name;
1382 if ( scalar_variable_name.size() == 0 )
continue;
1385 throw utility::excn::EXCN_Msg_Exception(
"Variable '" + scalar_variable_name +
"' is a vector variable and"
1386 " cannot be listed in the scalar-variable list in a VECTOR_VARIABLE command.\n"
1387 "Error processing VECTOR_VARIABLE command on line " + utility::to_string( line_number ) +
"\n" + line );
1390 throw utility::excn::EXCN_Msg_Exception(
"Unknown variable '" + scalar_variable_name +
"' requested"
1391 " in the VECTOR_VARIABLE command on line " + utility::to_string( line_number ) +
"\n" + line );
1394 varname_list.push_back( scalar_variable_name );
1400 scanner_->add_variable( vector_variable_name );
1402 vector_variables[ vector_variable_name ] = varname_list;
1421 std::istream & input_line,
1422 std::map< std::string, ArithmeticASTExpressionOP > & scalar_expression_asts
1426 if ( ! input_line ) {
1427 throw utility::excn::EXCN_Msg_Exception(
"Expected to read variable name in the DynamicAggregateFunction"
1428 " input file after reading SCALAR_EXPRESSION command on line " + utility::to_string( line_number ) +
"\n" + line );
1430 input_line >> vname;
1431 if ( ! input_line ) {
1432 throw utility::excn::EXCN_Msg_Exception(
"Expected to read equals sign in the DynamicAggregateFunction"
1433 " input file after reading SCALAR_EXPRESSION variable name on line " + utility::to_string( line_number ) +
"\n" + line );
1438 input_line >> equals_sign;
1439 if ( equals_sign !=
"=" ) {
1440 throw utility::excn::EXCN_Msg_Exception(
"Expected to read equals sign in the DynamicAggregateFunction"
1441 " input file after reading SCALAR_EXPRESSION variable name on line " + utility::to_string( line_number )
1442 +
"\n" + line +
"\nbut encountered " + equals_sign +
" instead." );
1444 if ( ! input_line ) {
1445 throw utility::excn::EXCN_Msg_Exception(
"Expected to read an expression in the DynamicAggregateFunction"
1446 " input file after reading SCALAR_EXPRESSION equals sign on line " + utility::to_string( line_number ) +
"\n" + line );
1450 std::getline( input_line, rest_of_line );
1452 TR <<
"On line " << line_number <<
", attempting to tokenize scalar expression: " << rest_of_line << std::endl;
1453 TokenSetOP tokens =
scanner_->scan( rest_of_line );
1454 TR <<
"On line " << line_number <<
", attempting to parse scalar expression: " << rest_of_line << std::endl;
1456 expression_ast->parse( *tokens );
1459 scalar_expression_asts[ vname ] = expression_ast;
1464 TR <<
"SCALAR_EXPRESSION on line " << line_number <<
" successfully parsed" << std::endl;
1471 std::istream & input_line,
1475 std::string for_string, local_var, in_string, existing_vector_varname,
1476 comma_or_colon_string, vector_varname, equals_sign, rest_of_line;
1478 std::map< std::string, std::string > localvar_map;
1481 ArithmeticScanner local_scanner( *
scanner_ );
1483 if ( ! input_line ) {
1484 throw utility::excn::EXCN_Msg_Exception(
"Expected to read FOR in the DynamicAggregateFunction"
1485 " input file after reading VECTOR_EXPRESSION command on line " + utility::to_string( line_number ) +
"\n" + line );
1487 input_line >> for_string;
1488 if ( for_string !=
"FOR" ) {
1489 throw utility::excn::EXCN_Msg_Exception(
"Expected to read FOR in the DynamicAggregateFunction"
1490 " input file after reading VECTOR_EXPRESSION command, but read '" + for_string +
"' on line "
1491 + utility::to_string( line_number ) +
"\n" + line );
1493 if ( ! input_line ) {
1494 throw utility::excn::EXCN_Msg_Exception(
"Expected to read local variable name in the DynamicAggregateFunction"
1495 " input file after reading FOR on a VECTOR_EXPRESSION command on line "
1496 + utility::to_string( line_number ) +
"\n" + line );
1498 bool colon_found =
false;
1499 while ( ! colon_found ) {
1500 if ( ! input_line ) {
1501 throw utility::excn::EXCN_Msg_Exception(
"Expected to read local variable name in the DynamicAggregateFunction input file"
1502 " while processing multiple local variables on a VECTOR_EXPRESSION command on line "
1503 + utility::to_string( line_number ) +
"\n" + line );
1505 input_line >> local_var;
1509 if ( localvar_map.find( local_var ) != localvar_map.end() ) {
1510 throw utility::excn::EXCN_Msg_Exception(
"Local variable, '" + local_var +
"' in VECTOR_EXPRESSION command appears multiple times on line "
1511 + utility::to_string( line_number ) +
"\n" + line );
1514 if ( ! input_line ) {
1515 throw utility::excn::EXCN_Msg_Exception(
"Expected to read 'IN' in the DynamicAggregateFunction input file"
1516 " following the declaration of local variable '" + local_var +
"' on a VECTOR_EXPRESSION command on line "
1517 + utility::to_string( line_number ) +
"\n" + line );
1519 input_line >> in_string;
1520 if ( in_string !=
"IN" ) {
1521 throw utility::excn::EXCN_Msg_Exception(
"Expected to read 'IN' in the DynamicAggregateFunction input file"
1522 " following the declaration of local variable '" + local_var +
"', but read '" + in_string +
"' in the VECTOR_EXPRESSION command on line "
1523 + utility::to_string( line_number ) +
"\n" + line );
1525 if ( ! input_line ) {
1526 throw utility::excn::EXCN_Msg_Exception(
"Expected to read a vector-variable name in the DynamicAggregateFunction input file"
1527 " following '" + local_var +
" IN' in the VECTOR_EXPRESSION command on line "
1528 + utility::to_string( line_number ) +
"\n" + line );
1530 input_line >> existing_vector_varname;
1533 throw utility::excn::EXCN_Msg_Exception(
"The vector-variable name '" + existing_vector_varname
1534 +
"' given for local-variable '" + local_var +
"' does not belong to an already-declared vector variable"
1535 +
". Error in the VECTOR_EXPRESSION command on line "
1536 + utility::to_string( line_number ) +
"\n" + line );
1538 localvar_map[ local_var ] = existing_vector_varname;
1539 local_scanner.add_variable( local_var );
1540 if ( ! input_line ) {
1541 throw utility::excn::EXCN_Msg_Exception(
"Expected to read a colon or a comma following"
1542 " the declaration of local variable " + local_var +
" in the VECTOR_EXPRESSION command on line "
1543 + utility::to_string( line_number ) +
"\n" + line );
1545 input_line >> comma_or_colon_string;
1546 if ( comma_or_colon_string ==
"," ) {
1549 if ( comma_or_colon_string ==
":" ) {
1552 throw utility::excn::EXCN_Msg_Exception(
"Expected to read a colon or a comma following"
1553 " the declaration of local variable " + local_var +
", but found '" + comma_or_colon_string +
"' instead."
1554 "\nError in the VECTOR_EXPRESSION command on line "
1555 + utility::to_string( line_number ) +
"\n" + line );
1560 if ( ! input_line ) {
1561 throw utility::excn::EXCN_Msg_Exception(
"Expected to read a variable name"
1562 " following the colon in the VECTOR_EXPRESSION command on line "
1563 + utility::to_string( line_number ) +
"\n" + line );
1565 input_line >> vector_varname;
1569 if ( localvar_map.find( vector_varname ) != localvar_map.end() ) {
1570 throw utility::excn::EXCN_Msg_Exception(
"Vector variable, '" + vector_varname +
"' in VECTOR_EXPRESSION command appears first as a local variable\n.Line "
1571 + utility::to_string( line_number ) +
"\n" + line );
1575 if ( ! input_line ) {
1576 throw utility::excn::EXCN_Msg_Exception(
"Expected to read an equals sign after reading variable-vector name '"
1577 + vector_varname +
"' in the VECTOR_EXPRESSION command on line "
1578 + utility::to_string( line_number ) +
"\n" + line );
1581 input_line >> equals_sign;
1582 if ( equals_sign !=
"=" ) {
1583 throw utility::excn::EXCN_Msg_Exception(
"Expected to read an equals sign after reading variable-vector name '"
1584 + vector_varname +
"' in the VECTOR_EXPRESSION command on line "
1585 + utility::to_string( line_number ) +
" but found '" + equals_sign +
"' instead\n" + line );
1587 std::getline( input_line, rest_of_line );
1588 TR <<
"On line " << line_number <<
", attempting to tokenize VECTOR_EXPRESSION expression: " << rest_of_line << std::endl;
1589 TokenSetOP tokens = local_scanner.scan( rest_of_line );
1590 TR <<
"On line " << line_number <<
", attempting to parse expression: " << rest_of_line << std::endl;
1592 vector_expression_ast->parse( *tokens );
1593 TR <<
"VECTOR_EXPRESSION on line " << line_number <<
" successfully parsed" << std::endl;
1597 scanner_->add_variable( vector_varname );
1600 vector_expression_asts[ vector_varname ] = std::make_pair( localvar_map, vector_expression_ast );
1607 std::istream & input_line
1611 if ( ! input_line ) {
1612 throw utility::excn::EXCN_Msg_Exception(
"Expected to read state name in the DynamicAggregateFunction"
1613 " input file after reading ENTITY_FUNCTION command on line " + utility::to_string( line_number ) +
"\n" + line );
1615 input_line >> entityfunc_name;
1616 if ( ! input_line ) {
1617 throw utility::excn::EXCN_Msg_Exception(
"Expected to EnitytFunc file name in the DynamicAggregateFunction"
1618 " input file after reading ENTITY_FUNCTION command on line " + utility::to_string( line_number ) +
"\n" + line );
1620 if ( entityfunc_name.size() == 0 ) {
1621 throw utility::excn::EXCN_Msg_Exception(
"Expected to read EntityFunc variable name in the DynamicAggregateFunction"
1622 " input file after reading ENTITY_FUNCTION command on line " + utility::to_string( line_number ) +
"\n" + line );
1627 input_line >> entityfunc_file;
1628 if ( ! input_line ) {
1629 throw utility::excn::EXCN_Msg_Exception(
"Expected to read correspondence file name in the DynamicAggregateFunction"
1630 " input file after reading ENTITY_FUNCTION pdb file on line " + utility::to_string( line_number ) +
"\n" + line );
1632 if ( entityfunc_file.size() == 0 ) {
1633 throw utility::excn::EXCN_Msg_Exception(
"Expected to read pdb file name in the DynamicAggregateFunction"
1634 " input file after reading ENTITY_FUNCTION variable named " + entityfunc_name +
1635 " on line " + utility::to_string( line_number ) +
"\n" + line );
1640 throw utility::excn::EXCN_Msg_Exception(
"DynamicAggregateFunction::set_num_entity_elements must be called before EntityFuncs may be created" );
1648 std::map< std::string, std::string >::const_iterator fc_iter =
file_contents_.find( entityfunc_file );
1650 entfunc_contents = utility::file_contents( entityfunc_file );
1652 entfunc_contents = fc_iter->second;
1655 std::istringstream iss( entfunc_contents );
1656 entfunc->initialize_from_input_file( iss );
1660 scanner_->add_variable( entityfunc_name );
1676 std::istream & input_line,
1680 if ( fitness_expression_ast ) {
1681 throw utility::excn::EXCN_Msg_Exception(
"FITNESS command appears multiple"
1682 " times in the DynamicAggregateFunction file.\nSecond occurrance found while reading\n"
1683 + line +
"\nLine # " + utility::to_string( line_number ) );
1686 std::getline( input_line, rest_of_line );
1687 TR <<
"On line " << line_number <<
", attempting to tokenize FITNESS expression: " << rest_of_line << std::endl;
1688 TokenSetOP tokens =
scanner_->scan( rest_of_line );
1689 TR <<
"On line " << line_number <<
", attempting to parse expression: " << rest_of_line << std::endl;
1690 fitness_expression_ast =
new ArithmeticASTExpression;
1691 fitness_expression_ast->parse( *tokens );
1692 TR <<
"FITNESS on line " << line_number <<
" successfully parsed" << std::endl;
1713 Size & n_vector_states
1716 std::istringstream strucvec_file;
1722 strucvec_file.str( fc );
1723 }
catch ( utility::excn::EXCN_Msg_Exception & e ) {
1724 throw utility::excn::EXCN_Msg_Exception(
"Failed to open state vector file named '" + fname +
"' which was listed on line " + utility::to_string(
variable_names_dec_line_[ vec_varname ] ) );
1727 Size svline_num( 0 );
1729 while ( strucvec_file ) {
1732 std::getline( (std::istream &) ( strucvec_file ), line );
1733 if ( line.size() == 0 )
continue;
1735 std::istringstream input_line( line );
1736 if ( input_line.peek() ==
'#' )
continue;
1738 std::string structure_file, correspondence_file, secondary_resfile;
1739 if ( ! input_line ) {
1740 throw utility::excn::EXCN_Msg_Exception(
"Expected to read pdb file name as the first argument on line "
1741 + utility::to_string( svline_num ) +
" of the state-vector file" + fname +
"\n" + line );
1743 input_line >> structure_file;
1744 if ( ! input_line ) {
1745 throw utility::excn::EXCN_Msg_Exception(
"Expected to read correspondence file name as the second argument on line "
1746 + utility::to_string( svline_num ) +
" of the state-vector file" + fname +
"\n" + line );
1748 input_line >> correspondence_file;
1749 if ( ! input_line ) {
1750 throw utility::excn::EXCN_Msg_Exception(
"Expected to read secondary resfile name as the third argument on line "
1751 + utility::to_string( svline_num ) +
" of the state-vector file" + fname +
"\n" + line );
1753 input_line >> secondary_resfile;
1759 state_triples.push_back( sfn );
1760 TR <<
"Read state from " << fname <<
" PDB= " << structure_file
1761 <<
" Corr= " << correspondence_file <<
" 2RF= " << secondary_resfile << std::endl;
1764 if ( state_triples.size() == 0 ) {
1765 throw utility::excn::EXCN_Msg_Exception(
"Failed to find any states in state-vector file " + fname );
1785 Size & count_npd_index,
1786 Size & count_variable_index
1789 for ( std::map< std::string, StructureFileNames >::const_iterator
1791 iter != iter_end; ++iter ) {
1793 ++count_variable_index;
1803 for ( std::list< std::pair< std::string, std::string > >::const_iterator
1804 npditer = npdlist.begin(), npditer_end = npdlist.end();
1805 npditer != npditer_end; ++npditer ) {
1807 ++count_variable_index;
1837 Size & count_npd_index,
1838 Size & count_variable_index
1843 iter != iter_end; ++iter ) {
1846 std::map< std::string, utility::vector1< VariableExpressionCOP > > npd_property_variables;
1849 for (
Size ii = 1; ii <= iter->second.size(); ++ii ) {
1851 ++count_variable_index;
1852 std::string ii_varname( iter->first +
"_" + utility::to_string( ii ) );
1853 TR <<
"Adding state " << ii_varname <<
" with state index " << count_state << std::endl;
1856 indices[ ii ] = count_state;
1864 if ( has_npd_properties ) {
1866 for ( std::list< std::pair< std::string, std::string > >::const_iterator
1867 npditer = npdlist.begin(), npditer_end = npdlist.end();
1868 npditer != npditer_end; ++npditer ) {
1870 ++count_variable_index;
1872 std::string ii_npd_varname = npditer->second +
"_" + utility::to_string( ii );
1877 npd_property_variables[ npditer->first ].push_back(
variable_expressions_[ count_variable_index ] );
1884 if ( has_npd_properties ) {
1886 for ( std::list< std::pair< std::string, std::string > >::const_iterator
1887 npditer = npdlist.begin(), npditer_end = npdlist.end();
1888 npditer != npditer_end; ++npditer ) {
1905 std::map< std::string, ArithmeticASTExpressionOP >
const & scalar_expression_asts,
1906 std::map<
std::string, std::list< std::string > >
const & vector_variables,
1907 Size & count_variable_index
1910 for ( std::map< std::string, ArithmeticASTExpressionOP >::const_iterator
1911 iter = scalar_expression_asts.begin(), iter_end = scalar_expression_asts.end();
1912 iter != iter_end; ++iter ) {
1913 ++count_variable_index;
1921 for ( std::map<
std::string, std::list< std::string > >::const_iterator
1922 vvar_iter = vector_variables.begin(), vvar_iter_end = vector_variables.end();
1923 vvar_iter != vvar_iter_end; ++vvar_iter ) {
1925 variables.reserve( vvar_iter->second.size() );
1926 for ( std::list< std::string >::const_iterator
1927 scalvar_iter = vvar_iter->second.begin(), scalvar_iter_end = vvar_iter->second.end();
1928 scalvar_iter != scalvar_iter_end; ++scalvar_iter ) {
1929 std::map< std::string, VariableExpressionCOP >::const_iterator scvar =
scalar_expression_map_.find( *scalvar_iter );
1931 throw utility::excn::EXCN_Msg_Exception(
"Internal error: could not locate requested scalar variable '"
1932 + *scalvar_iter +
"' when constructing the VECTOR_VARIABLE '" + vvar_iter->first );
1934 variables.push_back( scvar->second );
1950 std::map< std::string, ArithmeticASTExpressionOP >
const & scalar_expression_asts,
1964 for( std::list< std::pair< Size, std::string > >::const_iterator
1966 iter != iter_end; ++iter ) {
1967 if ( iter->first == 1 ) {
1968 TR <<
"Creating scalar expression for " << iter->second << std::endl;
1969 std::map< std::string, ArithmeticASTExpressionOP >::const_iterator ast_iter = scalar_expression_asts.find( iter->second );
1970 if ( ast_iter == scalar_expression_asts.end() ) {
1971 throw utility::excn::EXCN_Msg_Exception(
"Internal error. Unable to find scalar expression named '" + iter->second +
"' in the scalar_expression_asts map" );
1973 TR <<
"Creating expression from AST:\n" << printer.ast_string( *(ast_iter->second) ) << std::endl;
1975 ExpressionCOP var_expr = expression_creator.create_expression_tree( *(ast_iter->second) );
1980 }
else if ( iter->first == 2 ) {
1981 TR <<
"Creating vector expression for " << iter->second << std::endl;
1983 ast_iter = vector_expression_asts.find( iter->second );
1984 if ( ast_iter == vector_expression_asts.end() ) {
1985 throw utility::excn::EXCN_Msg_Exception(
"Internal error. Unable to find vector expression named '" + iter->second +
"' in the vector_expression_asts map" );
1993 std::map< std::string, VectorExpressionCOP > vector_varnames;
1994 for ( std::map< std::string, std::string >::const_iterator
1995 vec_iter = itvecexp_data.first.begin(), vec_iter_end = itvecexp_data.first.end();
1996 vec_iter != vec_iter_end; ++vec_iter ) {
1999 throw utility::excn::EXCN_Msg_Exception(
"Variable " + vec_iter->second +
" absent from the IterativeVectorExpression name map" );
2005 TR <<
"Creating expression from AST:\n" << printer.ast_string( *itvecexp_data.second ) << std::endl;
2011 ivec_exp->initialize( vector_varnames, *itvecexp_data.second, expression_creator );
2018 TR <<
"Creating fitness expression from AST:\n" << printer.ast_string( *fitness_expression_ast ) << std::endl;
2019 fitness_exp_ = expression_creator.create_expression_tree( *fitness_expression_ast );
2034 if ( args.size() != expected_nargs ) {
2035 throw utility::excn::EXCN_Msg_Exception(
"vector function expression " + fname +
" construction requested with nargs != 1. Nargs= " + utility::to_string( args.size() ) );
2038 for (
Size ii = 1; ii <= expected_nargs; ++ii ) {
2043 throw utility::excn::EXCN_Msg_Exception(
"vector function expression " + fname +
" can only be constructed from a vector expression.\n"
2044 "Variable " + var_ptr->name() +
" is not a vector variable." );
2046 throw utility::excn::EXCN_Msg_Exception(
"vector function expression " + fname +
" can only be constructed from a vector expression." );
2049 vector_expressions[ ii ] = vec_ptr;
2051 return vector_expressions;
2063 throw utility::excn::EXCN_Msg_Exception(
"Variable name " + vname +
" appears multiple"
2064 " times in the DynamicAggregateFunction file.\nSecond occurrance found while reading a " +
2065 command_name +
" command\n" + line +
"\nLine # " + utility::to_string( line_number ) );
2068 throw utility::excn::EXCN_Msg_Exception(
"Declaration of variable '" + vname +
"' in " + command_name +
" command conflicts with a function name. Line "
2069 + utility::to_string( line_number ) +
"\n" + line );
2072 throw utility::excn::EXCN_Msg_Exception(
"Declaration of variable '" + vname +
"' in " + command_name +
" command conflicts"
2073 " with a previously declared EntityFunc variable.\nPrevious declaration was on line "
2075 + utility::to_string( line_number ) +
"\n" + line );
2079 throw utility::excn::EXCN_Msg_Exception(
"Illegal name for variable, '" + vname +
"' in the " +
2080 command_name +
" command on line " + utility::to_string( line_number ) +
"\n" + line );
2092 std::map< std::string, Size > total_read_counts_for_files;
2093 std::map< std::string, Size > read_counts_for_files;
2096 std::map< std::string, std::string > file_contents;
2106 daemon_set->setup_daemons();
2111 std::map< std::string, Size > & total_reads,
2112 std::map< std::string, Size > & reads_completed
2115 for ( std::map< std::string, StructureFileNames >::const_iterator
2117 iter != iter_end; ++iter ) {
2125 iter != iter_end; ++iter ) {
2126 for (
Size ii = 1; ii <= iter->second.size(); ++ii ) {
2139 std::map< std::string, Size > & total_reads,
2140 std::map< std::string, Size > & reads_completed
2143 std::map< std::string, Size >::iterator iter = total_reads.find( fname );
2144 if ( iter == total_reads.end() ) {
2145 total_reads[ fname ] = 1;
2146 reads_completed[ fname ] = 0;
2155 std::map< std::string, Size >
const & total_reads,
2156 std::map< std::string, Size > & reads_completed,
2157 std::map< std::string, std::string > & file_contents_map
2160 std::map< std::string, Size >::const_iterator tr_iter = total_reads.find( filename );
2161 std::map< std::string, Size >::iterator rc_iter = reads_completed.find( filename );
2162 if ( tr_iter == total_reads.end() ) {
2163 throw utility::excn::EXCN_Msg_Exception(
"Unexpected file read requested: " + filename );
2165 if ( rc_iter == reads_completed.end() ) {
2166 throw utility::excn::EXCN_Msg_Exception(
"Reads-completed map does not contain an entry for file: " + filename );
2169 if ( tr_iter->second == 1 ) {
2171 std::map< std::string, std::string >::const_iterator fc_iter =
file_contents_.find( filename );
2173 return utility::file_contents( filename );
2175 return fc_iter->second;
2177 }
else if ( tr_iter->second == rc_iter->second ) {
2178 std::map< std::string, std::string >::iterator fc_iter = file_contents_map.find( filename );
2179 if ( fc_iter == file_contents_map.end() ) {
2180 throw utility::excn::EXCN_Msg_Exception(
"file-contents map does not contain an entry for file that has been read before: " + filename );
2183 file_contents_map.erase( fc_iter );
2188 std::map< std::string, std::string >::const_iterator fc_iter =
file_contents_.find( filename );
2191 file_contents_map[
filename ] = fc;
2192 ++(rc_iter->second);
2200 std::map< std::string, Size >
const & total_reads,
2201 std::map< std::string, Size > & reads_completed
2205 std::list< int > joblist;
2206 for (
int ii = 1; ii <= nstructs; ++ii ) joblist.push_back( ii );
2207 std::map< std::string, std::string > file_contents_map;
2213 }
catch ( utility::excn::EXCN_Msg_Exception & e ) {
2214 TR <<
"Error from daemon-set initialization \n";
2227 std::map< std::string, Size >
const & total_reads,
2228 std::map< std::string, Size > & reads_completed
2231 std::map< std::string, std::string > file_contents_map;
2233 int MPI_nprocs = utility::mpi_nprocs();
2236 int njobs_per_cpu =
static_cast< int > ( std::ceil( (
double) nstructs / MPI_nprocs ));
2240 int overhang = njobs_per_cpu * MPI_nprocs - nstructs;
2243 if ( overhang == 0 ) {
2244 int state_count = 0;
2245 for (
int ii = 0; ii < MPI_nprocs; ++ii ) {
2246 for (
int jj = 1; jj <= njobs_per_cpu; ++jj ) {
2248 job_assignments[ ii ].push_back( state_count );
2251 }
else if ( overhang == 1 && njobs_per_cpu == 1 ) {
2252 int state_count = 0;
2253 for (
int ii = 1; ii < MPI_nprocs; ++ii ) {
2255 job_assignments[ ii ].push_back( state_count );
2258 int state_count = 0;
2259 for (
int ii = 0; ii < MPI_nprocs; ++ii ) {
2260 int ii_n_jobs = ii < overhang ? njobs_per_cpu - 1 : njobs_per_cpu;
2261 for (
int jj = 1; jj <= ii_n_jobs; ++jj ) {
2263 job_assignments[ ii ].push_back( state_count );
2269 for (
int ii = 1; ii < MPI_nprocs; ++ii ) {
2272 bool jobs_successfully_initialized(
true );
2278 }
catch ( utility::excn::EXCN_Msg_Exception & e ) {
2279 error_message +=
"Error from node 0\n";
2280 error_message += e.msg();
2281 TR << e.msg() << std::endl;
2282 jobs_successfully_initialized =
false;
2285 for (
int ii = 1; ii < MPI_nprocs; ++ii ) {
2287 error_message +=
"Error from node " + utility::to_string( ii ) +
"\n";
2288 std::string remote_message = utility::receive_string_from_node( ii );
2289 error_message += remote_message +
"\n";
2290 TR << remote_message << std::endl;
2291 jobs_successfully_initialized =
false;
2295 if ( jobs_successfully_initialized ) {
2296 for (
int ii = 1; ii < MPI_nprocs; ++ii ) {
2304 utility_exit_with_message( error_message );
2317 std::list< int >
const & job_indices,
2319 std::map< std::string, Size >
const &
tr ,
2320 std::map< std::string, Size > & rc ,
2321 std::map< std::string, std::string > & fcm
2324 for ( std::list< int >::const_iterator iter = job_indices.begin(),
2325 iter_end = job_indices.end(); iter != iter_end; ++iter ) {
2326 int state_id = *iter;
2332 daemon_set->add_pack_daemon(
2340 for ( std::list< std::pair< Size, std::string > >::const_iterator
2343 npditer != npditer_end; ++npditer ) {
2344 daemon_set->add_npd_property_calculator_for_state( state_id, npditer->second, npditer->first );
2353 std::list< int >
const & job_indices,
2354 std::map< std::string, Size >
const &
tr ,
2355 std::map< std::string, Size > & rc ,
2356 std::map< std::string, std::string > & fcm
2359 utility::send_integer_to_node( proc_id,
add_daemon );
2361 int ndaemons = job_indices.size();
2362 utility::send_integer_to_node( proc_id, ndaemons );
2363 for ( std::list< int >::const_iterator iter = job_indices.begin(),
2364 iter_end = job_indices.end(); iter != iter_end; ++iter ) {
2365 int state_id = *iter;
2367 utility::send_integer_to_node( proc_id, state_id );
2368 utility::send_string_to_node( proc_id, sfn.
pdb_name_ );
2375 utility::send_integer_to_node( proc_id, n_npd_properties_to_send );
2377 for ( std::list< std::pair< Size, std::string > >::const_iterator
2380 npditer != npditer_end; ++npditer) {
2382 utility::send_integer_to_node( proc_id, npditer->first );
2383 utility::send_string_to_node( proc_id, npditer->second );
2391 int message = utility::receive_integer_from_node( proc_id );
2395 throw utility::excn::EXCN_Msg_Exception(
"Expected either a success_message or an error_message "
2396 "after initializing remote daemon sets from process " +
2397 utility::to_string( proc_id ) +
" but received " + utility::to_string( message ) );
2409 int MPI_nprocs = utility::mpi_nprocs();
2410 for (
int ii = 1; ii < MPI_nprocs; ++ii ) {
2423 for ( std::map<
std::string, std::pair< EntityFuncOP, VariableExpressionOP > >::const_iterator
2425 iter != iter_end; ++iter ) {
2426 core::Real entity_func_value = iter->second.first->evaluate( entity, verbose );
2427 iter->second.second->set_value( entity_func_value );
2429 TR <<
"EntityFunc:: total for " << iter->second.second->name() <<
" " << entity_func_value << std::endl;
2435 TR <<
"Assigning value " << state_energies[ ii ] <<
" to VariableExpression " << ii << std::endl;
2439 for (
Size ii = 1; ii <= npd_properties.size(); ++ii ) {
2462 for ( std::map< std::string, StructureFileNames >::const_iterator
2464 iter != iter_end; ++iter ) {
2472 iter != iter_end; ++iter ) {
2495 ArithmeticASTValue
const & node
2503 FunctionTokenCOP
function,
2516 num_entity_elements_( 0 )
2531 throw utility::excn::EXCN_Msg_Exception(
"EntityFunc::initialize_from_input_file cannot be called without EntityFunc::set_num_entity_elements having first been called." );
2535 std::map< std::string, ArithmeticASTExpressionOP > expression_asts;
2537 Size count_line( 0 );
2542 std::getline( ( std::istream & ) input, line );
2543 if ( line.size() == 0 )
continue;
2545 std::istringstream input_line( line );
2546 if ( input_line.peek() ==
'#' )
continue;
2548 input_line >> command;
2549 if ( command ==
"AA_SET" ) {
2551 }
else if ( command ==
"SET_CONDITION" ) {
2553 }
else if ( command ==
"SUB_EXPRESSION" ) {
2555 }
else if ( command ==
"SCORE" ) {
2558 throw utility::excn::EXCN_Msg_Exception(
"Unable to recognize command '" + command +
"' while reading EntityFunc file" );
2562 if ( ! score_expression_ast ) {
2563 throw utility::excn::EXCN_Msg_Exception(
"SCORE command was not found in EntityFunc file." );
2586 if ( var_node.is_literal() ) {
2587 utility_exit_with_message(
"Error in EntityFunc::variable_expression; non-variable (literal) node recieved" +
2588 utility::to_string( var_node.literal_value() ));
2591 std::map< std::string, VariableExpressionOP >::const_iterator var_iter =
2594 return var_iter->second;
2597 throw utility::excn::EXCN_Msg_Exception(
"Unable to find variable with name " + var_node.variable_name() +
" in"
2598 " EntityFunc while trying to build expression trees for the expressions already tokenized and parsed.\n"
2599 "Cannot continue. Contact Andrew Leaver-Fay (aleaverfay@gmail.com)" );
2605 FunctionTokenCOP
function,
2610 if ( fname ==
"max" ) {
2611 return new MaxExpression( args[ 1 ], args[ 2 ] );
2612 }
else if ( fname ==
"min" ) {
2613 return new MinExpression( args[ 1 ], args[ 2 ] );
2614 }
else if ( fname ==
"exp" ) {
2615 if ( args.size() != 1 ) {
2616 throw utility::excn::EXCN_Msg_Exception(
"exp expression construction requested with more than one argument: " + utility::to_string( args.size() ) );
2619 }
else if ( fname ==
"ln" ) {
2620 if ( args.size() != 1 ) {
2621 throw utility::excn::EXCN_Msg_Exception(
"ln expression construction requested with more than one argument: " + utility::to_string( args.size() ) );
2624 }
else if ( fname ==
"pow" ) {
2625 if ( args.size() != 2 ) {
2626 throw utility::excn::EXCN_Msg_Exception(
"pow expression construction requested with nargs != 2. Nargs= " + utility::to_string( args.size() ) );
2629 }
else if ( fname ==
"ite" ) {
2630 if ( args.size() != 3 ) {
2631 throw utility::excn::EXCN_Msg_Exception(
"ite expression construction requested with nargs != 3. Nargs= " + utility::to_string( args.size() ) );
2633 return new ITEExpression( args[ 1 ], args[ 2 ], args[ 3 ] );
2634 }
else if ( fname ==
"abs" ) {
2635 if ( args.size() != 1 ) {
2636 throw utility::excn::EXCN_Msg_Exception(
"abs expression construction requested with nargs != 1. Nargs= " + utility::to_string( args.size() ) );
2638 return new AbsoluteValueExpression( args[ 1 ] );
2639 }
else if ( fname ==
"gt" ) {
2640 if ( args.size() != 2 ) {
2641 throw utility::excn::EXCN_Msg_Exception(
"gt expression construction requested with nargs != 2. Nargs= " + utility::to_string( args.size() ) );
2643 return new GT_Expression( args[ 1 ], args[ 2 ] );
2644 }
else if ( fname ==
"lt" ) {
2645 if ( args.size() != 2 ) {
2646 throw utility::excn::EXCN_Msg_Exception(
"lt expression construction requested with nargs != 2. Nargs= " + utility::to_string( args.size() ) );
2648 return new LT_Expression( args[ 1 ], args[ 2 ] );
2649 }
else if ( fname ==
"gte" ) {
2650 if ( args.size() != 2 ) {
2651 throw utility::excn::EXCN_Msg_Exception(
"gte expression construction requested with nargs != 2. Nargs= " + utility::to_string( args.size() ) );
2653 return new GTE_Expression( args[ 1 ], args[ 2 ] );
2654 }
else if ( fname ==
"lte" ) {
2655 if ( args.size() != 2 ) {
2656 throw utility::excn::EXCN_Msg_Exception(
"lte expression construction requested with nargs != 2. Nargs= " + utility::to_string( args.size() ) );
2658 return new LTE_Expression( args[ 1 ], args[ 2 ] );
2659 }
else if ( fname ==
"eq" ) {
2660 if ( args.size() != 2 ) {
2661 throw utility::excn::EXCN_Msg_Exception(
"eq expression construction requested with nargs != 2. Nargs= " + utility::to_string( args.size() ) );
2663 return new EqualsExpression( args[ 1 ], args[ 2 ] );
2664 }
else if ( fname ==
"and" ) {
2665 if ( args.size() != 2 ) {
2666 throw utility::excn::EXCN_Msg_Exception(
"and expression construction requested with nargs != 2. Nargs= " + utility::to_string( args.size() ) );
2668 return new AndExpression( args[ 1 ], args[ 2 ] );
2669 }
else if ( fname ==
"or" ) {
2670 if ( args.size() != 2 ) {
2671 throw utility::excn::EXCN_Msg_Exception(
"or expression construction requested with nargs != 2. Nargs= " + utility::to_string( args.size() ) );
2673 return new OrExpression( args[ 1 ], args[ 2 ] );
2674 }
else if ( fname ==
"not" ) {
2675 if ( args.size() != 1 ) {
2676 throw utility::excn::EXCN_Msg_Exception(
"not expression construction requested with nargs != 1. Nargs= " + utility::to_string( args.size() ) );
2678 return new NotExpression( args[ 1 ] );
2681 throw utility::excn::EXCN_Msg_Exception(
"Unable to find function with name " + fname +
" in"
2682 " EntityFunc while trying to build expression trees for the expressions already tokenized and parsed.\n"
2683 "Cannot continue. Contact Andrew Leaver-Fay (aleaverfay@gmail.com)" );
2691 scanner_ =
new ArithmeticScanner(
false );
2692 scanner_->add_function(
"sqrt", 1 );
2693 scanner_->add_function(
"max", 2 );
2694 scanner_->add_function(
"min", 2 );
2695 scanner_->add_function(
"exp", 1 );
2696 scanner_->add_function(
"pow", 2 );
2697 scanner_->add_function(
"ite", 3 );
2699 scanner_->add_function(
"abs", 1 );
2702 scanner_->add_function(
"gte", 2 );
2703 scanner_->add_function(
"lte", 2 );
2705 scanner_->add_function(
"and", 2 );
2707 scanner_->add_function(
"not", 1 );
2734 std::string ii_name =
"ee_" + utility::to_string( ii );
2748 std::istream & input_line
2751 if ( ! input_line ) {
2752 throw utility::excn::EXCN_Msg_Exception(
"Expected to read amino acid set name in the EntityFunc"
2753 " input file after reading AA_SET on line " + utility::to_string( line_number ) +
"\n" + line );
2756 input_line >> aa_setname;
2757 if ( aa_setname.size() == 0 ) {
2758 throw utility::excn::EXCN_Msg_Exception(
"Expected to read amino acid set name in the EntityFunc"
2759 " input file after reading AA_SET on line " + utility::to_string( line_number ) +
"\n" + line );
2762 throw utility::excn::EXCN_Msg_Exception(
"Amino-acid-set name '" + aa_setname +
"' appears multiple"
2763 " times in the EntityFunc file.\nFirst occurrance was found on line " +
2765 ". Second occurrance found while reading"
2766 " AA_SET command\n" + line +
"\nLine # " + utility::to_string( line_number ) );
2771 throw utility::excn::EXCN_Msg_Exception(
"Illegal amino-acid-set name '" + aa_setname +
"' which was previously"
2772 " declared in the EntityFunc file as a sub-expression.\nFirst occurrance was found on line " +
2774 ". Second occurrance found while reading"
2775 " AA_SET command\n" + line +
"\nLine # " + utility::to_string( line_number ) );
2777 throw utility::excn::EXCN_Msg_Exception(
"Illegal amino-acid-set name '" + aa_setname +
"' which is reserved"
2778 " as a name for an entity-element variable.\nError found while reading"
2779 " AA_SET command\n" + line +
"\nLine # " + utility::to_string( line_number ) );
2784 throw utility::excn::EXCN_Msg_Exception(
"Illegal amino-acid-set name '" + aa_setname +
"' which is reserved"
2785 " as a name for an funcion.\nError encountered while reading"
2786 " AA_SET command\n" + line +
"\nLine # " + utility::to_string( line_number ) );
2790 throw utility::excn::EXCN_Msg_Exception(
"Illegal amino-acid-set name '" + aa_setname +
"' which is a reserved"
2791 " word for this input file format.\nError encountered while reading"
2792 " AA_SET command\n" + line +
"\nLine # " + utility::to_string( line_number ) );
2796 char equals_sign(
' ' );
2797 while ( equals_sign ==
' ' || equals_sign ==
'\t' ) {
2798 if ( !input_line ) {
2799 throw utility::excn::EXCN_Msg_Exception(
"Expected to read an equals sign after reading amino-acid-set name'"
2800 + aa_setname +
"' but found an end-of-line.\nError encountered while reading"
2801 " AA_SET command\n" + line +
"\nLine # " + utility::to_string( line_number ) );
2803 input_line.get( equals_sign );
2805 if ( equals_sign !=
'=' ) {
2806 throw utility::excn::EXCN_Msg_Exception(
"Expected to read an equals sign after reading amino-acid-set name'"
2807 + aa_setname +
"' but found '" + equals_sign +
"'\nError encountered while reading"
2808 " AA_SET command\n" + line +
"\nLine # " + utility::to_string( line_number ) );
2813 while ( lcurly ==
' ' || lcurly ==
'\t' ) {
2814 if ( !input_line ) {
2815 throw utility::excn::EXCN_Msg_Exception(
"Expected to read a left curly bracket ('{') after reading"
2816 " an equals sign, but found an end-of-line.\nError encountered while reading"
2817 " AA_SET command\n" + line +
"\nLine # " + utility::to_string( line_number ) );
2819 input_line.get( lcurly );
2821 if ( lcurly !=
'{' ) {
2822 throw utility::excn::EXCN_Msg_Exception(
"Expected to read a left curly bracket ('{') after reading"
2823 " an equals sign, but found '" + utility::to_string( lcurly ) +
"'\nError encountered while reading"
2824 " AA_SET command\n" + line +
"\nLine # " + utility::to_string( line_number ) );
2830 while ( next_aa !=
'}' ) {
2831 while ( next_aa ==
' ' || next_aa ==
'\t' ) {
2832 if ( !input_line ) {
2833 throw utility::excn::EXCN_Msg_Exception(
"Expected to read a right curly bracket ('}') or a 1-letter"
2834 " amino acid code, but found an end-of-line.\nError encountered while reading"
2835 " AA_SET command\n" + line +
"\nLine # " + utility::to_string( line_number ) );
2837 input_line.get( next_aa );
2839 if ( next_aa ==
'}' )
break;
2845 throw utility::excn::EXCN_Msg_Exception(
"Expected to read a 1-letter"
2846 " amino acid code or a right curly brace, but found '" + utility::to_string( next_aa ) +
"'.\n"
2847 "Error encountered while reading AA_SET command\n" + line +
"\n"
2848 "Line # " + utility::to_string( line_number ) );
2851 while ( next_aa ==
' ' || next_aa ==
'\t' ) {
2852 if ( !input_line ) {
2853 throw utility::excn::EXCN_Msg_Exception(
"Expected to read a right curly bracket ('}') or a 1-letter"
2854 " amino acid code, but found an end-of-line.\nError encountered while reading"
2855 " AA_SET command\n" + line +
"\nLine # " + utility::to_string( line_number ) );
2857 input_line.get( next_aa );
2859 if ( next_aa ==
'}' )
break;
2860 if ( next_aa ==
',' ) {
2864 throw utility::excn::EXCN_Msg_Exception(
"Expected to read comma"
2865 " or a right curly brace, but found '" + utility::to_string( next_aa ) +
"'.\n"
2866 "Error encountered while reading AA_SET command\n" + line +
"\n"
2867 "Line # " + utility::to_string( line_number ) );
2881 std::istream & input_line
2884 if ( ! input_line ) {
2885 throw utility::excn::EXCN_Msg_Exception(
"Expected to read a set-condition name in the EntityFunc"
2886 " input file after reading SET_CONDITION on line " + utility::to_string( line_number ) +
"\n" + line );
2889 input_line >> condition_name;
2890 if ( condition_name.size() == 0 ) {
2891 throw utility::excn::EXCN_Msg_Exception(
"Expected to read a set-condition name in the EntityFunc"
2892 " input file after reading SET_CONDITION on line " + utility::to_string( line_number ) +
"\n" + line );
2895 throw utility::excn::EXCN_Msg_Exception(
"Set-condition name '" + condition_name +
"' appears multiple"
2896 " times in the EntityFunc file.\nFirst occurrance was found on line " +
2898 ". Second occurrance found while reading"
2899 " SET_CONDITION command\n" + line +
"\nLine # " + utility::to_string( line_number ) );
2904 throw utility::excn::EXCN_Msg_Exception(
"Illegal set-condition name '" + condition_name +
"' which was previously"
2905 " declared in the EntityFunc file as a sub-expression.\nFirst occurrance was found on line " +
2907 ". Second occurrance found while reading"
2908 " SET_CONDITION command\n" + line +
"\nLine # " + utility::to_string( line_number ) );
2910 throw utility::excn::EXCN_Msg_Exception(
"Illegal set-condition name '" + condition_name +
"' which is reserved"
2911 " as a name for an entity-element variable.\nError found while reading"
2912 " SET_CONDITION command\n" + line +
"\nLine # " + utility::to_string( line_number ) );
2917 throw utility::excn::EXCN_Msg_Exception(
"Illegal set-condition name '" + condition_name +
"' which is reserved"
2918 " as a name for an funcion.\nError encountered while reading"
2919 " SET_CONDITION command\n" + line +
"\nLine # " + utility::to_string( line_number ) );
2923 throw utility::excn::EXCN_Msg_Exception(
"Illegal set-condition name '" + condition_name +
"' which is a reserved"
2924 " word for this input file format.\nError encountered while reading"
2925 " SET_CONDITION command\n" + line +
"\nLine # " + utility::to_string( line_number ) );
2929 char equals_sign(
' ' );
2930 while ( equals_sign ==
' ' || equals_sign ==
'\t' ) {
2931 if ( !input_line ) {
2932 throw utility::excn::EXCN_Msg_Exception(
"Expected to read an equals sign after reading the set-condition name'"
2933 + condition_name +
"' but found an end-of-line.\nError encountered while reading"
2934 " SET_CONDITION command\n" + line +
"\nLine # " + utility::to_string( line_number ) );
2936 input_line >> equals_sign;
2938 if ( equals_sign !=
'=' ) {
2939 throw utility::excn::EXCN_Msg_Exception(
"Expected to read an equals sign after reading amino-acid-set name'"
2940 + condition_name +
"' but found '" + utility::to_string( equals_sign ) +
"'\nError encountered while reading"
2941 " SET_CONDITION command\n" + line +
"\nLine # " + utility::to_string( line_number ) );
2945 if ( ! input_line ) {
2946 throw utility::excn::EXCN_Msg_Exception(
"Expected to read the entity-element name in the EntityFunc"
2947 " input file after reading the set condition name, \"" + condition_name +
",\" but found an end-of-line.\n"
2948 "Error encountered while reading SET_CONDITION command on line " + utility::to_string( line_number ) +
"\n" + line );
2951 input_line >> eename;
2953 throw utility::excn::EXCN_Msg_Exception(
"Expected to read an entity-element name in the EntityFunc"
2954 " input file after reading an equals sign, while processing the set-condition named \"" + condition_name +
",\" but"
2955 " found \"" + eename +
"\" which is not a valid entity element name.\n"
2957 "Entity-element variables should be named ee_1 through ee_" + utility::to_string(
num_entity_elements_ ) +
".\n"
2958 "Error encountered while reading SET_CONDITION command on line " + utility::to_string( line_number ) +
"\n" + line );
2961 throw utility::excn::EXCN_Msg_Exception(
"Expected to read an entity-element name in the EntityFunc"
2962 " input file after reading an equals sign, while processing the set-condition named \"" + condition_name +
",\" but"
2963 " found the named subexpression \"" + eename +
"\" instead.\n"
2964 "Error encountered while reading SET_CONDITION command on line " + utility::to_string( line_number ) +
"\n" + line );
2967 if ( ! input_line ) {
2968 throw utility::excn::EXCN_Msg_Exception(
"Expected to read the string \"in\" in the EntityFunc"
2969 " input file after reading the set condition name, \"" + condition_name +
",\" but found an end-of-line.\n"
2970 "Error encountered while reading SET_CONDITION command on line " + utility::to_string( line_number ) +
"\n" + line );
2975 input_line >> in_string;
2976 if ( in_string !=
"in" ) {
2977 throw utility::excn::EXCN_Msg_Exception(
"Expected to read the string \"in\" in the EntityFunc"
2978 " input file after reading the set condition name, \"" + condition_name +
",\" but found \"" +
2979 in_string +
"\" instead.\n"
2980 "Error encountered while reading SET_CONDITION command on line " + utility::to_string( line_number ) +
"\n" + line );
2983 char next_char =
' ';
2984 while ( input_line.peek() ==
' ' || input_line.peek() ==
'\t' ) {
2985 if ( !input_line ) {
2986 throw utility::excn::EXCN_Msg_Exception(
"Expected to read a left curly bracket ('}') or an"
2987 " amino acid set name, but found an end-of-line.\nError encountered while reading"
2988 " SET_CONDITION command\n" + line +
"\nLine # " + utility::to_string( line_number ) );
2990 input_line.get( next_char );
2996 if ( input_line.peek() ==
'{' ) {
2998 input_line.get( next_aa );
3000 while ( next_aa !=
'}' ) {
3001 while ( next_aa ==
' ' || next_aa ==
'\t' ) {
3002 if ( !input_line ) {
3003 throw utility::excn::EXCN_Msg_Exception(
"Expected to read a right curly bracket ('}') or a 1-letter"
3004 " amino acid code, but found an end-of-line.\nError encountered while reading"
3005 " SET_CONDITION command\n" + line +
"\nLine # " + utility::to_string( line_number ) );
3007 input_line.get( next_aa );
3009 if ( next_aa ==
'}' )
break;
3015 throw utility::excn::EXCN_Msg_Exception(
"Expected to read a 1-letter"
3016 " amino acid code or a right curly brace, but found '" + utility::to_string( next_aa ) +
"'.\n"
3017 "Error encountered while reading SET_CONDITION command\n" + line +
"\n"
3018 "Line # " + utility::to_string( line_number ) );
3021 while ( next_aa ==
' ' || next_aa ==
'\t' ) {
3022 if ( !input_line ) {
3023 throw utility::excn::EXCN_Msg_Exception(
"Expected to read a right curly bracket ('}') or a 1-letter"
3024 " amino acid code, but found an end-of-line.\nError encountered while reading"
3025 " SET_CONDITION command\n" + line +
"\nLine # " + utility::to_string( line_number ) );
3027 input_line.get( next_aa );
3029 if ( next_aa ==
'}' ) {
break; }
3030 if ( next_aa ==
',' ) {
3035 throw utility::excn::EXCN_Msg_Exception(
"Expected to read comma"
3036 " or a right curly brace, but found '" + utility::to_string( next_aa ) +
"'.\n"
3037 "Error encountered while reading SET_CONDITION command\n" + line +
"\n"
3038 "Line # " + utility::to_string( line_number ) );
3043 input_line >> aa_setname;
3045 throw utility::excn::EXCN_Msg_Exception(
"Amino-acid-set name '" + aa_setname +
3046 "' has not previously been declared.\nError encountered while reading"
3047 " SET_CONDITION command\n" + line +
"\nLine # " + utility::to_string( line_number ) );
3054 inset_expression->value_set( aas_in_set );
3057 surrogate_expression->root_expression( inset_expression );
3063 scanner_->add_variable( condition_name );
3070 std::istream & input_line,
3071 std::map< std::string, ArithmeticASTExpressionOP > & expression_asts
3074 if ( ! input_line ) {
3075 throw utility::excn::EXCN_Msg_Exception(
"Expected to read a sub-expression name in the EntityFunc"
3076 " input file after reading SUB_EXPRESSION on line " + utility::to_string( line_number ) +
"\n" + line );
3079 input_line >> subexpression_name;
3080 if ( subexpression_name.size() == 0 ) {
3081 throw utility::excn::EXCN_Msg_Exception(
"Expected to read a sub-expression name in the EntityFunc"
3082 " input file after reading SUB_EXPRESSION on line " + utility::to_string( line_number ) +
"\n" + line );
3085 throw utility::excn::EXCN_Msg_Exception(
"Sub-expression name '" + subexpression_name +
"' appears multiple"
3086 " times in the EntityFunc file.\nFirst occurrance was found on line " +
3088 ". Second occurrance found while reading"
3089 " SUB_EXPRESSION command\n" + line +
"\nLine # " + utility::to_string( line_number ) );
3094 throw utility::excn::EXCN_Msg_Exception(
"Illegal sub-expression name '" + subexpression_name +
"' which was previously"
3095 " declared in the EntityFunc file as a sub-expression.\nFirst occurrance was found on line " +
3097 ". Second occurrance found while reading"
3098 " SUB_EXPRESSION command\n" + line +
"\nLine # " + utility::to_string( line_number ) );
3100 throw utility::excn::EXCN_Msg_Exception(
"Illegal sub-expression name '" + subexpression_name +
"' which is reserved"
3101 " as a name for an entity-element variable.\nError found while reading"
3102 " SUB_EXPRESSION command\n" + line +
"\nLine # " + utility::to_string( line_number ) );
3107 throw utility::excn::EXCN_Msg_Exception(
"Illegal sub-expression name '" + subexpression_name +
"' which is reserved"
3108 " as a name for an funcion.\nError encountered while reading"
3109 " SUB_EXPRESSION command\n" + line +
"\nLine # " + utility::to_string( line_number ) );
3113 throw utility::excn::EXCN_Msg_Exception(
"Illegal sub-expression name '" + subexpression_name +
"' which is a reserved"
3114 " word for this input file format.\nError encountered while reading"
3115 " SUB_EXPRESSION command\n" + line +
"\nLine # " + utility::to_string( line_number ) );
3119 char equals_sign(
' ' );
3120 while ( equals_sign ==
' ' || equals_sign ==
'\t' ) {
3121 if ( !input_line ) {
3122 throw utility::excn::EXCN_Msg_Exception(
"Expected to read an equals sign after reading the sub-expression name '"
3123 + subexpression_name +
"' but found an end-of-line.\nError encountered while reading"
3124 " SUB_EXPRESSION command\n" + line +
"\nLine # " + utility::to_string( line_number ) );
3126 input_line >> equals_sign;
3128 if ( equals_sign !=
'=' ) {
3129 throw utility::excn::EXCN_Msg_Exception(
"Expected to read an equals sign after reading the sub-expression name '"
3130 + subexpression_name +
"' but found '" + utility::to_string( equals_sign ) +
"'\nError encountered while reading"
3131 " SUB_EXPRESSION command\n" + line +
"\nLine # " + utility::to_string( line_number ) );
3135 std::getline( input_line, rest_of_line );
3137 TR <<
"On line " << line_number <<
", attempting to tokenize scalar expression: " << rest_of_line << std::endl;
3138 TokenSetOP tokens =
scanner_->scan( rest_of_line );
3139 TR <<
"On line " << line_number <<
", attempting to parse scalar expression: " << rest_of_line << std::endl;
3141 expression_ast->parse( *tokens );
3143 expression_asts[ subexpression_name ] = expression_ast;
3150 scanner_->add_variable( subexpression_name );
3158 std::istream & input_line,
3162 if ( score_expression_ast ) {
3163 throw utility::excn::EXCN_Msg_Exception(
"Encountered a second SCORE line"
3164 "while processing the EntityFunc file\n"
3165 + line +
"\nLine # " + utility::to_string( line_number ) );
3169 std::getline( input_line, rest_of_line );
3171 TR <<
"On line " << line_number <<
", attempting to tokenize score expression: " << rest_of_line << std::endl;
3172 TokenSetOP tokens =
scanner_->scan( rest_of_line );
3173 TR <<
"On line " << line_number <<
", attempting to parse score expression: " << rest_of_line << std::endl;
3174 score_expression_ast =
new ArithmeticASTExpression;
3175 score_expression_ast->parse( *tokens );
3181 std::map< std::string, ArithmeticASTExpressionOP >
const & expression_asts,
3189 std::map< std::string, ArithmeticASTExpressionOP >::const_iterator iter = expression_asts.find( ii_name );
3190 ExpressionCOP var_expr = expression_creator.create_expression_tree( * iter->second );
3197 score_expression_ = expression_creator.create_expression_tree( * score_expression_ast );
3202 using namespace protocols::multistate_design;
3205 for (
Size ii = 1; ii <= entity.
traits().size(); ++ii ) {
3206 PosType const & pt_ptr( dynamic_cast< PosType const & > ( * entity.
traits()[ ii ] ));