Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
v2_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/v2_parser.cc
11 /// @author Sam DeLuca
12 
15 #include <utility/string_util.hh>
16 
17 #include <utility/vector1.hh>
18 
19 
20 namespace core {
21 namespace chemical {
22 namespace sdf {
23 
24 V2Parser::V2Parser(utility::vector1<std::string> const & connection_table_lines,
25  core::chemical::ResidueTypeOP molecule_container, MolData const & mol_data):
26  CtabBase(connection_table_lines,molecule_container,mol_data)
27 { }
28 
30 {
31  std::string counts_line = this->connection_table_line(1);
32  core::Size atom_count = atoi(counts_line.substr(0,3).c_str());
33  core::Size bond_count = atoi(counts_line.substr(3,3).c_str());
34 
35  //ctabParserTracer.Debug << atom_count << " atoms and " << bond_count << " bonds" <<std::endl;
36  //std::map<core::Size, std::string> atom_type_data = this->ParseAtomTypeData();
37  std::string version_tag = counts_line.substr(34,5);
38 
39  assert(version_tag == "V2000");
40 
41  core::Size last_atom = atom_count;
42  core::Size last_bond = last_atom+bond_count;
43 
44  for(core::Size line_number = 1; line_number < this->connection_table_length(); ++line_number)
45  {
46  if(line_number <= last_atom)
47  {
48  ParseAtom(this->connection_table_line(line_number+1),line_number);
49  }else if(line_number <= last_bond)
50  {
51  ParseBond(this->connection_table_line(line_number+1));
52  }
53  }
54 
55  //Iterate across the atoms, finding their types
56  this->fix_atom_types();
57  /*
58  core::chemical::ResidueTypeOP residue(this->GetResidueType());
59  for(core::Size atom_index = 1; atom_index <= atom_count; ++atom_index)
60  {
61  std::string atom_name(this->atom_name_from_index(atom_index));
62  core::Size atomno = residue->atom_index(atom_name);
63  this->set_atom_type(atomno,atom_name);
64  }
65  */
66 }
67 
68 void V2Parser::ParseAtom(std::string const atom_line, core::Size const atom_number)
69 {
70  core::Real x_coord = atof(atom_line.substr(0,10).c_str());
71  core::Real y_coord = atof(atom_line.substr(10,10).c_str());
72  core::Real z_coord = atof(atom_line.substr(20,10).c_str());
73  //ctabParserTracer.Debug << "atom " <<atom_number << " has coordinates " << x_coord << ',' << y_coord << ',' << z_coord << std::endl;
74  std::string element_name = atom_line.substr(31,3).c_str();
75  if(element_name.at(1)==' ') {
76  element_name=element_name.substr(0,1);
77  } else if (element_name.at(2)==' ') {
78  element_name=element_name.substr(0,2);
79  }
80 
81  std::string atom_number_string= utility::to_string<core::Size>(atom_number);
82 
83  //atom_number_string = convert_stream.str();
84 
85  //Set the atom type to a default based on the element.
86  std::string atom_type = element_to_default_type.get(element_name);
87 
88  std::string element_id = element_name+ atom_number_string;
89  utility::add_spaces_left_align(element_id,4);
90 
91  core::Size charge = atoi(atom_line.substr(36,3).c_str());
92  numeric::xyzVector<core::Real> coordinates(x_coord,y_coord,z_coord);
93  this->add_index_name_pair(atom_number,element_id);
94 
96  residue->add_atom(element_id,atom_type,DEFAULT_MM_ATOM_TYPE_,charge);
97  residue->set_ideal_xyz(element_id,coordinates);
98  //residue->finalize();
99 }
100 
101 void V2Parser::ParseBond(std::string const bond_line)
102 {
103  core::Size atom1_index = atoi(bond_line.substr(0,3).c_str());
104  core::Size atom2_index = atoi(bond_line.substr(3,3).c_str());
105  core::chemical::BondName bond_type = static_cast<core::chemical::BondName>(atoi(bond_line.substr(6,3).c_str()));
106  if(this->check_for_aromatic(atom1_index,atom2_index))
107  {
108  bond_type = core::chemical::AromaticBond;
109  }
110  std::string atom1_id(this->atom_name_from_index(atom1_index));
111  std::string atom2_id(this->atom_name_from_index(atom2_index));
112 
114  residue->add_bond(atom1_id,atom2_id,bond_type);
115  //residue->finalize();
116 
117 }
118 
119 }
120 }
121 }