Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
MMBondAngleResidueTypeParamSet.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 Class to store bond angle parameters for a set of ResidueTypes
12 /// @author Colin A. Smith (colin.smith@ucsf.edu)
13 
14 // Unit headers
16 
17 // Project headers
24 #include <core/types.hh>
25 #include <basic/Tracer.hh>
26 
27 // Utility headers
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 #include <iostream>
39 #include <sstream>
40 // AUTO-REMOVED #include <fstream>
41 #include <cassert>
42 
44 #include <utility/vector1.hh>
45 
46 
47 
48 namespace core {
49 namespace scoring {
50 namespace mm {
51 
52 static basic::Tracer TR("core.mm.MMBondAngleResidueTypeParamSet");
53 
55  mm_bondangle_library_( scoring::ScoringManager::get_instance()->get_MMBondAngleLibrary() ),
56  use_residue_type_theta0_( false )
57 { }
58 
59 /// @brief copy ctor
62 ) :
63  utility::pointer::ReferenceCount( src )
64 {
65  *this = src;
66 }
67 
69 
70 /// @brief lookup a param object for a given ResidueType
73  core::chemical::ResidueType const & residue_type
74 )
75 {
76  std::map<std::string, MMBondAngleResidueTypeParam>::iterator iter(reside_type_param_map_.find(residue_type.name()));
77 
78  if (iter == reside_type_param_map_.end()) {
79 
82  reside_type_param_map_[residue_type.name()] = new_param;
83 
84  return reside_type_param_map_[residue_type.name()];
85  }
86 
87  return iter->second;
88 }
89 
90 /// @brief lookup a param object for a given ResidueType, does not auto-create
93  core::chemical::ResidueType const & residue_type
94 ) const
95 {
96  std::map<std::string, MMBondAngleResidueTypeParam>::const_iterator iter(reside_type_param_map_.find(residue_type.name()));
97 
98  if (iter == reside_type_param_map_.end()) {
99 
100  return NULL;
101  }
102 
103  return &(iter->second);
104 }
105 
106 /// @brief get the indices of the connections that connects one of my atoms to an atom on another residue
107 bool
109  core::conformation::Residue const & residue,
110  core::conformation::Residue const & other_residue,
111  core::Size const my_atomno,
112  core::Size const other_atomno,
113  core::Size & my_connection,
114  core::Size & other_connection
115 )
116 {
117  for (core::Size i = 1; i <= residue.n_residue_connections(); ++i) {
118  if (residue.residue_connection(i).atomno() == (signed)my_atomno) {
119  if (residue.connect_map(i).resid() == other_residue.seqpos()) {
120  my_connection = i;
121  other_connection = residue.connect_map(i).connid();
122  if (other_residue.residue_connection(other_connection).atomno() == (signed)other_atomno) {
123  return true;
124  }
125  }
126  }
127  }
128 
129  // didn't find a connection between the two atoms
130  my_connection = 0;
131  other_connection = 0;
132  return false;
133 }
134 
135 /// @brief lookup Ktheta and theta0 for any bond angle in a conformation
136 void
138  core::conformation::Conformation const & conformation,
139  core::id::AtomID const & atomid1,
140  core::id::AtomID const & atomid2,
141  core::id::AtomID const & atomid3,
142  core::Real & Ktheta,
143  core::Real & theta0
144 )
145 {
146  MMBondAngleResidueTypeParam const & residue_type_param(get(conformation.residue_type(atomid2.rsd())));
147 
148  lookup(conformation, atomid1, atomid2, atomid3, residue_type_param, Ktheta, theta0);
149 }
150 
151 
152 
153 /// @brief lookup Ktheta and theta0 for any bond angle in a conformation
154 void
156  core::conformation::Conformation const & conformation,
157  core::id::AtomID const & atomid1,
158  core::id::AtomID const & atomid2,
159  core::id::AtomID const & atomid3,
160  core::Real & Ktheta,
161  core::Real & theta0
162 ) const
163 {
164  MMBondAngleResidueTypeParam const * residue_type_param(get(conformation.residue_type(atomid2.rsd())));
165 
166  if (residue_type_param) {
167  lookup(conformation, atomid1, atomid2, atomid3, *residue_type_param, Ktheta, theta0);
168  } else {
169  // this is slow, but shouln't be called after scoring caches all MMBondAngleResidueTypeParam objects
170  MMBondAngleResidueTypeParam new_param;
172  lookup(conformation, atomid1, atomid2, atomid3, new_param, Ktheta, theta0);
173  }
174 }
175 
176 /// @brief lookup Ktheta and theta0 for any bond angle in a conformation
177 void
179  core::conformation::Conformation const & conformation,
180  core::id::AtomID const & atomid1,
181  core::id::AtomID const & atomid2,
182  core::id::AtomID const & atomid3,
183  MMBondAngleResidueTypeParam const & residue_type_param,
184  core::Real & Ktheta,
185  core::Real & theta0
186 ) const
187 {
188  Ktheta = 0;
189  theta0 = 0;
190 
191  if (atomid1.rsd() == atomid2.rsd() && atomid1.rsd() == atomid3.rsd()) {
192 
193  // simple case, all atoms are in the same residue
194  three_atom_set atom_set(atomid1.atomno(), atomid2.atomno(), atomid3.atomno());
195  core::Size bondangle_index(residue_type_param.bondangle_index(atom_set));
196 
197  if (bondangle_index != 0) {
198  // use residue_type_param data
199  Ktheta = residue_type_param.Ktheta(bondangle_index);
200  theta0 = residue_type_param.theta0(bondangle_index);
201  }
202 
203  return;
204  }
205 
206  int const mmtype1(conformation.residue_type(atomid1.rsd()).atom(atomid1.atomno()).mm_atom_type_index());
207  int const mmtype2(conformation.residue_type(atomid2.rsd()).atom(atomid2.atomno()).mm_atom_type_index());
208  int const mmtype3(conformation.residue_type(atomid3.rsd()).atom(atomid3.atomno()).mm_atom_type_index());
209 
210  mm_bondangle_library_citer_pair params(mm_bondangle_library_->lookup(mmtype1, mmtype2, mmtype3));
211 
212  Ktheta = (params.first->second).key1();
213  theta0 = (params.first->second).key2();
214 
215  // the rest is all to determine if theta0 should be derived from the ResidueType geometry
216 
217  core::Size primary_rsd(atomid2.rsd());
218  core::Size secondary_rsd(0);
219  core::Size atomno1(0);
220  core::Size atomno2(atomid2.atomno());
221  core::Size atomno3(0);
222 
223  if (atomid1.rsd() == atomid2.rsd()) {
224  // more complicated case, an interresidue bond angle with atoms 1 & 2 in the same residue
225  secondary_rsd = atomid3.rsd();
226  atomno1 = atomid1.atomno();
227  atomno3 = atomid3.atomno();
228  } else if (atomid2.rsd() == atomid3.rsd()) {
229  // more complicated case, an interresidue bond angle with atoms 2 & 3 in the same residue
230  secondary_rsd = atomid1.rsd();
231  atomno1 = atomid3.atomno();
232  atomno3 = atomid1.atomno();
233  } else {
234  // unsupported case, an interresidue bond angle with atom 2 in its own residue distinct from 1 & 3
235  utility_exit_with_message("Lookup of three residue bond angle parameters not supported");
236  }
237 
238  core::Size primary_connection;
239  core::Size secondary_connection;
240  // lookup the residue connection ids
241  if (connection_indices(conformation.residue(primary_rsd), conformation.residue(secondary_rsd), atomno2, atomno3,
242  primary_connection, secondary_connection)) {
243  two_atom_set const primary_atom_set(atomno1, atomno2);
244  core::Size connection_index(residue_type_param.connection_index(primary_connection, primary_atom_set));
245  if (!connection_index) {
246  Ktheta = 0;
247  return;
248  }
249  if (residue_type_param.connection_use_theta0(primary_connection, connection_index)) {
250  theta0 = residue_type_param.connection_theta0(primary_connection, connection_index);
251  }
252  }
253 }
254 
257  core::scoring::ScoreFunction const & scorefxn
258 )
259 {
261  iter != scorefxn.ci_2b_intrares_end(); ++iter) {
262 
263  core::scoring::methods::MMBondAngleEnergyCAP bond_angle_energy_method;
264 
265  bond_angle_energy_method = dynamic_cast<core::scoring::methods::MMBondAngleEnergy const *>((*iter)());
266 
267  if (bond_angle_energy_method) {
268  return bond_angle_energy_method->residue_type_param_set();
269  }
270  }
271 
272  return NULL;
273 }
274 
275 
276 } // namespace mm
277 } // namespace scoring
278 } // namespace core