Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
SetAACompositionPotential.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 protocols/fldsgn/potentials/SetAACompositionEnergy.cc
11 /// @brief
12 /// @author Nobuyasu Koga ( nobuyasu@uw.edu )
13 
14 // unit headers
18 
19 // C++ headers
20 #include <core/chemical/AA.hh>
21 #include <core/pose/Pose.hh>
24 
25 // utility header
26 #include <utility/string_util.hh>
27 #include <utility/io/izstream.hh>
28 
29 // boost
30 #include <boost/lexical_cast.hpp>
31 
32 // parser
33 #include <utility/tag/Tag.hh>
35 #include <basic/Tracer.hh>
36 
37 #include <utility/vector0.hh>
38 #include <utility/vector1.hh>
39 
40 
41 namespace protocols {
42 namespace fldsgn {
43 namespace potentials {
44 
45 
46 static basic::Tracer TR( "protocols.fldsgn.potentials.SetAACompositionPotential" );
47 
48 
49 /// @brief
52 {
54 }
55 
56 
57 /// @brief
60  return new SetAACompositionPotential;
61 }
62 
63 
64 /// @brief
67 {
68  return "SetAACompositionPotential";
69 }
70 
71 
72 /// @brief default constructor
74  Super( "SetAACompositionPotential" ),
75  loaded_( false )
76 {}
77 
78 
79 /// @Brief copy constructor
81  Super( rval ),
82  comp_constraint_aas_( rval.comp_constraint_aas_ ),
83  weight_( rval.weight_ ),
84  sfx_( rval.sfx_ ),
85  loaded_( rval.loaded_ )
86 {}
87 
88 
89 /// @brief default destructor
91 
92 
93 /// @brief clone this object
96 {
97  return new SetAACompositionPotential( *this );
98 }
99 
100 
101 /// @brief create this type of object
104 {
105  return new SetAACompositionPotential();
106 }
107 
108 /// @brief set parameters
109 bool
111 {
112  utility::io::izstream data( file );
113  if ( !data ) {
114  TR.Error << "can not open file " << file << std::endl;
115  return false;
116  }
117 
118  String line;
119  Size linecount( 0 );
120  while( getline( data, line ) ) {
121 
122  linecount++;
123  utility::vector1< String > tokens ( utility::split( line ) );
124  if( tokens[1][0] == '#' ) continue; // skip reading line that is commented out
125  runtime_assert( tokens.size() == 3 );
126 
127  core::chemical::AA const aa = core::chemical::aa_from_name( tokens[1] );
128  Real const lower_threshold = boost::lexical_cast<Real>( tokens[2] );
129  Real const upper_threshold = boost::lexical_cast<Real>( tokens[3] );
130 
131  runtime_assert( lower_threshold <= upper_threshold );
132 
133  std::pair< Real, Real > thresholds( lower_threshold, upper_threshold );
134 
135  comp_constraint_aas_.insert( std::map< core::chemical::AA, std::pair< Real, Real > >::value_type( aa, thresholds ) );
136 
137  }
138 
139 
140  Real checkL( 0.0 ), checkU( 0.0 );
141  std::map< AA, std::pair< Real, Real > >::iterator it = comp_constraint_aas_.begin();
142  while( it != comp_constraint_aas_.end() ) {
143  AA aa( it->first );
144  checkL += comp_constraint_aas_[ aa ].first;
145  checkU += comp_constraint_aas_[ aa ].second;
146  ++it;
147  }
148  runtime_assert( checkL <= 1.0 && checkU <= 1.0 );
149 
150 
151  return true;
152 } // set_parameters
153 
154 
155 /// @brief apply defined moves to given Pose
156 void
158 {
160 
161  if( loaded_ ) return;
162 
164 
165  std::map< ScoreType, Real > new_weights;
166  new_weights.insert( std::map< ScoreType, Real >::value_type( core::scoring::aa_cmp, weight_ ) );
167 
168  sfx_->set_weight( core::scoring::aa_cmp, 0.0 );
169  sfx_->add_extra_method( new_weights, cce );
170 
171  //sfx_->show( TR, pose );
172 }
173 
174 
175 /// @brief
179 }
180 /// @brief parse xml
181 void
183  TagPtr const tag,
184  DataMap & data,
185  Filters_map const &,
186  Movers_map const &,
187  Pose const & )
188 {
189 
190  std::string const file( tag->getOption<String>( "file", "" ) );
191  if( file == "" ){
192  TR << "No input of file ! " << std::endl;
193  runtime_assert( false );
194  }
195  set_parameters( file );
196 
197  weight_ = ( tag->getOption<Real>( "weight", 1.0 ) );
198 
199  // set scorefxn
200  String const sfxn ( tag->getOption<String>( "scorefxn", "" ) );
201  sfx_ = data.get< ScoreFunction* >( "scorefxns", sfxn );
202  if( sfxn == "" ) {
203  TR << "No input of sfxn ! " << std::endl;
204  runtime_assert( false );
205  }
206 
207 }
208 
209 
210 } // namespace potentials
211 } // namespace fldsgn
212 } // namespace protocols