Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
qsarMap.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/ligand_docking/qsar/qsarMap.cc
11 /// @author Sam DeLuca
12 
14 //#include <protocols/qsar/qsarTypeManager.hh>
17 #include <basic/Tracer.hh>
18 #include <utility/string_util.hh>
19 #include <map>
20 
21 #include <utility/vector1.hh>
22 
23 
24 namespace protocols {
25 namespace qsar {
26 
27 /// @details Auto-generated virtual destructor
29 
30 /// @details Auto-generated virtual destructor
32 
33 static basic::Tracer qsarMapTracer("protocols.qsar.qsarMap");
34 
35 
37  type_(type), value_(value), atom_name_(name), residue_(residue)
38 {}
39 
41 {
42  value_ = value;
43 }
44 
46 {
47  return value_;
48 }
49 
51 {
52  return type_;
53 }
54 
56 {
57  return atom_name_;
58 }
59 
61 {
62  return residue_;
63 }
64 
66  map_name_(map_name), residue_(residue)
67 { }
68 
70 {
71  return qsar_map_.size();
72 }
73 
75 {
76  this->clear();
77  core::Size const heavy_atom_size(residue_->nheavyatoms());
78  //std::cout << "atom size" << heavy_atom_size <<std::endl;
79 
80  for(core::Size atom_index = 1; atom_index <= heavy_atom_size; ++atom_index)
81  {
82  std::string atom_name(residue_->atom_name(atom_index));
83  for(core::Size grid_index = 1; grid_index <= grids_to_use.size(); ++grid_index)
84  {
85  //qsarType current_type(static_cast<qsarType>(enum_index));
86  qsarPointOP current_point(new qsarPoint(grids_to_use[grid_index],value,atom_name,residue_));
87  std::string point_name(grids_to_use[grid_index]+"_"+atom_name);
88  this->add_point(point_name,current_point);
89  }
90  }
91 
92  //std::cout << "filled with value"<<std::endl;
93 }
94 
96 {
97  //the mol data line has type qsar_map. it is a collection of lines like this:
98  //atomno\tqsar_type\tqsar_weight
99  //atomno is a Size, qsar_type is a string, qsar_weight is a float
100  this->clear();
101  utility::vector1<std::string> data_lines(mol_data.get_mol_data_string_vector("qsar_map", '\n'));
102  if(data_lines.size() == 0)
103  {
104  return false;
105  }
106 
107  for(core::Size index = 1; index <= data_lines.size(); ++index)
108  {
109  std::string line(data_lines[index]);
110 
111  utility::vector1<std::string> line_fields(utility::string_split(line, '\t'));
112  if(line_fields.size() != 3)
113  {
114  utility_exit_with_message("a qsar_map data line doesn't have 3 fields. something is wrong. Aborting.");
115  }
116 
117  std::string atom_name(residue_->atom_name(utility::string2int(line_fields[1])));
118  std::string qsar_type(line_fields[2]);
119  //qsarType qsar_type(qsarTypeManager::qsar_type_from_name(line_fields[2]));
120  core::Real qsar_weight(utility::string2float(line_fields[3]));
121  qsarPointOP current_point(new qsarPoint(qsar_type,qsar_weight,atom_name,residue_));
122  std::string point_name(line_fields[3]+"_"+atom_name);
123  this->add_point(point_name,current_point);
124  }
125  return true;
126 }
127 
128 void qsarMap::add_point(std::string point_name, qsarPointOP new_point)
129 {
130  std::pair<std::string, qsarPointOP> new_qsar_map_item(point_name,new_point);
131 
132  std::string new_point_type(new_point->get_type());
133  //qsarType new_point_type(new_point->get_type());
134  std::pair<std::string,qsarPointOP> new_type_map_item(new_point_type,new_point);
135 
136  core::conformation::ResidueOP point_residue(new_point->get_residue());
137  std::string atom_name(new_point->get_name());
138  core::Size atom_index(point_residue->atom_index(atom_name));
139 
140  std::pair<core::Size, qsarPointOP> new_atom_map_item(atom_index,new_point);
141 
142  qsar_map_.insert(new_qsar_map_item);
143  type_map_.insert(new_type_map_item);
144  atom_map_.insert(new_atom_map_item);
145 }
146 
148 {
149  qsar_map_.clear();
150  type_map_.clear();
151  atom_map_.clear();
152 }
153 
155 {
156  std::map<std::string,qsarPointOP>::iterator point(qsar_map_.find(point_name));
157  if(point == qsar_map_.end())
158  {
159  return 0;
160  }else
161  {
162  return point->second;
163  }
164 }
165 
167 {
168  std::multimap<core::Size, qsarPointOP>::iterator lower_bound(atom_map_.lower_bound(atom_id));
169  std::multimap<core::Size, qsarPointOP>::iterator upper_bound(atom_map_.upper_bound(atom_id));
170 
171  std::multimap<core::Size,qsarPointOP>::iterator current_point(lower_bound);
172  for(; current_point !=upper_bound; ++current_point)
173  {
174  qsarPointOP point = current_point->second;
175  if(point->get_type() == type)
176  {
177  return point;
178  }
179  }
180  qsarMapTracer << "couldn't find a point, returning 0" <<std::endl;
181  return 0;
182 
183 }
184 
186 {
187  return residue_;
188 }
189 
191 {
193 
194  std::multimap<core::Size, qsarPointOP>::iterator lower_bound(atom_map_.lower_bound(atom_id));
195  std::multimap<core::Size, qsarPointOP>::iterator upper_bound(atom_map_.upper_bound(atom_id));
196 
197  std::multimap<core::Size,qsarPointOP>::iterator current_point(lower_bound);
198  for(; current_point != upper_bound; ++current_point)
199  {
200  points.push_back(current_point->second);
201  }
202 
203  return points;
204 }
205 
206 
208 {
210 
211  std::multimap<std::string, qsarPointOP>::iterator lower_bound(type_map_.lower_bound(type));
212  std::multimap<std::string, qsarPointOP>::iterator upper_bound(type_map_.upper_bound(type));
213 
214  std::multimap<std::string,qsarPointOP>::iterator current_point(lower_bound);
215  for(; current_point != upper_bound; ++current_point)
216  {
217  points.push_back(current_point->second);
218  }
219 
220  return points;
221 }
222 
223 }
224 }