Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ConformerSwitchMover.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 ConformerSwitchMover.cc
11 /// @brief code for the conformer switch mover in ensemble docking
12 /// @author Sid Chaudhury
13 /// @author Modified by Daisuke Kuroda
14 
15 
18 
19 // Rosetta Headers
20 #include <basic/datacache/CacheableStringFloatMap.hh>
21 // AUTO-REMOVED #include <core/io/pdb/pose_io.hh>
22 #include <core/id/types.hh>
24 #include <core/pose/Pose.hh>
25 #include <core/pose/util.hh>
26 // AUTO-REMOVED #include <core/scoring/Energies.hh>
27 #include <core/scoring/rms_util.hh>
30 #include <core/types.hh>
31 
36 
37 
38 // Random number generator
39 #include <numeric/random/random.hh>
40 //
41 #include <string>
42 
43 #include <basic/Tracer.hh>
44 
45 // AUTO-REMOVED #include <utility/io/izstream.hh>
46 
48 #include <utility/vector0.hh>
49 #include <utility/vector1.hh>
50 #include <basic/datacache/BasicDataCache.hh>
51 
52 //Auto Headers
53 #include <core/pose/util.tmpl.hh>
54 using basic::T;
55 using basic::Error;
56 using basic::Warning;
57 
58 static numeric::random::RandomGenerator RG(38627226);
59 
60 static basic::Tracer TR("protocols.docking.ConformerSwitchMover");
61 
62 namespace protocols {
63 namespace docking {
64 
65 
67  moves::Mover(),
68  random_conformer_(false),
69  temperature_(0.8)
70 {
71  moves::Mover::type( "ConformerSwitchMover" );
72 }
73 
74 
77 {
79 }
80 
83  return new ConformerSwitchMover;
84 }
85 
88 {
89  return "ConformerSwitchMover";
90 }
91 
92 //constructor with arguments
95  bool random_conformer
96 ) :
97  moves::Mover(),
98  random_conformer_( random_conformer ),
99  temperature_(0.8)
100 {
101  ensemble_ = ensemble;
102 
104 }
105 
107 {
108  temperature_ = temp_in;
109 }
110 
112 {
113  using namespace core::pose::datacache;
114  core::Size conf_num = 1;
115 
116  (*(ensemble_->scorefxn_low()))(pose);
117 
118  // the conformer used can either be random, or generated from the probability table of energies of the conformers
119  // to use a random conformer, random_conformer must be set to true
120  if ( !random_conformer_ && lowres_filter_->apply( pose ) ){ //only calculate partition function if filters are passed
121  GenerateProbTable( pose );
122  core::Real rand_num( RG.uniform() );
123  for (Size i = 1; i <= ensemble_->size(); i++){
124  if( (rand_num >= prob_table_[i]) ) conf_num++;
125  }
126  } else {
127  conf_num = RG.random_range( 1, ensemble_->size() );
128  }
129 
130  TR << "Switching partner with conformer: " << conf_num << std::endl;
131 
132  switch_conformer( pose, conf_num );
133  ensemble_->set_current_confnum( conf_num );
134 
135  // make sure that the pose has ARBITRARY_FLOAT_DATA in the DataCache
136  if ( !pose.data().has( ( CacheableDataType::ARBITRARY_FLOAT_DATA ) ) ){
137  pose.data().set(
138  CacheableDataType::ARBITRARY_FLOAT_DATA,
139  new basic::datacache::CacheableStringFloatMap()
140  );
141  }
142 
143  basic::datacache::CacheableStringFloatMap *data
144  = dynamic_cast< basic::datacache::CacheableStringFloatMap* >
145  ( pose.data().get_raw_ptr(CacheableDataType::ARBITRARY_FLOAT_DATA) );
146 
147  data->map()[ ensemble_->partner() ] = ensemble_->lowres_reference_energy(conf_num);
149 }
150 
152 {
153 
154  core::pose::Pose complex_pose = pose;
156  core::Real partition_sum(0.0);
157 
158  prob_table_.clear();
159 
160  for( core::Size i = 1; i <= ensemble_->size(); i++){
161  switch_conformer( complex_pose, i );
162  // the score takes the reference energy into consideration
163  core::Real complex_score = (*(ensemble_->scorefxn_low()))(complex_pose) - ensemble_->lowres_reference_energy(i);
164  complex_pose = pose;
165  e_table.push_back( complex_score );
166  }
167 
168  core::Real min_energy(0.0);
169  for ( core::Size i = 1; i <= ensemble_->size(); i++){
170  if (e_table[i] <= min_energy) min_energy = e_table[i];
171  }
172 
173  for ( core::Size i = 1; i <= ensemble_->size(); i++){
174  e_table[i] = std::exp((-1*(e_table[i] - min_energy))/temperature_);
175  partition_sum += e_table[i];
176  }
177 
178  prob_table_.push_back( e_table[1]/partition_sum );
179  for (core::Size i = 2; i <=ensemble_->size(); i++){
180  prob_table_.push_back( prob_table_[i-1] + (e_table[i]/partition_sum) );
181  }
182 
183 }
184 
186  core::pose::Pose & pose,
187  core::Size conf_num
188  )
189 {
190  core::pose::Pose new_conf = ensemble_->get_conformer_cen(conf_num); // new_conf is centroid
191 
192  (*(ensemble_->scorefxn_low()))(pose);
193  scoring::Interface interface( ensemble_->jump_id() );
194 
195  interface.calculate( pose );
196 
197  utility::vector1<Size>conf_interface;
198  for (Size i = ensemble_->start_res(); i <= ensemble_->end_res(); i++){
199  if (interface.is_interface(i)) conf_interface.push_back( i );
200  }
201 
202  if (conf_interface.size() <= 5){
203  conf_interface.clear();
204  for (Size i = ensemble_->start_res(); i <= ensemble_->end_res(); i++){
205  conf_interface.push_back( i );
206  }
207  }
208 
210  core::pose::initialize_atomid_map( atom_map, new_conf, core::id::BOGUS_ATOM_ID ); // maps every atomid to bogus
211 
212  for (Size i = 1; i <= conf_interface.size(); i++){
213  Size new_conf_resnum = conf_interface[i]-ensemble_->start_res()+1;
214  Size pose_resnum = conf_interface[i];
215  core::id::AtomID const id1( new_conf.residue(new_conf_resnum).atom_index("CA"), new_conf_resnum );
216  core::id::AtomID const id2( pose.residue(pose_resnum).atom_index("CA"), pose_resnum );
217  atom_map[ id1 ] = id2;
218  }
219 
220  core::scoring::superimpose_pose( new_conf, pose, atom_map );
221  pose.copy_segment( ensemble_->conf_size(), new_conf, ensemble_->start_res(), 1);
222 }
223 
226 }
227 
228 std::ostream &operator<< (std::ostream &os, ConformerSwitchMover const &mover)
229 {
230  moves::operator<<(os, mover);
231  os << "Temperature: " << mover.get_temperature() << std::endl <<
232  "Use random conformer?: " << (mover.use_random_conformer() ? "True" : "False") << std::endl;
233  return os;
234 }
235 
236 } // namespace docking
237 
238 } // namespace protocols