Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
CSDAtomTypeSet.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/CSDAtomTypeSet.cc
11 /// @brief
12 /// @author Ian W. Davis
13 
14 // Unit headers
16 
17 // Project headers
18 #include <basic/Tracer.hh>
19 
20 // Utility headers
21 #include <utility/io/izstream.hh>
22 
23 // C++ headers
24 #include <fstream>
25 #include <iostream>
26 
27 namespace core {
28 namespace chemical {
29 
30 static basic::Tracer tr("core.chemical");
31 
32 
34  atom_type_index_(),
35  atoms_()
36 {}
37 
38 
40 
41 Size
42 CSDAtomTypetSet::n_atomtypes() const {
43  return atoms_.size();
44 }
45 
46 bool
47 CSDAtomTypeSetcontains_atom_type( std::string const & atom_type_name ) const {
48  std::map< std::string, int >::const_iterator
49  iter( atom_type_index_.find( atom_type_name ) );
50  return iter != atom_type_index_.end();
51 }
52 
53 
54 /// @details Initialize an CSDAtomTypeSet from an external file "filename",
55 /// and set parameters and properties for each CSDAtomType.
56 /// Refer to minirosetta_database_stock/chemical/mm_atom_type_sets/fa_standard/mm_atom_properties.txt
57 /// for file format
58 void
60  using namespace basic;
61 
62  utility::io::izstream data( filename.c_str() );
63 
64  if ( !data.good() ) utility_exit_with_message( "Unable to open CSDAtomTypeSet file: "+filename );
65 
66  std::string line, tag;
67  while ( getline( data,line ) ) {
68  std::istringstream l( line );
69  l >> tag;
70  if ( l.fail() ) {
71  utility_exit_with_message("bad line: "+line);
72  }
73 
74  std::string name(tag); //( line.substr(0,4) );
75  CSDAtomType* csd_atom_type_ptr( new CSDAtomType( name ) );
76 
77 
78  // add this to the list
79  atoms_.push_back( csd_atom_type_ptr );
80  atom_type_index_[ name ] = atoms_.size();
81  tr.Debug << "New CSD atom type: " << name << std::endl;
82  }
83 
84  tr.Debug << "CSD atoms types added " << atoms_.size() << std::endl;
85 }
86 
87 /// @details This function iterates over each element in the atom_type_index_ map and
88 /// prints both keys. It is only used for debugging.
89 void
91  for( std::map< std::string, int >::const_iterator i = atom_type_index_.begin(), e = atom_type_index_.end(); i != e; ++i )
92  {
93  std::cout << (*i).first << " " << (*i).second << std::endl;
94  }
95 }
96 
97 int
99 atom_type_name ) const {
100  std::map< std::string, int >::const_iterator
101  iter( atom_type_index_.find( atom_type_name ) );
102  if ( iter == atom_type_index_.end() ) {
103  utility_exit_with_message("unrecognized csd_atom_type_name "+atom_type_name);
104  }
105  return iter->second;
106 }
107 
108 CSDAtomType const &
109 CSDAtomTypeSet::operator[] ( Size const index ) const
110 {
111  return *( atoms_[ index ] );
112 }
113 
114 } // chemical
115 } // core