Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ctab_typer.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 // :noTabs=false:tabSize=4:indentSize=4:
4 //
5 // This file is part of the Rosetta software suite and is made available under license.
6 // The Rosetta software is developed by the contributing members of the Rosetta Commons consortium.
7 // (C) 199x-2009 Rosetta Commons participating institutions and developers.
8 // For more information, see http://www.rosettacommons.org/.
9 
10 /// @file core/chemical/sdf/ctab_typer.cc
11 ///
12 /// @brief
13 /// @author Robert Carroll
14 
15 // AUTO-REMOVED #include <basic/Tracer.hh>
18 #include <core/chemical/Atom.hh>
19 // AUTO-REMOVED #include <utility/string_util.hh>
20 //#include <core/chemical/ResidueType.hh>
21 //#include <protocols/ligand_docking/ColoredGraph.hh>
22 #include <utility/exit.hh>
23 #include <numeric/xyzVector.hh>
24 #include <vector>
25 #include <algorithm>
26 #include <map>
27 // AUTO-REMOVED #include <sstream>
28 // AUTO-REMOVED #include <cstring>
29 // AUTO-REMOVED #include <stdlib.h>
30 
32 #include <utility/vector1.hh>
33 
34 
35 namespace core {
36 namespace chemical {
37 namespace sdf {
38 
39 
40 
42 {
43  if(type_=="")
44  {
45  //Get the default atom type
46  type_=molecule_container_->atom_type(atomno_).name();
50 
52 
55 
58 
61 
62  if(element_=="C")
63  {
64 
65  if(nonO_aro_bonds>0) {
66  type_="aroC";
67  }else if(O_single_bonds > 0 && O_double_bonds > 0) {
68  type_="COO";
69  }else if(N_single_bonds == 1) {
70  if(O_double_bonds == 1 && C_single_bonds == 1 && hasbbN()) {
71  type_="CObb";
72  } else if(O_double_bonds == 1 && hasCarbonylC()) {
73  type_="CAbb";
74  } else {
75  type_="CNH2";
76  }
77  }else if(N_single_bonds == 2 && N_double_bonds == 1) {
78  type_="aroC"; //Guanidinium
79  }else {
80  switch(H_single_bonds){
81  case 1: type_="CH1";break;
82  case 2: type_="CH2";break;
83  case 3: type_="CH3";break;
84  }
85  }
86  } else if (element_ == "N")
87  {
88  if(nonO_aro_bonds==2) {
89  if(hasNinRing()) {
90  type_="Nhis";
91  } else {
92  type_="Ntrp";
93  }
94  } else if(hasGuanidiniumC()) {
95  type_="Narg";
96  } else if(molecule_container_->atom(atomno_).charge() == 1) {
97  type_="Nlys";
98  } else if(hasCarbonylC()){
99  if(H_single_bonds == 2) {
100  type_="NH2O";
101  } else if (H_single_bonds == 1 && C_single_bonds == 1) {
102  type_="Nbb";
103  } else if (C_single_bonds == 2) {
104  type_="Npro";
105  }
106  }
107  } else if (element_ == "O")
108  {
109  if(nonO_aro_bonds > 0) {
110  type_="Oaro";
111  } else if(H_single_bonds == 2) {
112  type_="HOH";
113  } else if(H_single_bonds == 1 && C_single_bonds == 1) {
114  type_="OH";
115  }else if(hasCarboxylC()) {
116  type_="OOC";
117  } else if(hasCwithbbN()) {
118  type_="OCbb";
119  } else if(hasAmideN()) {
120  type_="ONH2";
121  }
122  } else if (element_ == "H")
123  {
124 
126 
127  if(NOS_bonds >= 1)
128  {
129  type_="Hpol";
130  }else if(C_aromatic_bonds >=1)
131  {
132  type_="Haro";
133  }else
134  {
135  type_="Hapo";
136  }
137 
138  /*
139  if(C_single_bonds == 1) {
140  type_="Hapo";
141  } else {
142  type_="Hpol";
143  }
144  */
145  } else if (element_ == "Fe")
146  {
147  //Read the charge, and change to +2/+3 if applicable.
148  if(molecule_container_->atom(atomno_).charge()==2)
149  {
150  molecule_container_->set_atom_type(atomname_,"Fe2p");
151  }
152  else if(molecule_container_->atom(atomno_).charge()==3)
153  {
154  molecule_container_->set_atom_type(atomname_,"Fe3p");
155  }
156  } else
157  {
158  //It is properly set already
159  }
160  }
161  return type_;
162 }
163 
165 {
166  this->atomno_=atomno;
167  this->molecule_container_=molecule_container_;
168  this->atomname_=molecule_container_->atom_name(atomno);
169  element_ = molecule_container_->atom_type(atomno).element();
170 
171 
172  type_="";
173  /*
174  for(core::Size i=0; i<14; i++) {
175  numBonds_[i]=0;
176  }
177  */
178  //Bonded to this atom
179  core::chemical::AtomIndices bonded = molecule_container_->bonded_neighbor(atomno);
180  utility::vector1<core::chemical::BondName> bondtypes = molecule_container_->bonded_neighbor_types(atomno);
181 
182  //Both are vector1
183  for(core::Size i=1; i<=bonded.size(); i++) {
184  //typerBond bond;
185  std::string element = molecule_container_->atom_type(bonded[i]).element();
186  core::chemical::BondName bondtype = bondtypes[i];
187  core::Size bond_count = get_bond_count(element,bondtype);
188  set_bond_count(element,bondtype,bond_count+1);
189  //std::cout <<element << " " << bondtype << " "<<get_bond_count(element,bondtype) <<std::endl;
190  }
191 }
192 
194 {
195  bool found=false;
196  //Bonded to this atom
197  core::chemical::AtomIndices bonded = molecule_container_->bonded_neighbor(atomno_);
198  utility::vector1<core::chemical::BondName> bondtypes = molecule_container_->bonded_neighbor_types(atomno_);
199 
200  //Both are vector1
201  for(core::Size i=1; i<=bonded.size()&&!found; i++) {
202  std::string element = molecule_container_->atom_type(bonded[i]).element();
203  if(element=="N") {
204  atomTyper neighbor(bonded[i],molecule_container_);
205  if(neighbor.get_bond_count("C",core::chemical::SingleBond)==2) {
206  found=true;
207  }
208  }
209  }
210  return found;
211 }
212 
214 {
215  return element_;
216 }
217 
219 {
220  bool found=false;
221  //Bonded to this atom
222  core::chemical::AtomIndices bonded = molecule_container_->bonded_neighbor(atomno_);
223  utility::vector1<core::chemical::BondName> bondtypes = molecule_container_->bonded_neighbor_types(atomno_);
224 
225  //Both are vector1
226  for(core::Size i=1; i<=bonded.size()&&!found; i++) {
227  std::string element = molecule_container_->atom_type(bonded[i]).element();
228  if(element=="C") {
229  atomTyper neighbor(bonded[i],molecule_container_);
230  if(neighbor.get_bond_count("O",core::chemical::DoubleBond )==1) {
231  found=true;
232  }
233  }
234  }
235  return found;
236 }
237 
239 {
240  bool found=false;
241  //Bonded to this atom
242  core::chemical::AtomIndices bonded = molecule_container_->bonded_neighbor(atomno_);
243  utility::vector1<core::chemical::BondName> bondtypes = molecule_container_->bonded_neighbor_types(atomno_);
244 
245  //Both are vector1
246  for(core::Size i=1; i<=bonded.size()&&!found; i++) {
247  std::string element = molecule_container_->atom_type(bonded[i]).element();
248  if(element=="C") {
249  atomTyper neighbor(bonded[i],molecule_container_);
252  neighbor.get_bond_count("N",core::chemical::AromaticBond)>=2) {
253  found=true;
254  }
255  }
256  }
257  return found;
258 }
259 
261 {
262  bool found=false;
263  //Bonded to this atom
264  core::chemical::AtomIndices bonded = molecule_container_->bonded_neighbor(atomno_);
265  utility::vector1<core::chemical::BondName> bondtypes = molecule_container_->bonded_neighbor_types(atomno_);
266 
267  //Both are vector1
268  for(core::Size i=1; i<=bonded.size()&&!found; i++) {
269  std::string element = molecule_container_->atom_type(bonded[i]).element();
270  if(element=="C") {
271  atomTyper neighbor(bonded[i],molecule_container_);
274  neighbor.get_bond_count("N",core::chemical::AromaticBond)>=3) {
275  found=true;
276  }
277  }
278  }
279  return found;
280 }
281 
283 {
284  bool found=false;
285  //Bonded to this atom
286  core::chemical::AtomIndices bonded = molecule_container_->bonded_neighbor(atomno_);
287  utility::vector1<core::chemical::BondName> bondtypes = molecule_container_->bonded_neighbor_types(atomno_);
288 
289  //Both are vector1
290  for(core::Size i=1; i<=bonded.size()&&!found; i++) {
291  std::string element = molecule_container_->atom_type(bonded[i]).element();
292  if(element=="C") {
293  atomTyper neighbor(bonded[i],molecule_container_);
294  if(neighbor.get_bond_count("N",core::chemical::SingleBond) >= 1) {
295  found=true;
296  }
297  }
298  }
299  return found;
300 }
301 
303 {
304  bool found=false;
305  //Bonded to this atom
306  core::chemical::AtomIndices bonded = molecule_container_->bonded_neighbor(atomno_);
307  utility::vector1<core::chemical::BondName> bondtypes = molecule_container_->bonded_neighbor_types(atomno_);
308 
309  //Both are vector1
310  for(core::Size i=1; i<=bonded.size()&&!found; i++) {
311  std::string element = molecule_container_->atom_type(bonded[i]).element();
312  if(element=="C") {
313  atomTyper neighbor(bonded[i],molecule_container_);
314  if(neighbor.get_bond_count("O",core::chemical::DoubleBond) == 1 &&
315  neighbor.get_bond_count("O",core::chemical::SingleBond) == 1) {
316  found=true;
317  }
318  }
319  }
320  return found;
321 }
322 
324 {
325  bool found=false;
326  //Bonded to this atom
327  core::chemical::AtomIndices bonded = molecule_container_->bonded_neighbor(atomno_);
328  utility::vector1<core::chemical::BondName> bondtypes = molecule_container_->bonded_neighbor_types(atomno_);
329 
330  //Save the C with an N
331  core::Size iC=0;
332 
333  //Both are vector1
334  for(core::Size i=1; i<=bonded.size()&&!found; i++) {
335  std::string element = molecule_container_->atom_type(bonded[i]).element();
336  if(element=="C") {
337  atomTyper neighbor(bonded[i],molecule_container_);
338  if(neighbor.get_bond_count("N",core::chemical::SingleBond)>=1) {
339  found=true;
340  iC=bonded[i];
341  }
342  }
343  }
344  if(found) {
345  found=false;
346  bonded = molecule_container_->bonded_neighbor(iC);
347  bondtypes = molecule_container_->bonded_neighbor_types(iC);
348  //Both are vector1
349  for(core::Size i=1; i<=bonded.size()&&!found; i++) {
350  std::string element = molecule_container_->atom_type(bonded[i]).element();
351  if(element=="N") {
352  atomTyper neighbor(bonded[i],molecule_container_);
353  if(neighbor.get_bond_count("C",core::chemical::SingleBond)>=2) {
354  found=true;
355  }
356  }
357  }
358  }
359  return found;
360 }
361 
362 /*
363 core::Size atomTyper::getNumBonds(typerBond i)
364 {
365  return numBonds_[i];
366 }
367 */
368 
370 {
371  core::Real total=0;
374  //total+=1*(numBonds_[Csingle]+numBonds_[Nsingle]+numBonds_[Osingle]+numBonds_[Hsingle]);
377  //total+=2*(numBonds_[Cdouble]+numBonds_[Ndouble]+numBonds_[Odouble]);
379  //total+=3*(numBonds_[Ctriple]+numBonds_[Ntriple]);
381 
382  return static_cast<core::Size>(total);
383 }
384 
385 void atomTyper::set_bond_count(std::string const element, core::chemical::BondName const bond_type,core::Size const bond_count)
386 {
387  std::pair<std::string,core::chemical::BondName> key(element,bond_type);
388  numBonds_[key] = bond_count;
389 }
390 
392 {
393  std::pair<std::string,core::chemical::BondName> key(element,bond_type);
394  std::map< std::pair<std::string,core::chemical::BondName>,core::Size>::const_iterator bond_iter;
395  bond_iter = numBonds_.find(key);
396  if(bond_iter == numBonds_.end())
397  {
398  return 0;
399  }else
400  {
401  return bond_iter->second;
402  }
403 }
404 
406 {
407  core::Size total = 0;
408  std::map< std::pair<std::string,core::chemical::BondName>,core::Size >::const_iterator bond_iter;
409  for(bond_iter = numBonds_.begin();bond_iter != numBonds_.end();++bond_iter)
410  {
411  std::pair<std::string,core::chemical::BondName> key = bond_iter->first;
412  if(key.second == bond_type)
413  {
414  total += bond_iter->second;
415  }
416  }
417  return total;
418 }
419 
421 {
422  core::Size total = 0;
423  std::map< std::pair<std::string,core::chemical::BondName>,core::Size >::const_iterator bond_iter;
424  for(bond_iter = numBonds_.begin();bond_iter != numBonds_.end();++bond_iter)
425  {
426  std::pair<std::string, core::chemical::BondName> key = bond_iter->first;
427  if(key.first == element)
428  {
429  total += bond_iter->second;
430  }
431  }
432  return total;
433 }
434 
435 } // sdf
436 } // io
437 } // core