Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
MMBondLengthLibrary.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/scoring/mm/MMBondLengthLibary.cc
11 /// @brief Molecular mechanics bond length score class
12 /// @author Frank DiMaio (based on Colin Smith's MMBondAngle potential)
13 
14 // Unit headers
16 
17 // Project headers
20 // AUTO-REMOVED #include <basic/options/option.hh>
21 #include <basic/Tracer.hh>
22 #include <core/types.hh>
23 
24 // Utility headers
25 #include <utility/vector1.hh>
26 // AUTO-REMOVED #include <utility/keys/Key3Tuple.hh>
27 #include <utility/keys/Key2Tuple.hh>
28 #include <utility/pointer/access_ptr.hh>
29 #include <utility/pointer/owning_ptr.hh>
30 #include <utility/pointer/ReferenceCount.hh>
31 
32 // Numeric headers
33 // AUTO-REMOVED #include <numeric/conversions.hh>
34 
35 // C++ headers
36 #include <string>
37 #include <map>
38 // AUTO-REMOVED #include <iostream>
39 #include <sstream>
40 #include <fstream>
41 #include <cassert>
42 
43 // AUTO-REMOVED #include <basic/options/keys/MM.OptionKeys.gen.hh>
44 
46 
47 
48 namespace core {
49 namespace scoring {
50 namespace mm {
51 
52 /// @details Auto-generated virtual destructor
54 
55 using basic::T;
56 using basic::Error;
57 using basic::Warning;
58 
59 static basic::Tracer TR("core.mm.MMBondLengthLibrary");
60 
61 /// @details Construct a MMBondLengthLibrary instant from a filename string and constant access pointer to an MMAtomTypeSet
65 )
66 {
67  mm_atom_set_ = mm_atom_set;
68 
69  // read the file
70  std::string line;
72  std::ifstream data( filename.c_str() );
73 
74  bool in_bonds_section = false;
75  while( getline( data, line ) ) {
76  std::istringstream l( line );
77  if( line.size() < 1 || line[0] == '!' || line[0] == ' ' ) continue; // comment or blank lines
78  if (line == "ANGLES") in_bonds_section = false;
79  if (in_bonds_section) lines.push_back( line );
80  if (line == "BONDS") in_bonds_section = true;
81  }
82 
83  // parse params
84  for( Size i = 1; i <= lines.size(); ++i ) {
85  std::istringstream l( lines[i] );
86 
87  std::string atom_type_string_1, atom_type_string_2;
88  l >> atom_type_string_1 >> atom_type_string_2;
89 
90  // skip the parameters if any of the atom types don't exist
91  if ( ! mm_atom_set_->contains_atom_type( atom_type_string_1 ) ) continue;
92  if ( ! mm_atom_set_->contains_atom_type( atom_type_string_2 ) ) continue;
93 
94  // get atom-type_index from atom set
95  int atom_type_int1 = mm_atom_set_->atom_type_index( atom_type_string_1 );
96  int atom_type_int2 = mm_atom_set_->atom_type_index( atom_type_string_2 );
97 
98  // get k_b and b_0
99  Real k_b, b_0;
100  l >> k_b >> b_0;
101 
102  mm_bondlength_library_.insert( std::make_pair(
103  mm_bondlength_atom_pair( atom_type_int1, atom_type_int2 ),
104  mm_bondlength_param_set( k_b, b_0 ) ) );
105  }
106 
107  /// apl -- add "no-op" pair for virtual atoms
108  int const virt_type = mm_atom_set_->atom_type_index("VIRT");
109  Real const noop_kb( 0.0 );
110  Real const noop_b0( 0.0 );
111  mm_bondlength_library_.insert( std::make_pair(
112  mm_bondlength_atom_pair( virt_type, virt_type ),
113  mm_bondlength_param_set( noop_kb, noop_b0 ) ));
114 
115 
116  // print number torsion params added
117  TR << "MM bond length sets added: " << mm_bondlength_library_.size()
118  << " (+1 virtual)." << std::endl;
119 }
120 
122 MMBondLengthLibrary::lookup( int atom1, int atom2 ) const {
123  static std::string const x_string = "X";
124  static std::string const virt_string = "VIRT";
125 
126  if( mm_bondlength_library_.count( mm_bondlength_atom_pair( atom1, atom2 ) ) ) {
127  // forward
128  return mm_bondlength_library_.equal_range( mm_bondlength_atom_pair( atom1, atom2 ) );
129  } else if( mm_bondlength_library_.count( mm_bondlength_atom_pair( atom2, atom1 ) ) ) {
130  // backward
131  return mm_bondlength_library_.equal_range( mm_bondlength_atom_pair( atom2, atom1 ) );
132  }
133  int const virt_atom_type = mm_atom_set_->atom_type_index( virt_string );
134 
135  /// Virtual atoms get no mm-parameters. Return the no-op torsion object
136  if ( atom1 == virt_atom_type || atom2 == virt_atom_type ) {
137  return mm_bondlength_library_.equal_range( mm_bondlength_atom_pair( virt_atom_type, virt_atom_type ));
138  }
139 
140  TR << "No parameters for " << (*mm_atom_set_)[atom1].name() << "-" << (*mm_atom_set_)[atom2].name() << std::endl;
141  utility_exit_with_message("COULD NOT FIND BOND LENGTH PARAMS" );
142 
143  return mm_bondlength_library_citer_pair(); ///< meaningless, just for removing gcc warning.
144 }
145 
148  return (*this).lookup(
149  mm_atom_set_->atom_type_index( atom1 ),
150  mm_atom_set_->atom_type_index( atom2 ) );
151 }
152 
153 void
155  // for each key print out its value
157  e = mm_bondlength_library_.end(); i != e; ++i ) {
158  TR << (i->first).key1() << "\t"
159  << (i->first).key2() << "\t"
160  << (i->second).key1() << "\t"
161  << (i->second).key2() << "\t"
162  << std::endl;
163  }
164 }
165 
166 void
167 MMBondLengthLibrary::pretty_print( int atom1, int atom2 ) const {
168  mm_bondlength_library_citer_pair temppair = this->lookup(atom1, atom2);
169  for( mm_bondlength_library_citer i = temppair.first, e = temppair.second; i != e; ++i ) {
170  TR << (i->first).key1() << "\t"
171  << (i->first).key2() << "\t"
172  << (i->second).key1() << "\t"
173  << (i->second).key2() << "\t"
174  << std::endl;
175  }
176 }
177 
178 void
180  mm_bondlength_library_citer_pair temppair = this->lookup(atom1, atom2);
181  for( mm_bondlength_library_citer i = temppair.first, e = temppair.second; i != e; ++i ) {
182  TR << (i->first).key1() << "\t"
183  << (i->first).key2() << "\t"
184  << (i->second).key1() << "\t"
185  << (i->second).key2() << "\t"
186  << std::endl;
187  }
188 }
189 
190 
191 } // namespace mm
192 } // namespace scoring
193 } // namespace core