21 #ifdef USEBOOSTSERIALIZE
23 #include <boost/archive/binary_oarchive.hpp>
26 #include <basic/options/option.hh>
27 #include <basic/options/keys/els.OptionKeys.gen.hh>
29 #include <utility/lua/LuaIterator.hh>
30 #include "luabind/class_info.hpp"
33 #include <utility/Factory.hh>
61 #include <basic/Tracer.hh>
67 static basic::Tracer
TR(
"protocols.elscripts.BaseRole");
69 void lregister_BaseRole( lua_State * lstate ) {
70 luabind::module(lstate,
"protocols")
72 luabind::namespace_(
"elscripts")
74 luabind::class_<BaseRole>(
"BaseRole")
75 .def(
"reparse_def", &BaseRole::reparse_def)
79 void BaseRole::lua_init(){
80 using namespace basic::options;
82 lstate_ = luaL_newstate();
83 luabind::open(lstate_);
84 luabind::bind_class_info(lstate_);
85 luaL_openlibs(lstate_);
90 "setmetatable(els, {__index = _G })\n"
98 " dinputterstream = {}\n"
103 int err = luaL_dostring ( lstate_, action.c_str() );
105 TR <<
"Creating els namespace failed. Error is:" << std::endl;
106 TR << lua_tostring(lstate_, -1) << std::endl;
111 core::io::serialization::lregister_PipeMap(lstate_);
112 core::io::serialization::lregister_Pipe(lstate_);
113 core::pose::lregister_Pose(lstate_);
114 core::pose::lregister_util(lstate_);
115 protocols::moves::lregister_Mover(lstate_);
116 protocols::filters::lregister_Filter(lstate_);
117 core::scoring::lregister_ScoreFunction(lstate_);
118 protocols::moves::lregister_SerializableState(lstate_);
119 protocols::outputter::lregister_Outputter(lstate_);
120 protocols::inputter::lregister_Inputter(lstate_);
121 core::pack::task::operation::lregister_TaskOperation(lstate_);
124 if( option[OptionKeys::els::vars].user() ) {
125 err = luaL_dostring ( lstate_, option[OptionKeys::els::vars]().c_str() );
127 TR <<
"Lua interpreting of elscripts::vars failed. Error is:" << std::endl;
128 TR << lua_tostring(lstate_, -1) << std::endl;
134 TR <<
"Must specify a elscript to run" << std::endl;
144 std::ifstream
script( scriptname );
146 std::istreambuf_iterator<char>());
149 " local _ENV = _ENV\n"
150 " function els_setenv(t) _ENV = t end\n"
151 " function loop_every()\n"
152 " master:make_wu_until_limit(\"default\", 1)\n"
156 + modules::MonteCarlo
161 err = luaL_dostring ( lstate_, closure_script.c_str() );
163 TR <<
"Loading lua script '" << scriptname <<
"' failed. Error is:" << std::endl;
164 TR << lua_tostring(lstate_, -1) << std::endl;
169 err = luaL_dostring ( lstate_,
"definitions()" );
171 TR <<
"Calling lua function definitions() failed. Error is:" << std::endl;
172 TR << lua_tostring(lstate_, -1) << std::endl;
179 void BaseRole::instantiate_workunits() {
184 int err = luaL_dostring ( lstate_,
"define_workunits()" );
186 TR <<
"Calling lua function define_workunits() failed. Error is:" << std::endl;
187 TR << lua_tostring(lstate_, -1) << std::endl;
192 void BaseRole::instantiate_scorefxns() {
193 using namespace core::scoring;
194 using namespace core::scoring::symmetry;
195 using namespace utility::lua;
197 TR <<
"----------Instantiating Score Functions----------" << std::endl;
201 luabind::globals(lstate_)[
"els"][
"scorefxns"] = luabind::newtable( lstate_ );
202 scorefxns_.raw( luabind::globals(lstate_)[
"els"][
"scorefxns"] );
204 LuaObject dscorefxns(luabind::globals(lstate_)[
"els"][
"dscorefxns"]);
205 for (LuaIterator i=dscorefxns.begin(),
end; i !=
end; ++i) {
206 TR <<
"Instantiating score function named " << i.skey() << std::endl;
209 if( (*i)[
"weights"] && (*i)[
"patch"] ) {
211 (*i)[
"weights"].to<std::string>(),
212 (*i)[
"patch"].to<std::string>()
214 }
else if ( (*i)[
"weights"] ) {
222 if( (*i)[
"reweight"]) {
223 for (LuaIterator j=(*i)[
"reweight"].begin(),
end; j !=
end; ++j) {
225 scorefxn->set_weight( type, (*j).to<
core::Real>() );
230 if( (*i)[
"emoptions"] ) {
235 for (LuaIterator j=(*i)[
"emoptions"].begin(),
end; j !=
end; ++j) {
236 if( j.skey() ==
"softrep_etable" && (*j).to<
bool>() ) {
238 }
else if( j.skey() ==
"exclude_protein_protein_hack_elec" ) {
239 emoptions.exclude_protein_protein_hack_elec( (*j).to<
bool>() );
240 }
else if( j.skey() ==
"exclude_DNA_DNA" ) {
241 emoptions.exclude_DNA_DNA( (*j).to<
bool>() );
242 }
else if( j.skey() ==
"use_hb_env_dep_DNA" ) {
243 hboptions->use_hb_env_dep_DNA( (*j).to<
bool>() );
244 }
else if( j.skey() ==
"use_hb_env_dep" ) {
245 hboptions->use_hb_env_dep( (*j).to<
bool>() );
246 }
else if( j.skey() ==
"smooth_hb_env_dep" ) {
247 hboptions->smooth_hb_env_dep( (*j).to<
bool>() );
248 }
else if( j.skey() ==
"decompose_bb_hb_into_pair_energies" ) {
249 hboptions->decompose_bb_hb_into_pair_energies( (*j).to<
bool>() );
252 scorefxn->set_energy_method_options( emoptions );
258 if( (*i)[
"hs_hash"] ) {
263 bool const scorefxn_symm = (*i)[
"symmetric"] ? (*i)[
"symmetric"].to<
bool>() : 0 ;
270 scorefxn.relinquish_ownership();
271 luabind::globals(lstate_)[
"els"][
"scorefxns"][ i.skey() ] = tmpsp;
274 if( luabind::type( scorefxns_[
"score12"].raw() ) == 0 ) {
277 scorefxn.relinquish_ownership();
278 luabind::globals(lstate_)[
"els"][
"scorefxns"][
"score12"] = tmpsp;
280 TR <<
"----------Finished Instantiating Score Functions----------" << std::endl;
283 void BaseRole::instantiate_tasks() {
284 using namespace core::pack::task::operation;
285 using namespace utility::lua;
287 TR <<
"----------Instantiating TaskOperations----------" << std::endl;
289 luabind::globals(lstate_)[
"els"][
"tasks"] = luabind::newtable( lstate_ );
290 tasks_.raw( luabind::globals(lstate_)[
"els"][
"tasks"] );
292 LuaObject dtasks( luabind::globals(lstate_)[
"els"][
"dtasks"]);
294 for (LuaIterator i=dtasks.begin(),
end; i !=
end; ++i) {
295 TR <<
"Instantiating task operation " << (*i)[
"class"].to<
std::string>() <<
" named " << i.skey() << std::endl;
298 task->parse_def( (*i) );
300 task.relinquish_ownership();
301 tasks_.raw()[ i.skey() ] = tmpsp;
303 TR <<
"----------Finished Instantiating TaskOperations----------" << std::endl;
306 void BaseRole::instantiate_movers() {
307 using namespace utility;
308 using namespace utility::lua;
309 using namespace protocols::moves;
311 TR <<
"----------Instantiating Movers----------" << std::endl;
313 luabind::globals(lstate_)[
"els"][
"movers"] = luabind::newtable( lstate_ );
314 movers_.raw( luabind::globals(lstate_)[
"els"][
"movers"] );
316 LuaObject dmovers( luabind::globals(lstate_)[
"els"][
"dmovers"]);
317 Factory<Mover> * moverfactory = Factory<Mover>::get_instance();
318 for (LuaIterator i=dmovers.begin(),
end; i !=
end; ++i) {
319 TR <<
"Instantiating mover " << (*i)[
"class"].to<
std::string>() <<
" named " << i.skey() << std::endl;
320 if( moverfactory->has_string( (*i)[
"class"].to<
std::string>() ) ) {
321 MoverSP mover = moverfactory->from_string( (*i)[
"class"].to<std::string>() );
322 mover->parse_def( (*i), scorefxns_, tasks_, mover_cache_ );
323 luabind::globals(lstate_)[
"els"][
"movers"][ i.skey() ] = mover;
325 MoverOP mover( MoverFactory::get_instance()->newMover( (*i)[
"class"].to<std::string>() ) );
326 mover->parse_def( (*i), scorefxns_, tasks_, mover_cache_ );
328 mover.relinquish_ownership();
329 luabind::globals(lstate_)[
"els"][
"movers"][ i.skey() ] = tmpsp;
332 TR <<
"----------Finished Instantiating Movers----------" << std::endl;
335 void BaseRole::instantiate_filters() {
336 using namespace utility::lua;
337 using namespace protocols::filters;
339 TR <<
"----------Instantiating Filters----------" << std::endl;
341 luabind::globals(lstate_)[
"els"][
"filters"] = luabind::newtable( lstate_ );
342 filters_.raw( luabind::globals(lstate_)[
"els"][
"filters"] );
344 LuaObject dfilters( luabind::globals(lstate_)[
"els"][
"dfilters"]);
345 for (LuaIterator i=dfilters.begin(),
end; i !=
end; ++i) {
346 TR <<
"Instantiating filter " << (*i)[
"class"].to<
std::string>() <<
" named " << i.skey() << std::endl;
347 FilterOP filter( FilterFactory::get_instance()->newFilter( (*i)[
"class"].to<std::string>() ) );
348 filter->parse_def( (*i), scorefxns_, tasks_);
350 filter.relinquish_ownership();
351 luabind::globals(lstate_)[
"els"][
"filters"][ i.skey() ] = tmpsp;
353 TR <<
"----------Finished Instantiating Filters----------" << std::endl;
355 void BaseRole::instantiate_output() {
356 using namespace utility::lua;
357 using namespace protocols::outputter;
359 TR <<
"----------Instantiating Outputters----------" << std::endl;
361 luabind::globals(lstate_)[
"els"][
"outputters"] = luabind::newtable( lstate_ );
362 outputters_.raw( luabind::globals(lstate_)[
"els"][
"outputters"] );
364 LuaObject doutputters( luabind::globals(lstate_)[
"els"][
"doutputters"] );
365 utility::Factory<Outputter> * outputterfactory = utility::Factory<Outputter>::get_instance();
366 for (LuaIterator i=doutputters.begin(),
end; i !=
end; ++i) {
367 TR <<
"Instantiating outputter " << (*i)[
"class"].to<
std::string>() <<
" named " << i.skey() << std::endl;
369 outputter->lregister( lstate_ );
370 outputter->parse_def( (*i), tasks_ );
371 luabind::globals(lstate_)[
"els"][
"outputters"][ i.skey() ] = outputter;
373 TR <<
"----------Finished Instantiating Outputters----------" << std::endl;
375 void BaseRole::instantiate_inputters() {
376 using namespace utility::lua;
377 using namespace protocols::inputter;
379 TR <<
"----------Instantiating Inputters----------" << std::endl;
381 luabind::globals(lstate_)[
"els"][
"inputters"] = luabind::newtable( lstate_ );
382 inputters_.raw( luabind::globals(lstate_)[
"els"][
"inputters"] );
384 LuaObject dinputters( luabind::globals(lstate_)[
"els"][
"dinputters"] );
385 utility::Factory<Inputter> * inputterfactory = utility::Factory<Inputter>::get_instance();
386 for (LuaIterator i=dinputters.begin(),
end; i !=
end; ++i) {
387 TR <<
"Instantiating inputter " << (*i)[
"class"].to<
std::string>() <<
" named " << i.skey() << std::endl;
389 inputter->lregister( lstate_ );
390 inputter->parse_def( (*i), tasks_, inputters_ );
391 luabind::globals(lstate_)[
"els"][
"inputters"][ i.skey() ] = inputter;
394 TR <<
"----------Finished Instantiating Inputters----------" << std::endl;
397 void BaseRole::instantiate_inputterstream() {
398 using namespace utility::lua;
399 using namespace protocols::inputter;
400 TR <<
"----------Adding Inputters to InputterStream----------" << std::endl;
401 LuaObject dinputterstream( luabind::globals(lstate_)[
"els"][
"dinputterstream"]);
402 for (LuaIterator i=dinputterstream.begin(),
end; i !=
end; ++i) {
405 if( inputterstream_->size() == 0 ) {
406 LuaObject dinputters( luabind::globals(lstate_)[
"els"][
"dinputters"] );
408 for (LuaIterator i=dinputters.begin(),
end; i !=
end; ++i) {
409 inputterstream_->add_inputter( inputters_[ i.skey() ].to<
InputterSP>() );
412 TR <<
"----------Finished adding Inputters to InputterStream----------" << std::endl;
415 void BaseRole::update_mover_cache_mem() {
416 if( mover_cache_length_ != mover_cache_->size() ) {
419 #ifdef USEBOOSTSERIALIZE
421 boost::archive::binary_oarchive oa(s);
423 mover_cache_mem_ = s.str().length();
424 mover_cache_length_ = mover_cache_->size();
426 TR <<
"Memory usage tracked only if compiled against serialize" << std::endl;
430 void BaseRole::register_calculators() {
435 using namespace core::pose::metrics;
437 if( !CalculatorFactory::Instance().check_calculator_exists(
"sasa_interface" ) ){
439 CalculatorFactory::Instance().register_calculator(
"sasa_interface", int_sasa_calculator );
442 if( !CalculatorFactory::Instance().check_calculator_exists(
"sasa" ) ){
444 CalculatorFactory::Instance().register_calculator(
"sasa", sasa_calculator );
446 if( !CalculatorFactory::Instance().check_calculator_exists(
"ligneigh" ) ){
448 CalculatorFactory::Instance().register_calculator(
"ligneigh", lig_neighbor_calc );
450 if( !CalculatorFactory::Instance().check_calculator_exists(
"liginterfE" ) ){
452 CalculatorFactory::Instance().register_calculator(
"liginterfE", lig_interf_E_calc );
457 using namespace utility::lua;
458 if( type ==
"tasks" ) {
459 using namespace core::pack::task::operation;
460 LuaObject dtasks( luabind::globals(lstate_)[
"els"][
"dtasks"]);
461 for (LuaIterator i=dtasks.begin(),
end; i !=
end; ++i) {
462 if( i.skey() == name ) {
468 if( type ==
"movers" ) {
469 using namespace protocols::moves;
470 LuaObject dmovers( luabind::globals(lstate_)[
"els"][
"dmovers"]);
471 for (LuaIterator i=dmovers.begin(),
end; i !=
end; ++i) {
472 if( i.skey() == name ) {
473 movers_[ i.skey() ].to<
MoverSP>()->parse_def( (*i), scorefxns_, tasks_, mover_cache_ );