Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ProteinSilentStruct.tmpl.hh
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 // :noTabs=false:tabSize=4:indentSize=4:
4 //
5 // (c) Copyright Rosetta Commons Member Institutions.
6 // (c) This file is part of the Rosetta software suite and is made available under license.
7 // (c) The Rosetta software is developed by the contributing members of the Rosetta Commons.
8 // (c) For more information, see http://www.rosettacommons.org. Questions about this can be
9 // (c) addressed to University of Washington UW TechTransfer, email: license@u.washington.edu.
10 
11 /// @file core/io/silent/ProteinSilentStruct.tmpl.hh
12 ///
13 /// @brief Representation of rosetta++ protein silent-file structures.
14 /// @author James Thompson, Mike Tyka
15 
16 #ifndef INCLUDED_core_io_silent_ProteinSilentStruct_tmpl_hh
17 #define INCLUDED_core_io_silent_ProteinSilentStruct_tmpl_hh
18 
19 // Unit headers
21 
22 // C++ Headers
23 #include <algorithm>
24 #include <cmath>
25 #include <cstdlib>
26 #include <iostream>
27 #include <utility>
28 #include <vector>
29 #include <list>
30 #include <string>
31 #include <map>
32 #include <sstream>
33 
34 // mini headers
35 #include <ObjexxFCL/char.functions.hh>
36 #include <utility/exit.hh>
37 
38 #include <basic/Tracer.hh>
39 #include <basic/prof.hh>
40 
42 
45 #include <core/pose/util.hh>
46 #include <core/id/AtomID.hh>
47 #include <core/id/NamedStubID.hh>
54 #include <basic/options/option.hh>
55 #include <basic/options/keys/in.OptionKeys.gen.hh>
56 #include <core/pose/Pose.hh>
57 #include <core/pose/util.hh>
58 
59 #include <numeric/model_quality/rms.hh>
60 
61 // Boost headers
62 #include <boost/lexical_cast.hpp>
63 
64 //Auto Headers
65 #include <platform/types.hh>
66 #include <core/types.hh>
67 #include <core/chemical/AA.hh>
69 #include <core/chemical/Adduct.hh>
113 #include <core/id/AtomID.fwd.hh>
114 #include <core/id/AtomID_Map.fwd.hh>
115 #include <core/id/AtomID_Map.hh>
117 #include <core/id/DOF_ID.fwd.hh>
118 #include <core/id/DOF_ID.hh>
119 #include <core/id/DOF_ID_Map.fwd.hh>
122 #include <core/id/NamedAtomID.hh>
125 #include <core/id/TorsionID.fwd.hh>
126 #include <core/id/types.hh>
136 #include <core/kinematics/Edge.hh>
140 #include <core/kinematics/Jump.hh>
143 #include <core/kinematics/RT.fwd.hh>
144 #include <core/kinematics/RT.hh>
147 #include <core/kinematics/Stub.hh>
150 #include <core/pose/MiniPose.fwd.hh>
151 #include <core/pose/PDBInfo.fwd.hh>
152 #include <core/pose/Pose.fwd.hh>
154 #include <core/pose/util.tmpl.hh>
163 #include <core/scoring/ScoreType.hh>
166 #include <utility/Bound.fwd.hh>
167 #include <utility/Bound.hh>
168 #include <utility/down_cast.hh>
169 #include <utility/vector0_bool.hh>
170 #include <utility/vector1.fwd.hh>
171 #include <utility/vector1.hh>
172 #include <utility/vector1_bool.hh>
173 #include <utility/vectorL.fwd.hh>
174 #include <utility/vectorL.hh>
175 #include <utility/vectorL_Selector.hh>
176 #include <utility/vectorL_bool.hh>
177 #include <utility/file/FileName.fwd.hh>
178 #include <utility/file/FileName.hh>
179 #include <utility/file/PathName.fwd.hh>
180 #include <utility/file/PathName.hh>
181 #include <utility/keys/AutoKey.fwd.hh>
182 #include <utility/keys/AutoKey.hh>
183 #include <utility/keys/Key.fwd.hh>
184 #include <utility/keys/Key.hh>
185 #include <utility/keys/Key2Tuple.fwd.hh>
186 #include <utility/keys/Key2Tuple.hh>
187 #include <utility/keys/Key3Tuple.fwd.hh>
188 #include <utility/keys/Key3Tuple.hh>
189 #include <utility/keys/Key4Tuple.fwd.hh>
190 #include <utility/keys/Key4Tuple.hh>
191 #include <utility/keys/KeyLess.fwd.hh>
192 #include <utility/keys/KeyLookup.fwd.hh>
193 #include <utility/keys/KeyLookup.hh>
194 #include <utility/keys/NoClient.fwd.hh>
195 #include <utility/keys/NoClient.hh>
196 #include <utility/keys/SmallKeyVector.fwd.hh>
197 #include <utility/keys/SmallKeyVector.hh>
198 #include <utility/keys/UserKey.fwd.hh>
199 #include <utility/keys/VariantKey.fwd.hh>
200 #include <utility/keys/VariantKey.hh>
201 #include <utility/options/AnyOption.fwd.hh>
202 #include <utility/options/AnyOption.hh>
203 #include <utility/options/AnyVectorOption.fwd.hh>
204 #include <utility/options/AnyVectorOption.hh>
205 #include <utility/options/BooleanOption.fwd.hh>
206 #include <utility/options/BooleanOption.hh>
207 #include <utility/options/BooleanVectorOption.fwd.hh>
208 #include <utility/options/BooleanVectorOption.hh>
209 #include <utility/options/FileOption.fwd.hh>
210 #include <utility/options/FileOption.hh>
211 #include <utility/options/FileVectorOption.fwd.hh>
212 #include <utility/options/FileVectorOption.hh>
213 #include <utility/options/IntegerOption.fwd.hh>
214 #include <utility/options/IntegerOption.hh>
215 #include <utility/options/IntegerVectorOption.fwd.hh>
216 #include <utility/options/IntegerVectorOption.hh>
217 #include <utility/options/Option.fwd.hh>
218 #include <utility/options/Option.hh>
219 #include <utility/options/OptionCollection.fwd.hh>
220 #include <utility/options/OptionCollection.hh>
221 #include <utility/options/PathOption.fwd.hh>
222 #include <utility/options/PathOption.hh>
223 #include <utility/options/PathVectorOption.fwd.hh>
224 #include <utility/options/PathVectorOption.hh>
225 #include <utility/options/RealOption.fwd.hh>
226 #include <utility/options/RealOption.hh>
227 #include <utility/options/RealVectorOption.fwd.hh>
228 #include <utility/options/RealVectorOption.hh>
229 #include <utility/options/ScalarOption.fwd.hh>
230 #include <utility/options/ScalarOption.hh>
231 #include <utility/options/ScalarOption_T_.fwd.hh>
232 #include <utility/options/ScalarOption_T_.hh>
233 #include <utility/options/StringOption.fwd.hh>
234 #include <utility/options/StringOption.hh>
235 #include <utility/options/StringVectorOption.fwd.hh>
236 #include <utility/options/StringVectorOption.hh>
237 #include <utility/options/VariantOption.fwd.hh>
238 #include <utility/options/VariantOption.hh>
239 #include <utility/options/VectorOption.fwd.hh>
240 #include <utility/options/VectorOption.hh>
241 #include <utility/options/VectorOption_T_.fwd.hh>
242 #include <utility/options/VectorOption_T_.hh>
243 #include <utility/options/mpi_stderr.hh>
244 #include <utility/options/keys/AnyOptionKey.fwd.hh>
245 #include <utility/options/keys/AnyOptionKey.hh>
246 #include <utility/options/keys/AnyVectorOptionKey.fwd.hh>
247 #include <utility/options/keys/AnyVectorOptionKey.hh>
248 #include <utility/options/keys/BooleanOptionKey.fwd.hh>
249 #include <utility/options/keys/BooleanOptionKey.hh>
250 #include <utility/options/keys/BooleanVectorOptionKey.fwd.hh>
251 #include <utility/options/keys/BooleanVectorOptionKey.hh>
252 #include <utility/options/keys/FileOptionKey.fwd.hh>
253 #include <utility/options/keys/FileOptionKey.hh>
254 #include <utility/options/keys/FileVectorOptionKey.fwd.hh>
255 #include <utility/options/keys/FileVectorOptionKey.hh>
256 #include <utility/options/keys/IntegerOptionKey.fwd.hh>
257 #include <utility/options/keys/IntegerOptionKey.hh>
258 #include <utility/options/keys/IntegerVectorOptionKey.fwd.hh>
259 #include <utility/options/keys/IntegerVectorOptionKey.hh>
260 #include <utility/options/keys/OptionKey.fwd.hh>
261 #include <utility/options/keys/OptionKey.hh>
262 #include <utility/options/keys/OptionKeys.hh>
263 #include <utility/options/keys/PathOptionKey.fwd.hh>
264 #include <utility/options/keys/PathOptionKey.hh>
265 #include <utility/options/keys/PathVectorOptionKey.fwd.hh>
266 #include <utility/options/keys/PathVectorOptionKey.hh>
267 #include <utility/options/keys/RealOptionKey.fwd.hh>
268 #include <utility/options/keys/RealOptionKey.hh>
269 #include <utility/options/keys/RealVectorOptionKey.fwd.hh>
270 #include <utility/options/keys/RealVectorOptionKey.hh>
271 #include <utility/options/keys/ScalarOptionKey.fwd.hh>
272 #include <utility/options/keys/ScalarOptionKey.hh>
273 #include <utility/options/keys/StringOptionKey.fwd.hh>
274 #include <utility/options/keys/StringOptionKey.hh>
275 #include <utility/options/keys/StringVectorOptionKey.fwd.hh>
276 #include <utility/options/keys/StringVectorOptionKey.hh>
277 #include <utility/options/keys/VectorOptionKey.fwd.hh>
278 #include <utility/options/keys/VectorOptionKey.hh>
279 #include <utility/options/keys/all.hh>
280 #include <utility/pointer/ReferenceCount.fwd.hh>
281 #include <utility/pointer/ReferenceCount.hh>
282 #include <utility/pointer/access_ptr.fwd.hh>
283 #include <utility/pointer/access_ptr.hh>
284 #include <utility/pointer/owning_ptr.functions.hh>
285 #include <utility/pointer/owning_ptr.fwd.hh>
286 #include <utility/pointer/owning_ptr.hh>
287 #include <utility/signals/BufferedSignalHub.fwd.hh>
288 #include <utility/signals/BufferedSignalHub.hh>
289 #include <utility/signals/Link.fwd.hh>
290 #include <utility/signals/Link.hh>
291 #include <utility/signals/LinkUnit.fwd.hh>
292 #include <utility/signals/LinkUnit.hh>
293 #include <utility/signals/PausableSignalHub.fwd.hh>
294 #include <utility/signals/PausableSignalHub.hh>
295 #include <utility/signals/SignalHub.fwd.hh>
296 #include <utility/signals/SignalHub.hh>
297 #include <numeric/numeric.functions.hh>
298 #include <numeric/sphericalVector.fwd.hh>
299 #include <numeric/trig.functions.hh>
300 #include <numeric/types.hh>
301 #include <numeric/xyz.functions.fwd.hh>
302 #include <numeric/xyzMatrix.fwd.hh>
303 #include <numeric/xyzMatrix.hh>
304 #include <numeric/xyzVector.fwd.hh>
305 #include <numeric/xyzVector.hh>
306 #include <numeric/internal/ColPointers.hh>
307 #include <numeric/internal/ColVectors.hh>
308 #include <numeric/internal/ColsPointer.hh>
309 #include <numeric/internal/RowPointers.hh>
310 #include <numeric/internal/RowVectors.hh>
311 #include <numeric/internal/RowsPointer.hh>
312 #include <ObjexxFCL/Dimension.fwd.hh>
313 #include <ObjexxFCL/Dimension.hh>
314 #include <ObjexxFCL/DimensionExpression.hh>
315 #include <ObjexxFCL/DynamicIndexRange.fwd.hh>
316 #include <ObjexxFCL/DynamicIndexRange.hh>
317 #include <ObjexxFCL/FArray.fwd.hh>
318 #include <ObjexxFCL/FArray.hh>
319 #include <ObjexxFCL/FArray1.fwd.hh>
320 #include <ObjexxFCL/FArray1.hh>
321 #include <ObjexxFCL/FArray1A.fwd.hh>
322 #include <ObjexxFCL/FArray1A.hh>
323 #include <ObjexxFCL/FArray1D.fwd.hh>
324 #include <ObjexxFCL/FArray1D.hh>
325 #include <ObjexxFCL/FArray1P.fwd.hh>
326 #include <ObjexxFCL/FArray1P.hh>
327 #include <ObjexxFCL/FArray2.fwd.hh>
328 #include <ObjexxFCL/FArray2.hh>
329 #include <ObjexxFCL/FArray2A.fwd.hh>
330 #include <ObjexxFCL/FArray2A.hh>
331 #include <ObjexxFCL/FArray2D.fwd.hh>
332 #include <ObjexxFCL/FArray2D.hh>
333 #include <ObjexxFCL/FArray2P.fwd.hh>
334 #include <ObjexxFCL/FArray2P.hh>
335 #include <ObjexxFCL/FArrayInitializer.fwd.hh>
336 #include <ObjexxFCL/FArrayInitializer.hh>
337 #include <ObjexxFCL/FArraySection.fwd.hh>
338 #include <ObjexxFCL/FArraySection.hh>
339 #include <ObjexxFCL/FArrayTraits.fwd.hh>
340 #include <ObjexxFCL/FArrayTraits.hh>
341 #include <ObjexxFCL/Fstring.fwd.hh>
342 #include <ObjexxFCL/IndexRange.fwd.hh>
343 #include <ObjexxFCL/IndexRange.hh>
344 #include <ObjexxFCL/InitializerSentinel.hh>
345 #include <ObjexxFCL/Observer.fwd.hh>
346 #include <ObjexxFCL/Observer.hh>
347 #include <ObjexxFCL/ObserverMulti.hh>
348 #include <ObjexxFCL/ObserverSingle.hh>
349 #include <ObjexxFCL/ProxySentinel.hh>
350 #include <ObjexxFCL/SetWrapper.fwd.hh>
351 #include <ObjexxFCL/Star.fwd.hh>
352 #include <ObjexxFCL/Star.hh>
353 #include <ObjexxFCL/StaticIndexRange.fwd.hh>
354 #include <ObjexxFCL/StaticIndexRange.hh>
355 #include <ObjexxFCL/TypeTraits.hh>
356 #include <ObjexxFCL/byte.fwd.hh>
357 #include <ObjexxFCL/format.hh>
358 #include <ObjexxFCL/proxy_const_assert.hh>
359 #include <ObjexxFCL/string.functions.hh>
360 #include <ObjexxFCL/ubyte.fwd.hh>
361 #include <cassert>
362 #include <complex>
363 #include <cstddef>
364 #include <cstdio>
365 #include <iomanip>
366 #include <iosfwd>
367 #include <istream>
368 #include <limits>
369 #include <ostream>
370 #include <set>
371 #include <time.h>
372 #include <basic/MetricValue.fwd.hh>
373 #include <basic/Tracer.fwd.hh>
374 #include <basic/datacache/BasicDataCache.fwd.hh>
375 #include <basic/options/keys/OptionKeys.hh>
376 #include <basic/options/keys/run.OptionKeys.gen.hh>
377 #include <boost/bind.hpp>
378 #include <boost/function.hpp>
379 #include <boost/functional/hash.hpp>
380 
381 
382 //using namespace ObjexxFCL;
383 //using namespace ObjexxFCL::fmt;
384 
385 // option key includes
386 namespace core {
387 namespace io {
388 namespace silent {
389 
390 using namespace ObjexxFCL;
391 using namespace ObjexxFCL::fmt;
392 static basic::Tracer pss_tr("core.io.silent");
393 
394 //explciit instantiation
395 
396 //template class ProteinSilentStruct_Template<core::Real>;
397 //template class ProteinSilentStruct_Template<float>;
398 
399 
400 
401 template <class T>
402 void
404  core::pose::Pose const & pose,
405  std::string tag
406 ) {
407  basic::ProfileThis doit( basic::SILENT_FILL_STRUCT );
408  if ( !core::pose::is_ideal_pose(pose) ) {
409  // Barak 07/09 - non-ideal poses are currently not supported for PSS
410  // nor will they ever be!
411  pss_tr.Error << "ERROR: trying to use a 'protein' type silent file for a non-ideal pose" << std::endl;
412  pss_tr.Error << "consider using the '-out:file:silent_struct_type binary' flag" << std::endl;
413  // utility_exit();
414  }
415 
416  decoy_tag( tag );
417  if ( tag == "empty_tag" ) set_tag_from_pose( pose );
418 
419  using namespace core::chemical;
420  fullatom( pose.is_fullatom() );
421 
422  energies_from_pose( pose );
423 
424  // conformation information
425  sequence( pose.annotated_sequence( true /* show-all-variants */ ) );
426  resize( pose.total_residue() );
427  static const std::string important_atom = "CA";
428  for ( Size i = 1; i <= pose.total_residue(); ++i ) {
429  core::conformation::Residue const & resi = pose.residue(i);
430 
431  // skip VRT atoms
432  if ( ( resi.aa() == core::chemical::aa_vrt ) || ( resi.aa() == core::chemical::aa_unk ) ) {
433  phi ( i, 0.0 );
434  psi ( i, 0.0 );
435  omega ( i, 0.0 );
436  coords ( i, resi.xyz(1) ); // for non-standard polymer residue, output coord of the first atom ).
437  secstruct( i, 'L' );
438  if ( fullatom() ) {
439  //chi_[i].push_back(0.0);
440  for ( Size kk = 1; kk <= max_chi(); ++kk ) {
441  // give this non-standard residue 4 chi's if we're in fullatom mode.
442  chi( i, kk, 0.0 );
443  }
444  } // if ( fullatom )
445  } else {
446  phi ( i, resi.mainchain_torsion( 1 ) );
447  psi ( i, resi.mainchain_torsion( 2 ) );
448  omega ( i, resi.mainchain_torsion( 3 ) );
449  coords ( i, resi.xyz( important_atom ) );
450  secstruct( i, pose.secstruct(i) );
451  if ( fullatom() ) {
452  //chi_[i] = resi.chi();
453  for ( Size kk = 1; kk <= max_chi(); ++kk ) {
454  if ( resi.nchi() >= kk ) {
455  chi( i, kk, resi.chi(kk) );
456  }
457  }
458  } // if ( fullatom )
459  } // for ( unsigned int i = 1; i <= pose.total_residue(); ++i )
460  } // for ( Size i = 1; i <= pose.total_residue; ++i )
461  fold_tree( pose.fold_tree() );
462 
463  jumps_.clear();
464  for ( Size nr = 1; nr <= fold_tree().num_jump(); nr++) {
465  add_jump( pose.jump(nr) );
466  }
467 
468  chain_endings( pose.conformation().chain_endings() );
469 }
470 
471 template <class T>
473  utility::vector1< std::string > const & lines,
474  SilentFileData & container
475 ) {
476  bool success( false );
477 
478  utility::vector1< std::string > energy_names;
480  if ( iter->substr(0,9) != "SEQUENCE:" ) { //a full new header would change the default columns
481  // get sequence and scorename data from the silent-file data object, because I don't have it!
482  EnergyNamesOP enames = EnergyNamesOP(
483  static_cast< EnergyNames * > ( container.get_shared_silent_data( energynames )() )
484  );
485 
487  static_cast< SimpleSequenceData * > ( container.get_shared_silent_data( simplesequencedata )() )
488  );
489 
490  sequence ( seqdata->sequence() );
491  energy_names = enames ->energy_names();
492  } else {
493  // get sequence and scorename data from the first two lines provided, put
494  // them into container for further use by other ProteinSilentStruct
495  // objects.
496 
497  // first line is SEQUENCE:
498  if ( !read_sequence( *iter ) ) return false;
499  ++iter;
500  read_score_headers( *iter, energy_names, container ); ++iter;
501 
502  } // get header information
503 
504  // resize myself appropriately, according to length of sequence
505  Size const total_residue = one_letter_sequence().length();
506  resize( total_residue );
507  utility::vector1< bool > read_flag( total_residue, false ); //to check whether all seqpos have been filled with info
508  for ( utility::vector1< std::string >::const_iterator end = lines.end(); iter != end; ++iter ) {
509  std::string tag;
510  std::istringstream line_stream( *iter );
511 
512  if ( iter->substr(0,6) == "REMARK" ) {
513 // std::string tag;
514 // std::string comment;
515 // std::string value;
516 // runtime_assert( tag == "REMARK" );
517 // line_stream >> tag >> comment >> value;
518  comment_from_line( *iter );//add_comment( comment, value );
519  continue; // don't skip comments
520  }
521 
522  if ( iter->substr(0,7) == "SCORE: " ) { // SCORE: line with values from this structure.
523  resize( total_residue ); // sequence_ should be defined by now.
524 
525  std::string tag;
526  line_stream >> tag;
527  if ( line_stream.fail() || tag != "SCORE:" ) {
528  pss_tr.Error << "bad format in first score line of silent file" << std::endl;
529  pss_tr.Error << "line = " << *iter << std::endl;
530  pss_tr.Error << "tag = " << tag << std::endl;
531  }
532 
533  parse_energies( line_stream, energy_names );
534  } else { // conformation lines
535  // parse fold_tree and jump lines
536  if ( iter->substr(0,10) == "FOLD_TREE " ) {
538  line_stream >> f;
539  fold_tree( f ); // add fold-tree to this SilentStruct
540  pss_tr.Debug << "read fold-tree " << f; //"\n" is in fold-tree output
541  pss_tr.Debug << "reading " << f.num_jump() << " jumps " << std::endl;
542  continue;
543  } else if ( iter->substr(0,2) == "RT" ) {
544  kinematics::Jump jump;
545  line_stream >> jump;
546  pss_tr.Debug << "read jump " << jump << std::endl;
547  add_jump( jump );
548  bJumps_use_IntraResStub_ = false; // modern style jumps, defined completely with the FoldTree
549  continue;
550  } else if ( iter->substr(0,9) == "SEQUENCE:" ) {
551  pss_tr.Warning << "skipping duplicate sequence declaration " << std::endl;
552  //after a SEQUENCE declaration we might find another SCORE header that should be skipped, too...
554  if (( iter2 != end ) && iter2->substr(0,7) == "SCORE: " ) {
555  pss_tr.Warning << "re-reading score declaration from second line... " << std::endl;
556  read_score_headers( *iter2, energy_names, container );
557  ++iter;
558  }
559  continue;
560  } else if ( iter->substr(0,19) == "ANNOTATED_SEQUENCE:" ) {
561  std::string annotated_seq;
562  line_stream >> tag; //ANNOTATED_SEQUENCE
563  line_stream >> annotated_seq;
564  sequence( annotated_seq );
565  continue;
566  } else if ( iter->substr(0,4) == "JUMP" ) {
567  // support for rosetta++ silent files
568  std::string tag;
569  Size nr;
570  line_stream >> tag; //JUMP
571  line_stream >> nr;
572  if ( nr != fold_tree().num_jump() ) {
573  pss_tr.Warning << "WARNING: corrupted silent file read line JUMP X -- X ";
574  pss_tr.Warning << "should match number of jumps in FOLD_TREE " << std::endl;
575  }
576  for ( Size i = 1; i<= nr; i++ ) {
577  kinematics::Jump jump;
578  line_stream >> jump;
579  add_jump( jump );
580  }
581  bJumps_use_IntraResStub_ = true; // jump is defined via N-C-CA rosetta++ style
582  continue;
583  } else if ( iter->substr( 0, 13 ) == "CHAIN_ENDINGS" ) {
584  chain_endings_.clear();
585  parse_chain_endings( line_stream );
586  continue;
587  }
588 
589  // parse ss,torsions, and c-alpha coords
590  Size seqpos;
591  Real x, y, z, my_phi, my_psi, my_omega;
592  char ss;
593 
594  line_stream >> tag;
595  if ( !is_int( tag ) ) {
596  pss_tr.Error << "ERROR: !is_int( " << tag << " ) from line (" << *iter << ")" << std::endl;
597  pss_tr.Error << "Are you trying to read a binary silent file ? Use -in:file:silent_struct_type binary " << std::endl;
598  success = false;
599  return success;
600  }
601  //assert( is_int( tag ) ); // this tag should represent the sequence position within the silent-file
602  seqpos = int_of( tag );
603  if ( seqpos <= 0 || seqpos > nres() ) {
604  pss_tr.Error << "ERROR: incorrect sequence number " << seqpos << " (nres = "
605  << nres() << " ) from line (" << *iter << ")\n";
606  success = false;
607  return success;
608  } else {
609  read_flag[ seqpos ] = true;
610  }
611  line_stream >> ss >> my_phi >> my_psi >> my_omega >> x >> y >> z;
612  numeric::xyzVector< T > temp_vec( x, y, z );
613 
614  phi ( seqpos, my_phi );
615  psi ( seqpos, my_psi );
616  omega ( seqpos, my_omega );
617  secstruct( seqpos, ss );
618  coords ( seqpos, temp_vec );
619 
620  // Parse chi angles if this is a fullatom ProteinSilentStruct. Try to
621  // figure out if the file format is fullatom by measuring if the tag is a
622  // number.
623  line_stream >> tag;
624  Size chi_idx(1);
625  while ( !line_stream.fail() ) {
626  if ( is_float( tag ) ) {
627  fullatom( true );
628  //chis.push_back( float_of( tag ) );
629  if ( chi_idx > max_chi() ) {
630  pss_tr.Warning << "parse error (" << *iter << " ) " << tag << " has to many chi-angles" << std::endl;
631  success = false;
632  break;
633  }
634  chi( seqpos, chi_idx, float_of(tag) );
635  ++chi_idx;
636  }
637  //chi( seqpos, chis );
638  line_stream >> tag;
639  }
640 
641  if ( tag != decoy_tag() ) { // decoy_tag should be last tag.
642  pss_tr.Warning << "parse error(" << *iter << ") " << tag << " != " << decoy_tag() << std::endl;
643  success = false;
644  break;
645  }
646  } // conformation lines
647  } // for ( iter ... )
648 
649  if ( fold_tree().num_jump() != jumps_.size() ) {
650  pss_tr.Warning << "parse error: found only " << jumps_.size()
651  << " RT-lines for a fold-tree with " << fold_tree().num_jump()
652  << " for decoy tag " << decoy_tag() << std::endl;
653  return false;
654  }
655 
656  // check if each sequence-position has been set
658  = find( read_flag.begin(), read_flag.end(), false );
659 
660  if ( bad_pos != read_flag.end() ) {
661  pss_tr.Error << "ERROR: did not find coordinates for all sequence positions for "
662  << decoy_tag() << std::endl;
663  core::Size idx = 1;
664  for ( utility::vector1< bool >::iterator it = read_flag.begin(), end = read_flag.end();
665  it != end; ++it, ++idx
666  ) {
667  if ( !*it ) pss_tr.Error << "Couldn't read position " << idx << std::endl;
668  }
669  return false; //no success
670  }
671 
672  // if no fold-tree available generate a standard tree
673  if ( fold_tree().size() < 1 ) {
674  fold_tree_.simple_tree( nres() );
675  pss_tr.Debug << " generating simple fold-tree " << fold_tree();
676  }
677 
678  if ( bJumps_use_IntraResStub_ ) { //for rosetta++ file-format
679  //prepares of setting RT via N, CA, C
680  fold_tree_.put_jump_stubs_intra_residue();
681  //on could also think of making this a temporary change after read is finished
682  // return to a standard fold_tree...
683  }
684 
685  success = true;
686  return success;
687 } // init_from_lines
688 
689 template <class T>
690 void
692  Size const nres_in
693 ) {
694  nres( nres_in );
695  secstruct_.resize( nres() );
696  phi_ .resize( nres() );
697  psi_ .resize( nres() );
698  omega_ .resize( nres() );
699  coords_ .resize( nres() );
700  secstruct_.reserve( nres() );
701  phi_ .reserve( nres() );
702  psi_ .reserve( nres() );
703  omega_ .reserve( nres() );
704  coords_ .reserve( nres() );
705  fold_tree_.simple_tree( nres() );
706 
707  // chi_ is a little bit more dangerous, so it has its own method.
708  resize_chi();
709 } // resize
710 
711 template <class T>
712 void
714  // make sure that there are the appropriate
715  // number of chi angles in each position of
716  // the chi_ vector1.
717  chi_.resize( nres() );
718  chi_.reserve( nres() );
719  //for ( Size kk = 1; kk <= nres(); ++kk ) {
720  // if ( n_chi(kk) < max_chi() ) {
721  // chi_[ kk ].resize( max_chi(), 0.0 );
722  // }
723  //} // kk
724 } // resize_chi
725 
726 template <class T>
728  core::pose::Pose & pose
729 ) const {
730  using namespace core::chemical;
731  ResidueTypeSetCAP residue_set;
732  pss_tr.Debug << "fill_pose: SilentStruct is " << ( fullatom() ? "fullatom" : "centroid" ) << std::endl;
733  if ( fullatom() ) {
735  } else {
737  }
738  fill_pose( pose, *residue_set );
739 } // fill_pose
740 
741 template <class T>
743  core::pose::Pose & pose,
744  core::chemical::ResidueTypeSet const & residue_set
745 ) const {
746  basic::ProfileThis doit( basic::SILENT_FILL_POSE );
747  runtime_assert( nres() != 0 );
748  runtime_assert( sequence() != "" );
749  //fpd why was this called twice???
750  //if ( pose.annotated_sequence() != sequence() ) {
751  // core::pose::make_pose_from_sequence( pose, sequence(), residue_set );
752  //}
753  //if ( pss_tr.Debug.visible() ) pss_tr.Debug << "FOLD TREE: " << fold_tree();
754  core::pose::make_pose_from_sequence( pose, sequence(), residue_set );
755  pss_tr.Debug << "FOLD TREE: " << fold_tree();
756 
757  // set fold_tree
758  pose.fold_tree( fold_tree() );
759 
760  // set jumps
761  for ( Size nr = 1; nr <= fold_tree().num_jump(); nr++) {
762  if ( !bJumps_use_IntraResStub_ ) { //default modern file-format
763  pose.set_jump( nr, jump( nr ) );
764  } else { //support for rosetta++ format
765  Size start = fold_tree().jump_edge( nr ).start();
766  Size stop = fold_tree().jump_edge( nr ).stop();
767  id::StubID up_stub( pose::named_stub_id_to_stub_id( id::NamedStubID("CA", "N", "CA", "C", start < stop ? start : stop ), pose ));
768  id::StubID down_stub( pose::named_stub_id_to_stub_id( id::NamedStubID("CA", "N", "CA", "C", start < stop ? stop : start ), pose ));
769  pose.conformation().set_stub_transform( up_stub, down_stub, jump( nr ) );
770  }
771  }
772 
773 
774  if ( nres() != one_letter_sequence().length() ) {
775  utility_exit_with_message( "RuntimeAssert failed: nres() == one_letter_sequence().length()" );
776  }
777 
778  { basic::ProfileThis doit( basic::SILENT_SET_POSE_COORDS );
779  // angles and secondary structure
780  for ( Size seqpos = 1; seqpos <= nres(); ++seqpos ) {
781  if ( pose.residue_type(seqpos).is_protein() ) { //skip non-protein residues //ask for type to avoid updateing of coords.
782  pose.set_phi ( seqpos, phi (seqpos) );
783  pose.set_psi ( seqpos, psi (seqpos) );
784  pose.set_omega ( seqpos, omega(seqpos) );
785  if ( fullatom() ) {
786  for ( Size jj = 1,
787  end = std::min( pose.residue_type(seqpos).nchi(), n_chi(seqpos) );
788  jj <= end; ++jj
789  ) {
790  pose.set_chi( jj, seqpos, chi(seqpos,jj) );
791  }
792  } // if ( fullatom() )
793  } // skip non-protein residues
794  pose.set_secstruct( seqpos, secstruct(seqpos) );
795  }
796 
797  if ( !chain_endings().empty() ) {
798  pose.conformation().chain_endings( chain_endings() );
799  }
800  } //Profile scope
801 
803 
804  finish_pose( pose );
805 } // fill_pose
806 
807 
808 template <class T>
809 void ProteinSilentStruct_Template<T>::print_conformation( std::ostream & output ) const {
810  // fold tree
811  output << "REMARK PROTEIN SILENTFILE";
812  if ( is_single_precision() ) output << " SINGLE_PRECISION\n";
813  else output << "\n";
814  if ( fold_tree().size() > 1 ) { //assume non-trivial fold_tree only if more than one edge, i.e., EDGE 1 <nres> -1
815  output << "FOLD_TREE ";
816  for ( kinematics::FoldTree::const_iterator it = fold_tree().begin(), it_end = fold_tree().end();
817  it != it_end; ++it ) {
818  output << *it;
819  }
820  // output << fold_tree(); this produces a new-line --- wrong behaviour of fold_tree but I don't want to fix 1000 u-tracer unit-tests!
821  output << ' ' << decoy_tag() << "\n";
822  }
823  for ( Size i = 1; i <= fold_tree().num_jump(); i++ ) {
824  output << jump( i ) << ' ' << decoy_tag() << "\n";
825  }
826 
827  // sequence
828  output << "ANNOTATED_SEQUENCE: " << sequence() << " " << decoy_tag() << "\n"; // print annotated_sequence per decoy
829 
830  // chain endings
831  if ( !chain_endings().empty() ) {
832  output << chain_endings_str() << ' ' << decoy_tag() << '\n';
833  }
834 
835  // the actual dihedral/coordinate info
836  //pss_tr.Debug << "FOLD_TREE Size: " << fold_tree().size() << " " << fold_tree() << std::endl;
837  for ( Size i = 1; i <= nres(); ++i ) {
838  output
839  << I( 4, i ) << ' '
840  << secstruct(i) << ' '
841  << F( 9, 3, phi(i) )
842  << F( 9, 3, psi(i) )
843  << F( 9, 3, omega(i) )
844  << F( 9, 3, coords(i).x() )
845  << F( 9, 3, coords(i).y() )
846  << F( 9, 3, coords(i).z() );
847 
848  if ( fullatom() ) {
849  for ( Size chino = 1; chino <= max_chi(); ++chino ) {
850  Real chi_to_print = 0.0;
851  if ( chino <= n_chi(i) ) {
852  chi_to_print = chi(i,chino);
853  }
854  output << F( 9, 3, chi_to_print );
855  }
856  } // if fullatom()
857 
858  output << ' ' << decoy_tag();
859  output << "\n";
860  } // for ( Size i = 1; i <= nres; ++i )
861 } // print_conformation
862 
863 template <class T>
865  pose::Pose temp_pose;
866  FArray2D< Real > rebuilt_coords (3, coords_.size() ), original_coords( 3, coords_.size() );
867  static std::string atom_name = "CA";
868 
869  // build temp_pose from coordinates
870  fill_pose( temp_pose );
871 
872  for ( Size i = 1; i <= temp_pose.total_residue(); ++i ) {
873  for ( Size k = 1; k <= 3; ++k ) { // k = X, Y and Z
874  rebuilt_coords (k,i) = temp_pose.residue(i).xyz( atom_name )[k-1];
875  original_coords(k,i) = coords_[i][k-1];
876  }
877  }
878 
879  Real rmsd = numeric::model_quality::rms_wrapper( temp_pose.total_residue(), rebuilt_coords, original_coords );
880  return rmsd;
881 }
882 
883 template <class T>
884 ObjexxFCL::FArray2D< Real >
886  core::Size n_residues = nres();
887  FArray2D< Real > my_coords( 3, n_residues );
888  for ( Size i = 1; i <= n_residues; ++i ) { // i = n_residues
889  for ( Size k = 1; k <= 3; ++k ) { // k = X, Y and Z
890  my_coords(k,i) = coords_[i][k-1];
891  } // k
892  } // i
893 
894  return my_coords;
895 } // get_CA_positions
896 
897 template <class T>
899  FArray2D< Real > my_coords = get_CA_xyz();
900  FArray2D< Real > other_coords = other_pss.get_CA_xyz();
901  Real rmsd = numeric::model_quality::rms_wrapper( nres(), my_coords, other_coords );
902 
903  return rmsd;
904 } // ProteinSilentStruct_Template<T>::CA_rmsd
905 
906 template <class T>
909 )
910 {
911  resize( src.nres() );
912 
913  // per-residue conformation information
914  for ( Size i = 1; i <= nres(); ++i ) {
915  phi ( i, src.phi(i) );
916  psi ( i, src.psi(i) );
917  omega ( i, src.omega(i) );
918  coords ( i, src.coords(i) );
919  secstruct( i, src.secstruct(i) );
920  }
921 
922  // fold-tree and jumps
923  for ( Size jj = 1; jj <= src.njumps(); ++jj ) {
924  add_rt( src.jump(jj) );
925  }
926  fold_tree( src.fold_tree() );
927 
928  chain_endings( src.chain_endings() );
929 
930  // add energy copying here
931 
932  return *this;
933 }
934 
935 /// @brief parse the chain endings string from an input stream
936 template <class T>
938  std::string s;
939  stream >> s; // first column is "CHAIN_ENDINGS" tag, skip it
940 
942  while ( stream.good() ) {
943  stream >> s;
944  v.push_back( s );
945  }
946 
947  // remember to skip the last entry in the vector, which is the structure's nametag
948  for ( Size i = 1, ie = v.size(); i < ie; ++i ) {
949  add_chain_ending( boost::lexical_cast< Size >( v[ i ] ) );
950  }
951 }
952 
953 /// @brief return the chain endings string
954 template <class T>
956  std::ostringstream ss;
957  ss << "CHAIN_ENDINGS ";
958 
959  for ( utility::vector1< Size >::const_iterator i = chain_endings().begin(), ie = chain_endings().end(); i != ie; ++i ) {
960  ss << ' ' << (*i);
961  }
962 
963  return ss.str();
964 }
965 
966 template <class T>
968  for ( utility::vector1< Size >::const_iterator i = endings.begin(), ie = endings.end(); i != ie; ++i ) {
969  if ( (*i) < 1 || (*i) > nres() ) {
970  pss_tr.Fatal << "ERROR: chain_endings() invalid chain ending " << (*i) << std::endl;
971  utility_exit();
972  }
973  }
974 
975  chain_endings_ = endings;
976  std::sort( chain_endings_.begin(), chain_endings_.end() ); // keep the list sorted
977 }
978 
979 template <class T>
981  if ( seqpos < 1 || seqpos >= nres() ) {
982  pss_tr.Fatal << "ERROR: add_chain_ending() invalid chain ending " << seqpos << std::endl;
983  utility_exit();
984  }
985 
986  chain_endings_.push_back( seqpos );
987  std::sort( chain_endings_.begin(), chain_endings_.end() ); // keep the list sorted
988 }
989 
990 template <class T>
991 Real ProteinSilentStruct_Template<T>::chi( Size const seqpos, Size const chi_num ) const {
992  // error checking.
993  if ( chi_num > max_chi() ) {
994  std::string const msg(
995  "Error: trying to chi " + string_of(chi_num) +
996  " when max_chi is " + string_of( max_chi() ) + '\n'
997  );
998  utility_exit_with_message( msg );
999  }
1000 
1001  // super-safe check to make sure that we don't return a memory access
1002  // violation on platforms like Windows in release mode.
1003  if ( chi_num > n_chi(seqpos) ) {
1004  pss_tr.Error << "Error: attempting to access chi that doesn't exist!"
1005  << "(chi = " << chi_num << " seqpos = " << seqpos << ")"
1006  << std::endl;;
1007  return 0.0;
1008  }
1009  return chi_[seqpos][chi_num];
1010 }
1011 
1012 template <class T>
1013 void ProteinSilentStruct_Template<T>::chi( Size const seqpos, Size const chi_num, Real const chi ) {
1014  // error checking.
1015  if ( chi_num > max_chi() ) {
1016  std::string const msg(
1017  "Error: trying to set chi " + string_of(chi_num) +
1018  " when max_chi is " + string_of( max_chi() ) + '\n'
1019  );
1020  utility_exit_with_message( msg );
1021  }
1022 
1023  if ( chi_num > chi_[seqpos].size() ) {
1024  chi_[seqpos].resize( chi_num );
1025  }
1026 
1027  chi_[seqpos][chi_num] = chi;
1028 } // chi
1029 
1030 /// @brief returns the number of chis at this position.
1031 template <class T>
1033  return chi_[seqpos].size();
1034 }
1035 
1036 template <class T>
1038  chi_[seqpos] = chis;
1039 }
1040 
1041 template <class T>
1043  return max_chi_;
1044 }
1045 /// end accessors
1046 
1047 
1048 template <class T>
1050  typedef typename utility::vector1< utility::vector1< T > >::const_iterator chi_iterator;
1051  T var;
1052  core::Size sum=
1053  sizeof(char)* secstruct_.capacity() +
1054  sizeof(var)* phi_.capacity() +
1055  sizeof(var)* psi_.capacity() +
1056  sizeof(var)* omega_.capacity() +
1057  sizeof( numeric::xyzVector< T > )* coords_.capacity() +
1058  sizeof(kinematics::RT)* jumps_.capacity()+
1059  sizeof(Size) * chain_endings_.capacity()+
1060  sizeof( fold_tree_ ) +
1061  sizeof( symminfo_ );
1062  for( chi_iterator it = chi_.begin(); it < chi_.end(); ++it ) sum += (*it).capacity() * sizeof( T ) ;
1063  return sum;
1064 }
1065 
1066 
1067 
1068 
1069 } // namespace silent
1070 } // namespace io
1071 } // namespace core
1072 
1073 #endif
1074