Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
MMBondAngleLibrary.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/MMBondAngleLibary.cc
11 /// @brief Molecular mechanics bond angle library
12 /// @author Colin A. Smith (colin.smith@ucsf.edu)
13 
14 // Unit headers
16 
17 // Project headers
20 #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 #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 #include <numeric/conversions.hh>
34 
35 // C++ headers
36 #include <string>
37 #include <map>
38 #include <iostream>
39 #include <sstream>
40 #include <fstream>
41 #include <cassert>
42 
43 #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.MMBondAngleLibrary");
60 
61 /// @details Construct a MMBondAngleLibrary 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 == "DIHEDRALS") in_bonds_section = false;
79  if (in_bonds_section) lines.push_back( line );
80  if (line == "ANGLES") in_bonds_section = true;
81  }
82 
83  // add the torsion params
84  for( Size i = 1; i <= lines.size(); ++i ) {
85 
86  std::istringstream l( lines[i] );
87 
88  // get four atom type strings
89  std::string atom_type_string_1, atom_type_string_2,
90  atom_type_string_3;
91  l >> atom_type_string_1 >> atom_type_string_2
92  >> atom_type_string_3;
93 
94  // skip the parameters if any of the atom types don't exist
95  if ( ! mm_atom_set_->contains_atom_type( atom_type_string_1 ) ) continue;
96  if ( ! mm_atom_set_->contains_atom_type( atom_type_string_2 ) ) continue;
97  if ( ! mm_atom_set_->contains_atom_type( atom_type_string_3 ) ) continue;
98 
99  // get atom-type_index from atom set
100  int atom_type_int1 = mm_atom_set_->atom_type_index( atom_type_string_1 );
101  int atom_type_int2 = mm_atom_set_->atom_type_index( atom_type_string_2 );
102  int atom_type_int3 = mm_atom_set_->atom_type_index( atom_type_string_3 );
103 
104  // get k_theta and minimum
105  Real k_theta, minimum;
106  l >> k_theta >> minimum;
107  minimum = numeric::conversions::radians( minimum );
108 
109  //TR << atom_type_string_1 << "\t" << atom_type_string_2 << "\t" << atom_type_string_2 << "\t" << k_theta << "\t"
110  // << minimum << std::endl;
111 
112  // add to correct library
113  if( atom_type_string_1 == "X" && atom_type_string_3 == "X" )
114  {
115  wildcard_mm_bondangle_library_.insert( std::make_pair(
116  mm_bondangle_atom_tri( atom_type_int1, atom_type_int2, atom_type_int3 ),
117  mm_bondangle_param_set( k_theta, minimum ) ) );
118  }
119  else
120  {
121  fully_assigned_mm_bondangle_library_.insert( std::make_pair(
122  mm_bondangle_atom_tri( atom_type_int1, atom_type_int2, atom_type_int3 ),
123  mm_bondangle_param_set( k_theta, minimum ) ) );
124  }
125  }
126 
127  /// apl -- add "no-op" pair for virtual atoms
128  int const virt_type = mm_atom_set_->atom_type_index("VIRT");
129  Real const no_op_k_theta( 0.0 );
130  Real const no_op_minimum( 0.0 );
131  fully_assigned_mm_bondangle_library_.insert( std::make_pair(
132  mm_bondangle_atom_tri( virt_type, virt_type, virt_type ),
133  mm_bondangle_param_set( no_op_k_theta, no_op_minimum ) ));
134 
135 
136  // print number torsion params added
137  TR << "MM bond angle sets added fully assigned: " << fully_assigned_mm_bondangle_library_.size()
138  << "; wildcard: " << wildcard_mm_bondangle_library_.size() << " and 1 virtual parameter."
139  << std::endl;
140 }
141 
144 (
145  int atom1,
146  int atom2,
147  int atom3
148 ) const
149 {
150 
151  static std::string const x_string = "X";
152  static std::string const virt_string = "VIRT";
153 
154  if( fully_assigned_mm_bondangle_library_.count(
155  mm_bondangle_atom_tri( atom1, atom2, atom3 ) ) ) {
156  // forward
157  return fully_assigned_mm_bondangle_library_.equal_range(
158  mm_bondangle_atom_tri( atom1, atom2, atom3 ) );
159  } else if( fully_assigned_mm_bondangle_library_.count(
160  mm_bondangle_atom_tri( atom3, atom2, atom1 ) ) ) {
161  // backward
162  return fully_assigned_mm_bondangle_library_.equal_range(
163  mm_bondangle_atom_tri( atom3, atom2, atom1 ) );
164  }
165 
166  int const virt_atom_type = mm_atom_set_->atom_type_index( virt_string );
167 
168  /// Virtual atoms get no mm-parameters. Return the no-op torsion object
169  if ( atom1 == virt_atom_type ||
170  atom2 == virt_atom_type ||
171  atom3 == virt_atom_type ) {
172  return fully_assigned_mm_bondangle_library_.equal_range(
173  mm_bondangle_atom_tri( virt_atom_type, virt_atom_type, virt_atom_type ));
174  }
175 
176 
177  int const wild_atom_type = mm_atom_set_->atom_type_index( x_string );
178 
179  if( wildcard_mm_bondangle_library_.count(
180  mm_bondangle_atom_tri( wild_atom_type, atom2, wild_atom_type ) ) ) {
181  // wildcard 1 & 3
182  return wildcard_mm_bondangle_library_.equal_range(
183  mm_bondangle_atom_tri( wild_atom_type, atom2, wild_atom_type ) );
184  }
185 
186  TR << "No parameters for " << (*mm_atom_set_)[atom1].name() << "-" << (*mm_atom_set_)[atom2].name() << "-"
187  << (*mm_atom_set_)[atom3].name() << std::endl;
188  //return fully_assigned_mm_bondangle_library_.equal_range(
189  // mm_bondangle_atom_tri( virt_atom_type, virt_atom_type, virt_atom_type ));
190  if ( ! basic::options::option[ basic::options::OptionKeys::MM::ignore_missing_bondangle_params ]() )
191  utility_exit_with_message("COULD NOT FIND BOND ANGLE PARAMS FOR " + atom1 + ' ' + atom2 + ' ' + atom3 );
192 
193  return mm_bondangle_library_citer_pair(); ///< meaningless, just for removing gcc warning.
194 }
195 
198 (
199  std::string atom1,
200  std::string atom2,
201  std::string atom3
202 ) const
203 {
204  return (*this).lookup( mm_atom_set_->atom_type_index( atom1 ),
205  mm_atom_set_->atom_type_index( atom2 ),
206  mm_atom_set_->atom_type_index( atom3 ) );
207 }
208 
209 void
211 {
212  // for each key print out its value
214  e = fully_assigned_mm_bondangle_library_.end(); i != e; ++i ) {
215  TR << (i->first).key1() << "\t"
216  << (i->first).key2() << "\t"
217  << (i->first).key3() << "\t"
218  << (i->second).key1() << "\t"
219  << (i->second).key2() << "\t"
220  << std::endl;
221  }
222 
224  e = wildcard_mm_bondangle_library_.end(); i != e; ++i ) {
225  TR << (i->first).key1() << "\t"
226  << (i->first).key2() << "\t"
227  << (i->first).key3() << "\t"
228  << (i->second).key1() << "\t"
229  << (i->second).key2() << "\t"
230  << std::endl;
231  }
232 }
233 
234 void
235 MMBondAngleLibrary::pretty_print( int atom1, int atom2, int atom3 ) const
236 {
237  mm_bondangle_library_citer_pair temppair = (*this).lookup(atom1, atom2, atom3);
238  for( mm_bondangle_library_citer i = temppair.first, e = temppair.second; i != e; ++i ) {
239  TR << (i->first).key1() << "\t"
240  << (i->first).key2() << "\t"
241  << (i->first).key3() << "\t"
242  << (i->second).key1() << "\t"
243  << (i->second).key2() << "\t"
244  << std::endl;
245  }
246 }
247 
248 void
250 {
251  mm_bondangle_library_citer_pair temppair = (*this).lookup(atom1, atom2, atom3);
252  for( mm_bondangle_library_citer i = temppair.first, e = temppair.second; i != e; ++i ) {
253  TR << (i->first).key1() << "\t"
254  << (i->first).key2() << "\t"
255  << (i->first).key3() << "\t"
256  << (i->second).key1() << "\t"
257  << (i->second).key2() << "\t"
258  << std::endl;
259  }
260 }
261 
262 } // namespace mm
263 } // namespace scoring
264 } // namespace core