Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
StartFrom.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 core/pack/task/ResfileReader.cc
11 /// @brief implementation of resfile reader and its command classes
12 /// @author Gordon Lemmon (glemmon@gmail.com)
13 ///
14 
15 // Unit Headers
18 
21 
22 //project headers
23 #include <numeric/random/random.hh>
24 #include <basic/Tracer.hh>
25 #include <core/types.hh>
27 #include <core/pose/util.hh>
28 #include <protocols/jd2/Job.hh>
30 
31 // Utility Headers
32 
33 #include <utility/tag/Tag.hh>
34 #include <utility/exit.hh>
35 #include <utility/vector0.hh>
36 #include <utility/vector1.hh>
37 #include <utility/string_util.hh>
38 #include <utility/io/izstream.hh>
39 
40 #include <utility/json_spirit/json_spirit_reader.h>
41 
42 // Boost headers
43 #include <boost/foreach.hpp>
44 #define foreach BOOST_FOREACH
45 
46 #include <utility/excn/Exceptions.hh>
47 #include <fstream>
48 
49 using basic::T;
50 using basic::Error;
51 using basic::Warning;
52 
53 namespace protocols {
54 namespace ligand_docking {
55 
56 static basic::Tracer start_from_tracer("protocols.ligand_docking.ligand_options.Start_from", basic::t_debug);
57 
60 {
62 }
63 
66  return new StartFrom;
67 }
68 
71 {
72  return "StartFrom";
73 }
74 
75 ///@brief
77  //utility::pointer::ReferenceCount(),
78  Mover("StartFrom"),
79  chain_(""),
80  starting_points_(){}
81 
83  //utility::pointer::ReferenceCount(),
84  protocols::moves::Mover( that ),
85  chain_(that.chain_),
86  starting_points_(that.starting_points_),
87  potential_starting_positions_(that.potential_starting_positions_)
88 {}
89 
91 
93  return new StartFrom( *this );
94 }
95 
97  return new StartFrom;
98 }
99 
101  return "StartFrom";
102 }
103 
104 ///@brief parse XML (specifically in the context of the parser/scripting scheme)
105 void
107  utility::tag::TagPtr const tag,
108  protocols::moves::DataMap & /*datamap*/,
109  protocols::filters::Filters_map const & /*filters*/,
110  protocols::moves::Movers_map const & /*movers*/,
111  core::pose::Pose const & /*pose*/
112 )
113 {
114  if ( tag->getName() != "StartFrom" ){
115  throw utility::excn::EXCN_RosettaScriptsOption("This should be impossible");
116  }
117  if ( ! tag->hasOption("chain") ) throw utility::excn::EXCN_RosettaScriptsOption("'StartFrom' mover requires chain tag");
118 
119  chain_ = tag->getOption<std::string>("chain");
120 
121  foreach(utility::tag::TagPtr child_tag, tag->getTags()){
122  std::string name= child_tag->getName();
123  if( name == "features"){
124  std::cout << "found features tag with type '" << child_tag->getOption<std::string>("type") << "'" << std::endl;
125 
126  } else if( name == "Coordinates")
127  {
128  if ( ! child_tag->hasOption("x") ) throw utility::excn::EXCN_RosettaScriptsOption("'StartFrom' mover Coordinates tag requires 'x' coordinates option");
129  if ( ! child_tag->hasOption("y") ) throw utility::excn::EXCN_RosettaScriptsOption("'StartFrom' mover Coordinates tag requires 'y' coordinates option");
130  if ( ! child_tag->hasOption("z") ) throw utility::excn::EXCN_RosettaScriptsOption("'StartFrom' mover Coordinates tag requires 'z' coordinates option");
131 
132  std::string pdb_tag = "default";
133  if(child_tag->hasOption("pdb_tag"))
134  {
135  pdb_tag = child_tag->getOption<std::string>("pdb_tag");
136  }
137 
138  core::Vector v(
139  child_tag->getOption<core::Real>("x"),
140  child_tag->getOption<core::Real>("y"),
141  child_tag->getOption<core::Real>("z")
142  );
143 
144  coords(v,pdb_tag);
145  }else if(name == "File")
146  {
147  if(!child_tag->hasOption("filename")) throw utility::excn::EXCN_RosettaScriptsOption("'StartFrom' mover File tag requires 'filename' coordinates option");
148  parse_startfrom_file(child_tag->getOption<std::string>("filename"));
149 
150  }
151  }
152 }
153 
154 void StartFrom::coords(core::Vector const & coords,std::string const & pdb_tag)
155 {
156  std::map< std::string, utility::vector1<core::Vector> >::iterator start_point_it = starting_points_.find(pdb_tag);
157 
158  if(start_point_it == starting_points_.end())
159  {
160  utility::vector1<core::Vector> new_point_set;
161  new_point_set.push_back(coords);
162  starting_points_.insert(std::make_pair(pdb_tag,new_point_set));
163  }else
164  {
165  start_point_it->second.push_back(coords);
166  }
167 }
168 
169 void StartFrom::chain(std::string const & chain)
170 {
171  chain_ = chain;
172 }
173 
175  assert(!starting_points_.empty() || !potential_starting_positions_.empty());
176  int const starting_point_index= numeric::random::RG.random_range(1, starting_points_.size());
177 
178  if(!core::pose::has_chain(chain_,pose))
179  {
180  utility_exit_with_message("StartFrom mover cannot find the chain " +chain_+ " in the current pose.");
181  }
182 
183  if(!starting_points_.empty())
184  {
186  std::list<std::string> component_tags(utility::split_to_list(input_tag));
187 
188  utility::vector1<core::Vector> centroid_points;
189 
190  for(std::list<std::string>::iterator tag_it = component_tags.begin(); tag_it != component_tags.end();++tag_it)
191  {
192  std::map< std::string, utility::vector1<core::Vector> >::iterator tag_points( starting_points_.find(*tag_it));
193  if(tag_points != starting_points_.end())
194  {
195  centroid_points = tag_points->second;
196  break;
197  }else
198  {
199  tag_points = starting_points_.find("default");
200  if(tag_points == starting_points_.end())
201  {
202  utility_exit_with_message("There are no default starting coordinates specified in the StartFrom mover, and none of the specified coordinates match the current tag");
203  }
204  centroid_points = tag_points->second;
205  break;
206  }
207  }
208  assert(centroid_points.size());
209 
210  core::Vector desired_centroid = centroid_points[starting_point_index];
211 
213  move_ligand_to_desired_centroid(jump_id, desired_centroid, pose);
214  }else if(!potential_starting_positions_.empty())
215  {
217  std::map<std::string,core::Vector >::iterator position_hash = potential_starting_positions_.find(hash);
218  if(position_hash != potential_starting_positions_.end())
219  {
221  move_ligand_to_desired_centroid(jump_id, position_hash->second , pose);
222  }else
223  {
224  start_from_tracer << "cannot find structure with hash " <<hash <<" and tag " <<
225  protocols::jd2::JobDistributor::get_instance()->current_job()->input_tag() << std::endl;
226  utility_exit_with_message("the current structure is not in the startfrom_file");
227  }
228  }else
229  {
230  utility_exit_with_message("You must specify either a Coordinates or a File tag in the StartFrom mover");
231  }
232 }
233 
235 {
236  utility::io::izstream infile;
237  infile.open(filename.c_str(),std::ifstream::in);
238  utility::json_spirit::mValue startfrom_data;
239  utility::json_spirit::read(infile,startfrom_data);
240  infile.close();
241 
242  //The format is something like this:
243  /*
244  [
245  {
246  "input_tag" : "infile.pdb",
247  "x" : 0.0020,
248  "y" : -0.004,
249  "z" : 0.0020,
250  "hash" : "aa2aff055d19bc32e483df7ff4ae08361a768931"
251  }
252  ]
253  */
254 
255  utility::json_spirit::mArray start_positions = startfrom_data.get_array();
256  for(utility::json_spirit::mArray::iterator start_it = start_positions.begin(); start_it != start_positions.end();++start_it)
257  {
258  utility::json_spirit::mObject position_data(start_it->get_obj());
259 
260  std::string hash = position_data["hash"].get_str();
261  core::Real x = position_data["x"].get_real();
262  core::Real y = position_data["y"].get_real();
263  core::Real z = position_data["z"].get_real();
264 
265  core::Vector coords(x,y,z);
267  {
268 
269  start_from_tracer << "WARNING: There is more than one entry in the startfrom_file with the hash " << hash <<std::endl;
270  //utility_exit_with_message("hashes in startfrom files must all be unique");
271  }
273 
274  }
275 
276 }
277 
278 void
280  core::Size const jump_id,
281  core::Vector const desired_centroid,
282  core::pose::Pose & pose
283 ){
284  core::Vector const ligand_centroid = protocols::geometry::downstream_centroid_by_jump(pose, jump_id);
285  core::Vector const trans_vec = desired_centroid - ligand_centroid;
286  core::Real const trans_len = trans_vec.length();
287  if (trans_len > 1e-3) { // otherwise we get NaNs
288  protocols::rigid::RigidBodyTransMover mover(pose, jump_id);
289  mover.step_size(trans_len);
290  mover.trans_axis(trans_vec);
291  mover.apply(pose);
292  }
293 }
294 
295 
296 } //namespace ligand_docking
297 } //namespace protocols