Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
pose_mod.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 protocols/forge/methods/pose_mod.cc
11 /// @brief methods for Pose modifications
12 /// @author Yih-En Andrew Ban (yab@u.washington.edu)
13 
14 // unit headers
16 
17 // project headers
20 #include <core/id/DOF_ID.hh>
22 #include <basic/options/option.hh>
23 #include <basic/options/keys/in.OptionKeys.gen.hh>
28 #include <core/scoring/Energies.hh>
31 #include <basic/Tracer.hh>
32 
33 // numeric headers
34 // AUTO-REMOVED #include <numeric/xyz.functions.hh>
35 
36 // C++ headers
37 #include <cmath>
38 #include <list>
39 #include <map>
40 
41 #include <utility/vector0.hh>
42 #include <utility/vector1.hh>
43 
44 
45 
46 namespace protocols {
47 namespace forge {
48 namespace methods {
49 
50 
51 static basic::Tracer TR( "protocols.forge.methods.pose_mod" );
52 
53 
54 /// @brief add cutpoint variants at a specific position
55 /// @param[in,out] Pose to modify
56 /// @param[in] position at which to add cutpoint variants
57 /// @return true if cutpoint variants added, false if position not a topological cutpoint
58 /// or cutpoint variants already exist
59 bool
61  core::pose::Pose & pose,
62  core::Size const pos
63 )
64 { // This function is implemented only because I don't want to
65  // waste time changing all the calls for the the existing function
66  // in protocols::loops code right now, which, for some reason, takes
67  // a Loop object instead of a residue position...
68  using core::Size;
72 
73  bool op_performed = false;
74 
75  if ( !pose.fold_tree().is_cutpoint( pos ) || pos == 0 || pos >= pose.n_residue() ) {
76  return op_performed;
77  }
78 
79  if ( !pose.residue( pos ).has_variant_type( CUTPOINT_LOWER ) ) {
81  op_performed = true;
82  }
83 
84  Size const next_pos = pos + 1;
85  if ( !pose.residue( next_pos ).has_variant_type( CUTPOINT_UPPER ) ) {
87  op_performed = true;
88  }
89 
90  return op_performed;
91 }
92 
93 
94 /// @brief remove cutpoint variants at a specific position
95 /// @param[in,out] Pose to modify
96 /// @param[in] position at which to remove cutpoint variants
97 /// @return true if cutpoint variants removed, false if no cutpoint variants found
98 /// or position not a topological cutpoint
99 bool
101  core::pose::Pose & pose,
102  core::Size const pos
103 )
104 {
105  using core::Size;
109 
110  if ( !pose.fold_tree().is_cutpoint( pos ) || pos == 0 || pos >= pose.n_residue() ) {
111  return false;
112  }
113 
114  bool op_done = false;
115 
116  if ( pose.residue( pos ).has_variant_type( CUTPOINT_LOWER ) ) {
118  op_done = true;
119  }
120 
121  Size const next_pos = pos + 1;
122  if ( pose.residue( next_pos ).has_variant_type( CUTPOINT_UPPER ) ) {
124  op_done = true;
125  }
126 
127  return op_done;
128 }
129 
130 
131 /// @brief restore residues (i.e. sidechains)
132 /// @param[in] old2new map indicating residues to be transferred and
133 /// the mapping from archive_pose position -> pose position
134 /// @param[in] archive_pose the original Pose to take residues from
135 /// @param[out] pose the altered Pose that needs residue restoration
136 void
138  std::map< core::Size, core::Size > const & old2new,
139  core::pose::Pose & archive_pose,
140  core::pose::Pose & pose
141 )
142 {
150 
152 
153  typedef std::map< core::Size, core::Size > Old2New;
154 
155 
156 
157 
158  for ( Old2New::const_iterator i = old2new.begin(), ie = old2new.end(); i != ie; ++i ) {
159 
160  if ( i->second > pose.total_residue() || i->first > archive_pose.total_residue()){
161  //TR << "mappign beyond pose length. only possible in repeat generation!!" << std::endl;
162  continue;
163  }
164 
165  /*
166  // check variant type
167  core::chemical::ResidueType const & rsd_type (pose.residue(i->second).type());
168  core::chemical::ResidueType const & archive_type ( archive_pose.residue(i->first).type());
169 
170  if (! rsd_type.variants_match( archive_type )){
171  utility::vector1<core::chemical::VariantType> const & variant_types ( rsd_type.variant_types() );
172  utility::vector1<core::chemical::VariantType> missing_variant_types;
173  for ( utility::vector1<core::chemical::VariantType>::const_iterator it = variant_types.begin(), it_end = variant_types.end(); it != it_end; ++it) {
174  if (!archive_type.has_variant_type( *it )) missing_variant_types.push_back(*it);
175  }
176  for (utility::vector1<core::chemical::VariantType>::const_iterator it = missing_variant_types.begin(), it_end=missing_variant_types.end(); it != it_end; ++it) {
177  core::pose::add_variant_type_to_pose_residue( archive_pose, *it, i->first);
178  }
179  }
180  */
181  pose.replace_residue( i->second, archive_pose.residue( i->first ), true );
182  }
183 
184  //archive_pose.dump_pdb("ARCposeInprogress.pdb");
185  //pose.dump_pdb("inProgress.pdb");
186 
187  // safety
188  pose.energies().clear();
189 
190  // (re-)detect disulfides, will convert CYD to CYS if disulfide bond is lost
191  using basic::options::option;
192  using namespace basic::options::OptionKeys;
193  if ( option[ in::detect_disulf ].user() ?
194  option[ in::detect_disulf ]() : // detect_disulf true
195  pose.is_fullatom() // detect_disulf default but fa pose
196  )
197  {
199  }
200 
201  // fix HG of CYS to relieve clashes of any newly converted CYS
203  TaskFactoryOP tf = new TaskFactory();
204  tf->push_back( new OptCysHG() );
205  pack_rotamers( pose, *sfx, tf->create_task_and_apply_taskoperations( pose ) );
206 
207  // safety
208  pose.energies().clear();
209 }
210 
211 
212 /// @brief restore residues (i.e. sidechains)
213 /// @param[in] archive_pose the original Pose to take residues from
214 /// @param[out] pose the altered Pose that needs residue restoration
215 /// @remarks length between two poses must be equal
216 void
218  core::pose::Pose & archive_pose,
219  core::pose::Pose & pose
220 )
221 {
222  using core::Size;
223 
224  assert( archive_pose.n_residue() == pose.n_residue() );
225 
226  std::map< Size, Size > old2new;
227  for ( Size i = 1, ie = archive_pose.n_residue(); i <= ie; ++i ) {
228  old2new[ i ] = i;
229  }
230 
231  restore_residues( old2new, archive_pose, pose );
232 }
233 
234 
235 } // methods
236 } // forge
237 } // protocols