Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
sdf_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 // :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/sdf_parser.cc
11 ///
12 /// @brief sdf file parser implementation
13 /// @author Sam DeLuca
14 
17 
21 #include <basic/Tracer.hh>
22 
23 #include <string>
24 #include <map>
25 
26 // Boost Headers
27 #include <boost/foreach.hpp>
28 #define foreach BOOST_FOREACH
29 
30 namespace core {
31 namespace chemical {
32 namespace sdf {
33 
34 static basic::Tracer SDFParserTracer("core.io.sdf.sdf_parser");
35 
36 SDFParser::SDFParser(utility::vector1<std::string> file_vector) : file_vector_(file_vector)
37 { }
38 
40 {
41  SDFParserTracer << "generating residues " <<std::endl;
42 
45 
46  SDFParserTracer << "mol_file_map_ contains " << mol_file_map_.size() << " entries" <<std::endl;
47 
48  std::map<std::string,utility::vector1<std::string> >::iterator mol_file_map_iterator;
49  for(mol_file_map_iterator = mol_file_map_.begin(); mol_file_map_iterator != mol_file_map_.end(); ++mol_file_map_iterator)
50  {
51  utility::vector1<std::string> current_mol_file( mol_file_map_iterator->second);
52  MolFileParser mol_file_converter(current_mol_file);
53  mol_file_converter.parse_mol_file(atom_types, mm_atom_types);
54  core::chemical::ResidueTypeOP current_molecule(mol_file_converter.GetResidueTypeOP());
55  SDFParserTracer << "inserting " << mol_file_map_iterator->first <<std::endl;
56  molecule_map_.insert(std::pair<std::string, core::chemical::ResidueTypeOP>(mol_file_map_iterator->first,current_molecule));
57  SDFParserTracer << "size after insertion: " << molecule_map_.size() <<std::endl;
58  }
59 }
60 
62 {
63  return mol_file_map_.size();
64 }
65 
67 {
68  return molecule_name_vector_;
69 }
70 
72 {
73  std::string current_name;
74  utility::vector1<std::string> current_mol_block;
75  utility::vector1<std::string> current_data_block;
76  core::Size line_counter = 1;
77  bool data_block = false;
78 
79  foreach(std::string current_line, file_vector_){
80 
81  if(line_counter == 1)
82  {
83  //if the line counter is 1, we have a name line
84  current_name = current_line;
85  molecule_name_vector_.push_back(current_name);
86  }
87 
88  if(current_line == "$$$$")
89  {
90  //end of struct, clear add the block vectors to the map, reset the counter to 1
91  line_counter = 1;
92  mol_file_map_.insert(std::pair<std::string, utility::vector1<std::string> >(current_name,current_mol_block));
93  extended_data_map_.insert(std::pair<std::string,utility::vector1<std::string> >(current_name,current_data_block));
94 
95  current_mol_block.clear();
96  current_data_block.clear();
97  continue;
98  }
99 
100  if(data_block)
101  {
102  current_data_block.push_back(current_line);
103  }else
104  {
105  current_mol_block.push_back(current_line);
106  }
107  line_counter++;
108 
109  }
110 }
111 
113 {
114  return molecule_map_.find(name)->second;
115 }
116 
117 
118 
119 }
120 }
121 }