Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
StrandConstraints.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 /// @author Oliver Lange
11 
12 // Unit Headers
14 
15 // Package Headers
17 // AUTO-REMOVED #include <protocols/abinitio/Template.hh>
18 // AUTO-REMOVED #include <protocols/abinitio/Templates.hh>
19 // AUTO-REMOVED #include <protocols/abinitio/TemplateJumpSetup.hh>
20 
21 // Project Headers
22 #include <core/types.hh>
23 
24 // AUTO-REMOVED #include <core/pose/Pose.hh>
25 #include <core/pose/util.hh>
26 // AUTO-REMOVED #include <core/io/pdb/pose_io.hh>
27 
28 // AUTO-REMOVED #include <core/kinematics/MoveMap.hh>
29 #include <core/id/AtomID.hh>
30 #include <core/id/NamedAtomID.hh>
31 
32 // AUTO-REMOVED
33 // AUTO-REMOVED #include <core/chemical/ChemicalManager.hh>
34 
35 // AUTO-REMOVED #include <core/fragment/FragSet.fwd.hh>
36 // AUTO-REMOVED #include <core/fragment/ConstantLengthFragSet.hh>
37 // AUTO-REMOVED #include <core/fragment/FragData.hh> //to get secondary structure
38 // AUTO-REMOVED #include <core/fragment/SecstructSRFD.hh> //to get secondary structure
39 // AUTO-REMOVED #include <core/fragment/FragID_Iterator.hh>
40 
42 // AUTO-REMOVED #include <core/scoring/constraints/ConstraintIO.hh>
43 // AUTO-REMOVED #include <core/scoring/constraints/ConstraintSet.hh>
47 
48 // AUTO-REMOVED #include <core/sequence/util.hh>
49 // AUTO-REMOVED #include <core/id/SequenceMapping.hh>
50 
51 // AUTO-REMOVED #include <basic/options/option.hh>
52 // AUTO-REMOVED #include <core/fragment/SecondaryStructure.hh>
53 // AUTO-REMOVED #include <protocols/jumping/JumpSample.hh>
54 
55 #ifdef WIN32
57 #endif
58 
59 
60 
61 //numeric headers
62 // AUTO-REMOVED #include <numeric/random/random.hh>
63 
64 // ObjexxFCL Headers
65 
66 // Utility headers
67 // AUTO-REMOVED #include <utility/io/izstream.hh>
68 // AUTO-REMOVED #include <utility/io/ozstream.hh>
69 // AUTO-REMOVED #include <utility/vector1.hh>
70 #include <basic/Tracer.hh>
71 
72 // C++ headers
73 #include <cstdlib>
74 #include <string>
75 #include <vector>
76 
77 #include <utility/vector1.hh>
78 
79 
80 
81 static basic::Tracer tr("protocols.abinitio.StrandConstraints");
82 using namespace core;
83 using namespace basic;
84 
85 
86 namespace protocols {
87 namespace abinitio {
88 
89 /// @details Auto-generated virtual destructor
90 StrandConstraints::~StrandConstraints() {}
91 
92 //using namespace jumping;
93 
95 Size residue_cutoff( 5 );
96 
97 //static numeric::random::RandomGenerator RG(1123123544); // <- Magic number, do not change it!
99 bool AlternativePairings::compatible( core::scoring::dssp::StrandPairing const& strand_pairing ) const {
100  if ( pairings_.size() == 0 ) return true;
101  if ( strand_pairing.antiparallel() != antiparallel() ) return false;
102  Size const new_reg ( strand_pairing.get_register() );
103 
104  //get list of pairs for all pairings that roughly match the register of the new strand_pairing
105  for ( Pairings::const_iterator it=pairings_.begin(), eit = pairings_.end();
106  it!=eit; ++it ) {
107  //check register
108  Size const reg ( it->pairing().get_register() );
109  if ( std::abs( (int)new_reg - (int)reg ) > (int)register_cutoff ) return false;
110  //good register... get residues
111  if ( (int) strand_pairing.end1() < ( (int) it->pairing().begin1() - (int) residue_cutoff ) ) return false; //really no overlap
112  if ( strand_pairing.begin1() > it->pairing().end1() + residue_cutoff ) return false;
113  }
114  // should one also check the begin2, end2 residues?
115 
116  /*at this point:
117  register match up to register_cutoff_
118  if none of the staring residues overlap the gap between is at least smaller than residue_cutoff_
119  */
120  return true;
121 }
122 
123 bool AlternativePairings::add_pairing( PairingStatEntry const& pairing_entry ) {
124  for ( Pairings::const_iterator it = pairings_.begin(), eit = pairings_.end();
125  it != eit; ++it ) {
126  it->has_model( pairing_entry.models()[ 1 ] );
127  }
128  if ( compatible( pairing_entry.pairing() ) ) {
129  anti_ = pairing_entry.pairing().antiparallel();
130  pairings_.push_back( pairing_entry );
131  //evtl have to make sure that I don't add "mergeable" pairings.
132  return true;
133  };
134  return false;
135 }
136 
137 void AlternativePairings::show( std::ostream& out ) const {
138  out << "\n\n Set of alternative strand pairings: \n";
139  for ( Pairings::const_iterator it = pairings_.begin(), eit = pairings_.end();
140  it!=eit; ++it ) {
141  out << it->weight() << " " << it->pairing() << " ";
142  for ( PairingStatEntry::ModelList::const_iterator mit = it->models().begin(), emit = it->models().end();
143  mit != emit; ++mit ) {
144  out << *mit << " ";
145  }
146  out << "\n";
147  }
148 }
149 
150 
151 void AlternativePairings::build_constraints( pose::Pose const& pose, scoring::constraints::ConstraintCOPs& pairing_csts ) const {
152  using namespace core::scoring::constraints;
153  using namespace core::id;
154 
155  //we only constrain the most "visited" residues of a strand ( as seen from the start -- for now)
156  // example residue 54 55 56 57 58 59 60 61 62
157  // freq 1 2 4 4 4 4 3 2 1
158  // from strands going: 54-60, 55-59, 56-62, 56-61
159  // might be a problem, that I don't consider where the beta-pairing goes to...
160 
161  // constraints on residues 56 57 58 59
162 
163  // thought about two ways to make the constraints:
164  // 1) CA-CA with lengths 4.2-4.7 for A O
165  // 5.0-5.7 for A I
166  // 4.5-5.1 for P
167 // HarmonicFunc const CAfuncAO( 4.45, 0.5 ); //pleating I, 2
168 // HarmonicFunc const CAfuncAI 5.35, 0.7 ); //pleating O, 1
169 // HarmonicFunc const CAfuncP( 4.8, 0.6 ); //all pleatings
170 
171  BoundFunc const CAfuncAO( 4.2, 4.8, 0.2, "STRAND_AO" ); //anti - pleating O, 1
172  BoundFunc const CAfuncAI( 5.0, 5.7, 0.3, "STRAND_AI" ); //anti - pleating I, 2
173  BoundFunc const CAfuncP( 4.5, 5.1, 0.3, "STRAND_P" ); //para - all pleatings
174 
175  // 2) N-O(=C) constraints of 2.8-2.95A
176  // for A I residue n constrain N-O of n+1 and O-N n-1
177  // for A O residue n constrain N-O of n and O-N of n
178  // for P ...
179  HarmonicFunc const NOfunc( 2.875, 0.2 ); //pretty much the same for all different pleatings
180 
181  // Although 2) will give tighter constraints it might have the disadvantage that it creates high-energy barriers between
182  // different registers: going from reg N -> N+1 requires change of pleating for one residue.
183  // the N-O group has to come around fro// m the other side of the strand... that might be bad.
184  //find frequency of start residues
185  std::map< Size, Real > freq; //it will count the score values
186  Real max_freq( 0 );
187  for ( Pairings::const_iterator it = pairings_.begin(), eit = pairings_.end();
188  it != eit; ++it ) {
189  Size const start( it->pairing().begin1() );
190  Size const end( it->pairing().end1() );
191  for ( Size pos = start; pos <= end; pos++ ) {
192  if ( ! it->pairing().is_bulge( pos ) ) freq[ pos ] += it->weight();
193  if ( max_freq < freq[ pos ] ) max_freq = freq[ pos ];
194  }
195  }
196 
197  //*** no constraints if we don't have any confidence ***
198  if ( max_freq <= 10 ) return;
199 
200 
201  //for each start position
202  for ( std::map< Size, Real>::const_iterator it = freq.begin(), eit = freq.end();
203  it != eit; ++it ) {
204 
205  // is frequency == max_freq ?
206  if ( it->second >= max_freq * 0.8 ) {
207  //yes: a pairing that we want to enforce
208 
209  // start-atom
210  Size pos( it->first );
211  NamedAtomID atom1( "CA", pos );
212 
213  //make ambigous constraint with one distance constraint for each pairing
214  ConstraintCOPs constraints;
215  std::map< Size, bool > done;
216 
217  //for all end-atoms:
218  for ( Pairings::const_iterator pit = pairings_.begin(), epit = pairings_.end();
219  pit != epit; ++pit ) {
220  Size pair( pit->pairing().get_pair( pos ) );
221  if ( pair ) { //we have a pairing make a constraint for this guy
222  if ( !done[ pair ] ) {
223  done[ pair ] = true;
224  NamedAtomID atom2( "CA", pair );
225 
226  //get distance-function parameters right
227  FuncOP myfunc;
228  if ( pit->pairing().antiparallel() ) {
229  if ( pit->pairing().get_pleating( pos ) == 2 ) { // Inward
230  myfunc = CAfuncAI.clone();
231  } else { // Outward
232  myfunc = CAfuncAO.clone();
233  } //pleating
234  } else { //not anti-parallel
235  myfunc = CAfuncP.clone();
236  }
237 
238  //make the constraint
239  tr.Debug << " add constraint for " << pos << "->" << pair << " " << pit->pairing().get_pleating( pos ) << std::endl;
240  constraints.push_back( new AtomPairConstraint(
243  myfunc ) );
244 
245  }
246  }// if ( pair )
247  } //for Pairings
248  // AmbiguousConstraint test_cst( constraints );
249  // test_cst.show_def( tr.Info, pose );
250 
251  pairing_csts.push_back( new AmbiguousConstraint( constraints ) );
252  } // if freq == max_freq
253  } // for each start position
254 }
255 
256 std::ostream& operator<< ( std::ostream& out, AlternativePairings const& alt_pairs ) {
257  alt_pairs.show( out );
258  return out;
259 }
260 
261 void StrandConstraints::add_pairing( core::scoring::dssp::StrandPairing const& pairing, std::string model ) {
262  add_pairing( PairingStatEntry( pairing, model ) );
263 }
264 
265 void StrandConstraints::add_pairing( PairingStatEntry const& pairing_entry ) {
266  bool success( false );
267  tr.Debug << "add pairing to FuzzyTopology "<< pairing_entry << std::endl;
268  for ( FuzzyTopology::iterator it = fuzzy_topology_.begin(), eit = fuzzy_topology_.end();
269  it != eit && !success; ++it ) {
270  success = it->add_pairing( pairing_entry );
271  }
272  if ( !success ) {
273  AlternativePairings new_strand;
274  new_strand.add_pairing( pairing_entry );
275  fuzzy_topology_.push_back( new_strand );
276  }
277 }
278 
279 
280 StrandConstraints::StrandConstraints( PairingStatistics const& strand_stats ) {
281  for ( PairingStatistics::const_iterator it = strand_stats.begin(), eit = strand_stats.end();
282  it != eit; ++it ) {
283  add_pairing( it->second );
284  }
285  tr.Info << (*this) << std::endl;
286 }
287 
288 void StrandConstraints::show( std::ostream& out ) const {
289  for (FuzzyTopology::const_iterator it = fuzzy_topology_.begin(), eit = fuzzy_topology_.end();
290  it != eit; ++it ) {
291  it->show( out );
292  }
293 }
294 
295 scoring::constraints::ConstraintCOPs StrandConstraints::build_constraints( pose::Pose const& pose ) const {
296  scoring::constraints::ConstraintCOPs all_constraints;
297  for (FuzzyTopology::const_iterator it = fuzzy_topology_.begin(), eit = fuzzy_topology_.end();
298  it != eit; ++it ) {
299  it->build_constraints( pose, all_constraints );
300  }
301 
302 // for ( scoring::constraints::ConstraintCOPs::iterator it = all_constraints.begin(), eit = all_constraints.end();
303 // it != eit; ++it ) {
304 // (*it)->show_def( tr.Info, pose );
305 // }
306 
307  return all_constraints;
308 }
309 
310 std::ostream& operator<< ( std::ostream& out, StrandConstraints const& st ) {
311  st.show( out );
312  return out;
313 }
314 
315 
316 }
317 }