Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ctab_base.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 src/core/chemical/sdf/ctab_base.cc
11 /// @author Sam DeLuca
12 
15 #include <core/chemical/Atom.hh>
20 // AUTO-REMOVED #include <utility/string_util.hh>
21 
22 #include <basic/Tracer.hh>
23 
25 #include <utility/vector1.hh>
26 
27 
28 namespace core {
29 namespace chemical {
30 namespace sdf {
31 
32 static basic::Tracer ctabParserTracer("core.io.sdf.ctab_parser");
33 
35 {
36  e_to_t["C"]="CH3"; //Mult
37  e_to_t["N"]="Nbb"; //Mult
38  e_to_t["O"]="OH"; //Mult
39  e_to_t["S"]="S";
40  e_to_t["P"]="P";
41  e_to_t["H"]="Hpol"; //Mult
42  e_to_t["F"]="F";
43  e_to_t["Cl"]="Cl";
44  e_to_t["Br"]="Br";
45  e_to_t["I"]="I";
46  e_to_t["Zn"]="Zn2p";
47  e_to_t["Fe"]="Fe2p"; //Mult
48  e_to_t["Mg"]="Mg2p";
49  e_to_t["Ca"]="Ca2p";
50  e_to_t["Na"]="Na1p";
51  e_to_t["K"]="K1p";
52 
53 }
54 
56 {
57  std::map<std::string, std::string>::iterator val = e_to_t.find(key);
58  std::string type;
59  if (val==e_to_t.end()) {type="VIRT";}
60  else { type=val->second;}
61  return type;
62 }
63 
64 CtabBase::CtabBase(utility::vector1<std::string> const & connection_table_lines,
65  core::chemical::ResidueTypeOP molecule_container, MolData const & mol_data) :
66  connection_table_lines_(connection_table_lines),
67  molecule_container_(molecule_container),
68  mol_data_(mol_data)
69 {
71  bond_type_data_set_ = parse_bond_type_data(mol_data_.get_mol_data("PUBCHEM_BONDANNOTATIONS"));
72 }
73 
75 {
76 
77 }
78 
80 {
81  return molecule_container_;
82 }
83 
85 {
86  return connection_table_lines_.size();
87 }
88 
90 {
91  return connection_table_lines_[line_number];
92 }
93 
94 void CtabBase::add_index_name_pair(core::Size const index, std::string const atomname)
95 {
96  index_to_names_map_.insert(std::pair<core::Size,std::string>(index,atomname));
97 }
98 
100 {
101  std::map<core::Size,std::string>::const_iterator atom_map_it = index_to_names_map_.find(index);
102  if(atom_map_it == index_to_names_map_.end())
103  {
104  return "";
105 
106  }else
107  {
108  return atom_map_it->second;
109  }
110 }
111 
112 /*
113 std::map<core::Size, std::string> CtabBase::ParseAtomTypeData()
114 {
115  utility::vector1<std::string> tokens = mol_data_.get_mol_data_string_vector("Rosetta AtomTypes",' ');
116  std::map<core::Size, std::string> data_map;
117 
118  if(tokens.size() == 0)
119  {
120  return data_map;
121  }
122  else
123  {
124  //utility::vector1<std::string> tokens=utility::split(atom_type_data);
125  for(core::Size index = 1; index <= tokens.size();++index)
126  {
127 
128  std::string current_token = tokens[index];
129  if(current_token.size() <=1)
130  {
131  continue;
132  }
133  utility::vector1<std::string> token_split=utility::string_split(current_token,',');
134  utility::trim(token_split[0],"(");
135  utility::trim(token_split[1],")");
136  //std::cout << current_token<<std::endl;
137  core::Size atomno = atoi(token_split[0].c_str());
138  std::pair<core::Size, std::string> atom_type_point(atomno,token_split[1]);
139  data_map.insert(atom_type_point);
140  }
141 
142  }
143  return data_map;
144 }
145 
146 */
147 
149 {
150  if(bond_type_data_set_.find(BondData(lower,upper,8)) != bond_type_data_set_.end())
151  {
152  return true;
153  }else
154  {
155  return false;
156  }
157 }
158 
159 void CtabBase::set_atom_type(core::Size const atomno, std::string const atomname)
160 {
161  atomTyper typer = atomTyper(atomno, molecule_container_);
162  //%TODO fix hydrogen adding code eventually
163  /*
164  if(typer.get_element()=="C"||typer.get_element()=="N"||typer.get_element()=="O")
165  {
166  core::Size total_bonds=0;
167  char ele=typer.get_element().at(0);
168  switch(ele)
169  {
170  case 'C':
171  total_bonds++;
172  case 'N':
173  total_bonds++;
174  case 'O':
175  total_bonds+=2;
176  }
177  total_bonds+=molecule_container_->atom(atomno).charge();
178  total_bonds-=typer.getNumBonds();
179  while(total_bonds>0)
180  {
181  total_bonds--;
182  addedH newH;
183  newH.atom_number=++current_atom_;
184  newH.atom_type=(ele=='C')?"Hapo":"Hpol";
185  newH.bonded_atom_name=atomname;
186  added_H_.push_back(newH);
187  molecule_container_->add_atom("H"+newH.atom_number,
188  newH.atom_type,DEFAULT_MM_ATOM_TYPE_,0);
189  molecule_container_->add_bond(newH.bonded_atom_name,
190  std::string("H"+newH.atom_number),core::chemical::SingleBond);
191  typer = atomTyper(atomno, molecule_container_);
192  }
193  }
194  */
195 
196  //set default charge
198  core::chemical::AtomTypeSetCAP atom_type_set = chemical_manager->atom_type_set("fa_standard");
199  core::Size atom_type_index = atom_type_set->atom_type_index(typer.getType());
200  core::Size parameter_index = atom_type_set->extra_parameter_index("CHARGE");
201  core::Real charge = atom_type_set->operator[](atom_type_index).extra_parameter(parameter_index);
202  molecule_container_->atom( atomname ).charge(charge);
203  molecule_container_->set_atom_type(atomname, typer.getType());
204 }
205 
207 {
208 
209  std::map<core::Size,std::string>::iterator atom_it;
210  for(atom_it = index_to_names_map_.begin(); atom_it != index_to_names_map_.end();++atom_it)
211  {
212  std::string atom_name = atom_it->second;
213  core::Size atom_no = atom_it->first;
214  std::map<core::Size, std::string>::iterator atom_data_it = atom_type_data_map_.find(atom_no);
215  if(atom_data_it == atom_type_data_map_.end())
216  {
217  set_atom_type(atom_no,atom_name);
218  }else
219  {
220  //std::cout << atom_name << " " << atom_data_it->second <<std::endl;
221  molecule_container_->set_atom_type(atom_name,atom_data_it->second);
222  }
223 
224  }
225 }
226 
227 /*
228 void CtabBase::fix_bond_types()
229 {
230  utility::vector1<std::string> tokens = mol_data_.get_mol_data_string_vector("PUBCHEM_BONDANNOTATIONS",'\n');
231 
232  utility::vector1<std::string>::iterator token_it;
233  for(token_it = tokens.begin();token_it != tokens.end();++token_it)
234  {
235  utility::vector1<std::string> current_token(utility::split(*token_it));
236  if(current_token.size() < 3)
237  {
238  continue;
239  }
240 
241  core::Size lower_id = utility::from_string(current_token[1],core::Size(0));
242  core::Size upper_id = utility::from_string(current_token[2],core::Size(0));
243  core::Size type = utility::from_string(current_token[3],core::Size(0));
244 
245  //Currently we only support pubchem bondtype 8 (aromatic)
246  if(type == 8)
247  {
248 
249  }
250  }
251 }
252 */
253 }
254 }
255 }