Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
v3_parser.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/v3_parser.cc
11 /// @author Sam DeLuca
12 
14 
15 #include <numeric/xyzVector.hh>
17 
18 #include <utility/string_util.hh>
19 
20 // Boost Headers
21 #include <boost/foreach.hpp>
22 
23 #include <utility/vector1.hh>
24 
25 #define foreach BOOST_FOREACH
26 
27 namespace core {
28 namespace chemical {
29 namespace sdf {
30 
31 V3Parser::V3Parser(utility::vector1<std::string> const & connection_table_lines,
32  core::chemical::ResidueTypeOP molecule_container, MolData const & mol_data):
33  CtabBase(connection_table_lines,molecule_container,mol_data)
34 {
35 
36 }
37 
39 {
40  core::Size ctab_length = this->connection_table_length();
41 
42  bool atom_block(false);
43  bool bond_block(false);
44  //std::map<core::Size,std::string> atom_type_data = this->ParseAtomTypeData();
45  //core::Size atom_count(0);
46  //core::Size bond_count(0);
47  for(core::Size line_number = 1; line_number <= ctab_length; ++line_number)
48  {
49  std::string current_line(this->connection_table_line(line_number));
50  utility::vector1<std::string> line_vector(utility::split(current_line));
51 
52  if(line_vector[2] == "END")
53  {
54  break;
55  }
56  if(line_vector[2] != "V30" || line_vector.size() <2)
57  {
58  continue;
59  }
60  if(line_vector[3] == "COUNTS")
61  {
62  //atom_count = atoi(line_vector[4].c_str()); // set but never used ~Labonte
63  //bond_count = atoi(line_vector[5].c_str()); // set but never used ~Labonte
64  }else if(line_vector[3] == "BEGIN")
65  {
66  if (line_vector[4] == "ATOM")
67  atom_block = true;
68  else if (line_vector[4] == "BOND")
69  bond_block = true;
70  }else if(line_vector[3] == "END")
71  {
72  if (line_vector[4] == "ATOM")
73  atom_block = false;
74  else if (line_vector[4] == "BOND")
75  bond_block = false;
76  }else
77  {
78  if (atom_block)
79  ParseAtom(current_line,0 /*dummy arg*/);
80  else if (bond_block)
81  ParseBond(current_line);
82  }
83  }
84 
85  //Iterate across the atoms, finding their types
86  this->fix_atom_types();
87  /*
88  core::chemical::ResidueTypeOP residue(this->GetResidueType());
89  for(core::Size atom_index = 1; atom_index <=atom_count; ++atom_index)
90  {
91  std::string atom_name(this->atom_name_from_index(atom_index));
92  core::Size atomno = residue->atom_index(atom_name);
93  this->set_atom_type(atomno,atom_name);
94  }
95  */
96 }
97 
98 void V3Parser::ParseAtom(std::string const atom_line, core::Size const )
99 {
100  utility::vector1<std::string> atom_vector(utility::split(atom_line));
101 
102  core::Size index = atoi(atom_vector[3].c_str());
103  std::string element_name(atom_vector[4]);
104  std::string element_id(element_name+atom_vector[3]);
105  utility::add_spaces_left_align(element_id,4);
106  core::Real x_coord = atof(atom_vector[5].c_str());
107  core::Real y_coord = atof(atom_vector[6].c_str());
108  core::Real z_coord = atof(atom_vector[7].c_str());
109 
110  numeric::xyzVector<core::Real> coordinates(x_coord,y_coord,z_coord);
111 
112  core::Real charge(FindExtraParameter(atom_vector,"CHG"));
113 
114  this->add_index_name_pair(index,element_id);
115 
116  core::chemical::ResidueTypeOP molecule_container = this->GetResidueType();
117  std::string atom_type(element_to_default_type.get(element_name));
118  molecule_container->add_atom(element_id,atom_type,DEFAULT_MM_ATOM_TYPE_,charge);
119  molecule_container->set_ideal_xyz(element_id,coordinates);
120  //molecule_container->finalize();
121 
122 }
123 
124 void V3Parser::ParseBond(std::string const bond_line)
125 {
126  utility::vector1<std::string> bond_vector(utility::split(bond_line));
127 
128  //core::Size index = atoi(bond_vector[2].c_str());
129  core::chemical::BondName type = static_cast<core::chemical::BondName>(atoi(bond_vector[4].c_str()));
130 
131  core::Size atom1_index = atoi(bond_vector[5].c_str());
132  core::Size atom2_index = atoi(bond_vector[6].c_str());
133  if(this->check_for_aromatic(atom1_index,atom2_index))
134  {
136  }
137 
138  std::string atom1_id(this->atom_name_from_index(atom1_index));
139  std::string atom2_id(this->atom_name_from_index(atom2_index));
140 
141  core::chemical::ResidueTypeOP molecule_container = this->GetResidueType();
142  molecule_container->add_bond(atom1_id,atom2_id,type);
143 
144 }
145 
147 {
148  foreach(std::string current_parameter, extra_parameters){
149  if(current_parameter.find(query) == std::string::npos)
150  {
151  continue;
152  }
153  else
154  {
155  core::Size value_length = current_parameter.size() - (query.size()+1);
156  core::Size value_start = query.size()+1;
157 
158  std::string value_string = current_parameter.substr(value_start,value_length);
159  core::Real value = atof(value_string.c_str());
160  return value;
161  }
162  }
163  return 0.0;
164 }
165 
166 }
167 }
168 }