Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
MedalExchangeMover.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/medal/MedalExchangeMover.cc
11 /// @author Christopher Miles (cmiles@uw.edu)
12 
13 // Unit headers
15 
16 // C/C++ headers
17 #include <iostream>
18 #include <string>
19 
20 // Utility headers
21 #include <basic/options/option.hh>
22 #include <basic/options/keys/OptionKeys.hh>
23 #include <basic/options/keys/abinitio.OptionKeys.gen.hh>
24 #include <basic/options/keys/cm.OptionKeys.gen.hh>
25 #include <basic/options/keys/constraints.OptionKeys.gen.hh>
26 #include <basic/options/keys/in.OptionKeys.gen.hh>
27 #include <basic/Tracer.hh>
28 #include <numeric/prob_util.hh>
29 #include <utility/vector1.hh>
30 
31 // Project headers
32 #include <core/types.hh>
34 #include <core/id/AtomID.hh>
42 #include <core/fragment/FragSet.hh>
45 #include <core/pose/Pose.hh>
46 #include <core/scoring/Energies.hh>
49 #include <protocols/loops/Loop.hh>
50 #include <protocols/loops/Loops.hh>
51 #include <protocols/medal/util.hh>
60 
61 namespace protocols {
62 namespace medal {
63 
64 using core::Real;
65 using core::Size;
66 using core::pose::Pose;
74 using utility::vector1;
75 
76 static basic::Tracer TR("protocols.medal.MedalExchangeMover");
77 
78 /// @detail Combines both sets of loops, sorting the result in increasing order of start position
80  LoopsOP combined = new Loops();
81 
82  for (Loops::const_iterator i = aligned->begin(); i != aligned->end(); ++i) {
83  combined->add_loop(*i);
84  }
85 
86  for (Loops::const_iterator i = unaligned->begin(); i != unaligned->end(); ++i) {
87  combined->add_loop(*i);
88  }
89 
90  combined->sequential_order();
91  return combined;
92 }
93 
94 /// @detail Create coordinate constraints restraining aligned residues to their initial positions
95 void setup_coordinate_constraints(const Pose& pose, LoopsCOP aligned, ConstraintSetOP constraints) {
96  using namespace basic::options;
97  using namespace basic::options::OptionKeys;
98  using core::PointPosition;
100  using core::id::AtomID;
105 
106  // const Real delta = option[OptionKeys::cm::sanitize::bound_delta](); // Unused variable causes warning.
107  // const Real sd = option[OptionKeys::cm::sanitize::bound_sd](); // Unused variable causes warning.
108 
109  // Fixed reference position
110  const AtomID fixed_atom(1, pose.total_residue());
111  const PointPosition& fixed_coords = pose.xyz(fixed_atom);
112 
113  for (Size i = 1; i <= aligned->size(); ++i) {
114  const Loop& region = (*aligned)[i];
115 
116  for (Size j = region.start(); j <= region.stop(); ++j) {
117  const Residue& residue = pose.conformation().residue(j);
118  const AtomID ca_atom(residue.atom_index("CA"), j);
119  const PointPosition& ca_coords = pose.xyz(ca_atom);
120 
121  Real distance = ca_coords.distance(fixed_coords);
122  FuncOP function = new HarmonicFunc(distance, 5);
123  ConstraintCOP constraint = new CoordinateConstraint(ca_atom, fixed_atom, fixed_coords, function);
124  constraints->add_constraint(constraint);
125  }
126  }
127 }
128 
129 /// @detail Retain user-specified distance restraints that operate on pairs of aligned residues
130 void setup_atom_pair_constraints(const Pose& pose, LoopsCOP aligned, ConstraintSetOP constraints) {
131  using namespace basic::options;
132  using namespace basic::options::OptionKeys;
133  using core::id::AtomID;
137 
138  if (option[OptionKeys::constraints::cst_file].user()) {
139  boost::unordered_set<Size> valid;
140  as_set(aligned, &valid);
141 
142  const vector1<std::string>& filenames = option[OptionKeys::constraints::cst_file]();
143  if (filenames.size() > 1) {
144  TR.Warning << "Multiple constraint files specified; using first" << std::endl;
145  }
146 
147  ConstraintSetOP additional = ConstraintIO::get_instance()->read_constraints(filenames[1], new ConstraintSet(), pose);
148  ConstraintCOPs cst_list = additional->get_all_constraints();
149 
150  for (ConstraintCOPs::const_iterator i = cst_list.begin(); i != cst_list.end(); ++i) {
151  ConstraintCOP c = *i;
152 
153  if (c->score_type() != core::scoring::atom_pair_constraint)
154  continue;
155 
156  const Size res1 = c->atom(1).rsd();
157  const Size res2 = c->atom(2).rsd();
158  if (valid.find(res1) == valid.end() || valid.find(res2) == valid.end()) {
159  continue;
160  }
161 
162  constraints->add_constraint(c);
163  }
164  }
165 }
166 
167 void setup_constraints(const Pose& pose, LoopsCOP aligned, ConstraintSetOP constraints) {
168  setup_atom_pair_constraints(pose, aligned, constraints);
169  setup_coordinate_constraints(pose, aligned, constraints);
170 }
171 
172 /// @detail Computes the probability of selecting a residue for fragment insertion.
173 /// P(unaligned) = 0. P(aligned) = 1 / #aligned.
175  probs->resize(num_residues, 0);
176 
177  for (Loops::const_iterator i = aligned->begin(); i != aligned->end(); ++i) {
178  for (Size j = i->start(); j <= i->stop(); ++j) {
179  (*probs)[j] = 1;
180  }
181  }
182 
183  protocols::medal::invalidate_residues_spanning_cuts(tree, fragments_->max_frag_length(), probs);
184  numeric::normalize(probs->begin(), probs->end());
185  numeric::print_probabilities(*probs, TR.Debug);
186 }
187 
189  using namespace basic::options;
190  using namespace basic::options::OptionKeys;
203 
204  ThreadingJob const * const job = protocols::nonlocal::current_job();
205  to_centroid(&pose);
206 
207  Extender extender(job->alignment().clone(), pose.total_residue());
208  extender.set_secondary_structure(pred_ss_);
209  extender.extend_unaligned(&pose);
210  pose.dump_pdb("extended.pdb");
211 
212  LoopsCOP aligned = extender.aligned();
213  LoopsCOP unaligned = extender.unaligned();
214  LoopsCOP combined = combine_loops(aligned, unaligned);
215  TR << "Aligned:" << std::endl << *aligned << std::endl;
216  TR << "Unaligned:" << std::endl << *unaligned << std::endl;
217 
218  TreeBuilderOP builder = TreeBuilderFactory::get_builder("star");
219  builder->set_up(*combined, &pose);
220  TR << pose.fold_tree() << std::endl;
221 
222  ConstraintSetOP constraints = new ConstraintSet();
223  setup_constraints(pose, aligned, constraints);
224 
225  // Minimal score function used during initial replacement
226  ScoreFunctionOP minimal = new ScoreFunction();
227  //minimal->set_weight(core::scoring::vdw, 1);
228 
229  ScoreFunctionOP score = new ScoreFunction();
230  //score->set_weight(core::scoring::vdw, 1);
231  score->set_weight(core::scoring::atom_pair_constraint, option[OptionKeys::cm::sanitize::cst_weight_pair]());
232  score->set_weight(core::scoring::coordinate_constraint, option[OptionKeys::cm::sanitize::cst_weight_coord]());
233 
234  vector1<double> probs;
235  setup_sampling_probs(pose.total_residue() - 1, pose.fold_tree(), aligned, &probs);
236 
237  // Sampling parameters
238  const Real temp = option[OptionKeys::abinitio::temperature]();
239  const Size num_fragments = option[OptionKeys::cm::sanitize::num_fragments]();
240  const Size num_cycles = static_cast<Size>(aligned->nr_residues() * 50 * option[OptionKeys::abinitio::increase_cycles]());
241 
242  PolicyOP policy = PolicyFactory::get_policy("uniform", fragments_, num_fragments);
243  MoverOP fragment_mover = new BiasedFragmentMover(policy, probs);
244 
245  RationalMonteCarlo replace(fragment_mover, minimal, 1000, 2.0, false);
246  RationalMonteCarlo exchange(fragment_mover, score, num_cycles, temp, true);
247 
248  replace.apply(pose);
249  pose.dump_pdb("replaced.pdb");
250  pose.constraint_set(constraints);
251  exchange.apply(pose);
252 
253  // Removing the virtual residue introduced by the star fold tree invalidates
254  // the pose's cached energies. Doing so causes the score line in the silent
255  // file to be 0.
256  Energies energies = pose.energies();
257 
258  // Housekeeping
259  pose.remove_constraints();
260  builder->tear_down(&pose);
261  pose.set_new_energies_object(new Energies(energies));
262 }
263 
265  using namespace basic::options;
266  using namespace basic::options::OptionKeys;
269 
270  FragmentIO io;
271  fragments_ = io.read_data(option[in::file::frag3]());
272  pred_ss_ = new SecondaryStructure(*fragments_);
273 }
274 
276  return "MedalExchangeMover";
277 }
278 
280  return new MedalExchangeMover(*this);
281 }
282 
284  return new MedalExchangeMover();
285 }
286 
287 } // namespace medal
288 } // namespace protocols