Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
MinimizerMap.cc
Go to the documentation of this file.
1 
2 // -*- mode:c++;tab-width:2;indent-tabs-mode:t;show-trailing-whitespace:t;rm-trailing-spaces:t -*-
3 // vi: set ts=2 noet:
4 //
5 // (c) Copyright Rosetta Commons Member Institutions.
6 // (c) This file is part of the Rosetta software suite and is made available under license.
7 // (c) The Rosetta software is developed by the contributing members of the Rosetta Commons.
8 // (c) For more information, see http://www.rosettacommons.org. Questions about this can be
9 // (c) addressed to University of Washington UW TechTransfer, email: license@u.washington.edu.
10 
11 /// @file core/kinematics/min.cc
12 /// @brief Kinematics
13 /// @author Phil Bradley
14 
15 // Unit headers
17 
18 
19 // Project headers
20 #include <core/pose/util.hh>
21 // AUTO-REMOVED #include <core/kinematics/MoveMap.hh>
22 // AUTO-REMOVED #include <core/id/DOF_ID_Mask.hh>
23 #include <core/pose/Pose.hh>
24 
25 // Numeric headers
26 // #include <numeric/all.fwd.hh>
27 // #include <numeric/constants.hh>
28 #include <numeric/conversions.hh>
29 // #include <numeric/xyzMatrix.hh>
30 // #include <numeric/xyzVector.hh>
31 
32 // ObjexxFCL headers
33 // #include <ObjexxFCL/FArray1D.hh>
34 // #include <ObjexxFCL/FArray2D.hh>
35 // #include <ObjexxFCL/FArray3D.hh>
36 //#include <ObjexxFCL/FArray4D.h>
37 //#include <ObjexxFCL/formatted.io.h>
38 
39 // Utility headers
40 // #include <utility/exit.hh>
41 // #include <utility/io/orstream.hh>
42 
43 #include <basic/options/option.hh>
44 #include <basic/options/keys/optimization.OptionKeys.gen.hh>
45 
46 // C++ headers
47 #include <cstdlib>
48 
49 #include <utility/vector1.hh>
50 
51 //Auto Headers
52 #include <core/pose/util.tmpl.hh>
53 
54 
55 
56 namespace core {
57 namespace optimization {
58 
59 
60 
61 /////////////////////////////////////////////////////////////////////////////
63 {
65 }
66 
67 /////////////////////////////////////////////////////////////////////////////
68 // this will only work properly if the DOFs are sorted in decreasing
69 // depth
70 //
71 void
73 {
74  int last_depth = -1; // int depth( 100000 ); -- bad code buries assumptions deep deep into code where noone knows to find it
75  for ( iterator it=dof_nodes_.begin(),
76  it_end=dof_nodes_.end(); it != it_end; ++it ) {
77  DOF_Node & dof_node( **it );
78  assert( last_depth == -1 || dof_node.depth() <= last_depth );
79  last_depth = dof_node.depth();
80  dof_node.link_vectors();
81  }
82 }
83 
84 /////////////////////////////////////////////////////////////////////////////
85 void
87 {
88  for ( iterator iter=dof_nodes_.begin(), iter_end=dof_nodes_.end();
89  iter != iter_end; ++iter ) {
90  (*iter)->F1() = 0.0;
91  (*iter)->F2() = 0.0;
92  }
93  for ( Size ii = 1; ii <= atom_derivatives_.size(); ++ii ) {
94  for ( Size jj = 1; jj <= atom_derivatives_[ ii ].size(); ++jj ) {
95  atom_derivatives_[ ii ][ jj ].f1() = 0.0;
96  atom_derivatives_[ ii ][ jj ].f2() = 0.0;
97  }
98  }
99 }
100 
101 
102 
103 /////////////////////////////////////////////////////////////////////////////
104 
105 void
107  DOF_ID const & dof_id,
108  DOF_ID const & parent_id
109 )
110 {
111 
112  // assign the parent
114  if ( parent_id.valid() ) {
115  // not the root torsion
116  parent = dof_node_pointer_[ parent_id ];
117  if ( parent == 0 ) {
118  std::cerr << "parent torsion does not exist in map! torsion= " <<
119  dof_id << " parent= " << parent_id << std::endl;
120  utility_exit();
121  }
122  } else {
123  // root torsion!
124  parent = 0;
125  }
126 
127  DOF_NodeOP dof( new DOF_Node( dof_id, parent ) );
128  dof_node_pointer_[ dof_id ] = dof;
129  dof_nodes_.push_back( dof );
130 
131 }
132 
133 /////////////////////////////////////////////////////////////////////////////
134 void
136  AtomID const & atom_id,
137  DOF_ID const & dof_id
138 )
139 {
140  // add atom to list of atoms first moved by this torsion,
141  // unless we are in the root rigid body
142 
143  if ( dof_id.valid() ) {
144  DOF_NodeOP n( dof_node_pointer_[ dof_id ] );
145  if ( n == 0 ) {
146  std::cout << "torsion does not exist in map! torsion= " <<
147  dof_id << std::endl;
148  utility_exit();
149  }
150 
151  // add the atom to the torsion
152  n->add_atom( atom_id );
153  }
154 }
155 
156 /////////////////////////////////////////////////////////////////////////////
157 Real
159  DOF_Node const & dof_node
160 ) const
161 {
162  static Real const rad2deg( numeric::conversions::degrees(1.0) );
163  DOF_Type const type( dof_node.type() );
164  Real factor( 1.0 );
165  if ( type == id::PHI ) {
166  // bond torsion
167  factor = rad2deg;
168  } else if ( type == id::THETA ) {
169  // bond angle
170  factor = rad2deg * basic::options::option[ basic::options::OptionKeys::optimization::scale_theta ]();
171  } else if ( type == id::D ) {
172  // bond length
173  factor = basic::options::option[ basic::options::OptionKeys::optimization::scale_d ]();
174  } else if ( type == id::RB4 ||
175  type == id::RB5 ||
176  type == id::RB6 ) {
177  // the jump_rb_delta's are stored in degrees!!!
178  factor = basic::options::option[ basic::options::OptionKeys::optimization::scale_rbangle ]();
179  } else if ( type == id::RB1 ||
180  type == id::RB2 ||
181  type == id::RB3 ) {
182  // rigid body translation
183  factor = basic::options::option[ basic::options::OptionKeys::optimization::scale_rb ]();
184  }
185  return factor;
186 }
187 
188 /////////////////////////////////////////////////////////////////////////////
189 void
191 {
192  // delete old memory -- deprecated 7/1/2010 following DOF_Node's inherretance from ReferenceCount
193  //for ( iterator it=dof_nodes_.begin(), it_end = dof_nodes_.end();
194  // it != it_end; ++it ) {
195  // delete (*it);
196  //}
197 
198  dof_nodes_.clear();
199  dof_node_pointer_.clear(); // have to clear this map, too
200 }
201 
202 /////////////////////////////////////////////////////////////////////////////
203 void
205 {
206  clear_dof_nodes();
207 
208  // dimension the node_pointers to allow fast lookup
209  DOF_NodeOP tmp(0);
211  atom_derivatives_.resize( pose.total_residue() );
212  for ( Size ii = 1; ii <= pose.total_residue(); ++ii ) {
213  atom_derivatives_[ ii ].resize( pose.residue( ii ).natoms() );
214  }
215 }
216 
217 /////////////////////////////////////////////////////////////////////////////
218 void
220  pose::Pose const & pose,
221  Multivec & dofs
222 ) const
223 {
224  int imap = 1;
225  for ( const_iterator it=dof_nodes_.begin(), it_end = dof_nodes_.end();
226  it != it_end; ++it, ++imap ) {
227  DOF_Node const & dof_node( **it );
228  dofs[ imap ] = torsion_scale_factor( dof_node ) *
229  pose.dof( dof_node.dof_id() );
230  }
231 }
232 
233 
234 /////////////////////////////////////////////////////////////////////////////
235 void
237  pose::Pose & pose,
238  Multivec const & dofs
239 ) const
240 {
241  int imap = 1;
242  for ( const_iterator it=dof_nodes_.begin(), it_end = dof_nodes_.end();
243  it != it_end; ++it, ++imap ) {
244  DOF_Node const & dof_node( **it );
245  pose.set_dof( dof_node.dof_id(),
246  dofs[ imap ] / torsion_scale_factor( dof_node ));
247  }
248 }
249 
250 
251 /////////////////////////////////////////////////////////////////////////////
252 void
254  pose::Pose & pose,
255  Multivec & dofs
256 ) const
257 {
258  int imap = 1;
259  for ( const_iterator it=dof_nodes_.begin(), it_end = dof_nodes_.end();
260  it != it_end; ++it, ++imap ) {
261  DOF_Node const & dof_node( **it );
262  if ( DOF_type_is_rb( dof_node.type() ) ) {
263  // will do this multiple times for each jump, but should be OK
264  AtomID const & id( dof_node.atom_id() );
265  kinematics::Jump jump( pose.jump( id ) );
266  jump.fold_in_rb_deltas();
267  pose.set_jump( id, jump );
268  dofs[ imap ] = 0.0;
269  }
270  }
271 }
272 
273 /////////////////////////////////////////////////////////////////////////////
274 bool
276 {
277  return *a < *b;
278 }
279 
280 /////////////////////////////////////////////////////////////////////////////
281 
282 void
284  pose::Pose & pose,
285  kinematics::MoveMap const & move_map
286 )
287 {
288  // this clears dof_nodes_ and dimensions dof_node_pointer_
289  reset( pose );
290 
291  // convert the allow_bb,allow_chi,allow_jump information
292  // in the MoveMap into a simple boolean mask over AtomTree
293  // degrees of freedom
294  // this is necessary because the AtomTree doesn't know which degrees
295  // of freedom are chi angles, which are phi angles, etc
296  // the dof_mask is a low-level type of allow-move information
297  // that's used by the atomtree atoms inside Atom::setup_min_map
298  //
299  id::DOF_ID_Mask dof_mask( false );
300  pose::setup_dof_mask_from_move_map( move_map, pose, dof_mask );
301 
302  // this fills the torsion and atom lists
303  DOF_ID tmp( id::BOGUS_DOF_ID );
304  pose.atom_tree().root()->setup_min_map( tmp, dof_mask, *this );
305 
306  // sort DOFs for proper linking later on
307  dof_nodes_.sort( DOF_Node_sorter );
308 
309  // identify phi/psi/omega...
310  //
311  this->assign_rosetta_torsions( pose );
312 
313 
314  // setup the domain_map which indicates what rsd pairs are fixed/moving
315  id::AtomID_Mask moving_dof, moving_xyz;
316  core::pose::initialize_atomid_map( moving_xyz, pose, false );
317  core::pose::initialize_atomid_map( moving_dof, pose, false );
318  for ( const_iterator it = dof_nodes_.begin(), it_end = dof_nodes_.end();
319  it != it_end; ++it ) {
320  moving_dof[ (**it).atom_id() ] = true;
321  }
322 
323  domain_map_.dimension( pose.total_residue() );
325  ( domain_map_, moving_dof, moving_xyz );
326 }
327 
328 
329 /////////////////////////////////////////////////////////////////////////////
330 // private
331 void
333 {
334  // mapping from AtomTree DOF ID's to bb/chi torsion angle ids
337 
338  pose::setup_dof_to_torsion_map( pose, dof_map );
339 
340  for ( iterator it = dof_nodes_.begin(), it_end = dof_nodes_.end();
341  it != it_end; ++it ) {
342  DOF_Node & dof_node( **it );
343 
344  if ( dof_node.type() == id::PHI ) {
345  id::TorsionID const & id( dof_map[ dof_node.dof_id() ] );
346  if ( id.valid() ) {
347  dof_node.torsion_id( id );
348  }
349  }
350  }
351 }
352 
353 
354 } // namespace kinematics
355 } // namespace core