Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
IdealizeMover.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/idealize/IdealizeMover.cc
11 /// @brief
12 /// @author
13 
14 // Unit Headers
18 
19 // // Rosetta Headers
20 #include <core/types.hh>
21 #include <utility/tag/Tag.hh>
22 
24 
27 // AUTO-REMOVED #include <core/conformation/util.hh>
28 
29 // AUTO-REMOVED #include <core/kinematics/MoveMap.hh>
30 
31 // AUTO-REMOVED #include <core/optimization/AtomTreeMinimizer.hh>
32 // AUTO-REMOVED #include <core/optimization/MinimizerOptions.hh>
33 
34 #include <core/pose/Pose.hh>
35 
38 #include <core/scoring/rms_util.hh>
43 
44 #include <basic/options/option.hh>
45 #include <basic/options/keys/run.OptionKeys.gen.hh>
46 
47 // AUTO-REMOVED #include <basic/basic.hh>
48 #include <basic/Tracer.hh> // tracer output
49 
50 // symmetry
52 // AUTO-REMOVED #include <core/conformation/symmetry/util.hh>
53 
56 
57 // Numeric headers
58 // AUTO-REMOVED #include <numeric/random/random.hh>
59 
60 // ObjexxFCL headers
61 // AUTO-REMOVED #include <ObjexxFCL/format.hh>
62 #include <ObjexxFCL/string.functions.hh>
64 #include <core/pose/selection.hh>
65 
66 //Auto Headers
69 #include <utility/vector0.hh>
70 #include <utility/vector1.hh>
71 
72 
73 // // C++ Headers
74 
75 namespace protocols {
76 namespace idealize {
77 
78 using namespace core;
79 
80 static basic::Tracer TR( "protocols.idealize.IdealizeMover" );
81 
84 {
86 }
87 
90  return new IdealizeMover;
91 }
92 
95 {
96  return "Idealize";
97 }
98 
99 
100 /// @brief Add the idealize constraints to the pose's constraint set
101 void
103  using namespace scoring::constraints;
104  using namespace conformation;
105  using namespace id;
106 
107  Real const heavyatom_dis2_threshold( 5.5 * 5.5 );
108  Real const polarH_dis2_threshold( 2.5 * 2.5 );
109 
110  Real const atom_pair_sdev( 0.25 );
111  Real const coord_sdev( 0.1 );
112 
113 
114  Size const nres( pose.total_residue() );
115  Size total_atompairs( 0 );
116 
117  //fpd symmetry
120  TR.Info << "setting up symmetric idealize " << std::endl;
122  dynamic_cast<core::conformation::symmetry::SymmetricConformation &> ( pose.conformation()) );
123  symm_info = SymmConf.Symmetry_Info();
124  }
125 
126  if ( atom_pair_constraint_weight_ != 0.0 || symm_info ) {
127  for ( Size i=1; i<= nres-1; ++i ) {
128  if( std::find( ignore_residues_in_csts().begin(), ignore_residues_in_csts().end(), i ) != ignore_residues_in_csts().end() ) continue;
129  Residue const & i_rsd( pose.residue(i) );
130  if (i_rsd.aa() == core::chemical::aa_vrt) continue;
131 
132  for ( Size j=i+1; j<= nres-1; ++j ) {
133  if( std::find( ignore_residues_in_csts().begin(), ignore_residues_in_csts().end(), j ) != ignore_residues_in_csts().end() ) continue;
134  Residue const & j_rsd( pose.residue(j) );
135  if (j_rsd.aa() == core::chemical::aa_vrt) continue;
136 
137  //fpd for symmetry, we only need generate csts w.r.t. scoring subunit
138  if ( symm_info && !symm_info->bb_is_independent( i ) && !symm_info->bb_is_independent( j ) ) continue;
139 
140  //fpd if atom pair cst weight is 0, we _only_ generate atom pair csts across symm interface
141  if ( symm_info && atom_pair_constraint_weight_ == 0.0 &&
142  symm_info->bb_is_independent( i ) && symm_info->bb_is_independent( j ) )
143  continue;
144 
145  for ( Size ii = 1; ii<= i_rsd.natoms(); ++ii ) {
146  chemical::AtomType const & it( i_rsd.atom_type( ii ) );
147 
148  for ( Size jj = 1; jj<= j_rsd.natoms(); ++jj ) {
149  chemical::AtomType const & jt( j_rsd.atom_type( jj ) );
150 
151  Real const dis2( i_rsd.xyz( ii ).distance_squared( j_rsd.xyz( jj ) ) );
152 
153  if ( ( it.is_polar_hydrogen() && jt.is_acceptor() && dis2 < polarH_dis2_threshold ) ||
154  ( jt.is_polar_hydrogen() && it.is_acceptor() && dis2 < polarH_dis2_threshold ) ||
155  ( it.is_heavyatom() && jt.is_heavyatom() && dis2 < heavyatom_dis2_threshold ) ) {
156 
157  pose.add_constraint( new AtomPairConstraint( AtomID(ii,i), AtomID(jj,j),
158  new HarmonicFunc( std::sqrt( dis2 ), atom_pair_sdev ))
159  );
160  ++total_atompairs;
161  }
162  } // jj
163  } // ii
164  } // j>=i
165  } // i
166  }
167 
168  TR.Info << "total atompairs: " << total_atompairs << std::endl;
169 
170  if ( coordinate_constraint_weight_ != 0.0 ) {
171  // should already have setup for using coordinate constraints
172  runtime_assert( pose.residue( nres ).aa() == core::chemical::aa_vrt );
173  for ( Size i=1; i<= nres-1; ++i ) {
174  // only put coord csts on master
175  if ( symm_info &&
176  ( !symm_info->bb_is_independent( i ) || pose.residue(i).aa() == core::chemical::aa_vrt) )
177  continue;
178  Residue const & i_rsd( pose.residue(i) );
179  for ( Size ii = 1; ii<= i_rsd.natoms(); ++ii ) {
180  pose.add_constraint( new CoordinateConstraint( AtomID(ii,i), AtomID(1,nres), i_rsd.xyz( ii ),
181  new HarmonicFunc( 0.0, coord_sdev ) )
182  );
183  }
184  }
185  } // coordinate_constraint_weight_ != 0
186  TR.flush();
187 } // setup_idealize_constraints
188 
189 void
191  using namespace scoring;
192  using namespace basic::options;
193  using namespace basic::options::OptionKeys;
194 
195  pose::Pose unmodified_pose = pose;
196  //pose.dump_pdb("idl_initial.pdb");
197 
198  // save a copy of the pose's constraints
199  scoring::constraints::ConstraintSetOP original_cst_set( pose.constraint_set()->clone() );
200  if( impose_constraints() )
201  pose.constraint_set( NULL );
202  // add virtual residue at the end
203  //Size const old_root( pose.fold_tree().root() );
204  if ( pose.residue( pose.total_residue() ).aa() != core::chemical::aa_vrt ) {
205  /// bugfix for single-residue pose: don't append residue by jump from residue 0
206  Size const midpoint( pose.total_residue() == 1 ? 1 : pose.total_residue() / 2 );
209  midpoint
210  );
211 
212  Size const nres( pose.total_residue() ); // includes pseudo-rsd
213 
214  kinematics::FoldTree f( pose.fold_tree() );
215  f.reorder( nres );
216  pose.fold_tree( f );
217  }
218 
219  //fpd symmetry
223  dynamic_cast<core::conformation::symmetry::SymmetricConformation &> ( pose.conformation()) );
224  symm_info = SymmConf.Symmetry_Info();
225  }
226 
227  // setup scorefunction
228  scoring::ScoreFunctionOP scorefxn;
229  if (symm_info)
231  else
232  scorefxn = new scoring::ScoreFunction();
233  scorefxn->set_weight( atom_pair_constraint, atom_pair_constraint_weight_ );
234  scorefxn->set_weight( coordinate_constraint, coordinate_constraint_weight_ );
235 
236  // if we're symmetric, we need to turn atom pair csts on
237  if (symm_info && atom_pair_constraint_weight_ == 0)
238  scorefxn->set_weight( atom_pair_constraint, coordinate_constraint_weight_ );
239 
240 
241  if ( pose.is_fullatom() ) {
242  // keep prolines closed during idealizations.
243  scorefxn->set_weight( pro_close, 0.5 );
244  // keep disulphides together.
245  scorefxn->set_weight( dslf_ss_dst, 0.5 );//SG-SG bond length
246  scorefxn->set_weight( dslf_cs_ang, 2.0 );//CB-SG-SG covalent bond angle
247  }
248  // setup constraints
249  if( impose_constraints() )
250  setup_idealize_constraints( pose );
251  if( constraints_only() )
252  return;
253 
254  // by default idealize everything
255  //fpd ... unless symmetric, then only idealize master
256  if ( pos_list_.size() == 0 ) {
257  for ( Size i = 1; i <= pose.total_residue()-1; ++i ) {
258  if ( symm_info &&
259  (!symm_info->bb_is_independent( i ) || pose.residue(i).aa() == core::chemical::aa_vrt ) )
260  continue;
261  pos_list_.push_back( i );
262  }
263  }
264 
265 
266  if( !(option[ basic::options::OptionKeys::run::dry_run ]() )){
267  basic_idealize( pose, pos_list_, *scorefxn, fast_, chainbreaks_ );
268  }
269 
270  // remove that virtual residue now!
271  pose::Pose final_pose = unmodified_pose;
272 
273  if (symm_info) {
274  // special case for symmetry .. replace VRTs first
275  for ( Size ii = unmodified_pose.total_residue(); ii>=1; --ii ) {
276  if ( symm_info->bb_is_independent(ii) )
277  final_pose.replace_residue( ii, pose.residue( ii ), false );
278  }
279  } else {
280  for ( Size ii = 1; ii <= unmodified_pose.total_residue(); ++ii ) {
281  final_pose.replace_residue( ii, pose.residue( ii ), false );
282  }
283  }
284  pose = final_pose;
285 
286  // restore the original constraint set
287  pose.constraint_set( original_cst_set );
288 
289  /// Pose must be rescored after the original constraint set is restored.
290  (*scorefxn)( pose );
291 
292  TR.Info << "RMS between original pose and idealised pose: ";
293  if( report_CA_rmsd_ ) TR.Info << core::scoring::CA_rmsd( unmodified_pose, pose ) << " CA RMSD, ";
294 
295  TR.Info << core::scoring::all_atom_rmsd( unmodified_pose, pose ) << " All-Atom RMSD, "
296  << std::endl;
297  TR.flush();
298 } // apply
299 
302  return "IdealizeMover";
303 }
304 
305 void
307  atom_pair_constraint_weight( tag->getOption< core::Real >( "atom_pair_constraint_weight", 0.0 ) );
308  coordinate_constraint_weight( tag->getOption< core::Real >( "coordinate_constraint_weight", 0.01 ) );
309  fast( tag->getOption< bool >( "fast", false ) );
310  chainbreaks( tag->getOption< bool >( "chainbreaks", false ) );
311  report_CA_rmsd( tag->getOption< bool >( "report_CA_rmsd", true ) );
312  if( tag->hasOption( "ignore_residues_in_csts" ) )
313  ignore_residues_in_csts( core::pose::get_resnum_list( tag, "ignore_residues_in_csts", pose ) );
314  impose_constraints( tag->getOption< bool >( "impose_constraints", 1 ) );
315  constraints_only( tag->getOption< bool >( "constraints_only", 0 ) );
316 
317  TR<<"IdealizeMover with atom_pair_constraint_weight="<<atom_pair_constraint_weight_<<" coordinate_constraint_weight="<<coordinate_constraint_weight_<<" fast="<<fast_<<" chainbreaks="<<chainbreaks_<<" and report CA_rmsd_="<<report_CA_rmsd_<<" impose constraints "<<impose_constraints()<<std::endl;
318 }
319 
320 void
322  ignore_residues_in_csts_ = i;
323 }
324 
327  return ignore_residues_in_csts_;
328 }
329 
330 } // namespace idealize
331 } // namespace protocols