Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
make_loops.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 /// @brief general functions for generating typical kinds of Loops sets.
11 /// @author ashworth
12 
14 #include <protocols/loops/Loops.hh>
15 
16 #include <core/chemical/AA.hh>
18 #include <core/pose/Pose.hh>
19 #include <core/pose/PDBInfo.hh>
20 #include <basic/Tracer.hh>
21 
22 // AUTO-REMOVED #include <numeric/random/random.hh>
23 // AUTO-REMOVED #include <utility/vector1.hh>
24 #include <utility/exit.hh>
25 
26 #include <algorithm>
27 
28 #include <utility/vector1.hh>
29 #include <numeric/random/random.fwd.hh>
30 
31 //Auto Headers
32 
33 
34 
35 namespace protocols {
36 namespace loops {
37 
38 using namespace core;
39 using namespace chemical;
40 using utility::vector1;
41 
42 using basic::t_info;
43 using basic::t_debug;
44 using basic::t_trace;
45 static basic::Tracer TR( "protocols.loops.make_loops", t_info );
46 
47 void add_loop(
48  Size seg_begin,
49  Size seg_end,
50  pose::Pose const & pose,
51  loops::Loops & loops
52 )
53 {
54  if ( seg_begin >= seg_end || pose.chain( seg_begin ) != pose.chain( seg_end ) ) {
55  TR(t_info) << "WARNING: skipping segment with illegal beginning/ending: ";
56  if ( pose.pdb_info() ) {
57  pose::PDBInfo const & pdb( *pose.pdb_info() );
58  TR(t_info) << pdb.chain(seg_begin) << "." << pdb.number(seg_begin) << "."
59  << pose.residue_type(seg_begin).name3() << "/"
60  << pdb.chain(seg_end) << "." << pdb.number(seg_end) << "."
61  << pose.residue_type(seg_end).name3() << std::endl;
62  } else {
63  TR(t_info) << pose.chain(seg_begin) << "." << seg_begin << "."
64  << pose.residue_type(seg_begin).name3() << "/"
65  << pose.chain(seg_end) << "." << seg_end << "."
66  << pose.residue_type(seg_end).name3() << std::endl;
67  }
68  return;
69  }
70  Size const length( seg_end - seg_begin );
71  // random cutpoint - needs to be "seg_start < cut < seg_end"
72  Size cut(0), safety(0);
73  // ensure (cutpoint+1) is not a proline, as this will cause problems (?)
74  while ( safety < 100 && ( cut == 0 || pose.residue_type( cut+1 ).aa() == aa_pro ) ) {
75  cut = seg_begin + static_cast< Size >( numeric::random::uniform() * ( length ) );
76  ++safety;
77  }
78  runtime_assert( pose.residue_type( cut+1 ).aa() != aa_pro );
79 
80  if ( pose.pdb_info() ) {
81  pose::PDBInfo const & pdb( *pose.pdb_info() );
82  TR(t_info) << "adding segment: " << pdb.number( seg_begin ) << "-(" << pdb.number( cut ) << ")-"
83  << pdb.number( seg_end ) << " Chain " << pdb.chain( seg_end ) << std::endl;
84  } else {
85  TR(t_info) << "adding segment: " << seg_begin << "-(" << cut << ")-" << seg_end <<
86  " Chain " << pose.chain( seg_end ) << std::endl;
87  }
88 
89  loops.add_loop( seg_begin, seg_end, cut, 0, false );
90 }
91 
92 ///@brief add a set of loops 'built' around the provided residue indices
93 ///@details A maximum of gapsize residues are allowed between specified residues for any given loop, loop ends are extended by extend residues, and chain discontinuity starts a new loop
94 ///@author ashworth
96  loops::Loops & loops,
97  pose::Pose const & pose,
98  vector1< Size > const & residue_indices,
99  Size gapsize /* = 6 */,
100  Size extend /* = 2 */
101 )
102 {
103  if ( residue_indices.empty() ) {
104  TR(t_info) << "WARNING: no residues provided--can not define any loops" << std::endl;
105  return;
106  }
107  // loops should be empty, in order to guarantee no overlap
108  runtime_assert( loops.num_loop() == 0 );
109  // loop ends should be extended by at least 1 residue on each end
110  runtime_assert( extend >= 1 );
111  core::conformation::Conformation const & conf( pose.conformation() );
112  Size seg_begin( residue_indices.front() ), seg_end( residue_indices.front() );
113  int last_chain( pose.chain( residue_indices.front() ) );
114  Size const nres( pose.total_residue() );
115  for ( vector1< Size >::const_iterator index( residue_indices.begin() );
116  index != residue_indices.end(); ++index ) {
117  runtime_assert( *index > 0 );
118  runtime_assert( *index <= nres );
119  int const chain( pose.chain(*index) );
120  Size const chain_begin( chain > 0 ? conf.chain_begin( chain ) : 1 ),
121  chain_end( chain > 0 ? conf.chain_end( chain ) : nres );
122  // subtracting from unsigned ints is dangerous!
123  Size begin(*index);
124  for ( Size i(1); i <= extend; ++i ) {
125  if ( begin == chain_begin ) break;
126  begin -= 1;
127  }
128  Size const end( std::min( chain_end, *index + extend ) );
129  TR(t_trace) << *index << " ch " << chain << " chbgn " << chain_begin << " chend " << chain_end << " bgn " << begin << " end " << end << std::endl;
130  // first residue always opens a segment
131  if ( index == residue_indices.begin() ) {
132  seg_begin = begin;
133  // residue closes open segment and opens a new one only if gapsize is exceeded, or new chain
134  } else if ( begin > seg_end + gapsize || chain != last_chain ) {
135  // note: adds loop ending on previous residue, not current one
136  add_loop( seg_begin, seg_end, pose, loops );
137  seg_begin = begin;
138  }
139  seg_end = end;
140  last_chain = chain;
141  // last residue always closes last segment
142  if ( index + 1 == residue_indices.end() ) add_loop( seg_begin, seg_end, pose, loops );
143  }
144 }
145 
146 } //namespace loops
147 } //namespace protocols
148