Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
RNA_ResidueType.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
11 /// @brief
12 /// @author Parin Sripakdeevong (sripakpa@stanford.edu)
13 
14 // Unit headers
17 
18 // ObjexxFCL headers
22 
23 #include <ObjexxFCL/FArray2D.hh>
24 #include <ObjexxFCL/string.functions.hh>
25 
26 #include <basic/Tracer.hh>
27 
28 
29 namespace core {
30 namespace chemical {
31 namespace rna {
32 
33 using namespace ObjexxFCL;
34 
35 static basic::Tracer tr("core.chemical.rna.RNA_ResidueType");
36 
37 ////////////////////////////////////////////////////////////
38 
39 //Could perhaps find an atom index in term of its chemical position along the chain.
40 //For example could call chi_atoms( chi_torsion_# ) to get the atom_index of the atoms that define this torsion and then deduce the atom_index of the desired atom.
41 //Problem is that there is not analogous function for the backbone atoms! Parin S. June 25, 2011.
42 //Can get main_chain atoms from mainchain_atoms_?
43 //I think: mainchain_atoms_[1] is p_atom_index_
44 // mainchain_atoms_[2] is o5star_atom_index_
45 // mainchain_atoms_[3] is c5star_atom_index_
46 // mainchain_atoms_[4] is c4star_atom_index_
47 // mainchain_atoms_[5] is o3star_atom_index_
48 // mainchain_atoms_[6] is o4star_atom_index_
49 
50 ////////////////////////////////////////////////////////////////////////
52  o2star_index_( 0 ),
53  ho2star_index_( 0 ),
54  p_atom_index_( 0 ),
55  o1p_atom_index_( 0 ),
56  o2p_atom_index_( 0 ),
57  o5star_index_( 0 ),
58  o3star_index_( 0 ),
59  o4star_index_( 0 ),
60  c1star_index_( 0 ),
61  c2star_index_( 0 ),
62  c4star_index_( 0 )
63 {
64  base_atom_list_.clear();
65  Is_RNA_base_atom_list_.clear();
67 }
68 
69 
70 ////////////////////////////////////////////////////////////////////////
72 
73 
74 ////////////////////////////////////////////////////////////////////////
75 
76 void
78 
79  residue_type_=residue_type_in;
80 
81  //std::cout << "finalizing rna_residue_type_" << std::endl;
82 
83 
84  Is_virtual_atom_list_.clear();
85 
86  for ( Size i=1; i<= residue_type_->natoms(); i++ ) {
87  if(residue_type_->atom_type( i ).name()=="VIRT"){
88  Is_virtual_atom_list_.push_back(true);
89  }else{
90  Is_virtual_atom_list_.push_back(false);
91  }
92  }
93 
94  if(Is_virtual_atom_list_.size()!=residue_type_->natoms()) utility_exit_with_message("Is_virtual_atom_list_.size()!=residue_type_->natoms()");
95 
96 
97  o2star_index_=residue_type_->atom_index( " O2*" );
98  ho2star_index_=residue_type_->atom_index( "2HO*" );
99 
100  p_atom_index_ =residue_type_->atom_index( " P " );
101  o1p_atom_index_=residue_type_->atom_index( " O1P" );
102  o2p_atom_index_=residue_type_->atom_index( " O2P" );
103  o5star_index_ =residue_type_->atom_index( " O5*" );
104  o3star_index_ =residue_type_->atom_index( " O3*" );
105 
106  o4star_index_=residue_type_->atom_index( " O4*" );
107  c1star_index_=residue_type_->atom_index( " C1*" );
108  c2star_index_=residue_type_->atom_index( " C2*" );
109  c4star_index_=residue_type_->atom_index( " C4*" );
110 
111  base_atom_list_.clear();
112 
113  for ( Size i=1; i<= residue_type_->natoms(); i++ ) {
114  /*assume that chi # 1 is the base chi. chi_atoms_in[ 1 ][ 3 ] is the first base atom (either N1 or N9)*/
115  if(residue_type_->last_controlling_chi( i )==1 || ( i == residue_type_->chi_atoms( 1 )[ 3 ] ) ){
116  base_atom_list_.push_back( i );
117  }
118  }
119 
120  Is_RNA_base_atom_list_.clear();
121  Is_phosphate_atom_list_.clear();
122 
123  for ( Size i=1; i<= residue_type_->natoms(); i++ ) {
124 
125  bool Is_phosphate_atom=false;
126  if(i == p_atom_index_ ) Is_phosphate_atom=true;
127  if(i == o1p_atom_index_) Is_phosphate_atom=true;
128  if(i == o2p_atom_index_) Is_phosphate_atom=true;
129  if(i == o5star_index_ ) Is_phosphate_atom=true;
130  if(i == o3star_index_ ) Is_phosphate_atom=true;
131 
132  Is_phosphate_atom_list_.push_back(Is_phosphate_atom);
133 
134  /*assume that chi # 1 is the base chi, chi_atoms_in[ 1 ][3] is the index of the first RNA_base atom */
135  if( ( residue_type_->last_controlling_chi( i ) )==1 || ( i == residue_type_->chi_atoms( 1 )[3] ) ){
136  Is_RNA_base_atom_list_.push_back(true);
137  }else{
138  Is_RNA_base_atom_list_.push_back(false);
139  }
140 
141  }
142 
143  if(Is_RNA_base_atom_list_.size()!=residue_type_->natoms()) utility_exit_with_message("Is_RNA_base_atom_list_.size()!=residue_type_->natoms()");
144 
145  if(Is_phosphate_atom_list_.size()!=residue_type_->natoms()) utility_exit_with_message("Is_phosphate_atom_list_.size()!=residue_type_->natoms()");
146 
147 
148  if( (residue_type_->atoms_last_controlled_by_chi(1).size()+1)!= base_atom_list_.size() ){
149  std::cout << "residue_type_->atoms_last_controlled_by_chi(1).size()=" << residue_type_->atoms_last_controlled_by_chi(1).size() << std::endl;
150  std::cout << "base_atom_list_.size()=" << base_atom_list_.size() << std::endl;
151  utility_exit_with_message( "(residue_type_->atoms_last_controlled_by_chi(1).size()+1)!= base_atom_list_.size()" );
152  }
153 
154 }
155 
156 
157 ////////////////////////////////////////////////////////////
158 ///WARNING THIS FUNCTION SHOULD NOT ACCESS ANY DATA of the RNA_ResidueType object itself since at this point it is not yet updated!
159 ///ALSO SHOULD MAKE THIS FUNCTION A CONST FUNCTION!
160 void
162 
163 
164  //RNA require special treatment: Parin Sripakdeevong, Juen 26, 2011
165  //1) there are 4 chi torsions.
166  //2)The chi are not ordered from nearest to furthest from mainchain like in Protien. The sidechain also contain 2 branch (RNA base and 2'OH sidechains)
167  //3)chi_2 is NEAREST. Then branch to chi_3 and chi_4. then chi_3 connects to chi_1 which IS FURTHEST!
168 
169  if(4!= residue_type_->nchi()) utility_exit_with_message("is_RNA_==true but nchi()=" +ObjexxFCL::string_of(residue_type_->nchi())+ "!=4");
170  if(chi>residue_type_->nchi()) utility_exit_with_message("chi>residue_type_->nchi()");
171  if(chi<1) utility_exit_with_message("chi<1");
172 
173  utility::vector1< Size > chi_order;
174  chi_order.push_back(1000); //chi_1 is furthest
175  chi_order.push_back(1); //chi_2 is nearest
176  chi_order.push_back(100); //chi_3 is 3rd furthest (the choice between chi_4 and chi 3 is somewhat arbitrary)
177  chi_order.push_back(10); //chi_4 is 2nd furthest (the choice between chi_4 and chi 3 is somewhat arbitrary)
178 
179  if(last_controlling_chi[ atomno ]!=0){
180  if( chi_order[ last_controlling_chi[ atomno ] ] > chi_order[ chi ] ) return;
181  }
182 
183  //Stuck in a infinite recursion? But what about ring molecule like RNA base, can't a atom have two different base_atom is that case?
184  //[In effect this condition ensure that the recursion is called for each atom in residue at most once for each chi] since
185  //if called the second time then last_controlling_chi[ atomno ] is already set to chi in the prior call!
186  if( last_controlling_chi[ atomno ] == chi ) utility_exit_with_message("last_controlling_chi[ atomno ] == chi");
187 
188  /*
189  // This condition doesn't apply to RNA case since the chi are not ordered from nearest to furthest from mainchain like in Protien
190  if( last_controlling_chi[ atomno ] != 0 ){
191  std::cout << "last_controlling_chi[ atomno ] != 0" << std::endl;
192  std::cout << "atomno=" << atomno << std::endl;
193  std::cout << "chi=" << chi << std::endl;
194  std::cout << "last_controlling_chi[ atomno ]=" << last_controlling_chi[ atomno ] << std::endl;
195  utility_exit_with_message("last_controlling_chi[ atomno ] != 0 ");
196  }
197  */
198 
199  last_controlling_chi[ atomno ] = chi;
200 
201  AtomIndices const & nbrs( residue_type_->bonded_neighbor( atomno ) );
202  for ( Size ii = 1; ii <= nbrs.size(); ++ii ) {
203  if ( residue_type_->atom_base( nbrs[ ii ] ) == atomno ) {
204  rna_note_chi_controls_atom( chi, nbrs[ ii ], last_controlling_chi );
205  }
206  }
207 
208 }
209 
210 ////////////////////////////////////////////////////////////
211 ///WARNING THIS FUNCTION SHOULD NOT ACCESS ANY DATA of the RNA_ResidueType object itself since at this point it is not yet updated!
212 ///ALSO SHOULD MAKE THIS FUNCTION A CONST FUNCTION!
213 void
215  utility::vector1< core::Size > & last_controlling_chi,
216  utility::vector1< AtomIndices > & atoms_last_controlled_by_chi){
217 
218  residue_type_=residue_type_in;
219 
220  last_controlling_chi.clear(); //figure this out
221  atoms_last_controlled_by_chi.clear(); //figure this out!
222 
223  //RNA require special treatment: Parin Sripakdeevong, Juen 26, 2011
224 
225  Size const nchi=residue_type_->nchi();
226 
227  last_controlling_chi.resize( residue_type_->natoms() );
228 
229  std::fill( last_controlling_chi.begin(), last_controlling_chi.end(), 0 );
230 
231  for ( Size ii = nchi; ii >= 1; --ii ) {
232  /// Note children of atom 3 of chi_ii as being controlled by chi ii.
233  Size const iiat3 = residue_type_->chi_atoms( ii )[ 3 ];
234  // This may be unnecessary; I believe two atoms pair as each other's bases only at the mainchain.
235  Size const iiat3base = residue_type_->atom_base( iiat3 );
236  AtomIndices const & ii_nbrs( residue_type_->bonded_neighbor( iiat3 ) );
237  for ( Size jj = 1; jj <= ii_nbrs.size(); ++jj ) {
238  Size const jj_atom = ii_nbrs[ jj ];
239  if ( residue_type_->atom_base( jj_atom ) == iiat3 && iiat3base != jj_atom ) {
240  rna_note_chi_controls_atom( ii, jj_atom, last_controlling_chi );
241  }
242  }
243  }
244 
245  /// Now compute the atoms_last_controlled_by_chi_ arrays.
246 
247  /// get ready to allocate space in the atoms_last_controlled_by_chi_ arrays
248  utility::vector1< Size > natoms_for_chi( nchi, 0 );
249  for ( Size ii = 1; ii <= residue_type_->natoms(); ++ii ) {
250  if ( last_controlling_chi[ ii ] != 0 ) {
251  ++natoms_for_chi[ last_controlling_chi[ ii ] ];
252  }
253  }
254 
255  /// allocate space
256  atoms_last_controlled_by_chi.resize( nchi );
257  for ( Size ii = 1; ii <= nchi; ++ii ) {
258  atoms_last_controlled_by_chi[ ii ].clear();
259  atoms_last_controlled_by_chi[ ii ].reserve( natoms_for_chi[ ii ] );
260  }
261 
262  /// fill the arrays
263  for ( Size ii = 1; ii <= residue_type_->natoms(); ++ii ) {
264  if ( last_controlling_chi[ ii ] != 0 ) {
265  atoms_last_controlled_by_chi[ last_controlling_chi[ ii ]].push_back( ii );
266  }
267  }
268 
269 }
270 
271 ////////////////////////////////////////////////////////////
272 
273 //For fast lookup! Parin Sripakdeevong, June 25th, 2011
276 {
277  //runtime_assert( finalized_ );
278 
279  return Is_virtual_atom_list_;
280 
281 }
282 
283 bool
285 {
286  //runtime_assert( finalized_ );
287  //runtime_assert(Is_virtual_atom_list_.size()==natoms_);
288 
289  return (Is_virtual_atom_list_[atomno]);
290 }
291 
292 
295 {
296  //runtime_assert( finalized_ );
297 
299 
300 }
301 
302 bool
304 {
305  //runtime_assert( finalized_ );
306  //runtime_assert( atomno <= natoms_ );
307 
308  return (Is_phosphate_atom_list_[atomno]);
309 
310 }
311 
314 {
315  //runtime_assert( finalized_ );
316 
317  return Is_RNA_base_atom_list_;
318 
319 }
320 
321 //True for heavy, hydrogen and virtual atoms as long as it is in the RNA_base!
322 bool
324 {
325  //if(is_RNA_==false) utility_exit_with_message("is_RNA_==false");
326  //runtime_assert( finalized_ );
327  //runtime_assert( atomno <= natoms_ );
328 
329  /*assume that chi # 1 is the base chi, chi_atoms_[ 1 ][3] is the index of the first RNA_base atom */
330 
331  return (Is_RNA_base_atom_list_[ atomno ]);
332 }
333 
334 //Note that this implement return both heavy and hydrogen atoms in the RNA_base.
335 //Virtual atoms in the RNA_base atoms are also returned.
336 AtomIndices const &
338 {
339  //if(is_RNA_==false) utility_exit_with_message("is_RNA_==false");
340  //runtime_assert( finalized_ );
341 
342  /*
343  if( (atoms_last_controlled_by_chi_[1].size()+1)!= base_atom_list_.size() ){
344  std::cout << "atoms_last_controlled_by_chi_[1].size()=" << atoms_last_controlled_by_chi_[1].size() << std::endl;
345  std::cout << "base_atom_list_.size()=" << base_atom_list_.size() << std::endl;
346  utility_exit_with_message( "(atoms_last_controlled_by_chi_[1].size()+1)!= base_atom_list_.size() " );
347  }
348  */
349 
350  return base_atom_list_;
351 }
352 
353 //For fast lookup! Parin Sripakdeevong, June 25th, 2011
354 Size
356 {
357  //if(is_RNA_==false) utility_exit_with_message("is_RNA_==false");
358  //runtime_assert( finalized_ );
359  //if(rna_check_) runtime_assert(ho2star_index_==atom_index( "2HO*" )); //remove after testing!
360 
361  return ho2star_index_;
362 }
363 
364 
365 //For fast lookup! Parin Sripakdeevong, June 25th, 2011
366 Size
368 {
369 
370  //////////////////////////////
371  //residue_type_->require_final();
372  //runtime_assert(o2star_index_==residue_type_->atom_index( " O2*" )); //remove after testing!
373  // std::cout << "--------------------------------------" << std::endl;
374  // std::cout << "Inside RNA_ResidueType::o2star_index()" << std::endl;
375  // std::cout << "name_from_aa(residue_type_->aa())=" << name_from_aa(residue_type_->aa())<< std::endl;
376  // std::cout << "o2star_index_=" << o2star_index_ << std::endl;
377  // std::cout << "residue_type_->atom_name(o2star_index_)=" << residue_type_->atom_name(o2star_index_) << std::endl;
378  // std::cout << "residue_type_->first_sidechain_atom() =" << residue_type_->first_sidechain_atom() << std::endl;
379  // std::cout << "residue_type_->atom_name(residue_type_->first_sidechain_atom())=" << residue_type_->atom_name(residue_type_->first_sidechain_atom()) << std::endl;
380  // std::cout << "--------------------------------------" << std::endl;
381  //////////////////////////////
382 
383  return o2star_index_;
384 }
385 
386 
387 //For fast lookup! Parin Sripakdeevong, June 25th, 2011
388 Size
390 {
391  //if(is_RNA_==false) utility_exit_with_message("is_RNA_==false");
392  //runtime_assert( finalized_ );
393  //if(rna_check_) runtime_assert(p_atom_index_==atom_index( " P " )); //remove after testing!
394 
395  return p_atom_index_;
396 }
397 
398 //For fast lookup! Parin Sripakdeevong, June 25th, 2011
399 Size
401 {
402  //if(is_RNA_==false) utility_exit_with_message("is_RNA_==false");
403  //runtime_assert( finalized_ );
404  //if(rna_check_) runtime_assert(o1p_atom_index_==atom_index( " O1P" )); //remove after testing!
405 
406  return o1p_atom_index_;
407 }
408 
409 //For fast lookup! Parin Sripakdeevong, June 25th, 2011
410 Size
412 {
413  //if(is_RNA_==false) utility_exit_with_message("is_RNA_==false");
414  //runtime_assert( finalized_ );
415  //if(rna_check_) runtime_assert(o2p_atom_index_==atom_index( " O2P" )); //remove after testing!
416  return o2p_atom_index_;
417 }
418 
419 //For fast lookup! Parin Sripakdeevong, June 25th, 2011
420 Size
422 {
423  //if(is_RNA_==false) utility_exit_with_message("is_RNA_==false");
424  //runtime_assert( finalized_ );
425  //if(rna_check_) runtime_assert(o5star_index_==atom_index( " O5*" )); //remove after testing!
426  return o5star_index_;
427 }
428 
429 //For fast lookup! Parin Sripakdeevong, June 25th, 2011
430 Size
432 {
433  //if(is_RNA_==false) utility_exit_with_message("is_RNA_==false");
434  //runtime_assert( finalized_ ) ;
435  //if(rna_check_) runtime_assert(o3star_index_==atom_index( " O3*" )); //remove after testing!
436  return o3star_index_;
437 }
438 
439 //For fast lookup! Parin Sripakdeevong, June 25th, 2011
440 Size
442 {
443  //if(is_RNA_==false) utility_exit_with_message("is_RNA_==false");
444  //runtime_assert( finalized_ );
445  //if(rna_check_) runtime_assert(o4star_index_==atom_index( " O4*" )); //remove after testing!
446  return o4star_index_;
447 }
448 
449 Size
451 {
452  //if(is_RNA_==false) utility_exit_with_message("is_RNA_==false");
453  //runtime_assert( finalized_ );
454  //if(rna_check_) runtime_assert(c1star_index_==atom_index( " C1*" )); //remove after testing!
455  return c1star_index_;
456 }
457 
458 Size
460 {
461  //if(is_RNA_==false) utility_exit_with_message("is_RNA_==false");
462  //runtime_assert( finalized_ );
463  //if(rna_check_) runtime_assert(c2star_index_==atom_index( " C2*" )); //remove after testing!
464  return c2star_index_;
465 }
466 
467 Size
469 {
470  //if(is_RNA_==false) utility_exit_with_message("is_RNA_==false");
471  //runtime_assert( finalized_ );
472  //if(rna_check_) runtime_assert(c4star_index_==atom_index( " C4*" )); //remove after testing!
473  return c4star_index_;
474 }
475 ////////////////////////////////RNA specific stuff...maybe move function into its own class?///////////
476 
477 } // rna
478 } // chemical
479 } // core