Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
DebuggingAnnealer.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 core/pack/annealer/DebuggingAnnealer.cc
11 /// @brief Debugging annealer class implementation
12 /// @author Andrew Leaver-Fay (aleaverfay@gmail.com)
13 
14 // Unit Headers
16 
17 // Package Headers
19 
20 // Rosetta Headers
21 //#include "after_opts.h"
22 //#include "DebuggingAnnealer.h"
23 //#include "InteractionGraphBase.h"
24 //#include "param.h"
25 //#include "random_numbers.h"
26 //#include "RotamerSet.h"
27 
28 #include <ObjexxFCL/Fmath.hh>
29 
30 #include <fstream>
31 #include <istream>
32 #include <iostream>
33 
34 namespace core{
35 namespace pack{
36 namespace annealer{
37 
38 ////////////////////////////////////////////////////////////////////////////////
39 /// @begin DebuggingAnnealer::DebuggingAnnealer()
40 ///
41 /// @brief
42 /// constructor
43 ///
44 /// @detailed
45 ///
46 /// @global_read
47 ///
48 /// @global_write
49 ///
50 /// @remarks
51 ///
52 /// @references
53 ///
54 /// @authors
55 ///
56 /// @last_modified
57 
58 ////////////////////////////////////////////////////////////////////////////////
60  utility::vector0< int > & rot_to_pack,
61  FArray1D_int & bestrotamer_at_seqpos,
62  float & bestenergy,
63  bool start_with_current, // start simulation with current rotamers
64  pack::InteractionGraphBase * ig,
65  const RotamerSet * p_rotamer_set,
66  FArray1_int & current_rot_index,
67  bool calc_rot_freq,
68  FArray1D_float & rot_freq
69 ):
70  RotamerAssigningAnnealer(
71  rot_to_pack,
72  (int) rot_to_pack.size(),
73  bestrotamer_at_seqpos,
74  bestenergy,
75  start_with_current, // start simulation with current rotamers
76  p_rotamer_set,
77  current_rot_index,
78  calc_rot_freq,
79  rot_freq
80  ), ig_(ig)
81 {
82 }
83 
85  FArray1D_int & bestrotamer_at_seqpos,
86  float & bestenergy,
87  bool start_with_current, // start simulation with current rotamers
88  pack::InteractionGraphBase * ig,
89  const RotamerSet * p_rotamer_set,
90  FArray1_int & current_rot_index,
91  bool calc_rot_freq,
92  FArray1D_float & rot_freq
93 ):
94  RotamerAssigningAnnealer(
95  (ig->get_num_total_states()),
96  bestrotamer_at_seqpos,
97  bestenergy,
98  start_with_current, // start simulation with current rotamers
99  p_rotamer_set,
100  current_rot_index,
101  calc_rot_freq,
102  rot_freq
103  ), ig_(ig)
104 {
105 }
106 
107 ////////////////////////////////////////////////////////////////////////////////
108 /// @begin DebuggingAnnealer::~DebuggingAnnealer()
109 ///
110 /// @brief
111 /// virtual destructor
112 ///
113 /// @detailed
114 ///
115 /// @global_read
116 ///
117 /// @global_write
118 ///
119 /// @remarks
120 ///
121 /// @references
122 ///
123 /// @authors
124 ///
125 /// @last_modified
126 ////////////////////////////////////////////////////////////////////////////////
128 {}
129 
130 ////////////////////////////////////////////////////////////////////////////////
131 /// @begin FixbbSimAnnealer::run
132 ///
133 /// @brief
134 /// sim_annealing for fixed backbone design mode
135 ///
136 /// @detailed
137 ///
138 /// @global_read
139 ///
140 /// @global_write
141 ///
142 /// @remarks
143 ///
144 /// @references
145 ///
146 /// @authors
147 ///
148 /// @last_modified
149 ////////////////////////////////////////////////////////////////////////////////
151 {
152  using namespace param;
153 
154  //--------------------------------------------------------------------
155  //internal variables
156 
157  int const nmoltenres = ig_->get_num_nodes();
158  float currentenergy;
159  //FArray1D_int list( p_rotamer_set_->nrotamers() );
160  //FArray1D_int state_on_node( nmoltenres,0 );
161  FArray1D_int best_state_on_node( nmoltenres,0 );
162  FArray1D_int current_state( nmoltenres, 0 );
163  //FArray1D_float loopenergy(maxouteriterations,0.0);
164 
165  //kwk internal rot_index expanded to handled non amino acid molten residues
166  //kwk rot_to_moltenres(1,X)=moltenres_id
167  //kwk rot_to_moltenres(2,X)=moltenres_state
168  FArray2D_int rot_2_moltenres( 2,ig_->get_num_total_states(),0);
169 
170  //bk variables for calculating rotamer frequencies during simulation
171  //int nsteps = 0;
172 
173  //--------------------------------------------------------------------
174  //initialize variables
175 
176  currentenergy = 0.0;
177 
178  ig_->prepare_for_simulated_annealing();
179  ig_->blanket_assign_state_0();
180 
181  int rot_tmp=1;
182  for( int ii =1; ii<=nmoltenres; ++ii){
183  for(int jj =1; jj<=ig_->get_num_states_for_node( ii); ++jj){
184  rot_2_moltenres(1,rot_tmp)=ii;
185  rot_2_moltenres(2,rot_tmp)=jj;
186  rot_tmp++;
187  }
188  }
189 
190  //--------------------------------------------------------------------
191  if ( num_of_rot_to_pack_ == 0 ) return;
192 
194 
195  FArray1D_float previous_nsteps_for_rot(p_rotamer_set_->nrotamers(), 0.0);
196 
197  //int outeriterations = get_outeriterations();
198 
199  std::string annealer_file( stringafteroption( "db_annealer_file" ));
200  std::ifstream instructions( annealer_file.c_str() );
201 
202  while ( instructions )
203  {
204  int node_to_change;
205  instructions >> node_to_change;
206 
207  if ( node_to_change <= 0 || node_to_change > nmoltenres )
208  {
209  std::cerr << "Error in instructions for Debugging Annealer: node_to_change out of range." << std::endl;
210  std::cerr << "Requires 0 < node_in_range <= nmoltenres. nmoltenres: " << nmoltenres << " node_to_change: " << node_to_change << std::endl;
211  return;
212  }
213 
214  int new_state_for_node;
215  instructions >> new_state_for_node;
216 
217  if ( new_state_for_node <= 0 || new_state_for_node > ig_->get_num_states_for_node( node_to_change ) )
218  {
219  std::cerr << "Error in instructions for Debugging Annealer: new_state_for_node out of range." << std::endl;
220  std::cerr << "Requires 0 < new_state_for_node <= num_states_for_node( " << node_to_change << ");" << std::endl;
221  std::cerr << "new_state_for_node: " << new_state_for_node << " num_states_for_node( " << node_to_change << "): ";
222  std::cerr << ig_->get_num_states_for_node( node_to_change ) << std::endl;
223  return;
224  }
225 
226  char decision;
227  instructions >> decision;
228 
229  if ( decision != 'A' && decision != 'R' && decision != 'M' )
230  {
231  std::cerr << "Error in instructions for Debugging Annealer: invalid decision" << std::endl;
232  std::cerr << "Requires decision to be either 'A', or 'R' (for accept or reject)" << std::endl;
233  std::cerr << "decision: " << decision << std::endl;
234  return;
235  }
236 
237  float deltaE( 0.0f ), previous_energy_for_node( 0.0f );
238  ig_->consider_substitution( node_to_change, new_state_for_node, deltaE, previous_energy_for_node );
239 
240  std::cout << "mres: " << node_to_change << ", state: ";
241  std::cout << new_state_for_node << ", deltaE: " << deltaE << std::endl;
242 
243 
244  if ( decision == 'A' )
245  {
246  ig_->commit_considered_substitution();
247  current_state( node_to_change ) = new_state_for_node;
248  }
249 
250  }
251 
252  best_state_on_node = current_state;
253 
254  //convert best_state_on_node into best_rotamer_at_seqpos
255  for (int ii = 1;ii <= nmoltenres; ++ii){
256  int iiresid = p_rotamer_set_->moltenres_2_resid(ii);
257  bestrotamer_at_seqpos_(iiresid) = best_state_on_node(ii) + p_rotamer_set_->rotindex_offsets(iiresid);
258  }
259 
260 }
261 
262 }//end namespace annealer
263 }//end namespace pack
264 }//end namespace core