Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
OrbitalTypeSet.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 /// @begin AtomTypeSet
11 ///
12 /// @brief
13 /// A class for reading in the orbital type properties
14 ///
15 /// @detailed
16 /// This class reads in the orbital_properties.txt file which contains the "chemical" information for orbitals.
17 /// This does not contain the actual properties, but sets the properties through the OrbitalType class.
18 /// This class is called by the ChemicalManager. Modeled off of atomtypeset.
19 ///
20 ///
21 ///
22 /// @authors
23 /// Steven Combs
24 ///
25 ///
26 /// @last_modified December 12 2010
27 /////////////////////////////////////////////////////////////////////////
28 
29 
30 #include <fstream>
31 #include <iostream>
32 
33 #include <basic/Tracer.hh>
35 
37 #include <utility/io/izstream.hh>
38 
39 #include <utility/exit.hh>
40 #include <utility/vector1.hh>
41 
42 
43 namespace core{
44 namespace chemical{
45 namespace orbitals{
46 
47 /// @details Auto-generated virtual destructor
49 
50 static basic::Tracer TR("core.chemical.orbitals");
51 
53 {
54  directory_ = directory;
55  read_file( directory + "/orbital_properties.txt" );
56 
57  //currently commented out. This is if someone down the line wants to add extras, like
58  //in the atomtype extras.
59 /* std::ifstream data( ( directory+"/extras.txt" ).c_str() );
60  if ( data.good() ) { // add extra data
61  std::string line;
62  while( getline( data, line ) ) {
63  if ( line.size() && line[0] == '#' ) continue;
64  add_parameters_from_file( directory+"/"+line );
65  }
66  }
67  data.close();*/
68 
69 }
70 
71 
72 //function take from AtomTypeSet.cc. Modified slightly for OrbitalTypeSet.cc.
73 //basically reads the file orbital_properties.txt found in your directory.
74 //
76 {
77  utility::io::izstream data( filename.c_str() );
78 
79  if ( !data.good() ) utility_exit_with_message( "Unable to open atomset file: "+filename );
80 
81  // parse the header line currently should look like orbital_type atom_type hybridization distance
83  { // scope
84  std::string line, tag, tag2;
85  getline( data, line );
86  std::istringstream l( line );
87  l >> tag >> tag2;
88  if ( tag != "orbital_type" || tag2 != "atom_type" ) {
89  utility_exit_with_message("AtomTypeSet::read_file: bad first line: "+ line );
90  }
91  l >> tag;
92  while ( !l.fail() ) {
93  tags.push_back( tag );
94  l >> tag;
95  }
96  }
97 
98  // now parse the rest of the file
99  core::Size const ntags( tags.size() );
100  {
101  using namespace basic;
102 
103  std::string line, tag, name_wo_whitespace;
104  while ( getline( data,line ) ) {
105  std::istringstream l( line );
106  l >> name_wo_whitespace;
107  if ( l.fail() || name_wo_whitespace.find("#",0) == 0 ) continue; // skip comment,blank lines
108  l >> tag;
109  if ( l.fail() || tag.size() < 1 ) {
110  utility_exit_with_message("bad line: "+line);
111  }
112 
113  // std::string const name( line.substr(0,4) );
114  std::string atom_type_name( tag );
115  OrbitalType* orbital_type_ptr( new OrbitalType( name_wo_whitespace, atom_type_name ) );
116 
117  // now parse the parameters
118  for ( Size i=1; i<= ntags; ++i ) {
119  Real setting;
120  l >> setting;
121  orbital_type_ptr->set_parameter( tags[i], setting );
122  }
123  if ( l.fail() ) {
124  utility_exit_with_message("bad line: "+line);
125  }
126 
127  // now parse the properties
128  l >> tag;
129  while ( !l.fail() && tag.find("#",0) != 0) {
130  orbital_type_ptr->set_property( tag, true );
131  l >> tag;
132  }
133 
134  // add this to the list
135  orbitals_.push_back( orbital_type_ptr );
136  // atom_type_index_[ name ] = atoms_.size();
137  if ( orbital_type_index_.count( name_wo_whitespace ) ) {
138  utility_exit_with_message("AtomTypeSet:: duplicate atom name "+name_wo_whitespace);
139  }
140  orbital_type_index_[ name_wo_whitespace ] = orbitals_.size();
141  TR.Debug << "New atom type: " << name_wo_whitespace << ' ' << atom_type_name << std::endl; //std::endl;
142  }
143  } // scope
144 
145 
146 }
147 
148 int
149 OrbitalTypeSet::orbital_type_index( std::string const & orbital_type_name ) const
150 {
151  std::map< std::string, int >::const_iterator
152  iter( orbital_type_index_.find( orbital_type_name ) );
153  if ( iter == orbital_type_index_.end() ) {
154  utility_exit_with_message("unrecognized orbital type name "+orbital_type_name);
155  }
156  return iter->second;
157 }
158 
159 
160 int
162 {
163  std::map< std::string, int >::const_iterator
164  iter( orbital_type_index_.find( orbital_type_name ) );
165  if ( iter == orbital_type_index_.end() ) {
166  utility_exit_with_message("unrecognized orbital type name "+orbital_type_name);
167  }
168  return iter->second;
169 }
170 
171 }
172 }
173 }