Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ResidueDecompositionByChainCalculator.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/PoseMetricCalculators/ResidueDecompositionByChainCalculator.cc
11 /// @brief ResidueDecompositionByChainCalculator class
12 /// @author Colin A. Smith
13 
14 // Unit headers
16 
18 #include <core/pose/Pose.hh>
19 #include <core/pose/PDBInfo.hh>
20 
21 #include <utility/string_util.hh>
22 
23 #include <cassert>
24 
25 #include <utility/vector1.hh>
26 
27 
28 using namespace core;
29 using namespace core::pose;
30 using namespace core::pose::metrics;
31 
32 namespace protocols{
33 namespace toolbox {
34 namespace pose_metric_calculators {
35 
36 
37 ResidueDecompositionByChainCalculator::ResidueDecompositionByChainCalculator() :
39  use_numbers_(false)
40 {
41 }
42 
44  ResidueDecompositionByChainCalculator const & calculator
45 ):
47  chain_letters_(calculator.chain_letters()),
48  chain_numbers_(calculator.chain_numbers()),
49  use_numbers_(calculator.use_numbers())
50 {
51 }
52 
55  return new ResidueDecompositionByChainCalculator(*this);
56 }
57 
58 void
60  core::pose::Pose const & this_pose
61 )
62 {
63  if (use_numbers_) {
64  // create a map from chain number to set number
65  std::map<core::Size, core::Size> chain_map;
66  if (chain_numbers_.size()) {
67  set_names_.assign(chain_numbers_.size(), "");
68  for (core::Size i = 1; i <= chain_numbers_.size(); ++i) {
69  for (std::set<core::Size>::iterator iter = chain_numbers_[i].begin(); iter != chain_numbers_[i].end(); ++iter) {
70  // there shouldn't be any duplicate chains in the the sets
71  runtime_assert(chain_map.find(*iter) == chain_map.end());
72  chain_map[*iter] = i;
73  if (set_names_[i] != "") set_names_[i] += ",";
74  set_names_[i] += utility::to_string(*iter);
75  }
76  }
78  } else {
79  // create separate sets for each chain
80  set_names_.resize(this_pose.conformation().num_chains());
81  for (core::Size i = 1; i <= this_pose.conformation().num_chains(); ++i) {
82  chain_map[i] = i;
83  set_names_[i] = utility::to_string(i);
84  }
85  residue_decomposition_.resize(this_pose.conformation().num_chains());
86  }
87 
88  residue_set_numbers_.assign(this_pose.total_residue(), 0);
89  for (core::Size i = 1; i <= this_pose.total_residue(); ++i) {
90  std::map<core::Size, core::Size>::iterator iter(chain_map.find(this_pose.chain(i)));
91  if (iter != chain_map.end()) {
92  residue_decomposition_[iter->second].insert(i);
93  residue_set_numbers_[i] = iter->second;
94  }
95  }
96 
97  } else {
98  runtime_assert(this_pose.pdb_info());
99  // create a map from chain letter to set number
100  std::map<char, core::Size> chain_map;
101  if (chain_letters_.size()) {
102  set_names_.assign(chain_letters_.size(), "");
103  for (core::Size i = 1; i <= chain_letters_.size(); ++i) {
104  for (std::set<char>::iterator iter = chain_letters_[i].begin(); iter != chain_letters_[i].end(); ++iter) {
105  // there shouldn't be any duplicate chains in the the sets
106  runtime_assert(chain_map.find(*iter) == chain_map.end());
107  chain_map[*iter] = i;
108  if (set_names_[i] != "") set_names_[i] += ",";
109  set_names_[i] += utility::to_string(*iter);
110  }
111  }
112  residue_decomposition_.resize(chain_letters_.size());
113  } else {
114  // create separate sets for each chain
115  set_names_.clear();
116  for (core::Size i = 1; i <= this_pose.total_residue(); ++i) {
117  if (chain_map.find(this_pose.pdb_info()->chain(i)) == chain_map.end()) {
118  core::Size const chain_map_size(chain_map.size());
119  chain_map[this_pose.pdb_info()->chain(i)] = chain_map_size+1;
120  set_names_.push_back(utility::to_string(this_pose.pdb_info()->chain(i)));
121  }
122  }
123  residue_decomposition_.resize(chain_map.size());
124  }
125 
126  residue_set_numbers_.assign(this_pose.total_residue(), 0);
127  for (core::Size i = 1; i <= this_pose.total_residue(); ++i) {
128  std::map<char, core::Size>::iterator iter(chain_map.find(this_pose.pdb_info()->chain(i)));
129  if (iter != chain_map.end()) {
130  residue_decomposition_[iter->second].insert(i);
131  residue_set_numbers_[i] = iter->second;
132  }
133  }
134  }
135 }
136 
137 
138 } // PoseMetricCalculators
139 } // toolbox
140 } // protocols