Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
SymAtomTreeMinimizer.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 // This file is part of the Rosetta software suite and is made available under license.
5 // The Rosetta software is developed by the contributing members of the Rosetta Commons consortium.
6 // (C) 199x-2009 Rosetta Commons participating institutions and developers.
7 // For more information, see http://www.rosettacommons.org/.
8 
9 /// @file core/optimization/symmetry/SymAtomTreeMinimizer.cc
10 /// @brief High-level atom tree minimizer class for symmetrical minimization
11 /// @author Ingemar Andre
12 
13 // Unit headers
15 
16 // Symmetry headers
17 // AUTO-REMOVED #include <core/pose/symmetry/util.hh>
19 
20 
21 // Package headers
25 // AUTO-REMOVED #include <core/optimization/MinimizerMap.hh>
28 
30 
31 // Project headers
32 #include <core/id/DOF_ID.hh>
35 #include <core/scoring/Energies.hh>
37 
38 #include <basic/Tracer.hh>
39 
40 #include <ObjexxFCL/format.hh>
41 
42 //Auto Headers
45 #include <core/pose/Pose.hh>
46 #include <utility/vector1.hh>
47 
48 
49 using namespace ObjexxFCL::fmt;
50 
51 namespace core {
52 namespace optimization {
53 namespace symmetry {
54 
55 ///////////////////////////////////////////////////////////////////////////////
56 Real
58  pose::Pose & pose,
59  kinematics::MoveMap const & move_map,
60  scoring::ScoreFunction const & scorefxn,
61  MinimizerOptions const & options
62 )
63 {
64  using namespace core::conformation::symmetry;
65 
66  typedef SymmetryInfo::DOF_IDs DOF_IDs;
67 
68  bool const use_nblist( options.use_nblist() );
69 
70  // it's important that the structure be scored prior to nblist setup
71  Real const start_score( scorefxn( pose ) );
72 
73  kinematics::MoveMap semisym_move_map;
74  make_semisymmetric_movemap( pose, move_map, semisym_move_map );
75 
76  SymmetricConformation const & symm_conf ( dynamic_cast<SymmetricConformation const &> ( pose.conformation()) );
77  assert( conformation::symmetry::is_symmetric( symm_conf ) );
78  SymmetryInfoCOP symm_info( symm_conf.Symmetry_Info() );
79 
80  // setup the minimizer map using the semi-symetric min map
81  SymMinimizerMap sym_min_map( pose, semisym_move_map, symm_info );
82  //kinematics::DomainMap const & dm( sym_min_map.domain_map() );
83  //for ( Size ii = 1; ii <= pose.total_residue(); ++ii ) {
84  // std::cout << "(" << ii << ", " << dm(ii) << "), ";
85  // if ( ii % 10 == 0 ) std::cout << std::endl;
86  //}
87  //std::cout << std::endl;
88 
89  // if we are using the nblist, set it up
90  if ( use_nblist ) {
91  // setup a mask of the moving dofs
92  pose.energies().set_use_nblist( pose, sym_min_map.domain_map(), options.nblist_auto_update() );
93  }
94 
95  // etable functions must be initialized with asymm domain map
96  scorefxn.setup_for_minimizing( pose, sym_min_map );
97 
98  // setup the function that we will pass to the low-level minimizer
99  SymAtomTreeMultifunc f( pose, sym_min_map, scorefxn,
100  options.deriv_check(), options.deriv_check_verbose() );
101 
102  // starting position -- "dofs" = Degrees Of Freedom
103  Multivec dofs( sym_min_map.nangles() );
104  sym_min_map.copy_dofs_from_pose( pose, dofs );
105 
106  Real const start_func( f( dofs ) );
107 
108  // std::cout << "Start score: " << start_score << " start_func " << start_func << std::endl;
109  // APL Note: there might be a discrepancy between start_score and start_func if bb/bb hydrogen bonds
110  // are being used. Why? Well, during minimization, bb/bb hbonds are calculated in the residue_pair_energy_ext
111  // calls, but in regular scoring, bb/bb hbonds are calculated in setup_for_scoring. This means that
112  // bb/bb hbond energies are not stored in the EnergyGraph. Hbonding residue pairs that are not moving wrt
113  // each other are not rescored during minimization, so their energies would be stored in the "fixed_energies_"
114  // EnergyMap in the MinimizationGraph -- except for the fact that this EnergyMap is filled using energies
115  // stored in the EnergyGraph, and the bb/bb hbond energies are not stored there.
116  // The delta between start_score and start_func is not worrisome, however, because these energies are constant.
117  // The delta has no impact on the minimizer's behavior.
118 
119  // now do the optimization with the low-level minimizer function
120  Minimizer minimizer( f, options );
121  minimizer.run( dofs );
122 
123  Real const end_func( f( dofs ) );
124 
125  //std::cout << "end_func:" << std::endl;
126  //pose.energies().show( std::cout );
127 
128  // turn off nblist
129  if ( use_nblist ) pose.energies().reset_nblist();
130 
131  // if we were doing rigid-body minimization, fold the rotation and
132  // translation offsets into the jump transforms
133  //
134  // also sets rb dofs to 0.0, so in principle func value should be the same
135  //
136  sym_min_map.reset_jump_rb_deltas( pose, dofs );
137 
138  // rescore
139  Real const end_score( scorefxn( pose ) );
140 
141  //std::cout << "end_score:" << std::endl;
142  //pose.energies().show( std::cout );
143 
144  // we may not really need all these extra function evaluations
145  // good for diagnostics though
146 
147  static basic::Tracer core_optimize( "core.optimize", basic::t_debug);
148  core_optimize << "SymAtomTreeMinimizer::run: nangles= " << sym_min_map.nangles() <<
149  " start_score: " << F(12,3,start_score) <<
150  " start_func: " << F(12,3,start_func ) <<
151  " end_score: " << F(12,3,end_score ) <<
152  " end_func: " << F(12,3,end_func ) << std::endl;
153 
154 
155  return end_score;
156 }
157 
158 void
159 SymAtomTreeMinimizer::make_semisymmetric_movemap(
160  pose::Pose & pose,
161  kinematics::MoveMap const & move_map_sym,
162  kinematics::MoveMap & move_map_semisym
163 )
164 {
165  using namespace core::conformation::symmetry;
166  typedef SymmetryInfo::DOF_IDs DOF_IDs;
167 
168  SymmetricConformation const & SymmConf (
169  dynamic_cast<SymmetricConformation const &> ( pose.conformation()) );
170  assert( conformation::symmetry::is_symmetric( SymmConf ) );
171  SymmetryInfoCOP symm_info( SymmConf.Symmetry_Info() );
172 
173  // copy bb/chi DOFs from symm movemap
174  move_map_semisym = move_map_sym;
175 
176  for ( Size i=1; i<= pose.conformation().fold_tree().num_jump(); ++i ) {
177  id::DOF_ID const & null_id
179  if ( symm_info->get_dof_derivative_weight( null_id , SymmConf ) > 0 ) {
180  // if this is not the master get the master
181  if ( symm_info->jump_is_independent( i ) ) continue;
182 
183  Size master_i = symm_info->jump_follows( i );
184 
185  for ( int j=1; j<= 6; ++j ) {
186  id::DOF_ID const & id_master
188  id::DOF_ID const & id
190 
191  bool allow ( move_map_sym.get( id_master ) );
192  move_map_semisym.set(id, allow );
193  }
194  }
195  }
196 
197 }
198 
199 
200 void
201 SymAtomTreeMinimizer::make_assymetric_movemap(
202  pose::Pose & pose,
203  kinematics::MoveMap const & move_map_sym,
204  kinematics::MoveMap & move_map_asym
205 )
206 {
207  using namespace core::conformation::symmetry;
208  typedef SymmetryInfo::DOF_IDs DOF_IDs;
209 
210  SymmetricConformation const & SymmConf (
211  dynamic_cast<SymmetricConformation const &> ( pose.conformation()) );
212  assert( conformation::symmetry::is_symmetric( SymmConf ) );
213  SymmetryInfoCOP symm_info( SymmConf.Symmetry_Info() );
214 
215  for ( Size i=1; i<= pose.conformation().size(); ++i ) {
216  if ( symm_info->bb_is_independent( i ) ) {
217  bool bb ( move_map_sym.get_bb(i) );
218  bool chi ( move_map_sym.get_chi(i) );
219  move_map_asym.set_bb ( i, bb );
220  move_map_asym.set_chi( i, chi );
221  for ( std::vector< Size>::const_iterator
222  clone = symm_info->bb_clones( i ).begin(),
223  clone_end = symm_info->bb_clones( i ).end();
224  clone != clone_end; ++clone ){
225  move_map_asym.set_bb ( *clone, bb );
226  move_map_asym.set_chi( *clone, chi );
227  }
228  }
229  }
230  for ( Size i=1; i<= pose.conformation().fold_tree().num_jump(); ++i ) {
231  if ( symm_info->jump_is_independent( i ) ) {
232  for ( int j=1; j<= 6; ++j ) {
233  id::DOF_ID const & id
235  DOF_IDs const & dofs( symm_info->dependent_dofs( id, SymmConf ) );
236  bool allow ( move_map_sym.get( id ) );
237  move_map_asym.set(id, allow );
238  for ( DOF_IDs::const_iterator dof =dofs.begin(), dofe= dofs.end(); dof != dofe; ++dof ) {
239  move_map_asym.set( *dof, allow );
240  }
241  }
242  }
243  }
244 }
245 
246 } // symmetry
247 } // namespace optimization
248 } // namespace core