Rosetta
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
contactMap.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 contactMap.cc
11 /// @brief simple application for creating a contact map from multiple models of the same protein.
12 /// @author Joerg Schaarschmidt
13 
14 //include block
15 // C++ headers
16 #include <string>
17 
18 // libRosetta headers
19 
20 #include <devel/init.hh>
21 
22 #include <core/types.hh>
23 #include <basic/Tracer.hh>
24 #include <utility/tag/Tag.hh>
25 #include <utility/vector1.hh>
26 
27 #include <core/chemical/ResidueTypeSet.fwd.hh>
28 #include <core/chemical/ChemicalManager.hh>
29 
30 #include <protocols/filters/Filter.fwd.hh>
31 //#include <protocols/moves/Mover.hh>
33 #include <protocols/contact_map/ContactMap.hh>
34 
35 #include <core/pose/Pose.hh>
36 
37 #include <core/import_pose/pose_stream/util.hh>
38 #include <core/import_pose/pose_stream/MetaPoseInputStream.hh>
39 
40 // option key includes
41 #include <basic/options/option.hh>
42 #include <basic/options/keys/in.OptionKeys.gen.hh>
43 #include <basic/options/keys/contactMap.OptionKeys.gen.hh>
45 
47 
48 
49 // declare variables that need to be accessed outside the main routine
50 static THREAD_LOCAL basic::Tracer tr( "contactMap" );
51 
52 // Method to process region definition string into a vector of initialized ContactMap movers
54 
56  std::string current_region = "";
57 
58  // parameters for parse_my_tag routine
59  protocols::moves::Movers_map movers;
60  protocols::filters::Filters_map filters;
62 
63  if ( region_def == "" ) {
64  std::ostringstream oss;
65  oss << "1-" << pose.n_residue();
66  region_def = oss.str();
67  }
68  // split region_def into single regions and process each separately
69  while ( region_def != "" ) {
70  using namespace basic::options;
71  using namespace basic::options::OptionKeys;
72  using namespace utility::tag;
73  TagOP tag( new Tag() );
74  core::Size pos = region_def.find(',');
75  if ( pos == std::string::npos ) {
76  current_region = region_def;
77  region_def = "";
78  } else {
79  current_region = region_def.substr(0, pos);
80  region_def = region_def.substr(pos+1);
81  }
82  pos=current_region.find(':');
83  // set regionX and ligand tags corresponding to region definiton
84  if ( pos == std::string::npos ) {
85  tag->setOption("region1", current_region);
86  } else if ( current_region.find("ligand=")==std::string::npos ) {
87  tag->setOption("region1", current_region.substr(0, pos));
88  tag->setOption("region2", current_region.substr(pos+1));
89  } else {
90  if ( current_region.find("ligand=")>pos ) {
91  tag->setOption("region1", current_region.substr(0, pos));
92  tag->setOption("ligand", current_region.substr(pos+8));
93  } else {
94  tag->setOption("region1", current_region.substr(pos+1));
95  tag->setOption("ligand", current_region.substr(7,pos-7));
96  }
97  }
98  // instantiate ContactMap and call parse_my_tag routine
100  tag->setOption("distance_cutoff", option[contactMap::distance_cutoff]());
101  tag->setOption("models_per_file", 0);
102  if ( option[contactMap::row_format]() ) tag->setOption("row_format", "true");
103  if ( option[contactMap::distance_matrix]() ) tag->setOption("distance_matrix", "true");
104  cm.parse_my_tag( tag, data, filters , movers, pose);
105  // set output prefix for region
106  std::string output_prefix(option[contactMap::prefix]());
107  output_prefix +=current_region;
108  cm.set_output_prefix(output_prefix);
109  // add ContactMap to maps vector
110  maps.push_back(cm);
111  }
112  return maps;
113 }
114 
115 // main function
116 int main(int argc, char* argv[]) {
117 
118  try {
119 
120  using namespace core::chemical;
121  using namespace core::import_pose::pose_stream;
122  using namespace basic::options;
123  using namespace basic::options::OptionKeys;
124  using namespace core;
125 
126  // define protocol specific options
127  OPT(contactMap::prefix);
128  OPT(contactMap::distance_cutoff);
129  OPT(contactMap::region_def);
130  OPT(contactMap::row_format);
131  OPT(contactMap::distance_matrix);
132 
133  // define relevant standard options
135  OPT(in::file::s);
136  OPT(in::file::l);
138  OPT(in::file::tags);
139  OPT(in::file::silent_struct_type);
140  OPT(in::file::residue_type_set);
141  OPT(in::file::extra_res);
142  OPT(in::file::extra_res_fa);
143  OPT(in::file::extra_res_cen);
144 
145  // options, random initialization
146  devel::init(argc, argv);
147 
148  // initialize variables
149  core::chemical::ResidueTypeSetCOP rsd_set =
150  ChemicalManager::get_instance()->residue_type_set(
151  option[in::file::residue_type_set]());
152 
154 
155  // instantiate PoseInputStream based on input option
156  MetaPoseInputStream input( streams_from_cmd_line() );
157 
158  // exit if no poses are supplied
159  if ( ! input.has_another_pose() ) {
160  tr.Info << "No pose supplied - exiting without further action! "<< std::endl;
161  return 0;
162  }
163 
164  // use first pose to initialize ContactMaps
165  input.fill_pose(pose, *rsd_set);
166 
167  // process region_def option and initialize ContactMaps
169  maps = processRegions(option[contactMap::region_def](), pose);
170 
171  // reset PoseInputStream
172  input.reset();
173 
174  // process poses
175  while ( input.has_another_pose() ) {
176  input.fill_pose(pose, *rsd_set);
177  // loop over ContactMaps and call apply function
178  for ( core::Size i=1 ; i <= maps.size(); i++ ) {
179  maps[i].apply(pose);
180  }
181  }
182  // loop over ContactMaps and write each one to the corresponding file
183  for ( core::Size i=1 ; i <= maps.size(); i++ ) {
184  maps[i].write_to_file();
185  }
186 
187  return 0;
188 
189  } catch ( utility::excn::EXCN_Base const & e ) {
190  std::cout << "caught exception " << e.msg() << std::endl;
191  return -1;
192  }
193 
194 } // main
int main(int argc, char *argv[])
Definition: contactMap.cc:116
#define THREAD_LOCAL
virtual std::string const msg() const
Definition: EXCN_Base.hh:70
void init(int argc, char *argv[])
Command line init() version.
Definition: init.cc:23
core::pose::Pose Pose
Definition: supercharge.cc:101
TracerProxy Info
Definition: Tracer.hh:262
tuple database
Tracer IO system.
std::vector with 1-based indexing
Definition: vector1.fwd.hh:44
utility::pointer::shared_ptr< Tag > TagOP
Definition: Tag.fwd.hh:26
rule< Scanner, options_closure::context_t > options
Definition: Tag.cc:377
utility::options::OptionCollection option
OptionCollection global.
Definition: option.cc:45
general-purpose store for any reference-count derived object
Definition: DataMap.hh:36
static THREAD_LOCAL basic::Tracer tr("contactMap")
utility::vector1< ContactMap > processRegions(std::string region_def, core::pose::Pose const &pose)
Definition: contactMap.cc:53
ocstream cout(std::cout)
Wrapper around std::cout.
Definition: ocstream.hh:287
vector1: std::vector with 1-based indexing
protocols::contact_map::ContactMap ContactMap
Definition: contactMap.cc:46
Class for handling user debug/warnings/errors. Use instance of this class instead of 'std::cout' for ...
Definition: Tracer.hh:134
An object for reading/writing a simple xml-like language.
Program options global and initialization function.
rule< Scanner, tag_closure::context_t > tag
Definition: Tag.cc:373
#define OPT(akey)
platform::Size Size
Definition: random.fwd.hh:30
int const silent
Named verbosity levels.