Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
MMAtomTypeSet.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 core/chemical/MMAtomTypeSet.cc
11 /// @brief
12 /// @author P. Douglas Renfrew (renfrew@unc.edu)
13 
14 // Unit headers
16 
17 // Project headers
18 #include <basic/Tracer.hh>
19 
21 
22 // C++ headers
23 #include <fstream>
24 #include <iostream>
25 #include <utility/io/izstream.hh>
26 
27 #include <utility/vector1.hh>
28 
29 
30 namespace core {
31 namespace chemical {
32 
33 static basic::Tracer tr("core.chemical");
34 
35 
37  atom_type_index_(),
38  atoms_()
39 {
40 }
41 
42 
44 
45 
46 /// @details Initialize an MMAtomTypeSet from an external file "filename",
47 /// and set parameters and properties for each MMAtomType.
48 /// Refer to minirosetta_database_stock/chemical/mm_atom_type_sets/fa_standard/mm_atom_properties.txt
49 /// for file format
50 ///
51 void
53 {
54  utility::io::izstream data( filename.c_str() );
55 
56  if ( !data.good() ) utility_exit_with_message( "Unable to open MM atom type set file: "+filename );
57 
58  // parse the header line
60  { // scope
61  std::string line, tag;
62  getline( data, line );
63  std::istringstream l( line );
64  l >> tag;
65  if ( tag != "NAME" ) {
66  utility_exit_with_message("MMAtomTypeSet::read_file: bad first line: "+ line );
67  }
68  l >> tag;
69  while ( !l.fail() ) {
70  tags.push_back( tag );
71  l >> tag;
72  }
73  }
74 
75  // now parse the rest of the file
76  int const ntags( tags.size() );
77  {
78  using namespace basic;
79 
80  std::string line, tag, name_wo_whitespace;
81  while ( getline( data,line ) ) {
82  std::istringstream l( line );
83  l >> name_wo_whitespace;
84  if ( name_wo_whitespace.find("#",0) == 0 ) continue; // skip comment lines
85  if ( l.fail() ) {
86  utility_exit_with_message("bad line: "+line);
87  }
88 
89  MMAtomType* mm_atom_type_ptr( new MMAtomType( name_wo_whitespace ) );
90 
91  // now parse the parameters
92  for ( int i=1; i<= ntags; ++i ) {
93  Real setting;
94  l >> setting;
95  mm_atom_type_ptr->set_parameter( tags[i], setting );
96  }
97  if ( l.fail() ) {
98  utility_exit_with_message("bad line: "+line);
99  }
100 
101  // add this to the list
102  atoms_.push_back( mm_atom_type_ptr );
103  if ( atom_type_index_.count( name_wo_whitespace ) ) {
104  utility_exit_with_message("MMAtomTypeSet:: duplicate atom name "+name_wo_whitespace);
105  }
106  atom_type_index_[ name_wo_whitespace ] = atoms_.size();
107  tr.Debug << "New MM atom type: " << name_wo_whitespace << std::endl;
108  }
109  }
110 }
111 
112 /// @details This function iterates over each element in the atom_type_index_ map and
113 /// prints both keys. It is only used for debugging.
114 void
116 {
117  for( std::map< std::string, int >::const_iterator i = atom_type_index_.begin(), e = atom_type_index_.end(); i != e; ++i )
118  {
119  std::cout << (*i).first << " " << (*i).second << std::endl;
120  }
121 }
122 
123 } // chemical
124 } // core