Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
BluePrint.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 ./src/protocols/fldsgn/BluePrint.cc
11 /// @brief the basic idea of BluePrint is on the remodel Possu wrote in rosetta++.
12 /// @author Nobuyasu Koga
13 
14 // Unit header
16 
17 // Package header
18 
19 // Project header
20 #include <core/types.hh>
22 #include <basic/Tracer.hh>
23 #include <core/pose/Pose.hh>
24 
25 // Utility headers
26 #include <utility/io/izstream.hh>
27 #include <utility/string_util.hh>
28 #include <boost/lexical_cast.hpp>
29 
31 #include <utility/vector1.hh>
32 
33 static basic::Tracer TR("protocols.jd2.parser.BluePrint");
34 
35 using namespace core;
36 
37 namespace protocols {
38 namespace jd2 {
39 namespace parser {
40 
41 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////
42 /// @brief default constructor
43 BluePrint::BluePrint() :
44  total_residue_( 0 ),
45  total_residue_wolig_( 0 ),
46  sequence_( "" ),
47  secstruct_( "" ),
48  strand_pairings_( "" ),
49  helix_pairings_( "" ),
50  hss_triplets_( "" )
51 {}
52 
53 
54 /// @brief value constructor
56  total_residue_( 0 ),
57  total_residue_wolig_( 0 ),
58  sequence_( "" ),
59  secstruct_( "" ),
60  strand_pairings_( "" ),
61  helix_pairings_( "" ),
62  hss_triplets_( "" )
63 {
64  if ( ! read_blueprint( filename ) ) {
65  TR.Error << "Error in reading blueprint file " << filename << std::endl;
66  exit(0);
67  }
68 }
69 
70 
71 /// @brief destructor
73 {}
74 
75 
76 /// @brief copy constructor
78  ReferenceCount(),
79  total_residue_( src.total_residue_ ),
80  total_residue_wolig_( src.total_residue_wolig_ ),
81  sequence_( src.sequence_ ),
82  secstruct_( src.secstruct_ ),
83  resnum_( src.resnum_ ),
84  resname_( src.resname_ ),
85  sstype_( src.sstype_ ),
86  abego_( src.abego_ ),
87  buildtype_( src.buildtype_ ),
88  resnum_map_( src.resnum_map_ ),
89  strand_pairings_( src.strand_pairings_ ),
90  helix_pairings_( src.helix_pairings_ ),
91  hss_triplets_( src.hss_triplets_ )
92 {}
93 
94 
95 /// @brief total residue number defined in blueprint file
98 {
99  return total_residue_;
100 }
101 
102 
103 /// @brief total residue number defined in blueprint file
106 {
107  return total_residue_wolig_;
108 }
109 
110 
111 /// @brief sequence defined in blueprint file
114 {
115  return sequence_;
116 }
117 
118 
119 /// @brief amino acid type at a position in blueprint file
120 char
122 {
123  assert( seqpos >= 1 );
124  return resname_[ seqpos ];
125 }
126 
127 
128 /// @brief secondary structures defined in blueprint file
131 {
132  return secstruct_;
133 }
134 
135 /// @brief abego defined in blueprint file
138 {
139  return abego_;
140 }
141 
142 /// @brief abego defined in blueprint file
145 {
146  runtime_assert( seqpos >= 1 && seqpos <= abego_.size() );
147  return abego_[ seqpos ];
148 }
149 
150 /// @brief secondary structure at a position in blueprint file
151 char
153 {
154  assert( seqpos >= 1 && seqpos <= buildtype_.size() );
155  return sstype_[ seqpos ];
156 }
157 
158 
159 /// @brief residue number of each position in blueprint file
162 {
163  assert( seqpos >= 1 && seqpos <= buildtype_.size() );
164  return resnum_[ seqpos ];
165 }
166 
167 
168 /// @brief translate residue number of pose to that of blueprint file
170 BluePrint::resnum_map( Size resnum_pose ) const
171 {
172  std::map<Size,Size>::const_iterator itr;
173  itr = resnum_map_.find( resnum_pose );
174  if( itr != resnum_map_.end() ){
175  Size resnum_blueprint = itr->second;
176  return resnum_blueprint;
177  }else{
178  return 0;
179  }
180 }
181 
182 
183 /// @brief build type at each position in blueprint
184 char
186 {
187  assert( seqpos >= 1 && seqpos <= buildtype_.size() );
188  return buildtype_[ seqpos ];
189 }
190 
191 /// @brief build type at each position in blueprint
194 {
195  assert( seqpos >= 1 && seqpos <= extra_.size() );
196  return extra_[ seqpos ];
197 }
198 
199 /// @brief build type at each position in blueprint
202 {
203  assert( i <= insertion_.size() && i > 0 );
204  return insertion_[ i ];
205 }
206 
207 
208 /// @brief strand pairings defined at the line of SSPAIR in blueprint
211 {
212  return strand_pairings_;
213 }
214 
215 
216 /// @brief helix pairings defined at the line of HHPAIR in blueprint
219 {
220  return helix_pairings_;
221 }
222 
223 
224 /// @brief helix-strand-strand set at the line of HSSTRIPLET in blueprint
227 {
228  return hss_triplets_;
229 }
230 
231 
232 /// @brief secondary structure information
233 ///BluePrint::SS_Info2_OP
234 ///BluePrint::ssinfo() const
235 ///{
236 /// return ss_info_;
237 ///}
238 
239 
240 /// @brief read blueprint file
241 bool
243 {
244  using utility::string_split;
245 
246  utility::io::izstream data( filename );
247  if ( !data ) {
248  TR.Error << "can not open blueprint file " << filename << std::endl;
249  return false;
250  }
251 
252  // StranPairing info read from the line of SSPAIR
253  //StrandPairings spairs;
254  String spairs;
255 
256  String line;
257  Size linecount( 0 ), count( 0 );
258  while( getline( data, line ) ) {
259  linecount++;
260  utility::vector1< String > tokens ( utility::split( line ) );
261 
262  // skip reading line that is commented out
263  if( tokens[1][0] == '#' ) continue;
264 
265  if( tokens[1] == "FOLDINFO" || tokens[1] == "SSPAIR" || tokens[1] == "HHPAIR" || tokens[1] == "HSSTRIPLET" ) {
266  // read the line of SSPAIR( FOLDINFO ), HHPAIR
267 
268  if( tokens.size() > 2 ) {
269  TR.Error << "error parsing at " << linecount << " in " << filename << std::endl;
270  return false;
271  }
272 
273  if( tokens[1] == "SSPAIR" || tokens[1] == "FOLDINFO" ) {
274  // set string of strand pairings
275  strand_pairings_ = tokens[2];
276  } else if( tokens[1] == "HHPAIR" ) {
277  // set string of helix pairings
278  helix_pairings_ = tokens[2];
279  } else if( tokens[1] == "HSSTRIPLET" ) {
280  // set string of hss triplets
281  hss_triplets_ = tokens[2];
282  }
283 
284  } else if( tokens[1] == "INSERT" ) {
285  // read the line of INSERT for reading insertion pdb file
286  insertion_.push_back( tokens[2] );
287 
288  } else {
289 
290  // read the line where residue number, amino acid type, secondary structure and build type are written
291  // don't need to specify build type in blueprint
292  //flo aug 2012:
293  //it would be nice to be able to put comments behind bluerint lines...
294  for( core::Size i(1); i <= tokens.size(); ++i ){
295  if( tokens[i][0] == '#' ){
296  tokens.resize( i - 1 );
297  break;
298  }
299  }
300  runtime_assert( tokens.size() == 3 || tokens.size() == 4 || tokens.size() == 5 );
301 
302  count ++;
303  Size ii = boost::lexical_cast<Size>( tokens[1] );
304  char aa ( tokens[2][0] );
305  char sec( tokens[3][0] );
306  String abego("");
307  if( tokens[3].length() > 1 ) {
309  // check characters of abego is appropriate or not
310  for( Size k=2; k<=tokens[3].length(); k++ ) {
311  am.symbol2index( tokens[3][k-1] );
312  }
313  abego = tokens[3].substr( 1, tokens[3].length() - 1 );
314  } else {
315  abego = "X";
316  }
317 
318  // check the 3rd column where secondary structure and abego info are written
319  if ( sec != 'E' && sec != 'H' && sec != 'L' && sec != 'D' ) {
320  TR.Error << "unrecognized secstruct char : " << sec << " at lines " << linecount << " in " << filename << std::endl;
321  return false;
322  }
323 
324  resnum_.push_back( ii );
325  resname_.push_back( aa );
326  sstype_.push_back( sec );
327  abego_.push_back( abego );
328  if( ii != 0 ){
329  resnum_map_.insert( std::map<Size, Size>::value_type( ii, count ) );
330  }
331 
332  if( tokens.size() >= 4 ) {
333 
334  char build( tokens[4][0] );
335  if( build != '.' && build != 'R' && build != 'I' && build != 'X' &&
336  build != 'F' && build != 'P' && build != 'C' && build != 'W' ) {
337  TR.Error << "unrecognized build char : " << build << " at lines " << linecount << " in " << filename << std::endl;
338  return false;
339  }
340  if( ii == 0 && build == '.' ) {
341  TR.Error << "Cannot have simultaneously '0' at 1st column and '.' in 4th column in blueprint " << std::endl;
342  return false;
343  }
344  buildtype_.push_back( build );
345 
346  if( tokens.size() >= 5 ) {
347  String extra( tokens[5] );
348  extra_.push_back( extra );
349  } else {
350  extra_.push_back( "" );
351  }
352 
353  }else{
354  buildtype_.push_back( '.' );
355  } // tokens.size() >=4
356 
357  }// tokens.size() == 2 || tokens.size() == 3
358  } // while ( getline )
359 
360  assert( resname_.size() == sstype_.size() );
361  total_residue_ = sstype_.size();
362  assert( total_residue_ > 0 );
363 
365  for( Size ii=1; ii<=total_residue(); ii++ ) {
366  if( extra( ii ) == "LIGAND" ) continue;
368  }
369 
370  for( utility::vector1< char >::const_iterator iter = sstype_.begin(); iter != sstype_.end() ; ++iter) {
371  secstruct_ += *iter;
372  }
373  for( utility::vector1< char >::const_iterator iter = resname_.begin(); iter != resname_.end() ; ++iter) {
374  sequence_ += *iter;
375  }
376 
377  TR << secstruct_ << std::endl;
378  TR << sequence_ << std::endl;
379 
380  //ss_info_->initialize( secstruct_ );
381  //if( spairs.size() > 0 ){
382  //strand_pairings_ = set_strand_pairings( ss_info_, spairs );
383  //}
384 
385  return true;
386 
387 } // read_blueprint
388 
389 
390 /// @brief
391 void
393 {
394  for ( Size i=1; i<=total_residue_ ; ++i ) {
395  if ( buildtype( i ) == '.' ) {
396  movemap->set_bb( i, true );
397  movemap->set_chi( i, true );
398  } else if ( buildtype( i ) == 'P' ) {
399  movemap->set_bb( i, false );
400  movemap->set_chi( i, true );
401  TR.Debug << "At residue " << i << ", Backbone is freezed." << std::endl;
402  } else if ( buildtype( i ) == 'W' ) {
403  movemap->set_bb( i, true );
404  movemap->set_chi( i, false );
405  TR.Debug << "At residue " << i << ", Rotamer is freezed." << std::endl;
406  } else if ( buildtype( i ) == 'F' ){
407  movemap->set_bb( i, false );
408  movemap->set_chi( i, false );
409  TR.Debug << "At residue " << i << ", both backbone and rotamer are freezed. " << std::endl;
410  } else {
411  movemap->set_bb( i, true );
412  movemap->set_chi( i, true );
413  }
414  }
415 }
416 
417 /// @brief set secondary structure into pose
418 void
420 {
421  for( Size i=1; i<= pose.total_residue(); i++ ){
422  Size resi = resnum_map( i );
423  if( resi == 0 ) continue;
424  char ss = secstruct( resi );
425  pose.set_secstruct( i, boost::lexical_cast<char>( ss ) );
426  }
427 }
428 
429 } // ns parser
430 } // ns jd2
431 } // ns protocols