Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
StarAbinitio.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/star/StarAbinitio.cc
11 /// @author Christopher Miles (cmiles@uw.edu)
12 
13 // Unit header
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/options/keys/jumps.OptionKeys.gen.hh>
28 #include <basic/Tracer.hh>
29 #include <numeric/interpolate.hh>
30 #include <numeric/prob_util.hh>
31 #include <numeric/xyzVector.hh>
32 #include <ObjexxFCL/FArray1D.hh>
33 #include <ObjexxFCL/FArray2D.hh>
34 #include <utility/exit.hh>
35 #include <utility/vector1.hh>
36 
37 // Project headers
38 #include <core/types.hh>
44 #include <core/fragment/FragSet.hh>
46 #include <core/id/AtomID.hh>
50 #include <core/pose/Pose.hh>
51 #include <core/pose/util.hh>
63 #include <protocols/loops/Loop.hh>
64 #include <protocols/loops/Loops.hh>
65 #include <protocols/loops/util.hh>
66 #include <protocols/medal/util.hh>
67 #include <protocols/moves/Mover.hh>
74 
75 // Package headers
77 #include <protocols/star/util.hh>
78 
79 namespace protocols {
80 namespace star {
81 
82 static basic::Tracer TR("protocols.star.StarAbinitio");
83 
85 
86 using core::Real;
87 using core::Size;
89 using core::pose::Pose;
92 using numeric::xyzVector;
97 using utility::vector1;
98 
99 void compute_per_residue_probabilities(Size num_residues, Size fragment_len, const FoldTree& tree, Probabilities* probs) {
100  probs->resize(num_residues, 1);
101  protocols::medal::invalidate_residues_spanning_cuts(tree, fragment_len, probs);
102  numeric::normalize(probs->begin(), probs->end());
103  numeric::print_probabilities(*probs, TR);
104 }
105 
106 /// @detail Regulates the application of constraints during folding based on
107 /// distance between residues in the fold tree. The MonteCarlo object should
108 /// be reset after calling this function.
112 
113  MaxSeqSepConstraintSetOP new_cst = new MaxSeqSepConstraintSet(*pose->constraint_set(), pose->fold_tree());
114  new_cst->set_max_seq_sep(distance);
115  pose->constraint_set(new_cst);
116  TR << "max_seq_sep => " << distance << std::endl;
117 }
118 
119 /// @detail Adds constraints between contacting residues in different
120 /// aligned chunks, as well as those specified on the command line via
121 /// -constraints:cst_file. Call this *after* kinematics are in place.
122 void setup_constraints(const Loops& aligned, Pose* pose) {
123  using core::id::AtomID;
127  using namespace basic::options;
128  using namespace basic::options::OptionKeys;
129 
131 
132  Size n_csts = 0;
133  for (Size i = 1; i <= aligned.size(); ++i) {
134  const Loop& ci = aligned[i];
135 
136  for (Size j = i + 1; j <= aligned.size(); ++j) {
137  const Loop& cj = aligned[j];
138 
139  for (Size k = ci.start(); k <= ci.stop(); ++k) {
140  const AtomID ai(pose->conformation().residue(k).atom_index("CA"), k);
141  const xyzVector<Real>& p = pose->xyz(ai);
142 
143  for (Size l = cj.start(); l <= cj.stop(); ++l) {
144  const AtomID aj(pose->conformation().residue(l).atom_index("CA"), l);
145  const xyzVector<Real>& q = pose->xyz(aj);
146 
147  Real distance = p.distance(q);
148  if (distance <= option[OptionKeys::abinitio::star::initial_dist_cutoff]()) {
149  pose->add_constraint(new AtomPairConstraint(ai, aj, new HarmonicFunc(distance, 2)));
150  TR << "AtomPair CA " << k << " CA " << l << " HARMONIC " << distance << " 2" << std::endl;
151  ++n_csts;
152  }
153  }
154  }
155  }
156  }
157 
158  if (!n_csts) {
159  TR.Error << "Failed to define constraints between chunks in the non-local pairing" << std::endl;
160  TR.Error << "Check -abinitio:star:initial_dist_cutoff" << std::endl;
161  utility_exit();
162  }
163 
164  Size max_dist_ft = ShortestPathInFoldTree(pose->fold_tree()).max_dist();
165  update_sequence_separation(max_dist_ft, pose);
166 }
167 
169  pose->remove_constraints();
170 }
171 
172 /// @detail Instantiates a score function by name and sets constraint terms to
173 /// the value specified by the options system (-constraints:cst_weight)
175  using namespace basic::options;
176  using namespace basic::options::OptionKeys;
177 
179  score->set_weight(core::scoring::atom_pair_constraint, option[OptionKeys::constraints::cst_weight]());
180  score->set_weight(core::scoring::linear_chainbreak, cb);
181  return score;
182 }
183 
184 /// @detail Updates RationalMonteCarlo instance.
185 /// Calling this method twice without scoring a pose in between will trigger a
186 /// runtime assertion in core/pose/Pose.cc.
187 void configure_rmc(MoverOP mover, ScoreFunctionOP score, Size num_cycles, Real temperature, bool recover_low, RationalMonteCarlo* rmc) {
188  rmc->set_mover(mover);
189  rmc->set_score_function(score);
190  rmc->set_num_trials(num_cycles);
191  rmc->set_temperature(temperature);
192  rmc->set_recover_low(recover_low);
193 }
194 
195 void StarAbinitio::setup_kinematics(const Loops& aligned, const vector1<unsigned>& interior_cuts, Pose* pose) const {
196  assert(aligned.num_loop() >= 2);
197  assert(interior_cuts.size() == (aligned.num_loop() - 1));
198 
199  const Size num_residues = pose->total_residue();
200  const Size vres = num_residues + 1;
201 
202  xyzVector<double> center;
203  aligned.center_of_mass(*pose, &center);
204  core::pose::addVirtualResAsRoot(center, *pose);
205 
207  for (Size i = 1; i <= aligned.num_loop(); ++i) {
208  jumps.push_back(std::make_pair(vres, aligned[i].midpoint()));
209  }
210 
211  vector1<int> cuts(interior_cuts);
212  cuts.push_back(num_residues);
213 
214  ObjexxFCL::FArray2D_int ft_jumps(2, jumps.size());
215  for (Size i = 1; i <= jumps.size(); ++i) {
216  ft_jumps(1, i) = std::min(jumps[i].first, jumps[i].second);
217  ft_jumps(2, i) = std::max(jumps[i].first, jumps[i].second);
218  }
219 
220  ObjexxFCL::FArray1D_int ft_cuts(cuts.size());
221  for (Size i = 1; i <= cuts.size(); ++i) {
222  ft_cuts(i) = cuts[i];
223  }
224 
225  FoldTree tree(vres);
226  bool status = tree.tree_from_jumps_and_cuts(vres, // nres_in
227  jumps.size(), // num_jump_in
228  ft_jumps, // jump_point
229  ft_cuts, // cuts
230  vres); // root
231 
232  runtime_assert(status);
233  pose->fold_tree(tree);
235 
236  TR << pose->fold_tree() << std::endl;
237 }
238 
240  using namespace basic::options;
241  using namespace basic::options::OptionKeys;
246 
247  ThreadingJob const * const job = protocols::nonlocal::current_job();
248 
249  to_centroid(&pose);
250  emit_intermediate(pose, "star_initial.out");
251 
252  Extender extender(job->alignment().clone(), pose.total_residue());
253  extender.set_secondary_structure(pred_ss_);
254  extender.extend_unaligned(&pose);
255  emit_intermediate(pose, "star_extended.out");
256 
257  const Loops& aligned = *(extender.aligned());
258  //const Loops& unaligned = *(extender.unaligned());
259  TR << "Aligned: " << aligned << std::endl;
260 
261  const Size num_residues = pose.total_residue();
262  setup_kinematics(aligned, extender.cutpoints(), &pose);
263  setup_constraints(aligned, &pose);
264 
265  Probabilities probs_sm, probs_lg;
266  compute_per_residue_probabilities(num_residues, fragments_sm_->max_frag_length(), pose.fold_tree(), &probs_sm);
267  compute_per_residue_probabilities(num_residues, fragments_lg_->max_frag_length(), pose.fold_tree(), &probs_lg);
268 
269  MoverOP fragments_lg_uni = new BiasedFragmentMover(PolicyFactory::get_policy("uniform", fragments_lg_, 25), probs_lg);
270  MoverOP fragments_sm_uni = new BiasedFragmentMover(PolicyFactory::get_policy("uniform", fragments_sm_, 200), probs_sm);
271  MoverOP fragments_sm_smo = new BiasedFragmentMover(PolicyFactory::get_policy("smooth", fragments_sm_, 200), probs_sm);
272 
273  // Simulation parameters
274  const Real mult = option[OptionKeys::abinitio::increase_cycles]();
275  const Real temperature = option[OptionKeys::abinitio::temperature]();
276  const Real chainbreak = option[OptionKeys::jumps::increase_chainbreak]();
277 
278  ScoreFunctionOP score_stage1 = setup_score("score0", 0.1 * chainbreak);
279  ScoreFunctionOP score_stage2 = setup_score("score1", 0.2 * chainbreak);
280  ScoreFunctionOP score_stage3a = setup_score("score2", 0.4 * chainbreak);
281  ScoreFunctionOP score_stage3b = setup_score("score5", 0.4 * chainbreak);
282  ScoreFunctionOP score_stage4 = setup_score("score3", 0.6 * chainbreak);
283 
284  // Stage 1
285  TR << "Stage 1" << std::endl;
286  RationalMonteCarlo rmc(fragments_lg_uni, score_stage1, static_cast<Size>(mult * 2000), temperature, true);
287  rmc.apply(pose);
288 
289  configure_rmc(fragments_sm_uni, score_stage1, static_cast<Size>(mult * 2000), temperature, true, &rmc);
290  rmc.apply(pose);
291  emit_intermediate(pose, "star_stage1.out");
292 
293  // Stage 2
294  TR << "Stage 2" << std::endl;
295  configure_rmc(fragments_lg_uni, score_stage2, static_cast<Size>(mult * 4000), temperature, true, &rmc);
296  rmc.enable_autotemp(temperature);
297  rmc.apply(pose);
298 
299  configure_rmc(fragments_sm_uni, score_stage2, static_cast<Size>(mult * 4000), temperature, true, &rmc);
300  rmc.apply(pose);
301  emit_intermediate(pose, "star_stage2.out");
302 
303  // Stage 3
304  TR << "Stage 3" << std::endl;
305  for (Size i = 1; i <= 10; ++i) {
306  ScoreFunctionOP score = ((i % 2) == 0 && i <= 7) ? score_stage3a : score_stage3b;
307  configure_rmc(fragments_lg_uni, score, static_cast<Size>(mult * 4000), temperature, true, &rmc);
308  rmc.apply(pose);
309 
310  configure_rmc(fragments_sm_uni, score, static_cast<Size>(mult * 4000), temperature, true, &rmc);
311  rmc.apply(pose);
312  }
313  emit_intermediate(pose, "star_stage3.out");
314 
315  // Stage 4
316  TR << "Stage 4" << std::endl;
317  configure_rmc(fragments_sm_smo, score_stage4, static_cast<Size>(mult * 8000), temperature, true, &rmc);
318  for (Size i = 1; i <= 3; ++i) {
319  rmc.apply(pose);
320  }
321  emit_intermediate(pose, "star_stage4.out");
322 }
323 
327  simple_fold_tree(pose);
328 }
329 
331  using namespace basic::options;
332  using namespace basic::options::OptionKeys;
340 
341  FragmentIO io;
342  fragments_lg_ = io.read_data(option[in::file::frag9]());
343  fragments_sm_ = io.read_data(option[in::file::frag3]());
344 
345  // Approximate secondary structure from fragments when psipred isn't available
346  if (option[in::file::psipred_ss2].user()) {
347  pred_ss_ = new SecondaryStructure();
348  pred_ss_->read_psipred_ss2(option[in::file::psipred_ss2]());
349  } else {
350  pred_ss_ = new SecondaryStructure(*fragments_sm_);
351  }
352 
353  // Configure the minimizer
354  ScoreFunctionOP min_score = ScoreFunctionFactory::create_score_function("score4_smooth_cart");
355  min_score->set_weight(core::scoring::atom_pair_constraint, option[OptionKeys::constraints::cst_weight]());
356 
357  MinimizerOptionsOP min_options = new MinimizerOptions("lbfgs_armijo_nonmonotone", 0.01, true, false, false);
358  min_options->max_iter(100);
359 
360  MoveMapOP mm = new MoveMap();
361  mm->set_bb(true);
362  mm->set_chi(true);
363  mm->set_jump(true);
364 
365  minimizer_ = new SaneMinMover(mm, min_score, min_options, true);
366 }
367 
369  return "StarAbinitio";
370 }
371 
373  return new StarAbinitio(*this);
374 }
375 
377  return new StarAbinitio();
378 }
379 
380 } // namespace star
381 } // namespace protocols