Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
RemodelData.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 // CVS information:
4 // $Revision: 13011 $
5 // $Date: 2007-02-21 17:17:13 -0800 (Wed, 21 Feb 2007) $
6 // $Author: possu $
7 
8 // Rosetta Headers
9 #include <basic/Tracer.hh>
10 // AUTO-REMOVED #include <core/io/pdb/pose_io.hh>
11 
13 //#include <devel/remodel/helpMenu.hh>
14 
15 //for DSSP
17 
18 #include <basic/options/option.hh>
19 #include <basic/options/keys/OptionKeys.hh>
20 // AUTO-REMOVED #include <basic/options/keys/in.OptionKeys.gen.hh>
21 // AUTO-REMOVED #include <basic/options/keys/constraints.OptionKeys.gen.hh>
22 #include <basic/options/keys/remodel.OptionKeys.gen.hh>
23 #include <basic/options/keys/run.OptionKeys.gen.hh>
24 
25 //fragset
26 // AUTO-REMOVED #include <core/fragment/OrderedFragSet.hh>
27 
28 // AUTO-REMOVED #include <protocols/viewer/viewers.hh>
29 
30 
31 // AUTO-REMOVED #include <core/chemical/ResidueType.hh>
32  // for switch typeset
33 
34 
35 // for resfile command map
38 
39 // AUTO-REMOVED #include <protocols/forge/components/VarLengthBuild.hh>
40 
41 // AUTO-REMOVED #include <protocols/loops/LoopMover_QuickCCD_Moves.hh>
42 // AUTO-REMOVED #include <protocols/forge/build/BuildInstruction.hh> // REQUIRED FOR WINDOWS
43 
44 /*
45 //yab headers
46 #include "AtomPoint.hh"
47 #include "BoundingBox.hh"
48 #include "epigraft_functions.hh"
49 #include "Octree.hh"
50 #include "rootstock_types.hh"
51 #include "ccd_functions.hh"
52 */
53 // ObjexxFCL Headers
54 #include <ObjexxFCL/FArray1D.hh>
55 
56 // C++ Headers
57 #include <algorithm>
58 #include <cmath>
59 #include <cstdlib>
60 #include <iostream>
61 #include <sstream>
62 #include <fstream>
63 #include <vector>
64 #include <string>
65 #include <list>
66 #include <map>
67 #include <set>
68 
69 
70 // Utility Headers
71 // AUTO-REMOVED #include <utility/basic_sys_util.hh>
72 #include <utility/io/izstream.hh>
73 // AUTO-REMOVED #include <utility/io/ozstream.hh>
74 // AUTO-REMOVED #include <utility/io/ocstream.hh>
75 // AUTO-REMOVED #include <utility/file/file_sys_util.hh>
76 #include <utility/vector1.hh>
77 
79 
80 
81 
82 //////////////// REMODEL
83 
84 namespace protocols{
85 namespace forge{
86 namespace remodel{
87 
88 static basic::Tracer TR_REMODEL("REMODELd");
89 
90 void
92  int cutAt;
93  while((cutAt = (int)str.find_first_of(delim)) != int(str.npos) ) {
94  if(cutAt > 0) {
95  results.push_back(str.substr(0,cutAt));
96  }
97  str = str.substr(cutAt+1);
98  }
99  if(str.length() > 0) {
100  results.push_back(str);
101  }
102 }
103 
105  has_design_info_ = false;
106  design_neighbor = false;
107  auto_design = false;
108  natro_movemap_.set_chi(true);
109 }
110 
111 void
113 {
114 
115  using namespace basic::options;
116  using namespace basic::options::OptionKeys;
117 
118 // read blueprint file and load everything into the maps
119 // std::string filename(option[basic::options::OptionKeys::remodel::blueprint]());
120 
121  if (filename == ""){
122  TR_REMODEL << "can't find blueprint file for remodel!" << std::endl;
123  }
124  utility::io::izstream data(filename.c_str());
125  if (!data) {
126  TR_REMODEL << "Can't open blueprint file " << filename << std::endl;
127  utility::exit(EXIT_FAILURE, __FILE__, __LINE__);
128  }
129  std::string line;
130 
131  //extension management
132  std::string ext_ss_buffer;
133 
134  std::ostringstream oss; // for resfile parsing
135  //std::ostringstream oss_switch; // for detecting design info
136  oss << "NATRO" << std::endl; // preseve non designed to starting rotamer
137  oss << "start" << std::endl; // mark start for resfile parser
138 
139  // first getting the total line in the file, needed for repeat Resfile
140  // processing
141  int index = 0;
142  while (getline( data, line)){
143  index++;
144  }
145  int length = index;
146 
147  //reset file and counter
148  data.clear();
149  data.seek_beg();
150  index =1;
151 
152  bool mark_start = false;
153  while (getline( data, line)){
154  std::istringstream line_stream(line);
155  std::vector<std::string> split_info;
156  std::ostringstream oss_switch; // for detecting design info
157  this->splitString(line_stream.str(), " ", split_info);
158 
159  // skip comment lines
160  if (split_info[0].at(0) == '#'){
161  continue;
162  }
163 
165  line.isDesignable = false; // initialize design default to false
166  // TR << "index: " << index << std::endl;
167  line.index = index;
168 
169  // debug
170  // line_stream >> line.original_index >> line.resname >> line.sstype >> skip;
171  // this->blueprint.push_back(line);
172  //
173  index++;
174  // could have initialized blueprint after the split, oh well...
175  std::istringstream(split_info[0]) >> line.original_index;
176  if (line.original_index != 0 && mark_start == false){
177  pdb_start = line.original_index;
178  mark_start = true;
179  }
180  if (line.original_index != 0){
181  pdb_stop = line.original_index;
182  }
183 
184  line.resname = split_info[1];
185  line.sstype = split_info[2];
186 
187  // error checking, disallow '#' in columns 1 and 2
188  if (split_info[1].at(0) == '#' || split_info[2].at(0) == '#') {
189  std::ostringstream err_message;
190  err_message << "ERROR: comment marker '#' cannot be in residue or ss column at line:\n";
191  err_message << line_stream.str();
192  utility::exit(__FILE__, __LINE__, err_message.str());
193  }
194 
195  if (split_info.size() > 3){ // has design info
196  // skip comments at end of line
197  if (split_info[3].at(0) == '#'){
198  continue;
199  }
200 
201  for (std::vector<std::string>::iterator it=split_info.begin(), end=split_info.end(); it != end ; it++){
202  if ((*it).substr(0,3) == "CST"){
203  TR_REMODEL << "constraint found " << *it << std::endl;
204  line.has_constraints=true;
205  line.constraint_definition.push_back(*it);
206  }
207  if ((*it).substr(0,3) == "DM_"){
208  disulfMobileRange.push_back(line.index);
209  if (disulfMobileRange.size() > 2){
210  std::ostringstream err_message;
211  err_message << "ERROR: Disulfide mobile range assigment contains " << disulfMobileRange.size() << " elements." << std::endl;
212  utility::exit(__FILE__, __LINE__, err_message.str());
213  }
214  }
215  if ((*it).substr(0,3) == "DS_"){
216  disulfLandingRange.push_back(line.index);
217  if (disulfLandingRange.size() > 2){
218  std::ostringstream err_message;
219  err_message << "ERROR: Disulfide landing range assigment contains " << disulfLandingRange.size() << " elements." << std::endl;
220  utility::exit(__FILE__, __LINE__, err_message.str());
221  }
222  }
223  }
224 
225  std::map< std::string, core::pack::task::ResfileCommandOP > resfile_command_map = core::pack::task::create_command_map();
226 
227  //need to figure out if the line is to be part of Resfile
228  bool design_info = false;
229  int info_count = (int) split_info.size() - 3; //only keep count past 3
230  //std::cout << "split info count: " << (int) split_info.size() << std::endl;
231 
232  for (int i = 3; i< (int)split_info.size(); i++){
233  if (split_info[i].substr(0,3) == "CST" || split_info[i].substr(0,3) == "DM_" || split_info[i].substr(0,3) == "DS_"){
234  //std::cout << " split info: " << split_info[i].substr(0,3) << std::endl;
235  info_count--;
236  }
237  }
238  if ( info_count > 0){
239  design_info = true;
240  }
241 
242  //chain defined by option, no chain by default
243  if (design_info){
244  if (basic::options::option[ OptionKeys::run::chain].user()) {
245  std::string const chain (basic::options::option[ OptionKeys::run::chain]);
246  oss << line.index << " " << chain << " " ;
247  }
248  else {
249  oss << line.index << " _ " ;
250  }
251  }
252 
253  bool pickaa = false;
254  for (int i = 3; i< (int)split_info.size(); i++){
255  if (split_info[i].substr(0,3) != "CST" && split_info[i].substr(0,3) != "DM_" && split_info[i].substr(0,3) != "DS_"){
256  oss << split_info[i] << " " ;
257  oss_switch << split_info[i];
258  }
259  if (split_info[i].substr(0,5) == "PIKAA"){
260  //toggle on manual residue selection switch
261  pickaa = true;
262  continue;
263  }
264  if (pickaa){ // the column following PIKAA
265  for (int j = 0; j < (int)split_info[i].size();++j){ // only find string element size
266 
268  //char one_letter_name(core::chemical::aa_from_oneletter_code(aa));
269  char one_letter_name = split_info[i].substr(j,1).c_str()[0];
270  aa = core::chemical::aa_from_oneletter_code(one_letter_name);
271  TR_REMODEL << " design position to " << one_letter_name << " " << aa << std::endl;
272  line.aminoAcidList.push_back(aa);
273  }
274  pickaa=false; // turns it right off so doesn't get other columns
275  }
276 
277  if ( split_info[i] == "NATRO"){
278  TR_REMODEL << "NATRO movemap setup: turning off chi move for refinement stage: " << line.index << std::endl;
279  natro_movemap_.set_chi(line.index, false);
280  }
281  }
282  if (design_info){
283  oss << std::endl;
284  }
285 
286  // process repeats, pretty dangerous, as this only hacks the resfile string
287  // but not making duplicates in the blueprint held by RemodelData
288  if (option[ OptionKeys::remodel::repeat_structure].user()){
289  for (int rep = 1; rep< option[ OptionKeys::remodel::repeat_structure ]; rep++){
290  //chain defined by option, no chain by default
291  if (basic::options::option[ OptionKeys::run::chain].user()) {
292  std::string const chain (basic::options::option[ OptionKeys::run::chain]);
293  oss << line.index + length*rep << " " << chain << " " ;
294  }
295  else {
296  oss << line.index + length*rep << " _ " ;
297  }
298  for (int i = 3; i< (int)split_info.size(); i++){
299  if (split_info[i].substr(0,3) != "CST"){
300  oss << split_info[i] << " " ;
301  }
302  }
303  oss << std::endl;
304  }
305  }
306 
307  //find out that there's info other than CST and turn on manual modes
308  if (oss_switch.str() != ""){
309  //TR_REMODEL << "oss_switch: " << oss_switch.str() << std::endl;
310  has_design_info_ = true;
311  }
312 
313 
314  // std::cout << "DEBUG parsed STRING " << oss.str() << std::endl;
315  this->parsed_string_for_resfile = oss.str();
316 
317  //TR_REMODEL << "manual design overwrite position: " << line.index << std::endl;
318  //this->design_mode = 3; //default manual mode
319  /*if (option[Remodel::Design::design_neighbors]()){
320  // fully manual design mode automatically switched on when you assign residues by hand
321  this->design_mode = 4;
322  }
323  if (option[Remodel::Design::neighbor_repack]()){
324  // bc repack neigbors
325  this->design_mode = 5;
326  }
327  */
328  line.isDesignable = true;
329  line.design_type = split_info[3];
330  if (!resfile_command_map[line.design_type]){
331  TR_REMODEL << "WARNING: unknown packer token: " << line.design_type << std::endl;
332  }
333 
334  //debug
335  //TR << resfile_command_map[split_info[3]] << " resfile command map to " << split_info[3] << std::endl;
336 
337 /* BUGGY
338  if (split_info.size() > 4 && resfile_command_map[split_info[3]]) { // has manual amino acid assignment
339  for ( int i = 4 ; i < (int)split_info.size(); i++) {
340  // skip comments at end of line
341  if (split_info[i].at(0) == '#'){
342  break;
343  }
344  core::chemical::AA aa;
345  char one_letter_name(core::chemical::aa_from_oneletter_code(aa));
346  one_letter_name = split_info[i].c_str()[0];
347  aa = core::chemical::aa_from_oneletter_code(one_letter_name);
348  TR_REMODEL << " design position to " << one_letter_name << " " << aa << std::endl;
349  line.aminoAcidList.push_back(aa);
350  }
351  }
352  */
353 
354 
355  }
356  this->blueprint.push_back(line);
357  }
358 
359  std::cout << "manual design info" << std::endl << this->parsed_string_for_resfile << std::endl;
360 
361 
362  if ( has_design_info_ ){
363  design_mode = 3;
364  }
365 
366  //process blueprint to initialize all the needed strings/vectors
367  std::vector<protocols::forge::remodel::LineObject>::iterator iter;
368  for ( iter = this->blueprint.begin(); iter != this->blueprint.end(); iter++) {
369  this->sequence.append(iter->resname);
370  this->ss.append(iter->sstype);
371  }
372 
373  translateDSSP_ABEGO(this->ss, this->abego);
374 
375 
376  TR_REMODEL << "sequence: " << std::endl << this->sequence << std::endl;
377  TR_REMODEL << "sstype : " << std::endl << this->ss << std::endl;
378  TR_REMODEL << "ABEGOtype : " << std::endl << this->abego << std::endl;
379 
380 }
381 
382 void
384  size_t found_idx;
385  bool abego_switch = false;
386  found_idx = ss.find_first_of("abgoABGO"); // E is shared so only ABGO for mapping
387  if (found_idx == std::string::npos){
388  std::cout << "SS based assignment found" << std::endl; // in case of only E assignment, treat it as DSSP
389  } else if (found_idx != std::string::npos){
390  abego_switch = true;
391  std::cout << "ABEGO based assignment found" << std::endl;
392  }
393  std::string trans_ss;
394 
395  if (abego_switch){ //need to make a new string with DSSP assignment and swap
396  found_idx = ss.find_first_of("abegoABEGO"); // this substitution use all 5 regions
397  for (core::Size idx = 0; idx < ss.length(); idx++){
398  if (ss[idx] == 'A' || ss[idx] == 'a'){
399  trans_ss.push_back('H');
400  }
401  else if (ss[idx] == 'B' || ss[idx] == 'b'){
402  trans_ss.push_back('E');
403  }
404  else if (ss[idx] == 'E' || ss[idx] == 'e'){
405  trans_ss.push_back('L');
406  }
407  else if (ss[idx] == 'G' || ss[idx] == 'g'){
408  trans_ss.push_back('L');
409  }
410  else if (ss[idx] == 'O' || ss[idx] == 'o'){
411  trans_ss.push_back('L');
412  }
413  else if (ss[idx] == '.'){
414  trans_ss.push_back('.');
415  ss[idx]= 'X';
416  }
417  else{ // could have other characters like I, or D so leave them alone
418  trans_ss.push_back(ss[idx]);
419  }
420  }
421  trans_ss.swap(ss);
422  }
423  abego = trans_ss;
424 }
425 
426 
427 
428 
429 void
431  for (int i = 0; i < (int)ss.size(); i++){
432  int idx = this->blueprint[i].original_index;
433  char const * ss_chars = ss.c_str();
434  if (ss_chars[i] != '.'){
435  dssp_updated_ss.append(1, ss_chars[i]);
436  }
437  else {
438  dssp_updated_ss.append(1, dsspSS(idx));
439  }
440  }
441  //turn upper case if not already so
442  std::transform(dssp_updated_ss.begin(), dssp_updated_ss.end(), dssp_updated_ss.begin(), ::toupper);
443  TR_REMODEL << "dssp_updated_ss: lengths = " << dssp_updated_ss.length() << std::endl << dssp_updated_ss << std::endl;
444 }
445 
446 void
448 
449  core::import_pose::pose_from_pdb( insertPose, basic::options::option[basic::options::OptionKeys::remodel::domainFusion::insert_segment_from_pdb]());
450  insertionSize = (int)insertPose.total_residue();
451  core::scoring::dssp::Dssp dssp(insertPose);
452  ObjexxFCL::FArray1D_char dsspSS((int)insertPose.total_residue());
453  dssp.dssp_reduced(dsspSS);
454  for (int i = 1; i <= (int)dsspSS.size(); i++){
455  insertionSS.push_back(dsspSS(i));
456  }
457  std::cout << "insertion SS: " << insertionSS << std::endl;
458 }
459 
460 } //namespace remodel
461 } //namespace forge
462 } //namespace protocols