Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
util.cc
Go to the documentation of this file.
1 // -*- mode:c++;tab-width:2;indent-tabs-mode:t;show-trailing-whitespace:t;rm-trailing-spaces:t -*-
2 // vi: set ts=2 noet:
3 //
4 // (c) Copyright Rosetta Commons Member Institutions.
5 // (c) This file is part of the Rosetta software suite and is made available under license.
6 // (c) The Rosetta software is developed by the contributing members of the Rosetta Commons.
7 // (c) For more information, see http://www.rosettacommons.org. Questions about this can be
8 // (c) addressed to University of Washington UW TechTransfer, email: license@u.washington.edu.
9 
10 /// @file src/protocols/elscripts/util.hh
11 /// @brief Utility functions useful in elscripts
12 /// @author ken Jung
13 
14 // Unit Headers
16 
17 #include <basic/Tracer.hh>
21 #include <utility/exit.hh>
22 
23 static basic::Tracer TR( "protocols.elscripts.util" );
24 
25 namespace protocols {
26 namespace elscripts {
27 
28 using namespace utility;
29 using namespace utility::lua;
30 
32 parse_scoredef( LuaObject const & scoredef,
33  LuaObject const & score_fxns ) {
34 
35  std::string scorefxn_name = scoredef.to<std::string>();
36  for (LuaIterator i=score_fxns.begin(), end; i != end; ++i) {
37  if( i.skey() == scorefxn_name ) {
38  return (*i).to<core::scoring::ScoreFunctionSP>()->clone();
39  break;
40  }
41  }
42  utility_exit_with_message("ScoreFunction " + scorefxn_name + " not found in score_fxns map.");
43 }
44 
46 parse_taskdef( LuaObject const & taskdef,
47  LuaObject const & tasks ) {
48  using namespace core::pack::task;
49  using namespace core::pack::task::operation;
50 
51  TaskFactoryOP new_task_factory( new TaskFactory );
52  for (LuaIterator i=taskdef.begin(), end; i != end; ++i) {
53  std::string task_name = (*i).to<std::string>();
54  bool taskfound = false;
55  for (LuaIterator j=tasks.begin(), end; j != end; ++j) {
56  if( j.skey() == task_name ) {
57  new_task_factory->push_back( (*j).to<TaskOperationSP>() );
58  taskfound = true;
59  break;
60  }
61  }
62  if( !taskfound ) utility_exit_with_message("TaskOperation " + task_name + " not found in tasks map.");
63  }
64  return new_task_factory;
65 }
66 
68 sp_parse_taskdef( LuaObject const & taskdef,
69  LuaObject const & tasks ) {
70  using namespace core::pack::task;
71  using namespace core::pack::task::operation;
72  TaskFactoryOP tmpop = parse_taskdef( taskdef, tasks );
73  TaskFactorySP tmpsp( tmpop.get() );
74  tmpop.relinquish_ownership();
75  return tmpsp;
76 }
77 
78 void parse_movemapdef( LuaObject const & movemapdef, core::kinematics::MoveMapOP mm ) {
79  for (LuaIterator i=movemapdef.begin(), end; i != end; ++i) {
80  switch( (*i).size() ) {
81  case 2:
82  {
83  core::Size const num( (*i)[1].to<core::Size>() );
84  bool const setting( (*i)[2].to<bool>() );
85  num == 0 ? mm->set_jump( setting ) : mm->set_jump( num, setting );
86  break;
87  }
88  case 4:
89  {
90  core::Size const begin( (*i)[1].to<core::Size>() );
91  core::Size const end( (*i)[2].to<core::Size>() );
92  runtime_assert( end >= begin );
93  bool const chi( (*i)["chi"].to<bool>() );
94  bool const bb( (*i)["bb"].to<bool>() );
95  for( core::Size i( begin ); i <= end; ++i ){
96  mm->set_chi( i, chi );
97  mm->set_bb( i, bb );
98  }
99  break;
100  }
101  }
102  }
103 }
104 
105 } //elscripts
106 } //protocols