Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
CartSCMinMinimizerMap.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/scmin/CartSCMinMinimizerMap.cc
11 /// @brief Class for identifying the sidechain DOFs in the AtomTree which are free during
12 /// any particular call to the minimizer.
13 /// @author Andrew Leaver-Fay (aleaverfay@gmail.com)
14 
15 
16 // Unit headers
18 
19 // Project Headers
20 #include <core/types.hh>
25 
26 // Utility headers
27 #include <utility/vector1.hh>
28 #include <utility/pointer/ReferenceCount.hh>
29 
31 #include <utility/options/BooleanVectorOption.hh>
32 #include <numeric/constants.hh>
33 
34 namespace core {
35 namespace pack {
36 namespace scmin {
37 
38 optimization::DOF_NodeOP dummy_nodeop(new optimization::DOF_Node(id::DOF_ID(),NULL));
39 
40 
43  nactive_moving_atoms_total_(0)
44 {
45  // try to avoid reallocations by making this vector big enough for all AAs
46  residue_coord_workspace_.reserve(40);
47 }
48 
50 
52 {
55 
56  atcs_for_residues_.resize( total_residue );
57  active_residues_.resize( total_residue );
58  active_residue_index_for_res_.resize( total_residue );
59  moving_atoms_.resize( total_residue );
60  nactive_moving_atoms_.resize( total_residue );
61  atom_derivatives_.resize( total_residue );
62 
63  atoms_to_dofid_.resize( total_residue );
64  dofid_to_atoms_.resize( total_residue ); // guess ... will grow as needed
65 
66  domain_map_.dimension( total_residue );
67 
68  std::fill( active_residues_.begin(), active_residues_.end(), 0 );
69  std::fill( active_residue_index_for_res_.begin(), active_residue_index_for_res_.end(), 0 );
70 
71  for ( Size ii = 1; ii <= domain_map_.size(); ++ii ) domain_map_( ii ) = 1;
72 }
73 
74 /// @brief Disable the minimization for all residues. Ammortized O(1).
76 {
77  for ( Size ii = 1; ii <= nactive_residues_; ++ii ) {
78  domain_map_( active_residues_[ ii ] ) = 1;
80  active_residue_index_for_res_[ active_residues_[ ii ] ] = 0;
81  active_residues_[ ii ] = 0;
82  }
85 }
86 
87 /// @details This should be called at most once per residue between calls to "clear_active_chi"
89 {
90  assert( domain_map_( resindex ) == 1 ); // activate_residue_chi should not have already been called.
91  assert( active_residue_index_for_res_[ resindex ] == 0 ); // activate_residue_chi should not have already been called.
92 
93  domain_map_( resindex ) = 0;
94  active_residues_[ ++nactive_residues_ ] = resindex;
96 
97 }
98 
99 /// @brief Convenience lookup -- turns over the request to the AtomTreeCollection
100 conformation::Residue const &
102 {
103  return atcs_for_residues_[ seqpos ]->active_residue();
104 }
105 
107 CartSCMinMinimizerMap::atom( AtomID const & atid ) const
108 {
109  return atcs_for_residues_[ atid.rsd() ]->active_atom_tree().atom( id::AtomID( atid.atomno(), 1 ) );
110 }
111 
112 
114 {
115  if ( atom_derivatives_[ resid ].size() < natoms ) {
116  atom_derivatives_[ resid ].resize( natoms );
117  }
118 }
119 
120 /// @brief Invoked during the depth-first traversal through the AtomTree. The AtomTree
121 /// is indicating that a particular torsion is dependent on another torsion. Record
122 /// that fact.
123 void
125  DOF_ID const & /*new_torsion*/,
126  DOF_ID const & /*parent*/
127 )
128 {
129  ; // no op
130 }
131 
132 /// @brief Invoked during the depth-first traversal through the AtomTree; the atom
133 /// tree is indicating that a given atom is controlled by a particular DOF. Record
134 /// that fact.
135 void
137  AtomID const & /*atom_id*/,
138  DOF_ID const & /*dof_id*/
139 )
140 {
141  ; // no op
142  }
143 
144 /// @brief Traverse the atom trees in preparation for minimization to tie together all the
145 /// DOFs and the atoms they control.
146 void
148 {
149  reset_dof_nodes();
150  atom_tree_collection_ = trees;
151 
152  for ( Size ii = 1; ii <= nactive_residues_; ++ii ) {
153  Size iiresid = active_residues_[ ii ];
154  atcs_for_residues_[ iiresid ] = trees->residue_atomtree_collection_op( iiresid );
155 
156  focused_residue_ = iiresid;
157  conformation::Residue const & iires( atcs_for_residues_[ iiresid ]->active_residue() );
158 
159 
160  /////////////////////
161  // (1) cartesian dofs ...
162  int stop1 = (int)iires.nheavyatoms();
163  int start1 = std::min( (int)iires.first_sidechain_atom(), stop1+1 );
164  int start2 = (int)iires.first_sidechain_hydrogen();
165  int stop2 = (int)iires.natoms();
166  int natoms_to_add = (stop1-start1+1)+(stop2-start2+1);
167 
168  if ((int)moving_atoms_[iiresid].size() < natoms_to_add) {
169  moving_atoms_[iiresid].resize(natoms_to_add, id::AtomID( 0,0 ));
170  }
171  if ((int)dofid_to_atoms_.size() < (int)(nactive_moving_atoms_total_+natoms_to_add)) {
172  dofid_to_atoms_.resize( nactive_moving_atoms_total_+natoms_to_add );
173  }
174  if (atoms_to_dofid_[iiresid].size() < iires.natoms()) {
175  atoms_to_dofid_[iiresid].resize( iires.natoms() );
176  }
177 
178  for ( int jj=start1; jj<=stop1; ++jj ) {
179  ++nactive_moving_atoms_[iiresid];
181  moving_atoms_[iiresid][nactive_moving_atoms_[iiresid]] = id::AtomID( jj,iiresid );
184  }
185  for ( int jj=start2; jj<=stop2; ++jj ) {
186  ++nactive_moving_atoms_[iiresid];
188  moving_atoms_[iiresid][nactive_moving_atoms_[iiresid]] = id::AtomID( jj,iiresid );
191  }
192  }
193 }
194 
195 void
197 {
198  dof.resize(3*nactive_moving_atoms_total_);
199 
200  Size ctr = 0;
201  for ( Size ii = 1; ii <= nactive_residues_; ++ii ) {
202  Size iiresid = active_residues_[ ii ];
203  conformation::Residue const & iires( atcs_for_residues_[ iiresid ]->active_residue() );
204  core::Size nmoving_atoms_ii = moving_atoms_[iiresid].size();
205  for ( Size jj = 1; jj <= nmoving_atoms_ii; ++jj ) {
206  Vector const &jjxyz = iires.xyz(moving_atoms_[iiresid][jj].atomno());
207  dof[++ctr] = jjxyz[0];
208  dof[++ctr] = jjxyz[1];
209  dof[++ctr] = jjxyz[2];
210  }
211  }
212 
213  assert ( ctr == dof.size() );
214 }
215 
216 void
218 {
219  assert( dofs.size() == 3*nactive_moving_atoms_total_ );
220 
221  Size ctr = 0;
222  for ( Size ii = 1; ii <= nactive_residues_; ++ii ) {
223  Size iiresid = active_residues_[ ii ];
224  //conformation::Residue const & iires( atcs_for_residues_[ iiresid ]->active_residue() );
225  core::Size nmoving_atoms_ii = moving_atoms_[iiresid].size();
226  residue_coord_workspace_.resize(nmoving_atoms_ii); // potentially a reallocation
227  for ( Size jj = 1; jj <= nmoving_atoms_ii; ++jj ) {
228  residue_coord_workspace_[jj][0] = dofs[++ctr];
229  residue_coord_workspace_[jj][1] = dofs[++ctr];
230  residue_coord_workspace_[jj][2] = dofs[++ctr];
231  }
232  atcs_for_residues_[ iiresid ]->set_rescoords( moving_atoms_[iiresid] , residue_coord_workspace_ );
233  }
234 
235  //fpd -- set_rescoords() calls update_residue()
236  //for ( Size ii = 1; ii <= nactive_residues_; ++ii ) {
237  // atcs_for_residues_[ active_residues_[ ii ] ]->update_residue();
238  //}
239 }
240 
243  return (*dummy_nodeop); // dummy
244 }
245 
247 CartSCMinMinimizerMap::dof_node_for_chi( Size /*resid*/, Size /*chiid*/ ) const
248 {
249  return (*dummy_nodeop); // dummy
250 }
251 
254 {
255  if (dofid.type() != core::id::PHI) return core::id::BOGUS_TORSION_ID;
256 
257  Size const rsd( dofid.rsd() );
258  Size const chi( residue( rsd ).type().last_controlling_chi( dofid.atomno() ) );
259  id::TorsionID torid( rsd, id::CHI, chi );
260  return torid;
261 }
262 
264 {
265  ; // no op
266 }
267 
269 {
270  for ( Size ii = 1; ii <= nactive_residues_; ++ii ) {
271  Size iiresid = active_residues_[ ii ];
272  for ( Size jj = 1, jjend = atom_derivatives_[ iiresid ].size(); jj <= jjend; ++jj ) {
273  atom_derivatives_[ iiresid ][ jj ].f1() = 0.0;
274  atom_derivatives_[ iiresid ][ jj ].f2() = 0.0;
275  }
276  }
277 }
278 
280 {
281  for ( Size ii = 1; ii <= nactive_residues_; ++ii ) {
282  Size iiresid = active_residues_[ ii ];
283  nactive_moving_atoms_[iiresid] = 0;
284  }
286 }
287 
288 
289 
290 } // namespace scmin
291 } // namespace pack
292 } // namespace core
293