Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ScoreFunctionFactory.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/core/conformation/ResidueFactory.hh
11 /// @brief
12 /// @author Andrew Leaver-Fay (aleaverfay@gmail.com)
13 
14 
21 
22 #include <core/chemical/AA.hh>
23 
24 // AUTO-REMOVED #include <basic/database/open.hh>
25 
26 #include <basic/options/option.hh>
27 // AUTO-REMOVED #include <basic/options/after_opts.hh>
28 
29 #include <basic/Tracer.hh>
30 
31 // AUTO-REMOVED #include <utility/io/izstream.hh>
32 #include <utility/vector1.hh>
33 // option key includes
34 
35 #include <basic/options/keys/score.OptionKeys.gen.hh>
36 #include <basic/options/keys/corrections.OptionKeys.gen.hh>
37 // AUTO-REMOVED #include <basic/options/keys/constraints.OptionKeys.gen.hh>
38 #include <basic/options/keys/abinitio.OptionKeys.gen.hh>
39 #include <basic/options/keys/symmetry.OptionKeys.gen.hh>
40 #include <sstream>
41 
42 using basic::T;
43 
44 static basic::Tracer tr("core.scoring.ScoreFunctionFactory");
45 
46 namespace core {
47 namespace scoring {
48 
51 {
53  return create_score_function( weights_tag, patch_tags );
54  /* removing duplicated code OL 5/24/2012 */
55  /*
56  ScoreFunctionOP scorefxn( new ScoreFunction );
57 
58  load_weights_file( weights_tag, scorefxn );
59 
60  // allow user to change weights via options system
61  apply_user_defined_reweighting_( scorefxn );
62 
63  if ( basic::options::option[ basic::options::OptionKeys::symmetry::symmetry_definition ].user() ) {
64  scorefxn = new SymmetricScoreFunction( scorefxn );
65  }
66  if ( basic::options::option[ basic::options::OptionKeys::score::docking_interface_score ]() ) {
67  scorefxn = new DockingScoreFunction( scorefxn );
68  }
69 
70  return scorefxn;
71  */
72 }
73 
74 
77  using basic::options::option;
78  using namespace basic::options::OptionKeys;
79 
80  // create a new scorefunction
81  ScoreFunctionOP scorefxn( new ScoreFunction );
82 
83  /// Avoid loading the score12 patch if we're using
84  /// 1) standard weights,
85  /// 2) the score12 patch, and
86  /// 3) the flag "score12prime"
87  if ( weights_tag == STANDARD_WTS &&
88  basic::options::option[ basic::options::OptionKeys::corrections::score::score12prime ] ) {
89  bool sc12patch = false;
90  for ( Size ii = 1; ii <= patch_tags.size(); ++ii ) {
91  if ( patch_tags[ ii ] == SCORE12_PATCH ) {
92  patch_tags[ ii ] = "NOPATCH";
93  sc12patch = true;
94  }
95  }
96  if ( sc12patch ) {
97  weights_tag = "score12prime";
98  }
99  }
100 
101  load_weights_file( weights_tag, scorefxn );
102 
103  for ( utility::vector1< std::string >::const_iterator it = patch_tags.begin(); it != patch_tags.end(); ++it ) {
104  std::string const& patch_tag( *it );
105  if ( patch_tag.size() && patch_tag != "NOPATCH" ) {
106  // tr.Debug << "SCOREFUNCTION: apply patch " << patch_tag << std::endl;
107  scorefxn->apply_patch_from_file( patch_tag );
108  }
109  }
110 
111  // allow user to change weights via options system
113 
114  if ( basic::options::option[ basic::options::OptionKeys::symmetry::symmetry_definition ].user() ) {
115  scorefxn = new SymmetricScoreFunction( scorefxn );
116  }
117  if ( basic::options::option[ basic::options::OptionKeys::score::docking_interface_score ]() ) {
118  scorefxn = new DockingScoreFunction( scorefxn );
119  }
120  if ( basic::options::option[ basic::options::OptionKeys::score::min_score_score ].user() ) {
121  scorefxn = new MinScoreScoreFunction( scorefxn, basic::options::option[ basic::options::OptionKeys::score::min_score_score ]() );
122  }
123  scorefxn->name( weights_tag );
124  return scorefxn;
125 }
126 
127 
130 {
131  using basic::options::option;
132  using namespace basic::options::OptionKeys;
133 
134  // create a new scorefunction
135  ScoreFunctionOP scorefxn( new ScoreFunction );
137  patch_tags.push_back( patch_tag );
138  return create_score_function( weights_tag, patch_tags );
139  /* REMOVING DUPLICATED CODE OL 5/24/2012 */
140  /* std::string patch_tag_local( patch_tag );
141  if ( weights_tag == STANDARD_WTS && patch_tag == SCORE12_PATCH &&
142  basic::options::option[ basic::options::OptionKeys::corrections::score::score12prime ] ) {
143  weights_tag = "score12prime";
144  patch_tag_local = "";
145  }
146 
147  load_weights_file( weights_tag, scorefxn );
148 
149  if ( patch_tag_local.size() && patch_tag_local != "NOPATCH" ) {
150  scorefxn->apply_patch_from_file( patch_tag_local );
151  }
152 
153  // allow user to change weights via options system
154  apply_user_defined_reweighting_( scorefxn );
155 
156 
157  if ( basic::options::option[ basic::options::OptionKeys::symmetry::symmetry_definition ].user() ) {
158  scorefxn = new SymmetricScoreFunction( scorefxn );
159  }
160  if ( basic::options::option[ basic::options::OptionKeys::score::docking_interface_score ]() ) {
161  scorefxn = new DockingScoreFunction( scorefxn );
162  }
163 
164  return scorefxn;
165  */
166 }
167 
169  // do some reweighting here. This code could be much more simple if the options system could
170  // produce a std::pair< std::string, core::Real >. For now these are separate options for
171  // the different reweights.
172  using basic::options::option;
173  using namespace basic::options::OptionKeys;
174 
175 
176  /// new mechanism: set multiple weights using string vector option
177  if ( option[ score::set_weights ].user() ) {
178  std::string const errmsg("proper format for -set_weights is a list of paired strings, e.g: '-set_weights fa_atr 0.6 -fa_rep 0.55 -fa_sol 0.9' ");
179  utility::vector1< std::string > const settings( option[ score::set_weights ]() );
180  if ( settings.size()%2 != 0 ) utility_exit_with_message( errmsg );
181  for ( Size i=0; i< settings.size()/2; ++i ) {
182  if ( !ObjexxFCL::is_float( settings[ 2*i+2 ] ) ) utility_exit_with_message( errmsg );
183  ScoreType const t( score_type_from_name( settings[ 2*i + 1] ) );
184  Real const value( ObjexxFCL::float_of( settings[ 2*i + 2 ] ) );
185  tr << "Setting/modifying scorefxn weight from command line: " << t << ' ' << value << std::endl;
186  scorefxn->set_weight( t, value );
187  }
188  }
189 
190 
191  if ( option[ abinitio::rg_reweight ].user() ) {
192  scorefxn->set_weight( rg, scorefxn->get_weight( rg ) * option[ abinitio::rg_reweight ]() );
193  }
194  // offset reference energies using user options, for example: -score:ref_offsets TRP 0.9 HIS 0.3
195  if ( option[ score::ref_offsets ].user() ) {
196 
197  // get the ref weights from the EnergyMethodOptions object
198  methods::EnergyMethodOptions energy_method_options(scorefxn->energy_method_options());
199  if (!energy_method_options.has_method_weights(ref)) {
200  utility_exit_with_message("option -score:ref_offsets requires preexisting reference energies");
201  }
202  utility::vector1<core::Real> ref_weights(energy_method_options.method_weights(ref));
203 
204  // get the offsets vector and make sure it contains pairs
205  utility::vector1<std::string> const & ref_offsets( option[ score::ref_offsets ]() );
206  if (ref_offsets.size() % 2 != 0) {
207  utility_exit_with_message("option -score:ref_offsets requires pairs of 3 character residue types and offsets");
208  }
209 
210  // iterate over all pairs
211  for (utility::vector1<std::string>::const_iterator iter(ref_offsets.begin()), iter_end(ref_offsets.end());
212  iter != iter_end; ++iter) {
213  // get the aa type from the pair
214  std::istringstream aa_iss(*iter);
216  if (!(aa_iss >> aa)) {
217  utility_exit_with_message(aa_iss.str()+" is not a valid 3 character residue type for -score:ref_offsets");
218  }
219  // get the offset from the pair
220  std::istringstream offset_iss(*(++iter));
221  core::Real offset;
222  if (!(offset_iss >> offset)) {
223  utility_exit_with_message(offset_iss.str()+" is not a valid offset for -score:ref_offsets");
224  }
225  // offset the weight
226  ref_weights[aa] += offset;
227  }
228 
229  // load the ref weights back into the EnergyMethodOptions object
230  energy_method_options.set_method_weights(ref, ref_weights);
231  scorefxn->set_energy_method_options(energy_method_options);
232  }
233 }
234 
236 {
237  scorefxn->initialize_from_file(weights_tag);
238 }
239 
240 std::string const STANDARD_WTS( "standard" );
241 std::string const CENTROID_WTS( "cen_std" );
242 std::string const SOFT_REP_WTS( "soft_rep" );
243 std::string const SOFT_REP_DESIGN_WTS( "soft_rep_design" );
244 std::string const DNA_INT_WTS( "dna_no_gb" );
245 std::string const DNA_INT_WTS_GB( "dna" );
246 std::string const MM_STD_WTS( "mm_std" );
247 std::string const RNA_LORES_WTS( "rna_lores" );
248 std::string const RNA_HIRES_WTS( "rna_hires" );
249 std::string const RNA_LORES_PLUS_HIRES_WTS( "rna_lores_plus_hires" );
250 std::string const MEMB_HIGHRES_WTS( "membrane_highres" ); //pba
251 
252 std::string const SCORE12_PATCH( "score12" );
253 std::string const SCORE13( "score13" );
254 std::string const DOCK_PATCH( "docking" );
255 std::string const DOCK_LOW_PATCH( "docking_cen" );
256 
257 
258 core::scoring::ScoreFunctionOP getScoreFunction( bool const is_fullatom /* default true */ ) {
259  using basic::options::option;
260  using namespace basic::options::OptionKeys;
261 
263 
264  //if( option[ score::empty ]() || option[ abinitio::membrane ]() /*fullatom not implemented for membrane yet */) return scorefxn;
265 
266  if( option[ score::empty ]() ) return scorefxn;
267 
268  std::string weight_set = option[ score::weights ];
269  utility::vector1< std::string > patch_tags = option[ score::patch ]();
270 
271 
272  if ( !option[ score::weights ].user() && !is_fullatom ){
273 
274  // Defalt score of centroid is cen_wts when is_fullatom is false and user has not specified a score weights
275  weight_set = CENTROID_WTS;
276 
277  }else{
278 
279  /// Default score is score12 if the user has not specified a score weights file or a patch file
280  /// on the command line. If the user has specified that they would like the standard weight set,
281  /// and has not also asked for the score12 patch, then do not apply the score12 patch to it.
282  if ( ( weight_set == "standard" && !option[ score::weights ].user() ) &&
283  ( !option[ score::patch ].user() ) ) {
284  patch_tags.push_back( "score12" );
285  if( basic::options::option[basic::options::OptionKeys::corrections::correct]) {
286  weight_set = "score12_w_corrections";
287  patch_tags.clear();
288  } else if ( basic::options::option[ basic::options::OptionKeys::corrections::score::score12prime ] ) {
289  weight_set = "score12prime";
290  patch_tags.clear();
291  }
292  }
293 
294  }
295 
296  T("core.scoring.ScoreFunctionFactory") << "SCOREFUNCTION: " << weight_set << std::endl;
297  if ( patch_tags.size() == 0 ) {
299  } else {
300  if ( patch_tags.size() > 1 && patch_tags[1]=="" && patch_tags[2]!="" ) {
301  T("core.scoring.ScoreFunctionFactory") << "SCOREFUNCTION PATCH: " << patch_tags[2] << std::endl;
302  } else if ( patch_tags[1]!="" ) T("core.scoring.ScoreFunctionFactory") << "SCOREFUNCTION PATCH: " << patch_tags[1] << std::endl;
303  scorefxn = scoring::ScoreFunctionFactory::create_score_function( weight_set, patch_tags );
304  }
305 
306  // add in constraint weights if specified by the user. maybe we want other constraint
307  // types to be weighted as well ...
308  //
309  // mtyka: No No No we dont want this here. Add constraints and weights ouside this function.
310  // just setting the weights alone isnt gonna get oyu far anyway.
311  //if ( option[ constraints::cst_weight ].user() ) {
312  // scorefxn->set_weight( atom_pair_constraint, option[ constraints::cst_weight ]() );
313  // }
314 
315  // this is already done in create_score_function
316  // if ( basic::options::option[ basic::options::OptionKeys::symmetry::symmetry_definition ].user() )
317  // {
318  // return core::scoring::ScoreFunctionOP( new core::scoring::symmetry::SymmetricScoreFunction( scorefxn ) );
319  // }
320 
321  return scorefxn;
322 }
323 
326  bool const is_fullatom /* default true */
327 ) {
328  using basic::options::option;
329  using namespace basic::options::OptionKeys;
330 
331  if( option[ score::empty ]() ) return "empty";
332 
333  std::string weight_set = option[ score::weights ];
334  utility::vector1< std::string > patch_tags = option[ score::patch ]();
335 
336 
337  if ( !option[ score::weights ].user() && !is_fullatom ){
338 
339  // Defalt score of centroid is cen_wts when is_fullatom is false and user has not specified a score weights
340  weight_set = CENTROID_WTS;
341 
342  }else{
343 
344  /// Default score is score12 if the user has not specified a score weights file or a patch file
345  /// on the command line. If the user has specified that they would like the standard weight set,
346  /// and has not also asked for the score12 patch, then do not apply the score12 patch to it.
347  if ( ( weight_set == "standard" && !option[ score::weights ].user() ) &&
348  ( !option[ score::patch ].user() ) ) {
349  patch_tags.push_back( "score12" );
350  if( option[ corrections::correct ]) {
351  weight_set = "score12_w_corrections";
352  patch_tags.clear();
353  } else if ( option[ corrections::score::score12prime ] ) {
354  weight_set = "score12prime";
355  patch_tags.clear();
356  }
357  }
358  }
359 
360  if ( patch_tags.size() != 0 &&
361  weight_set == STANDARD_WTS &&
362  option[ corrections::score::score12prime ] ) {
363 
364  bool sc12patch = false;
365  for ( Size ii = 1; ii <= patch_tags.size(); ++ii ) {
366  if ( patch_tags[ ii ] == SCORE12_PATCH ) {
367  patch_tags[ ii ] = "NOPATCH";
368  sc12patch = true;
369  }
370  }
371  if ( sc12patch ) {
372  weight_set = "score12prime";
373  }
374  }
375 
376  std::stringstream patch_string;
377  for(Size ii=1; ii <= patch_tags.size(); ++ii){
378  if( patch_tags[ii] == "NOPATCH" ) continue;
379  patch_string << "_" << patch_tags[ii];
380  }
381 
382  return weight_set + patch_string.str();
383 }
384 
385 
386 
387 } // namespace scoring
388 } // namespace core
389 
390