Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
FragmentCandidate.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 // This file is part of the Rosetta software suite and is made available under license.
5 // The Rosetta software is developed by the contributing members of the Rosetta Commons consortium.
6 // (C) 199x-2009 Rosetta Commons participating institutions and developers.
7 // For more information, see http://www.rosettacommons.org/.
8 
9 /// @file protocols/frag_picker/FragmentCandidate.hh
10 /// @brief Something that might become a fragment if its scores will be good enough
11 /// @author Dominik Gront (dgront@chem.uw.edu.pl)
12 
13 
14 // type headers
15 #include <core/types.hh>
16 
17 // package headers
21 
22 #include <ObjexxFCL/string.functions.hh>
23 
24 #include <basic/Tracer.hh>
25 
26 // Options
27 #include <basic/options/option.hh>
28 #include <basic/options/keys/OptionKeys.hh>
29 #include <basic/options/keys/frags.OptionKeys.gen.hh>
30 
31 // core
33 #include <core/scoring/Energies.hh>
36 #include <core/fragment/util.hh>
37 #include <core/pose/util.hh>
47 
48 // Project headers
49 #include <core/scoring/rms_util.hh>
50 #include <numeric/model_quality/rms.hh>
53 #include <protocols/relax/util.hh>
56 
57 
58 
59 // Utility
60 #include <utility/io/izstream.hh>
61 #include <utility/exit.hh>
62 // AUTO-REMOVED #include <cctype>
63 
64 #include <utility/vector1.hh>
65 
66 
67 namespace protocols {
68 namespace frag_picker {
69 
70 static basic::Tracer trFragmentCandidate(
71  "protocols.frag_picker.FragmentCandidate");
72 
73 const std::string FragmentCandidate::unknown_pool_name_ = "UNKNOWN_POOL_NAME";
74 
75 
77  std::string file_name, VallProviderOP chunk_owner, Size max_nfrags_per_pos) {
78 
80 
81  utility::io::izstream data(file_name.c_str());
82  trFragmentCandidate.Info << "Reading fragments from: " << file_name
83  << std::endl;
84 
85  if (!data)
86  utility_exit_with_message(
87  "[ERROR] Unable to open a file with fragments: " + file_name);
88 
89  std::string pdb_id = "";
90  char chain_id;
91  Size res_id = 0, qpos = 1, n_res = 0;
92  std::string line;
93  std::string tmp;
94  Size n_frags = 0;
95  while (data) {
96  getline(data, line);
97  Size found = line.find_first_not_of(" \t");
98  if (found == std::string::npos) { // the line is empty!
99  if (n_res > 0) {
100  Size vpos = 0;
101  VallChunkOP chunk = chunk_owner->find_chunk(pdb_id, chain_id,
102  res_id);
103  if (chunk != 0) {
104  for (Size j = 1; j <= chunk->size(); ++j) {
105  if (chunk->at(j)->resi() == res_id) {
106  vpos = j;
107  if (vpos > 99999)
108  trFragmentCandidate.Warning
109  << "Supprisingly high residue id for a vall postion: "
110  << vpos << std::endl;
111  break;
112  }
113  }
114  } else {
115  trFragmentCandidate.Warning
116  << "Can't find the following chunk in a vall: "
117  << pdb_id << " " << chain_id << " " << res_id
118  << std::endl;
119  n_res = 0;
120  pdb_id = "";
121  continue;
122  }
123  if (vpos == 0) {
124  trFragmentCandidate.Warning << "Can't find a residue: "
125  << res_id << " within a chunk" << std::endl;
126  n_res = 0;
127  pdb_id = "";
128  continue;
129  }
130  FragmentCandidateOP c = new FragmentCandidate(qpos, vpos,
131  chunk, n_res);
132  if (n_frags < max_nfrags_per_pos) candidates.push_back(c);
133  ++n_frags;
134  n_res = 0;
135  pdb_id = "";
136  }
137  continue;
138  }
139  if ((line.substr(0, 9) == "Position:") || (line.substr(0, 9)
140  == "position:") || (line.substr(0, 9) == " Position")
141  || (line.substr(0, 9) == " position")) {
142  std::istringstream line_stream(line);
143  line_stream >> tmp >> qpos;
144  if (n_frags > 0)
145  trFragmentCandidate.Info << " ... " << n_frags << " found"
146  << std::endl;
147  trFragmentCandidate.Info << "Reading fragments for a position: "
148  << qpos << " in a query";
149  n_frags = 0;
150  continue;
151  }
152  n_res++;
153  if ((pdb_id.size() == 4) && (res_id > 0) && (res_id < 99999))
154  continue;
155  std::istringstream line_stream(line);
156  line_stream >> pdb_id >> chain_id >> res_id;
157  if (pdb_id.size() != 4) {
158  trFragmentCandidate.Info << "Skiping strange PDB ID: " << pdb_id
159  << std::endl;
160  pdb_id = "";
161  continue;
162  }
163  }
164  trFragmentCandidate.Info << " ... " << n_frags << " found"<< std::endl;
165  trFragmentCandidate.Info << candidates.size()<<" fragments read from a file"<<std::endl;
166 
167  return candidates;
168 }
169 
170 
171 /// @brief Prints fragment data, the output can be directly loaded to minirosetta
173  using namespace basic::options;
174  using namespace basic::options::OptionKeys;
175  bool if_ca_in_output = false;
176  //bool score_in_output = false;
177  if ( option[frags::write_ca_coordinates].user() ) {
178  // std::cerr << "pf 2" << std::endl;
179  if_ca_in_output = option[frags::write_ca_coordinates]();
180  }
181  // optionally add the total score as a comment line.
182  // code for reading this score is in src/core/fragment/ConstantLengthFragSet.cc
183  if (option[frags::write_scores].user() && option[frags::write_scores]() && sc && ms) {
184  out << "# score " << F(9,3, ms->total_score(sc)) << std::endl;
185  }
186  for ( Size i = 1; i <= fragmentLength_; ++i ) {
187  // std::cerr << "pf 4 " << i << std::endl;
188  VallResidueOP r = get_residue(i);
189  if ( !r ) continue;
190  // std::cerr << "pf 5 " << i << std::endl;
191  char aa_upper( toupper(r->aa()) );
192  out << " " << get_pdb_id() << " " << get_chain_id() << " " << I(5,r->resi())
193  <<" " << aa_upper << " " << r->ss() << F(9, 3, r->phi())
194  << F(9, 3, r->psi()) << F(9, 3, r->omega());
195  if ( if_ca_in_output ) {
196  out << F(9, 3,r->x()) << F(9, 3, r->y()) << F(9, 3, r->z());
197  }
198  out << std::endl;
199  }
200 }
201 
202 
203 /* To be used in the nearest future...
204 ConstantLengthFragSet FragmentCandidate::create_frag_set(utility::vector1<std::pair<
205  FragmentCandidateOP, scores::FragmentScoreMapOP> >& selected_fragments) {
206 
207  std::stringstream s;
208  for (Size fi = 1; fi <= out.size(); ++fi) {
209  selected_fragments[i].first->print_fragment(output);
210  s << std::endl;
211  }
212 } */
213 
214 /// @brief Prints fragment data, the output can be directly loaded to minirosetta
215 void FragmentCandidate::print_fragment_seq(std::ostream& out) {
216 
217  using namespace basic::options;
218  using namespace basic::options::OptionKeys;
219  out << " " << get_pdb_id() << " " << get_chain_id();
220  VallResidueOP r1 = get_residue(1);
221  out << " " << I(5,r1->resi()) << " ";
222  for (Size i = 1; i <= fragmentLength_; ++i) {
223  VallResidueOP r = get_residue(i);
224  char aa_upper( toupper(r->aa()) );
225  out << aa_upper;
226  }
227 }
228 
229 /// @brief Prints fragment to silent struct
231 
232  using namespace ObjexxFCL;
233  using namespace basic::options;
234  using namespace basic::options::OptionKeys;
235  //if (option[frags::write_ca_coordinates].user())
236  // if_ca_in_output = option[frags::write_ca_coordinates]();
237 
238  pose::Pose pose;
239  // make pose from frag
241  fragdata.push_back(get_frag_data());
242  fragment::make_pose_from_frags( pose, sequence, fragdata, false );
243 
244  if (option[frags::score_output_silent]()) {
245  pose::Pose relax_pose = pose;
246 
248 
249  if ( !relax_pose.is_fullatom() )
251 
252 
253  relax_pose.energies().clear();
254  relax_pose.data().clear();
255 
256  // Detect disulfides
257  relax_pose.conformation().detect_disulfides();
258  relax_pose.conformation().detect_bonds();
259 
260  utility::vector1< bool > needToRepack( relax_pose.total_residue(), true );
262  taskstd->restrict_to_repacking();
263  taskstd->or_include_current(true);
264  taskstd->restrict_to_residues( needToRepack );
265  protocols::simple_moves::PackRotamersMover pack1( sfxn, taskstd );
266  pack1.apply( relax_pose );
267 
268  // quick SC minimization
270  core::optimization::MinimizerOptions options( "dfpmin_armijo_nonmonotone", 1e-5, true, false );
272  mm_min->set_bb( false );
273  mm_min->set_chi( true );
274  mzr.run( relax_pose, *mm_min, *sfxn, options );
275 
276  Real sc_min_score = (*sfxn)( relax_pose );
277  core::pose::setPoseExtraScores( pose, "sc_min_score", sc_min_score );
278 
279  // RELAX fragment
280  // setup relax protocol for pose
282  kinematics::MoveMapOP mm = sub_pose_relax_protocol->get_movemap();
283  sub_pose_relax_protocol->apply( relax_pose );
284 
285  // check relaxed pose
286  Real relaxed_rmsd = scoring::CA_rmsd( relax_pose, pose );
287  Real relaxed_score = (*sfxn)( relax_pose );
288 
289  core::pose::setPoseExtraScores( pose, "rlx_rms", relaxed_rmsd );
290  core::pose::setPoseExtraScores( pose, "rlx_score", relaxed_score );
291  }
292 
293  // add fragment info and scores
294  VallResidueOP r = get_residue(1);
295  core::pose::add_score_line_string( pose, "query_pos", string_of(get_first_index_in_query()) ); // query position
296  core::pose::add_score_line_string( pose, "vall_pos", string_of(r->resi()) ); // vall position
297  core::pose::add_score_line_string( pose, "pdbid", get_pdb_id() ); // pdbid
298  core::pose::add_score_line_string( pose, "c", string_of(get_chain_id()) ); // chain id
299  core::pose::add_score_line_string( pose, "ss", string_of(get_middle_ss()) ); // secondary structure
300 
301  bool if_quota = false;
302  if ( sc->get_quota_score() < 999.98 ) if_quota = true;
303 
304  for (Size i = 1; i <= sc->size(); i++) {
305  scores::FragmentScoringMethodOP ms_i = ms->get_component(i);
306  core::pose::setPoseExtraScores( pose, ms_i->get_score_name(), sc->at(i) );
307  }
308  if (if_quota) {
309  core::pose::setPoseExtraScores( pose, "QUOTA_TOT", sc->get_quota_score());
310  core::pose::setPoseExtraScores( pose, "TOTAL", ms->total_score(sc));
311  core::pose::add_score_line_string( pose, "POOL_NAME", get_pool_name());
312  } else {
313  core::pose::setPoseExtraScores( pose, "TOTAL", ms->total_score(sc));
314  }
315  assert ( key() > 0 );
316  assert ( key() < 40000000 );
317  core::pose::add_score_line_string( pose, "FRAG_ID", string_of(key()));
318 
320  ss->fill_struct( pose, tag );
321  sfd.write_silent_struct( *ss, silent_file_name );
322 }
323 
325  if (get_pdb_id() != fr->get_pdb_id() || get_chain_id() != fr->get_chain_id()) return false;
326  return true;
327 }
328 
329 } // frag_picker
330 } // protocols
331