Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
MMTorsionLibrary.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/MMTorsionLibary.cc
11 /// @brief Molecular mechanics torsion library
12 /// @author P. Douglas Renfrew (renfrew@unc.edu)
13 
14 // Unit headers
16 
17 // Project headers
20 #include <basic/Tracer.hh>
21 #include <core/types.hh>
22 
23 // Utility headers
24 // AUTO-REMOVED #include <utility/vector1.hh>
25 #include <utility/keys/Key4Tuple.hh>
26 #include <utility/keys/Key3Tuple.hh>
27 #include <utility/pointer/access_ptr.hh>
28 #include <utility/pointer/owning_ptr.hh>
29 #include <utility/pointer/ReferenceCount.hh>
30 
31 // Numeric headers
32 #include <numeric/conversions.hh>
33 
34 // C++ headers
35 #include <string>
36 #include <map>
37 // AUTO-REMOVED #include <iostream>
38 #include <sstream>
39 #include <fstream>
40 #include <cassert>
41 
43 
44 
45 
46 namespace core {
47 namespace scoring {
48 namespace mm {
49 
50 using basic::T;
51 using basic::Error;
52 using basic::Warning;
53 
54 static basic::Tracer TR("core.mm.MMTorsionLibrary");
55 
57 
58 /// @details Constructs a MMTorsionLibrary instance from a filename string and constant access pointer to an MMAtomTypeSet
62 )
63 {
64  mm_atom_set_ = mm_atom_set;
65 
66  // read the file
67  std::string line;
69  std::ifstream data( filename.c_str() );
70 
71  while( getline( data, line ) ) {
72  std::istringstream l( line );
73  if( line.size() < 1 || line[0] == '#' ) continue; // comment or blank lines
74  lines.push_back( line );
75  }
76 
77  // add the torsion params
78  for( Size i = 1; i <= lines.size(); ++i ) {
79 
80  std::istringstream l( lines[i] );
81 
82  // get four atom type strings
83  std::string atom_type_string_1, atom_type_string_2,
84  atom_type_string_3, atom_type_string_4;
85  l >> atom_type_string_1 >> atom_type_string_2
86  >> atom_type_string_3 >> atom_type_string_4;
87 
88  // get atom-type_index from atom set
89  int atom_type_int1 = mm_atom_set_->atom_type_index( atom_type_string_1 );
90  int atom_type_int2 = mm_atom_set_->atom_type_index( atom_type_string_2 );
91  int atom_type_int3 = mm_atom_set_->atom_type_index( atom_type_string_3 );
92  int atom_type_int4 = mm_atom_set_->atom_type_index( atom_type_string_4 );
93 
94  // get k_theta, multiplicty, and minimum
95  Real k_theta, minimum; int multiplicity;
96  l >> k_theta >> multiplicity >> minimum;
97  minimum = numeric::conversions::radians( minimum );
98 
99  // add to correct library
100  if( atom_type_string_1 == "X" && atom_type_string_4 == "X" )
101  {
102  wildcard_mm_torsion_library_.insert( std::make_pair(
103  mm_torsion_atom_quad( atom_type_int1, atom_type_int2, atom_type_int3, atom_type_int4 ),
104  mm_torsion_param_set( k_theta, multiplicity, minimum ) ) );
105  }
106  else
107  {
108  fully_assigned_mm_torsion_library_.insert( std::make_pair(
109  mm_torsion_atom_quad( atom_type_int1, atom_type_int2, atom_type_int3, atom_type_int4 ),
110  mm_torsion_param_set( k_theta, multiplicity, minimum ) ) );
111  }
112  }
113 
114  /// apl -- add "no-op" pair for virtual atoms
115  int const virt_type = mm_atom_set_->atom_type_index("VIRT");
116  Real const no_op_k_theta( 0.0 );
117  Real const no_op_minimum( 0.0 );
118  int const no_op_multiplicity( 0 );
119  fully_assigned_mm_torsion_library_.insert( std::make_pair(
120  mm_torsion_atom_quad( virt_type, virt_type, virt_type, virt_type ),
121  mm_torsion_param_set( no_op_k_theta, no_op_multiplicity, no_op_minimum ) ));
122 
123  // print number torsion params added
124  TR << "MM torsion sets added fully assigned: " << fully_assigned_mm_torsion_library_.size()
125  << "; wildcard: " << wildcard_mm_torsion_library_.size() << " and 1 virtual parameter."
126  << std::endl;
127 }
128 
129 /// @details The lookup function returns a pair of iterators to the first and last element in the multimap library that
130 /// corespond to the set(s) of mm params that corespond to the 4 mm atom type indices. If non are found it exits.
133 (
134  int atom1,
135  int atom2,
136  int atom3,
137  int atom4
138 ) const
139 {
140  static std::string const x_string = "X";
141  static std::string const virt_string = "VIRT";
142 
143  // forward
144  if( fully_assigned_mm_torsion_library_.count(
145  mm_torsion_atom_quad( atom1, atom2, atom3, atom4 ) ) ) {
146  return fully_assigned_mm_torsion_library_.equal_range(
147  mm_torsion_atom_quad( atom1, atom2, atom3, atom4 ) );
148  } else if( fully_assigned_mm_torsion_library_.count(
149  mm_torsion_atom_quad( atom4, atom3, atom2, atom1 ) ) ) {
150  // backward
151  return fully_assigned_mm_torsion_library_.equal_range(
152  mm_torsion_atom_quad( atom4, atom3, atom2, atom1 ) );
153  }
154 
155  int const virt_atom_type = mm_atom_set_->atom_type_index( virt_string );
156 
157  /// Virtual atoms get no mm-parameters. Return the no-op torsion object
158  if ( atom1 == virt_atom_type ||
159  atom2 == virt_atom_type ||
160  atom3 == virt_atom_type ||
161  atom4 == virt_atom_type ) {
162  return fully_assigned_mm_torsion_library_.equal_range(
163  mm_torsion_atom_quad( virt_atom_type, virt_atom_type, virt_atom_type, virt_atom_type ));
164  }
165 
166 
167  int const wild_atom_type = mm_atom_set_->atom_type_index( x_string );
168 
169  if( wildcard_mm_torsion_library_.count(
170  mm_torsion_atom_quad( wild_atom_type, atom2, atom3, wild_atom_type ) ) ) {
171  // wildcard forward
172  return wildcard_mm_torsion_library_.equal_range(
173  mm_torsion_atom_quad( wild_atom_type, atom2, atom3, wild_atom_type ) );
174  } else if (wildcard_mm_torsion_library_.count(
175  mm_torsion_atom_quad( wild_atom_type, atom3, atom2, wild_atom_type ) ) ) {
176  // wildcard backward
177  return wildcard_mm_torsion_library_.equal_range(
178  mm_torsion_atom_quad( wild_atom_type, atom3, atom2, wild_atom_type ) );
179  }
180 
181  TR << "No parameters for "
182  << (*mm_atom_set_)[atom1].name() << "-"
183  << (*mm_atom_set_)[atom2].name() << "-"
184  << (*mm_atom_set_)[atom3].name() << "-"
185  << (*mm_atom_set_)[atom4].name() << std::endl;
186 
187  /// Arriving here, we've failed to find essential parameters
188  utility_exit_with_message("COULD NOT FIND TORSION PARAMS FOR " + atom1 + ' ' + atom2 + ' ' + atom3 + ' ' + atom4 );
189  return mm_torsion_library_citer_pair(); ///< meaningless, just for removing gcc warning.
190 }
191 
192 /// @details
195 (
196  std::string atom1,
197  std::string atom2,
198  std::string atom3,
199  std::string atom4
200 ) const
201 {
202  return (*this).lookup( mm_atom_set_->atom_type_index( atom1 ),
203  mm_atom_set_->atom_type_index( atom2 ),
204  mm_atom_set_->atom_type_index( atom3 ),
205  mm_atom_set_->atom_type_index( atom4 ) );
206 }
207 
208 } // namespace mm
209 } // namespace scoring
210 } // namespace core