Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
AddConstraintsToCurrentConformationMover.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
11 /// @brief Add constraints to the current pose conformation.
12 /// @author Yifan Song
13 
16 
17 #include <core/pose/Pose.hh>
18 #include <core/pose/util.hh>
19 
22 
25 
27 
35 
36 // task operation
40 #include <numeric/xyzVector.hh>
41 
42 // utility
43 #include <utility/tag/Tag.hh>
44 #include <basic/Tracer.hh>
45 
46 // option
47 #include <basic/options/option.hh>
48 #include <basic/options/keys/relax.OptionKeys.gen.hh>
49 
50 static basic::Tracer TR( "protocols.simple_moves.AddConstraintsToCurrentConformationMover" );
51 
52 namespace protocols {
53 namespace simple_moves {
54 
55 using namespace core;
56 using namespace basic::options;
57 using namespace pack;
58 using namespace task;
59 using namespace operation;
60 using namespace scoring;
61 using namespace constraints;
62 
64  use_distance_cst_ = false;
65  max_distance_ = 12.0;
66  coord_dev_ = 1.0;
67  bound_width_ = 0.;
68  min_seq_sep_ = 8;
69  cst_weight_ = 1.0;
70 }
71 
73 
75 {
76  using namespace conformation;
77  using namespace core;
78  using namespace basic::options;
79  using namespace basic::options::OptionKeys;
80  using namespace core::pose::datacache;
81  using namespace core::scoring;
82  using namespace core::scoring::constraints;
83  using namespace core::id;
84  using namespace protocols::moves;
85  using namespace core::scoring;
86 
87  if (!use_distance_cst_) {
88  // this is not quite right without adding a virtual residue
89  /*
90  if ( pose.residue( pose.fold_tree().root() ).aa() != core::chemical::aa_vrt ) {
91  core::pose::addVirtualResAsRoot(pose);
92  }
93  */
94 
95  // TR << pose.fold_tree() << std::endl;
96  Size nres = pose.total_residue();
97 
98  // find anchor residue
101  core::Real natom;
102  for ( Size ires = 1; ires <= nres; ++ires ) {
103  if ( pose.residue_type(ires).has("CA") ) {
104  Size iatom = pose.residue_type(ires).atom_index("CA");
105  sum_xyz += pose.residue(ires).xyz(iatom);
106  natom += 1.;
107  }
108  if (natom > 1e-3) {
109  anchor_xyz = sum_xyz / natom;
110  }
111  }
112  core::Real min_dist2 = 1e9;
113  Size best_anchor = 0;
114  for ( Size ires = 1; ires <= nres; ++ires ) {
115  if ( pose.residue_type(ires).has("CA") ) {
116  Size iatom = pose.residue_type(ires).atom_index("CA");
117  core::Real dist2 = pose.residue(ires).xyz(iatom).distance_squared(anchor_xyz);
118  if (dist2 < min_dist2) {
119  min_dist2 = dist2;
120  best_anchor = ires;
121  }
122  }
123  }
124 
125  if (best_anchor == 0) return;
126  Size best_anchor_atom = pose.residue_type(best_anchor).atom_index("CA");
127 
128  //Real const coord_sdev( option[ OptionKeys::relax::coord_cst_stdev ] );
129  for ( Size ires = 1; ires <= nres; ++ires ) {
130  Size iatom;
131  if ( pose.residue_type(ires).has("CA") ) {
132  iatom = pose.residue_type(ires).atom_index("CA");
133  }
134  else if ( pose.residue_type(ires).is_DNA() ) {
135  iatom = 0;
136  }
137  else {
138  continue;
139  }
140 
141  if ( bound_width_ < 1e-3 ) {
142  if (iatom != 0) {
144  AtomID(iatom,ires), AtomID(best_anchor_atom,best_anchor), pose.residue(ires).xyz(iatom),
145  new HarmonicFunc( 0.0, coord_dev_ ) ) );
146  TR.Debug << "Constraint added to residue " << ires << ", atom " << iatom << std::endl;
147  }
148  else {
149  for (iatom = 1; iatom <= pose.residue_type(ires).nheavyatoms(); ++iatom) {
151  AtomID(iatom,ires), AtomID(best_anchor_atom,best_anchor), pose.residue(ires).xyz(iatom),
152  new HarmonicFunc( 0.0, coord_dev_ ) ) );
153  }
154  }
155  } else {
156  //Real const cst_width( option[ OptionKeys::relax::coord_cst_width ]() );
157  if (iatom != 0) {
159  AtomID(iatom,ires), AtomID(best_anchor_atom,best_anchor), pose.residue(ires).xyz(iatom),
160  new BoundFunc( 0, bound_width_, coord_dev_, "xyz" )) );
161  TR << "Constraint added to residue " << ires << ", atom " << iatom << std::endl;
162  }
163  else {
164  for (iatom = 1; iatom <= pose.residue_type(ires).nheavyatoms(); ++iatom) {
166  AtomID(iatom,ires), AtomID(best_anchor_atom,best_anchor), pose.residue(ires).xyz(iatom),
167  new BoundFunc( 0, bound_width_, coord_dev_, "xyz" )) );
168  }
169  }
170  }
171  }
172  }
173  else {
174  // distance constraints
175  for (Size ires=1; ires<=pose.total_residue(); ++ires) {
176  if ( ! pose.residue_type(ires).has("CA") ) continue;
177  core::Size iatom = pose.residue_type(ires).atom_index("CA");
178 
179  for (Size jres=ires+min_seq_sep_; jres<=pose.total_residue(); ++jres) {
180  if ( ! pose.residue_type(jres).has("CA") ) continue;
181  core::Size jatom = pose.residue_type(jres).atom_index("CA");
182 
183  core::Real dist = pose.residue(ires).xyz(iatom).distance( pose.residue(jres).xyz(jatom) );
184  if ( dist <= max_distance_ ) {
185  TR.Debug << "Constraint added to residue " << ires << ", atom " << iatom << " and residue " << jres << ", atom " << jatom << " with weight " << cst_weight_ << std::endl;
186 
187  pose.add_constraint(
189  core::id::AtomID(jatom,jres),
191  )
192  );
193  }
194  }
195  }
196 
197  }
198 }
199 
200 ///@brief parse XML (specifically in the context of the parser/scripting scheme)
201 void
203  TagPtr const tag,
204  moves::DataMap & datamap,
205  Filters_map const & filters,
206  moves::Movers_map const & movers,
207  Pose const & pose
208  )
209 {
210  if ( tag->hasOption("use_distance_cst") ) {
211  use_distance_cst_ = tag->getOption<bool>("use_distance_cst");
212  }
213  if ( tag->hasOption("max_distance") ) {
214  max_distance_ = tag->getOption<core::Real>("max_distance");
215  }
216  if ( tag->hasOption("coord_dev") ) {
217  coord_dev_ = tag->getOption<core::Real>("coord_dev");
218  }
219  if ( tag->hasOption("bound_width") ) {
220  bound_width_ = tag->getOption<core::Real>("bound_width");
221  }
222  if ( tag->hasOption("min_seq_sep") ) {
223  min_seq_sep_ = tag->getOption<core::Size>("min_seq_sep");
224  }
225  if ( tag->hasOption("cst_weight") ) {
226  cst_weight_ = tag->getOption<core::Real>("cst_weight");
227  }
228 
229  parse_task_operations( tag, datamap, filters, movers, pose );
230 }
231 
232 void
234  TagPtr const tag,
235  moves::DataMap const & datamap,
236  Filters_map const &,
237  moves::Movers_map const &,
238  Pose const &
239  )
240 {
241  TaskFactoryOP new_task_factory( protocols::rosetta_scripts::parse_task_operations( tag, datamap ) );
242  if ( new_task_factory == 0) return;
243  task_factory( new_task_factory );
244 }
245 
247 {
248  runtime_assert( tf );
249  task_factory_ = tf;
250 }
251 
254 
258 }
259 
262 {
264 }
265 
268 {
269  return "AddConstraintsToCurrentConformationMover";
270 }
271 
274  return "AddConstraintsToCurrentConformationMover";
275 }
276 
277 } // moves
278 } // protocols