Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
util_functions.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 protocols/toolbox/match_enzdes_util/util_functions.cc
11 /// @brief bunch of utility functions
12 /// @author Florian Richter, floric@u.washington.edu
13 /// @modified Tom Linsky, tlinsky@uw.edu
14 
15 //unit headers
17 
18 //package headers
21 
22 // project headers
23 #include <basic/Tracer.hh>
24 
25 #include <core/types.hh>
26 
28 #include <core/id/AtomID.hh>
31 #include <core/pose/Pose.hh>
37 
38 
39 //utility headers
40 #include <utility/string_util.hh>
41 
42 //stl headers
43 #include <map>
44 
45 namespace protocols {
46 namespace toolbox {
47 namespace match_enzdes_util{
48 
49 static basic::Tracer tr("protocols.toolbox.match_enzdes_util.util_functions");
50 
51 void
53  core::pose::Pose & pose,
55  core::Size res_pos
56 )
57 {
58 
59  //have to set the position of the new res to their old values, so we gotta save them now
60  std::map< std::string, core::PointPosition > atom_name_to_xyz;
61 
62  for( core::Size at_ct = 1; at_ct <= pose.residue(res_pos).natoms(); at_ct++){
63  atom_name_to_xyz.insert( std::pair< std::string, core::PointPosition > (pose.residue(res_pos).atom_name(at_ct), pose.residue(res_pos).xyz( at_ct ) ) );
64  }
65 
66  //replacing the residue
67  pose.replace_residue( res_pos, new_res, true);
68 
69  //and resetting the xyz positions
70  for( core::Size at_ct = 1; at_ct <= pose.residue(res_pos).natoms(); at_ct++){
71 
72  std::map< std::string, core::PointPosition>::iterator xyz_map_it = atom_name_to_xyz.find( pose.residue(res_pos).atom_name(at_ct) );
73 
74  if(xyz_map_it == atom_name_to_xyz.end() ) {
75  std::cerr << "ERROR: when trying to make dsflkj constraint covalent, atom " << pose.residue(res_pos).atom_name(at_ct) << " was not found for residue " << pose.residue(res_pos).name3() << " at position " << res_pos << std::endl;
76  utility::exit( EXIT_FAILURE, __FILE__, __LINE__);
77  }
78  else{
79  pose.set_xyz( core::id::AtomID (at_ct, res_pos), xyz_map_it->second );
80  }
81  }
82 
83 } //replace_residues_keeping_positions
84 
85 
86 /// @details forwarding function, allows stuff to call this functionality
87 /// without caller having to specify root
90  std::list< core::conformation::ResidueCOP > const & invrots,
91  utility::vector1< core::Size > const & seqpos,
92  core::pose::Pose const & pose,
94 )
95 {
96  core::id::AtomID fixed_pt( pose.atom_tree().root()->atom_id() );
97  return constrain_pose_res_to_invrots( invrots, seqpos, pose, fixed_pt, constraint_func );
98 }
99 
100 
103  std::list< core::conformation::ResidueCOP > const & invrots,
104  utility::vector1< core::Size > const & seqpos,
105  core::pose::Pose const & pose,
106  core::id::AtomID const & fixed_pt,
107  core::scoring::constraints::FuncOP constraint_func
108 )
109 {
110  using namespace core::scoring::constraints;
111 
112  if( !constraint_func ) constraint_func = new BoundFunc( 0, 0.05, 0.4, "invrot");
113  //see the comment in protocols/ligand_docking/LigandBaseProtocol.cc::restrain_protein_Calphas
114  //core::id::AtomID fixed_pt( pose.atom_tree().root()->atom_id() );
115  //tr << "Hackack fixed_pt was passed in to be AtomID " << fixed_pt << std::endl;
116 
117  utility::vector1< ConstraintCOP > all_res_invrot_csts;
118  core::Size totrescount(0);
119 
120  for( core::Size i =1; i <= seqpos.size(); ++i ){
121 
122  core::conformation::ResidueCOP cur_remodel_res( &pose.residue( seqpos[i] ) );
123  if( cur_remodel_res->name3() == "GLY" ) continue;
124  totrescount++;
125 
126  core::id::AtomID rem_CA( cur_remodel_res->type().atom_index("CA"), seqpos[i] );
127  core::id::AtomID rem_CB( cur_remodel_res->type().atom_index("CB"), seqpos[i] );
128  core::id::AtomID rem_N( cur_remodel_res->type().atom_index("N"), seqpos[i] );
129 
130  for( std::list< core::conformation::ResidueCOP >::const_iterator invrot_it( invrots.begin() ), invrot_end( invrots.end() ); invrot_it != invrot_end; ++invrot_it ){
131 
132  utility::vector1< ConstraintCOP > cur_res_invrot_csts;
133  cur_res_invrot_csts.push_back( new BackboneStubConstraint( pose, seqpos[i], fixed_pt, **invrot_it, -20.0, 0.8) );
134 
135  //old style: coordinate constraints for all atoms, backbone stub csts
136  // might be working better
137  cur_res_invrot_csts.push_back( new CoordinateConstraint( rem_CA, fixed_pt, (*invrot_it)->xyz("CA"), constraint_func ) );
138  cur_res_invrot_csts.push_back( new CoordinateConstraint( rem_CB, fixed_pt, (*invrot_it)->xyz("CB"), constraint_func ) );
139  cur_res_invrot_csts.push_back( new CoordinateConstraint( rem_N, fixed_pt, (*invrot_it)->xyz("N"), constraint_func ) );
140 
141  all_res_invrot_csts.push_back( new MultiConstraint( cur_res_invrot_csts ) );
142  }// loop over invrots
143  }//loop over seqpos
144 
145  tr << "Created a total of " << all_res_invrot_csts.size() << " constraints between " << invrots.size() << " inverse rotamers and " << totrescount << " residues." << std::endl;
146 
147  return new AmbiguousConstraint( all_res_invrot_csts );
148 
149 } //constrain_pose_res_to_invrots
150 
151 
154  core::pose::Pose const & pose,
155  core::Size geomcst,
156  core::Size geomcst_template_res
157 )
158 {
159 
161  if( !enz_ob ) return NULL;
162 
163  EnzCstTemplateResCacheCOP res_cache( enz_ob->cst_cache()->param_cache( geomcst )->template_res_cache( geomcst_template_res) );
164  runtime_assert( res_cache );
165  if( res_cache->not_in_pose() ) return NULL;
166 
167  runtime_assert( res_cache->seqpos_map_size() == 1 );
168 
169  return new core::conformation::Residue( pose.residue( res_cache->seqpos_map_begin()->first ) );
170 }
171 
172 
175  std::string chainA,
176  std::string resA,
177  int seqposA,
178  std::string chainB,
179  std::string resB,
180  int seqposB,
181  core::Size cst_block,
182  core::Size ex_geom_id
183 )
184 {
185  std::string posA = utility::to_string( seqposA );
186  utility::add_spaces_right_align( posA, 4 );
187 
188  std::string posB = utility::to_string( seqposB );
189  utility::add_spaces_right_align( posB, 4 );
190 
191  return "MATCH TEMPLATE "+ chainA +" "+ resA +" "+ posA + " MATCH MOTIF "+ chainB + " " + resB + " "+posB + " " + utility::to_string( cst_block ) + " " + utility::to_string( ex_geom_id );
192 
193 } //assemble remark line function
194 
195 
196 bool
198  std::string line,
199  std::string & chainA,
200  std::string & resA,
201  int & seqposA,
202  std::string & chainB,
203  std::string & resB,
204  int & seqposB,
205  core::Size & cst_block,
206  core::Size & ex_geom_id
207 )
208 {
209 
210  std::istringstream line_stream;
211  std::string buffer(""), tag("");
212 
213  line_stream.clear();
214  line_stream.str( line );
215 
216  line_stream >> buffer >> tag;
217  if( tag == "TEMPLATE"){
218  line_stream >> chainA >> resA >> seqposA >> buffer >> buffer;
219  line_stream >> chainB >> resB >> seqposB >> cst_block;
220  if( resA.size() == 2 ) resA = " " + resA;
221  if( resB.size() == 2 ) resB = " " + resB;
222 
223  if( line_stream.bad() ){
224  tr << "ERROR when trying to split up pdb remark line. Not all fields seem to have been specified." << std::endl;
225  return false;
226  }
227 
228  line_stream >> ex_geom_id;
229  if( !line_stream.good() ) ex_geom_id = 1;
230 
231  return true;
232  }
233 
234  return false;
235 } //split up remark line function
236 
237 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
238 // @brief finds the first non-ligand residue in the pose (should be the N-terminus)
241 {
242  // This will not work properly on structures with multiple chains, for now
243 
244  // briefly, loop through the list of residues in the pose, from 1 to N
245  // if the pose is not in the list of ligands, it is the N-terminal residue
246  for( core::Size i = 1; i <= pose.total_residue(); i++) {
247  if ( pose.residue( i ).is_protein() ){
248  return i;
249  }
250  }
251 
252  tr << "No non-ligand residues were detected!!" << std::endl;
253  runtime_assert( false );
254  return 0;
255 }
256 
257 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
258 // @brief finds the first non-ligand residue in the pose (should be the N-terminus)
261 {
262  // This should fail on structures with multiple chains, for now
263 
264  // briefly, loop through the list of residues in the pose, from 1 to N
265  // if the pose is not in the list of ligands, it is the N-terminal residue
266  for( core::Size i = pose.total_residue(); i >= 1; i--) {
267  if ( pose.residue( i ).is_protein() ){
268  return i;
269  }
270  }
271 
272  tr << "No non-ligand residues were detected!!" << std::endl;
273  runtime_assert( false );
274  return 0;
275 }
276 
277 } // match_enzdes_util
278 } // toolbox
279 } //protocols
280