Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
StructureRestrictor.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 // This file is part of the Rosetta software suite and is made available under license.
5 // The Rosetta software is developed by the contributing members of the Rosetta Commons consortium.
6 // (C) 199x-2009 Rosetta Commons participating institutions and developers.
7 // For more information, see http://www.rosettacommons.org/.
8 
9 /// @file protocols/moves/StructureRestrictor.cc
10 ///
11 /// @brief lookup relevant chains for a structure in a table.
12 /// @author Matthew O'Meara
13 
14 /// This should probably be a pilot app, but the way Rosetta Scripts
15 /// is set up, it can't be in the pilot apps
16 
17 #include <boost/algorithm/string.hpp>
20 #include <core/pose/Pose.hh>
21 #include <core/pose/PDBInfo.hh>
22 #include <basic/datacache/BasicDataCache.hh>
23 #include <basic/datacache/CacheableString.hh>
24 #include <basic/Tracer.hh>
27 
28 
29 #include <utility/io/izstream.hh>
30 #include <utility/tag/Tag.hh>
31 
32 
33 #include <string>
34 
35 #include <protocols/jd2/Job.hh>
36 #include <utility/vector0.hh>
37 #include <utility/vector1.hh>
38 
39 
40 using namespace std;
41 using namespace boost;
42 using namespace core;
43  using namespace pose;
44  using namespace protocols::jd2;
45 
46 basic::Tracer TR_SR("protocols.moves.StructureRestrictor");
47 
48 namespace protocols{
49 namespace moves{
50 
51 StructureRestrictor::StructureRestrictor():
52  Mover("StructureRestrictor"),
53  // relevant_chains_fname( basic::options::option[ basic::options::OptionKeys::StructureRestrictor::relevant_chains].value() ),
54  initialized( false )
55 {}
56 
58  Mover(name),
59  // relevant_chains_fname( basic::options::option[ basic::options::OptionKeys::StructureRestrictor::relevant_chains].value() ),
60  initialized( false )
61 {}
62 
64  //utility::pointer::ReferenceCount(),
65  Mover(src)
66 {
67  chain_map = src.chain_map;
70 }
71 
73 
75 
77 {
78  return new StructureRestrictor( *this );
79 }
80 
81 
82 // So this this can be called from RosettaScripts
83 void
85  TagPtr const tag,
86  protocols::moves::DataMap & /*data*/,
87  Filters_map const & /*filters*/,
88  protocols::moves::Movers_map const & /*movers*/,
89  Pose const & /*pose*/ )
90 {
91  if( tag->hasOption("relevant_chains") ){
92  relevant_chains_fname = tag->getOption<string>("relevant_chains");
93  }
94 }
95 
96 void
98  string const & relevant_chains_fname,
99  map<string const, string const> & chain_map
100  ){
101  if(relevant_chains_fname.length() == 0){
102  TR_SR.Error << " Cannot open relevant_chains_file '"<< relevant_chains_fname << "'" << endl;
103  return;
104  }
105  utility::io::izstream relevant_chains_file( relevant_chains_fname );
106  if ( !relevant_chains_file ){
107  TR_SR.Error << " Cannot open relevant_chains_file '"<< relevant_chains_fname << "'" << endl;
108  return;
109  } else {
110  TR_SR << "Reading in relevant chains from file '"<< relevant_chains_fname << "'" << endl;
111  }
112  string line;
113  string chains = "*";
114  vector<string> tokens;
115  getline(relevant_chains_file,line); // header
116  while( getline( relevant_chains_file, line ) ){
117  string tab("\t");
118  split(tokens, line, is_any_of(tab) );
119  chain_map.insert(std::pair<string const, string const>(tokens[0], tokens[1]));
120  }
121  initialized = true;
122 }
123 
124 // this is a hack because poses do not have canonical names!
125 string
127  //silent files and pdbs set the name of the pose differently
128  string name = "No_Name_Found";
129  if (pose.pdb_info()){
130  name = pose.pdb_info()->name();
131  } else if ( pose.data().has( datacache::CacheableDataType::JOBDIST_OUTPUT_TAG ) ) {
132  name = static_cast< basic::datacache::CacheableString const & >
133  ( pose.data().get( datacache::CacheableDataType::JOBDIST_OUTPUT_TAG ) ).str();
134  } else {
135  name = JobDistributor::get_instance()->current_job()->input_tag();
136  }
137  return name;
138 }
139 
140 
141 void
143  if( !initialized){
145  }
146 
147 
148  string const & name = pose_name(pose);
149  map<string const, string const>::iterator i(chain_map.find(name));
150  if (i == chain_map.end()){
151  TR_SR << "No chain information found for structure " << name << "." << endl;
152  return;
153  }
154  string chains = i->second;
155  TR_SR << "Restricting structure " << name << " to chains " << chains << "." << endl;
156  Size res_begin_delete = 1;
157  for(Size i=1; i <= pose.total_residue(); ++i){
158  //INVARIANT: if we're in a stretch to delete then res_begin_delete
159  //indicates the first residue in this stretch to delete
160  if(chains.find( pose.pdb_info()->chain(i), 0) != string::npos){
161  //keep this position
162  if (res_begin_delete != i){
163  pose.conformation().delete_residue_range_slow(res_begin_delete, i-1);
164  }
165  res_begin_delete = i+1;
166  }
167  }
168  // don't for get the last section to delete
169  if(res_begin_delete <= pose.total_residue()){
170  pose.conformation().delete_residue_range_slow(res_begin_delete, pose.total_residue());
171  }
172 }
173 
174 
175 } // moves namespace
176 } // protocols namespace