Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ScoreFunctionLoader.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/jd2/parser/DataLoader.cc
11 /// @brief Implementation of the XML parser's DataLoader base class (ctor & dstor)
12 /// @author Andrew Leaver-Fay (aleaverfay@gmail.com)
13 
14 // Unit Headers
17 
18 // Project Headers
25 #include <basic/Tracer.hh>
26 
27 // Utility headers
28 #include <utility/tag/Tag.hh>
29 
30 // Boost Headers
31 #include <boost/foreach.hpp>
32 
34 #include <utility/vector0.hh>
35 #include <utility/vector1.hh>
36 #include <utility/string_util.hh>
37 
38 #define foreach BOOST_FOREACH
39 
40 namespace protocols {
41 namespace jd2 {
42 namespace parser {
43 
44 static basic::Tracer TR( "protocols.jd2.parser.ScoreFunctionLoader" );
45 
48 
50  core::pose::Pose const &,
51  utility::tag::TagPtr const tag,
52  moves::DataMap & data
53 ) const
54 {
55  using namespace utility::tag;
57 
58  TagPtrs const scorefxn_tags( tag->getTags() );
59 
60  foreach(TagPtr scorefxn_tag, scorefxn_tags){
61  using namespace core::scoring;
62  using namespace core::scoring::symmetry;
63 
64  ScoreFunctionOP in_scorefxn;
65  std::string const scorefxn_name( scorefxn_tag->getName() );
66  std::string const scorefxn_weights( scorefxn_tag->getOption<std::string>( "weights", "standard" ) );
67  if( scorefxn_tag->hasOption( "weights" ) && scorefxn_tag->hasOption( "patch" ) ) {
68  std::string const scorefxn_patch( scorefxn_tag->getOption<std::string>( "patch" ) );
69  in_scorefxn = ScoreFunctionFactory::create_score_function( scorefxn_weights, scorefxn_patch);
70  TR << "defined score function \"" << scorefxn_name << "\" with weights \""
71  << scorefxn_weights << "\" and patch \"" << scorefxn_patch << "\"\n";
72  } else if ( scorefxn_tag->hasOption( "weights" ) ) {
73  in_scorefxn = ScoreFunctionFactory::create_score_function( scorefxn_weights );
74  TR << "defined score function \"" << scorefxn_name << "\" with weights \""
75  << scorefxn_weights << "\"\n";
76  } else {
77  in_scorefxn = new ScoreFunction;
78  in_scorefxn->reset();
79  TR << "***WARNING***: No weights/patch defined. Defining " << scorefxn_name << " with all-zero weights.\n";
80  }
81  foreach(TagPtr mod_tag, scorefxn_tag->getTags()){
82  if( mod_tag->getName() == "Reweight" ) {
83  std::string const scoretype_name( mod_tag->getOption<std::string>( "scoretype" ) );
84  core::Real const weight( mod_tag->getOption<core::Real>( "weight" ) );
85  TR<<"setting "<<scorefxn_name<<" weight " << scoretype_name << " to " << weight<<'\n';
86  core::scoring::ScoreType const type = score_type_from_name( scoretype_name );
87  in_scorefxn->set_weight( type, weight );
88  }
89 
90  // Set energy method options:
91  if( mod_tag->getName() == "Set" ){
92  core::scoring::methods::EnergyMethodOptions emoptions( in_scorefxn->energy_method_options() );
93  core::scoring::hbonds::HBondOptionsOP hboptions( emoptions.hbond_options() );
94 
95  if( mod_tag->hasOption( "softrep_etable" )) {
96  if ( mod_tag->getOption<bool>( "softrep_etable" )) {
97  emoptions.etable_type( core::scoring::FA_STANDARD_SOFT );
98 
99  }
100  }
101 
102  if( mod_tag->hasOption( "hack_elec_min_dis" )) {
103  emoptions.hackelec_min_dis( mod_tag->getOption<core::Real>( "hack_elec_min_dis" ) );
104  }
105  if( mod_tag->hasOption( "hack_elec_max_dis" )) {
106  emoptions.hackelec_max_dis( mod_tag->getOption<core::Real>( "hack_elec_max_dis" ) );
107  }
108  if( mod_tag->hasOption( "hack_elec_dielectric" )) {
109  emoptions.hackelec_die( mod_tag->getOption<core::Real>( "hack_elec_dielectric" ) );
110  }
111  if( mod_tag->hasOption( "hack_elec_no_dis_dep_die" )) {
112  emoptions.hackelec_no_dis_dep_die( mod_tag->getOption<bool>( "hack_elec_no_dis_dep_die" ) );
113  }
114  if( mod_tag->hasOption( "exclude_protein_protein_hack_elec" )) {
115  emoptions.exclude_protein_protein_hack_elec( mod_tag->getOption<bool>( "exclude_protein_protein_hack_elec" ) );
116  }
117  if( mod_tag->hasOption( "exclude_DNA_DNA" )) {
118  emoptions.exclude_DNA_DNA( mod_tag->getOption<bool>( "exclude_DNA_DNA" ) );
119  }
120  if( mod_tag->hasOption( "exclude_DNA_DNA_hbond" )) {
121  hboptions->exclude_DNA_DNA( mod_tag->getOption<bool>( "exclude_DNA_DNA_hbond" ) );
122  }
123  if( mod_tag->hasOption( "use_hb_env_dep_DNA" )) {
124  hboptions->use_hb_env_dep_DNA( mod_tag->getOption<bool>( "use_hb_env_dep_DNA" ) );
125  }
126  if( mod_tag->hasOption( "use_hb_env_dep" )) {
127  hboptions->use_hb_env_dep( mod_tag->getOption<bool>( "use_hb_env_dep" ) );
128  }
129  if( mod_tag->hasOption( "smooth_hb_env_dep" )) {
130  hboptions->smooth_hb_env_dep( mod_tag->getOption<bool>( "smooth_hb_env_dep" ) );
131  }
132  if( mod_tag->hasOption( "decompose_bb_hb_into_pair_energies" )) {
133  hboptions->decompose_bb_hb_into_pair_energies( mod_tag->getOption<bool>( "decompose_bb_hb_into_pair_energies" ) );
134  }
135  if( mod_tag->hasOption( "pb_bound_tag" )) {
136  emoptions.pb_bound_tag( mod_tag->getOption<std::string>("pb_bound_tag" ) );
137  TR << "User defined bound tag: " << emoptions.pb_bound_tag() << std::endl;
138  }
139  if( mod_tag->hasOption( "pb_unbound_tag" )) {
140  emoptions.pb_unbound_tag( mod_tag->getOption<std::string>("pb_unbound_tag" ) );
141  TR << "User defined unbound tag: " << emoptions.pb_unbound_tag() << std::endl;
142  }
143  in_scorefxn->set_energy_method_options( emoptions );
144  }
145  } // Mod tags
146 
147  // weights for arbitrary ScoreFunctions should be tampered with only as a consequence of user input--NEVER by default
148 
149  // hotspot hash constraint
150  if ( scorefxn_tag->hasOption("hs_hash") ) {
151  core::Real hotspot_hash( 0.0 ); // APL FIX THIS! This used to be initialized when the HotspotHashingConstraints were read in.
152  core::Real const hs_hash( scorefxn_tag->getOption<core::Real>( "hs_hash", hotspot_hash ) );
153  TR<<"setting "<<scorefxn_name<<" backbone_stub_constraint to "<<hs_hash<<'\n';
154  in_scorefxn->set_weight( backbone_stub_constraint, hs_hash );
155  }
156 
157  //fpd should we symmetrize scorefunction?
158  bool const scorefxn_symm( scorefxn_tag->getOption<bool>( "symmetric", 0 ) );
159  if (scorefxn_symm) {
160  in_scorefxn = ScoreFunctionOP( new SymmetricScoreFunction( in_scorefxn ) );
161  TR<<"symmetrizing "<<scorefxn_name<<'\n';
162  }
163 
164  // auto-generate and set cache-tags for bound and unbound energy states, if PB term is used.
165  if( !in_scorefxn->has_zero_weight(PB_elec) ) {
166 
167  core::scoring::methods::EnergyMethodOptions emoptions( in_scorefxn->energy_method_options() );
168  // Don't overwrite if it's already set, by "Set" modifier.
169  if( emoptions.pb_bound_tag() == "" ){
170  //std::string bound_tag = scorefxn_name + "_" + "bound";
171  emoptions.pb_bound_tag( "bound" );
172  }
173  if( emoptions.pb_unbound_tag() == "" ){
174  //std::string unbound_tag = scorefxn_name + "_" + "unbound";
175  emoptions.pb_unbound_tag( "unbound" );
176  }
177  in_scorefxn->set_energy_method_options( emoptions );
178  }
179 
180  data.add( "scorefxns" , scorefxn_name, in_scorefxn );
181  }//end user-defined scorefxns
182  TR.flush();
183 }
184 
187 
189 ScoreFunctionLoaderCreator::keyname() const { return "SCOREFXNS"; }
190 
191 
192 } //namespace parser
193 } //namespace jd2
194 } //namespace protocols