Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
InvrotTree.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 // :noTabs=false:tabSize=4:indentSize=4:
4 //
5 // (c) Copyright Rosetta Commons Member Institutions.
6 // (c) This file is part of the Rosetta software suite and is made available under license.
7 // (c) The Rosetta software is developed by the contributing members of the Rosetta Commons.
8 // (c) For more information, see http://www.rosettacommons.org. Questions about this can be
9 // (c) addressed to University of Washington UW TechTransfer, email: license@u.washington.edu.
10 
11 /// @file protocols/toolbox/match_enzdes_util/ReactionState.hh
12 /// @brief class to model one state of a reaction
13 /// @author Florian Richter, flosopher@gmail.com, feb/mar 2012
14 
15 // Unit headers
17 
18 // package headers
23 
24 
25 // Project headers
29 #include <core/io/pdb/pose_io.hh>
31 #include <core/pose/Pose.hh>
33 
34 #include <basic/Tracer.hh>
35 
36 //utility headers
37 #include <utility/string_util.hh>
38 #include <utility/vector1.hh>
39 
40 // c++ headers
41 #include <fstream>
42 
43 
44 namespace protocols {
45 namespace toolbox {
46 namespace match_enzdes_util {
47 
48 static basic::Tracer tr( "protocols.toolbox.match_enzdes_util.InvrotTree" );
49 
50 
52  : ReferenceCount()
53 {
54  invrot_targets_.clear();
56 }
57 
59 
62  return invrot_tree_constraints_[target_state];
63 }
64 
65 void
67  core::pose::Pose const & pose,
68  AllowedSeqposForGeomCstCOP geomcst_seqpos
69 )
70 {
71  if( invrot_targets_.size() == 0 ) utility_exit_with_message("InvrotTree is asked to generate constraints even though no target states exist. Something is wrong somewhere.");
72 
74 
75  for( Size i = 1; i <= invrot_targets_.size(); ++i){
76  invrot_tree_constraints_.push_back( invrot_targets_[i]->generate_constraints( pose, geomcst_seqpos ) );
77  }
78 
79 }
80 
83 {
84  utility::vector1< InvrotCollectorOP > invrot_collectors;
85  for(Size i =1; i <= invrot_targets_.size(); ++i ) invrot_targets_[i]->collect_all_inverse_rotamers( invrot_collectors );
86  return invrot_collectors;
87 }
88 
89 void
91 {
92  tr << "Writing InvrotTree to file(s).... " << std::endl;
93  //1. collect all the invrots
95  if( invrot_collectors.size() == 0 ){
96  tr <<"Error when trying to dump inverse rotamer tree to file. No inverse rotamers found in tree.";
97  return;
98  }
99 
100  //2. write them
101  Size files_to_write( invrot_collectors.size() );
102  tr <<"A total of " << files_to_write << " unique definitions of the invrot tree exist." << std::endl;
103 
104  for( Size i =1; i <= files_to_write; ++i ){
105  std::string filename( filename_base + "_" + utility::to_string( i ) + ".pdb" );
106  std::vector< std::list< core::conformation::ResidueCOP > > const & invrot_lists( invrot_collectors[i]->invrots() );
107  Size num_rotamer_lists( invrot_lists.size() );
108  std::vector< std::list< core::conformation::ResidueCOP >::const_iterator > res_iterators( num_rotamer_lists );
109 
110  tr << "Writing definition " << i << " to file " << filename << "... " << std::endl;
111  for( Size j =0; j < num_rotamer_lists; ++j ){
112  res_iterators[ j ] = invrot_lists[j].begin();
113  tr << invrot_lists[j].size() << " invrots for list " << j << ", ";
114  }
115  tr << std::endl;
116 
117  core::Size atomcounter(0), modelcount(1);
118  bool all_res_iterators_at_end( false );
119  std::ofstream file_out( filename.c_str() );
120  file_out << "MODEL 1\n";
121 
122  while( !all_res_iterators_at_end ){
123  all_res_iterators_at_end = true;
124  for( core::Size j =0; j < num_rotamer_lists; ++j ){
125  if( res_iterators[ j ] != invrot_lists[j].end() ){
126  all_res_iterators_at_end = false;
127  core::io::pdb::dump_pdb_residue( **(res_iterators[ j ]), atomcounter, file_out );
128  res_iterators[ j ]++;
129  }
130  }
131  if( !all_res_iterators_at_end ){
132  file_out << "ENDMDL \n";
133  file_out << "MODEL "+utility::to_string( ++modelcount )+"\n";
134  }
135  } // while( !all_res_iterators_at_end )
136  file_out.close();
137  } //loop over files to write
138 }
139 
140 void
142 {
143  invrot_targets_.clear();
144 }
145 
146 void
148 {
149  invrot_targets_.push_back( invrot_target );
150 }
151 
152 
154  : InvrotTree(), enzcst_io_(enzcst_io)
155 {}
156 
158 
159 
160 bool
162  core::pose::Pose & ) const
163 {
164  utility_exit_with_message("stubbed out");
165  return false; // required for compilation on Windows
166 }
167 
168 void
170 {
171  this->clear_target_states();
172 
173  //1. make a residue from the first block ligand
174  utility::vector1< core::chemical::ResidueTypeCOP > ds_restypes( enzcst_io_->mcfi_list( 1 )->mcfi( 1 )->allowed_restypes( enzcst_io_->mcfi_list( 1 )->mcfi( 1 )->downstream_res() ) );
176 
178  //amino acid target?
179  if( ligres->is_protein() ) all_rots = core::pack::rotamer_set::bb_independent_rotamers( &(ligres->type()) );
180 
181  //ligand?
182  else if( ligres->is_ligand() ){
183  //for now
184  //all_rots.push_back( ligres );
185  all_rots = core::pack::rotamer_set::bb_independent_rotamers( &(ligres->type()) );
186  }
187 
188  else{
189  //one residue only
190  all_rots.push_back( ligres );
191  }
192  //2. determine redundancy, same way as it's determined in matcher task
193  // ..... no code yet .. will probably have to refactor redundancy determination a bit
194  // easiest will be to put the redundancy determining code in LigandConformerBuilder
195  //into a utility function in LigandConformer, and move the relevant atom determining
196  //code from the matcher task to EnzConstraintIO
197  //
198  //hack for now
200  conformer_groups.push_back( all_rots );
201 
202  //but at afer this, we'll generate a bunch of ligand targets
203  for( Size i =1; i <= conformer_groups.size(); ++i ){
204 
205  SingleResidueInvrotTargetOP invtarg = new SingleResidueInvrotTarget( conformer_groups[i] );
206  if( !invtarg->initialize_tree_nodes_from_enzcst_io( enzcst_io_ ) ) tr << "Target from conformer group " << i << " failed to initialize, cstfile geometry (clashes?) is bad somewhere." << std::endl;
207  else this->add_to_targets( invtarg );
208  }
209  if( this->num_target_states() == 0 ) utility_exit_with_message("No targets could be initialized by TheozymeInvrotTree. check cstfile");
210 }
211 
212 } //match_enzdes_util
213 } //toolbox
214 } //protocols