Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
MolData.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/MolData.cc
11 /// @author Sam DeLuca
12 
14 #include <utility/string_util.hh>
15 #include <basic/Tracer.hh>
16 #include <map>
17 #include <string>
18 
19 // Boost Headers
20 #include <boost/foreach.hpp>
21 
22 #include <utility/vector1.hh>
23 
24 #define foreach BOOST_FOREACH
25 
26 namespace core {
27 namespace chemical {
28 namespace sdf {
29 static basic::Tracer MolDataTracer("core.io.sdf.MolData");
30 
32 {
33 
34 }
35 
37 {
38 
39 }
40 
42 {
43  return mol_data_map_.size();
44 }
45 
47 {
48  mol_data_map_.clear();
49 }
50 
52 {
53  bool inside_block = false;
54 
55  std::string data_name = "";
56  std::string data = "";
57 
58  foreach(std::string line, file_lines){
59  if(line[0] == '>') //we've found a data header
60  {
61  data_name = line.substr(3,line.size());
62  utility::trim(data_name,">");
63  data.clear();
64  inside_block = true;
65  }else if(inside_block && (line[0] == '\n' || line.size() == 0 ))
66  {
67  //data_name = "";
68  mol_data_map_.insert(std::pair<std::string,std::string>(data_name,data));
69  inside_block = false;
70  }else if(inside_block)
71  {
72  data.append(line+"\n");
73  }
74  }
75 }
76 
78 {
79  std::map<std::string,std::string>::const_iterator data_it = mol_data_map_.find(key);
80  if(data_it == mol_data_map_.end())
81  {
82  return "";
83  }else
84  {
85  return data_it->second;
86  }
87 }
88 
90 {
91  std::map<std::string,std::string>::const_iterator data_it = mol_data_map_.find(key);
92  if(data_it == mol_data_map_.end())
93  {
95  return data_vector;
96  }else
97  {
98  std::string data = data_it->second;
99  utility::vector1<std::string> data_vector(utility::string_split(data,splitter));
100  return data_vector;
101  }
102 }
103 
104 void MolData::print() const
105 {
106  std::map<std::string,std::string>::const_iterator data_it;
107  for(data_it = mol_data_map_.begin(); data_it != mol_data_map_.end();++data_it)
108  {
109  MolDataTracer << "\""<< data_it->first <<"\"" << " : " <<data_it->second <<std::endl;
110  }
111 }
112 
113 }
114 }
115 }