Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
SequenceClaimer.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 TopologyBroker
11 /// @brief top-class (Organizer) of the TopologyBroker mechanism
12 /// @detailed responsibilities:
13 /// @author Oliver Lange
14 
15 // Unit Headers
17 
18 // Package Headers
21 // Project Headers
23 
25 #include <core/pose/Pose.hh>
26 // AUTO-REMOVED #include <core/pose/util.hh>
27 // ObjexxFCL Headers
28 
29 // Utility headers
30 #include <core/sequence/util.hh>
32 
33 
34 // utility
35 #include <basic/Tracer.hh>
36 #include <utility/excn/Exceptions.hh>
37 #include <basic/options/option.hh>
38 #include <basic/options/keys/in.OptionKeys.gen.hh>
39 
41 #include <utility/vector1.hh>
42 
43 #ifdef WIN32
44 #include <iterator>
45 #endif
46 
47 static basic::Tracer tr("protocols.topo_broker",basic::t_info);
48 
49 namespace protocols {
50 namespace topology_broker {
51 
52 using namespace core;
54  sequence_( "NO_SEQUENCE" ),
55  rsd_type_set_( core::chemical::CENTROID ),
56  offset_( 0 ),
57  nr_res_( 0 )
58 {}
59 
60 SequenceClaimer::SequenceClaimer( std::string const& sequence, std::string const& rsd_type_set_identifier, std::string label ) :
61  rsd_type_set_( rsd_type_set_identifier ),
62  offset_( 0 )
63 {
64  set_sequence( sequence );
65  set_label( label );
66 }
67 
69 {
70  return new SequenceClaimer( *this );
71 }
72 
73 
75  sequence_ = str;
76  pose::Pose my_pose;
77  tr.Info << "make pose from sequence: " << str << std::endl;
79  my_pose,
80  sequence_,
81  *( chemical::ChemicalManager::get_instance()->residue_type_set( rsd_type_set_ ))
82  );
84  nr_res_ = my_pose.total_residue();
85 }
86 
88 
89  new_claims.push_back( new SequenceClaim( this, 1, nr_res_, label(), DofClaim::INIT /* for now... eventually CAN_INIT ? */ ) );
90 }
91 
93  // that doesn't seem necessary. the atom-tree has them as lower and upper termini anyway
94  if ( offset() > 1 ) {
95  new_claims.push_back( new CutClaim( this, offset() - 1, DofClaim::INIT /* for now... eventually CAN_INIT ? */ ) );
96  }
97 
98  //special --- if only 1 residue chain... the torsion will be irrelvant and probably unclaimed
99  // ... make broker happy but don't do anything...
100  if ( nr_res_ == 1 ) new_claims.push_back( new BBClaim( this, offset() ) );
101 }
102 
103 void SequenceClaimer::initialize_dofs( core::pose::Pose& pose, DofClaims const& init_claims, DofClaims& failed_to_init ) {
104  if ( nr_res_ > 1 ) {
105  TopologyClaimer::initialize_dofs( pose, init_claims, failed_to_init );
106  } else { //special case the BBTorsion claim for position offset() is ours and is left unitialized...
107  for ( DofClaims::const_iterator it = init_claims.begin(), eit = init_claims.end();
108  it != eit; ++it ) {
109  if ( (*it)->owner()==this ) {
110  if ( (*it)->type() == DofClaim::BB && (*it)->pos( 1 ) == offset() ) {
111  tr.Trace << "SequenceClaimer: 1-residue chain --- no need to init: " << **it << std::endl;
112  continue;
113  } else {
114  tr.Trace << "SequenceClaimer: can't handle " << **it << std::endl;
115  failed_to_init.push_back( *it );
116  }
117  } // our claim
118  } //loop
119  } //nr_res_ == 1
120 }
121 
122 //bool SequenceClaimer::allow_claim( DofClaim const& foreign_claim ) {
123 // if ( foreign_claim.owner() == this ) return true; // always allow your own claims!
124 // if ( foreign_claim.type() == DofClaim::SEQUENCE ) {
125 // if ( foreign_claim.pos( 1 ) == 1 && foreing_claim.right() == DofClaim::EXCLUSIVE ) {
126 // return false; // don't accept any other fixed positions right now --- maybe never ?!
127 // }
128 // }
129 // return true;
130 //} // SequenceClaimer::allow_claim()
131 
132 
134  //need to copy coords and jumps --- if chunks were idealized no problem .... but non-idealized stuff ?
135  //also take care of fullatom vs centroid...
136  tr.Debug << "add sequence " << sequence_ << " to " << pose.annotated_sequence() << std::endl;
137  offset_ = my_claim->offset();
138  runtime_assert( offset_ == pose.total_residue() + 1 );
139  runtime_assert( nr_res_ > 0 );
141  pose,
143  *( chemical::ChemicalManager::get_instance()->residue_type_set( rsd_type_set_ ))
144  );
145  // make extended chain
146  for ( Size pos = 1; pos <= pose.total_residue(); pos++ ) {
147  if ( ! pose.residue(pos).is_protein() ) continue;
148  pose.set_phi( pos, -150 );
149  pose.set_psi( pos, 150);
150  pose.set_omega( pos, 180 );
151  }
152 
153 }
154 
155 bool SequenceClaimer::read_tag( std::string tag, std::istream& is ) {
156  if ( tag == "file" || tag == "FILE" || tag == "file:" ) {
157  is >> tag;
158  set_sequence( core::sequence::read_fasta_file( tag )[1]->sequence() );
159  } else if ( tag == "DEF" ) {
160  while ( is >> tag && tag != "END_DEF" ) {
161  if ( tag[0]=='#' ) {
162  getline( is, tag );
163  continue;
164  }
165  copy( tag.begin(), tag.end(), std::back_inserter( sequence_ ) );
166  set_sequence( sequence_ ); //to get the dependent values updated!
167  }
168  if ( tag != "END_DEF" ) {
169  throw EXCN_Input( "END_DEF expected after DEF while reading sequence" );
170  }
171  } else if ( tag == "CMD_FLAG" ) {
172  using namespace basic::options;
173  using namespace basic::options::OptionKeys;
174  if ( option[ in::file::fasta ].user() ) {
175  set_sequence( core::sequence::read_fasta_file( option[ in::file::fasta ]()[1] )[1]->sequence() );
176  tr.Info << "read fasta sequence: " << sequence_.size() << " residues\n" << sequence_ << std::endl;
177  } else {
178  throw EXCN_Input( "SequenceClaimer found tag CMD_FLAG but no -in:file:fasta on command-line");
179  }
180  } else return Parent::read_tag( tag, is );
181  return true;
182 }
183 
185  if ( nr_res_ == 0 ) {
186  throw EXCN_Input( "no sequence found when reading " +type() );
187  }
188 }
189 
190 } //topology_broker
191 } //protocols